Slide 1

Slide 1 text

DroidKaigi 2020 Sato Shun GitHub: satoshun Twitter: @stsn_jp CyberAgent, Inc. System UIΛίϯτϩʔϧͯ͠ɺ ը໘Λ࠷େݶʹੜ͔ͨ͠ΞϓϦΛߏங͢Δ

Slide 2

Slide 2 text

͜ͷൃදͷલఏ • API 21Ҏ߱Λ૝ఆ͍ͯ͠·͢ • ͜ͷൃදͰ͸ɺAPI 21͕API 1ʹͳΓ·͢

Slide 3

Slide 3 text

• Edge to Edgeͱ͸? • Edge to EdgeΛͳͥ΍Δ͔? • Edge to EdgeΛͲͷΑ͏ʹ΍Δ͔ʁ • ΧελϜView͔ΒֶͿ • ଞͷΞϓϦ͔ΒֶͿ

Slide 4

Slide 4 text

Edge to Edgeͱ͸?

Slide 5

Slide 5 text

• ը໘શମΛίϯςϯπྖҬʹ • System UIͷഎޙʹίϯςϯπ Λඳը https://medium.com/androiddevelopers/gesture-navigation-going-edge-to-edge-812f62e4e83e

Slide 6

Slide 6 text

Edge to EdgeΛͳͥ΍Δ͔?

Slide 7

Slide 7 text

Edge to EdgeΛͳͥ΍Δ͔? • ը໘શମΛ࢖͏͜ͱͰɺΑΓ຅ೖײͷ͋ΔΞϓϦΛߏஙͰ͖ Δ • AndroidϓϥοτϑΥʔϜશମͷྲྀΕ • API 29(Q)Ҏ߱Ͱ͸ɺڧ͘નΊ͍ͯΔ

Slide 8

Slide 8 text

Edge to EdgeΛͲͷΑ͏ʹ΍Δ͔

Slide 9

Slide 9 text

Edge to EdgeΛͲͷΑ͏ʹ΍Δ͔ • SystemUiVisibility • System UIͷഎܠ৭ • fitsSystemWindows • WindowInsets

Slide 10

Slide 10 text

SystemUiVisibility ͱ͸? • System UIʢstatus bar / navigation barʣͷݟͨ໨ɺৼΔ෣͍ Λมߋ͢Δ

Slide 11

Slide 11 text

SystemUiVisibility ͱ͸? • System UIʢstatus bar / navigation barʣͷݟͨ໨ɺৼΔ෣͍ Λมߋ͢Δ • Immersive modeʢ຅ೖϞʔυʣ

Slide 12

Slide 12 text

SystemUiVisibility ͱ͸? • System UIʢstatus bar / navigation barʣͷݟͨ໨ɺৼΔ෣͍ Λมߋ͢Δ • Immersive modeʢ຅ೖϞʔυʣ

Slide 13

Slide 13 text

SystemUiVisibility ͱ͸? • System UIʢstatus bar / navigation barʣͷݟͨ໨ɺৼΔ෣͍ Λมߋ͢Δ • Immersive modeʢ຅ೖϞʔυʣ

Slide 14

Slide 14 text

SystemUiVisibility ͱ͸? • System UIʢstatus bar / navigation barʣͷݟͨ໨ɺৼΔ෣͍ Λมߋ͢Δ • Immersive modeʢ຅ೖϞʔυʣ • status bar / navigation barͷഎޙʹඳը

Slide 15

Slide 15 text

SystemUiVisibility ͱ͸? • System UIʢstatus bar / navigation barʣͷݟͨ໨ɺৼΔ෣͍ Λมߋ͢Δ • Immersive modeʢ຅ೖϞʔυʣ • status bar / navigation barͷഎޙʹඳը

Slide 16

Slide 16 text

status bar navigation bar

Slide 17

Slide 17 text

Slide 18

Slide 18 text

Slide 19

Slide 19 text

Slide 20

Slide 20 text

γεςϜ͕ViewΛ ૠೖ͢Δ

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

paddingTopɺmarginBottom͕ ηοτ͞Ε͍ͯΔ

Slide 26

Slide 26 text

paddingTopɺmarginBottom͕ ηοτ͞Ε͍ͯΔ

Slide 27

Slide 27 text

paddingTopɺmarginBottom͕ ηοτ͞Ε͍ͯΔ -> ίϯςϯπΛඳը͢Δ͜ͱ͸ग़དྷͳ͍

Slide 28

Slide 28 text

paddingTopɺmarginBottom͕ ηοτ͞Ε͍ͯΔ -> ίϯςϯπΛඳը͢Δ͜ͱ͸ग़དྷͳ͍ ͜ͷpaddingTopɺmarginBottomͷ஋Λ ্ॻ͖͢Δඞཁ͕͋Δ

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

view.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN

Slide 31

Slide 31 text

view.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN

Slide 32

Slide 32 text

view.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN

Slide 33

Slide 33 text

view.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN

Slide 34

Slide 34 text

view.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN

Slide 35

Slide 35 text

view.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN

Slide 36

Slide 36 text

view.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION

Slide 37

Slide 37 text

view.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION

Slide 38

Slide 38 text

view.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION

Slide 39

Slide 39 text

view.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION

Slide 40

Slide 40 text

view.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION

Slide 41

Slide 41 text

view.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

view.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION

Slide 45

Slide 45 text

