본문 바로가기

Android

유튜브 아이디를 통해 유튜브 앱으로 재생하기 public class YouTubeHelper { public static void watchYoutubeVideo(Context context, String id){ try { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube:" + id)); context.startActivity(intent); } catch (ActivityNotFoundException ex) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com/watch?v=" + id)); context.startActivity(intent); } }} 더보기
AES256 encode,decode 를 해보자 public class EncryptionHelper { public static byte[] ivBytes = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };private static String key = "KEY"; public static String AES_Encode(String str){ byte[] textBytes = new byte[0];Cipher cipher = null;String result = null;try {textBytes = str.getBytes("UTF-8");AlgorithmParameterSpec ivSpec = new IvParame.. 더보기
dp를 px로 변환하기 public class DPHelper { public static int dpToPx(Context context,float dp){ Resources r = context.getResources(); int px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, r.getDisplayMetrics()); return px; }} dp값을 px 로 변환하는 간단한 함수이다. 더보기
Intent를 이용한 트위터 공유하기 public static void shareTwitter(Context context,String title,String content){ Intent intent = new Intent(); intent.setAction(Intent.ACTION_SEND); intent.setType("text/plain"); intent.setPackage("com.twitter.android"); intent.putExtra(Intent.EXTRA_SUBJECT, title); intent.putExtra(Intent.EXTRA_TEXT, content); try { context.startActivity(intent); } catch (Exception e) { ToastHelper.showText(context.. 더보기
Intent를 이용한 카카오스토리 공유하기 public static void shareKakaoStory(Context context,String title,String content){ Intent intent = new Intent(); intent.setAction(Intent.ACTION_SEND); intent.setType("text/plain"); intent.setPackage("com.kakao.story"); intent.putExtra(Intent.EXTRA_SUBJECT, title); intent.putExtra(Intent.EXTRA_TEXT, content); try { context.startActivity(intent); } catch (Exception e) { ToastHelper.showText(context,.. 더보기
Intent를 이용한 페이스북 공유하기 소스는 2가지 방법을 포함하고 있다.1.facebook sdk를 이용하여 공유하기2.Intent를 이용한 공유하기 주석된 부분이 인텐트를 이용하는 부분이다. public static void shareFacebook(Context context,String title,String content,String image){ ShareLinkContent shareLinkContent = new ShareLinkContent.Builder() .setContentTitle(title) .setContentDescription(content) .setContentUrl(Uri.parse("http://www.test.com")) .setImageUrl(Uri.parse(image)) .build(); Share.. 더보기
Intent를 이용한 카카오톡 공뷰하기 public static void shareKakaotalk(Context context,String title,String content){ Intent intent = new Intent(); intent.setAction(Intent.ACTION_SEND); intent.setType("text/plain"); intent.setPackage("com.kakao.talk"); intent.putExtra(Intent.EXTRA_SUBJECT, title); intent.putExtra(Intent.EXTRA_TEXT, content); try { context.startActivity(intent); } catch (Exception e) { ToastHelper.showText(context,co.. 더보기
ValueAnimator 를 이용한 색상 변경 애니메이션 int fromColor = Color.RED;int toColor = Color.BLUE; colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), fromColor, toColor);colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {@Overridepublic void onAnimationUpdate(ValueAnimator valueAnimator) { control_background_color.setBackgroundColor((Integer) valueAnimator.getAnimatedValue()); }}); colorAnimation.setDurati.. 더보기