diff options
Diffstat (limited to 'packages/SystemUI/src')
5 files changed, 48 insertions, 27 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/HardwareUiLayout.java b/packages/SystemUI/src/com/android/systemui/HardwareUiLayout.java index f5451e952dd9..26c5ef95981f 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 8c49d56ae348..8259da6efe2d 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 3fa6035387c7..c16c91bd4625 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<Action> 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 1d042776efc9..036d8ca3afb6 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 d5dcd74c7ea8..4df1c5a43a1b 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(); + 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; + } if (reverseSublists) { - column = reverseSublistIndex(column); + sublistIndex = reverseSublistIndex(sublistIndex); } - return column; + return sublistIndex; } /** |