Slide 1

Slide 1 text

Adjust Full Screen @magie_pooh https://github.com/magiepooh/ AdjustFullScreenLayout #umeda_apk 2

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

Adjust Full Screen @magie_pooh https://github.com/magiepooh/ AdjustFullScreenLayout #umeda_apk 2

Slide 5

Slide 5 text

HIDE NavigationBar and StatusBar

Slide 6

Slide 6 text

public static void hideSystemUi(Window window) { int options = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { options = options ^ View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; } else { options = options | View.SYSTEM_UI_FLAG_LAYOUT_STABLE; } window.getDecorView().setSystemUiVisibility(options); }

Slide 7

Slide 7 text

SHOW NavigationBar and StatusBar

Slide 8

Slide 8 text

public static void showSystemUi(Window window) { window.getDecorView() .setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); }

Slide 9

Slide 9 text

showSystemUi & hideSystemUi actual expected

Slide 10

Slide 10 text

showSystemUi & hideSystemUi actual expected

Slide 11

Slide 11 text

1. Refrection

Slide 12

Slide 12 text

Reflection 24dp 48dp 48dp 42dp

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

2. Calculate

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

getRealSize getSize getCurrentSizeRange

Slide 18

Slide 18 text

getRealSize getSize getCurrentSizeRange

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

3. WindowInsetsCompat

Slide 23

Slide 23 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 24

Slide 24 text

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

Slide 25

Slide 25 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 26

Slide 26 text

Thank you for your attention.