diff --git a/packages/SystemUI/res/layout-land/global_actions_grid.xml b/packages/SystemUI/res/layout-land/global_actions_grid.xml index 480f5235f75a1..235d0fc62e2d5 100644 --- a/packages/SystemUI/res/layout-land/global_actions_grid.xml +++ b/packages/SystemUI/res/layout-land/global_actions_grid.xml @@ -10,14 +10,12 @@ android:gravity="top|right" android:clipChildren="false" > - @@ -26,7 +24,6 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" - android:layoutDirection="ltr" android:layout_marginTop="@dimen/global_actions_grid_side_margin" android:translationZ="@dimen/global_actions_translate" android:paddingLeft="@dimen/global_actions_grid_horizontal_padding" @@ -39,25 +36,21 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:visibility="gone" - android:layoutDirection="ltr" - android:orientation="horizontal" + android:layoutDirection="locale" /> - - - diff --git a/packages/SystemUI/res/layout/global_actions_grid.xml b/packages/SystemUI/res/layout/global_actions_grid.xml index 729e96ebc22e3..a620a8eb144be 100644 --- a/packages/SystemUI/res/layout/global_actions_grid.xml +++ b/packages/SystemUI/res/layout/global_actions_grid.xml @@ -10,7 +10,6 @@ android:gravity="bottom|center" android:clipChildren="false" > - - diff --git a/packages/SystemUI/src/com/android/systemui/HardwareUiLayout.java b/packages/SystemUI/src/com/android/systemui/HardwareUiLayout.java index f5451e952dd95..26c5ef95981f6 100644 --- a/packages/SystemUI/src/com/android/systemui/HardwareUiLayout.java +++ b/packages/SystemUI/src/com/android/systemui/HardwareUiLayout.java @@ -90,7 +90,7 @@ public class HardwareUiLayout extends MultiListLayout implements Tunable { } @Override - public ViewGroup getParentView(boolean separated, int index, boolean reverse) { + public ViewGroup getParentView(boolean separated, int index, int rotation) { if (separated) { return getSeparatedView(); } else { diff --git a/packages/SystemUI/src/com/android/systemui/MultiListLayout.java b/packages/SystemUI/src/com/android/systemui/MultiListLayout.java index 8c49d56ae3488..8259da6efe2d1 100644 --- a/packages/SystemUI/src/com/android/systemui/MultiListLayout.java +++ b/packages/SystemUI/src/com/android/systemui/MultiListLayout.java @@ -57,12 +57,12 @@ public abstract class MultiListLayout extends LinearLayout { * @param separated Whether or not this index refers to a position in the separated or list * container. * @param index The index of the item within the container. - * @param reverse If the MultiListLayout contains sub-lists within the list container, reverse - * the order that they are filled. + * @param rotation Specifies the rotation of the device, which is used in some cases to + * determine child ordering. * @return The parent ViewGroup which will be used to contain the specified item * after it has been added to the layout. */ - public abstract ViewGroup getParentView(boolean separated, int index, boolean reverse); + public abstract ViewGroup getParentView(boolean separated, int index, int rotation); /** * Sets the divided view, which may have a differently-colored background. diff --git a/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java b/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java index 3fa6035387c71..c16c91bd46256 100644 --- a/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java +++ b/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java @@ -96,6 +96,7 @@ import com.android.systemui.volume.SystemUIInterpolators.LogAccelerateInterpolat import java.util.ArrayList; import java.util.List; +import java.util.Locale; /** * Helper to show the global actions dialog. Each item is an {@link Action} that @@ -1546,33 +1547,40 @@ class GlobalActionsDialog implements DialogInterface.OnDismissListener, ArrayList listActions = mAdapter.getListActions(mShouldDisplaySeparatedButton); mGlobalActionsLayout.setExpectedListItemCount(listActions.size()); mGlobalActionsLayout.setExpectedSeparatedItemCount(separatedActions.size()); + int rotation = RotationUtils.getRotation(mContext); + + boolean reverse = false; // should we add items to parents in the reverse order? + if (isGridEnabled(mContext)) { + if (rotation == RotationUtils.ROTATION_NONE + || rotation == RotationUtils.ROTATION_SEASCAPE) { + reverse = !reverse; // if we're in portrait or seascape, reverse items + } + if (TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()) + == View.LAYOUT_DIRECTION_RTL) { + reverse = !reverse; // if we're in an RTL language, reverse items (again) + } + } for (int i = 0; i < mAdapter.getCount(); i++) { Action action = mAdapter.getItem(i); int separatedIndex = separatedActions.indexOf(action); ViewGroup parent; if (separatedIndex != -1) { - parent = mGlobalActionsLayout.getParentView(true, separatedIndex, false); + parent = mGlobalActionsLayout.getParentView(true, separatedIndex, rotation); } else { - boolean reverse = false; - - // If we're using the grid layout and we're in seascape, reverse the order - // of sublists to make sure they render in the correct positions, - // since we can't reverse vertical LinearLayouts through the layout xml. - - if (isGridEnabled(mContext) && RotationUtils.getRotation(mContext) - == RotationUtils.ROTATION_SEASCAPE) { - reverse = true; - } int listIndex = listActions.indexOf(action); - parent = mGlobalActionsLayout.getParentView(false, listIndex, reverse); + parent = mGlobalActionsLayout.getParentView(false, listIndex, rotation); } View v = mAdapter.getView(i, null, parent); final int pos = i; v.setOnClickListener(view -> mClickListener.onClick(this, pos)); v.setOnLongClickListener(view -> mLongClickListener.onItemLongClick(null, v, pos, 0)); - parent.addView(v); + if (reverse) { + parent.addView(v, 0); // reverse order of items + } else { + parent.addView(v); + } } } diff --git a/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsGridLayout.java b/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsGridLayout.java index 1d042776efc93..036d8ca3afb6e 100644 --- a/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsGridLayout.java +++ b/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsGridLayout.java @@ -23,6 +23,7 @@ import android.view.ViewGroup; import com.android.systemui.HardwareBgDrawable; import com.android.systemui.MultiListLayout; +import com.android.systemui.util.leak.RotationUtils; /** * Grid-based implementation of the button layout created by the global actions dialog. @@ -83,11 +84,18 @@ public class GlobalActionsGridLayout extends MultiListLayout { } @Override - public ViewGroup getParentView(boolean separated, int index, boolean reverseOrder) { + public ViewGroup getParentView(boolean separated, int index, int rotation) { if (separated) { return getSeparatedView(); } else { - return getListView().getParentView(index, reverseOrder); + switch (rotation) { + case RotationUtils.ROTATION_LANDSCAPE: + return getListView().getParentView(index, false, true); + case RotationUtils.ROTATION_SEASCAPE: + return getListView().getParentView(index, true, true); + default: + return getListView().getParentView(index, false, false); + } } } @@ -96,6 +104,6 @@ public class GlobalActionsGridLayout extends MultiListLayout { */ @Override public void setDivisionView(View v) { - + // do nothing } } diff --git a/packages/SystemUI/src/com/android/systemui/globalactions/ListGridLayout.java b/packages/SystemUI/src/com/android/systemui/globalactions/ListGridLayout.java index d5dcd74c7ea86..4df1c5a43a1bc 100644 --- a/packages/SystemUI/src/com/android/systemui/globalactions/ListGridLayout.java +++ b/packages/SystemUI/src/com/android/systemui/globalactions/ListGridLayout.java @@ -62,11 +62,11 @@ public class ListGridLayout extends LinearLayout { /** * Get the parent view associated with the item which should be placed at the given position. */ - public ViewGroup getParentView(int index, boolean reverseSublists) { + public ViewGroup getParentView(int index, boolean reverseSublists, boolean swapRowsAndColumns) { if (mRows == 0) { return null; } - int column = getParentViewIndex(index, reverseSublists); + int column = getParentViewIndex(index, reverseSublists, swapRowsAndColumns); return (ViewGroup) getChildAt(column); } @@ -74,13 +74,18 @@ public class ListGridLayout extends LinearLayout { return getChildCount() - (index + 1); } - private int getParentViewIndex(int index, boolean reverseSublists) { - int column = (int) Math.floor(index / mRows); - int columnCount = getChildCount(); - if (reverseSublists) { - column = reverseSublistIndex(column); + private int getParentViewIndex(int index, boolean reverseSublists, boolean swapRowsAndColumns) { + int sublistIndex; + ViewGroup row; + if (swapRowsAndColumns) { + sublistIndex = (int) Math.floor(index / mRows); + } else { + sublistIndex = index % mRows; } - return column; + if (reverseSublists) { + sublistIndex = reverseSublistIndex(sublistIndex); + } + return sublistIndex; } /**