Merge "Merge "Some Slices API refinement" into pi-dev am: 1543171d3e" into pi-dev-plus-aosp
This commit is contained in:
committed by
Android (Google) Code Review
commit
743d013856
@@ -7193,6 +7193,7 @@ package android.app.slice {
|
||||
field public static final deprecated java.lang.String EXTRA_SLIDER_VALUE = "android.app.slice.extra.SLIDER_VALUE";
|
||||
field public static final java.lang.String EXTRA_TOGGLE_STATE = "android.app.slice.extra.TOGGLE_STATE";
|
||||
field public static final java.lang.String HINT_ACTIONS = "actions";
|
||||
field public static final java.lang.String HINT_ERROR = "error";
|
||||
field public static final java.lang.String HINT_HORIZONTAL = "horizontal";
|
||||
field public static final java.lang.String HINT_KEY_WORDS = "key_words";
|
||||
field public static final java.lang.String HINT_LARGE = "large";
|
||||
@@ -7218,29 +7219,22 @@ package android.app.slice {
|
||||
}
|
||||
|
||||
public static class Slice.Builder {
|
||||
ctor public Slice.Builder(android.net.Uri);
|
||||
ctor public deprecated Slice.Builder(android.net.Uri);
|
||||
ctor public Slice.Builder(android.net.Uri, android.app.slice.SliceSpec);
|
||||
ctor public Slice.Builder(android.app.slice.Slice.Builder);
|
||||
method public android.app.slice.Slice.Builder addAction(android.app.PendingIntent, android.app.slice.Slice);
|
||||
method public android.app.slice.Slice.Builder addAction(android.app.PendingIntent, android.app.slice.Slice, java.lang.String);
|
||||
method public android.app.slice.Slice.Builder addBundle(android.os.Bundle, java.lang.String, java.lang.String...);
|
||||
method public android.app.slice.Slice.Builder addBundle(android.os.Bundle, java.lang.String, java.util.List<java.lang.String>);
|
||||
method public android.app.slice.Slice.Builder addHints(java.lang.String...);
|
||||
method public android.app.slice.Slice.Builder addHints(java.util.List<java.lang.String>);
|
||||
method public android.app.slice.Slice.Builder addIcon(android.graphics.drawable.Icon, java.lang.String, java.lang.String...);
|
||||
method public android.app.slice.Slice.Builder addIcon(android.graphics.drawable.Icon, java.lang.String, java.util.List<java.lang.String>);
|
||||
method public android.app.slice.Slice.Builder addInt(int, java.lang.String, java.lang.String...);
|
||||
method public android.app.slice.Slice.Builder addInt(int, java.lang.String, java.util.List<java.lang.String>);
|
||||
method public android.app.slice.Slice.Builder addLong(long, java.lang.String, java.util.List<java.lang.String>);
|
||||
method public android.app.slice.Slice.Builder addRemoteInput(android.app.RemoteInput, java.lang.String, java.util.List<java.lang.String>);
|
||||
method public android.app.slice.Slice.Builder addRemoteInput(android.app.RemoteInput, java.lang.String, java.lang.String...);
|
||||
method public android.app.slice.Slice.Builder addSubSlice(android.app.slice.Slice);
|
||||
method public android.app.slice.Slice.Builder addSubSlice(android.app.slice.Slice, java.lang.String);
|
||||
method public android.app.slice.Slice.Builder addText(java.lang.CharSequence, java.lang.String, java.lang.String...);
|
||||
method public android.app.slice.Slice.Builder addText(java.lang.CharSequence, java.lang.String, java.util.List<java.lang.String>);
|
||||
method public android.app.slice.Slice.Builder addTimestamp(long, java.lang.String, java.lang.String...);
|
||||
method public android.app.slice.Slice.Builder addTimestamp(long, java.lang.String, java.util.List<java.lang.String>);
|
||||
method public deprecated android.app.slice.Slice.Builder addTimestamp(long, java.lang.String, java.util.List<java.lang.String>);
|
||||
method public android.app.slice.Slice build();
|
||||
method public android.app.slice.Slice.Builder setCallerNeeded(boolean);
|
||||
method public android.app.slice.Slice.Builder setSpec(android.app.slice.SliceSpec);
|
||||
method public deprecated android.app.slice.Slice.Builder setSpec(android.app.slice.SliceSpec);
|
||||
}
|
||||
|
||||
public final class SliceItem implements android.os.Parcelable {
|
||||
@@ -7263,10 +7257,11 @@ package android.app.slice {
|
||||
field public static final java.lang.String FORMAT_BUNDLE = "bundle";
|
||||
field public static final java.lang.String FORMAT_IMAGE = "image";
|
||||
field public static final java.lang.String FORMAT_INT = "int";
|
||||
field public static final java.lang.String FORMAT_LONG = "long";
|
||||
field public static final java.lang.String FORMAT_REMOTE_INPUT = "input";
|
||||
field public static final java.lang.String FORMAT_SLICE = "slice";
|
||||
field public static final java.lang.String FORMAT_TEXT = "text";
|
||||
field public static final java.lang.String FORMAT_TIMESTAMP = "timestamp";
|
||||
field public static final deprecated java.lang.String FORMAT_TIMESTAMP = "long";
|
||||
}
|
||||
|
||||
public class SliceManager {
|
||||
|
||||
@@ -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,8 +166,13 @@ 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.
|
||||
*/
|
||||
@@ -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,13 +337,23 @@ 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.
|
||||
@@ -340,58 +382,37 @@ public final class Slice implements Parcelable {
|
||||
/**
|
||||
* Add hints to the Slice being constructed
|
||||
*/
|
||||
public Builder addHints(@SliceHint String... hints) {
|
||||
mHints.addAll(Arrays.asList(hints));
|
||||
public Builder addHints(@SliceHint List<String> hints) {
|
||||
mHints.addAll(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()]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the spec for this slice.
|
||||
* @deprecated TO BE REMOVED
|
||||
*/
|
||||
public Builder setSpec(SliceSpec spec) {
|
||||
mSpec = spec;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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,43 +460,33 @@ 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));
|
||||
public Slice.Builder addLong(long value, @Nullable @SliceSubtype String subType,
|
||||
@SliceHint List<String> hints) {
|
||||
mItems.add(new SliceItem(value, SliceItem.FORMAT_LONG, subType,
|
||||
hints.toArray(new String[hints.size()])));
|
||||
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,
|
||||
@SliceHint List<String> hints) {
|
||||
return addTimestamp(time, subType, hints.toArray(new String[hints.size()]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a bundle to the slice being constructed.
|
||||
* <p>Expected to be used for support library extension, should not be used for general
|
||||
@@ -510,25 +494,13 @@ 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.
|
||||
*/
|
||||
|
||||
@@ -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}.
|
||||
*/
|
||||
@@ -119,6 +124,14 @@ public final class SliceItem implements Parcelable {
|
||||
private final String mSubType;
|
||||
private final Object mObj;
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
public SliceItem(Object obj, @SliceType String format, String subType,
|
||||
List<String> hints) {
|
||||
this(obj, format, subType, hints.toArray(new String[hints.size()]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user