From 8608cde6cbb4652b3f44a0f2ad4e9ecae99bad8b Mon Sep 17 00:00:00 2001 From: Yoshihide Sogawa <12043975+YoshihideSogawa@users.noreply.github.com> Date: Thu, 27 Sep 2018 13:03:15 +0900 Subject: [PATCH 1/6] Fix find navigation bar --- .../android/floatingview/FloatingViewManager.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/library/src/main/java/jp/co/recruit_lifestyle/android/floatingview/FloatingViewManager.java b/library/src/main/java/jp/co/recruit_lifestyle/android/floatingview/FloatingViewManager.java index 67c1e6d..494f844 100644 --- a/library/src/main/java/jp/co/recruit_lifestyle/android/floatingview/FloatingViewManager.java +++ b/library/src/main/java/jp/co/recruit_lifestyle/android/floatingview/FloatingViewManager.java @@ -241,7 +241,7 @@ public void onScreenChanged(Rect windowRect, int visibility) { } // detect navigation bar - final boolean isHideNavigationBar; + boolean isHideNavigationBar; if (visibility == FullscreenObserverView.NO_LAST_VISIBILITY) { // At the first it can not get the correct value, so do special processing mWindowManager.getDefaultDisplay().getMetrics(mDisplayMetrics); @@ -249,8 +249,14 @@ public void onScreenChanged(Rect windowRect, int visibility) { } else { isHideNavigationBar = (visibility & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; } - final boolean isPortrait = mResources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT; + // auto dismiss navigation bar mode(Galaxy S8, S9 and so on.) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { + final DisplayMetrics realMetrics = new DisplayMetrics(); + mWindowManager.getDefaultDisplay().getRealMetrics(realMetrics); + isHideNavigationBar = isHideNavigationBar || windowRect.bottom - realMetrics.heightPixels == 0; + } + final boolean isPortrait = mResources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT; // update FloatingView layout mTargetFloatingView.onUpdateSystemLayout(isHideStatusBar, isHideNavigationBar, isPortrait, windowRect.left); From bb358d042ea7ad449213bb6642ee8d83c7a62510 Mon Sep 17 00:00:00 2001 From: Yoshihide Sogawa <12043975+YoshihideSogawa@users.noreply.github.com> Date: Thu, 27 Sep 2018 13:20:25 +0900 Subject: [PATCH 2/6] Refactor various name --- .../android/floatingview/FloatingViewManager.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/src/main/java/jp/co/recruit_lifestyle/android/floatingview/FloatingViewManager.java b/library/src/main/java/jp/co/recruit_lifestyle/android/floatingview/FloatingViewManager.java index 494f844..c452fde 100644 --- a/library/src/main/java/jp/co/recruit_lifestyle/android/floatingview/FloatingViewManager.java +++ b/library/src/main/java/jp/co/recruit_lifestyle/android/floatingview/FloatingViewManager.java @@ -251,9 +251,9 @@ public void onScreenChanged(Rect windowRect, int visibility) { } // auto dismiss navigation bar mode(Galaxy S8, S9 and so on.) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { - final DisplayMetrics realMetrics = new DisplayMetrics(); - mWindowManager.getDefaultDisplay().getRealMetrics(realMetrics); - isHideNavigationBar = isHideNavigationBar || windowRect.bottom - realMetrics.heightPixels == 0; + final DisplayMetrics realDisplayMetrics = new DisplayMetrics(); + mWindowManager.getDefaultDisplay().getRealMetrics(realDisplayMetrics); + isHideNavigationBar = isHideNavigationBar || windowRect.bottom - realDisplayMetrics.heightPixels == 0; } final boolean isPortrait = mResources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT; From 5a22d9345dee7b6d2d5ed730ee0a4937c63b6067 Mon Sep 17 00:00:00 2001 From: Yoshihide Sogawa <12043975+YoshihideSogawa@users.noreply.github.com> Date: Thu, 27 Sep 2018 16:25:15 +0900 Subject: [PATCH 3/6] Add final --- .../co/recruit_lifestyle/android/floatingview/FloatingView.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/src/main/java/jp/co/recruit_lifestyle/android/floatingview/FloatingView.java b/library/src/main/java/jp/co/recruit_lifestyle/android/floatingview/FloatingView.java index 43671eb..e0c92fb 100644 --- a/library/src/main/java/jp/co/recruit_lifestyle/android/floatingview/FloatingView.java +++ b/library/src/main/java/jp/co/recruit_lifestyle/android/floatingview/FloatingView.java @@ -284,7 +284,7 @@ class FloatingView extends FrameLayout implements ViewTreeObserver.OnPreDrawList /** * status bar's height(landscape) */ - private int mBaseStatusBarRotatedHeight; + private final int mBaseStatusBarRotatedHeight; /** * Current status bar's height From 78528f24646c59706cdd3c705002825fd7cd83ea Mon Sep 17 00:00:00 2001 From: Yoshihide Sogawa <12043975+YoshihideSogawa@users.noreply.github.com> Date: Fri, 28 Sep 2018 15:17:26 +0900 Subject: [PATCH 4/6] Fix find navigation bar - a bug when rotating the device to landscape mode on home screen --- .../floatingview/FloatingViewManager.java | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/library/src/main/java/jp/co/recruit_lifestyle/android/floatingview/FloatingViewManager.java b/library/src/main/java/jp/co/recruit_lifestyle/android/floatingview/FloatingViewManager.java index c452fde..2bd9636 100644 --- a/library/src/main/java/jp/co/recruit_lifestyle/android/floatingview/FloatingViewManager.java +++ b/library/src/main/java/jp/co/recruit_lifestyle/android/floatingview/FloatingViewManager.java @@ -241,20 +241,19 @@ public void onScreenChanged(Rect windowRect, int visibility) { } // detect navigation bar - boolean isHideNavigationBar; + final boolean isHideNavigationBar; if (visibility == FullscreenObserverView.NO_LAST_VISIBILITY) { // At the first it can not get the correct value, so do special processing - mWindowManager.getDefaultDisplay().getMetrics(mDisplayMetrics); - isHideNavigationBar = windowRect.width() - mDisplayMetrics.widthPixels > 0 || windowRect.height() - mDisplayMetrics.heightPixels > 0; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { + mWindowManager.getDefaultDisplay().getRealMetrics(mDisplayMetrics); + isHideNavigationBar = windowRect.width() - mDisplayMetrics.widthPixels == 0 && windowRect.bottom - mDisplayMetrics.heightPixels == 0; + } else { + mWindowManager.getDefaultDisplay().getMetrics(mDisplayMetrics); + isHideNavigationBar = windowRect.width() - mDisplayMetrics.widthPixels > 0 || windowRect.height() - mDisplayMetrics.heightPixels > 0; + } } else { isHideNavigationBar = (visibility & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; } - // auto dismiss navigation bar mode(Galaxy S8, S9 and so on.) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { - final DisplayMetrics realDisplayMetrics = new DisplayMetrics(); - mWindowManager.getDefaultDisplay().getRealMetrics(realDisplayMetrics); - isHideNavigationBar = isHideNavigationBar || windowRect.bottom - realDisplayMetrics.heightPixels == 0; - } final boolean isPortrait = mResources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT; // update FloatingView layout @@ -445,13 +444,13 @@ public void setDisplayMode(@DisplayMode int displayMode) { mDisplayMode = displayMode; // 常に表示/フルスクリーン時に非表示にするモードの場合 if (mDisplayMode == DISPLAY_MODE_SHOW_ALWAYS || mDisplayMode == DISPLAY_MODE_HIDE_FULLSCREEN) { - for (FloatingView floatingView: mFloatingViewList) { + for (FloatingView floatingView : mFloatingViewList) { floatingView.setVisibility(View.VISIBLE); } } // 常に非表示にするモードの場合 else if (mDisplayMode == DISPLAY_MODE_HIDE_ALWAYS) { - for (FloatingView floatingView: mFloatingViewList) { + for (FloatingView floatingView : mFloatingViewList) { floatingView.setVisibility(View.GONE); } mTrashView.dismiss(); From 123c5106004b6a646a9032f3a3b7c44c13330475 Mon Sep 17 00:00:00 2001 From: Yoshihide Sogawa <12043975+YoshihideSogawa@users.noreply.github.com> Date: Fri, 28 Sep 2018 18:36:13 +0900 Subject: [PATCH 5/6] Fix navigation bar auto hide mode - test only portrait --- .../android/floatingview/FloatingView.java | 49 ++++++++++++++++--- .../floatingview/FloatingViewManager.java | 2 +- 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/library/src/main/java/jp/co/recruit_lifestyle/android/floatingview/FloatingView.java b/library/src/main/java/jp/co/recruit_lifestyle/android/floatingview/FloatingView.java index e0c92fb..d435e33 100644 --- a/library/src/main/java/jp/co/recruit_lifestyle/android/floatingview/FloatingView.java +++ b/library/src/main/java/jp/co/recruit_lifestyle/android/floatingview/FloatingView.java @@ -568,17 +568,17 @@ public boolean onPreDraw() { * @param isHideStatusBar If true, the status bar is hidden * @param isHideNavigationBar If true, the navigation bar is hidden * @param isPortrait If true, the device orientation is portrait - * @param windowLeftOffset Left side offset of device display + * @param windowRect {@link Rect} of system window */ - void onUpdateSystemLayout(boolean isHideStatusBar, boolean isHideNavigationBar, boolean isPortrait, int windowLeftOffset) { + void onUpdateSystemLayout(boolean isHideStatusBar, boolean isHideNavigationBar, boolean isPortrait, Rect windowRect) { // status bar updateStatusBarHeight(isHideStatusBar, isPortrait); // touch X offset(support Cutout) - updateTouchXOffset(isHideNavigationBar, windowLeftOffset); + updateTouchXOffset(isHideNavigationBar, windowRect.left); // touch Y offset(support Cutout) mTouchYOffset = isPortrait ? mSafeInsetRect.top : 0; // navigation bar - updateNavigationBarOffset(isHideNavigationBar, isPortrait); + updateNavigationBarOffset(isHideNavigationBar, isPortrait, windowRect); refreshLimitRect(); } @@ -636,17 +636,52 @@ private void updateTouchXOffset(boolean isHideNavigationBar, int windowLeftOffse * * @param isHideNavigationBar If true, the navigation bar is hidden * @param isPortrait If true, the device orientation is portrait + * @param windowRect {@link Rect} of system window */ - private void updateNavigationBarOffset(boolean isHideNavigationBar, boolean isPortrait) { + private void updateNavigationBarOffset(boolean isHideNavigationBar, boolean isPortrait, Rect windowRect) { + int currentNavigationBarVerticalHeight = 0; + int navigationBarVerticalDiff = 0; + final boolean hasSoftNavigationBar = hasSoftNavigationBar(); + // auto hide navigation bar(Galaxy S8, S9 and so on.) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { + final DisplayMetrics realDisplayMetrics = new DisplayMetrics(); + mWindowManager.getDefaultDisplay().getRealMetrics(realDisplayMetrics); + currentNavigationBarVerticalHeight = realDisplayMetrics.heightPixels - windowRect.bottom; + navigationBarVerticalDiff = mBaseNavigationBarHeight - currentNavigationBarVerticalHeight; + } + if (!isHideNavigationBar) { - mNavigationBarVerticalOffset = 0; + // auto hide navigation bar + // 他デバイスとの矛盾をもとに推測する + // 1.デバイスに組み込まれたナビゲーションバー(mBaseNavigationBarHeight == 0)はシステムの状態によって高さに差が発生しない + // 2.デバイスに組み込まれたナビゲーションバー(!hasSoftNavigationBar)は意図的にBaseを0にしているので、矛盾している + if (navigationBarVerticalDiff != 0 && mBaseNavigationBarHeight == 0 || + !hasSoftNavigationBar && mBaseNavigationBarHeight != 0) { + if (hasSoftNavigationBar) { + // 1.auto hide mode -> show mode + // 2.show mode -> auto hide mode -> home + mNavigationBarVerticalOffset = 0; + } else { + // show mode -> home + mNavigationBarVerticalOffset = -currentNavigationBarVerticalHeight; + } + } else { + // normal device + mNavigationBarVerticalOffset = 0; + } + mNavigationBarHorizontalOffset = 0; return; } // If the portrait, is displayed at the bottom of the screen if (isPortrait) { - mNavigationBarVerticalOffset = mBaseNavigationBarHeight; + // auto hide navigation bar + if (!hasSoftNavigationBar && mBaseNavigationBarHeight != 0) { + mNavigationBarVerticalOffset = 0; + } else { + mNavigationBarVerticalOffset = mBaseNavigationBarHeight; + } mNavigationBarHorizontalOffset = 0; return; } diff --git a/library/src/main/java/jp/co/recruit_lifestyle/android/floatingview/FloatingViewManager.java b/library/src/main/java/jp/co/recruit_lifestyle/android/floatingview/FloatingViewManager.java index 2bd9636..cf5698e 100644 --- a/library/src/main/java/jp/co/recruit_lifestyle/android/floatingview/FloatingViewManager.java +++ b/library/src/main/java/jp/co/recruit_lifestyle/android/floatingview/FloatingViewManager.java @@ -257,7 +257,7 @@ public void onScreenChanged(Rect windowRect, int visibility) { final boolean isPortrait = mResources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT; // update FloatingView layout - mTargetFloatingView.onUpdateSystemLayout(isHideStatusBar, isHideNavigationBar, isPortrait, windowRect.left); + mTargetFloatingView.onUpdateSystemLayout(isHideStatusBar, isHideNavigationBar, isPortrait, windowRect); // フルスクリーンでの非表示モードでない場合は何もしない if (mDisplayMode != DISPLAY_MODE_HIDE_FULLSCREEN) { From c6a466bdc9b6415af4109949ff5f0e96540abfe7 Mon Sep 17 00:00:00 2001 From: Yoshihide Sogawa <12043975+YoshihideSogawa@users.noreply.github.com> Date: Fri, 28 Sep 2018 20:28:01 +0900 Subject: [PATCH 6/6] Fix navigation bar auto hide mode - landscape mode --- .../android/floatingview/FloatingView.java | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/library/src/main/java/jp/co/recruit_lifestyle/android/floatingview/FloatingView.java b/library/src/main/java/jp/co/recruit_lifestyle/android/floatingview/FloatingView.java index d435e33..95b1353 100644 --- a/library/src/main/java/jp/co/recruit_lifestyle/android/floatingview/FloatingView.java +++ b/library/src/main/java/jp/co/recruit_lifestyle/android/floatingview/FloatingView.java @@ -639,15 +639,17 @@ private void updateTouchXOffset(boolean isHideNavigationBar, int windowLeftOffse * @param windowRect {@link Rect} of system window */ private void updateNavigationBarOffset(boolean isHideNavigationBar, boolean isPortrait, Rect windowRect) { - int currentNavigationBarVerticalHeight = 0; + int currentNavigationBarHeight = 0; + int currentNavigationBarWidth = 0; int navigationBarVerticalDiff = 0; final boolean hasSoftNavigationBar = hasSoftNavigationBar(); // auto hide navigation bar(Galaxy S8, S9 and so on.) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { final DisplayMetrics realDisplayMetrics = new DisplayMetrics(); mWindowManager.getDefaultDisplay().getRealMetrics(realDisplayMetrics); - currentNavigationBarVerticalHeight = realDisplayMetrics.heightPixels - windowRect.bottom; - navigationBarVerticalDiff = mBaseNavigationBarHeight - currentNavigationBarVerticalHeight; + currentNavigationBarHeight = realDisplayMetrics.heightPixels - windowRect.bottom; + currentNavigationBarWidth = realDisplayMetrics.widthPixels - mMetrics.widthPixels; + navigationBarVerticalDiff = mBaseNavigationBarHeight - currentNavigationBarHeight; } if (!isHideNavigationBar) { @@ -663,7 +665,7 @@ private void updateNavigationBarOffset(boolean isHideNavigationBar, boolean isPo mNavigationBarVerticalOffset = 0; } else { // show mode -> home - mNavigationBarVerticalOffset = -currentNavigationBarVerticalHeight; + mNavigationBarVerticalOffset = -currentNavigationBarHeight; } } else { // normal device @@ -693,7 +695,17 @@ private void updateNavigationBarOffset(boolean isHideNavigationBar, boolean isPo mNavigationBarHorizontalOffset = 0; } else { mNavigationBarVerticalOffset = 0; - mNavigationBarHorizontalOffset = mBaseNavigationBarRotatedHeight; + // auto hide navigation bar + // 他デバイスとの矛盾をもとに推測する + // 1.デバイスに組み込まれたナビゲーションバー(!hasSoftNavigationBar)は、意図的にBaseを0にしているので、矛盾している + if (!hasSoftNavigationBar && mBaseNavigationBarRotatedHeight != 0) { + mNavigationBarHorizontalOffset = 0; + } else if (hasSoftNavigationBar && mBaseNavigationBarRotatedHeight == 0) { + // 2.ソフトナビゲーションバーの場合、Baseが設定されるため矛盾している + mNavigationBarHorizontalOffset = currentNavigationBarWidth; + } else { + mNavigationBarHorizontalOffset = mBaseNavigationBarRotatedHeight; + } } }