Debian Codegraph @

core/java/android/view/translation/TranslationRequest.java

raw symbols SCIP
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.os.Parcel;
21 import android.os.Parcelable;
22
23 import com.android.internal.util.DataClass;
24
25 import java.util.ArrayList;
26 import java.util.Collections;
27 import java.util.List;
28
29 /**
30 * Translation request sent to the {@link android.service.translation.TranslationService} by the
31 * {@link android.view.translation.Translator} which contains the text to be translated.
32 */
33 @DataClass(genToString = true, genHiddenConstDefs = true, genBuilder = true)
34 public final class TranslationRequest implements Parcelable {
35
36 /**
37 * Indicates this request wants to receive the standard translation result.
38 */
39 public static final @RequestFlags int FLAG_TRANSLATION_RESULT = 0x1;
40 /**
41 * Indicates this request wants to receive the dictionary result.
42 *
43 * <p>See {@link TranslationResponseValue#EXTRA_DEFINITIONS} for more detail on the structure
44 * of the returned data.
45 */
46 public static final @RequestFlags int FLAG_DICTIONARY_RESULT = 0x2;
47 /**
48 * Indicates this request wants to receive the transliteration result.
49 *
50 * <p>This returns a CharSequence representation of the transliteration of the translated text.
51 * See {@link TranslationResponseValue#getTransliteration()}.
52 */
53 public static final @RequestFlags int FLAG_TRANSLITERATION_RESULT = 0x4;
54 /**
55 * Indicates this request is willing to accept partial responses.
56 *
57 * <p>The partial responses can be accessed by
58 * {@link TranslationResponse#getTranslationResponseValues()} or
59 * {@link TranslationResponse#getViewTranslationResponses()}. These responses will each contain
60 * only a subset of the corresponding translated values.
61 *
62 * <p>The are no guarantees to the number of translated values or the order in which these
63 * values are returned in the {@link TranslationResponse}.
64 *
65 * <p>This flag denotes the client can expect multiple partial responses, but there may not
66 * necessarily be multiple responses.</p>
67 */
68 public static final @RequestFlags int FLAG_PARTIAL_RESPONSES = 0x8;
69
70 /**
71 * Request flags. {@link #FLAG_TRANSLATION_RESULT} by default.
72 */
73 private final @RequestFlags int mFlags;
74
75 /**
76 * List of {@link TranslationRequestValue}s to be translated. The index of entries in this list
77 * will be their respective key in the {@link android.util.SparseArray} returned by calling
78 * {@link TranslationResponse#getTranslationResponseValues()}.
79 */
80 @NonNull
81 @DataClass.PluralOf("translationRequestValue")
82 private final List<TranslationRequestValue> mTranslationRequestValues;
83
84 /**
85 * List of {@link ViewTranslationRequest}s to be translated. The index of entries in this list
86 * will be their respective key in the {@link android.util.SparseArray} returned by calling
87 * {@link TranslationResponse#getViewTranslationResponses()}.
88 */
89 @NonNull
90 @DataClass.PluralOf("viewTranslationRequest")
91 private final List<ViewTranslationRequest> mViewTranslationRequests;
92
93 private static int defaultFlags() {
94 return FLAG_TRANSLATION_RESULT;
95 }
96
97 private static List<TranslationRequestValue> defaultTranslationRequestValues() {
98 return Collections.emptyList();
99 }
100
101 private static List<ViewTranslationRequest> defaultViewTranslationRequests() {
102 return Collections.emptyList();
103 }
104
105 abstract static class BaseBuilder {
106 /**
107 * @removed use {@link Builder#setTranslationRequestValues(List)}.
108 */
109 @Deprecated
110 public abstract Builder addTranslationRequestValue(
111 @NonNull TranslationRequestValue value);
112
113 /**
114 * @removed use {@link Builder#setViewTranslationRequests(List)}.
115 */
116 @Deprecated
117 public abstract Builder addViewTranslationRequest(
118 @NonNull ViewTranslationRequest value);
119
120 }
121
122
123
124 // Code below generated by codegen v1.0.23.
125 //
126 // DO NOT MODIFY!
127 // CHECKSTYLE:OFF Generated code
128 //
129 // To regenerate run:
130 // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/view/translation/TranslationRequest.java
131 //
132 // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
133 // Settings > Editor > Code Style > Formatter Control
134 //@formatter:off
135
136
137 /** @hide */
138 @android.annotation.IntDef(flag = true, prefix = "FLAG_", value = {
139 FLAG_TRANSLATION_RESULT,
140 FLAG_DICTIONARY_RESULT,
141 FLAG_TRANSLITERATION_RESULT,
142 FLAG_PARTIAL_RESPONSES
143 })
144 @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.SOURCE)
145 @DataClass.Generated.Member
146 public @interface RequestFlags {}
147
148 /** @hide */
149 @DataClass.Generated.Member
150 public static String requestFlagsToString(@RequestFlags int value) {
151 return com.android.internal.util.BitUtils.flagsToString(
152 value, TranslationRequest::singleRequestFlagsToString);
153 }
154
155 @DataClass.Generated.Member
156 static String singleRequestFlagsToString(@RequestFlags int value) {
157 switch (value) {
158 case FLAG_TRANSLATION_RESULT:
159 return "FLAG_TRANSLATION_RESULT";
160 case FLAG_DICTIONARY_RESULT:
161 return "FLAG_DICTIONARY_RESULT";
162 case FLAG_TRANSLITERATION_RESULT:
163 return "FLAG_TRANSLITERATION_RESULT";
164 case FLAG_PARTIAL_RESPONSES:
165 return "FLAG_PARTIAL_RESPONSES";
166 default: return Integer.toHexString(value);
167 }
168 }
169
170 @DataClass.Generated.Member
171 /* package-private */ TranslationRequest(
172 @RequestFlags int flags,
173 @NonNull List<TranslationRequestValue> translationRequestValues,
174 @NonNull List<ViewTranslationRequest> viewTranslationRequests) {
175 this.mFlags = flags;
176
177 com.android.internal.util.Preconditions.checkFlagsArgument(
178 mFlags,
179 FLAG_TRANSLATION_RESULT
180 | FLAG_DICTIONARY_RESULT
181 | FLAG_TRANSLITERATION_RESULT
182 | FLAG_PARTIAL_RESPONSES);
183 this.mTranslationRequestValues = translationRequestValues;
184 com.android.internal.util.AnnotationValidations.validate(
185 NonNull.class, null, mTranslationRequestValues);
186 this.mViewTranslationRequests = viewTranslationRequests;
187 com.android.internal.util.AnnotationValidations.validate(
188 NonNull.class, null, mViewTranslationRequests);
189
190 // onConstructed(); // You can define this method to get a callback
191 }
192
193 /**
194 * Request flags. {@link #FLAG_TRANSLATION_RESULT} by default.
195 */
196 @DataClass.Generated.Member
197 public @RequestFlags int getFlags() {
198 return mFlags;
199 }
200
201 /**
202 * List of {@link TranslationRequestValue}s to be translated. The index of entries in this list
203 * will be their respective key in the {@link android.util.SparseArray} returned by calling
204 * {@link TranslationResponse#getTranslationResponseValues()}.
205 */
206 @DataClass.Generated.Member
207 public @NonNull List<TranslationRequestValue> getTranslationRequestValues() {
208 return mTranslationRequestValues;
209 }
210
211 /**
212 * List of {@link ViewTranslationRequest}s to be translated. The index of entries in this list
213 * will be their respective key in the {@link android.util.SparseArray} returned by calling
214 * {@link TranslationResponse#getViewTranslationResponses()}.
215 */
216 @DataClass.Generated.Member
217 public @NonNull List<ViewTranslationRequest> getViewTranslationRequests() {
218 return mViewTranslationRequests;
219 }
220
221 @Override
222 @DataClass.Generated.Member
223 public String toString() {
224 // You can override field toString logic by defining methods like:
225 // String fieldNameToString() { ... }
226
227 return "TranslationRequest { " +
228 "flags = " + requestFlagsToString(mFlags) + ", " +
229 "translationRequestValues = " + mTranslationRequestValues + ", " +
230 "viewTranslationRequests = " + mViewTranslationRequests +
231 " }";
232 }
233
234 @Override
235 @DataClass.Generated.Member
236 public void writeToParcel(@NonNull Parcel dest, int flags) {
237 // You can override field parcelling by defining methods like:
238 // void parcelFieldName(Parcel dest, int flags) { ... }
239
240 dest.writeInt(mFlags);
241 dest.writeParcelableList(mTranslationRequestValues, flags);
242 dest.writeParcelableList(mViewTranslationRequests, flags);
243 }
244
245 @Override
246 @DataClass.Generated.Member
247 public int describeContents() { return 0; }
248
249 /** @hide */
250 @SuppressWarnings({"unchecked", "RedundantCast"})
251 @DataClass.Generated.Member
252 /* package-private */ TranslationRequest(@NonNull Parcel in) {
253 // You can override field unparcelling by defining methods like:
254 // static FieldType unparcelFieldName(Parcel in) { ... }
255
256 int flags = in.readInt();
257 List<TranslationRequestValue> translationRequestValues = new ArrayList<>();
258 in.readParcelableList(translationRequestValues, TranslationRequestValue.class.getClassLoader(), android.view.translation.TranslationRequestValue.class);
259 List<ViewTranslationRequest> viewTranslationRequests = new ArrayList<>();
260 in.readParcelableList(viewTranslationRequests, ViewTranslationRequest.class.getClassLoader(), android.view.translation.ViewTranslationRequest.class);
261
262 this.mFlags = flags;
263
264 com.android.internal.util.Preconditions.checkFlagsArgument(
265 mFlags,
266 FLAG_TRANSLATION_RESULT
267 | FLAG_DICTIONARY_RESULT
268 | FLAG_TRANSLITERATION_RESULT
269 | FLAG_PARTIAL_RESPONSES);
270 this.mTranslationRequestValues = translationRequestValues;
271 com.android.internal.util.AnnotationValidations.validate(
272 NonNull.class, null, mTranslationRequestValues);
273 this.mViewTranslationRequests = viewTranslationRequests;
274 com.android.internal.util.AnnotationValidations.validate(
275 NonNull.class, null, mViewTranslationRequests);
276
277 // onConstructed(); // You can define this method to get a callback
278 }
279
280 @DataClass.Generated.Member
281 public static final @NonNull Parcelable.Creator<TranslationRequest> CREATOR
282 = new Parcelable.Creator<TranslationRequest>() {
283 @Override
284 public TranslationRequest[] newArray(int size) {
285 return new TranslationRequest[size];
286 }
287
288 @Override
289 public TranslationRequest createFromParcel(@NonNull Parcel in) {
290 return new TranslationRequest(in);
291 }
292 };
293
294 /**
295 * A builder for {@link TranslationRequest}
296 */
297 @SuppressWarnings("WeakerAccess")
298 @DataClass.Generated.Member
299 public static final class Builder extends BaseBuilder {
300
301 private @RequestFlags int mFlags;
302 private @NonNull List<TranslationRequestValue> mTranslationRequestValues;
303 private @NonNull List<ViewTranslationRequest> mViewTranslationRequests;
304
305 private long mBuilderFieldsSet = 0L;
306
307 public Builder() {
308 }
309
310 /**
311 * Request flags. {@link #FLAG_TRANSLATION_RESULT} by default.
312 */
313 @DataClass.Generated.Member
314 public @NonNull Builder setFlags(@RequestFlags int value) {
315 checkNotUsed();
316 mBuilderFieldsSet |= 0x1;
317 mFlags = value;
318 return this;
319 }
320
321 /**
322 * List of {@link TranslationRequestValue}s to be translated. The index of entries in this list
323 * will be their respective key in the {@link android.util.SparseArray} returned by calling
324 * {@link TranslationResponse#getTranslationResponseValues()}.
325 */
326 @DataClass.Generated.Member
327 public @NonNull Builder setTranslationRequestValues(@NonNull List<TranslationRequestValue> value) {
328 checkNotUsed();
329 mBuilderFieldsSet |= 0x2;
330 mTranslationRequestValues = value;
331 return this;
332 }
333
334 /**
335 * @see #setTranslationRequestValues
336 * @removed
337 */
338 @DataClass.Generated.Member
339 @Override
340 @Deprecated
341 public @NonNull Builder addTranslationRequestValue(@NonNull TranslationRequestValue value) {
342 if (mTranslationRequestValues == null) setTranslationRequestValues(new ArrayList<>());
343 mTranslationRequestValues.add(value);
344 return this;
345 }
346
347 /**
348 * List of {@link ViewTranslationRequest}s to be translated. The index of entries in this list
349 * will be their respective key in the {@link android.util.SparseArray} returned by calling
350 * {@link TranslationResponse#getViewTranslationResponses()}.
351 */
352 @DataClass.Generated.Member
353 public @NonNull Builder setViewTranslationRequests(@NonNull List<ViewTranslationRequest> value) {
354 checkNotUsed();
355 mBuilderFieldsSet |= 0x4;
356 mViewTranslationRequests = value;
357 return this;
358 }
359
360 /**
361 * @see #setViewTranslationRequests
362 * @removed
363 */
364 @DataClass.Generated.Member
365 @Override
366 @Deprecated
367 public @NonNull Builder addViewTranslationRequest(@NonNull ViewTranslationRequest value) {
368 if (mViewTranslationRequests == null) setViewTranslationRequests(new ArrayList<>());
369 mViewTranslationRequests.add(value);
370 return this;
371 }
372
373 /** Builds the instance. This builder should not be touched after calling this! */
374 public @NonNull TranslationRequest build() {
375 checkNotUsed();
376 mBuilderFieldsSet |= 0x8; // Mark builder used
377
378 if ((mBuilderFieldsSet & 0x1) == 0) {
379 mFlags = defaultFlags();
380 }
381 if ((mBuilderFieldsSet & 0x2) == 0) {
382 mTranslationRequestValues = defaultTranslationRequestValues();
383 }
384 if ((mBuilderFieldsSet & 0x4) == 0) {
385 mViewTranslationRequests = defaultViewTranslationRequests();
386 }
387 TranslationRequest o = new TranslationRequest(
388 mFlags,
389 mTranslationRequestValues,
390 mViewTranslationRequests);
391 return o;
392 }
393
394 private void checkNotUsed() {
395 if ((mBuilderFieldsSet & 0x8) != 0) {
396 throw new IllegalStateException(
397 "This Builder should not be reused. Use a new Builder instance instead");
398 }
399 }
400 }
401
402 @DataClass.Generated(
403 time = 1629159107226L,
404 codegenVersion = "1.0.23",
405 sourceFile = "frameworks/base/core/java/android/view/translation/TranslationRequest.java",
406 inputSignatures = "public static final @android.view.translation.TranslationRequest.RequestFlags int FLAG_TRANSLATION_RESULT\npublic static final @android.view.translation.TranslationRequest.RequestFlags int FLAG_DICTIONARY_RESULT\npublic static final @android.view.translation.TranslationRequest.RequestFlags int FLAG_TRANSLITERATION_RESULT\npublic static final @android.view.translation.TranslationRequest.RequestFlags int FLAG_PARTIAL_RESPONSES\nprivate final @android.view.translation.TranslationRequest.RequestFlags int mFlags\nprivate final @android.annotation.NonNull @com.android.internal.util.DataClass.PluralOf(\"translationRequestValue\") java.util.List<android.view.translation.TranslationRequestValue> mTranslationRequestValues\nprivate final @android.annotation.NonNull @com.android.internal.util.DataClass.PluralOf(\"viewTranslationRequest\") java.util.List<android.view.translation.ViewTranslationRequest> mViewTranslationRequests\nprivate static int defaultFlags()\nprivate static java.util.List<android.view.translation.TranslationRequestValue> defaultTranslationRequestValues()\nprivate static java.util.List<android.view.translation.ViewTranslationRequest> defaultViewTranslationRequests()\nclass TranslationRequest extends java.lang.Object implements [android.os.Parcelable]\npublic abstract @java.lang.Deprecated android.view.translation.TranslationRequest.Builder addTranslationRequestValue(android.view.translation.TranslationRequestValue)\npublic abstract @java.lang.Deprecated android.view.translation.TranslationRequest.Builder addViewTranslationRequest(android.view.translation.ViewTranslationRequest)\nclass BaseBuilder extends java.lang.Object implements []\n@com.android.internal.util.DataClass(genToString=true, genHiddenConstDefs=true, genBuilder=true)\npublic abstract @java.lang.Deprecated android.view.translation.TranslationRequest.Builder addTranslationRequestValue(android.view.translation.TranslationRequestValue)\npublic abstract @java.lang.Deprecated android.view.translation.TranslationRequest.Builder addViewTranslationRequest(android.view.translation.ViewTranslationRequest)\nclass BaseBuilder extends java.lang.Object implements []")
407 @Deprecated
408 private void __metadata() {}
409
410
411 //@formatter:on
412 // End of generated code
413
414 }