Merge "Add Slice.Builder#addBundle"

This commit is contained in:
TreeHugger Robot
2017-12-12 16:44:13 +00:00
committed by Android (Google) Code Review
3 changed files with 50 additions and 14 deletions

View File

@@ -7027,6 +7027,8 @@ package android.app.slice {
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 deprecated android.app.slice.Slice.Builder addColor(int, java.lang.String, java.lang.String...);
method public deprecated android.app.slice.Slice.Builder addColor(int, java.lang.String, java.util.List<java.lang.String>);
method public android.app.slice.Slice.Builder addHints(java.lang.String...);
@@ -7050,6 +7052,7 @@ package android.app.slice {
public final class SliceItem implements android.os.Parcelable {
method public int describeContents();
method public android.app.PendingIntent getAction();
method public android.os.Bundle getBundle();
method public deprecated int getColor();
method public java.lang.String getFormat();
method public java.util.List<java.lang.String> getHints();
@@ -7064,6 +7067,7 @@ package android.app.slice {
method public void writeToParcel(android.os.Parcel, int);
field public static final android.os.Parcelable.Creator<android.app.slice.SliceItem> CREATOR;
field public static final java.lang.String FORMAT_ACTION = "action";
field public static final java.lang.String FORMAT_BUNDLE = "bundle";
field public static final deprecated java.lang.String FORMAT_COLOR = "color";
field public static final java.lang.String FORMAT_IMAGE = "image";
field public static final java.lang.String FORMAT_INT = "int";

View File

@@ -462,6 +462,32 @@ public final class Slice implements Parcelable {
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
* development
* @param subType Optional template-specific type information
* @see {@link SliceItem#getSubType()}
*/
public Slice.Builder addBundle(Bundle bundle, @Nullable String subType,
@SliceHint 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.
*/

View File

@@ -21,6 +21,7 @@ import android.annotation.StringDef;
import android.app.PendingIntent;
import android.app.RemoteInput;
import android.graphics.drawable.Icon;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
@@ -47,6 +48,7 @@ import java.util.List;
* <li>{@link #FORMAT_INT}</li>
* <li>{@link #FORMAT_TIMESTAMP}</li>
* <li>{@link #FORMAT_REMOTE_INPUT}</li>
* <li>{@link #FORMAT_BUNDLE}</li>
*
* The hints that a {@link SliceItem} are a set of strings which annotate
* the content. The hints that are guaranteed to be understood by the system
@@ -54,6 +56,8 @@ import java.util.List;
*/
public final class SliceItem implements Parcelable {
private static final String TAG = "SliceItem";
/**
* @hide
*/
@@ -65,6 +69,7 @@ public final class SliceItem implements Parcelable {
FORMAT_INT,
FORMAT_TIMESTAMP,
FORMAT_REMOTE_INPUT,
FORMAT_BUNDLE,
})
@Retention(RetentionPolicy.SOURCE)
public @interface SliceType {}
@@ -105,6 +110,10 @@ public final class SliceItem implements Parcelable {
* A {@link SliceItem} that contains a {@link RemoteInput}.
*/
public static final String FORMAT_REMOTE_INPUT = "input";
/**
* A {@link SliceItem} that contains a {@link Bundle}.
*/
public static final String FORMAT_BUNDLE = "bundle";
/**
* @hide
@@ -142,20 +151,6 @@ public final class SliceItem implements Parcelable {
return Arrays.asList(mHints);
}
/**
* @hide
*/
public void addHint(@Slice.SliceHint String hint) {
mHints = ArrayUtils.appendElement(String.class, mHints, hint);
}
/**
* @hide
*/
public void removeHint(String hint) {
ArrayUtils.removeElement(String.class, mHints, hint);
}
/**
* Get the format of this SliceItem.
* <p>
@@ -167,6 +162,7 @@ public final class SliceItem implements Parcelable {
* <li>{@link #FORMAT_INT}</li>
* <li>{@link #FORMAT_TIMESTAMP}</li>
* <li>{@link #FORMAT_REMOTE_INPUT}</li>
* <li>{@link #FORMAT_BUNDLE}</li>
* @see #getSubType() ()
*/
public String getFormat() {
@@ -192,6 +188,13 @@ public final class SliceItem implements Parcelable {
return (CharSequence) mObj;
}
/**
* @return The parcelable held by this {@link #FORMAT_BUNDLE} SliceItem
*/
public Bundle getBundle() {
return (Bundle) mObj;
}
/**
* @return The icon held by this {@link #FORMAT_IMAGE} SliceItem
*/
@@ -321,6 +324,7 @@ public final class SliceItem implements Parcelable {
case FORMAT_SLICE:
case FORMAT_IMAGE:
case FORMAT_REMOTE_INPUT:
case FORMAT_BUNDLE:
((Parcelable) obj).writeToParcel(dest, flags);
break;
case FORMAT_ACTION:
@@ -357,6 +361,8 @@ public final class SliceItem implements Parcelable {
return in.readLong();
case FORMAT_REMOTE_INPUT:
return RemoteInput.CREATOR.createFromParcel(in);
case FORMAT_BUNDLE:
return Bundle.CREATOR.createFromParcel(in);
}
throw new RuntimeException("Unsupported type " + type);
}