diff options
| author | TreeHugger Robot <treehugger-gerrit@google.com> | 2018-10-31 12:24:30 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2018-10-31 12:24:30 +0000 |
| commit | 316902da9b78279f362068168c2facc4e154df47 (patch) | |
| tree | 4b3e9b55334e4be5d9049e65231100e040b2b1b8 /core/java/android | |
| parent | d33b50a66acde10cf35fecfb63ae194a62483c0e (diff) | |
| parent | d6f3fb46c6bea842f2fc93bf2ad0ce79183d591a (diff) | |
Merge "Add get/setExtras to TextClassification"
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/view/textclassifier/TextClassification.java | 67 |
1 files changed, 63 insertions, 4 deletions
diff --git a/core/java/android/view/textclassifier/TextClassification.java b/core/java/android/view/textclassifier/TextClassification.java index 9511a9efb3d5..d972bb872af6 100644 --- a/core/java/android/view/textclassifier/TextClassification.java +++ b/core/java/android/view/textclassifier/TextClassification.java @@ -33,6 +33,7 @@ import android.graphics.drawable.AdaptiveIconDrawable; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.graphics.drawable.Icon; +import android.os.Bundle; import android.os.LocaleList; import android.os.Parcel; import android.os.Parcelable; @@ -126,6 +127,7 @@ public final class TextClassification implements Parcelable { @NonNull private final List<RemoteAction> mActions; @NonNull private final EntityConfidence mEntityConfidence; @Nullable private final String mId; + @NonNull private final Bundle mExtras; private TextClassification( @Nullable String text, @@ -135,7 +137,8 @@ public final class TextClassification implements Parcelable { @Nullable OnClickListener legacyOnClickListener, @NonNull List<RemoteAction> actions, @NonNull Map<String, Float> entityConfidence, - @Nullable String id) { + @Nullable String id, + @NonNull Bundle extras) { mText = text; mLegacyIcon = legacyIcon; mLegacyLabel = legacyLabel; @@ -144,6 +147,7 @@ public final class TextClassification implements Parcelable { mActions = Collections.unmodifiableList(actions); mEntityConfidence = new EntityConfidence(entityConfidence); mId = id; + mExtras = extras; } /** @@ -255,6 +259,18 @@ public final class TextClassification implements Parcelable { return mId; } + /** + * Returns the extended data. + * + * <p><b>NOTE: </b>Each call to this method returns a new bundle copy so clients should + * prefer to hold a reference to the returned bundle rather than frequently calling this + * method. + */ + @NonNull + public Bundle getExtras() { + return mExtras.deepCopy(); + } + @Override public String toString() { return String.format(Locale.US, @@ -359,6 +375,7 @@ public final class TextClassification implements Parcelable { @Nullable private Intent mLegacyIntent; @Nullable private OnClickListener mLegacyOnClickListener; @Nullable private String mId; + @Nullable private Bundle mExtras; /** * Sets the classified text. @@ -471,12 +488,22 @@ public final class TextClassification implements Parcelable { } /** + * Sets the extended data. + */ + @NonNull + public Builder setExtras(@Nullable Bundle extras) { + mExtras = extras; + return this; + } + + /** * Builds and returns a {@link TextClassification} object. */ @NonNull public TextClassification build() { return new TextClassification(mText, mLegacyIcon, mLegacyLabel, mLegacyIntent, - mLegacyOnClickListener, mActions, mEntityConfidence, mId); + mLegacyOnClickListener, mActions, mEntityConfidence, mId, + mExtras == null ? Bundle.EMPTY : mExtras.deepCopy()); } } @@ -490,18 +517,21 @@ public final class TextClassification implements Parcelable { private final int mEndIndex; @Nullable private final LocaleList mDefaultLocales; @Nullable private final ZonedDateTime mReferenceTime; + @NonNull private final Bundle mExtras; private Request( CharSequence text, int startIndex, int endIndex, LocaleList defaultLocales, - ZonedDateTime referenceTime) { + ZonedDateTime referenceTime, + Bundle extras) { mText = text; mStartIndex = startIndex; mEndIndex = endIndex; mDefaultLocales = defaultLocales; mReferenceTime = referenceTime; + mExtras = extras; } /** @@ -548,6 +578,18 @@ public final class TextClassification implements Parcelable { } /** + * Returns the extended data. + * + * <p><b>NOTE: </b>Each call to this method returns a new bundle copy so clients should + * prefer to hold a reference to the returned bundle rather than frequently calling this + * method. + */ + @NonNull + public Bundle getExtras() { + return mExtras.deepCopy(); + } + + /** * A builder for building TextClassification requests. */ public static final class Builder { @@ -555,6 +597,7 @@ public final class TextClassification implements Parcelable { private final CharSequence mText; private final int mStartIndex; private final int mEndIndex; + private Bundle mExtras; @Nullable private LocaleList mDefaultLocales; @Nullable private ZonedDateTime mReferenceTime; @@ -602,11 +645,23 @@ public final class TextClassification implements Parcelable { } /** + * Sets the extended data. + * + * @return this builder + */ + @NonNull + public Builder setExtras(@Nullable Bundle extras) { + mExtras = extras; + return this; + } + + /** * Builds and returns the request object. */ @NonNull public Request build() { - return new Request(mText, mStartIndex, mEndIndex, mDefaultLocales, mReferenceTime); + return new Request(mText, mStartIndex, mEndIndex, mDefaultLocales, mReferenceTime, + mExtras == null ? Bundle.EMPTY : mExtras.deepCopy()); } } @@ -628,6 +683,7 @@ public final class TextClassification implements Parcelable { if (mReferenceTime != null) { dest.writeString(mReferenceTime.toString()); } + dest.writeBundle(mExtras); } public static final Parcelable.Creator<Request> CREATOR = @@ -649,6 +705,7 @@ public final class TextClassification implements Parcelable { mEndIndex = in.readInt(); mDefaultLocales = in.readInt() == 0 ? null : LocaleList.CREATOR.createFromParcel(in); mReferenceTime = in.readInt() == 0 ? null : ZonedDateTime.parse(in.readString()); + mExtras = in.readBundle(); } } @@ -664,6 +721,7 @@ public final class TextClassification implements Parcelable { dest.writeTypedList(mActions); mEntityConfidence.writeToParcel(dest, flags); dest.writeString(mId); + dest.writeBundle(mExtras); } public static final Parcelable.Creator<TextClassification> CREATOR = @@ -695,6 +753,7 @@ public final class TextClassification implements Parcelable { mLegacyIntent = null; // mLegacyIntent is not parcelled. mEntityConfidence = EntityConfidence.CREATOR.createFromParcel(in); mId = in.readString(); + mExtras = in.readBundle(); } // Best effort attempt to try to load a drawable from the provided icon. |
