From aa94d95bfce2dbb9673675e609d811b260fb53bf Mon Sep 17 00:00:00 2001 From: Charles Chen Date: Tue, 19 Feb 2019 14:18:19 +0800 Subject: [PATCH] Use size to inflate nav bar buttons instead of rotation For a landscape or close-to-square device, the button layout of nav bar was abnormal since System UI assumes the nav bar position would change if device rotated. However, for default landscape device, nav bar will be always on the buttom. This patch resolve the assumption by using nav bar direction (horizon/vertical) instead of rotation. Also renaming the layout for consistency. Test: atest SystemUITests Test: atest NavigationBarFlaterViewTest Test: manual - rotate the phone and comapre to my Pixel2 Test: manual - test the peproduce steps and the layout of nav bar buttons is normal Fix: 124428114 Change-Id: I23444bcb2a44555e7116f6140a29147c5a03ed69 --- .../navigation_layout_rot90.xml | 44 -------- .../res/layout/nav_bar_tuner_inflater.xml | 4 +- .../SystemUI/res/layout/navigation_layout.xml | 3 +- ...t90.xml => navigation_layout_vertical.xml} | 3 +- .../phone/NavigationBarInflaterView.java | 92 +++++++-------- .../statusbar/phone/NavigationBarView.java | 64 +++++------ .../phone/NavigationBarInflaterViewTest.java | 105 ++++++++++++++++++ 7 files changed, 191 insertions(+), 124 deletions(-) delete mode 100644 packages/SystemUI/res/layout-sw600dp/navigation_layout_rot90.xml rename packages/SystemUI/res/layout/{navigation_layout_rot90.xml => navigation_layout_vertical.xml} (96%) create mode 100644 packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NavigationBarInflaterViewTest.java diff --git a/packages/SystemUI/res/layout-sw600dp/navigation_layout_rot90.xml b/packages/SystemUI/res/layout-sw600dp/navigation_layout_rot90.xml deleted file mode 100644 index 78304fd894dde..0000000000000 --- a/packages/SystemUI/res/layout-sw600dp/navigation_layout_rot90.xml +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - - - - - - - - diff --git a/packages/SystemUI/res/layout/nav_bar_tuner_inflater.xml b/packages/SystemUI/res/layout/nav_bar_tuner_inflater.xml index b2376333a30e3..133b2158c7711 100644 --- a/packages/SystemUI/res/layout/nav_bar_tuner_inflater.xml +++ b/packages/SystemUI/res/layout/nav_bar_tuner_inflater.xml @@ -20,8 +20,8 @@ android:layout_width="match_parent" android:layout_height="@dimen/navigation_bar_size"> - + - + diff --git a/packages/SystemUI/res/layout/navigation_layout.xml b/packages/SystemUI/res/layout/navigation_layout.xml index d72021e27e0bc..db1c79d24c548 100644 --- a/packages/SystemUI/res/layout/navigation_layout.xml +++ b/packages/SystemUI/res/layout/navigation_layout.xml @@ -22,7 +22,8 @@ android:layout_marginStart="@dimen/rounded_corner_content_padding" android:layout_marginEnd="@dimen/rounded_corner_content_padding" android:paddingStart="@dimen/nav_content_padding" - android:paddingEnd="@dimen/nav_content_padding"> + android:paddingEnd="@dimen/nav_content_padding" + android:id="@+id/horizontal"> + android:paddingBottom="@dimen/nav_content_padding" + android:id="@+id/vertical"> mPlugins = new ArrayList<>(); - private final Display mDisplay; protected LayoutInflater mLayoutInflater; protected LayoutInflater mLandscapeInflater; - protected FrameLayout mRot0; - protected FrameLayout mRot90; - private boolean isRot0Landscape; + protected FrameLayout mHorizontal; + protected FrameLayout mVertical; - private SparseArray mButtonDispatchers; + @VisibleForTesting + SparseArray mButtonDispatchers; private String mCurrentLayout; private View mLastPortrait; private View mLastLandscape; + private boolean mIsVertical; private boolean mAlternativeOrder; private boolean mUsingCustomLayout; @@ -106,14 +103,11 @@ public class NavigationBarInflaterView extends FrameLayout public NavigationBarInflaterView(Context context, AttributeSet attrs) { super(context, attrs); createInflaters(); - mDisplay = ((WindowManager) - context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); - Mode displayMode = mDisplay.getMode(); - isRot0Landscape = displayMode.getPhysicalWidth() > displayMode.getPhysicalHeight(); mOverviewProxyService = Dependency.get(OverviewProxyService.class); } - private void createInflaters() { + @VisibleForTesting + void createInflaters() { mLayoutInflater = LayoutInflater.from(mContext); Configuration landscape = new Configuration(); landscape.setTo(mContext.getResources().getConfiguration()); @@ -131,13 +125,12 @@ public class NavigationBarInflaterView extends FrameLayout private void inflateChildren() { removeAllViews(); - mRot0 = (FrameLayout) mLayoutInflater.inflate(R.layout.navigation_layout, this, false); - mRot0.setId(R.id.rot0); - addView(mRot0); - mRot90 = (FrameLayout) mLayoutInflater.inflate(R.layout.navigation_layout_rot90, this, - false); - mRot90.setId(R.id.rot90); - addView(mRot90); + mHorizontal = (FrameLayout) mLayoutInflater.inflate(R.layout.navigation_layout, + this /* root */, false /* attachToRoot */); + addView(mHorizontal); + mVertical = (FrameLayout) mLayoutInflater.inflate(R.layout.navigation_layout_vertical, + this /* root */, false /* attachToRoot */); + addView(mVertical); updateAlternativeOrder(); } @@ -197,12 +190,9 @@ public class NavigationBarInflaterView extends FrameLayout } } - public void updateButtonDispatchersCurrentView() { + void updateButtonDispatchersCurrentView() { if (mButtonDispatchers != null) { - final int rotation = mDisplay.getRotation(); - final boolean portrait = rotation == Surface.ROTATION_0 - || rotation == Surface.ROTATION_180; - final View view = portrait ? mRot0 : mRot90; + View view = mIsVertical ? mVertical : mHorizontal; for (int i = 0; i < mButtonDispatchers.size(); i++) { final ButtonDispatcher dispatcher = mButtonDispatchers.valueAt(i); dispatcher.setCurrentView(view); @@ -210,7 +200,13 @@ public class NavigationBarInflaterView extends FrameLayout } } - public void setAlternativeOrder(boolean alternativeOrder) { + void setVertical(boolean vertical) { + if (vertical != mIsVertical) { + mIsVertical = vertical; + } + } + + void setAlternativeOrder(boolean alternativeOrder) { if (alternativeOrder != mAlternativeOrder) { mAlternativeOrder = alternativeOrder; updateAlternativeOrder(); @@ -218,10 +214,10 @@ public class NavigationBarInflaterView extends FrameLayout } private void updateAlternativeOrder() { - updateAlternativeOrder(mRot0.findViewById(R.id.ends_group)); - updateAlternativeOrder(mRot0.findViewById(R.id.center_group)); - updateAlternativeOrder(mRot90.findViewById(R.id.ends_group)); - updateAlternativeOrder(mRot90.findViewById(R.id.center_group)); + updateAlternativeOrder(mHorizontal.findViewById(R.id.ends_group)); + updateAlternativeOrder(mHorizontal.findViewById(R.id.center_group)); + updateAlternativeOrder(mVertical.findViewById(R.id.ends_group)); + updateAlternativeOrder(mVertical.findViewById(R.id.center_group)); } private void updateAlternativeOrder(View v) { @@ -231,10 +227,10 @@ public class NavigationBarInflaterView extends FrameLayout } private void initiallyFill(ButtonDispatcher buttonDispatcher) { - addAll(buttonDispatcher, (ViewGroup) mRot0.findViewById(R.id.ends_group)); - addAll(buttonDispatcher, (ViewGroup) mRot0.findViewById(R.id.center_group)); - addAll(buttonDispatcher, (ViewGroup) mRot90.findViewById(R.id.ends_group)); - addAll(buttonDispatcher, (ViewGroup) mRot90.findViewById(R.id.center_group)); + addAll(buttonDispatcher, mHorizontal.findViewById(R.id.ends_group)); + addAll(buttonDispatcher, mHorizontal.findViewById(R.id.center_group)); + addAll(buttonDispatcher, mVertical.findViewById(R.id.ends_group)); + addAll(buttonDispatcher, mVertical.findViewById(R.id.center_group)); } private void addAll(ButtonDispatcher buttonDispatcher, ViewGroup parent) { @@ -266,17 +262,23 @@ public class NavigationBarInflaterView extends FrameLayout String[] center = sets[1].split(BUTTON_SEPARATOR); String[] end = sets[2].split(BUTTON_SEPARATOR); // Inflate these in start to end order or accessibility traversal will be messed up. - inflateButtons(start, mRot0.findViewById(R.id.ends_group), isRot0Landscape, true); - inflateButtons(start, mRot90.findViewById(R.id.ends_group), !isRot0Landscape, true); + inflateButtons(start, mHorizontal.findViewById(R.id.ends_group), + false /* landscape */, true /* start */); + inflateButtons(start, mVertical.findViewById(R.id.ends_group), + true /* landscape */, true /* start */); - inflateButtons(center, mRot0.findViewById(R.id.center_group), isRot0Landscape, false); - inflateButtons(center, mRot90.findViewById(R.id.center_group), !isRot0Landscape, false); + inflateButtons(center, mHorizontal.findViewById(R.id.center_group), + false /* landscape */, false /* start */); + inflateButtons(center, mVertical.findViewById(R.id.center_group), + true /* landscape */, false /* start */); - addGravitySpacer(mRot0.findViewById(R.id.ends_group)); - addGravitySpacer(mRot90.findViewById(R.id.ends_group)); + addGravitySpacer(mHorizontal.findViewById(R.id.ends_group)); + addGravitySpacer(mVertical.findViewById(R.id.ends_group)); - inflateButtons(end, mRot0.findViewById(R.id.ends_group), isRot0Landscape, false); - inflateButtons(end, mRot90.findViewById(R.id.ends_group), !isRot0Landscape, false); + inflateButtons(end, mHorizontal.findViewById(R.id.ends_group), + false /* landscape */, false /* start */); + inflateButtons(end, mVertical.findViewById(R.id.ends_group), + true /* landscape */, false /* start */); updateButtonDispatchersCurrentView(); } @@ -469,8 +471,8 @@ public class NavigationBarInflaterView extends FrameLayout mButtonDispatchers.valueAt(i).clear(); } } - clearAllChildren(mRot0.findViewById(R.id.nav_buttons)); - clearAllChildren(mRot90.findViewById(R.id.nav_buttons)); + clearAllChildren(mHorizontal.findViewById(R.id.nav_buttons)); + clearAllChildren(mVertical.findViewById(R.id.nav_buttons)); } private void clearAllChildren(ViewGroup group) { diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java index 8152206aa2ed9..e4650d5b14e6c 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java @@ -115,9 +115,11 @@ public class NavigationBarView extends FrameLayout implements PluginListener