티스토리 툴바


1. LayoutInflater ?


안드로이드에서  어떤 뷰가 화면에 보일려면 반드시 객체화(인스턴스) 되어 있어야 하는데요.

안드로이드에서 뷰 객체를 생성하는 과정은 크게 2가지가 있습니다.

 

직접 코드상에서 아래와 같이 생성하는 방법이 있고

Button b = new Button(this)   // this 는 Context 를 의미

그리고 xml 파일을 통해서 객체를 생성하는 방법이 있습니다.


인플레이트라는 것은 xml 파일을 통해서 객체화를 시키는 것을 말합니다.


2. LayoutInflater 사용시 주의 사항


LayoutInflater inflate 사용할때 parameter의 의미에 주의해서 처리해야합니다. 


        String service = Context.LAYOUT_INFLATER_SERVICE;
        LayoutInflater li = (LayoutInflater)getContext().getSystemService (service);


        LinearLayout ll =(LinearLayout)li.inflate (R.layout.region_main_header, this, false);

       addView(ll);


       또는

        LinearLayout ll =(LinearLayout)li.inflate (R.layout.region_main_header, this, true);

       

this 는 attach할 rootViewGroup 이다

true,false는 attach여부


안드로이드 help

View inflate(int resource, ViewGroup root)
Inflate a new view hierarchy from the specified xml resource.
View inflate(XmlPullParser parser, ViewGroup root)
Inflate a new view hierarchy from the specified xml node.
View inflate(XmlPullParser parser, ViewGroup root, boolean attachToRoot)
Inflate a new view hierarchy from the specified XML node.
View inflate(int resource, ViewGroup root, boolean attachToRoot)
Inflate a new view hierarchy from the specified xml resource.


3. LayoutInflater 사용예


1) 암시적으로 사용됨


    public void onCreate(Bundle savedInstanceState){    
        super.onCreate(savedInstanceState);
        setContentView(R.layout.home);

       ....

   }


setContentView내부에서  LayoutInflater 사용 

     li.inflate (R.layout.home, this, true);



2) 리스트뷰의  커스텀 BaseAdapter에서  객첵화 해야 하는 경우 사용


private class TableListAdapter extends BaseAdapter {

    private LayoutInflater mInflater


    TableListAdapter() {
         mInflater = (LayoutInflater)

           getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);     }
    }

              @Override
              public View getView(int position, View convertView, ViewGroup parent) {
                   if (convertView == null) {
                       convertView = mInflater.inflate(R.layout.home_list_row, parent, false);
                    }

                    ......

                    return convertView;

                 }

            }


3) 커스텀뷰를 만들어 사용하는 경우


public class VideoThumbView extends RelativeLayout {

    RemoteImageView mImageView;
    
    public VideoThumbView(Context context) {
        super(context);
        create(context);
    }
    
    public VideoThumbView(Context context, AttributeSet attrs) {
        super(context, attrs);
        create(context);
    }
    
    private void create(Context context)
    {
        String service = Context.LAYOUT_INFLATER_SERVICE;
        LayoutInflater li = (LayoutInflater)context.getSystemService (service);
        li.inflate (R.layout.video_thumb, this, true);
        
        mImageView = (RemoteImageView )findViewById(R.id.video_thumb_image);
        mImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    }

}



4) XML 리소를 객체화 하여 사용하는 경우


    private void setLayout() {
        mTableListView=(ListView)findViewById(R.id.home_table_list);

        mInflater = (LayoutInflater)getSystemService (Context.LAYOUT_INFLATER_SERVICE);
        mHeaderView = mInflater.inflate(R.layout.home_list_header,mTableListView, false);
        
        mImagePageLabel=(TextView)mHeaderView.findViewById(R.id.home_image_page);
        mImageGallery=(Gallery)mHeaderView.findViewById(R.id.home_image_slide);
        mImageTextLabel=(TextView)mHeaderView.findViewById(R.id.home_image_text);       
        mVideoPageLabel=(TextView)mHeaderView.findViewById(R.id.home_video_page);
        mVideoGallery=(FilingGallery)mHeaderView.findViewById(R.id.home_video_slide);
        mTableListView.addHeaderView(mHeaderView);
    }

저작자 표시
Posted by dyecolor 심성진 Trackback 0 : Comment 1
안드로이드 Intent에서 앱을 호출하는 방법을 정리 합니다.

연락처 Intent

  • 연락처 조회
intent = new Intent(Intent.ACTION_VIEW, 
Uri.parse("content://contacts/people/" +
String.valueOf(contact.getId())));
startActivity(intent);
  • 연락처 등록
intent = new Intent(Intent.ACTION_INSERT, 
Uri.parse("content://contacts/people"));
startActivity(intent);
  • 연락처 수정
