| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.view.textclassifier; |
| 18 |
|
| 19 |
import android.annotation.IntDef; |
| 20 |
import android.annotation.NonNull; |
| 21 |
import android.annotation.Nullable; |
| 22 |
import android.icu.util.ULocale; |
| 23 |
import android.os.Bundle; |
| 24 |
import android.os.Parcel; |
| 25 |
import android.os.Parcelable; |
| 26 |
|
| 27 |
import com.android.internal.annotations.VisibleForTesting; |
| 28 |
|
| 29 |
import java.lang.annotation.Retention; |
| 30 |
import java.lang.annotation.RetentionPolicy; |
| 31 |
import java.util.Arrays; |
| 32 |
import java.util.Objects; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
public abstract class TextClassifierEvent implements Parcelable { |
| 43 |
|
| 44 |
private static final int PARCEL_TOKEN_TEXT_SELECTION_EVENT = 1; |
| 45 |
private static final int PARCEL_TOKEN_TEXT_LINKIFY_EVENT = 2; |
| 46 |
private static final int PARCEL_TOKEN_CONVERSATION_ACTION_EVENT = 3; |
| 47 |
private static final int PARCEL_TOKEN_LANGUAGE_DETECTION_EVENT = 4; |
| 48 |
|
| 49 |
|
| 50 |
@Retention(RetentionPolicy.SOURCE) |
| 51 |
@IntDef({CATEGORY_SELECTION, CATEGORY_LINKIFY, |
| 52 |
CATEGORY_CONVERSATION_ACTIONS, CATEGORY_LANGUAGE_DETECTION}) |
| 53 |
public @interface Category { |
| 54 |
|
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
public static final int CATEGORY_SELECTION = 1; |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
public static final int CATEGORY_LINKIFY = 2; |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
public static final int CATEGORY_CONVERSATION_ACTIONS = 3; |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
public static final int CATEGORY_LANGUAGE_DETECTION = 4; |
| 81 |
|
| 82 |
|
| 83 |
@Retention(RetentionPolicy.SOURCE) |
| 84 |
@IntDef({TYPE_SELECTION_STARTED, TYPE_SELECTION_MODIFIED, |
| 85 |
TYPE_SMART_SELECTION_SINGLE, TYPE_SMART_SELECTION_MULTI, TYPE_AUTO_SELECTION, |
| 86 |
TYPE_ACTIONS_SHOWN, TYPE_LINK_CLICKED, TYPE_OVERTYPE, TYPE_COPY_ACTION, |
| 87 |
TYPE_PASTE_ACTION, TYPE_CUT_ACTION, TYPE_SHARE_ACTION, TYPE_SMART_ACTION, |
| 88 |
TYPE_SELECTION_DRAG, TYPE_SELECTION_DESTROYED, TYPE_OTHER_ACTION, TYPE_SELECT_ALL, |
| 89 |
TYPE_SELECTION_RESET, TYPE_MANUAL_REPLY, TYPE_ACTIONS_GENERATED, TYPE_LINKS_GENERATED, |
| 90 |
TYPE_READ_CLIPBOARD}) |
| 91 |
public @interface Type { |
| 92 |
|
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
public static final int TYPE_SELECTION_STARTED = 1; |
| 99 |
|
| 100 |
public static final int TYPE_SELECTION_MODIFIED = 2; |
| 101 |
|
| 102 |
public static final int TYPE_SMART_SELECTION_SINGLE = 3; |
| 103 |
|
| 104 |
public static final int TYPE_SMART_SELECTION_MULTI = 4; |
| 105 |
|
| 106 |
public static final int TYPE_AUTO_SELECTION = 5; |
| 107 |
|
| 108 |
public static final int TYPE_ACTIONS_SHOWN = 6; |
| 109 |
|
| 110 |
public static final int TYPE_LINK_CLICKED = 7; |
| 111 |
|
| 112 |
public static final int TYPE_OVERTYPE = 8; |
| 113 |
|
| 114 |
public static final int TYPE_COPY_ACTION = 9; |
| 115 |
|
| 116 |
public static final int TYPE_PASTE_ACTION = 10; |
| 117 |
|
| 118 |
public static final int TYPE_CUT_ACTION = 11; |
| 119 |
|
| 120 |
public static final int TYPE_SHARE_ACTION = 12; |
| 121 |
|
| 122 |
public static final int TYPE_SMART_ACTION = 13; |
| 123 |
|
| 124 |
public static final int TYPE_SELECTION_DRAG = 14; |
| 125 |
|
| 126 |
public static final int TYPE_SELECTION_DESTROYED = 15; |
| 127 |
|
| 128 |
public static final int TYPE_OTHER_ACTION = 16; |
| 129 |
|
| 130 |
public static final int TYPE_SELECT_ALL = 17; |
| 131 |
|
| 132 |
public static final int TYPE_SELECTION_RESET = 18; |
| 133 |
|
| 134 |
public static final int TYPE_MANUAL_REPLY = 19; |
| 135 |
|
| 136 |
public static final int TYPE_ACTIONS_GENERATED = 20; |
| 137 |
|
| 138 |
public static final int TYPE_LINKS_GENERATED = 21; |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
public static final int TYPE_READ_CLIPBOARD = 22; |
| 146 |
|
| 147 |
@Category |
| 148 |
private final int mEventCategory; |
| 149 |
@Type |
| 150 |
private final int mEventType; |
| 151 |
@Nullable |
| 152 |
private final String[] mEntityTypes; |
| 153 |
@Nullable |
| 154 |
private TextClassificationContext mEventContext; |
| 155 |
@Nullable |
| 156 |
private final String mResultId; |
| 157 |
private final int mEventIndex; |
| 158 |
private final float[] mScores; |
| 159 |
@Nullable |
| 160 |
private final String mModelName; |
| 161 |
private final int[] mActionIndices; |
| 162 |
@Nullable |
| 163 |
private final ULocale mLocale; |
| 164 |
private final Bundle mExtras; |
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
@VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 171 |
@Nullable |
| 172 |
public TextClassificationSessionId mHiddenTempSessionId; |
| 173 |
|
| 174 |
private TextClassifierEvent(Builder builder) { |
| 175 |
mEventCategory = builder.mEventCategory; |
| 176 |
mEventType = builder.mEventType; |
| 177 |
mEntityTypes = builder.mEntityTypes; |
| 178 |
mEventContext = builder.mEventContext; |
| 179 |
mResultId = builder.mResultId; |
| 180 |
mEventIndex = builder.mEventIndex; |
| 181 |
mScores = builder.mScores; |
| 182 |
mModelName = builder.mModelName; |
| 183 |
mActionIndices = builder.mActionIndices; |
| 184 |
mLocale = builder.mLocale; |
| 185 |
mExtras = builder.mExtras == null ? Bundle.EMPTY : builder.mExtras; |
| 186 |
} |
| 187 |
|
| 188 |
private TextClassifierEvent(Parcel in) { |
| 189 |
mEventCategory = in.readInt(); |
| 190 |
mEventType = in.readInt(); |
| 191 |
mEntityTypes = in.readStringArray(); |
| 192 |
mEventContext = in.readParcelable(null, android.view.textclassifier.TextClassificationContext.class); |
| 193 |
mResultId = in.readString(); |
| 194 |
mEventIndex = in.readInt(); |
| 195 |
int scoresLength = in.readInt(); |
| 196 |
mScores = new float[scoresLength]; |
| 197 |
in.readFloatArray(mScores); |
| 198 |
mModelName = in.readString(); |
| 199 |
mActionIndices = in.createIntArray(); |
| 200 |
final String languageTag = in.readString(); |
| 201 |
mLocale = languageTag == null ? null : ULocale.forLanguageTag(languageTag); |
| 202 |
mExtras = in.readBundle(); |
| 203 |
} |
| 204 |
|
| 205 |
@Override |
| 206 |
public int describeContents() { |
| 207 |
return 0; |
| 208 |
} |
| 209 |
|
| 210 |
@NonNull |
| 211 |
public static final Creator<TextClassifierEvent> CREATOR = new Creator<TextClassifierEvent>() { |
| 212 |
@Override |
| 213 |
public TextClassifierEvent createFromParcel(Parcel in) { |
| 214 |
int token = in.readInt(); |
| 215 |
if (token == PARCEL_TOKEN_TEXT_SELECTION_EVENT) { |
| 216 |
return new TextSelectionEvent(in); |
| 217 |
} |
| 218 |
if (token == PARCEL_TOKEN_TEXT_LINKIFY_EVENT) { |
| 219 |
return new TextLinkifyEvent(in); |
| 220 |
} |
| 221 |
if (token == PARCEL_TOKEN_LANGUAGE_DETECTION_EVENT) { |
| 222 |
return new LanguageDetectionEvent(in); |
| 223 |
} |
| 224 |
if (token == PARCEL_TOKEN_CONVERSATION_ACTION_EVENT) { |
| 225 |
return new ConversationActionsEvent(in); |
| 226 |
} |
| 227 |
throw new IllegalStateException("Unexpected input event type token in parcel."); |
| 228 |
} |
| 229 |
|
| 230 |
@Override |
| 231 |
public TextClassifierEvent[] newArray(int size) { |
| 232 |
return new TextClassifierEvent[size]; |
| 233 |
} |
| 234 |
}; |
| 235 |
|
| 236 |
@Override |
| 237 |
public void writeToParcel(Parcel dest, int flags) { |
| 238 |
dest.writeInt(getParcelToken()); |
| 239 |
dest.writeInt(mEventCategory); |
| 240 |
dest.writeInt(mEventType); |
| 241 |
dest.writeStringArray(mEntityTypes); |
| 242 |
dest.writeParcelable(mEventContext, flags); |
| 243 |
dest.writeString(mResultId); |
| 244 |
dest.writeInt(mEventIndex); |
| 245 |
dest.writeInt(mScores.length); |
| 246 |
dest.writeFloatArray(mScores); |
| 247 |
dest.writeString(mModelName); |
| 248 |
dest.writeIntArray(mActionIndices); |
| 249 |
dest.writeString(mLocale == null ? null : mLocale.toLanguageTag()); |
| 250 |
dest.writeBundle(mExtras); |
| 251 |
} |
| 252 |
|
| 253 |
private int getParcelToken() { |
| 254 |
if (this instanceof TextSelectionEvent) { |
| 255 |
return PARCEL_TOKEN_TEXT_SELECTION_EVENT; |
| 256 |
} |
| 257 |
if (this instanceof TextLinkifyEvent) { |
| 258 |
return PARCEL_TOKEN_TEXT_LINKIFY_EVENT; |
| 259 |
} |
| 260 |
if (this instanceof LanguageDetectionEvent) { |
| 261 |
return PARCEL_TOKEN_LANGUAGE_DETECTION_EVENT; |
| 262 |
} |
| 263 |
if (this instanceof ConversationActionsEvent) { |
| 264 |
return PARCEL_TOKEN_CONVERSATION_ACTION_EVENT; |
| 265 |
} |
| 266 |
throw new IllegalArgumentException("Unexpected type: " + this.getClass().getSimpleName()); |
| 267 |
} |
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
@Category |
| 273 |
public int getEventCategory() { |
| 274 |
return mEventCategory; |
| 275 |
} |
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
@Type |
| 281 |
public int getEventType() { |
| 282 |
return mEventType; |
| 283 |
} |
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
@NonNull |
| 291 |
public String[] getEntityTypes() { |
| 292 |
return mEntityTypes; |
| 293 |
} |
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
@Nullable |
| 299 |
public TextClassificationContext getEventContext() { |
| 300 |
return mEventContext; |
| 301 |
} |
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
void setEventContext(@Nullable TextClassificationContext eventContext) { |
| 309 |
mEventContext = eventContext; |
| 310 |
} |
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
@Nullable |
| 316 |
public String getResultId() { |
| 317 |
return mResultId; |
| 318 |
} |
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
public int getEventIndex() { |
| 324 |
return mEventIndex; |
| 325 |
} |
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
@NonNull |
| 331 |
public float[] getScores() { |
| 332 |
return mScores; |
| 333 |
} |
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
@Nullable |
| 339 |
public String getModelName() { |
| 340 |
return mModelName; |
| 341 |
} |
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
@NonNull |
| 352 |
public int[] getActionIndices() { |
| 353 |
return mActionIndices; |
| 354 |
} |
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
@Nullable |
| 360 |
public ULocale getLocale() { |
| 361 |
return mLocale; |
| 362 |
} |
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
@NonNull |
| 370 |
public Bundle getExtras() { |
| 371 |
return mExtras; |
| 372 |
} |
| 373 |
|
| 374 |
@Override |
| 375 |
public String toString() { |
| 376 |
StringBuilder out = new StringBuilder(128); |
| 377 |
out.append(this.getClass().getSimpleName()); |
| 378 |
out.append("{"); |
| 379 |
out.append("mEventCategory=").append(mEventCategory); |
| 380 |
out.append(", mEventType=").append(mEventType); |
| 381 |
out.append(", mEntityTypes=").append(Arrays.toString(mEntityTypes)); |
| 382 |
out.append(", mEventContext=").append(mEventContext); |
| 383 |
out.append(", mResultId=").append(mResultId); |
| 384 |
out.append(", mEventIndex=").append(mEventIndex); |
| 385 |
out.append(", mExtras=").append(mExtras); |
| 386 |
out.append(", mScores=").append(Arrays.toString(mScores)); |
| 387 |
out.append(", mModelName=").append(mModelName); |
| 388 |
out.append(", mActionIndices=").append(Arrays.toString(mActionIndices)); |
| 389 |
toString(out); |
| 390 |
out.append("}"); |
| 391 |
return out.toString(); |
| 392 |
} |
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
void toString(StringBuilder out) {} |
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
@VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 407 |
@Nullable |
| 408 |
public final SelectionEvent toSelectionEvent() { |
| 409 |
final int invocationMethod; |
| 410 |
switch (getEventCategory()) { |
| 411 |
case TextClassifierEvent.CATEGORY_SELECTION: |
| 412 |
invocationMethod = SelectionEvent.INVOCATION_MANUAL; |
| 413 |
break; |
| 414 |
case TextClassifierEvent.CATEGORY_LINKIFY: |
| 415 |
invocationMethod = SelectionEvent.INVOCATION_LINK; |
| 416 |
break; |
| 417 |
default: |
| 418 |
|
| 419 |
return null; |
| 420 |
} |
| 421 |
|
| 422 |
final String entityType = getEntityTypes().length > 0 |
| 423 |
? getEntityTypes()[0] : TextClassifier.TYPE_UNKNOWN; |
| 424 |
final SelectionEvent out = new SelectionEvent( |
| 425 |
0, |
| 426 |
0, |
| 427 |
0, |
| 428 |
entityType, |
| 429 |
SelectionEvent.INVOCATION_UNKNOWN, |
| 430 |
SelectionEvent.NO_SIGNATURE); |
| 431 |
out.setInvocationMethod(invocationMethod); |
| 432 |
|
| 433 |
final TextClassificationContext eventContext = getEventContext(); |
| 434 |
if (eventContext != null) { |
| 435 |
out.setTextClassificationSessionContext(getEventContext()); |
| 436 |
} |
| 437 |
out.setSessionId(mHiddenTempSessionId); |
| 438 |
final String resultId = getResultId(); |
| 439 |
out.setResultId(resultId == null ? SelectionEvent.NO_SIGNATURE : resultId); |
| 440 |
out.setEventIndex(getEventIndex()); |
| 441 |
|
| 442 |
|
| 443 |
final int eventType; |
| 444 |
switch (getEventType()) { |
| 445 |
case TextClassifierEvent.TYPE_SELECTION_STARTED: |
| 446 |
eventType = SelectionEvent.EVENT_SELECTION_STARTED; |
| 447 |
break; |
| 448 |
case TextClassifierEvent.TYPE_SELECTION_MODIFIED: |
| 449 |
eventType = SelectionEvent.EVENT_SELECTION_MODIFIED; |
| 450 |
break; |
| 451 |
case TextClassifierEvent.TYPE_SMART_SELECTION_SINGLE: |
| 452 |
eventType = SelectionEvent.EVENT_SMART_SELECTION_SINGLE; |
| 453 |
break; |
| 454 |
case TextClassifierEvent.TYPE_SMART_SELECTION_MULTI: |
| 455 |
eventType = SelectionEvent.EVENT_SMART_SELECTION_MULTI; |
| 456 |
break; |
| 457 |
case TextClassifierEvent.TYPE_AUTO_SELECTION: |
| 458 |
eventType = SelectionEvent.EVENT_AUTO_SELECTION; |
| 459 |
break; |
| 460 |
case TextClassifierEvent.TYPE_OVERTYPE: |
| 461 |
eventType = SelectionEvent.ACTION_OVERTYPE; |
| 462 |
break; |
| 463 |
case TextClassifierEvent.TYPE_COPY_ACTION: |
| 464 |
eventType = SelectionEvent.ACTION_COPY; |
| 465 |
break; |
| 466 |
case TextClassifierEvent.TYPE_PASTE_ACTION: |
| 467 |
eventType = SelectionEvent.ACTION_PASTE; |
| 468 |
break; |
| 469 |
case TextClassifierEvent.TYPE_CUT_ACTION: |
| 470 |
eventType = SelectionEvent.ACTION_CUT; |
| 471 |
break; |
| 472 |
case TextClassifierEvent.TYPE_SHARE_ACTION: |
| 473 |
eventType = SelectionEvent.ACTION_SHARE; |
| 474 |
break; |
| 475 |
case TextClassifierEvent.TYPE_SMART_ACTION: |
| 476 |
eventType = SelectionEvent.ACTION_SMART_SHARE; |
| 477 |
break; |
| 478 |
case TextClassifierEvent.TYPE_SELECTION_DRAG: |
| 479 |
eventType = SelectionEvent.ACTION_DRAG; |
| 480 |
break; |
| 481 |
case TextClassifierEvent.TYPE_SELECTION_DESTROYED: |
| 482 |
eventType = SelectionEvent.ACTION_ABANDON; |
| 483 |
break; |
| 484 |
case TextClassifierEvent.TYPE_OTHER_ACTION: |
| 485 |
eventType = SelectionEvent.ACTION_OTHER; |
| 486 |
break; |
| 487 |
case TextClassifierEvent.TYPE_SELECT_ALL: |
| 488 |
eventType = SelectionEvent.ACTION_SELECT_ALL; |
| 489 |
break; |
| 490 |
case TextClassifierEvent.TYPE_SELECTION_RESET: |
| 491 |
eventType = SelectionEvent.ACTION_RESET; |
| 492 |
break; |
| 493 |
default: |
| 494 |
eventType = 0; |
| 495 |
break; |
| 496 |
} |
| 497 |
out.setEventType(eventType); |
| 498 |
|
| 499 |
if (this instanceof TextClassifierEvent.TextSelectionEvent) { |
| 500 |
final TextClassifierEvent.TextSelectionEvent selEvent = |
| 501 |
(TextClassifierEvent.TextSelectionEvent) this; |
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
out.setStart(selEvent.getRelativeWordStartIndex()); |
| 507 |
out.setEnd(selEvent.getRelativeWordEndIndex()); |
| 508 |
out.setSmartStart(selEvent.getRelativeSuggestedWordStartIndex()); |
| 509 |
out.setSmartEnd(selEvent.getRelativeSuggestedWordEndIndex()); |
| 510 |
} |
| 511 |
|
| 512 |
return out; |
| 513 |
} |
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
public abstract static class Builder<T extends Builder<T>> { |
| 521 |
|
| 522 |
private final int mEventCategory; |
| 523 |
private final int mEventType; |
| 524 |
private String[] mEntityTypes = new String[0]; |
| 525 |
@Nullable |
| 526 |
private TextClassificationContext mEventContext; |
| 527 |
@Nullable |
| 528 |
private String mResultId; |
| 529 |
private int mEventIndex; |
| 530 |
private float[] mScores = new float[0]; |
| 531 |
@Nullable |
| 532 |
private String mModelName; |
| 533 |
private int[] mActionIndices = new int[0]; |
| 534 |
@Nullable |
| 535 |
private ULocale mLocale; |
| 536 |
@Nullable |
| 537 |
private Bundle mExtras; |
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
private Builder(@Category int eventCategory, @Type int eventType) { |
| 546 |
mEventCategory = eventCategory; |
| 547 |
mEventType = eventType; |
| 548 |
} |
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
@NonNull |
| 559 |
public T setEntityTypes(@NonNull String... entityTypes) { |
| 560 |
Objects.requireNonNull(entityTypes); |
| 561 |
mEntityTypes = new String[entityTypes.length]; |
| 562 |
System.arraycopy(entityTypes, 0, mEntityTypes, 0, entityTypes.length); |
| 563 |
return self(); |
| 564 |
} |
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
@NonNull |
| 570 |
public T setEventContext(@Nullable TextClassificationContext eventContext) { |
| 571 |
mEventContext = eventContext; |
| 572 |
return self(); |
| 573 |
} |
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
@NonNull |
| 579 |
public T setResultId(@Nullable String resultId) { |
| 580 |
mResultId = resultId; |
| 581 |
return self(); |
| 582 |
} |
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
@NonNull |
| 588 |
public T setEventIndex(int eventIndex) { |
| 589 |
mEventIndex = eventIndex; |
| 590 |
return self(); |
| 591 |
} |
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
@NonNull |
| 597 |
public T setScores(@NonNull float... scores) { |
| 598 |
Objects.requireNonNull(scores); |
| 599 |
mScores = new float[scores.length]; |
| 600 |
System.arraycopy(scores, 0, mScores, 0, scores.length); |
| 601 |
return self(); |
| 602 |
} |
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
@NonNull |
| 608 |
public T setModelName(@Nullable String modelVersion) { |
| 609 |
mModelName = modelVersion; |
| 610 |
return self(); |
| 611 |
} |
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
@NonNull |
| 638 |
public T setActionIndices(@NonNull int... actionIndices) { |
| 639 |
mActionIndices = new int[actionIndices.length]; |
| 640 |
System.arraycopy(actionIndices, 0, mActionIndices, 0, actionIndices.length); |
| 641 |
return self(); |
| 642 |
} |
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
@NonNull |
| 648 |
public T setLocale(@Nullable ULocale locale) { |
| 649 |
mLocale = locale; |
| 650 |
return self(); |
| 651 |
} |
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
@NonNull |
| 662 |
public T setExtras(@NonNull Bundle extras) { |
| 663 |
mExtras = Objects.requireNonNull(extras); |
| 664 |
return self(); |
| 665 |
} |
| 666 |
|
| 667 |
abstract T self(); |
| 668 |
} |
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
public static final class TextSelectionEvent extends TextClassifierEvent implements Parcelable { |
| 760 |
|
| 761 |
@NonNull |
| 762 |
public static final Creator<TextSelectionEvent> CREATOR = |
| 763 |
new Creator<TextSelectionEvent>() { |
| 764 |
@Override |
| 765 |
public TextSelectionEvent createFromParcel(Parcel in) { |
| 766 |
in.readInt(); |
| 767 |
return new TextSelectionEvent(in); |
| 768 |
} |
| 769 |
|
| 770 |
@Override |
| 771 |
public TextSelectionEvent[] newArray(int size) { |
| 772 |
return new TextSelectionEvent[size]; |
| 773 |
} |
| 774 |
}; |
| 775 |
|
| 776 |
final int mRelativeWordStartIndex; |
| 777 |
final int mRelativeWordEndIndex; |
| 778 |
final int mRelativeSuggestedWordStartIndex; |
| 779 |
final int mRelativeSuggestedWordEndIndex; |
| 780 |
|
| 781 |
private TextSelectionEvent(TextSelectionEvent.Builder builder) { |
| 782 |
super(builder); |
| 783 |
mRelativeWordStartIndex = builder.mRelativeWordStartIndex; |
| 784 |
mRelativeWordEndIndex = builder.mRelativeWordEndIndex; |
| 785 |
mRelativeSuggestedWordStartIndex = builder.mRelativeSuggestedWordStartIndex; |
| 786 |
mRelativeSuggestedWordEndIndex = builder.mRelativeSuggestedWordEndIndex; |
| 787 |
} |
| 788 |
|
| 789 |
private TextSelectionEvent(Parcel in) { |
| 790 |
super(in); |
| 791 |
mRelativeWordStartIndex = in.readInt(); |
| 792 |
mRelativeWordEndIndex = in.readInt(); |
| 793 |
mRelativeSuggestedWordStartIndex = in.readInt(); |
| 794 |
mRelativeSuggestedWordEndIndex = in.readInt(); |
| 795 |
} |
| 796 |
|
| 797 |
@Override |
| 798 |
public void writeToParcel(Parcel dest, int flags) { |
| 799 |
super.writeToParcel(dest, flags); |
| 800 |
dest.writeInt(mRelativeWordStartIndex); |
| 801 |
dest.writeInt(mRelativeWordEndIndex); |
| 802 |
dest.writeInt(mRelativeSuggestedWordStartIndex); |
| 803 |
dest.writeInt(mRelativeSuggestedWordEndIndex); |
| 804 |
} |
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
public int getRelativeWordStartIndex() { |
| 810 |
return mRelativeWordStartIndex; |
| 811 |
} |
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
public int getRelativeWordEndIndex() { |
| 817 |
return mRelativeWordEndIndex; |
| 818 |
} |
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
public int getRelativeSuggestedWordStartIndex() { |
| 824 |
return mRelativeSuggestedWordStartIndex; |
| 825 |
} |
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
public int getRelativeSuggestedWordEndIndex() { |
| 832 |
return mRelativeSuggestedWordEndIndex; |
| 833 |
} |
| 834 |
|
| 835 |
@Override |
| 836 |
void toString(StringBuilder out) { |
| 837 |
out.append(", getRelativeWordStartIndex=").append(mRelativeWordStartIndex); |
| 838 |
out.append(", getRelativeWordEndIndex=").append(mRelativeWordEndIndex); |
| 839 |
out.append(", getRelativeSuggestedWordStartIndex=") |
| 840 |
.append(mRelativeSuggestedWordStartIndex); |
| 841 |
out.append(", getRelativeSuggestedWordEndIndex=") |
| 842 |
.append(mRelativeSuggestedWordEndIndex); |
| 843 |
} |
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
public static final class Builder extends |
| 849 |
TextClassifierEvent.Builder<TextSelectionEvent.Builder> { |
| 850 |
int mRelativeWordStartIndex; |
| 851 |
int mRelativeWordEndIndex; |
| 852 |
int mRelativeSuggestedWordStartIndex; |
| 853 |
int mRelativeSuggestedWordEndIndex; |
| 854 |
|
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
public Builder(@Type int eventType) { |
| 861 |
super(CATEGORY_SELECTION, eventType); |
| 862 |
} |
| 863 |
|
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
@NonNull |
| 868 |
public Builder setRelativeWordStartIndex(int relativeWordStartIndex) { |
| 869 |
mRelativeWordStartIndex = relativeWordStartIndex; |
| 870 |
return this; |
| 871 |
} |
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
|
| 876 |
|
| 877 |
@NonNull |
| 878 |
public Builder setRelativeWordEndIndex(int relativeWordEndIndex) { |
| 879 |
mRelativeWordEndIndex = relativeWordEndIndex; |
| 880 |
return this; |
| 881 |
} |
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
@NonNull |
| 888 |
public Builder setRelativeSuggestedWordStartIndex(int relativeSuggestedWordStartIndex) { |
| 889 |
mRelativeSuggestedWordStartIndex = relativeSuggestedWordStartIndex; |
| 890 |
return this; |
| 891 |
} |
| 892 |
|
| 893 |
|
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
@NonNull |
| 898 |
public Builder setRelativeSuggestedWordEndIndex(int relativeSuggestedWordEndIndex) { |
| 899 |
mRelativeSuggestedWordEndIndex = relativeSuggestedWordEndIndex; |
| 900 |
return this; |
| 901 |
} |
| 902 |
|
| 903 |
@Override |
| 904 |
TextSelectionEvent.Builder self() { |
| 905 |
return this; |
| 906 |
} |
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
@NonNull |
| 912 |
public TextSelectionEvent build() { |
| 913 |
return new TextSelectionEvent(this); |
| 914 |
} |
| 915 |
} |
| 916 |
} |
| 917 |
|
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
|
| 926 |
|
| 927 |
|
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
|
| 945 |
|
| 946 |
|
| 947 |
|
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
public static final class TextLinkifyEvent extends TextClassifierEvent implements Parcelable { |
| 953 |
|
| 954 |
@NonNull |
| 955 |
public static final Creator<TextLinkifyEvent> CREATOR = |
| 956 |
new Creator<TextLinkifyEvent>() { |
| 957 |
@Override |
| 958 |
public TextLinkifyEvent createFromParcel(Parcel in) { |
| 959 |
in.readInt(); |
| 960 |
return new TextLinkifyEvent(in); |
| 961 |
} |
| 962 |
|
| 963 |
@Override |
| 964 |
public TextLinkifyEvent[] newArray(int size) { |
| 965 |
return new TextLinkifyEvent[size]; |
| 966 |
} |
| 967 |
}; |
| 968 |
|
| 969 |
private TextLinkifyEvent(Parcel in) { |
| 970 |
super(in); |
| 971 |
} |
| 972 |
|
| 973 |
private TextLinkifyEvent(TextLinkifyEvent.Builder builder) { |
| 974 |
super(builder); |
| 975 |
} |
| 976 |
|
| 977 |
|
| 978 |
|
| 979 |
|
| 980 |
public static final class Builder |
| 981 |
extends TextClassifierEvent.Builder<TextLinkifyEvent.Builder> { |
| 982 |
|
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
|
| 987 |
public Builder(@Type int eventType) { |
| 988 |
super(TextClassifierEvent.CATEGORY_LINKIFY, eventType); |
| 989 |
} |
| 990 |
|
| 991 |
@Override |
| 992 |
Builder self() { |
| 993 |
return this; |
| 994 |
} |
| 995 |
|
| 996 |
|
| 997 |
|
| 998 |
|
| 999 |
@NonNull |
| 1000 |
public TextLinkifyEvent build() { |
| 1001 |
return new TextLinkifyEvent(this); |
| 1002 |
} |
| 1003 |
} |
| 1004 |
} |
| 1005 |
|
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
|
| 1014 |
|
| 1015 |
|
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
|
| 1022 |
|
| 1023 |
|
| 1024 |
|
| 1025 |
|
| 1026 |
|
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
public static final class LanguageDetectionEvent extends TextClassifierEvent |
| 1031 |
implements Parcelable { |
| 1032 |
|
| 1033 |
@NonNull |
| 1034 |
public static final Creator<LanguageDetectionEvent> CREATOR = |
| 1035 |
new Creator<LanguageDetectionEvent>() { |
| 1036 |
@Override |
| 1037 |
public LanguageDetectionEvent createFromParcel(Parcel in) { |
| 1038 |
|
| 1039 |
in.readInt(); |
| 1040 |
return new LanguageDetectionEvent(in); |
| 1041 |
} |
| 1042 |
|
| 1043 |
@Override |
| 1044 |
public LanguageDetectionEvent[] newArray(int size) { |
| 1045 |
return new LanguageDetectionEvent[size]; |
| 1046 |
} |
| 1047 |
}; |
| 1048 |
|
| 1049 |
private LanguageDetectionEvent(Parcel in) { |
| 1050 |
super(in); |
| 1051 |
} |
| 1052 |
|
| 1053 |
private LanguageDetectionEvent(LanguageDetectionEvent.Builder builder) { |
| 1054 |
super(builder); |
| 1055 |
} |
| 1056 |
|
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
public static final class Builder |
| 1061 |
extends TextClassifierEvent.Builder<LanguageDetectionEvent.Builder> { |
| 1062 |
|
| 1063 |
|
| 1064 |
|
| 1065 |
|
| 1066 |
|
| 1067 |
|
| 1068 |
public Builder(@Type int eventType) { |
| 1069 |
super(TextClassifierEvent.CATEGORY_LANGUAGE_DETECTION, eventType); |
| 1070 |
} |
| 1071 |
|
| 1072 |
@Override |
| 1073 |
Builder self() { |
| 1074 |
return this; |
| 1075 |
} |
| 1076 |
|
| 1077 |
|
| 1078 |
|
| 1079 |
|
| 1080 |
@NonNull |
| 1081 |
public LanguageDetectionEvent build() { |
| 1082 |
return new LanguageDetectionEvent(this); |
| 1083 |
} |
| 1084 |
} |
| 1085 |
} |
| 1086 |
|
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
|
| 1091 |
|
| 1092 |
|
| 1093 |
|
| 1094 |
|
| 1095 |
|
| 1096 |
|
| 1097 |
|
| 1098 |
|
| 1099 |
|
| 1100 |
|
| 1101 |
|
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
|
| 1109 |
|
| 1110 |
|
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
|
| 1119 |
|
| 1120 |
|
| 1121 |
|
| 1122 |
|
| 1123 |
|
| 1124 |
|
| 1125 |
|
| 1126 |
|
| 1127 |
public static final class ConversationActionsEvent extends TextClassifierEvent |
| 1128 |
implements Parcelable { |
| 1129 |
|
| 1130 |
@NonNull |
| 1131 |
public static final Creator<ConversationActionsEvent> CREATOR = |
| 1132 |
new Creator<ConversationActionsEvent>() { |
| 1133 |
@Override |
| 1134 |
public ConversationActionsEvent createFromParcel(Parcel in) { |
| 1135 |
|
| 1136 |
in.readInt(); |
| 1137 |
return new ConversationActionsEvent(in); |
| 1138 |
} |
| 1139 |
|
| 1140 |
@Override |
| 1141 |
public ConversationActionsEvent[] newArray(int size) { |
| 1142 |
return new ConversationActionsEvent[size]; |
| 1143 |
} |
| 1144 |
}; |
| 1145 |
|
| 1146 |
private ConversationActionsEvent(Parcel in) { |
| 1147 |
super(in); |
| 1148 |
} |
| 1149 |
|
| 1150 |
private ConversationActionsEvent(ConversationActionsEvent.Builder builder) { |
| 1151 |
super(builder); |
| 1152 |
} |
| 1153 |
|
| 1154 |
|
| 1155 |
|
| 1156 |
|
| 1157 |
public static final class Builder |
| 1158 |
extends TextClassifierEvent.Builder<ConversationActionsEvent.Builder> { |
| 1159 |
|
| 1160 |
|
| 1161 |
|
| 1162 |
|
| 1163 |
|
| 1164 |
public Builder(@Type int eventType) { |
| 1165 |
super(TextClassifierEvent.CATEGORY_CONVERSATION_ACTIONS, eventType); |
| 1166 |
} |
| 1167 |
|
| 1168 |
@Override |
| 1169 |
Builder self() { |
| 1170 |
return this; |
| 1171 |
} |
| 1172 |
|
| 1173 |
|
| 1174 |
|
| 1175 |
|
| 1176 |
@NonNull |
| 1177 |
public ConversationActionsEvent build() { |
| 1178 |
return new ConversationActionsEvent(this); |
| 1179 |
} |
| 1180 |
} |
| 1181 |
} |
| 1182 |
} |