1 /*
2  * Copyright (C) 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.view.translation;
18 
19 import android.annotation.NonNull;
20 import android.icu.util.ULocale;
21 import android.os.Parcel;
22 import android.os.Parcelable;
23 
24 import com.android.internal.util.DataClass;
25 
26 import java.util.Objects;
27 
28 /**
29  * Specs and additional info for the translation data.
30  *
31  * <p>This spec help specify information such as the language/locale for the translation, as well
32  * as the data format for the translation (text, audio, etc.)</p>
33  */
34 @DataClass(genEqualsHashCode = true, genHiddenConstDefs = true, genToString = true,
35         genConstructor = false)
36 public final class TranslationSpec implements Parcelable {
37 
38     /** Data format for translation is text. */
39     public static final int DATA_FORMAT_TEXT = 1;
40 
41     /** @hide */
42     @android.annotation.IntDef(prefix = "DATA_FORMAT_", value = {
43             DATA_FORMAT_TEXT
44     })
45     @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.SOURCE)
46     @DataClass.Generated.Member
47     public @interface DataFormat {}
48 
49     /**
50      * @removed use {@code mLocale} instead.
51      */
52     @Deprecated
53     private final @NonNull String mLanguage;
54 
55     /**
56      * {@link ULocale} representing locale information of this spec.
57      */
58     private final @NonNull ULocale mLocale;
59 
60     private final @DataFormat int mDataFormat;
61 
parcelLocale(Parcel dest, int flags)62     void parcelLocale(Parcel dest, int flags) {
63         dest.writeSerializable(mLocale);
64     }
65 
unparcelLocale(Parcel in)66     static ULocale unparcelLocale(Parcel in) {
67         return (ULocale) in.readSerializable(android.icu.util.ULocale.class.getClassLoader(), android.icu.util.ULocale.class);
68     }
69 
70     /**
71      * @removed use {@link #TranslationSpec(ULocale, int)} instead.
72      */
73     @Deprecated
TranslationSpec(@onNull String language, @DataFormat int dataFormat)74     public TranslationSpec(@NonNull String language, @DataFormat int dataFormat) {
75         mLanguage = language;
76         mDataFormat = dataFormat;
77         mLocale = new ULocale.Builder().setLanguage(language).build();
78     }
79 
80     /**
81      * Constructs a translation spec with the given locale and data format.
82      *
83      * @param locale locale of the associated translation data.
84      * @param dataFormat data format of the associated translation data.
85      */
TranslationSpec(@onNull ULocale locale, @DataFormat int dataFormat)86     public TranslationSpec(@NonNull ULocale locale, @DataFormat int dataFormat) {
87         Objects.requireNonNull(locale);
88         mLanguage = locale.getLanguage();
89         mLocale = locale;
90         mDataFormat = dataFormat;
91     }
92 
93 
94 
95     // Code below generated by codegen v1.0.23.
96     //
97     // DO NOT MODIFY!
98     // CHECKSTYLE:OFF Generated code
99     //
100     // To regenerate run:
101     // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/view/translation/TranslationSpec.java
102     //
103     // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
104     //   Settings > Editor > Code Style > Formatter Control
105     //@formatter:off
106 
107 
108     /**
109      * @removed use {@code mLocale} instead.
110      */
111     @DataClass.Generated.Member
getLanguage()112     public @Deprecated @NonNull String getLanguage() {
113         return mLanguage;
114     }
115 
116     /**
117      * {@link ULocale} representing locale information of this spec.
118      */
119     @DataClass.Generated.Member
getLocale()120     public @NonNull ULocale getLocale() {
121         return mLocale;
122     }
123 
124     @DataClass.Generated.Member
getDataFormat()125     public @DataFormat int getDataFormat() {
126         return mDataFormat;
127     }
128 
129     @Override
130     @DataClass.Generated.Member
toString()131     public String toString() {
132         // You can override field toString logic by defining methods like:
133         // String fieldNameToString() { ... }
134 
135         return "TranslationSpec { " +
136                 "language = " + mLanguage + ", " +
137                 "locale = " + mLocale + ", " +
138                 "dataFormat = " + mDataFormat +
139         " }";
140     }
141 
142     @Override
143     @DataClass.Generated.Member
equals(@ndroid.annotation.Nullable Object o)144     public boolean equals(@android.annotation.Nullable Object o) {
145         // You can override field equality logic by defining either of the methods like:
146         // boolean fieldNameEquals(TranslationSpec other) { ... }
147         // boolean fieldNameEquals(FieldType otherValue) { ... }
148 
149         if (this == o) return true;
150         if (o == null || getClass() != o.getClass()) return false;
151         @SuppressWarnings("unchecked")
152         TranslationSpec that = (TranslationSpec) o;
153         //noinspection PointlessBooleanExpression
154         return true
155                 && Objects.equals(mLanguage, that.mLanguage)
156                 && Objects.equals(mLocale, that.mLocale)
157                 && mDataFormat == that.mDataFormat;
158     }
159 
160     @Override
161     @DataClass.Generated.Member
hashCode()162     public int hashCode() {
163         // You can override field hashCode logic by defining methods like:
164         // int fieldNameHashCode() { ... }
165 
166         int _hash = 1;
167         _hash = 31 * _hash + Objects.hashCode(mLanguage);
168         _hash = 31 * _hash + Objects.hashCode(mLocale);
169         _hash = 31 * _hash + mDataFormat;
170         return _hash;
171     }
172 
173     @Override
174     @DataClass.Generated.Member
writeToParcel(@onNull Parcel dest, int flags)175     public void writeToParcel(@NonNull Parcel dest, int flags) {
176         // You can override field parcelling by defining methods like:
177         // void parcelFieldName(Parcel dest, int flags) { ... }
178 
179         dest.writeString(mLanguage);
180         parcelLocale(dest, flags);
181         dest.writeInt(mDataFormat);
182     }
183 
184     @Override
185     @DataClass.Generated.Member
describeContents()186     public int describeContents() { return 0; }
187 
188     /** @hide */
189     @SuppressWarnings({"unchecked", "RedundantCast"})
190     @DataClass.Generated.Member
TranslationSpec(@onNull Parcel in)191     /* package-private */ TranslationSpec(@NonNull Parcel in) {
192         // You can override field unparcelling by defining methods like:
193         // static FieldType unparcelFieldName(Parcel in) { ... }
194 
195         String language = in.readString();
196         ULocale locale = unparcelLocale(in);
197         int dataFormat = in.readInt();
198 
199         this.mLanguage = language;
200         com.android.internal.util.AnnotationValidations.validate(
201                 Deprecated.class, null, mLanguage);
202         com.android.internal.util.AnnotationValidations.validate(
203                 NonNull.class, null, mLanguage);
204         this.mLocale = locale;
205         com.android.internal.util.AnnotationValidations.validate(
206                 NonNull.class, null, mLocale);
207         this.mDataFormat = dataFormat;
208         com.android.internal.util.AnnotationValidations.validate(
209                 DataFormat.class, null, mDataFormat);
210 
211         // onConstructed(); // You can define this method to get a callback
212     }
213 
214     @DataClass.Generated.Member
215     public static final @NonNull Parcelable.Creator<TranslationSpec> CREATOR
216             = new Parcelable.Creator<TranslationSpec>() {
217         @Override
218         public TranslationSpec[] newArray(int size) {
219             return new TranslationSpec[size];
220         }
221 
222         @Override
223         public TranslationSpec createFromParcel(@NonNull Parcel in) {
224             return new TranslationSpec(in);
225         }
226     };
227 
228     @DataClass.Generated(
229             time = 1620089623334L,
230             codegenVersion = "1.0.23",
231             sourceFile = "frameworks/base/core/java/android/view/translation/TranslationSpec.java",
232             inputSignatures = "public static final  int DATA_FORMAT_TEXT\nprivate final @java.lang.Deprecated @android.annotation.NonNull java.lang.String mLanguage\nprivate final @android.annotation.NonNull android.icu.util.ULocale mLocale\nprivate final @android.view.translation.TranslationSpec.DataFormat int mDataFormat\n  void parcelLocale(android.os.Parcel,int)\nstatic  android.icu.util.ULocale unparcelLocale(android.os.Parcel)\nclass TranslationSpec extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genEqualsHashCode=true, genHiddenConstDefs=true, genToString=true, genConstructor=false)")
233     @Deprecated
__metadata()234     private void __metadata() {}
235 
236 
237     //@formatter:on
238     // End of generated code
239 
240 }
241