SystemUiVisibility·ͱΊ • SYSTEM_UI_FLAG_LAYOUT_FULLSCREENɺ SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION • 2ͭΛ૊Έ߹ΘͤΔ͜ͱͰɺmarginɺpaddingΛ0ʹઃఆ͢Δ͜ͱ ͕ग़དྷΔ • ίϯςϯπΛSystem UIͷഎޙʹඳը͢Δ͜ͱ͕ग़དྷΔ • SYSTEM_UI_FLAG_LAYOUT_STABLE΋෇͚ͨ΄͏͕ྑ͍ • ৄ͘͠͸ɺDroidKaigi2020 ৄղ WindowInsetsΛݟ͍ͯͩ͘͞

Slide 46

Slide 46 text

System UIͷഎܠ৭

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

window.statusBarColor = … #B3FFFFFF

Slide 50

Slide 50 text

window.statusBarColor = … #B3FFFFFF

Slide 51

Slide 51 text

No content

Slide 52

Slide 52 text

view.systemUiVisibility = ... View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR true

Slide 53

Slide 53 text

view.systemUiVisibility = ... View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR true

Slide 54

Slide 54 text

API23+ view.systemUiVisibility = ... View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR true

Slide 55

Slide 55 text

API23+ API23ະຬͰ͸ɺ Lightʢ໌Δ͍ʣ৭Λstatus barͷ എܠ৭ʹऔΔͱࢹೝੑ͕ஶ͘͠ ௿Լ͢Δ͜ͱΛҙຯ͢Δ view.systemUiVisibility = ... View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR true

Slide 56

Slide 56 text

No content

Slide 57

Slide 57 text

No content

Slide 58

Slide 58 text

window.navigationBarColor = … #B3FFFFFF

Slide 59

Slide 59 text

window.navigationBarColor = … #B3FFFFFF

Slide 60

Slide 60 text

No content

Slide 61

Slide 61 text

view.systemUiVisibility = ... View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR true

Slide 62

Slide 62 text

view.systemUiVisibility = ... View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR true

Slide 63

Slide 63 text

API27+ view.systemUiVisibility = ... View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR true

Slide 64

Slide 64 text

API27+ API27ະຬͰ͸ɺ Lightʢ໌Δ͍ʣ৭Λnavigationͷ എܠ৭ʹऔΔͱࢹೝੑ͕ஶ͘͠ ௿Լ͢Δ͜ͱΛҙຯ͢Δ view.systemUiVisibility = ... View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR true

Slide 65

Slide 65 text

No content

Slide 66

Slide 66 text

transparent

Slide 67

Slide 67 text

transparent

Slide 68

Slide 68 text

API29+͔ΒtransparentΛ ࢦఆͨ͠৔߹ʹɺ ࣗಈతʹഎܠ৭Λઃఆͯ͘͠ΕΔ Α͏ʹͳͬͨ transparent

Slide 69

Slide 69 text

API29+͔ΒtransparentΛ ࢦఆͨ͠৔߹ʹɺ ࣗಈతʹഎܠ৭Λઃఆͯ͘͠ΕΔ Α͏ʹͳͬͨ transparent false false

Slide 70

Slide 70 text

transparent API29+͔ΒtransparentΛ ࢦఆͨ͠৔߹ʹɺ ࣗಈతʹഎܠ৭Λઃఆͯ͘͠ΕΔ Α͏ʹͳͬͨ false false

Slide 71

Slide 71 text

System UIഎܠ৭ͷ·ͱΊ • API23+: windowLightStatusBarͷ௥Ճ • API27+: windowLightNavigationBarͷ௥Ճ • API29+: enforceNavigationBarContrastɺ enforceStatusBarContrastͷ௥Ճ • transparentͷͱ͖ɺ͍͍ײ͡ʹഎܠ৭Λௐ੔ͯ͘͠ΕΔ

Slide 72

Slide 72 text

fitsSystemWindows

Slide 73

Slide 73 text

fitsSystemWindowsͱ͸? • System UIΛߟྀͯ͠ɺΞϓϦέʔγϣϯίϯςϯπΛ഑ஔͯ͠ ͘ΕΔ • σϑΥϧτͷಈ࡞ͱɺΧελϚΠζͨ͠ಈ࡞͕͋Δ • ೉͍͠ଐੑͷ1ͭʢݸਓతͳײ૝ʣ

Slide 74

Slide 74 text

No content

Slide 75

Slide 75 text

Slide 76

Slide 76 text

view.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION

Slide 77

Slide 77 text

view.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION

Slide 78

Slide 78 text

view.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION ্෦ɺԼ෦ͷmarginɺpadding͕θϩʹͳΔͷͰɺ ཁૉ͕ΊΓࠐΜͰ͠·͏

Slide 79

Slide 79 text

Slide 80

Slide 80 text

Slide 81

Slide 81 text

Slide 82

Slide 82 text

Slide 83

Slide 83 text

Slide 84

Slide 84 text

fitsSystemWindows͸ɺ paddingTopɺpaddingBottomΛઃఆ͢Δ

Slide 85

Slide 85 text

Slide 86

Slide 86 text

Slide 87

Slide 87 text

Slide 88

Slide 88 text

͜ͷfitsSystemWindows͸ແࢹ͞ΕΔ

Slide 89

Slide 89 text

