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