이 블로그 검색

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 로 해서 클릭 이벤트가 전달이 안되게 하면 레이아웃 전체에 무리없이 클릭 이벤트가 먹는다...