Loading api/current.txt +4 −0 Original line number Diff line number Diff line Loading @@ -51576,6 +51576,7 @@ package android.view.textclassifier { method public float getConfidenceScore(java.lang.String); method public java.lang.String getEntity(int); method public int getEntityCount(); method public android.os.Bundle getExtras(); method public deprecated android.graphics.drawable.Drawable getIcon(); method public java.lang.String getId(); method public deprecated android.content.Intent getIntent(); Loading @@ -51591,6 +51592,7 @@ package android.view.textclassifier { method public android.view.textclassifier.TextClassification.Builder addAction(android.app.RemoteAction); method public android.view.textclassifier.TextClassification build(); method public android.view.textclassifier.TextClassification.Builder setEntityType(java.lang.String, float); method public android.view.textclassifier.TextClassification.Builder setExtras(android.os.Bundle); method public deprecated android.view.textclassifier.TextClassification.Builder setIcon(android.graphics.drawable.Drawable); method public android.view.textclassifier.TextClassification.Builder setId(java.lang.String); method public deprecated android.view.textclassifier.TextClassification.Builder setIntent(android.content.Intent); Loading @@ -51603,6 +51605,7 @@ package android.view.textclassifier { method public int describeContents(); method public android.os.LocaleList getDefaultLocales(); method public int getEndIndex(); method public android.os.Bundle getExtras(); method public java.time.ZonedDateTime getReferenceTime(); method public int getStartIndex(); method public java.lang.CharSequence getText(); Loading @@ -51614,6 +51617,7 @@ package android.view.textclassifier { ctor public TextClassification.Request.Builder(java.lang.CharSequence, int, int); method public android.view.textclassifier.TextClassification.Request build(); method public android.view.textclassifier.TextClassification.Request.Builder setDefaultLocales(android.os.LocaleList); method public android.view.textclassifier.TextClassification.Request.Builder setExtras(android.os.Bundle); method public android.view.textclassifier.TextClassification.Request.Builder setReferenceTime(java.time.ZonedDateTime); } core/java/android/view/textclassifier/TextClassification.java +63 −4 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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, Loading @@ -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; Loading @@ -144,6 +147,7 @@ public final class TextClassification implements Parcelable { mActions = Collections.unmodifiableList(actions); mEntityConfidence = new EntityConfidence(entityConfidence); mId = id; mExtras = extras; } /** Loading Loading @@ -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, Loading Loading @@ -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. Loading Loading @@ -470,13 +487,23 @@ public final class TextClassification implements Parcelable { return this; } /** * 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()); } } Loading @@ -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; } /** Loading Loading @@ -547,6 +577,18 @@ public final class TextClassification implements Parcelable { return mReferenceTime; } /** * 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. */ Loading @@ -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; Loading Loading @@ -601,12 +644,24 @@ public final class TextClassification implements Parcelable { return this; } /** * 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()); } } Loading @@ -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 = Loading @@ -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(); } } Loading @@ -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 = Loading Loading @@ -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. Loading core/tests/coretests/src/android/view/textclassifier/TextClassificationTest.java +14 −0 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ import android.graphics.Color; 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.support.test.InstrumentationRegistry; Loading @@ -48,6 +49,13 @@ import java.util.Locale; @RunWith(AndroidJUnit4.class) public class TextClassificationTest { private static final String BUNDLE_KEY = "key"; private static final String BUNDLE_VALUE = "value"; private static final Bundle BUNDLE = new Bundle(); static { BUNDLE.putString(BUNDLE_KEY, BUNDLE_VALUE); } public Icon generateTestIcon(int width, int height, int colorValue) { final int numPixels = width * height; final int[] colors = new int[numPixels]; Loading Loading @@ -89,6 +97,7 @@ public class TextClassificationTest { .setEntityType(TextClassifier.TYPE_ADDRESS, 0.3f) .setEntityType(TextClassifier.TYPE_PHONE, 0.7f) .setId(id) .setExtras(BUNDLE) .build(); // Parcel and unparcel Loading Loading @@ -119,6 +128,9 @@ public class TextClassificationTest { assertEquals(TextClassifier.TYPE_ADDRESS, result.getEntity(1)); assertEquals(0.7f, result.getConfidenceScore(TextClassifier.TYPE_PHONE), 1e-7f); assertEquals(0.3f, result.getConfidenceScore(TextClassifier.TYPE_ADDRESS), 1e-7f); // Extras assertEquals(BUNDLE_VALUE, result.getExtras().getString(BUNDLE_KEY)); } @Test Loading Loading @@ -182,6 +194,7 @@ public class TextClassificationTest { new TextClassification.Request.Builder(text, 0, text.length()) .setDefaultLocales(new LocaleList(Locale.US, Locale.GERMANY)) .setReferenceTime(referenceTime) .setExtras(BUNDLE) .build(); // Parcel and unparcel. Loading @@ -197,5 +210,6 @@ public class TextClassificationTest { assertEquals(referenceTime, result.getReferenceTime()); assertEquals("en-US,de-DE", result.getDefaultLocales().toLanguageTags()); assertEquals(referenceTime, result.getReferenceTime()); assertEquals(BUNDLE_VALUE, result.getExtras().getString(BUNDLE_KEY)); } } Loading
api/current.txt +4 −0 Original line number Diff line number Diff line Loading @@ -51576,6 +51576,7 @@ package android.view.textclassifier { method public float getConfidenceScore(java.lang.String); method public java.lang.String getEntity(int); method public int getEntityCount(); method public android.os.Bundle getExtras(); method public deprecated android.graphics.drawable.Drawable getIcon(); method public java.lang.String getId(); method public deprecated android.content.Intent getIntent(); Loading @@ -51591,6 +51592,7 @@ package android.view.textclassifier { method public android.view.textclassifier.TextClassification.Builder addAction(android.app.RemoteAction); method public android.view.textclassifier.TextClassification build(); method public android.view.textclassifier.TextClassification.Builder setEntityType(java.lang.String, float); method public android.view.textclassifier.TextClassification.Builder setExtras(android.os.Bundle); method public deprecated android.view.textclassifier.TextClassification.Builder setIcon(android.graphics.drawable.Drawable); method public android.view.textclassifier.TextClassification.Builder setId(java.lang.String); method public deprecated android.view.textclassifier.TextClassification.Builder setIntent(android.content.Intent); Loading @@ -51603,6 +51605,7 @@ package android.view.textclassifier { method public int describeContents(); method public android.os.LocaleList getDefaultLocales(); method public int getEndIndex(); method public android.os.Bundle getExtras(); method public java.time.ZonedDateTime getReferenceTime(); method public int getStartIndex(); method public java.lang.CharSequence getText(); Loading @@ -51614,6 +51617,7 @@ package android.view.textclassifier { ctor public TextClassification.Request.Builder(java.lang.CharSequence, int, int); method public android.view.textclassifier.TextClassification.Request build(); method public android.view.textclassifier.TextClassification.Request.Builder setDefaultLocales(android.os.LocaleList); method public android.view.textclassifier.TextClassification.Request.Builder setExtras(android.os.Bundle); method public android.view.textclassifier.TextClassification.Request.Builder setReferenceTime(java.time.ZonedDateTime); }
core/java/android/view/textclassifier/TextClassification.java +63 −4 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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, Loading @@ -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; Loading @@ -144,6 +147,7 @@ public final class TextClassification implements Parcelable { mActions = Collections.unmodifiableList(actions); mEntityConfidence = new EntityConfidence(entityConfidence); mId = id; mExtras = extras; } /** Loading Loading @@ -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, Loading Loading @@ -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. Loading Loading @@ -470,13 +487,23 @@ public final class TextClassification implements Parcelable { return this; } /** * 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()); } } Loading @@ -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; } /** Loading Loading @@ -547,6 +577,18 @@ public final class TextClassification implements Parcelable { return mReferenceTime; } /** * 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. */ Loading @@ -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; Loading Loading @@ -601,12 +644,24 @@ public final class TextClassification implements Parcelable { return this; } /** * 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()); } } Loading @@ -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 = Loading @@ -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(); } } Loading @@ -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 = Loading Loading @@ -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. Loading
core/tests/coretests/src/android/view/textclassifier/TextClassificationTest.java +14 −0 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ import android.graphics.Color; 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.support.test.InstrumentationRegistry; Loading @@ -48,6 +49,13 @@ import java.util.Locale; @RunWith(AndroidJUnit4.class) public class TextClassificationTest { private static final String BUNDLE_KEY = "key"; private static final String BUNDLE_VALUE = "value"; private static final Bundle BUNDLE = new Bundle(); static { BUNDLE.putString(BUNDLE_KEY, BUNDLE_VALUE); } public Icon generateTestIcon(int width, int height, int colorValue) { final int numPixels = width * height; final int[] colors = new int[numPixels]; Loading Loading @@ -89,6 +97,7 @@ public class TextClassificationTest { .setEntityType(TextClassifier.TYPE_ADDRESS, 0.3f) .setEntityType(TextClassifier.TYPE_PHONE, 0.7f) .setId(id) .setExtras(BUNDLE) .build(); // Parcel and unparcel Loading Loading @@ -119,6 +128,9 @@ public class TextClassificationTest { assertEquals(TextClassifier.TYPE_ADDRESS, result.getEntity(1)); assertEquals(0.7f, result.getConfidenceScore(TextClassifier.TYPE_PHONE), 1e-7f); assertEquals(0.3f, result.getConfidenceScore(TextClassifier.TYPE_ADDRESS), 1e-7f); // Extras assertEquals(BUNDLE_VALUE, result.getExtras().getString(BUNDLE_KEY)); } @Test Loading Loading @@ -182,6 +194,7 @@ public class TextClassificationTest { new TextClassification.Request.Builder(text, 0, text.length()) .setDefaultLocales(new LocaleList(Locale.US, Locale.GERMANY)) .setReferenceTime(referenceTime) .setExtras(BUNDLE) .build(); // Parcel and unparcel. Loading @@ -197,5 +210,6 @@ public class TextClassificationTest { assertEquals(referenceTime, result.getReferenceTime()); assertEquals("en-US,de-DE", result.getDefaultLocales().toLanguageTags()); assertEquals(referenceTime, result.getReferenceTime()); assertEquals(BUNDLE_VALUE, result.getExtras().getString(BUNDLE_KEY)); } }