목록개발 (7)
Life Life Life
안드로이드 Reeceiver 등록 및 해체할때마다 신경쓰인다. 등록되어져 있는 상태에서 해체하면 상관없는데 미등록상태에서 해체하면 오류가 발생하며 따로 등록되어져 있는지 확인하는 API가 존재하지 않아 tyr ~ catch로 처리하였는데 관리 Manager을 만들어 처리하였어요. private ReceiverManager(Context context){this.context = context;} public static synchronized ReceiverManager init(Context context){if (ref == null)ref = new ReceiverManager(context);return ref;} public void registerReceiver(BroadcastReceiver..
가끔 TextView에 전체적으로 폰트를 변경할 경우가 있다. 일일이 TextView을 찾아서 폰트를 적용하는 노가다을 하지 않고 그냥 TextView을 상속받아 처리하면 훨씬 빠른 처리가 가능하다. public class CTextView extends TextView{private static Typeface mTypeface; public CTextView(final Context context){this(context, null);} public CTextView(final Context context, final AttributeSet attrs){this(context, attrs, 0);} public CTextView(final Context context, final AttributeSe..
이미지 파일에 대한 EXIF 정보를 조회하여 이미지 회전 public static Bitmap makeBitmap(String filename){File file = new File(filename);if (file.exists()){Bitmap downSize = null;try{BitmapFactory.Options options = new BitmapFactory.Options();options.inJustDecodeBounds = true;downSize = BitmapFactory.decodeFile(filename, options);ExifInterface exif = new ExifInterface(filename);int exifOrientation = exif.getAttributeInt..
안드로이드 윈도우메니져에 뷰을 붙이면 됩니다. /* * 윈도우메니져 뷰에서 토스트 */public static void showToast(final Context context, String msg){WindowManager.LayoutParams params = new WindowManager.LayoutParams();params.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;params.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;params.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;params.height = WindowManager..
안드로이드에서 종종 Dialog, ProgressDialog에 대해 하드웨어 키을 못하게 막는 경우가 발생한다. 1. Back Key 막기 AlertDialog.Builder에서 setCancelable 설정을 true 처리하면 된다. Ex) AlertDialog.Builder alertDlg = new AlertDialog.Builder(context); alertDlg.setCancelable(true); alertDlg.setTitle("안내"); alertDlg.setMessage("'종료하시겠습니까?"); alertDlg.setPositiveButton("종료", new DialogInterface.OnClickListener() { @Override public void onClick(Dial..
안드로이드에서 LBS할 경우 GPS을 활용하게 된다. 타이틀 내용처럼 맵Activity로 이동하여 GPS가 활성화가 되어 있는지 확인하고 안되어있는 경우 설정하게끔 사용자에게 유도하여야한다. LocationManager을 우선적으로 정의하여야 하며 기타 기초 세팅은 제외하겠다. mLocationManager = (LocationMagager)getSystemService(Context.LOCATION_SERVICE); onResume() 메소드 오버라이드하여 정의하여야 하며 밑에 코드을 적적히 사용하된다. // GPS 사용 유무에 따라 위치설정으로 이동 if(!mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){startActivity(n..
출처 : http://blog.kfmes.com/227 안드로이드폰은 화면 회전이 지원된다. 키보드를 열거나 닫으면 가로보기/세로보기로 전환이 되는데, 이때 UI가 새로 그려지면서 Activity의 onDestroy()와 onCreate() 가 수행된다. 위 과정이 수행되고 나면, Activity 에서 가지고 있었던 변수들(field 도 포함)이 초기 상태로 된다. 만약, 코드에서 Thread를 만들어 돌아가는 중이었다면, 화면 회전을 한 후에는 사라지는 현상이다. 해결방법 /** Activity소스코드를 보면, 타입이 HashMap이고, null 을 리턴하고 있다. 유지해야할 데이터가 한개라면 그 Object를 바로 리턴해도 된다. */ @Override public Object onRetainNonC..