Slide 1

Slide 1 text

How to get size of NavigationBar and StatusBar @magiepooh https://github.com/magiepooh/ AdjustFullScreenLayout

Slide 2

Slide 2 text

About me @magiepooh @magie_pooh Takuma Fujita

Slide 3

Slide 3 text

Company AbemaTV, Inc. (Cyber Agent, Inc.)

Slide 4

Slide 4 text

How to get size of NavigationBar and StatusBar @magiepooh https://github.com/magiepooh/ AdjustFullScreenLayout

Slide 5

Slide 5 text

1. Refrection

Slide 6

Slide 6 text

Reflection 24dp 48dp 48dp 42dp

Slide 7

Slide 7 text

Reflection // portrait resources.getIdentifier("navigation_bar_height", "dimen", “android"); // landscape resources.getIdentifier("navigation_bar_height_l andscape", "dimen", "android");

Slide 8

Slide 8 text

But … • Some device with hardware keyboard return wrong size • tablet? mobile??

Slide 9

Slide 9 text

2. Calculate

Slide 10

Slide 10 text

Calculate StatusBar and NavigationBar Size • getSize • getCurrentSizeRange • getRealSize(getRawSize)

Slide 11

Slide 11 text

getRealSize getSize getCurrentSizeRange

Slide 12

Slide 12 text

getRealSize getSize getCurrentSizeRange

Slide 13

Slide 13 text

NavigationBar Width public int getNavigationBarWidth() { return getRealSize().x - getDisplaySize().x; }

Slide 14

Slide 14 text

NavigationBar Height public int getNavigationBarHeight() {
 return getRealSize().y - getDisplaySize().y;
 }

Slide 15

Slide 15 text

StatusBar Height public int getStatusBarHeight() { Point smallSize = new Point(); Point largeSize = new Point(); display.getCurrentSizeRange(smallSize, largeSize); // getDisplaySize() = getSize() Point displaySize = getDisplaySize(); if (displaySize.x > displaySize.y) { return displaySize.y - smallSize.y; } else { return displaySize.y - largeSize.y; } }

Slide 16

Slide 16 text

3. WindowInsetsCompat

Slide 17

Slide 17 text

private class ApplyInsetsListener implements android.support.v4.view.OnApplyWindowInsetsListener { @Override public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) { if (mLastInsets != insets) { mLastInsets = insets; } return insets; } }

Slide 18

Slide 18 text

ViewCompat.setOnApplyWindowInsetsListener(view, new ApplyInsetsListener());

Slide 19

Slide 19 text

public int getNavigationBarWidth() { return mLastInsets == null ? 0 : mLastInsets.getSystemWindowInsetRight(); } public int getNavigationBarHeight() { return mLastInsets == null ? 0 : mLastInsets.getSystemWindowInsetBottom(); } public int getStatusBarHeight() { return mLastInsets == null ? 0 : mLastInsets.getSystemWindowInsetTop(); }

Slide 20

Slide 20 text

WTF!!!! WindowInsetsCompat is very useful class!

Slide 21

Slide 21 text

Thanks for your attention.