[go: nahoru, domu]

Rearrange selection subtypes/hints.

Test: ./gradlew :slice-{core,builders,view}:connectedCheck
Change-Id: I5b32e636528f04946b0891d81e568f0575b1b5bc
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
     })