Top Banner
AndroidAnnotations Enhanced components 작작작 – 작작작 작작 작작작 : 151202
19

Jurano강의 lec3 android_annotations_enhanced_components

Apr 15, 2017

Download

Software

Ju-ri Seo
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Jurano강의 lec3 android_annotations_enhanced_components

AndroidAnnotationsEnhanced components

작성자 – 김태희 최종 수정일 : 151202

Page 2: Jurano강의 lec3 android_annotations_enhanced_components

Enhanced components

Enhanced components 는 안드로이드의 기본 컴포넌트들을

쉽고 빠르게 사용할 수 있도록 해 줍니다 .

Page 3: Jurano강의 lec3 android_annotations_enhanced_components

Enhanced components

구성@EActivity@EApplication@EBean@EFragment@EProvider@EReceiver@EIntentService@EService@EView@EViewGroup

Page 4: Jurano강의 lec3 android_annotations_enhanced_components

Enhanced components

구성@EActivity@EApplication@EBean@EFragment@EProvider@EReceiver@EIntentService@EService@EView@EViewGroup

본 강에서는 이 중 가장 가주 사용되는 컴포넌트 몇 가지를 활용한 예제 어플리케이션을 통해 사용법을 익혀보도록 합니다 .

Page 5: Jurano강의 lec3 android_annotations_enhanced_components

@EActivity@EActivity annotation 을 이용하여 왼쪽과 같은 기본적인 액티비티를 만들어 봅시다 !

그 전에 , 1 강의 안내에 따라 빌드 환경 세팅을 해 주셔야 하는 것 기억하시죠 ?

Page 6: Jurano강의 lec3 android_annotations_enhanced_components

LinearLayout 을 베이스로 한 레이아웃 xml 을 구성하였습니다 .

Page 7: Jurano강의 lec3 android_annotations_enhanced_components

이번에는 Java 소스 코드입니다 .일반적인 경우라면 MainActivity 라고 이름을 지었겠지만 , AndroidAnnotations를 사용하는 Activity 임을 명시하기 위해 앞에 AA 라는 접두어를 붙여 보았습니다 .

Page 8: Jurano강의 lec3 android_annotations_enhanced_components

Manifest 파일입니다 .

블록 쳐진 부분의 _ 에 유의하여야 합니다 !AAMainActivity 가 아니라 AAMainActivity_입니다 !나머지 부분은 동일합니다 .

Page 9: Jurano강의 lec3 android_annotations_enhanced_components

빌드를 해볼까요 ?

왼쪽과 같은 Activity 가 정상적으로 Main 으로 설정되어 화면에 출력되는 것을 볼 수 있습니다 . 와 신난다 ~

Page 10: Jurano강의 lec3 android_annotations_enhanced_components

여기서의 질문 , setContentView() 가 없는데 레이아웃이 어떻게 출력되나요 ?

Page 11: Jurano강의 lec3 android_annotations_enhanced_components

여기서의 질문 , setContentView() 가 없는데 레이아웃이 어떻게 출력되나요 ?

빌드를 하면 annotation processor 가 AAMainActivity_ 를 생성하게 됩니다 .

생성되는 위치는 왼쪽의 프로젝트의 구조와 같습니다 .

Page 12: Jurano강의 lec3 android_annotations_enhanced_components

우리는 onCreate() 를 정의하지 않았지마는 , AA 는 onCreate() 를 정의하였습니다 .

이러한 상속 구조를 활용하여 onCreate() 에서의 setContentView() 를 비롯한 기본적인 Activity 의 구성요소들을 활용할 수 있게 됩니다 !

Page 13: Jurano강의 lec3 android_annotations_enhanced_components

Sample Application

AAMainActivityBroadcastRecei

ver

AAServiceBroadcastRecei

ver

이를 활용하여 AAMainActivity 에서 Button 을 눌러 Service 와 Broadcast 로 통신하는 어플리케이션을 만들어 보겠습니다 .Full 코드는 아래의 링크에 있습니다 .https://github.com/JuranoSaurus/EnhancedComponentsSample

Page 14: Jurano강의 lec3 android_annotations_enhanced_components

Structure

프로젝트의 구조는 다음과 같습니다 .

Page 15: Jurano강의 lec3 android_annotations_enhanced_components

AAMainActivity완성된 코드입니다 .

onCreate() 에서 startService() 로 서비스 시작을 요청하고 ,

@Receiver 를 통해 해당 action 이 들어오는지 Broadcast 에 대한 대기를 하고 있으며 ,

@Click 을 통해 sendBroadcast() 를 수행할 준비를 하고 있습니다 .

특이점은 BroadcastReceiver 를 사용하는 것으로 보임에도 불구하고 registerReceiver(), unregisterReceiver() 의 호출이 없습니다 .

Page 16: Jurano강의 lec3 android_annotations_enhanced_components

AAService완성된 코드입니다 .

앞의 Activity 와 마찬가지로 @Receiver 를 통해 해당 action이 들어오는지 Broadcast 에 대한 대기를 하고 있으며 ,

Broadcast 를 받는 경우 다시 Activity 로 Broadcast 를 보내게 됩니다 .

마찬가지로 Receiver 에 대한 등록과 해제는 따로 명시해 주지 않습니다 .

Page 17: Jurano강의 lec3 android_annotations_enhanced_components

Layout & Manifest

activity_main.xml 과 AndroidManifest.xml 입니다 .

레이아웃 파일은 앞에서 소개한 activity_main.xml 과 완전히 동일합니다 .

Activity 과 마찬가지로 Service 도 맨 뒤에 생성된 Service(_ 가 붙은 ) 를 명시해 주어야 한다는 것을 다시 한 번 강조합니다 . ( 자주 실수해요 .. ㅠㅠ )

Page 18: Jurano강의 lec3 android_annotations_enhanced_components

버튼을 누르면 , 정상적으로 서비스와 통신하여 토스트가 뜨는 것을 확인할 수 있습니다 ^_^

Page 19: Jurano강의 lec3 android_annotations_enhanced_components

Thank you