Slide 1

Slide 1 text

Android DroidKaigi 2019 Tomoya Miwa, Yuri Hondo

Slide 2

Slide 2 text

$# tomoya0x00 ' ( ) Kiosk " ! &%RX-8( *) Twitter : @tomoya0x00 Pokemon GO (%Lv.40): 1024 1615 6009

Slide 3

Slide 3 text

URI ( ) Android @DeNA - MOV Twitter : URI - @yuyuyuyuyuri Pokemon GO : 05URI28 - 0188 7196 1789

Slide 4

Slide 4 text

"! $ # $ $ 4 1 4 3 2

Slide 5

Slide 5 text

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

● +*. ○ -)OK ● *%&!" ○ (,* $#'

Slide 8

Slide 8 text

# ("&) $ !%/% !%$ '

Slide 9

Slide 9 text

c # $ !%/% !%$ ' ("&)

Slide 10

Slide 10 text

(Android) BLE Logger

Slide 11

Slide 11 text

Slide 12

Slide 12 text

Slide 13

Slide 13 text

Slide 14

Slide 14 text

OK

Slide 15

Slide 15 text

Slide 16

Slide 16 text

Slide 17

Slide 17 text

310

Slide 18

Slide 18 text

310

Slide 19

Slide 19 text

310

Slide 20

Slide 20 text

1000

Slide 21

Slide 21 text

Slide 22

Slide 22 text

• • •

Slide 23

Slide 23 text

• • •

Slide 24

Slide 24 text

https://dena.com/jp/press/003459

Slide 25

Slide 25 text

● 20179"2% ○ $ ● "200 #!

Slide 26

Slide 26 text

Slide 27

Slide 27 text

Slide 28

Slide 28 text

'* • !+)" • +$#(%& • • !+

Slide 29

Slide 29 text

BLE Logger BLE

Slide 30

Slide 30 text

,+, # BLE Logger )!%/%'(* $ BLE !% &% % "

Slide 31

Slide 31 text

+*+ " ( $/$&') # BT Classic ! $ %$ $

Slide 32

Slide 32 text

