Merge changes Id5d0db40,I5b32e636 into androidx-master-dev
* changes:
Parse selection slices in RowContent.
Rearrange selection subtypes/hints.
diff --git a/slices/builders/src/main/java/androidx/slice/builders/impl/SelectionBuilderV1Impl.java b/slices/builders/src/main/java/androidx/slice/builders/impl/SelectionBuilderV1Impl.java
index 853b54a..b7696d3f 100644
--- a/slices/builders/src/main/java/androidx/slice/builders/impl/SelectionBuilderV1Impl.java
+++ b/slices/builders/src/main/java/androidx/slice/builders/impl/SelectionBuilderV1Impl.java
@@ -22,7 +22,7 @@
import static android.app.slice.Slice.SUBTYPE_LAYOUT_DIRECTION;
import static androidx.annotation.RestrictTo.Scope.LIBRARY;
-import static androidx.slice.core.SliceHints.HINT_SELECTION;
+import static androidx.slice.core.SliceHints.HINT_SELECTION_OPTION_VALUE;
import static androidx.slice.core.SliceHints.SUBTYPE_SELECTION_OPTION_KEY;
import androidx.annotation.RequiresApi;
@@ -50,8 +50,6 @@
selectionBuilder.check();
- sliceBuilder.addHints(HINT_SELECTION);
-
selectionBuilder.getPrimaryAction().setPrimaryAction(sliceBuilder);
if (selectionBuilder.getTitle() != null) {
@@ -77,8 +75,8 @@
if (option.first.equals(selectionBuilder.getSelectedOption())) {
optionSubSliceBuilder.addHints(HINT_SELECTED);
}
- optionSubSliceBuilder.addText(option.second, null);
optionSubSliceBuilder.addText(option.first, SUBTYPE_SELECTION_OPTION_KEY);
+ optionSubSliceBuilder.addText(option.second, null, HINT_SELECTION_OPTION_VALUE);
sliceBuilder.addSubSlice(optionSubSliceBuilder.build());
}
}
diff --git a/slices/core/src/main/java/androidx/slice/Slice.java b/slices/core/src/main/java/androidx/slice/Slice.java
index 8b27ea6..035b582 100644
--- a/slices/core/src/main/java/androidx/slice/Slice.java
+++ b/slices/core/src/main/java/androidx/slice/Slice.java
@@ -45,7 +45,7 @@
import static androidx.slice.SliceConvert.unwrap;
import static androidx.slice.core.SliceHints.HINT_ACTIVITY;
import static androidx.slice.core.SliceHints.HINT_CACHED;
-import static androidx.slice.core.SliceHints.HINT_SELECTION;
+import static androidx.slice.core.SliceHints.HINT_SELECTION_OPTION_VALUE;
import android.app.PendingIntent;
import android.app.RemoteInput;
@@ -128,7 +128,7 @@
HINT_ERROR,
HINT_ACTIVITY,
HINT_CACHED,
- HINT_SELECTION
+ HINT_SELECTION_OPTION_VALUE
})
@Retention(RetentionPolicy.SOURCE)
public @interface SliceHint{ }
diff --git a/slices/core/src/main/java/androidx/slice/core/SliceHints.java b/slices/core/src/main/java/androidx/slice/core/SliceHints.java
index 7948b78..04c2ca9 100644
--- a/slices/core/src/main/java/androidx/slice/core/SliceHints.java
+++ b/slices/core/src/main/java/androidx/slice/core/SliceHints.java
@@ -16,14 +16,15 @@
package androidx.slice.core;
-import java.lang.annotation.Retention;
+import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP;
+
+import static java.lang.annotation.RetentionPolicy.SOURCE;
import androidx.annotation.IntDef;
import androidx.annotation.RequiresApi;
import androidx.annotation.RestrictTo;
-import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP;
-import static java.lang.annotation.RetentionPolicy.SOURCE;
+import java.lang.annotation.Retention;
/**
* Temporary class to contain hint constants for slices to be used.
@@ -64,18 +65,28 @@
public static final String HINT_CACHED = "cached";
/**
- * Hint indicating that this slice represents a selection. The options will be included as
+ * Subtype indicating that this slice represents a selection. The options will be included as
* sub-slices.
*/
- public static final String HINT_SELECTION = "selection";
+ public static final String SUBTYPE_SELECTION = "selection";
/**
* Subtype indicating that this slice represents the key passed back to the application when the
- * user selects this option. The grandparent of this slice must have {@link #HINT_SELECTION}.
- * Expected to be an item of format {@link androidx.slice.SliceItem@FORMAT_STRING}.
+ * user selects this option. The grandparent of this slice must be of subtype
+ * {@link #SUBTYPE_SELECTION}.
+ *
+ * Expected to be an item of format {@link androidx.slice.SliceItem@FORMAT_TEXT}.
*/
public static final String SUBTYPE_SELECTION_OPTION_KEY = "selection_option_key";
+ /**
+ * Hint indicating that this slice represents the text displayed to the user for this option.
+ * The grandparent of this slice must be of subtype {@link #SUBTYPE_SELECTION}.
+ *
+ * Expected to be an item of format {@link androidx.slice.SliceItem@FORMAT_TEXT}.
+ */
+ public static final String HINT_SELECTION_OPTION_VALUE = "selection_option_value";
+
@IntDef({
LARGE_IMAGE, SMALL_IMAGE, ICON_IMAGE, UNKNOWN_IMAGE
})
diff --git a/slices/view/src/main/java/androidx/slice/widget/RowContent.java b/slices/view/src/main/java/androidx/slice/widget/RowContent.java
index ba9e43a..6544d31 100644
--- a/slices/view/src/main/java/androidx/slice/widget/RowContent.java
+++ b/slices/view/src/main/java/androidx/slice/widget/RowContent.java
@@ -35,6 +35,9 @@
import static android.app.slice.SliceItem.FORMAT_SLICE;
import static android.app.slice.SliceItem.FORMAT_TEXT;
+import static androidx.slice.core.SliceHints.SUBTYPE_SELECTION;
+import static androidx.slice.core.SliceHints.SUBTYPE_SELECTION_OPTION_KEY;
+
import android.text.TextUtils;
import android.util.Log;
@@ -67,6 +70,8 @@
private ArrayList<SliceItem> mEndItems = new ArrayList<>();
private ArrayList<SliceAction> mToggleItems = new ArrayList<>();
private SliceItem mRange;
+ private SliceItem mSelection;
+ private ArrayList<SliceItem> mSelectionOptions = new ArrayList<>();
private boolean mIsHeader;
private int mLineCount = 0;
private boolean mShowTitleItems;
@@ -103,6 +108,9 @@
if (SUBTYPE_RANGE.equals(rowSlice.getSubType())) {
mRange = rowSlice;
}
+ if (SUBTYPE_SELECTION.equals(rowSlice.getSubType())) {
+ mSelection = rowSlice;
+ }
if (rowItems.size() > 0) {
// Remove the things we already know about
if (mStartItem != null) {
@@ -231,6 +239,14 @@
}
/**
+ * @return the {@link SliceItem} representing the selection in the row; can be null.
+ */
+ @Nullable
+ public SliceItem getSelection() {
+ return mSelection;
+ }
+
+ /**
* @return the {@link SliceItem} for the icon to use for the input range thumb drawable.
*/
@Nullable
@@ -412,11 +428,17 @@
* @return whether this item is valid content to visibly appear in a row.
*/
private static boolean isValidRowContent(SliceItem slice, SliceItem item) {
+ // XXX: This is fragile -- new subtypes may be erroneously displayed by old clients, since
+ // this is effectively a blocklist, not an allowlist. I'm not sure if SELECTION_OPTION_KEY
+ // needs to be here, but better safe than sorry.
if (item.hasAnyHints(HINT_KEYWORDS, HINT_TTL, HINT_LAST_UPDATED, HINT_HORIZONTAL)
- || SUBTYPE_CONTENT_DESCRIPTION.equals(item.getSubType())) {
+ || SUBTYPE_CONTENT_DESCRIPTION.equals(item.getSubType())
+ || SUBTYPE_SELECTION_OPTION_KEY.equals(item.getSubType())) {
return false;
}
final String itemFormat = item.getFormat();
+ // XXX: This is confusing -- the FORMAT_INTs in a SUBTYPE_RANGE Slice aren't visible
+ // themselves, they're just used to inform rendering.
return FORMAT_IMAGE.equals(itemFormat)
|| FORMAT_TEXT.equals(itemFormat)
|| FORMAT_LONG.equals(itemFormat)