Ensure QS contains at least 6 tiles.
Do not allow users to remove QS tiles in the customizer if they
currently have 6 or fewer tiles.
Bug: 72511412
Test: visual
Change-Id: I02be1ee330a81db3d3af6a371187294d71f4db65
diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml
index bf3fa29..d6fb39c 100644
--- a/packages/SystemUI/res/values/strings.xml
+++ b/packages/SystemUI/res/values/strings.xml
@@ -1853,6 +1853,9 @@
<!-- Label for area where tiles can be dragged in to [CHAR LIMIT=60] -->
<string name="drag_to_remove_tiles">Drag here to remove</string>
+ <!-- Label to indicate to users that additional tiles cannot be removed. [CHAR LIMIT=60] -->
+ <string name="drag_to_remove_disabled">You need at least 6 tiles</string>
+
<!-- Button to edit the tile ordering of quick settings [CHAR LIMIT=60] -->
<string name="qs_edit">Edit</string>
diff --git a/packages/SystemUI/src/com/android/systemui/qs/customize/TileAdapter.java b/packages/SystemUI/src/com/android/systemui/qs/customize/TileAdapter.java
index bdc5e7d..3ba5fe6 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/customize/TileAdapter.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/customize/TileAdapter.java
@@ -42,19 +42,19 @@
import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.nano.MetricsProto;
import com.android.systemui.R;
-import com.android.systemui.qs.tileimpl.QSIconViewImpl;
+import com.android.systemui.qs.QSTileHost;
import com.android.systemui.qs.customize.TileAdapter.Holder;
import com.android.systemui.qs.customize.TileQueryHelper.TileInfo;
import com.android.systemui.qs.customize.TileQueryHelper.TileStateListener;
import com.android.systemui.qs.external.CustomTile;
-import com.android.systemui.qs.QSTileHost;
+import com.android.systemui.qs.tileimpl.QSIconViewImpl;
import com.android.systemui.statusbar.phone.SystemUIDialog;
import java.util.ArrayList;
import java.util.List;
public class TileAdapter extends RecyclerView.Adapter<Holder> implements TileStateListener {
-
+ private static final int MIN_NUM_TILES = 6;
private static final long DRAG_LENGTH = 100;
private static final float DRAG_SCALE = 1.2f;
public static final long MOVE_DURATION = 150;
@@ -219,9 +219,15 @@
return;
}
if (holder.getItemViewType() == TYPE_EDIT) {
- ((TextView) holder.itemView.findViewById(android.R.id.title)).setText(
- mCurrentDrag != null ? R.string.drag_to_remove_tiles
- : R.string.drag_to_add_tiles);
+ final int titleResId;
+ if (mCurrentDrag == null) {
+ titleResId = R.string.drag_to_add_tiles;
+ } else if (!canRemoveTiles() && mCurrentDrag.getAdapterPosition() < mEditIndex) {
+ titleResId = R.string.drag_to_remove_disabled;
+ } else {
+ titleResId = R.string.drag_to_remove_tiles;
+ }
+ ((TextView) holder.itemView.findViewById(android.R.id.title)).setText(titleResId);
return;
}
if (holder.getItemViewType() == TYPE_ACCESSIBLE_DROP) {
@@ -286,7 +292,7 @@
if (mAccessibilityMoving) {
selectPosition(position, v);
} else {
- if (position < mEditIndex) {
+ if (position < mEditIndex && canRemoveTiles()) {
showAccessibilityDialog(position, v);
} else {
startAccessibleDrag(position);
@@ -297,6 +303,10 @@
}
}
}
+
+ private boolean canRemoveTiles() {
+ return mCurrentSpecs.size() > MIN_NUM_TILES;
+ }
private void selectPosition(int position, View v) {
// Remove the placeholder.
@@ -507,7 +517,7 @@
break;
}
}
- };
+ }
private final ItemTouchHelper.Callback mCallbacks = new ItemTouchHelper.Callback() {
@@ -551,6 +561,9 @@
@Override
public boolean canDropOver(RecyclerView recyclerView, ViewHolder current,
ViewHolder target) {
+ if (!canRemoveTiles() && current.getAdapterPosition() < mEditIndex) {
+ return target.getAdapterPosition() < mEditIndex;
+ }
return target.getAdapterPosition() <= mEditIndex + 1;
}