Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Adjust Full Screen

magiepooh
August 05, 2016

Adjust Full Screen

Android
StatusBar
NavigationBar

magiepooh

August 05, 2016
Tweet

More Decks by magiepooh

Other Decks in Technology

Transcript

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

    View Slide

  2. About me
    @magiepooh
    @magie_pooh
    Takuma Fujita

    View Slide

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

    View Slide

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

    View Slide

  5. HIDE NavigationBar and
    StatusBar

    View Slide

  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);
    }

    View Slide

  7. SHOW NavigationBar and
    StatusBar

    View Slide

  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);
    }

    View Slide

  9. showSystemUi & hideSystemUi
    actual expected

    View Slide

  10. showSystemUi & hideSystemUi
    actual expected

    View Slide

  11. 1. Refrection

    View Slide

  12. Reflection

    24dp

    48dp

    48dp

    42dp

    View Slide

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

    View Slide

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

    View Slide

  15. 2. Calculate

    View Slide

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

    View Slide

  17. getRealSize
    getSize
    getCurrentSizeRange

    View Slide

  18. getRealSize
    getSize
    getCurrentSizeRange

    View Slide

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

    View Slide

  20. NavigationBar Height
    public int getNavigationBarHeight() {

    return getRealSize().y - getDisplaySize().y;

    }

    View Slide

  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;
    }
    }

    View Slide

  22. 3. WindowInsetsCompat

    View Slide

  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;
    }
    }

    View Slide

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

    View Slide

  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();
    }

    View Slide

  26. Thank you for your attention.

    View Slide