강원대학교 IT대학컴퓨터학부 - Kangwonysmoon/courses/2011_1/android/...UI 이벤트 Event...

52
To be an Android Expert 문양세 강원대학교 IT대학 컴퓨터학부

Transcript of 강원대학교 IT대학컴퓨터학부 - Kangwonysmoon/courses/2011_1/android/...UI 이벤트 Event...

Page 1: 강원대학교 IT대학컴퓨터학부 - Kangwonysmoon/courses/2011_1/android/...UI 이벤트 Event listener Touch mode FocushandlingFocus handling Notification Basic toast notification

To be an Android Expert

문양세강원대학교 IT대학 컴퓨터학부

Page 2: 강원대학교 IT대학컴퓨터학부 - Kangwonysmoon/courses/2011_1/android/...UI 이벤트 Event listener Touch mode FocushandlingFocus handling Notification Basic toast notification

UI 이벤 UI 이벤트◦ Event listener

◦ Touch mode

◦ Focus handling◦ Focus handling

Notification◦ Basic toast notification

◦ Customized toast notification◦ Customized toast notification

◦ Status bar notification

2

Page 3: 강원대학교 IT대학컴퓨터학부 - Kangwonysmoon/courses/2011_1/android/...UI 이벤트 Event listener Touch mode FocushandlingFocus handling Notification Basic toast notification

사용자가 인터랙션하는 특정 View 오브젝트의 이벤트를 획득하

는 방법을 제공한다는 방법을 제공한다.◦ 대표적으로 사용해 온 것이 버튼에 대한 click 처리이다.이벤트 발생 시 안드로이드는 해당 llb k th d를 호출하며 프로◦ 이벤트 발생 시, 안드로이드는 해당 callback method를 호출하며, 프로그래머는 이 callback을 override하여 사용할 수 있다.

기존 View 오브젝트에 대해서는 event listener를 사용한다 기존 View 오브젝트에 대해서는 event listener를 사용한다. Customized View 오브젝트를 만들고, 이 오브젝트에 대해서

event 처리를 하려면 event handler로 사용되는 몇몇 callbackevent 처리를 하려면, event handler로 사용되는 몇몇 callback method들을 정의하여야 한다.

3

Page 4: 강원대학교 IT대학컴퓨터학부 - Kangwonysmoon/courses/2011_1/android/...UI 이벤트 Event listener Touch mode FocushandlingFocus handling Notification Basic toast notification

Event listener는하나의 callback method를 포함하는 View 클래스 내

의 인터페이스이다의 인터페이스이다.◦ Listener의 대표적 예: OnClickListener()◦ 해당 callback: onClick()해당 ()

Callback methods◦ onClick(): View.OnClickListener에 의해 콜백 됨

◦ onLongClick(): View.OnLongClickListener에 의함

◦ onFocusChange(): View.OnFocusChangeListener에 의함

K () Vi O K Li t 에 의함◦ onKey(): View.OnKeyListener에 의함

◦ onTouch(): View.OnTouchListener에 의함

◦ onCreateContextMenu(): View.OnCreateContextMenuListener에 의함에 의

4

Page 5: 강원대학교 IT대학컴퓨터학부 - Kangwonysmoon/courses/2011_1/android/...UI 이벤트 Event listener Touch mode FocushandlingFocus handling Notification Basic toast notification

Activity UiPracticeFirstAct2를 만듦 (1/6)

5

Page 6: 강원대학교 IT대학컴퓨터학부 - Kangwonysmoon/courses/2011_1/android/...UI 이벤트 Event listener Touch mode FocushandlingFocus handling Notification Basic toast notification

새로운 Activity인 UiPracticeFirstAct2를 만듦 (2/6)act2.xml

6

Page 7: 강원대학교 IT대학컴퓨터학부 - Kangwonysmoon/courses/2011_1/android/...UI 이벤트 Event listener Touch mode FocushandlingFocus handling Notification Basic toast notification

새로운 Activity인 UiPracticeFirstAct2를 만듦 (3/6)act1.xml

strings.xml

7

Page 8: 강원대학교 IT대학컴퓨터학부 - Kangwonysmoon/courses/2011_1/android/...UI 이벤트 Event listener Touch mode FocushandlingFocus handling Notification Basic toast notification

새로운 Activity인 UiPracticeFirstAct2를 만듦 (4/6)