͜ͷfitsSystemWindows͸ແࢹ͞ΕΔ fitsSystemWindows͸σϑΥϧτͰɺ ਂ͞༏ઌ୳ࡧΛ͠ɺݟ͔ͭͬͨ࠷ॳͷΈ༗ޮ

Slide 90

Slide 90 text

͜ͷfitsSystemWindows͸ແࢹ͞ΕΔ fitsSystemWindows͸σϑΥϧτͰɺ ਂ͞༏ઌ୳ࡧΛ͠ɺݟ͔ͭͬͨ࠷ॳͷΈ༗ޮ View View View View View

Slide 91

Slide 91 text

͜ͷfitsSystemWindows͸ແࢹ͞ΕΔ fitsSystemWindows͸σϑΥϧτͰɺ ਂ͞༏ઌ୳ࡧΛ͠ɺݟ͔ͭͬͨ࠷ॳͷΈ༗ޮ View View View View View

Slide 92

Slide 92 text

͜ͷfitsSystemWindows͸ແࢹ͞ΕΔ fitsSystemWindows͸σϑΥϧτͰɺ ਂ͞༏ઌ୳ࡧΛ͠ɺݟ͔ͭͬͨ࠷ॳͷΈ༗ޮ View View View View View

Slide 93

Slide 93 text

͜ͷfitsSystemWindows͸ແࢹ͞ΕΔ fitsSystemWindows͸σϑΥϧτͰɺ ਂ͞༏ઌ୳ࡧΛ͠ɺݟ͔ͭͬͨ࠷ॳͷΈ༗ޮ View View View View View

Slide 94

Slide 94 text

͜ͷfitsSystemWindows͸ແࢹ͞ΕΔ fitsSystemWindows͸σϑΥϧτͰɺ ਂ͞༏ઌ୳ࡧΛ͠ɺݟ͔ͭͬͨ࠷ॳͷΈ༗ޮ View View View View View

Slide 95

Slide 95 text

͜ͷfitsSystemWindows͸ແࢹ͞ΕΔ fitsSystemWindows͸σϑΥϧτͰɺ ਂ͞༏ઌ୳ࡧΛ͠ɺݟ͔ͭͬͨ࠷ॳͷΈ༗ޮ View View View View View

Slide 96

Slide 96 text

͜ͷfitsSystemWindows͸ແࢹ͞ΕΔ fitsSystemWindows͸σϑΥϧτͰɺ ਂ͞༏ઌ୳ࡧΛ͠ɺݟ͔ͭͬͨ࠷ॳͷΈ༗ޮ

Slide 97

Slide 97 text

fitsSystemWindows͸σϑΥϧτͰɺ ਂ͞༏ઌ୳ࡧΛ͠ɺݟ͔ͭͬͨ࠷ॳͷΈ༗ޮ ͜ͷfitsSystemWindows͸ແࢹ͞ΕΔ

Slide 98

Slide 98 text

fitsSystemWindows·ͱΊ • σϑΥϧτͷڍಈ • System UIʹඃΒͳ͍Α͏ʹɺpaddingTopɺpaddingBottomΛ ઃఆ͢Δ • ਂ͞༏ઌ୳ࡧͰݟ͔ͭͬͨɺ࠷ॳͷViewͷΈ༗ޮʹͳΔ ΋ͬͱॊೈʹ࢖͍͍ͨཁٻ

Slide 99

Slide 99 text

WindowInsets

Slide 100

Slide 100 text

WindowInsetsͱ͸? • System UIͷ෯ɺ઎ΊΔྖҬ • WindowInsetsΛ࢖͏͜ͱͰɺfitsSystemWindowsΛΑΓॊೈ ʹΧελϚΠζͯ͠࢖͏͜ͱ͕ग़དྷΔ

Slide 101

Slide 101 text

No content

Slide 102

Slide 102 text

view.setOnApplyWindowInsetsListener { v, insets -> insets }

Slide 103

Slide 103 text

view.setOnApplyWindowInsetsListener { v, insets -> v.updatePadding( top = insets.systemWindowInsetTop, bottom = insets.systemWindowInsetBottom ) insets }

Slide 104

Slide 104 text

view.setOnApplyWindowInsetsListener { v, insets -> v.updatePadding( top = insets.systemWindowInsetTop, bottom = insets.systemWindowInsetBottom ) insets }

Slide 105

Slide 105 text

view.setOnApplyWindowInsetsListener { v, insets -> v.updatePadding( top = insets.systemWindowInsetTop, bottom = insets.systemWindowInsetBottom ) insets }

Slide 106

Slide 106 text

view.setOnApplyWindowInsetsListener { v, insets -> v.updatePadding( top = insets.systemWindowInsetTop, bottom = insets.systemWindowInsetBottom ) insets } class WindowInsets { Insets getSystemWindowInsets() Insets getStableInsets() Insets getSystemGestureInsets() Insets getMandatorySystemGestureInsets() Insets getTappableElementInsets() DisplayCutout getDisplayCutout() }

Slide 107

Slide 107 text

view.setOnApplyWindowInsetsListener { v, insets -> v.updatePadding( top = insets.systemWindowInsetTop, bottom = insets.systemWindowInsetBottom ) insets }

Slide 108

Slide 108 text

view.setOnApplyWindowInsetsListener { v, insets -> v.updatePadding( top = insets.systemWindowInsetTop, bottom = insets.systemWindowInsetBottom ) insets } child.setOnApplyWindowInsetsListener { v, insets -> v.updatePadding( top = insets.systemWindowInsetTop, bottom = insets.systemWindowInsetBottom ) insets }

