diff options
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java | 56 | ||||
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/statusbar/phone/ReverseLinearLayout.java | 52 |
2 files changed, 50 insertions, 58 deletions
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 0febbd20eedf..97d7dd5181cf 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java @@ -496,8 +496,6 @@ public class NavigationBarView extends LinearLayout { getImeSwitchButton().setOnClickListener(mImeSwitcherClickListener); - updateRTLOrder(); - try { WindowManagerGlobal.getWindowManagerService().registerDockedStackListener(new Stub() { @Override @@ -590,7 +588,6 @@ public class NavigationBarView extends LinearLayout { protected void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); boolean uiCarModeChanged = updateCarMode(newConfig); - updateRTLOrder(); updateTaskSwitchHelper(); if (uiCarModeChanged) { // uiMode changed either from carmode or to carmode. @@ -618,59 +615,6 @@ public class NavigationBarView extends LinearLayout { return uiCarModeChanged; } - /** - * In landscape, the LinearLayout is not auto mirrored since it is vertical. Therefore we - * have to do it manually - */ - private void updateRTLOrder() { - boolean isLayoutRtl = getResources().getConfiguration() - .getLayoutDirection() == LAYOUT_DIRECTION_RTL; - if (mIsLayoutRtl != isLayoutRtl) { - - // We swap all children of the 90 and 270 degree layouts, since they are vertical - View rotation90 = mRotatedViews[Surface.ROTATION_90]; - swapChildrenOrderIfVertical(rotation90); - - View rotation270 = mRotatedViews[Surface.ROTATION_270]; - if (rotation90 != rotation270) { - swapChildrenOrderIfVertical(rotation270); - } - mIsLayoutRtl = isLayoutRtl; - } - } - - /** - * 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) { - if ((linearLayout.getGravity() & Gravity.TOP) != 0) { - linearLayout.setGravity(Gravity.BOTTOM); - } else if ((linearLayout.getGravity() & Gravity.BOTTOM) != 0) { - linearLayout.setGravity(Gravity.TOP); - } - int childCount = linearLayout.getChildCount(); - ArrayList<View> 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)); - } - } - } else if (group instanceof ViewGroup) { - ViewGroup viewGroup = (ViewGroup) group; - for (int i = 0; i < viewGroup.getChildCount(); i++) { - swapChildrenOrderIfVertical(viewGroup.getChildAt(i)); - } - } - } - /* @Override protected void onLayout (boolean changed, int left, int top, int right, int bottom) { diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ReverseLinearLayout.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ReverseLinearLayout.java index da16954d0d46..3682aa1b06f8 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ReverseLinearLayout.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ReverseLinearLayout.java @@ -16,31 +16,79 @@ package com.android.systemui.statusbar.phone; import android.annotation.Nullable; import android.content.Context; +import android.content.res.Configuration; import android.util.AttributeSet; import android.view.View; import android.view.ViewGroup; import android.widget.LinearLayout; +import java.util.ArrayList; + /** * Automatically reverses the order of children as they are added. * Also reverse the width and height values of layout params */ public class ReverseLinearLayout extends LinearLayout { + private boolean mIsLayoutRtl; + public ReverseLinearLayout(Context context, @Nullable AttributeSet attrs) { super(context, attrs); } @Override + protected void onFinishInflate() { + super.onFinishInflate(); + mIsLayoutRtl = getResources().getConfiguration() + .getLayoutDirection() == LAYOUT_DIRECTION_RTL; + } + + @Override public void addView(View child) { reversParams(child.getLayoutParams()); - super.addView(child, 0); + if (mIsLayoutRtl) { + super.addView(child); + } else { + super.addView(child, 0); + } } @Override public void addView(View child, ViewGroup.LayoutParams params) { reversParams(params); - super.addView(child, 0, params); + if (mIsLayoutRtl) { + super.addView(child, params); + } else { + super.addView(child, 0, params); + } + } + + @Override + protected void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + updateRTLOrder(); + } + + /** + * In landscape, the LinearLayout is not auto mirrored since it is vertical. Therefore we + * have to do it manually + */ + private void updateRTLOrder() { + boolean isLayoutRtl = getResources().getConfiguration() + .getLayoutDirection() == LAYOUT_DIRECTION_RTL; + if (mIsLayoutRtl != isLayoutRtl) { + // RTL changed, swap the order of all views. + int childCount = getChildCount(); + ArrayList<View> childList = new ArrayList<>(childCount); + for (int i = 0; i < childCount; i++) { + childList.add(getChildAt(i)); + } + removeAllViews(); + for (int i = childCount - 1; i >= 0; i--) { + super.addView(childList.get(i)); + } + mIsLayoutRtl = isLayoutRtl; + } } private void reversParams(ViewGroup.LayoutParams params) { |