Merge "Change dictionary results to use a bundle instead since it is a structured result." into sc-dev

This commit is contained in:
Adam He
2021-05-18 18:49:03 +00:00
committed by Android (Google) Code Review
4 changed files with 65 additions and 48 deletions

View File

@@ -52846,7 +52846,7 @@ package android.view.translation {
method public int getTranslationFlags();
method public void writeToParcel(@NonNull android.os.Parcel, int);
field @NonNull public static final android.os.Parcelable.Creator<android.view.translation.TranslationContext> CREATOR;
field public static final int FLAG_DICTIONARY_DESCRIPTION = 4; // 0x4
field public static final int FLAG_DEFINITIONS = 4; // 0x4
field public static final int FLAG_LOW_LATENCY = 1; // 0x1
field public static final int FLAG_TRANSLITERATION = 2; // 0x2
}
@@ -52931,12 +52931,13 @@ package android.view.translation {
public final class TranslationResponseValue implements android.os.Parcelable {
method public int describeContents();
method @NonNull public static android.view.translation.TranslationResponseValue forError();
method @Nullable public CharSequence getDictionaryDescription();
method @NonNull public android.os.Bundle getExtras();
method public int getStatusCode();
method @Nullable public CharSequence getText();
method @Nullable public CharSequence getTransliteration();
method public void writeToParcel(@NonNull android.os.Parcel, int);
field @NonNull public static final android.os.Parcelable.Creator<android.view.translation.TranslationResponseValue> CREATOR;
field public static final String EXTRA_DEFINITIONS = "android.view.translation.extra.DEFINITIONS";
field public static final int STATUS_ERROR = 1; // 0x1
field public static final int STATUS_SUCCESS = 0; // 0x0
}
@@ -52944,7 +52945,7 @@ package android.view.translation {
public static final class TranslationResponseValue.Builder {
ctor public TranslationResponseValue.Builder(int);
method @NonNull public android.view.translation.TranslationResponseValue build();
method @NonNull public android.view.translation.TranslationResponseValue.Builder setDictionaryDescription(@NonNull CharSequence);
method @NonNull public android.view.translation.TranslationResponseValue.Builder setExtras(@NonNull android.os.Bundle);
method @NonNull public android.view.translation.TranslationResponseValue.Builder setText(@NonNull CharSequence);
method @NonNull public android.view.translation.TranslationResponseValue.Builder setTransliteration(@NonNull CharSequence);
}

View File

@@ -37,9 +37,9 @@ public final class TranslationContext implements Parcelable {
*/
public static final @TranslationFlag int FLAG_TRANSLITERATION = 0x2;
/**
* This context will enable the {@link Translator} to return dictionary results.
* This context will enable the {@link Translator} to return dictionary definitions.
*/
public static final @TranslationFlag int FLAG_DICTIONARY_DESCRIPTION = 0x4;
public static final @TranslationFlag int FLAG_DEFINITIONS = 0x4;
/**
* {@link TranslationSpec} describing the source data to be translated.
@@ -69,7 +69,7 @@ public final class TranslationContext implements Parcelable {
// Code below generated by codegen v1.0.22.
// Code below generated by codegen v1.0.23.
//
// DO NOT MODIFY!
// CHECKSTYLE:OFF Generated code
@@ -86,7 +86,7 @@ public final class TranslationContext implements Parcelable {
@android.annotation.IntDef(flag = true, prefix = "FLAG_", value = {
FLAG_LOW_LATENCY,
FLAG_TRANSLITERATION,
FLAG_DICTIONARY_DESCRIPTION
FLAG_DEFINITIONS
})
@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.SOURCE)
@DataClass.Generated.Member
@@ -106,8 +106,8 @@ public final class TranslationContext implements Parcelable {
return "FLAG_LOW_LATENCY";
case FLAG_TRANSLITERATION:
return "FLAG_TRANSLITERATION";
case FLAG_DICTIONARY_DESCRIPTION:
return "FLAG_DICTIONARY_DESCRIPTION";
case FLAG_DEFINITIONS:
return "FLAG_DEFINITIONS";
default: return Integer.toHexString(value);
}
}
@@ -129,7 +129,7 @@ public final class TranslationContext implements Parcelable {
mTranslationFlags,
FLAG_LOW_LATENCY
| FLAG_TRANSLITERATION
| FLAG_DICTIONARY_DESCRIPTION);
| FLAG_DEFINITIONS);
// onConstructed(); // You can define this method to get a callback
}
@@ -209,7 +209,7 @@ public final class TranslationContext implements Parcelable {
mTranslationFlags,
FLAG_LOW_LATENCY
| FLAG_TRANSLITERATION
| FLAG_DICTIONARY_DESCRIPTION);
| FLAG_DEFINITIONS);
// onConstructed(); // You can define this method to get a callback
}
@@ -295,10 +295,10 @@ public final class TranslationContext implements Parcelable {
}
@DataClass.Generated(
time = 1616199021789L,
codegenVersion = "1.0.22",
time = 1621034221152L,
codegenVersion = "1.0.23",
sourceFile = "frameworks/base/core/java/android/view/translation/TranslationContext.java",
inputSignatures = "public static final @android.view.translation.TranslationContext.TranslationFlag int FLAG_LOW_LATENCY\npublic static final @android.view.translation.TranslationContext.TranslationFlag int FLAG_TRANSLITERATION\npublic static final @android.view.translation.TranslationContext.TranslationFlag int FLAG_DICTIONARY_DESCRIPTION\nprivate final @android.annotation.NonNull android.view.translation.TranslationSpec mSourceSpec\nprivate final @android.annotation.NonNull android.view.translation.TranslationSpec mTargetSpec\nprivate final @android.view.translation.TranslationContext.TranslationFlag int mTranslationFlags\nprivate static int defaultTranslationFlags()\nclass TranslationContext extends java.lang.Object implements [android.os.Parcelable]\nclass BaseBuilder extends java.lang.Object implements []\n@com.android.internal.util.DataClass(genHiddenConstDefs=true, genToString=true, genBuilder=true)\nclass BaseBuilder extends java.lang.Object implements []")
inputSignatures = "public static final @android.view.translation.TranslationContext.TranslationFlag int FLAG_LOW_LATENCY\npublic static final @android.view.translation.TranslationContext.TranslationFlag int FLAG_TRANSLITERATION\npublic static final @android.view.translation.TranslationContext.TranslationFlag int FLAG_DEFINITIONS\nprivate final @android.annotation.NonNull android.view.translation.TranslationSpec mSourceSpec\nprivate final @android.annotation.NonNull android.view.translation.TranslationSpec mTargetSpec\nprivate final @android.view.translation.TranslationContext.TranslationFlag int mTranslationFlags\nprivate static int defaultTranslationFlags()\nclass TranslationContext extends java.lang.Object implements [android.os.Parcelable]\nclass BaseBuilder extends java.lang.Object implements []\n@com.android.internal.util.DataClass(genHiddenConstDefs=true, genToString=true, genBuilder=true)\nclass BaseBuilder extends java.lang.Object implements []")
@Deprecated
private void __metadata() {}

View File

@@ -18,6 +18,7 @@ package android.view.translation;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
@@ -41,6 +42,17 @@ public final class TranslationResponseValue implements Parcelable {
*/
public static final int STATUS_ERROR = 1;
/**
* Name in the result of {@link #getExtras()} to pass dictionary definitions of the text
* categorized by parts of speech.
*
* <p>The dictionary definitions consists of groups of terms keyed by their corresponding parts
* of speech. This map-like structure is stored in a {@link Bundle}. The individual parts of
* speech can be traversed by {@link Bundle#keySet()} and used to get the corresponding list
* of terms as {@link CharSequence}s.</p>
*/
public static final String EXTRA_DEFINITIONS = "android.view.translation.extra.DEFINITIONS";
/**
* The status code of this {@link TranslationResponseValue}.
*
@@ -56,11 +68,12 @@ public final class TranslationResponseValue implements Parcelable {
private final CharSequence mText;
/**
* The dictionary description of the translated text.
* TODO: Describe the result structure.
* Extra results associated with the translated text.
*
* <p>The bundle includes {@link #EXTRA_DEFINITIONS}, obtained by {@link Bundle#getBundle}.</p>
*/
@Nullable
private final CharSequence mDictionaryDescription;
@NonNull
private final Bundle mExtras;
/**
* The transliteration result of the translated text.
@@ -74,15 +87,15 @@ public final class TranslationResponseValue implements Parcelable {
*/
@NonNull
public static TranslationResponseValue forError() {
return new TranslationResponseValue(STATUS_ERROR, null, null, null);
return new TranslationResponseValue(STATUS_ERROR, null, Bundle.EMPTY, null);
}
private static CharSequence defaultText() {
return null;
}
private static CharSequence defaultDictionaryDescription() {
return null;
private static Bundle defaultExtras() {
return Bundle.EMPTY;
}
private static CharSequence defaultTransliteration() {
@@ -96,7 +109,7 @@ public final class TranslationResponseValue implements Parcelable {
// Code below generated by codegen v1.0.22.
// Code below generated by codegen v1.0.23.
//
// DO NOT MODIFY!
// CHECKSTYLE:OFF Generated code
@@ -134,7 +147,7 @@ public final class TranslationResponseValue implements Parcelable {
/* package-private */ TranslationResponseValue(
@Status int statusCode,
@Nullable CharSequence text,
@Nullable CharSequence dictionaryDescription,
@NonNull Bundle extras,
@Nullable CharSequence transliteration) {
this.mStatusCode = statusCode;
@@ -147,7 +160,9 @@ public final class TranslationResponseValue implements Parcelable {
}
this.mText = text;
this.mDictionaryDescription = dictionaryDescription;
this.mExtras = extras;
com.android.internal.util.AnnotationValidations.validate(
NonNull.class, null, mExtras);
this.mTransliteration = transliteration;
// onConstructed(); // You can define this method to get a callback
@@ -173,12 +188,13 @@ public final class TranslationResponseValue implements Parcelable {
}
/**
* The dictionary description of the translated text.
* TODO: Describe the result structure.
* Extra results associated with the translated text.
*
* <p>The bundle includes {@link #EXTRA_DEFINITIONS}, obtained by {@link Bundle#getBundle}.</p>
*/
@DataClass.Generated.Member
public @Nullable CharSequence getDictionaryDescription() {
return mDictionaryDescription;
public @NonNull Bundle getExtras() {
return mExtras;
}
/**
@@ -199,7 +215,7 @@ public final class TranslationResponseValue implements Parcelable {
return "TranslationResponseValue { " +
"statusCode = " + statusToString(mStatusCode) + ", " +
"text = " + mText + ", " +
"dictionaryDescription = " + mDictionaryDescription + ", " +
"extras = " + mExtras + ", " +
"transliteration = " + mTransliteration +
" }";
}
@@ -219,7 +235,7 @@ public final class TranslationResponseValue implements Parcelable {
return true
&& mStatusCode == that.mStatusCode
&& Objects.equals(mText, that.mText)
&& Objects.equals(mDictionaryDescription, that.mDictionaryDescription)
&& Objects.equals(mExtras, that.mExtras)
&& Objects.equals(mTransliteration, that.mTransliteration);
}
@@ -232,7 +248,7 @@ public final class TranslationResponseValue implements Parcelable {
int _hash = 1;
_hash = 31 * _hash + mStatusCode;
_hash = 31 * _hash + Objects.hashCode(mText);
_hash = 31 * _hash + Objects.hashCode(mDictionaryDescription);
_hash = 31 * _hash + Objects.hashCode(mExtras);
_hash = 31 * _hash + Objects.hashCode(mTransliteration);
return _hash;
}
@@ -245,12 +261,11 @@ public final class TranslationResponseValue implements Parcelable {
byte flg = 0;
if (mText != null) flg |= 0x2;
if (mDictionaryDescription != null) flg |= 0x4;
if (mTransliteration != null) flg |= 0x8;
dest.writeByte(flg);
dest.writeInt(mStatusCode);
if (mText != null) dest.writeCharSequence(mText);
if (mDictionaryDescription != null) dest.writeCharSequence(mDictionaryDescription);
dest.writeBundle(mExtras);
if (mTransliteration != null) dest.writeCharSequence(mTransliteration);
}
@@ -268,7 +283,7 @@ public final class TranslationResponseValue implements Parcelable {
byte flg = in.readByte();
int statusCode = in.readInt();
CharSequence text = (flg & 0x2) == 0 ? null : (CharSequence) in.readCharSequence();
CharSequence dictionaryDescription = (flg & 0x4) == 0 ? null : (CharSequence) in.readCharSequence();
Bundle extras = in.readBundle();
CharSequence transliteration = (flg & 0x8) == 0 ? null : (CharSequence) in.readCharSequence();
this.mStatusCode = statusCode;
@@ -282,7 +297,9 @@ public final class TranslationResponseValue implements Parcelable {
}
this.mText = text;
this.mDictionaryDescription = dictionaryDescription;
this.mExtras = extras;
com.android.internal.util.AnnotationValidations.validate(
NonNull.class, null, mExtras);
this.mTransliteration = transliteration;
// onConstructed(); // You can define this method to get a callback
@@ -311,7 +328,7 @@ public final class TranslationResponseValue implements Parcelable {
private @Status int mStatusCode;
private @Nullable CharSequence mText;
private @Nullable CharSequence mDictionaryDescription;
private @NonNull Bundle mExtras;
private @Nullable CharSequence mTransliteration;
private long mBuilderFieldsSet = 0L;
@@ -351,14 +368,15 @@ public final class TranslationResponseValue implements Parcelable {
}
/**
* The dictionary description of the translated text.
* TODO: Describe the result structure.
* Extra results associated with the translated text.
*
* <p>The bundle includes {@link #EXTRA_DEFINITIONS}, obtained by {@link Bundle#getBundle}.</p>
*/
@DataClass.Generated.Member
public @NonNull Builder setDictionaryDescription(@NonNull CharSequence value) {
public @NonNull Builder setExtras(@NonNull Bundle value) {
checkNotUsed();
mBuilderFieldsSet |= 0x4;
mDictionaryDescription = value;
mExtras = value;
return this;
}
@@ -383,7 +401,7 @@ public final class TranslationResponseValue implements Parcelable {
mText = defaultText();
}
if ((mBuilderFieldsSet & 0x4) == 0) {
mDictionaryDescription = defaultDictionaryDescription();
mExtras = defaultExtras();
}
if ((mBuilderFieldsSet & 0x8) == 0) {
mTransliteration = defaultTransliteration();
@@ -391,7 +409,7 @@ public final class TranslationResponseValue implements Parcelable {
TranslationResponseValue o = new TranslationResponseValue(
mStatusCode,
mText,
mDictionaryDescription,
mExtras,
mTransliteration);
return o;
}
@@ -405,10 +423,10 @@ public final class TranslationResponseValue implements Parcelable {
}
@DataClass.Generated(
time = 1614983829716L,
codegenVersion = "1.0.22",
time = 1621034223313L,
codegenVersion = "1.0.23",
sourceFile = "frameworks/base/core/java/android/view/translation/TranslationResponseValue.java",
inputSignatures = "public static final int STATUS_SUCCESS\npublic static final int STATUS_ERROR\nprivate final @android.view.translation.TranslationResponseValue.Status int mStatusCode\nprivate final @android.annotation.Nullable java.lang.CharSequence mText\nprivate final @android.annotation.Nullable java.lang.CharSequence mDictionaryDescription\nprivate final @android.annotation.Nullable java.lang.CharSequence mTransliteration\npublic static @android.annotation.NonNull android.view.translation.TranslationResponseValue forError()\nprivate static java.lang.CharSequence defaultText()\nprivate static java.lang.CharSequence defaultDictionaryDescription()\nprivate static java.lang.CharSequence defaultTransliteration()\nclass TranslationResponseValue extends java.lang.Object implements [android.os.Parcelable]\nclass BaseBuilder extends java.lang.Object implements []\n@com.android.internal.util.DataClass(genBuilder=true, genToString=true, genEqualsHashCode=true, genHiddenConstDefs=true)\nclass BaseBuilder extends java.lang.Object implements []")
inputSignatures = "public static final int STATUS_SUCCESS\npublic static final int STATUS_ERROR\npublic static final java.lang.String EXTRA_DEFINITIONS\nprivate final @android.view.translation.TranslationResponseValue.Status int mStatusCode\nprivate final @android.annotation.Nullable java.lang.CharSequence mText\nprivate final @android.annotation.NonNull android.os.Bundle mExtras\nprivate final @android.annotation.Nullable java.lang.CharSequence mTransliteration\npublic static @android.annotation.NonNull android.view.translation.TranslationResponseValue forError()\nprivate static java.lang.CharSequence defaultText()\nprivate static android.os.Bundle defaultExtras()\nprivate static java.lang.CharSequence defaultTransliteration()\nclass TranslationResponseValue extends java.lang.Object implements [android.os.Parcelable]\nclass BaseBuilder extends java.lang.Object implements []\n@com.android.internal.util.DataClass(genBuilder=true, genToString=true, genEqualsHashCode=true, genHiddenConstDefs=true)\nclass BaseBuilder extends java.lang.Object implements []")
@Deprecated
private void __metadata() {}

View File

@@ -658,9 +658,7 @@ public class UiTranslationController {
msg.append("text=").append(value.getText() == null
? "null"
: "string[" + value.getText().length() + "], ");
msg.append("dict=").append(value.getDictionaryDescription() == null
? "null"
: "string[" + value.getDictionaryDescription().length() + "], ");
//TODO: append dictionary results.
msg.append("transliteration=").append(value.getTransliteration() == null
? "null"
: "string[" + value.getTransliteration().length() + "]}, ");