Slide 109

Slide 109 text

view.setOnApplyWindowInsetsListener { v, insets -> v.updatePadding( top = insets.systemWindowInsetTop, bottom = insets.systemWindowInsetBottom ) insets } child.setOnApplyWindowInsetsListener { v, insets -> v.updatePadding( top = insets.systemWindowInsetTop, bottom = insets.systemWindowInsetBottom ) insets }

Slide 110

Slide 110 text

view.setOnApplyWindowInsetsListener { v, insets -> v.updatePadding( top = insets.systemWindowInsetTop, bottom = insets.systemWindowInsetBottom ) insets.consumeSystemWindowInsets() } child.setOnApplyWindowInsetsListener { v, insets -> v.updatePadding( top = insets.systemWindowInsetTop, bottom = insets.systemWindowInsetBottom ) insets }

Slide 111

Slide 111 text

view.setOnApplyWindowInsetsListener { v, insets -> v.updatePadding( top = insets.systemWindowInsetTop, bottom = insets.systemWindowInsetBottom ) insets.consumeSystemWindowInsets() } child.setOnApplyWindowInsetsListener { v, insets -> v.updatePadding( top = insets.systemWindowInsetTop, bottom = insets.systemWindowInsetBottom ) insets }

Slide 112

Slide 112 text

view.setOnApplyWindowInsetsListener { v, insets -> v.updatePadding( top = insets.systemWindowInsetTop, bottom = insets.systemWindowInsetBottom ) insets.consumeSystemWindowInsets() } child.setOnApplyWindowInsetsListener { v, insets -> v.updatePadding( top = insets.systemWindowInsetTop, bottom = insets.systemWindowInsetBottom ) insets }

Slide 113

Slide 113 text

public WindowInsets dispatchApplyWindowInsets(WindowInsets insets) { try { mPrivateFlags3 |= PFLAG3_APPLYING_INSETS; if (mListenerInfo != null && mListenerInfo.mOnApplyWindowInsetsListener != null) { return mListenerInfo.mOnApplyWindowInsetsListener.onApplyWindowInsets(this, insets); } else { return onApplyWindowInsets(insets); } } finally { mPrivateFlags3 &= ~PFLAG3_APPLYING_INSETS; } }

Slide 114

Slide 114 text

public WindowInsets dispatchApplyWindowInsets(WindowInsets insets) { try { mPrivateFlags3 |= PFLAG3_APPLYING_INSETS; if (mListenerInfo != null && mListenerInfo.mOnApplyWindowInsetsListener != null) { return mListenerInfo.mOnApplyWindowInsetsListener.onApplyWindowInsets(this, insets); } else { return onApplyWindowInsets(insets); } } finally { mPrivateFlags3 &= ~PFLAG3_APPLYING_INSETS; } }

Slide 115

Slide 115 text

public WindowInsets onApplyWindowInsets(WindowInsets insets) { if ((mPrivateFlags3 & PFLAG3_FITTING_SYSTEM_WINDOWS) == 0) { if (fitSystemWindows(insets.getSystemWindowInsetsAsRect())) { return insets.consumeSystemWindowInsets(); } } else { if (fitSystemWindowsInt(insets.getSystemWindowInsetsAsRect())) { return insets.consumeSystemWindowInsets(); } } return insets; }

Slide 116

Slide 116 text

public WindowInsets onApplyWindowInsets(WindowInsets insets) { if ((mPrivateFlags3 & PFLAG3_FITTING_SYSTEM_WINDOWS) == 0) { if (fitSystemWindows(insets.getSystemWindowInsetsAsRect())) { return insets.consumeSystemWindowInsets(); } } else { if (fitSystemWindowsInt(insets.getSystemWindowInsetsAsRect())) { return insets.consumeSystemWindowInsets(); } } return insets; } σϑΥϧτͷfitsSystemWindowsͷ৔߹ɺInsetsΛফඅ͢Δ

Slide 117

Slide 117 text

public WindowInsets dispatchApplyWindowInsets(WindowInsets insets) { try { mPrivateFlags3 |= PFLAG3_APPLYING_INSETS; if (mListenerInfo != null && mListenerInfo.mOnApplyWindowInsetsListener != null) { return mListenerInfo.mOnApplyWindowInsetsListener.onApplyWindowInsets(this, insets); } else { return onApplyWindowInsets(insets); } } finally { mPrivateFlags3 &= ~PFLAG3_APPLYING_INSETS; } }

Slide 118

Slide 118 text

