From 17a327ad059d92863d16334170c8391a5f7152eb Mon Sep 17 00:00:00 2001 From: Selim Cinek Date: Mon, 25 Aug 2014 15:03:48 +0200 Subject: Fixed the navigation bar for LTR languages. The navigation bar now correctly mirrors it's children even in landscape and the tablet layout is correctly applied for LTR languages. Also fixes some bugs where the buttons were invisible in landscape with certain configurations. Bug: 15280748 Change-Id: I27304d9468211a0975824c17e031e2b04b44f9e0 --- .../SystemUI/res/layout-ldrtl/navigation_bar.xml | 328 --------------------- .../SystemUI/res/layout-sw600dp/navigation_bar.xml | 8 - packages/SystemUI/res/layout/navigation_bar.xml | 7 - .../statusbar/phone/NavigationBarView.java | 63 +++- 4 files changed, 58 insertions(+), 348 deletions(-) delete mode 100644 packages/SystemUI/res/layout-ldrtl/navigation_bar.xml diff --git a/packages/SystemUI/res/layout-ldrtl/navigation_bar.xml b/packages/SystemUI/res/layout-ldrtl/navigation_bar.xml deleted file mode 100644 index 35414bca419f..000000000000 --- a/packages/SystemUI/res/layout-ldrtl/navigation_bar.xml +++ /dev/null @@ -1,328 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/packages/SystemUI/res/layout-sw600dp/navigation_bar.xml b/packages/SystemUI/res/layout-sw600dp/navigation_bar.xml index f8b7bae8681c..b5983bb8cd95 100644 --- a/packages/SystemUI/res/layout-sw600dp/navigation_bar.xml +++ b/packages/SystemUI/res/layout-sw600dp/navigation_bar.xml @@ -314,12 +314,4 @@ android:layout_gravity="top" /> - - - - diff --git a/packages/SystemUI/res/layout/navigation_bar.xml b/packages/SystemUI/res/layout/navigation_bar.xml index 7616cb1f85ba..a165940616ba 100644 --- a/packages/SystemUI/res/layout/navigation_bar.xml +++ b/packages/SystemUI/res/layout/navigation_bar.xml @@ -322,11 +322,4 @@ /> - - - 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 35929716c243..3bb403d209a8 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java @@ -23,6 +23,7 @@ import android.animation.TimeInterpolator; import android.animation.ValueAnimator; import android.app.StatusBarManager; import android.content.Context; +import android.content.res.Configuration; import android.content.res.Resources; import android.graphics.Point; import android.graphics.Rect; @@ -48,13 +49,12 @@ import com.android.systemui.statusbar.policy.KeyButtonView; import java.io.FileDescriptor; import java.io.PrintWriter; +import java.util.ArrayList; public class NavigationBarView extends LinearLayout { final static boolean DEBUG = false; final static String TAG = "PhoneStatusBar/NavigationBarView"; - final static boolean NAVBAR_ALWAYS_AT_RIGHT = true; - // slippery nav bar when everything is disabled, e.g. during setup final static boolean SLIPPERY_WHEN_DISABLED = true; @@ -87,6 +87,7 @@ public class NavigationBarView extends LinearLayout { private final NavTransitionListener mTransitionListener = new NavTransitionListener(); private OnVerticalChangedListener mOnVerticalChangedListener; + private boolean mIsLtr; private class NavTransitionListener implements TransitionListener { private boolean mBackTransitioning; @@ -387,13 +388,13 @@ public class NavigationBarView extends LinearLayout { mRotatedViews[Surface.ROTATION_90] = findViewById(R.id.rot90); - mRotatedViews[Surface.ROTATION_270] = NAVBAR_ALWAYS_AT_RIGHT - ? findViewById(R.id.rot90) - : findViewById(R.id.rot270); + mRotatedViews[Surface.ROTATION_270] = mRotatedViews[Surface.ROTATION_90]; mCurrentView = mRotatedViews[Surface.ROTATION_0]; getImeSwitchButton().setOnClickListener(mImeSwitcherClickListener); + + updateLTROrder(); } public boolean isVertical() { @@ -456,6 +457,58 @@ public class NavigationBarView extends LinearLayout { super.onSizeChanged(w, h, oldw, oldh); } + @Override + protected void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + updateLTROrder(); + } + + /** + * In landscape, the LinearLayout is not auto mirrored since it is vertical. Therefore we + * have to do it manually + */ + private void updateLTROrder() { + boolean isLtr = getResources().getConfiguration() + .getLayoutDirection() == LAYOUT_DIRECTION_RTL; + if (mIsLtr != isLtr) { + + // We swap all children of the 90 and 270 degree layouts, since they are vertical + View rotation90 = mRotatedViews[Surface.ROTATION_90]; + swapChildrenOrderIfVertical(rotation90.findViewById(R.id.nav_buttons)); + + View rotation270 = mRotatedViews[Surface.ROTATION_270]; + if (rotation90 != rotation270) { + swapChildrenOrderIfVertical(rotation270.findViewById(R.id.nav_buttons)); + } + mIsLtr = isLtr; + } + } + + + /** + * Swaps the children order of a LinearLayout if it's orientation is Vertical + * + * @param group The LinearLayout to swap the children from. + */ + private void swapChildrenOrderIfVertical(View group) { + if (group instanceof LinearLayout) { + LinearLayout linearLayout = (LinearLayout) group; + if (linearLayout.getOrientation() == VERTICAL) { + int childCount = linearLayout.getChildCount(); + ArrayList childList = new ArrayList<>(childCount); + for (int i = 0; i < childCount; i++) { + childList.add(linearLayout.getChildAt(i)); + } + linearLayout.removeAllViews(); + for (int i = childCount - 1; i >= 0; i--) { + linearLayout.addView(childList.get(i)); + } + } + } + } + + + /* @Override protected void onLayout (boolean changed, int left, int top, int right, int bottom) { -- cgit v1.2.3-59-g8ed1b