Add unit tests to GlobalActionsGridLayout.
Refactor GlobalActionsGridLayout, ListGridLayout, and related classes/XML files to clean things up and improve testability.
Test: Automated tests pass. (Hooray, they exist now!)
Fixes: 130808337
Change-Id: I89f1a90b07425a95ce600dd104ed3a4729c2215b
diff --git a/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java b/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java
index 411536c..9b69dc5 100644
--- a/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java
+++ b/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java
@@ -919,73 +919,59 @@
* via {@link com.android.systemui.globalactions.GlobalActionsDialog#mDeviceProvisioned}.
*/
public class MyAdapter extends MultiListAdapter {
- @Override
- public int getCount() {
+ private int countItems(boolean separated) {
int count = 0;
for (int i = 0; i < mItems.size(); i++) {
final Action action = mItems.get(i);
- if (mKeyguardShowing && !action.showDuringKeyguard()) {
- continue;
+ if (shouldBeShown(action) && action.shouldBeSeparated() == separated) {
+ count++;
}
- if (!mDeviceProvisioned && !action.showBeforeProvisioning()) {
- continue;
- }
- count++;
}
return count;
}
+ private boolean shouldBeShown(Action action) {
+ if (mKeyguardShowing && !action.showDuringKeyguard()) {
+ return false;
+ }
+ if (!mDeviceProvisioned && !action.showBeforeProvisioning()) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public int countSeparatedItems() {
+ return countItems(true);
+ }
+
+ @Override
+ public int countListItems() {
+ return countItems(false);
+ }
+
+ @Override
+ public int getCount() {
+ return countSeparatedItems() + countListItems();
+ }
+
@Override
public boolean isEnabled(int position) {
return getItem(position).isEnabled();
}
@Override
- public ArrayList<Action> getSeparatedItems() {
- ArrayList<Action> separatedActions = new ArrayList<Action>();
- if (!shouldUseSeparatedView()) {
- return separatedActions;
- }
- for (int i = 0; i < mItems.size(); i++) {
- final Action action = mItems.get(i);
- if (action.shouldBeSeparated()) {
- separatedActions.add(action);
- }
- }
- return separatedActions;
- }
-
- @Override
- public ArrayList<Action> getListItems() {
- if (!shouldUseSeparatedView()) {
- return new ArrayList<Action>(mItems);
- }
- ArrayList<Action> listActions = new ArrayList<Action>();
- for (int i = 0; i < mItems.size(); i++) {
- final Action action = mItems.get(i);
- if (!action.shouldBeSeparated()) {
- listActions.add(action);
- }
- }
- return listActions;
- }
-
- @Override
public boolean areAllItemsEnabled() {
return false;
}
@Override
public Action getItem(int position) {
-
int filteredPos = 0;
for (int i = 0; i < mItems.size(); i++) {
final Action action = mItems.get(i);
- if (mKeyguardShowing && !action.showDuringKeyguard()) {
- continue;
- }
- if (!mDeviceProvisioned && !action.showBeforeProvisioning()) {
+ if (!shouldBeShown(action)) {
continue;
}
if (filteredPos == position) {
@@ -1010,10 +996,8 @@
public View getView(int position, View convertView, ViewGroup parent) {
Action action = getItem(position);
View view = action.create(mContext, convertView, parent, LayoutInflater.from(mContext));
- // Everything but screenshot, the last item, gets white background.
- if (position == getCount() - 1) {
- MultiListLayout.get(parent).setDivisionView(view);
- }
+ view.setOnClickListener(v -> onClickItem(position));
+ view.setOnLongClickListener(v -> onLongClickItem(position));
return view;
}
@@ -1035,6 +1019,11 @@
}
item.onPress();
}
+
+ @Override
+ public boolean shouldBeSeparated(int position) {
+ return getItem(position).shouldBeSeparated();
+ }
}
// note: the scheme below made more sense when we were planning on having
@@ -1589,7 +1578,6 @@
com.android.systemui.R.drawable.global_action_panel_scrim);
mScrimAlpha = 1f;
}
- mGlobalActionsLayout.setSnapToEdge(true);
getWindow().setBackgroundDrawable(mBackgroundDrawable);
}