AndroidManifest.xml

8

Page 9: 강원대학교 IT대학컴퓨터학부 - Kangwonysmoon/courses/2011_1/android/...UI 이벤트 Event listener Touch mode FocushandlingFocus handling Notification Basic toast notification

새로운 Activity인 UiPracticeFirstAct2를 만듦 (5/6)UiPracticeFirst.java

main.xml

9strings.xml

Page 10: 강원대학교 IT대학컴퓨터학부 - Kangwonysmoon/courses/2011_1/android/...UI 이벤트 Event listener Touch mode FocushandlingFocus handling Notification Basic toast notification

새로운 Activity인 UiPracticeFirstAct2를 만듦 (6/6)

10

Page 11: 강원대학교 IT대학컴퓨터학부 - Kangwonysmoon/courses/2011_1/android/...UI 이벤트 Event listener Touch mode FocushandlingFocus handling Notification Basic toast notification

다양한 listener 등록 (1/2)UiPracticeFirstAct2 javaUiPracticeFirstAct2.java

다음 페이지 계속

11

Page 12: 강원대학교 IT대학컴퓨터학부 - Kangwonysmoon/courses/2011_1/android/...UI 이벤트 Event listener Touch mode FocushandlingFocus handling Notification Basic toast notification

다양한 listener 등록 (2/2)

UiPracticeFirstAct2.java

12

Page 13: 강원대학교 IT대학컴퓨터학부 - Kangwonysmoon/courses/2011_1/android/...UI 이벤트 Event listener Touch mode FocushandlingFocus handling Notification Basic toast notification

Listener 실행 예 (1/3)

13

Page 14: 강원대학교 IT대학컴퓨터학부 - Kangwonysmoon/courses/2011_1/android/...UI 이벤트 Event listener Touch mode FocushandlingFocus handling Notification Basic toast notification

Listener 실행 예 (2/2)

14

Page 15: 강원대학교 IT대학컴퓨터학부 - Kangwonysmoon/courses/2011_1/android/...UI 이벤트 Event listener Touch mode FocushandlingFocus handling Notification Basic toast notification

Listener 실행 예 (3/3)

15

Page 16: 강원대학교 IT대학컴퓨터학부 - Kangwonysmoon/courses/2011_1/android/...UI 이벤트 Event listener Touch mode FocushandlingFocus handling Notification Basic toast notification

UI 이벤 UI 이벤트◦ Event listener

◦ Touch mode

◦ Focus handling◦ Focus handling

Notification◦ Basic toast notification

◦ Customized toast notification◦ Customized toast notification

◦ Status bar notification

16

Page 17: 강원대학교 IT대학컴퓨터학부 - Kangwonysmoon/courses/2011_1/android/...UI 이벤트 Event listener Touch mode FocushandlingFocus handling Notification Basic toast notification

터치 기능을 지원하는 디바이스에서는 터치 모드를 지원한다. 터치 모드에 진입했을 때(사용자가 화면을 터치 했을 때)는

isFocusableInTouchMode()가 참인 View들만이 포커스 된다. 사용자가 방향키를 누르거나, 트랙볼을 스크롤하면, 언제든 해당

디바이스는 터치 모드에서 빠져나간다. 터지 모드에 있는지의 여부는 isInTouchMode()를 사용하여 파

악할 수 있다.

17

Page 18: 강원대학교 IT대학컴퓨터학부 - Kangwonysmoon/courses/2011_1/android/...UI 이벤트 Event listener Touch mode FocushandlingFocus handling Notification Basic toast notification

어떤 View가 포커스를 가질 수 있는지의 여부는 isFocusable()을사용하여 확인할 수 있다사용하여 확인할 수 있다.

View가 포커스를 가질 수 있도록/없도록 하기 위해서는

할setFocusable()을 사용할 수 있다. 포커스 제어 예제: TextView가 포커스를 갖도록 한다.◦ 해당 TextView의 XML layout에서 android:focusable을 true로 한다.◦ 특정 View(이 경우, TextView)가 포커스를 가지도록 requestFocus()를호출한다호출한다.

◦ 포커스 이벤트를 받기 위해서, 앞서 소개한 onFocusChange를 사용한다.

18