+. • !%!/-& • !/(',)* • # • "BLEBT Classic • !%!/$ #

Slide 33

Slide 33 text

Slide 34

Slide 34 text

• ➡ • OK • ➡ • NG •

Slide 35

Slide 35 text

Slide 36

Slide 36 text

• ➡ • OK • ➡ • • ” ➡ ”

Slide 37

Slide 37 text

# " ! ⬇

Slide 38

Slide 38 text

Slide 39

Slide 39 text

Slide 40

Slide 40 text

● ● Rx ! ○ !

Slide 41

Slide 41 text

14 • #*#53+ • #5.,2/0 • ' • &BLE LoggerBT Classic • #*#5( ' • $"!%)-

Slide 42

Slide 42 text

Slide 43

Slide 43 text

Slide 44

Slide 44 text

● ○ // / ●

Slide 45

Slide 45 text

Slide 46

Slide 46 text

Slide 47

Slide 47 text

Slide 48

Slide 48 text

Slide 49

Slide 49 text

/ → “”

Slide 50

Slide 50 text

!14 ✔%-%5 3. →' ✔#$* →)2"&( ✔%-%5+$* →' / ,0

Slide 51

Slide 51 text

Slide 52

Slide 52 text

Slide 53

Slide 53 text

Slide 54

Slide 54 text

Slide 55

Slide 55 text

https://dena.com/jp/press/004421

Slide 56

Slide 56 text

Slide 57

Slide 57 text

https://dena.com/jp/press/004421

Slide 58

Slide 58 text

+

Slide 59

Slide 59 text

MOV or

Slide 60

Slide 60 text

Before

Slide 61

Slide 61 text

After

Slide 62

Slide 62 text

Slide 63

Slide 63 text

Slide 64

Slide 64 text

Slide 65

Slide 65 text

"!

Slide 66

Slide 66 text

Slide 67

Slide 67 text

Slide 68

Slide 68 text

● Singleton & mutableclass ● ●

Slide 69

Slide 69 text

!

Slide 70

Slide 70 text

MOV

Slide 71

Slide 71 text

( )

Slide 72

Slide 72 text

('* - - % !& - ,#+$)"& - & '*

Slide 73

Slide 73 text

Slide 74

Slide 74 text

" ● ● $# ! ●

Slide 75

Slide 75 text

" ● ● $# ! ●

Slide 76

Slide 76 text

!

Slide 77

Slide 77 text

No content

Slide 78

Slide 78 text

No content

Slide 79

Slide 79 text

Slide 80

Slide 80 text

No content

Slide 81

Slide 81 text

No content

Slide 82

Slide 82 text

No content

Slide 83

Slide 83 text

LED

Slide 84

Slide 84 text

stateMachine(initial = NOT_LOANED) { state(NOT_LOANED) { edge(LOCK) } state(ON_LOAN, entry = { /* LED ON */ }, exit = { /* LED OFF */ }) { state(LOCK) { edge(UNLOCK) edge(NOT_LOANED, guard = { it.isLongPress }) } state(UNLOCK) { edge(LOCK, guard = { !it.isLongPress }) } } }

Slide 85

Slide 85 text

stateMachine(initial = NOT_LOANED) { state(NOT_LOANED) { edge(LOCK) } state(ON_LOAN, entry = { /* LED ON */ }, exit = { /* LED OFF */ }) { state(LOCK) { edge(UNLOCK) edge(NOT_LOANED, guard = { it.isLongPress }) } state(UNLOCK) { edge(LOCK, guard = { !it.isLongPress }) } } }

Slide 86

Slide 86 text

stateMachine(initial = NOT_LOANED) { state(NOT_LOANED) { edge(LOCK) } state(ON_LOAN, entry = { /* LED ON */ }, exit = { /* LED OFF */ }) { state(LOCK) { edge(UNLOCK) edge(NOT_LOANED, guard = { it.isLongPress }) } state(UNLOCK) { edge(LOCK, guard = { !it.isLongPress }) } } }

Slide 87

Slide 87 text

stateMachine(initial = NOT_LOANED) { state(NOT_LOANED) { edge(LOCK) } state(ON_LOAN, entry = { /* LED ON */ }, exit = { /* LED OFF */ }) { state(LOCK) { edge(UNLOCK) edge(NOT_LOANED, guard = { it.isLongPress }) } state(UNLOCK) { edge(LOCK, guard = { !it.isLongPress }) } } }

Slide 88

Slide 88 text

stateMachine(initial = NOT_LOANED) { state(NOT_LOANED) { edge(LOCK) } state(ON_LOAN, entry = { /* LED ON */ }, exit = { /* LED OFF */ }) { state(LOCK) { edge(UNLOCK) edge(NOT_LOANED, guard = { it.isLongPress }) } state(UNLOCK) { edge(LOCK, guard = { !it.isLongPress }) } } } ✌

Slide 89

Slide 89 text

" ● ● $# ! ●

Slide 90

Slide 90 text

Slide 91

Slide 91 text

Slide 92

Slide 92 text

Slide 93

Slide 93 text

Tablet Phone Maps API A B

Slide 94

Slide 94 text

Tablet Phone Maps API

Slide 95

Slide 95 text

Tablet Phone Maps API

Slide 96

Slide 96 text

Tablet Phone Maps API UI

Slide 97

Slide 97 text

UI

Slide 98

Slide 98 text

Tablet Phone Maps API A B

Slide 99

Slide 99 text

Tablet( )0 ! '* .% &+ Maps API .% Phone( )0 ! /-&+ "".% "".% A B &+" $ # ,

Slide 100

Slide 100 text

(&$ ' ' Maps API ' # ' $ Tablet! ") Phone! ") A B UI %

Slide 101

Slide 101 text

" ● ● $# ! ●

Slide 102

Slide 102 text

Slide 103

Slide 103 text

! '" - $ - #&( % '" )

Slide 104

Slide 104 text

...

Slide 105

Slide 105 text

Slide 106

Slide 106 text

,'! 3. 8(1 1 UI(/2)5# !0" 2 &76+%$ -4 )*

Slide 107

Slide 107 text

Logic / Data UI / External 1 UI(#%)' $ 2 ) (! "&

Slide 108

Slide 108 text

Logic / Data UI / External ! ! 1 UI(!#)% " 2 ' & $

Slide 109

Slide 109 text

Logic / Data UI / External ! GUI ! Sytem 1 2

Slide 110

Slide 110 text

GUI System MVP MVVM Flux Redux MVI Hexagonal Onion Clean

Slide 111

Slide 111 text

!

Slide 112

Slide 112 text

MVP GUI MVI Redux MVVM Flux

Slide 113

Slide 113 text

GUI" Flux vs MVVM • View !%7 3.MVVM*1 • Flux"-#*'1 • ActionStore4&+/,0)( "-26$5

Slide 114

Slide 114 text

System Hexagonal Onion Clean

Slide 115

Slide 115 text

System( % Onion( % vs Clean( % • />=2!$',? 5< #*-4 • 0;7."&(6:Clean ⊃ Onion719 • Onion3+)7817$( !

Slide 116

Slide 116 text

.6 (# • Flux →'"%(4+ →38 &'! • Onion(# →)19*,:5;20 →/&$(7-

Slide 117

Slide 117 text

Slide 118

Slide 118 text

Slide 119

Slide 119 text

- UI

Slide 120

Slide 120 text

- UI View

Slide 121

Slide 121 text

- external

Slide 122

Slide 122 text

- external

Slide 123

Slide 123 text

- infrastructure

Slide 124

Slide 124 text

- infrastructure API DataBase

Slide 125

Slide 125 text

- service

Slide 126

Slide 126 text

- service

Slide 127

Slide 127 text

- model

Slide 128

Slide 128 text

- model UIService Action

Slide 129

Slide 129 text

View Action Dispatcer Store Flux

Slide 130

Slide 130 text

Infra Service Model UI External

Slide 131

Slide 131 text

Slide 132

Slide 132 text

StateMachine Dispatcher Action

Slide 133

Slide 133 text

View IF Event ServiceIF ActionDispatcherStateMachine Flux

Slide 134

Slide 134 text

Slide 135

Slide 135 text

① UI

Slide 136

Slide 136 text

① 1. 1.

Slide 137

Slide 137 text

1.

Slide 138

Slide 138 text

A

Slide 139

Slide 139 text

State ↓ State

Slide 140

Slide 140 text

Slide 141

Slide 141 text

State focus = SELF

Slide 142

Slide 142 text

SELF

Slide 143

Slide 143 text

310 2.

Slide 144

Slide 144 text

Slide 145

Slide 145 text

② 1. 1.

Slide 146

Slide 146 text

’ . B IF

Slide 147

Slide 147 text

StateMachine new 2.

Slide 148

Slide 148 text

...!

Slide 149

Slide 149 text

...

Slide 150

Slide 150 text

Slide 151

Slide 151 text

Core Sub StateMachine Sub Event Event StateMachine

Slide 152

Slide 152 text

Slide 153

Slide 153 text

No content

Slide 154

Slide 154 text

1.

Slide 155

Slide 155 text

No content

Slide 156

Slide 156 text

Device (TaxiMeter) interface TaxiMeter { val status: Observable } EventHandler private val sm: StateMachine by lazy {...} init { meter.status.subscribe { handle(MapEvent.ChangeMeterStatus(it)) }.addTo(disposable) } fun handle(event: MapEvent) { sm.dispatch(event) }

Slide 157

Slide 157 text

Device (TaxiMeter) interface TaxiMeter { val status: Observable } private val sm: StateMachine by lazy {...} init { meter.status.subscribe { handle(MapEvent.ChangeMeterStatus(it)) }.addTo(disposable) } fun handle(event: MapEvent) { sm.dispatch(event) } EventHandler Event#handle

Slide 158

Slide 158 text

Device (TaxiMeter) interface TaxiMeter { val status: Observable } EventHandler private val sm: StateMachine by lazy {...} init { meter.status.subscribe { handle(MapEvent.ChangeMeterStatus(it)) }.addTo(disposable) } fun handle(event: MapEvent) { sm.dispatch(event) }

Slide 159

Slide 159 text

No content

Slide 160

Slide 160 text

stateMachine(initial = PickupState.ON_ACCEPT) { state(PickupState.ON_ACCEPT) { edge( next = PickupState.ON_PICKING ) } state(PickupState.ON_PICKING, entry = { dispatcher.dispatch(MapAction.ChangeCameraFocus(MapAction.Focus.SELF)) launch { repository.command(ChangeTaxiBusinessStatus.PICK_UP) } } ) { edge { dispatcher.dispatch(TaxiAction.ArrivePickupArea) } } } StateMachine

Slide 161

Slide 161 text

stateMachine(initial = PickupState.ON_ACCEPT) { state(PickupState.ON_ACCEPT) { edge( next = PickupState.ON_PICKING ) } state(PickupState.ON_PICKING, entry = { dispatcher.dispatch(MapAction.ChangeCameraFocus(MapAction.Focus.SELF)) launch { repository.command(ChangeTaxiBusinessStatus.PICK_UP) } } ) { edge { dispatcher.dispatch(TaxiAction.ArrivePickupArea) } } } StateMachine Event State

Slide 162

Slide 162 text

stateMachine(initial = PickupState.ON_ACCEPT) { state(PickupState.ON_ACCEPT) { edge( next = PickupState.ON_PICKING ) } state(PickupState.ON_PICKING, entry = { launch { repository.command(ChangeTaxiBusinessStatus.PICK_UP) dispatcher.dispatch(MapAction.ChangeCameraFocus(MapAction.Focus.SELF)) } } ) { edge { dispatcher.dispatch(TaxiAction.ArrivePickupArea) } } } StateMachine Repository Action Dispatcher

Slide 163

Slide 163 text

No content

Slide 164

Slide 164 text

Dispatcher private val subject = PublishSubject.create().toSerialized() fun dispatch(action: Action) { subject.onNext(action) } fun on(clazz: Class): Observable = subject.ofType(clazz) .observeOn(AndroidSchedulers.mainThread()) .hide() Store val focusObservable: Observable = dispatcher.on(MapAction.ChangeCameraFocus::class. java ) .scan(Focus.UNKNOWN) { _, action -> when (action.focus) { MapAction.Focus.SELF -> Focus.SELF else -> Focus.DESTINATION } }

Slide 165

Slide 165 text

Dispatcher private val subject = PublishSubject.create().toSerialized() fun dispatch(action: Action) { subject.onNext(action) } fun on(clazz: Class): Observable = subject.ofType(clazz) .observeOn(AndroidSchedulers.mainThread()) .hide() Store val focusObservable: Observable = dispatcher.on(MapAction.ChangeCameraFocus::class. java ) .scan(Focus.UNKNOWN) { _, action -> when (action.focus) { MapAction.Focus.SELF -> Focus.SELF else -> Focus.DESTINATION } } #dispatch Action subject

Slide 166

Slide 166 text

Dispatcher private val subject = PublishSubject.create().toSerialized() fun dispatch(action: Action) { subject.onNext(action) } fun on(clazz: Class): Observable = subject.ofType(clazz) .observeOn(AndroidSchedulers.mainThread()) .hide() Store val focusObservable: Observable = dispatcher.on(MapAction.ChangeCameraFocus::class. java ) .scan(Focus.UNKNOWN) { _, action -> when (action.focus) { MapAction.Focus.SELF -> Focus.SELF else -> Focus.DESTINATION } } Store Action

Slide 167

Slide 167 text

No content

Slide 168

Slide 168 text

UI // For example store.focusObservable.toLiveData() // .observe(this, Observer { moveCameraToDriver() }) private fun moveCameraToDriver() { ownPosition.value?.let { val latlng = LatLng(it.location.latitude, it.location.longitude) val cameraPosition = CameraPosition(latlng, ZOOM_LEVEL_DEFAULT, TILT, 0f) val update = CameraUpdateFactory.newCameraPosition(cameraPosition) map.moveCamera(update) } }

Slide 169

Slide 169 text

UI // For example store.focusObservable.toLiveData() // .observe(this, Observer { moveCameraToDriver() }) private fun moveCameraToDriver() { ownPosition.value?.let { val latlng = LatLng(it.location.latitude, it.location.longitude) val cameraPosition = CameraPosition(latlng, ZOOM_LEVEL_DEFAULT, TILT, 0f) val update = CameraUpdateFactory.newCameraPosition(cameraPosition) map.moveCamera(update) } } LiveData

Slide 170

Slide 170 text

310 2.

Slide 171

Slide 171 text

!

Slide 172

Slide 172 text

Slide 173

Slide 173 text

- "#,8 ); :.(& /9 $ - #!13-% *70 6<3-4' +5 2

Slide 174

Slide 174 text

!

Slide 175

Slide 175 text