이 블로그 검색

2015년 10월 26일 월요일

Log 작성 시 유용한 툴: Thread 객체

    private static void log(char level, String msg) {
        if(DEBUG) {
            Thread thread = Thread.currentThread();      // <- 이와같이 Thread 객체를 이용하면
            String threadName = thread.getName();        // 현재 Thread 이름
            String  fileName = thread.getStackTrace()[4].getFileName();  // 현재 로그가 찍히는 file 이름
            int nLine = thread.getStackTrace()[4].getLineNumber();     // 현재 로그가 찍히는 줄넘버 까지 다 알수 있음.

            if(fileName.length() > 20) {
                fileName = fileName.substring(0, 20);
            }

            String strLog = String.format("%s:%-10s[%-20s %5d]%s\n", TAG, threadName, fileName, nLine, msg);

            switch(level) {
                case 'D':
                    Log.d(TAG, strLog);
                    break;
                case 'E':
                    Log.e(TAG, strLog);
                    break;
                case 'W':
                    Log.w(TAG, strLog);
                    break;
                case 'I':
                    Log.i(TAG, strLog);
                    break;
                case 'V':
                    Log.v(TAG, strLog);
                    break;
            }

        }

2015년 10월 3일 토요일

안드로이드 키보드 호출 option: adjustPan, adjustResize

안드로이드 키보드 호출 시 가장 중요한 두 옵션이다. (설정은 manifest의 해당 activity에서 하면 된다.)

Ex) <activity android:name=".activities.BoardActivity" android:windowSoftInputMode="adjustPan"></activity>

이 두 옵션의 가장 큰 차이는 한마디로 키보드의 높이만큼 올라가서 가려지는 부분을 허용하겠느냐, 말겠느냐의 차이라 볼 수 있다.

adjustPan 은 쿨하게 가려버리라는 것이고, (즉, 가려져도 상관없다.) 
adjustResize 는 한마디로 "리사이즈" 해서라도 가려지는 부분이 없도록 다 보이게 하라는 의미이다. (가려지는 부분이 있으면 안된다.) 

따라서, pan 으로 설정하면 각 UI 컴포넌트(즉,뷰(View)들)의 사이즈 변화가 없고, Resize로 설정하면 View 들의 높이가 줄어들게 된다.(키보드의 높이만큼 뷰들이 나누어서 크기가 줄어든다고 생각하면 됨)
 

2015년 7월 24일 금요일

Android: OnClick Event 의 하위 뷰(View) 전달

 LinearLayout, RelativeLayout 등 레이아웃에 OnClickListener를 걸어, 레이아웃을 클릭했을 때 무언가 작동을 하게끔 할때가 있다. 이때 레이아웃의 클릭(터치) 이벤트는 레이아웃 아래의 하위 뷰에 전달이 되어서 그 하위 뷰의 영역만큼 레이아웃의 OnClick Event가 발생하지 않는다....

보통 아래와 같은 case  이다..


<LinearLayout    
 android:layout_width="0dp"    
 android:layout_height="match_parent"    
 android:id="@+id/llimgBtnShowMenu"    
 android:gravity="bottom|center_horizontal"    
 android:layout_weight="1">

    <ImageButton        
      android:id="@+id/imgBtnShowMenu"        
      android:clickable="false"
      android:layout_width="13.33dp"        
      android:layout_height="10.67dp"        
      android:layout_marginBottom="18dp"        
      android:background="@drawable/ico_menu" />
</LinearLayout>


  
  이것을 막기 위해서는 하위 뷰의 clickable = false 로 해서 클릭 이벤트가 전달이 안되게 하면 레이아웃 전체에 무리없이 클릭 이벤트가 먹는다... 

2014년 11월 22일 토요일

Java 날짜 및 시간 처리


Calendar today = Calendar.getInstance();

int year = today.get(Calendar.YEAR);
int month = today.get(Calendar.MONTH);
int day = today.get(Calendar.DAY_OF_MONTH);
int hour = today.get(Calendar.HOUR_OF_DAY);

today.setTime(new Date(System.currentTimeMillis()+ 3600000));
// 지금으로부터 1시간 후로 시간 세팅

2014년 10월 20일 월요일

Android Library Project 추가

Android 에 외부 library를 추가하는 방법은
1. 일반 jar 라이브러리 파일을 추가하는 법
2. 외부 project를 통으로 추가하는 법

이렇게 2가지가 있다.
이중 jar파일 추가는 아래의 방법과 같이 하고,


프로젝트를 통체로 추가하는 방법은(라이브러리 프로젝트라 한다.)
아래와 같이 한다.


굳이 이렇게 써 놓는 이유는 2번의 라이브러리 프로젝트를 1번의 방법으로 추가하면
몬가 추가된 것처럼 빌드 패쓰에는 정상적으로 잡히는 데, 결국 읽어 오지 못해 에러를 뿜는다..

(이러한 이유로 "왜 안되지?" 하면서 삽질을 반드시 하게 된다.)

그리고 이렇게 라이브러리 프로젝트로 추가된 프로젝트 jar 는 반드시
이클립스의 "Android Dependencies" 라는 폴더 아래에 있어야 한다.






2014년 7월 24일 목요일

SQLiteException 이 catch가 안될 때...

키 값이 같은 값은 insert 가 안되고
SQLiteException 발생해
catch 문에 handling 하는 로직을 넣으려고 하였으나...
왠일인지 절대 잡히지 않는다...
문제는...

아래의 insert 메서드를 쓰면 안되고,

try {
   db.insert(TABLE_USERvalues); 
    isInsertSucceed = true;

} catch (SQLiteException e) {
    isInsertSucceed = false;


}

insertOrThrow() 메서드를 써야한다..  (쉣~!)

try {
   db.insertOrThrow(TABLE_USERvalues); 
    isInsertSucceed = true;

catch (SQLiteException e) {
    isInsertSucceed = false;


}