Page 19: 강원대학교 IT대학컴퓨터학부 - Kangwonysmoon/courses/2011_1/android/...UI 이벤트 Event listener Touch mode FocushandlingFocus handling Notification Basic toast notification

포커스 제어 예제: TextView가 포커스를 갖도록 함 (1/2)act2.xml

UiPracticeFirstAct2.java

19

Page 20: 강원대학교 IT대학컴퓨터학부 - Kangwonysmoon/courses/2011_1/android/...UI 이벤트 Event listener Touch mode FocushandlingFocus handling Notification Basic toast notification

포커스 제어 예제: TextView가 포커스를 갖도록 함 (2/2)

20

Page 21: 강원대학교 IT대학컴퓨터학부 - Kangwonysmoon/courses/2011_1/android/...UI 이벤트 Event listener Touch mode FocushandlingFocus handling Notification Basic toast notification

UI 이벤 UI 이벤트◦ Event listener

◦ Touch mode

◦ Focus handling◦ Focus handling

Notification◦ Basic toast notification

◦ Customized toast notification◦ Customized toast notification

◦ Status bar notification

21

Page 22: 강원대학교 IT대학컴퓨터학부 - Kangwonysmoon/courses/2011_1/android/...UI 이벤트 Event listener Touch mode FocushandlingFocus handling Notification Basic toast notification

Toast notification Toast notification◦ 사용자에게 알리고자 하는 짧은 메시지를 (잠시) 표현한다.◦ Foreground에서 수행되는 activity뿐 아니라, background에서 수행되는 serviceg g에서도 생성될 수 있다.

◦ 예제: 파일 저장 작업 과정에서, 저장이 성공했다는 것을 확인시켜 준다.

b f Status bar notification◦ 시스템의 상태 바에 아이콘을 표시하며, notification window에는 확장 메시지를

보여준다.보여준다.◦ 예제: SMS가 도착했을 때, 상태 바에 표시한다(진동, 사운드, 발광 등도 가능)

Dialog notification◦ (앞서 Dialog에서 설명한 바와 같이) 진행상태 바퀴 혹은 진행상태 바를 표시한다.

22

Page 23: 강원대학교 IT대학컴퓨터학부 - Kangwonysmoon/courses/2011_1/android/...UI 이벤트 Event listener Touch mode FocushandlingFocus handling Notification Basic toast notification

T t tifi ti Toast notification

Status bar notification Status bar notification

Dialog notificationg

23

Page 24: 강원대학교 IT대학컴퓨터학부 - Kangwonysmoon/courses/2011_1/android/...UI 이벤트 Event listener Touch mode FocushandlingFocus handling Notification Basic toast notification

UI 이벤 UI 이벤트◦ Event listener

◦ Touch mode

◦ Focus handling◦ Focus handling

Notification◦ Basic toast notification

◦ Customized toast notification◦ Customized toast notification

◦ Status bar notification

24

Page 25: 강원대학교 IT대학컴퓨터학부 - Kangwonysmoon/courses/2011_1/android/...UI 이벤트 Event listener Touch mode FocushandlingFocus handling Notification Basic toast notification

메시지 표현에 필요한 공간만 나타내고, 자동으로 나타났다

가 사라지며, 사용자 인터랙션은 허용하지 않는다.

Activity 혹은 Service로부터 toast가 생성될 수 있다.y 혹은 S 로부터 가 생성될 수 있다

생성 절차

1 k T ()를 사용하여 ifi i 을 생성한다◦ 1. makeText()를 사용하여 notification을 생성한다.

◦ 2. setGravity()를 사용하여 toast가 나타날 위치를 정한다.

◦ 3. show()를 사용하여 toast를 화면에 나타낸다.

25

Page 26: 강원대학교 IT대학컴퓨터학부 - Kangwonysmoon/courses/2011_1/android/...UI 이벤트 Event listener Touch mode FocushandlingFocus handling Notification Basic toast notification

Toast를 activate시킬 버튼을 하나 만든다.

26

Page 27: 강원대학교 IT대학컴퓨터학부 - Kangwonysmoon/courses/2011_1/android/...UI 이벤트 Event listener Touch mode FocushandlingFocus handling Notification Basic toast notification

버튼에 toast 달기 (1/2)

UiPracticeFirstAct2.java

27