public WindowInsets dispatchApplyWindowInsets(WindowInsets insets) { try { mPrivateFlags3 |= PFLAG3_APPLYING_INSETS; if (mListenerInfo != null && mListenerInfo.mOnApplyWindowInsetsListener != null) { return mListenerInfo.mOnApplyWindowInsetsListener.onApplyWindowInsets(this, insets); } else { return onApplyWindowInsets(insets); } finally { mPrivateFlags3 &= ~PFLAG3_APPLYING_INSETS; } }

Slide 119

Slide 119 text

public void setOnApplyWindowInsetsListener(OnApplyWindowInsetsListener listener) { getListenerInfo().mOnApplyWindowInsetsListener = listener; } Listener͕ొ࿥͞Ε͍ͯΔͱɺ fitsSystemWindowsͷಈ࡞ΛΧελϚΠζ͢Δ ͜ͱ͕ग़དྷΔ view.setOnApplyWindowInsetsListener { v, insets -> … }

Slide 120

Slide 120 text

WindowInsets·ͱΊ • System UIͷ෯ɺྖҬΛऔಘͰ͖Δ • ফඅͨ͠৔߹ɺͦΕҎ߱ʹWindowInsets͕఻ൖ͠ͳ͍ • σϑΥϧτͷfitsSystemWindowsͷ৔߹ɺඞͣফඅ͢Δ • setOnApplyWindowListener͔ΒɺfitsSystemWindowsͷσ ϑΥϧτͷڍಈΛม͑Δ͜ͱ͕Մೳ

Slide 121

Slide 121 text

ΧελϜView͔ΒֶͿ

Slide 122

Slide 122 text

Slide 123

Slide 123 text

Slide 124

Slide 124 text

Slide 125

Slide 125 text

Slide 126

Slide 126 text

Slide 127

Slide 127 text

Slide 128

Slide 128 text

Slide 129

Slide 129 text

setOnApplyWindowListenerΛ࢖ͬͯɺ σϑΥϧτͷڍಈΛม͍͑ͯΔ ·ͨɺWindowInsets͸ফඅ͍ͯ͠ͳ͍

Slide 130

Slide 130 text

private void setupForInsets() { if (ViewCompat.getFitsSystemWindows(this)) { if (mApplyWindowInsetsListener == null) { mApplyWindowInsetsListener = new androidx.core.view.OnApplyWindowInsetsListener() { @Override public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) { return setWindowInsets(insets); } }; } // First apply the insets listener ViewCompat.setOnApplyWindowInsetsListener(this, mApplyWindowInsetsListener);

Slide 131

Slide 131 text

private void setupForInsets() { if (ViewCompat.getFitsSystemWindows(this)) { if (mApplyWindowInsetsListener == null) { mApplyWindowInsetsListener = new androidx.core.view.OnApplyWindowInsetsListener() { @Override public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) { return setWindowInsets(insets); } }; } // First apply the insets listener ViewCompat.setOnApplyWindowInsetsListener(this, mApplyWindowInsetsListener);

Slide 132

Slide 132 text

private void setupForInsets() { if (ViewCompat.getFitsSystemWindows(this)) { if (mApplyWindowInsetsListener == null) { mApplyWindowInsetsListener = new androidx.core.view.OnApplyWindowInsetsListener() { @Override public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) { return setWindowInsets(insets); } }; } // First apply the insets listener ViewCompat.setOnApplyWindowInsetsListener(this, mApplyWindowInsetsListener);

Slide 133

Slide 133 text

private void setupForInsets() { if (ViewCompat.getFitsSystemWindows(this)) { if (mApplyWindowInsetsListener == null) { mApplyWindowInsetsListener = new androidx.core.view.OnApplyWindowInsetsListener() { @Override public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) { return setWindowInsets(insets); } }; } // First apply the insets listener ViewCompat.setOnApplyWindowInsetsListener(this, mApplyWindowInsetsListener);

Slide 134

Slide 134 text

final WindowInsetsCompat setWindowInsets(WindowInsetsCompat insets) { if (!ObjectsCompat.equals(mLastInsets, insets)) { mLastInsets = insets; // Now dispatch to the Behaviors insets = dispatchApplyWindowInsetsToBehaviors(insets); requestLayout(); } return insets; }

Slide 135

Slide 135 text

final WindowInsetsCompat setWindowInsets(WindowInsetsCompat insets) { if (!ObjectsCompat.equals(mLastInsets, insets)) { mLastInsets = insets; // Now dispatch to the Behaviors insets = dispatchApplyWindowInsetsToBehaviors(insets); requestLayout(); } return insets; }

Slide 136

Slide 136 text

if (mLastInsets != null && ViewCompat.getFitsSystemWindows(this) && !ViewCompat.getFitsSystemWindows(child)) { parent.left += mLastInsets.getSystemWindowInsetLeft(); parent.top += mLastInsets.getSystemWindowInsetTop(); parent.right -= mLastInsets.getSystemWindowInsetRight(); parent.bottom -= mLastInsets.getSystemWindowInsetBottom(); } final Rect out = acquireTempRect(); GravityCompat.apply(resolveGravity(lp.gravity), child.getMeasuredWidth(), child.getMeasuredHeight(), parent, out, layoutDirection); child.layout(out.left, out.top, out.right, out.bottom); private void layoutChild(…)

Slide 137

Slide 137 text

if (mLastInsets != null && ViewCompat.getFitsSystemWindows(this) && !ViewCompat.getFitsSystemWindows(child)) { parent.left += mLastInsets.getSystemWindowInsetLeft(); parent.top += mLastInsets.getSystemWindowInsetTop(); parent.right -= mLastInsets.getSystemWindowInsetRight(); parent.bottom -= mLastInsets.getSystemWindowInsetBottom(); } final Rect out = acquireTempRect(); GravityCompat.apply(resolveGravity(lp.gravity), child.getMeasuredWidth(), child.getMeasuredHeight(), parent, out, layoutDirection); child.layout(out.left, out.top, out.right, out.bottom); private void layoutChild(…)

Slide 138

Slide 138 text

if (mLastInsets != null && ViewCompat.getFitsSystemWindows(this) && !ViewCompat.getFitsSystemWindows(child)) { parent.left += mLastInsets.getSystemWindowInsetLeft(); parent.top += mLastInsets.getSystemWindowInsetTop(); parent.right -= mLastInsets.getSystemWindowInsetRight(); parent.bottom -= mLastInsets.getSystemWindowInsetBottom(); } final Rect out = acquireTempRect(); GravityCompat.apply(resolveGravity(lp.gravity), child.getMeasuredWidth(), child.getMeasuredHeight(), parent, out, layoutDirection); child.layout(out.left, out.top, out.right, out.bottom);

Slide 139

Slide 139 text

if (mLastInsets != null && ViewCompat.getFitsSystemWindows(this) && !ViewCompat.getFitsSystemWindows(child)) { parent.left += mLastInsets.getSystemWindowInsetLeft(); parent.top += mLastInsets.getSystemWindowInsetTop(); parent.right -= mLastInsets.getSystemWindowInsetRight(); parent.bottom -= mLastInsets.getSystemWindowInsetBottom(); } final Rect out = acquireTempRect(); GravityCompat.apply(resolveGravity(lp.gravity), child.getMeasuredWidth(), child.getMeasuredHeight(), parent, out, layoutDirection); child.layout(out.left, out.top, out.right, out.bottom);

Slide 140

Slide 140 text

ViewCompat.setOnApplyWindowInsetsListener( this, new androidx.core.view.OnApplyWindowInsetsListener() { @Override public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) { return onWindowInsetChanged(insets); } }); class AppBarLayout

Slide 141

Slide 141 text

ViewCompat.setOnApplyWindowInsetsListener( this, new androidx.core.view.OnApplyWindowInsetsListener() { @Override public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) { return onWindowInsetChanged(insets); } });

Slide 142

Slide 142 text

WindowInsetsCompat onWindowInsetChanged(final WindowInsetsCompat insets) { WindowInsetsCompat newInsets = null; if (ViewCompat.getFitsSystemWindows(this)) { newInsets = insets; } … }

Slide 143

Slide 143 text

WindowInsetsCompat onWindowInsetChanged(final WindowInsetsCompat insets) { WindowInsetsCompat newInsets = null; if (ViewCompat.getFitsSystemWindows(this)) { newInsets = insets; } … }

Slide 144

Slide 144 text

protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); final int heightMode = MeasureSpec.getMode(heightMeasureSpec); if (heightMode != MeasureSpec.EXACTLY && ViewCompat.getFitsSystemWindows(this) && shouldOffsetFirstChild()) { int newHeight = getMeasuredHeight(); switch (heightMode) { case MeasureSpec.AT_MOST: newHeight = MathUtils.clamp( getMeasuredHeight() + getTopInset(), 0, MeasureSpec.getSize(heightMeasureSpec)); break; …

Slide 145

Slide 145 text

protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); final int heightMode = MeasureSpec.getMode(heightMeasureSpec); if (heightMode != MeasureSpec.EXACTLY && ViewCompat.getFitsSystemWindows(this) && shouldOffsetFirstChild()) { int newHeight = getMeasuredHeight(); switch (heightMode) { case MeasureSpec.AT_MOST: newHeight = MathUtils.clamp( getMeasuredHeight() + getTopInset(), 0, MeasureSpec.getSize(heightMeasureSpec)); break; …

Slide 146

Slide 146 text

protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); final int heightMode = MeasureSpec.getMode(heightMeasureSpec); if (heightMode != MeasureSpec.EXACTLY && ViewCompat.getFitsSystemWindows(this) && shouldOffsetFirstChild()) { int newHeight = getMeasuredHeight(); switch (heightMode) { case MeasureSpec.AT_MOST: newHeight = MathUtils.clamp( getMeasuredHeight() + getTopInset(), 0, MeasureSpec.getSize(heightMeasureSpec)); break; …

Slide 147

Slide 147 text

protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); final int heightMode = MeasureSpec.getMode(heightMeasureSpec); if (heightMode != MeasureSpec.EXACTLY && ViewCompat.getFitsSystemWindows(this) && shouldOffsetFirstChild()) { int newHeight = getMeasuredHeight(); switch (heightMode) { case MeasureSpec.AT_MOST: newHeight = MathUtils.clamp( getMeasuredHeight() + getTopInset(), 0, MeasureSpec.getSize(heightMeasureSpec)); break; …

Slide 148

Slide 148 text

protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); final int heightMode = MeasureSpec.getMode(heightMeasureSpec); if (heightMode != MeasureSpec.EXACTLY && ViewCompat.getFitsSystemWindows(this) && shouldOffsetFirstChild()) { int newHeight = getMeasuredHeight(); switch (heightMode) { case MeasureSpec.AT_MOST: newHeight = MathUtils.clamp( getMeasuredHeight() + getTopInset(), 0, MeasureSpec.getSize(heightMeasureSpec)); break; …

Slide 149

Slide 149 text

protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); final int heightMode = MeasureSpec.getMode(heightMeasureSpec); if (heightMode != MeasureSpec.EXACTLY && ViewCompat.getFitsSystemWindows(this) && shouldOffsetFirstChild()) { int newHeight = getMeasuredHeight(); switch (heightMode) { case MeasureSpec.AT_MOST: newHeight = MathUtils.clamp( getMeasuredHeight() + getTopInset(), 0, MeasureSpec.getSize(heightMeasureSpec)); break; … ΋ͱ΋ͱͷAppbarLayoutߴ͞ + status bar ͷߴ͞

Slide 150

Slide 150 text

ΧελϜView·ͱΊ • CoordinatorLayoutɺAppbarLayoutɺBottomAppbar͸ɺͦΕ ͧΕWindowInsetΛಠࣗͰղऍ͢Δ • ଞʹ΋ɺCollapsingToolbarLayoutɺDrawerLayoutͱ͔΋ͦ͏ • ͜ΕΒͷView͸ɺfitsSystemWindowsΛtrueʹࢦఆ͢Δͱɺ ͍͍ײ͡ʹInsetΛղऍͯ͘͠ΕΔ • fitsSystemWindowsࢦఆͯ͠΋ɺফඅ͠ͳ͔ͬͨΓ͢Δ

Slide 151

Slide 151 text

ଞͷΞϓϦ͔ΒֶͿ

Slide 152

Slide 152 text

ςʔϚΛߏங͢Δ

Slide 153

Slide 153 text

APIϨϕϧΛߟྀ͢Δඞཁ͕͋Δ • API23+ • windowLightStatusBar • API27+ • windowLightNavigationBar • API29+ • enforceStatusBarContrast • enforceNavigationBarContrast

Slide 154

Slide 154 text

APIϨϕϧΛߟྀ͢Δඞཁ͕͋Δ • API23+ • windowLightStatusBar • API27+ • windowLightNavigationBar • API29+ • enforceStatusBarContrast • enforceNavigationBarContrast 21 22 23 24 25 26 27 28 29

Slide 155

Slide 155 text

Dev Summit 2019ΞϓϦ https://github.com/google/iosched/pull/333

Slide 156

Slide 156 text

21 22 23 24 25 26 27 28 29

Slide 157

Slide 157 text

21 22 23 24 25 26 27 28 29

Slide 158

Slide 158 text

windowLightStatusBar ✗ windowLightNavigationBar ✗ statusBarColor #66000000 navigationBarColor #66000000 API21 22

Slide 159

Slide 159 text

windowLightStatusBar true windowLightNavigationBar ✗ statusBarColor transparent navigationBarColor #66000000 API23 24 25 26

Slide 160

Slide 160 text

windowLightStatusBar true windowLightNavigationBar ✗ statusBarColor transparent navigationBarColor #66000000 API23 24 25 26

Slide 161

Slide 161 text

windowLightStatusBar true windowLightNavigationBar true statusBarColor transparent navigationBarColor #B3FFFFFF API27 28

Slide 162

Slide 162 text

windowLightStatusBar true windowLightNavigationBar true statusBarColor transparent navigationBarColor #B3FFFFFF API27 28

Slide 163

Slide 163 text

windowLightStatusBar true windowLightNavigationBar true statusBarColor transparent navigationBarColor transparent API29

Slide 164

Slide 164 text

windowLightStatusBar ✗ / false windowLightNavigationBar ✗ / false statusBarColor transparent navigationBarColor #B3000000 API21 ~ 28

Slide 165

Slide 165 text

windowLightStatusBar ✗ / false windowLightNavigationBar ✗ / false statusBarColor transparent navigationBarColor transparent API29

Slide 166

Slide 166 text

<item name="android:windowLightStatusBar" tools:targetApi="m">@bool/ use_light_status</item> <item name="android:windowLightNavigationBar" tools:targetApi=“o_mr1">@bool/use_light_navigation</item>

Slide 167

Slide 167 text

<item name="android:windowLightStatusBar" tools:targetApi="m">@bool/ use_light_status</item> <item name="android:windowLightNavigationBar" tools:targetApi=“o_mr1">@bool/use_light_navigation</item>

Slide 168

Slide 168 text

<item name="android:windowLightStatusBar" tools:targetApi="m">@bool/ use_light_status</item> <item name="android:windowLightNavigationBar" tools:targetApi=“o_mr1">@bool/use_light_navigation</item> true values-notnight-v23

Slide 169

Slide 169 text

<item name="android:windowLightStatusBar" tools:targetApi="m">@bool/ use_light_status</item> <item name="android:windowLightNavigationBar" tools:targetApi=“o_mr1">@bool/use_light_navigation</item> true values-notnight-v23 false values

Slide 170

Slide 170 text

<item name="android:windowLightStatusBar" tools:targetApi="m">@bool/ use_light_status</item> <item name="android:windowLightNavigationBar" tools:targetApi=“o_mr1">@bool/use_light_navigation</item>

Slide 171

Slide 171 text

@bool/ use_light_status @bool/use_light_navigation true values-notnight-v27

Slide 172

Slide 172 text

true values-notnight-v27 false values @bool/ use_light_status @bool/use_light_navigation

Slide 173

Slide 173 text

<item name="android:statusBarColor">@color/status_bar_scrim</item> <item name="android:navigationBarColor">@color/nav_bar_scrim</item>

Slide 174

Slide 174 text

<item name="android:statusBarColor">@color/status_bar_scrim</item> <item name="android:navigationBarColor">@color/nav_bar_scrim</item>

Slide 175

Slide 175 text

<item name="android:statusBarColor">@color/status_bar_scrim</item> <item name="android:navigationBarColor">@color/nav_bar_scrim</item> values-night @color/transparent

Slide 176

Slide 176 text

<item name="android:statusBarColor">@color/status_bar_scrim</item> <item name="android:navigationBarColor">@color/nav_bar_scrim</item> values-night @color/transparent values-notnight-v23 @color/transparent

Slide 177

Slide 177 text

<item name="android:statusBarColor">@color/status_bar_scrim</item> <item name="android:navigationBarColor">@color/nav_bar_scrim</item> values-night @color/transparent values-notnight-v23 @color/transparent values @color/system_ui_scrim_black

Slide 178

Slide 178 text

values-v29 <item name="android:statusBarColor">@color/transparent</item> <item name="android:navigationBarColor">@color/transparent</item>

Slide 179

Slide 179 text

ςʔϚͰߏங͢Δ·ͱΊ • σΟϨΫτϦΛ૊Έ߹Θͤͯɺߏங͢Δ • values • values-night • values-notnight-v23 • values-notnight-v27 • values-v29 • API29͸transparentΛࢦఆ͢Δͱɺ͍͍ײ͡ʹഎܠ৭Λௐ੔ͯ͘͠Ε Δ

Slide 180

Slide 180 text

StatusBarScrim

Slide 181

Slide 181 text

No content

Slide 182

Slide 182 text

Slide 183

Slide 183 text

class StatusBarScrim override fun onApplyWindowInsets(insets: WindowInsets): WindowInsets { if (insets != lastWindowInsets) { lastWindowInsets = insets // Set this view as invisible if there isn't a top inset visibility = if (insets.systemWindowInsetTop > 0) VISIBLE else INVISIBLE // Request a layout to change size requestLayout() } return insets }

Slide 184

Slide 184 text

class StatusBarScrim override fun onApplyWindowInsets(insets: WindowInsets): WindowInsets { if (insets != lastWindowInsets) { lastWindowInsets = insets // Set this view as invisible if there isn't a top inset visibility = if (insets.systemWindowInsetTop > 0) VISIBLE else INVISIBLE // Request a layout to change size requestLayout() } return insets }

Slide 185

Slide 185 text

class StatusBarScrim override fun onApplyWindowInsets(insets: WindowInsets): WindowInsets { if (insets != lastWindowInsets) { lastWindowInsets = insets // Set this view as invisible if there isn't a top inset visibility = if (insets.systemWindowInsetTop > 0) VISIBLE else INVISIBLE // Request a layout to change size requestLayout() } return insets }

Slide 186

Slide 186 text

Slide 187

Slide 187 text

InsetterϥΠϒϥϦ

Slide 188

Slide 188 text

InsetterϥΠϒϥϦ • WindowInsetsɺSystemUiVisibilityΛ؆୯ʹѻ͏͜ͱ͕ग़དྷΔ void setEdgeToEdgeSystemUiFlags(View view, boolean enabled)

Slide 189

Slide 189 text

InsetterϥΠϒϥϦ • WindowInsetsɺSystemUiVisibilityΛ؆୯ʹѻ͏͜ͱ͕ग़དྷΔ void setOnApplyInsetsListener(View view, OnApplyInsetsListener listener) public interface OnApplyInsetsListener { void onApplyInsets( View view, WindowInsetsCompat insets, ViewState initialState ); }

Slide 190

Slide 190 text

• WindowInsetsɺSystemUiVisibilityΛ؆୯ʹѻ͏͜ͱ͕ग़དྷΔ void setOnApplyInsetsListener(View view, OnApplyInsetsListener listener) public interface OnApplyInsetsListener { void onApplyInsets( View view, WindowInsetsCompat insets, ViewState initialState ); } view.updatePadding( top = view.paddingTop + insets.systemWindowInsetTop )

Slide 191

Slide 191 text

• WindowInsetsɺSystemUiVisibilityΛ؆୯ʹѻ͏͜ͱ͕ग़དྷΔ void setOnApplyInsetsListener(View view, OnApplyInsetsListener listener) public interface OnApplyInsetsListener { void onApplyInsets( View view, WindowInsetsCompat insets, ViewState initialState ); } view.updatePadding( top = view.paddingTop + insets.systemWindowInsetTop ) setOnApplyWindowInsetsListener͸ෳ਺ճίʔϧ͞ΕΔͷͰɺ͜Εͩͱμϝ

Slide 192

Slide 192 text

• WindowInsetsɺSystemUiVisibilityΛ؆୯ʹѻ͏͜ͱ͕ग़དྷΔ void setOnApplyInsetsListener(View view, OnApplyInsetsListener listener) public interface OnApplyInsetsListener { void onApplyInsets( View view, WindowInsetsCompat insets, ViewState initialState ); } view.updatePadding( top = initialState.paddings.top + insets.systemWindowInsetTop )

Slide 193

Slide 193 text

ࢀߟ • https://github.com/google/iosched • https://medium.com/androiddevelopers/gesture-navigation- going-edge-to-edge-812f62e4e83e • https://medium.com/androiddevelopers/why-would-i-want- to-fitssystemwindows-4e26d9ce1eec • https://speakerdeck.com/ytakahashi/xiang-jie-windowinsets • https://satoshun.github.io/2020/01/android- fitssystemwindows/

Slide 194

Slide 194 text

DroidKaigi 2020 System UIΛίϯτϩʔϧͯ͠ɺ ը໘Λ࠷େݶʹੜ͔ͨ͠ΞϓϦΛߏங͢Δ Sato Shun GitHub: satoshun Twitter: @stsn_jp CyberAgent, Inc.