intent = new Intent(Intent.ACTION_EDIT, 
Uri.parse("content://contacts/people/" +
String.valueOf(contact.getId())));
startActivity(intent);
  • 연락처 삭제
intent = new Intent(Intent.ACTION_DELETE, 
Uri.parse("content://contacts/people/" +
String.valueOf(contact.getId())));
startActivity(intent);

전화 Intent

  • 권한 설정 (AndroidManifest.xml)
전화 걸기         : CALL_PHONE = "android.permission.CALL_PHONE"
긴급 통화  : CALL_PRIVILEGED =
"android.permission.CALL_PRIVILEGED"
폰 상태 읽기  : READ_PHONE_STATE =
"android.permission.READ_PHONE_STATE"
폰 상태 수정  : MODIFY_PHONE_STATE =
"android.permission.MODIFY_PHONE_STATE"
브로드케스팅 수신 : PROCESS_OUTGOING_CALLS =
"android.permission.PROCESS_OUTGOING_CALLS"
전화 걸기 이전  : ACTION_NEW_OUTGOING_CALL =
"android.intent.action.NEW_OUTGOING_CALL"
  • 전화걸기 화면
Intent intent = new Intent(Intent.ACTION_DIAL, 
Uri.parse("tel:" + TelNumber));
startActivity(intent);
  • 전화걸기
Intent intent = new Intent(Intent.ACTION_CALL, 
Uri.parse("tel:" + TelNumber));
startActivity(intent);

SMS Intent

  • 권한 설정 (AndroidManifest.xml)
수신 모니터링       : RECEIVE_SMS = "android.permission.RECEIVE_SMS"
읽기 가능  : READ_SMS = "android.permission.READ_SMS"
발송 가능  : SEND_SMS = "android.permission.SEND_SMS"
SMS Provider로 전송 : WRITE_SMS = "android.permission.WRITE_SMS"
 : BROADCAST_SMS = "android.permission.BROADCAST_SMS"
  • SMS 발송 화면
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.putExtra("sms_body", "The SMS text");
intent.setType("vnd.android-dir/mms-sms");
startActivity(intent);
  • SMS 보내기
Intent intent = new Intent(Intent.ACTION_SENDTO, 
Uri.parse("smsto://" + contact.getHandphone()));
intent.putExtra("sms_body", "The SMS text");
intent.setType("vnd.android-dir/mms-sms");
startActivity(intent);

이메일 Intent

  • 이메일 발송 화면
Intent intent = new Intent(Intent.ACTION_SENDTO, 
Uri.parse("mailto:" + contact.getEmail()));
startActivity(intent);

브라우저 Intent

  • Browser에서 URL 호출하기
new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com/"));
startActivity(intent);
  • 브라우저에서 검색
Intent intent = new Intent(Intent.ACT ION_WEB_SEARCH);
intent.putExtra(SearchManager.QUERY, "검색어");
startActivity(intent);

지도 Intent

  • 지도 보기
Uri uri = Uri.parse ("geo: 38.00, -35.03");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);

안드로이드 마켓 Intent

  • 안드로이드 마켓에서 Apps 검색
Uri uri = Uri.parse("market://search?q=pname:전제_패키지_명");  
//--- 예) market://search?q=pname:com.jopenbusiness.android.smartsearch
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
  • 안드로이드 마켓의 App 상세 화면
Uri uri = Uri.parse("market://details?id=전제_패키지_명");
//--- 예) market://details?id=com.jopenbusiness.android.smartsearch
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);

갤럭시S의 Intent

  • 패키지명과 클래스명으로 App 호출
intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName("패키지명", "전체_클래스명"));
startActivity(intent);
  • 전화, SMS
  • 전화번호부 : com.android.contacts, com.sec.android.app.contacts.PhoneBookTopMenuActivity
  • 전화 : com.sec.android.app.dialertab, com.sec.android.app.dialertab.DialerTabActivity
  • 최근기록 : com.sec.android.app.dialertab, com.sec.android.app.dialertab.DialerTabDialerActivity
  • 메시지 : com.sec.mms, com.sec.mms.Mms
  • 이메일 : com.android.email, com.android.email.activity.Welcome
  • 일정 : com.android.calendar, com.android.calendar.LaunchActivity
  • 인터넷 : com.android.browser, com.android.browser.BrowserActivity
  • Google의 Android용 앱
  • 검색 : com.google.android.googlequicksearchbox, com.google.android.googlequicksearchbox.SearchActivity
  • 음성 검색 : com.google.android.voicesearch, com.google.android.voicesearch.RecognitionActivity
  • Gmail : com.google.android.gm, com.google.android.gm.ConversationListActivityGmail
  • 지도 : com.google.android.apps.maps, com.google.android.maps.MapsActivity
  • 위치찾기 : com.google.android.apps.maps, com.google.android.maps.LatitudeActivity
  • YouTube : com.google.android.youtube, com.google.android.youtube.HomeActivity
  • 토크 : com.google.android.talk, com.google.android.talk.SigningInActivity
  • Goggles : com.google.android.apps.unveil, com.google.android.apps.unveil.CaptureActivity
  • Google 번역 : com.google.android.apps.translate, com.google.android.apps.translate.HomeActivity
  • Reader : com.google.android.apps.reader, com.google.android.apps.unveil.CaptureActivity
  • Voice : com.google.android.apps.googlevoice, com.google.android.apps.googlevoice.SplashActivity
  • Google 별지도 : com.google.android.stardroid, com.google.android.stardroid.activities.SplashScreenActivity
  • 카메라 : com.sec.android.app.camera, com.sec.android.app.camera.Camera
  • TV : com.sec.android.app.dmb, com.sec.android.app.dmb.activity.DMBFullScreenView
  • Android 관리
  • 환경 설정 : com.android.settings, com.android.settings.Settings
  • 작업 관리자 : com.sec.android.app.controlpanel, com.sec.android.app.controlpanel.activity.JobManagerActivity
  • 마켓 : com.android.vending, com.android.vending.AssetBrowserActivity




*** 참고 문헌 ***

 출처 : http://www.jopenbusiness.com/tc/oss/entry/Android-Intent-%ED%99%9C%EC%9A%A9-%EC%82%AC%EB%A1%80

저작자 표시
Posted by dyecolor 심성진 Trackback 0 : Comment 0

20개 정도 규칙이 있으며 출처는 source.android.com에서 좀 더 자세한 내용을 볼 수 있다.

build된 sdk에는 없지만 sdk 소스를 다운받으면 이클립스용 코딩 포맷과 import순서가 정보가 적힌 xml파일도 같이 받을 수 있는데, 이 글에 첨부했다.

android-formatting.xml은 "Window › Preferences › Java › Code Style > Formatter 에 import하고,
android.importorder "Organize Imports에 import하면
Shift+command+F로 자동포멧정리 기능을 안드로이드에 맞게 사용할 수 있다.

  1. Exceptions: 예외 무시하지말고 처리하기.
  2. Exceptions: 상위 Exception으로 싸잡아서 처리하지 않기.
  3. Finalizers: 왠만하면 쓰지않기 (언제 적용될지 모름)
  4. Imports: *쓰지말고 정확하게 풀네임 적기.

Java Library Rules

표준 코딩컨벤션이 바뀌어서 예전 코딩컨벤션과 충돌이 난다면 예전 코딩컨벤션으로 작성해서 일관성을 유지하기.

Java Style Rules

자바표준 컨벤션에서 추가사항:

  1. Comments/Javadoc: 표준대로 작성하기.
  2. Short methods: 메소드는 40줄이 넘지않게 짧게 작성하기
  3. Fields: 초기에 선언하기나 사용하기 바로 전에 선언할 것.
  4. Local variables: 지역변수 범위는 최소화하기.
  5. Imports: 안드로이드, 서드파티(알파벳 순), java, javax 순으로 import하기.
  6. Indentation: 탭안쓰고 공백 4개 사용하기.
  7. Line length: 한줄에 100칸 이하 유지하기.
  8. Field names: Non-public, non-static 변수는 m으로 시작하고, static변수는 s로 시작하기.
  9. Braces: { 는 줄넘기지말고 사용하기
  10. Annotations: 표준 어노테이션 사용하기.
  11. Acronyms are words: XMLHTTPReques처럼 적지말고 XmlHttpRequest로 적기
  12. TODO style: "TODO: write this description"
  13. Consistency: 일관적으로 작성하기
  14. Logging: 로그도 비용이 드니 적절하기 사용하기
    ERROR > WARNING > INFORMATION > DEBUG > VERBOSE 사용할 것.
    한줄에 출력할 수 있는 80~100글자가 적당.
    StringBuilder는 기본버퍼가 16character라 String보다 항상 좋다고 할 수 없으니 확신이 없으면 그냥 String연산이 무난.
    System.out.print는 어차피 /dev/null로 던져버리니 절대 쓰지말 것. 괜히 비용만 잡아먹음.

Javatests Style Rules

  1. Naming test methods: testMethod_specificCase 이런식으로 이름짓기
저작자 표시
Posted by dyecolor 심성진 Trackback 0 : Comment 0
prev 1 2 3 4 5 ... 25 next