Page 28: 강원대학교 IT대학컴퓨터학부 - Kangwonysmoon/courses/2011_1/android/...UI 이벤트 Event listener Touch mode FocushandlingFocus handling Notification Basic toast notification

버튼에 toast 달기 (2/2)

28

Page 29: 강원대학교 IT대학컴퓨터학부 - Kangwonysmoon/courses/2011_1/android/...UI 이벤트 Event listener Touch mode FocushandlingFocus handling Notification Basic toast notification

UI 이벤 UI 이벤트◦ Event listener

◦ Touch mode

◦ Focus handling◦ Focus handling

Notification◦ Basic toast notification

◦ Customized toast notification◦ Customized toast notification

◦ Status bar notification

29

Page 30: 강원대학교 IT대학컴퓨터학부 - Kangwonysmoon/courses/2011_1/android/...UI 이벤트 Event listener Touch mode FocushandlingFocus handling Notification Basic toast notification

Toast notification을 위한 customized layout을 생성할 수 있다. XML 파일로 layout을 설정하고, 프로그램에서 이를 inflate한다.

(inflate: 부풀리다, 채워 넣다) 생성 절차

1. Toast 모양을 정의(결정)하는 XML layout 파일을만든다만든다.

2. 프로그램에서, 해당 layout을 inflate한다.3 Layout의 View object들을 채워 넣는다3. Layout의 View object들을 채워 넣는다.4. 일반적인 방법으로 toast를 나타낸다.

30

Page 31: 강원대학교 IT대학컴퓨터학부 - Kangwonysmoon/courses/2011_1/android/...UI 이벤트 Event listener Touch mode FocushandlingFocus handling Notification Basic toast notification

Toast를 위한 XML layout 파일을 만듦

31

Page 32: 강원대학교 IT대학컴퓨터학부 - Kangwonysmoon/courses/2011_1/android/...UI 이벤트 Event listener Touch mode FocushandlingFocus handling Notification Basic toast notification

Customized toast를 activate시킬 버튼을 하나 만듦

act2.xml

strings.xmlg

32

Page 33: 강원대학교 IT대학컴퓨터학부 - Kangwonysmoon/courses/2011_1/android/...UI 이벤트 Event listener Touch mode FocushandlingFocus handling Notification Basic toast notification

Customized toast를 inflate시키고, toast를 구성하여 나타냄

33

Page 34: 강원대학교 IT대학컴퓨터학부 - Kangwonysmoon/courses/2011_1/android/...UI 이벤트 Event listener Touch mode FocushandlingFocus handling Notification Basic toast notification

Customized toast의 실행 화면

34

Page 35: 강원대학교 IT대학컴퓨터학부 - Kangwonysmoon/courses/2011_1/android/...UI 이벤트 Event listener Touch mode FocushandlingFocus handling Notification Basic toast notification

UI 이벤 UI 이벤트◦ Event listener

◦ Touch mode

◦ Focus handling◦ Focus handling

Notification◦ Basic toast notification

◦ Customized toast notification◦ Customized toast notification

◦ Status bar notification

35

Page 36: 강원대학교 IT대학컴퓨터학부 - Kangwonysmoon/courses/2011_1/android/...UI 이벤트 Event listener Touch mode FocushandlingFocus handling Notification Basic toast notification

화면 상단의 상태바에, 아이콘을 표시하고, 확장 메시지를

ifi i i d 에 추가한다notification window에 추가한다.◦ NotificationManager: 시스템 내에서 Notification을 관리한다.

N tifi ti 실제 아이콘과 메시지를 담고 있다◦ Notification: 실제 아이콘과 메시지를 담고 있다.

생성 절차

1. NotificationManager에 대한 레퍼런스를 얻는다.2. Notification을 인스턴스화 한다.3 N tifi ti 의 확장 메시지와 인텐트를 정의한다3. Notification의 확장 메시지와 인텐트를 정의한다.4. NotificationManager에게 Notification을 전달한다.

36

Page 37: 강원대학교 IT대학컴퓨터학부 - Kangwonysmoon/courses/2011_1/android/...UI 이벤트 Event listener Touch mode FocushandlingFocus handling Notification Basic toast notification

Notification을 발생시킬 버튼을 하나 만든다.

act2.xml

strings.xmlg

37

Page 38: 강원대학교 IT대학컴퓨터학부 - Kangwonysmoon/courses/2011_1/android/...UI 이벤트 Event listener Touch mode FocushandlingFocus handling Notification Basic toast notification

