summaryrefslogtreecommitdiff
path: root/core/java/android
diff options
context:
space:
mode:
authorJason Monk <jmonk@google.com>2018-03-06 16:32:28 -0500
committerJason Monk <jmonk@google.com>2018-03-20 16:55:47 -0400
commit106387f0b283beeb5318f05e2033f15798e274b3 (patch)
tree7dd36d139bc94a6bcf7262f4dacd8c6590d1b214 /core/java/android
parent51d2cc45d8a7efac4e83303737ee8168fc161291 (diff)
Some Slices API refinement
Removing overloads, fixing documentation, adding stringdefs, etc. Test: update-api Change-Id: Iae902092a29d44c3f4735ad2c3392bb35988684a Fixes: 73124159 Bug: 73123366 Fixes: 73123451 Fixes: 73123651 Fixes: 73124123
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/app/slice/Slice.java166
-rw-r--r--core/java/android/app/slice/SliceItem.java19
-rw-r--r--core/java/android/app/slice/SliceProvider.java9
3 files changed, 91 insertions, 103 deletions
diff --git a/core/java/android/app/slice/Slice.java b/core/java/android/app/slice/Slice.java
index d6f23521bf3c..61679cb4d631 100644
--- a/core/java/android/app/slice/Slice.java
+++ b/core/java/android/app/slice/Slice.java
@@ -66,10 +66,27 @@ public final class Slice implements Parcelable {
HINT_HORIZONTAL,
HINT_PARTIAL,
HINT_SEE_MORE,
- HINT_KEY_WORDS
+ HINT_KEY_WORDS,
+ HINT_ERROR,
})
@Retention(RetentionPolicy.SOURCE)
public @interface SliceHint {}
+ /**
+ * @hide
+ */
+ @StringDef(prefix = { "SUBTYPE_" }, value = {
+ SUBTYPE_COLOR,
+ SUBTYPE_CONTENT_DESCRIPTION,
+ SUBTYPE_MAX,
+ SUBTYPE_MESSAGE,
+ SUBTYPE_PRIORITY,
+ SUBTYPE_RANGE,
+ SUBTYPE_SOURCE,
+ SUBTYPE_TOGGLE,
+ SUBTYPE_VALUE,
+ })
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface SliceSubtype {}
/**
* Hint that this content is a title of other content in the slice. This can also indicate that
@@ -149,9 +166,14 @@ public final class Slice implements Parcelable {
/**
* A hint to indicate that the contents of this subslice represent a list of keywords
* related to the parent slice.
+ * Expected to be on an item of format {@link SliceItem#FORMAT_SLICE}.
*/
public static final String HINT_KEY_WORDS = "key_words";
/**
+ * A hint to indicate that this slice represents an error.
+ */
+ public static final String HINT_ERROR = "error";
+ /**
* Key to retrieve an extra added to an intent when a control is changed.
*/
public static final String EXTRA_TOGGLE_STATE = "android.app.slice.extra.TOGGLE_STATE";
@@ -168,14 +190,18 @@ public final class Slice implements Parcelable {
/**
* Subtype to indicate that this is a message as part of a communication
* sequence in this slice.
+ * Expected to be on an item of format {@link SliceItem#FORMAT_SLICE}.
*/
public static final String SUBTYPE_MESSAGE = "message";
/**
* Subtype to tag the source (i.e. sender) of a {@link #SUBTYPE_MESSAGE}.
+ * Expected to be on an item of format {@link SliceItem#FORMAT_TEXT},
+ * {@link SliceItem#FORMAT_IMAGE} or an {@link SliceItem#FORMAT_SLICE} containing them.
*/
public static final String SUBTYPE_SOURCE = "source";
/**
* Subtype to tag an item as representing a color.
+ * Expected to be on an item of format {@link SliceItem#FORMAT_INT}.
*/
public static final String SUBTYPE_COLOR = "color";
/**
@@ -186,14 +212,18 @@ public final class Slice implements Parcelable {
public static final String SUBTYPE_SLIDER = "slider";
/**
* Subtype to tag an item as representing a range.
+ * Expected to be on an item of format {@link SliceItem#FORMAT_SLICE} containing
+ * a {@link #SUBTYPE_VALUE} and possibly a {@link #SUBTYPE_MAX}.
*/
public static final String SUBTYPE_RANGE = "range";
/**
* Subtype to tag an item as representing the max int value for a {@link #SUBTYPE_RANGE}.
+ * Expected to be on an item of format {@link SliceItem#FORMAT_INT}.
*/
public static final String SUBTYPE_MAX = "max";
/**
* Subtype to tag an item as representing the current int value for a {@link #SUBTYPE_RANGE}.
+ * Expected to be on an item of format {@link SliceItem#FORMAT_INT}.
*/
public static final String SUBTYPE_VALUE = "value";
/**
@@ -205,10 +235,12 @@ public final class Slice implements Parcelable {
public static final String SUBTYPE_TOGGLE = "toggle";
/**
* Subtype to tag an item representing priority.
+ * Expected to be on an item of format {@link SliceItem#FORMAT_INT}.
*/
public static final String SUBTYPE_PRIORITY = "priority";
/**
* Subtype to tag an item to use as a content description.
+ * Expected to be on an item of format {@link SliceItem#FORMAT_TEXT}.
*/
public static final String SUBTYPE_CONTENT_DESCRIPTION = "content_description";
@@ -305,14 +337,24 @@ public final class Slice implements Parcelable {
private SliceSpec mSpec;
/**
- * Create a builder which will construct a {@link Slice} for the Given Uri.
- * @param uri Uri to tag for this slice.
+ * @deprecated TO BE REMOVED
*/
+ @Deprecated
public Builder(@NonNull Uri uri) {
mUri = uri;
}
/**
+ * Create a builder which will construct a {@link Slice} for the given Uri.
+ * @param uri Uri to tag for this slice.
+ * @param spec the spec for this slice.
+ */
+ public Builder(@NonNull Uri uri, SliceSpec spec) {
+ mUri = uri;
+ mSpec = spec;
+ }
+
+ /**
* Create a builder for a {@link Slice} that is a sub-slice of the slice
* being constructed by the provided builder.
* @param parent The builder constructing the parent slice
@@ -340,20 +382,13 @@ public final class Slice implements Parcelable {
/**
* Add hints to the Slice being constructed
*/
- public Builder addHints(@SliceHint String... hints) {
- mHints.addAll(Arrays.asList(hints));
- return this;
- }
-
- /**
- * Add hints to the Slice being constructed
- */
public Builder addHints(@SliceHint List<String> hints) {
- return addHints(hints.toArray(new String[hints.size()]));
+ mHints.addAll(hints);
+ return this;
}
/**
- * Add the spec for this slice.
+ * @deprecated TO BE REMOVED
*/
public Builder setSpec(SliceSpec spec) {
mSpec = spec;
@@ -362,17 +397,10 @@ public final class Slice implements Parcelable {
/**
* Add a sub-slice to the slice being constructed
- */
- public Builder addSubSlice(@NonNull Slice slice) {
- return addSubSlice(slice, null);
- }
-
- /**
- * Add a sub-slice to the slice being constructed
* @param subType Optional template-specific type information
* @see {@link SliceItem#getSubType()}
*/
- public Builder addSubSlice(@NonNull Slice slice, @Nullable String subType) {
+ public Builder addSubSlice(@NonNull Slice slice, @Nullable @SliceSubtype String subType) {
mItems.add(new SliceItem(slice, SliceItem.FORMAT_SLICE, subType,
slice.getHints().toArray(new String[slice.getHints().size()])));
return this;
@@ -380,18 +408,11 @@ public final class Slice implements Parcelable {
/**
* Add an action to the slice being constructed
- */
- public Slice.Builder addAction(@NonNull PendingIntent action, @NonNull Slice s) {
- return addAction(action, s, null);
- }
-
- /**
- * Add an action to the slice being constructed
* @param subType Optional template-specific type information
* @see {@link SliceItem#getSubType()}
*/
public Slice.Builder addAction(@NonNull PendingIntent action, @NonNull Slice s,
- @Nullable String subType) {
+ @Nullable @SliceSubtype String subType) {
List<String> hints = s.getHints();
s.mSpec = null;
mItems.add(new SliceItem(action, s, SliceItem.FORMAT_ACTION, subType, hints.toArray(
@@ -404,58 +425,31 @@ public final class Slice implements Parcelable {
* @param subType Optional template-specific type information
* @see {@link SliceItem#getSubType()}
*/
- public Builder addText(CharSequence text, @Nullable String subType,
- @SliceHint String... hints) {
+ public Builder addText(CharSequence text, @Nullable @SliceSubtype String subType,
+ @SliceHint List<String> hints) {
mItems.add(new SliceItem(text, SliceItem.FORMAT_TEXT, subType, hints));
return this;
}
/**
- * Add text to the slice being constructed
- * @param subType Optional template-specific type information
- * @see {@link SliceItem#getSubType()}
- */
- public Builder addText(CharSequence text, @Nullable String subType,
- @SliceHint List<String> hints) {
- return addText(text, subType, hints.toArray(new String[hints.size()]));
- }
-
- /**
* Add an image to the slice being constructed
* @param subType Optional template-specific type information
* @see {@link SliceItem#getSubType()}
*/
- public Builder addIcon(Icon icon, @Nullable String subType, @SliceHint String... hints) {
+ public Builder addIcon(Icon icon, @Nullable @SliceSubtype String subType,
+ @SliceHint List<String> hints) {
mItems.add(new SliceItem(icon, SliceItem.FORMAT_IMAGE, subType, hints));
return this;
}
/**
- * Add an image to the slice being constructed
- * @param subType Optional template-specific type information
- * @see {@link SliceItem#getSubType()}
- */
- public Builder addIcon(Icon icon, @Nullable String subType, @SliceHint List<String> hints) {
- return addIcon(icon, subType, hints.toArray(new String[hints.size()]));
- }
-
- /**
* Add remote input to the slice being constructed
* @param subType Optional template-specific type information
* @see {@link SliceItem#getSubType()}
*/
- public Slice.Builder addRemoteInput(RemoteInput remoteInput, @Nullable String subType,
+ public Slice.Builder addRemoteInput(RemoteInput remoteInput,
+ @Nullable @SliceSubtype String subType,
@SliceHint List<String> hints) {
- return addRemoteInput(remoteInput, subType, hints.toArray(new String[hints.size()]));
- }
-
- /**
- * Add remote input to the slice being constructed
- * @param subType Optional template-specific type information
- * @see {@link SliceItem#getSubType()}
- */
- public Slice.Builder addRemoteInput(RemoteInput remoteInput, @Nullable String subType,
- @SliceHint String... hints) {
mItems.add(new SliceItem(remoteInput, SliceItem.FORMAT_REMOTE_INPUT,
subType, hints));
return this;
@@ -466,41 +460,31 @@ public final class Slice implements Parcelable {
* @param subType Optional template-specific type information
* @see {@link SliceItem#getSubType()}
*/
- public Builder addInt(int value, @Nullable String subType, @SliceHint String... hints) {
+ public Builder addInt(int value, @Nullable @SliceSubtype String subType,
+ @SliceHint List<String> hints) {
mItems.add(new SliceItem(value, SliceItem.FORMAT_INT, subType, hints));
return this;
}
/**
- * Add an integer to the slice being constructed
- * @param subType Optional template-specific type information
- * @see {@link SliceItem#getSubType()}
+ * @deprecated TO BE REMOVED.
*/
- public Builder addInt(int value, @Nullable String subType,
+ @Deprecated
+ public Slice.Builder addTimestamp(long time, @Nullable @SliceSubtype String subType,
@SliceHint List<String> hints) {
- return addInt(value, subType, hints.toArray(new String[hints.size()]));
+ return addLong(time, subType, hints);
}
/**
- * Add a timestamp to the slice being constructed
+ * Add a long to the slice being constructed
* @param subType Optional template-specific type information
* @see {@link SliceItem#getSubType()}
*/
- public Slice.Builder addTimestamp(long time, @Nullable String subType,
- @SliceHint String... hints) {
- mItems.add(new SliceItem(time, SliceItem.FORMAT_TIMESTAMP, subType,
- hints));
- return this;
- }
-
- /**
- * Add a timestamp to the slice being constructed
- * @param subType Optional template-specific type information
- * @see {@link SliceItem#getSubType()}
- */
- public Slice.Builder addTimestamp(long time, @Nullable String subType,
+ public Slice.Builder addLong(long value, @Nullable @SliceSubtype String subType,
@SliceHint List<String> hints) {
- return addTimestamp(time, subType, hints.toArray(new String[hints.size()]));
+ mItems.add(new SliceItem(value, SliceItem.FORMAT_LONG, subType,
+ hints.toArray(new String[hints.size()])));
+ return this;
}
/**
@@ -510,26 +494,14 @@ public final class Slice implements Parcelable {
* @param subType Optional template-specific type information
* @see {@link SliceItem#getSubType()}
*/
- public Slice.Builder addBundle(Bundle bundle, @Nullable String subType,
- @SliceHint String... hints) {
+ public Slice.Builder addBundle(Bundle bundle, @Nullable @SliceSubtype String subType,
+ @SliceHint List<String> hints) {
mItems.add(new SliceItem(bundle, SliceItem.FORMAT_BUNDLE, subType,
hints));
return this;
}
/**
- * Add a bundle to the slice being constructed.
- * <p>Expected to be used for support library extension, should not be used for general
- * development
- * @param subType Optional template-specific type information
- * @see {@link SliceItem#getSubType()}
- */
- public Slice.Builder addBundle(Bundle bundle, @Nullable String subType,
- @SliceHint List<String> hints) {
- return addBundle(bundle, subType, hints.toArray(new String[hints.size()]));
- }
-
- /**
* Construct the slice.
*/
public Slice build() {
diff --git a/core/java/android/app/slice/SliceItem.java b/core/java/android/app/slice/SliceItem.java
index 9eb2bb896356..019ae4926636 100644
--- a/core/java/android/app/slice/SliceItem.java
+++ b/core/java/android/app/slice/SliceItem.java
@@ -67,7 +67,7 @@ public final class SliceItem implements Parcelable {
FORMAT_IMAGE,
FORMAT_ACTION,
FORMAT_INT,
- FORMAT_TIMESTAMP,
+ FORMAT_LONG,
FORMAT_REMOTE_INPUT,
FORMAT_BUNDLE,
})
@@ -98,9 +98,14 @@ public final class SliceItem implements Parcelable {
*/
public static final String FORMAT_INT = "int";
/**
- * A {@link SliceItem} that contains a timestamp.
+ * A {@link SliceItem} that contains a long.
*/
- public static final String FORMAT_TIMESTAMP = "timestamp";
+ public static final String FORMAT_LONG = "long";
+ /**
+ * @deprecated TO BE REMOVED
+ */
+ @Deprecated
+ public static final String FORMAT_TIMESTAMP = FORMAT_LONG;
/**
* A {@link SliceItem} that contains a {@link RemoteInput}.
*/
@@ -123,6 +128,14 @@ public final class SliceItem implements Parcelable {
* @hide
*/
public SliceItem(Object obj, @SliceType String format, String subType,
+ List<String> hints) {
+ this(obj, format, subType, hints.toArray(new String[hints.size()]));
+ }
+
+ /**
+ * @hide
+ */
+ public SliceItem(Object obj, @SliceType String format, String subType,
@Slice.SliceHint String[] hints) {
mHints = hints;
mFormat = format;
diff --git a/core/java/android/app/slice/SliceProvider.java b/core/java/android/app/slice/SliceProvider.java
index aa2cf46891d8..dd892937be71 100644
--- a/core/java/android/app/slice/SliceProvider.java
+++ b/core/java/android/app/slice/SliceProvider.java
@@ -41,6 +41,7 @@ import android.os.UserHandle;
import android.util.Log;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
@@ -430,9 +431,11 @@ public abstract class SliceProvider extends ContentProvider {
return new Slice.Builder(sliceUri)
.addAction(createPermissionIntent(context, sliceUri, callingPackage),
new Slice.Builder(sliceUri.buildUpon().appendPath("permission").build())
- .addText(getPermissionString(context, callingPackage), null)
- .build())
- .addHints(Slice.HINT_LIST_ITEM)
+ .addText(getPermissionString(context, callingPackage), null,
+ Collections.emptyList())
+ .build(),
+ null)
+ .addHints(Arrays.asList(Slice.HINT_LIST_ITEM))
.build();
}