Merge "Move locale from LanguageDetectionEvent to base class" into qt-dev
diff --git a/api/current.txt b/api/current.txt
index 1623bb8..44b11e1 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -53407,7 +53407,7 @@
method @Nullable public String getCallingPackageName();
method @NonNull public java.util.List<android.view.textclassifier.ConversationActions.Message> getConversation();
method @NonNull public android.os.Bundle getExtras();
- method @Nullable public java.util.List<java.lang.String> getHints();
+ method @NonNull public java.util.List<java.lang.String> getHints();
method @IntRange(from=0xffffffff) public int getMaxSuggestions();
method @NonNull public android.view.textclassifier.TextClassifier.EntityConfig getTypeConfig();
method public void writeToParcel(android.os.Parcel, int);
@@ -53625,6 +53625,7 @@
method public int getEventIndex();
method public int getEventType();
method @NonNull public android.os.Bundle getExtras();
+ method @Nullable public android.icu.util.ULocale getLocale();
method @Nullable public String getModelName();
method @Nullable public String getResultId();
method @NonNull public float[] getScores();
@@ -53662,6 +53663,7 @@
method @NonNull public T setEventContext(@Nullable android.view.textclassifier.TextClassificationContext);
method @NonNull public T setEventIndex(int);
method @NonNull public T setExtras(@NonNull android.os.Bundle);
+ method @NonNull public T setLocale(@Nullable android.icu.util.ULocale);
method @NonNull public T setModelName(@Nullable String);
method @NonNull public T setResultId(@Nullable String);
method @NonNull public T setScores(@NonNull float...);
@@ -53677,14 +53679,12 @@
}
public static final class TextClassifierEvent.LanguageDetectionEvent extends android.view.textclassifier.TextClassifierEvent implements android.os.Parcelable {
- method @Nullable public android.icu.util.ULocale getLocale();
field @NonNull public static final android.os.Parcelable.Creator<android.view.textclassifier.TextClassifierEvent.LanguageDetectionEvent> CREATOR;
}
public static final class TextClassifierEvent.LanguageDetectionEvent.Builder extends android.view.textclassifier.TextClassifierEvent.Builder<android.view.textclassifier.TextClassifierEvent.LanguageDetectionEvent.Builder> {
ctor public TextClassifierEvent.LanguageDetectionEvent.Builder(int);
method @NonNull public android.view.textclassifier.TextClassifierEvent.LanguageDetectionEvent build();
- method @NonNull public android.view.textclassifier.TextClassifierEvent.LanguageDetectionEvent.Builder setLocale(@Nullable android.icu.util.ULocale);
}
public static final class TextClassifierEvent.TextLinkifyEvent extends android.view.textclassifier.TextClassifierEvent implements android.os.Parcelable {
diff --git a/core/java/android/view/textclassifier/ConversationActions.java b/core/java/android/view/textclassifier/ConversationActions.java
index f2fa67d..aeb99b8 100644
--- a/core/java/android/view/textclassifier/ConversationActions.java
+++ b/core/java/android/view/textclassifier/ConversationActions.java
@@ -401,7 +401,7 @@
}
/** Returns an immutable list of hints */
- @Nullable
+ @NonNull
@Hint
public List<String> getHints() {
return mHints;
diff --git a/core/java/android/view/textclassifier/TextClassifierEvent.java b/core/java/android/view/textclassifier/TextClassifierEvent.java
index d3d61a7..7b623e9 100644
--- a/core/java/android/view/textclassifier/TextClassifierEvent.java
+++ b/core/java/android/view/textclassifier/TextClassifierEvent.java
@@ -35,8 +35,8 @@
* something of note that relates to a feature powered by the TextClassifier. The TextClassifier may
* log these events or use them to improve future responses to queries.
* <p>
- * Each categories of the events have their own subclass. Events of each types has an associated
- * set of related properties. You can find the specification of them in the subclasses.
+ * Each category of events has its their own subclass. Events of each type have an associated
+ * set of related properties. You can find their specification in the subclasses.
*/
public abstract class TextClassifierEvent implements Parcelable {
@@ -146,6 +146,8 @@
@Nullable
private final String mModelName;
private final int[] mActionIndices;
+ @Nullable
+ private final ULocale mLocale;
private final Bundle mExtras;
private TextClassifierEvent(Builder builder) {
@@ -158,6 +160,7 @@
mScores = builder.mScores;
mModelName = builder.mModelName;
mActionIndices = builder.mActionIndices;
+ mLocale = builder.mLocale;
mExtras = builder.mExtras == null ? Bundle.EMPTY : builder.mExtras;
}
@@ -173,6 +176,8 @@
in.readFloatArray(mScores);
mModelName = in.readString();
mActionIndices = in.createIntArray();
+ final String languageTag = in.readString();
+ mLocale = languageTag == null ? null : ULocale.forLanguageTag(languageTag);
mExtras = in.readBundle();
}
@@ -220,6 +225,7 @@
dest.writeFloatArray(mScores);
dest.writeString(mModelName);
dest.writeIntArray(mActionIndices);
+ dest.writeString(mLocale == null ? null : mLocale.toLanguageTag());
dest.writeBundle(mExtras);
}
@@ -318,6 +324,14 @@
}
/**
+ * Returns the detected locale.
+ */
+ @Nullable
+ public ULocale getLocale() {
+ return mLocale;
+ }
+
+ /**
* Returns a bundle containing non-structured extra information about this event.
*
* <p><b>NOTE: </b>Do not modify this bundle.
@@ -365,6 +379,8 @@
private String mModelName;
private int[] mActionIndices = new int[0];
@Nullable
+ private ULocale mLocale;
+ @Nullable
private Bundle mExtras;
/**
@@ -473,6 +489,15 @@
}
/**
+ * Sets the detected locale.
+ */
+ @NonNull
+ public T setLocale(@Nullable ULocale locale) {
+ mLocale = locale;
+ return self();
+ }
+
+ /**
* Sets a bundle containing non-structured extra information about the event.
*
* <p><b>NOTE: </b>Prefer to set only immutable values on the bundle otherwise, avoid
@@ -858,26 +883,12 @@
}
};
- @Nullable
- private final ULocale mLocale;
-
private LanguageDetectionEvent(Parcel in) {
super(in);
- final String languageTag = in.readString();
- mLocale = languageTag == null ? null : ULocale.forLanguageTag(languageTag);
}
private LanguageDetectionEvent(LanguageDetectionEvent.Builder builder) {
super(builder);
- mLocale = builder.mLocale;
- }
-
- /**
- * Returns the detected locale.
- */
- @Nullable
- public ULocale getLocale() {
- return mLocale;
}
/**
@@ -885,8 +896,6 @@
*/
public static final class Builder
extends TextClassifierEvent.Builder<LanguageDetectionEvent.Builder> {
- @Nullable
- private ULocale mLocale;
/**
* Creates a builder for building {@link TextSelectionEvent}s.
@@ -897,15 +906,6 @@
super(TextClassifierEvent.CATEGORY_LANGUAGE_DETECTION, eventType);
}
- /**
- * Sets the detected locale.
- */
- @NonNull
- public Builder setLocale(@Nullable ULocale locale) {
- mLocale = locale;
- return this;
- }
-
@Override
Builder self() {
return this;
@@ -919,12 +919,6 @@
return new LanguageDetectionEvent(this);
}
}
-
- @Override
- public void writeToParcel(Parcel dest, int flags) {
- super.writeToParcel(dest, flags);
- dest.writeString(mLocale == null ? null : mLocale.toLanguageTag());
- }
}
/**