NotificationManager에 대한 레퍼런스를 얻고, N ifi i 을 인스턴스화 한다Notification을 인스턴스화 한다.

38

Page 39: 강원대학교 IT대학컴퓨터학부 - Kangwonysmoon/courses/2011_1/android/...UI 이벤트 Event listener Touch mode FocushandlingFocus handling Notification Basic toast notification

Notification을 만들어, NotificationManager에 전달한다.

39

Page 40: 강원대학교 IT대학컴퓨터학부 - Kangwonysmoon/courses/2011_1/android/...UI 이벤트 Event listener Touch mode FocushandlingFocus handling Notification Basic toast notification

실행 화면 (1/2)

40

Page 41: 강원대학교 IT대학컴퓨터학부 - Kangwonysmoon/courses/2011_1/android/...UI 이벤트 Event listener Touch mode FocushandlingFocus handling Notification Basic toast notification

실행 화면 (2/2)

잡아서 끌어당김

41

Page 42: 강원대학교 IT대학컴퓨터학부 - Kangwonysmoon/courses/2011_1/android/...UI 이벤트 Event listener Touch mode FocushandlingFocus handling Notification Basic toast notification

사운드(sound) 추가하기◦ Notification.defaults |= Notfication.DEFAULT_SOUND;

진동( ib ti ) 추가하기 진동(vibration) 추가하기◦ Notification.defaults |= Notfication.DEFAULT_VIBRATE;

발광 빛(flashing light) 추가하기◦ Notification.defaults |= Notfication.DEFAULT_LIGHTS;

42

Page 43: 강원대학교 IT대학컴퓨터학부 - Kangwonysmoon/courses/2011_1/android/...UI 이벤트 Event listener Touch mode FocushandlingFocus handling Notification Basic toast notification

Emulator를 새로 하나 더 만든다.를 새 하나 더 다

두 개의 emulator를 동시에 동작시킨다.

Emulator-5554에서 Emulator-5556로 문자를 보낸다.

Emulator 5556에 Notification이 생성되었는지 확인하 Emulator-5556에 Notification이 생성되었는지 확인하

고, 문자도 확인한다.

43

Page 44: 강원대학교 IT대학컴퓨터학부 - Kangwonysmoon/courses/2011_1/android/...UI 이벤트 Event listener Touch mode FocushandlingFocus handling Notification Basic toast notification

44

Page 45: 강원대학교 IT대학컴퓨터학부 - Kangwonysmoon/courses/2011_1/android/...UI 이벤트 Event listener Touch mode FocushandlingFocus handling Notification Basic toast notification

45

Page 46: 강원대학교 IT대학컴퓨터학부 - Kangwonysmoon/courses/2011_1/android/...UI 이벤트 Event listener Touch mode FocushandlingFocus handling Notification Basic toast notification

46

Page 47: 강원대학교 IT대학컴퓨터학부 - Kangwonysmoon/courses/2011_1/android/...UI 이벤트 Event listener Touch mode FocushandlingFocus handling Notification Basic toast notification

47

Page 48: 강원대학교 IT대학컴퓨터학부 - Kangwonysmoon/courses/2011_1/android/...UI 이벤트 Event listener Touch mode FocushandlingFocus handling Notification Basic toast notification

48

Page 49: 강원대학교 IT대학컴퓨터학부 - Kangwonysmoon/courses/2011_1/android/...UI 이벤트 Event listener Touch mode FocushandlingFocus handling Notification Basic toast notification

emulator-5554

emulator-5556

49

Page 50: 강원대학교 IT대학컴퓨터학부 - Kangwonysmoon/courses/2011_1/android/...UI 이벤트 Event listener Touch mode FocushandlingFocus handling Notification Basic toast notification

emulator-5554

50

Page 51: 강원대학교 IT대학컴퓨터학부 - Kangwonysmoon/courses/2011_1/android/...UI 이벤트 Event listener Touch mode FocushandlingFocus handling Notification Basic toast notification

emulator-5556

51

Page 52: 강원대학교 IT대학컴퓨터학부 - Kangwonysmoon/courses/2011_1/android/...UI 이벤트 Event listener Touch mode FocushandlingFocus handling Notification Basic toast notification

52