Fix TalkBack accessibility for grid-based power menu.
Test: Automated tests pass. TalkBack direction and ordering correct for LTR languages, direction ordering correct for RTL languages. Change-Id: Id7206a9e93976ae74a6d515a84e6840aaa730995
This commit is contained in:
@@ -10,14 +10,12 @@
|
||||
android:gravity="top|right"
|
||||
android:clipChildren="false"
|
||||
>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_height="match_parent"
|
||||
android:layout_width="wrap_content"
|
||||
android:gravity="top|right"
|
||||
android:padding="0dp"
|
||||
android:orientation="vertical"
|
||||
android:layoutDirection="ltr"
|
||||
android:layout_marginRight="@dimen/global_actions_grid_container_bottom_margin"
|
||||
>
|
||||
<!-- Grid of action items -->
|
||||
@@ -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"
|
||||
/>
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"
|
||||
android:layoutDirection="ltr"
|
||||
android:orientation="horizontal"
|
||||
android:layoutDirection="locale"
|
||||
/>
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"
|
||||
android:layoutDirection="ltr"
|
||||
android:orientation="horizontal"
|
||||
android:layoutDirection="locale"
|
||||
/>
|
||||
</com.android.systemui.globalactions.ListGridLayout>
|
||||
|
||||
<!-- For separated items-->
|
||||
<LinearLayout
|
||||
android:id="@+id/separated_button"
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
android:gravity="top|left"
|
||||
android:clipChildren="false"
|
||||
>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_height="match_parent"
|
||||
android:layout_width="wrap_content"
|
||||
@@ -37,11 +36,11 @@
|
||||
android:gravity="center"
|
||||
android:translationZ="@dimen/global_actions_translate"
|
||||
/>
|
||||
|
||||
<!-- Grid of action items -->
|
||||
<com.android.systemui.globalactions.ListGridLayout
|
||||
android:id="@android:id/list"
|
||||
android:layout_gravity="bottom|left"
|
||||
android:gravity="right"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
@@ -54,28 +53,22 @@
|
||||
android:background="?android:attr/colorBackgroundFloating"
|
||||
>
|
||||
<LinearLayout
|
||||
android:layout_gravity="bottom"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"
|
||||
android:layoutDirection="rtl"
|
||||
android:orientation="horizontal"
|
||||
android:layoutDirection="locale"
|
||||
/>
|
||||
<LinearLayout
|
||||
android:layout_gravity="bottom"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"
|
||||
android:layoutDirection="rtl"
|
||||
android:orientation="horizontal"
|
||||
android:layoutDirection="locale"
|
||||
/>
|
||||
<LinearLayout
|
||||
android:layout_gravity="bottom"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"
|
||||
android:layoutDirection="rtl"
|
||||
android:orientation="horizontal"
|
||||
android:layoutDirection="locale"
|
||||
/>
|
||||
</com.android.systemui.globalactions.ListGridLayout>
|
||||
</LinearLayout>
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
android:gravity="bottom|center"
|
||||
android:clipChildren="false"
|
||||
>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
@@ -35,14 +34,13 @@
|
||||
android:gravity="center"
|
||||
android:translationZ="@dimen/global_actions_translate"
|
||||
/>
|
||||
|
||||
<!-- Grid of action items -->
|
||||
<com.android.systemui.globalactions.ListGridLayout
|
||||
android:id="@android:id/list"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:layoutDirection="rtl"
|
||||
android:orientation="vertical"
|
||||
android:gravity="right"
|
||||
android:layout_marginRight="@dimen/global_actions_grid_side_margin"
|
||||
android:translationZ="@dimen/global_actions_translate"
|
||||
android:paddingLeft="@dimen/global_actions_grid_horizontal_padding"
|
||||
@@ -55,19 +53,19 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"
|
||||
android:orientation="vertical"
|
||||
android:layoutDirection="locale"
|
||||
/>
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"
|
||||
android:orientation="vertical"
|
||||
android:layoutDirection="locale"
|
||||
/>
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"
|
||||
android:orientation="vertical"
|
||||
android:layoutDirection="locale"
|
||||
/>
|
||||
</com.android.systemui.globalactions.ListGridLayout>
|
||||
</LinearLayout>
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user