Adjust Full Screen

F958fbf402a67a1742335a4894e041e5?s=47 magiepooh
August 05, 2016

Adjust Full Screen

Android
StatusBar
NavigationBar

F958fbf402a67a1742335a4894e041e5?s=128

magiepooh

August 05, 2016
Tweet

Transcript

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

  2. About me @magiepooh @magie_pooh Takuma Fujita

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

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

  5. HIDE NavigationBar and StatusBar

  6. 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); }
  7. SHOW NavigationBar and StatusBar

  8. 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); }
  9. showSystemUi & hideSystemUi actual expected

  10. showSystemUi & hideSystemUi actual expected

  11. 1. Refrection

  12. Reflection <!-- Height of the status bar --> <dimen name="status_bar_height">24dp</dimen>

    <!-- Height of the bottom navigation / system bar. --> <dimen name=“navigation_bar_height">48dp</dimen> <!-- Height of the bottom navigation bar in portrait; often the same as @dimen/navigation_bar_height --> <dimen name=“navigation_bar_height_landscape">48dp</dimen> <!-- Width of the navigation bar when it is placed vertically on the screen --> <dimen name="navigation_bar_width">42dp</dimen>
  13. Reflection // portrait resources.getIdentifier("navigation_bar_height", "dimen", “android"); // landscape resources.getIdentifier("navigation_bar_height_l andscape",

    "dimen", "android");
  14. But … • Some device with hardware keyboard return wrong

    size • tablet? mobile??
  15. 2. Calculate

  16. Calculate StatusBar and NavigationBar Size • getSize • getCurrentSizeRange •

    getRealSize(getRawSize)
  17. getRealSize getSize getCurrentSizeRange

  18. getRealSize getSize getCurrentSizeRange

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

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


    }
  21. 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; } }
  22. 3. WindowInsetsCompat

  23. private class ApplyInsetsListener implements android.support.v4.view.OnApplyWindowInsetsListener { @Override public WindowInsetsCompat onApplyWindowInsets(View

    v, WindowInsetsCompat insets) { if (mLastInsets != insets) { mLastInsets = insets; } return insets; } }
  24. ViewCompat.setOnApplyWindowInsetsListener(view, new ApplyInsetsListener());

  25. 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(); }
  26. Thank you for your attention.