| 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.os.Parcel; |
| 23 |
import android.os.Parcelable; |
| 24 |
import android.view.textclassifier.TextClassifier.EntityType; |
| 25 |
import android.view.textclassifier.TextClassifier.WidgetType; |
| 26 |
|
| 27 |
import com.android.internal.annotations.VisibleForTesting; |
| 28 |
import com.android.internal.util.Preconditions; |
| 29 |
|
| 30 |
import java.lang.annotation.Retention; |
| 31 |
import java.lang.annotation.RetentionPolicy; |
| 32 |
import java.util.Locale; |
| 33 |
import java.util.Objects; |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
public final class SelectionEvent implements Parcelable { |
| 40 |
|
| 41 |
|
| 42 |
@Retention(RetentionPolicy.SOURCE) |
| 43 |
@IntDef({ACTION_OVERTYPE, ACTION_COPY, ACTION_PASTE, ACTION_CUT, |
| 44 |
ACTION_SHARE, ACTION_SMART_SHARE, ACTION_DRAG, ACTION_ABANDON, |
| 45 |
ACTION_OTHER, ACTION_SELECT_ALL, ACTION_RESET}) |
| 46 |
|
| 47 |
|
| 48 |
public @interface ActionType { |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
public static final int ACTION_OVERTYPE = 100; |
| 57 |
|
| 58 |
public static final int ACTION_COPY = 101; |
| 59 |
|
| 60 |
public static final int ACTION_PASTE = 102; |
| 61 |
|
| 62 |
public static final int ACTION_CUT = 103; |
| 63 |
|
| 64 |
public static final int ACTION_SHARE = 104; |
| 65 |
|
| 66 |
public static final int ACTION_SMART_SHARE = 105; |
| 67 |
|
| 68 |
public static final int ACTION_DRAG = 106; |
| 69 |
|
| 70 |
public static final int ACTION_ABANDON = 107; |
| 71 |
|
| 72 |
public static final int ACTION_OTHER = 108; |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
public static final int ACTION_SELECT_ALL = 200; |
| 77 |
|
| 78 |
public static final int ACTION_RESET = 201; |
| 79 |
|
| 80 |
|
| 81 |
@Retention(RetentionPolicy.SOURCE) |
| 82 |
@IntDef({ACTION_OVERTYPE, ACTION_COPY, ACTION_PASTE, ACTION_CUT, |
| 83 |
ACTION_SHARE, ACTION_SMART_SHARE, ACTION_DRAG, ACTION_ABANDON, |
| 84 |
ACTION_OTHER, ACTION_SELECT_ALL, ACTION_RESET, |
| 85 |
EVENT_SELECTION_STARTED, EVENT_SELECTION_MODIFIED, |
| 86 |
EVENT_SMART_SELECTION_SINGLE, EVENT_SMART_SELECTION_MULTI, |
| 87 |
EVENT_AUTO_SELECTION}) |
| 88 |
|
| 89 |
|
| 90 |
public @interface EventType { |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
} |
| 95 |
|
| 96 |
|
| 97 |
public static final int EVENT_SELECTION_STARTED = 1; |
| 98 |
|
| 99 |
public static final int EVENT_SELECTION_MODIFIED = 2; |
| 100 |
|
| 101 |
public static final int EVENT_SMART_SELECTION_SINGLE = 3; |
| 102 |
|
| 103 |
public static final int EVENT_SMART_SELECTION_MULTI = 4; |
| 104 |
|
| 105 |
public static final int EVENT_AUTO_SELECTION = 5; |
| 106 |
|
| 107 |
|
| 108 |
@Retention(RetentionPolicy.SOURCE) |
| 109 |
@IntDef({INVOCATION_MANUAL, INVOCATION_LINK, INVOCATION_UNKNOWN}) |
| 110 |
public @interface InvocationMethod {} |
| 111 |
|
| 112 |
|
| 113 |
public static final int INVOCATION_MANUAL = 1; |
| 114 |
|
| 115 |
public static final int INVOCATION_LINK = 2; |
| 116 |
|
| 117 |
public static final int INVOCATION_UNKNOWN = 0; |
| 118 |
|
| 119 |
static final String NO_SIGNATURE = ""; |
| 120 |
|
| 121 |
private final int mAbsoluteStart; |
| 122 |
private final int mAbsoluteEnd; |
| 123 |
|
| 124 |
private @EntityType String mEntityType; |
| 125 |
private @EventType int mEventType; |
| 126 |
private String mPackageName = ""; |
| 127 |
private String mWidgetType = TextClassifier.WIDGET_TYPE_UNKNOWN; |
| 128 |
private @InvocationMethod int mInvocationMethod; |
| 129 |
@Nullable private String mWidgetVersion; |
| 130 |
@Nullable private String mResultId; |
| 131 |
private long mEventTime; |
| 132 |
private long mDurationSinceSessionStart; |
| 133 |
private long mDurationSincePreviousEvent; |
| 134 |
private int mEventIndex; |
| 135 |
@Nullable private TextClassificationSessionId mSessionId; |
| 136 |
private int mStart; |
| 137 |
private int mEnd; |
| 138 |
private int mSmartStart; |
| 139 |
private int mSmartEnd; |
| 140 |
@Nullable private SystemTextClassifierMetadata mSystemTcMetadata; |
| 141 |
|
| 142 |
SelectionEvent( |
| 143 |
int start, int end, |
| 144 |
@EventType int eventType, @EntityType String entityType, |
| 145 |
@InvocationMethod int invocationMethod, @Nullable String resultId) { |
| 146 |
Preconditions.checkArgument(end >= start, "end cannot be less than start"); |
| 147 |
mAbsoluteStart = start; |
| 148 |
mAbsoluteEnd = end; |
| 149 |
mEventType = eventType; |
| 150 |
mEntityType = Objects.requireNonNull(entityType); |
| 151 |
mResultId = resultId; |
| 152 |
mInvocationMethod = invocationMethod; |
| 153 |
} |
| 154 |
|
| 155 |
private SelectionEvent(Parcel in) { |
| 156 |
mAbsoluteStart = in.readInt(); |
| 157 |
mAbsoluteEnd = in.readInt(); |
| 158 |
mEventType = in.readInt(); |
| 159 |
mEntityType = in.readString(); |
| 160 |
mWidgetVersion = in.readInt() > 0 ? in.readString() : null; |
| 161 |
mPackageName = in.readString(); |
| 162 |
mWidgetType = in.readString(); |
| 163 |
mInvocationMethod = in.readInt(); |
| 164 |
mResultId = in.readString(); |
| 165 |
mEventTime = in.readLong(); |
| 166 |
mDurationSinceSessionStart = in.readLong(); |
| 167 |
mDurationSincePreviousEvent = in.readLong(); |
| 168 |
mEventIndex = in.readInt(); |
| 169 |
mSessionId = in.readInt() > 0 |
| 170 |
? TextClassificationSessionId.CREATOR.createFromParcel(in) : null; |
| 171 |
mStart = in.readInt(); |
| 172 |
mEnd = in.readInt(); |
| 173 |
mSmartStart = in.readInt(); |
| 174 |
mSmartEnd = in.readInt(); |
| 175 |
mSystemTcMetadata = in.readParcelable(null, android.view.textclassifier.SystemTextClassifierMetadata.class); |
| 176 |
} |
| 177 |
|
| 178 |
@Override |
| 179 |
public void writeToParcel(Parcel dest, int flags) { |
| 180 |
dest.writeInt(mAbsoluteStart); |
| 181 |
dest.writeInt(mAbsoluteEnd); |
| 182 |
dest.writeInt(mEventType); |
| 183 |
dest.writeString(mEntityType); |
| 184 |
dest.writeInt(mWidgetVersion != null ? 1 : 0); |
| 185 |
if (mWidgetVersion != null) { |
| 186 |
dest.writeString(mWidgetVersion); |
| 187 |
} |
| 188 |
dest.writeString(mPackageName); |
| 189 |
dest.writeString(mWidgetType); |
| 190 |
dest.writeInt(mInvocationMethod); |
| 191 |
dest.writeString(mResultId); |
| 192 |
dest.writeLong(mEventTime); |
| 193 |
dest.writeLong(mDurationSinceSessionStart); |
| 194 |
dest.writeLong(mDurationSincePreviousEvent); |
| 195 |
dest.writeInt(mEventIndex); |
| 196 |
dest.writeInt(mSessionId != null ? 1 : 0); |
| 197 |
if (mSessionId != null) { |
| 198 |
mSessionId.writeToParcel(dest, flags); |
| 199 |
} |
| 200 |
dest.writeInt(mStart); |
| 201 |
dest.writeInt(mEnd); |
| 202 |
dest.writeInt(mSmartStart); |
| 203 |
dest.writeInt(mSmartEnd); |
| 204 |
dest.writeParcelable(mSystemTcMetadata, flags); |
| 205 |
} |
| 206 |
|
| 207 |
@Override |
| 208 |
public int describeContents() { |
| 209 |
return 0; |
| 210 |
} |
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
@NonNull |
| 219 |
public static SelectionEvent createSelectionStartedEvent( |
| 220 |
@SelectionEvent.InvocationMethod int invocationMethod, int start) { |
| 221 |
return new SelectionEvent( |
| 222 |
start, start + 1, SelectionEvent.EVENT_SELECTION_STARTED, |
| 223 |
TextClassifier.TYPE_UNKNOWN, invocationMethod, NO_SIGNATURE); |
| 224 |
} |
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
@NonNull |
| 236 |
public static SelectionEvent createSelectionModifiedEvent(int start, int end) { |
| 237 |
Preconditions.checkArgument(end >= start, "end cannot be less than start"); |
| 238 |
return new SelectionEvent( |
| 239 |
start, end, SelectionEvent.EVENT_SELECTION_MODIFIED, |
| 240 |
TextClassifier.TYPE_UNKNOWN, INVOCATION_UNKNOWN, NO_SIGNATURE); |
| 241 |
} |
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
@NonNull |
| 255 |
public static SelectionEvent createSelectionModifiedEvent( |
| 256 |
int start, int end, @NonNull TextClassification classification) { |
| 257 |
Preconditions.checkArgument(end >= start, "end cannot be less than start"); |
| 258 |
Objects.requireNonNull(classification); |
| 259 |
final String entityType = classification.getEntityCount() > 0 |
| 260 |
? classification.getEntity(0) |
| 261 |
: TextClassifier.TYPE_UNKNOWN; |
| 262 |
return new SelectionEvent( |
| 263 |
start, end, SelectionEvent.EVENT_SELECTION_MODIFIED, |
| 264 |
entityType, INVOCATION_UNKNOWN, classification.getId()); |
| 265 |
} |
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
@NonNull |
| 279 |
public static SelectionEvent createSelectionModifiedEvent( |
| 280 |
int start, int end, @NonNull TextSelection selection) { |
| 281 |
Preconditions.checkArgument(end >= start, "end cannot be less than start"); |
| 282 |
Objects.requireNonNull(selection); |
| 283 |
final String entityType = selection.getEntityCount() > 0 |
| 284 |
? selection.getEntity(0) |
| 285 |
: TextClassifier.TYPE_UNKNOWN; |
| 286 |
return new SelectionEvent( |
| 287 |
start, end, SelectionEvent.EVENT_AUTO_SELECTION, |
| 288 |
entityType, INVOCATION_UNKNOWN, selection.getId()); |
| 289 |
} |
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
@NonNull |
| 302 |
public static SelectionEvent createSelectionActionEvent( |
| 303 |
int start, int end, @SelectionEvent.ActionType int actionType) { |
| 304 |
Preconditions.checkArgument(end >= start, "end cannot be less than start"); |
| 305 |
checkActionType(actionType); |
| 306 |
return new SelectionEvent( |
| 307 |
start, end, actionType, TextClassifier.TYPE_UNKNOWN, INVOCATION_UNKNOWN, |
| 308 |
NO_SIGNATURE); |
| 309 |
} |
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
@NonNull |
| 326 |
public static SelectionEvent createSelectionActionEvent( |
| 327 |
int start, int end, @SelectionEvent.ActionType int actionType, |
| 328 |
@NonNull TextClassification classification) { |
| 329 |
Preconditions.checkArgument(end >= start, "end cannot be less than start"); |
| 330 |
Objects.requireNonNull(classification); |
| 331 |
checkActionType(actionType); |
| 332 |
final String entityType = classification.getEntityCount() > 0 |
| 333 |
? classification.getEntity(0) |
| 334 |
: TextClassifier.TYPE_UNKNOWN; |
| 335 |
return new SelectionEvent(start, end, actionType, entityType, INVOCATION_UNKNOWN, |
| 336 |
classification.getId()); |
| 337 |
} |
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
private static void checkActionType(@SelectionEvent.EventType int eventType) |
| 343 |
throws IllegalArgumentException { |
| 344 |
switch (eventType) { |
| 345 |
case SelectionEvent.ACTION_OVERTYPE: |
| 346 |
case SelectionEvent.ACTION_COPY: |
| 347 |
case SelectionEvent.ACTION_PASTE: |
| 348 |
case SelectionEvent.ACTION_CUT: |
| 349 |
case SelectionEvent.ACTION_SHARE: |
| 350 |
case SelectionEvent.ACTION_SMART_SHARE: |
| 351 |
case SelectionEvent.ACTION_DRAG: |
| 352 |
case SelectionEvent.ACTION_ABANDON: |
| 353 |
case SelectionEvent.ACTION_SELECT_ALL: |
| 354 |
case SelectionEvent.ACTION_RESET: |
| 355 |
case SelectionEvent.ACTION_OTHER: |
| 356 |
return; |
| 357 |
default: |
| 358 |
throw new IllegalArgumentException( |
| 359 |
String.format(Locale.US, "%d is not an eventType", eventType)); |
| 360 |
} |
| 361 |
} |
| 362 |
|
| 363 |
int getAbsoluteStart() { |
| 364 |
return mAbsoluteStart; |
| 365 |
} |
| 366 |
|
| 367 |
int getAbsoluteEnd() { |
| 368 |
return mAbsoluteEnd; |
| 369 |
} |
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
@EventType |
| 375 |
public int getEventType() { |
| 376 |
return mEventType; |
| 377 |
} |
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
@VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 384 |
public void setEventType(@EventType int eventType) { |
| 385 |
mEventType = eventType; |
| 386 |
} |
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
@EntityType |
| 393 |
@NonNull |
| 394 |
public String getEntityType() { |
| 395 |
return mEntityType; |
| 396 |
} |
| 397 |
|
| 398 |
void setEntityType(@EntityType String entityType) { |
| 399 |
mEntityType = Objects.requireNonNull(entityType); |
| 400 |
} |
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
@NonNull |
| 406 |
public String getPackageName() { |
| 407 |
return mPackageName; |
| 408 |
} |
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
void setSystemTextClassifierMetadata(@Nullable SystemTextClassifierMetadata systemTcMetadata) { |
| 416 |
mSystemTcMetadata = systemTcMetadata; |
| 417 |
} |
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
@Nullable |
| 425 |
public SystemTextClassifierMetadata getSystemTextClassifierMetadata() { |
| 426 |
return mSystemTcMetadata; |
| 427 |
} |
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
@WidgetType |
| 433 |
@NonNull |
| 434 |
public String getWidgetType() { |
| 435 |
return mWidgetType; |
| 436 |
} |
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
@Nullable |
| 442 |
public String getWidgetVersion() { |
| 443 |
return mWidgetVersion; |
| 444 |
} |
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
@VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 451 |
public void setTextClassificationSessionContext(TextClassificationContext context) { |
| 452 |
mPackageName = context.getPackageName(); |
| 453 |
mWidgetType = context.getWidgetType(); |
| 454 |
mWidgetVersion = context.getWidgetVersion(); |
| 455 |
mSystemTcMetadata = context.getSystemTextClassifierMetadata(); |
| 456 |
} |
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
public @InvocationMethod int getInvocationMethod() { |
| 462 |
return mInvocationMethod; |
| 463 |
} |
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
@VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 470 |
public void setInvocationMethod(@InvocationMethod int invocationMethod) { |
| 471 |
mInvocationMethod = invocationMethod; |
| 472 |
} |
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
@Nullable |
| 478 |
public String getResultId() { |
| 479 |
return mResultId; |
| 480 |
} |
| 481 |
|
| 482 |
SelectionEvent setResultId(@Nullable String resultId) { |
| 483 |
mResultId = resultId; |
| 484 |
return this; |
| 485 |
} |
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
public long getEventTime() { |
| 491 |
return mEventTime; |
| 492 |
} |
| 493 |
|
| 494 |
SelectionEvent setEventTime(long timeMs) { |
| 495 |
mEventTime = timeMs; |
| 496 |
return this; |
| 497 |
} |
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
public long getDurationSinceSessionStart() { |
| 504 |
return mDurationSinceSessionStart; |
| 505 |
} |
| 506 |
|
| 507 |
SelectionEvent setDurationSinceSessionStart(long durationMs) { |
| 508 |
mDurationSinceSessionStart = durationMs; |
| 509 |
return this; |
| 510 |
} |
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
public long getDurationSincePreviousEvent() { |
| 517 |
return mDurationSincePreviousEvent; |
| 518 |
} |
| 519 |
|
| 520 |
SelectionEvent setDurationSincePreviousEvent(long durationMs) { |
| 521 |
this.mDurationSincePreviousEvent = durationMs; |
| 522 |
return this; |
| 523 |
} |
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
public int getEventIndex() { |
| 529 |
return mEventIndex; |
| 530 |
} |
| 531 |
|
| 532 |
|
| 533 |
@VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 534 |
public SelectionEvent setEventIndex(int index) { |
| 535 |
mEventIndex = index; |
| 536 |
return this; |
| 537 |
} |
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
@Nullable |
| 543 |
public TextClassificationSessionId getSessionId() { |
| 544 |
return mSessionId; |
| 545 |
} |
| 546 |
|
| 547 |
|
| 548 |
@VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 549 |
public SelectionEvent setSessionId(@Nullable TextClassificationSessionId id) { |
| 550 |
mSessionId = id; |
| 551 |
return this; |
| 552 |
} |
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
public int getStart() { |
| 559 |
return mStart; |
| 560 |
} |
| 561 |
|
| 562 |
|
| 563 |
@VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 564 |
public SelectionEvent setStart(int start) { |
| 565 |
mStart = start; |
| 566 |
return this; |
| 567 |
} |
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
public int getEnd() { |
| 574 |
return mEnd; |
| 575 |
} |
| 576 |
|
| 577 |
|
| 578 |
@VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 579 |
public SelectionEvent setEnd(int end) { |
| 580 |
mEnd = end; |
| 581 |
return this; |
| 582 |
} |
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
public int getSmartStart() { |
| 589 |
return mSmartStart; |
| 590 |
} |
| 591 |
|
| 592 |
|
| 593 |
@VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 594 |
public SelectionEvent setSmartStart(int start) { |
| 595 |
this.mSmartStart = start; |
| 596 |
return this; |
| 597 |
} |
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
public int getSmartEnd() { |
| 604 |
return mSmartEnd; |
| 605 |
} |
| 606 |
|
| 607 |
|
| 608 |
@VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 609 |
public SelectionEvent setSmartEnd(int end) { |
| 610 |
mSmartEnd = end; |
| 611 |
return this; |
| 612 |
} |
| 613 |
|
| 614 |
boolean isTerminal() { |
| 615 |
return isTerminal(mEventType); |
| 616 |
} |
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
public static boolean isTerminal(@EventType int eventType) { |
| 623 |
switch (eventType) { |
| 624 |
case ACTION_OVERTYPE: |
| 625 |
case ACTION_COPY: |
| 626 |
case ACTION_PASTE: |
| 627 |
case ACTION_CUT: |
| 628 |
case ACTION_SHARE: |
| 629 |
case ACTION_SMART_SHARE: |
| 630 |
case ACTION_DRAG: |
| 631 |
case ACTION_ABANDON: |
| 632 |
case ACTION_OTHER: |
| 633 |
return true; |
| 634 |
default: |
| 635 |
return false; |
| 636 |
} |
| 637 |
} |
| 638 |
|
| 639 |
@Override |
| 640 |
public int hashCode() { |
| 641 |
return Objects.hash(mAbsoluteStart, mAbsoluteEnd, mEventType, mEntityType, |
| 642 |
mWidgetVersion, mPackageName, mWidgetType, mInvocationMethod, mResultId, |
| 643 |
mEventTime, mDurationSinceSessionStart, mDurationSincePreviousEvent, |
| 644 |
mEventIndex, mSessionId, mStart, mEnd, mSmartStart, mSmartEnd, mSystemTcMetadata); |
| 645 |
} |
| 646 |
|
| 647 |
@Override |
| 648 |
public boolean equals(@Nullable Object obj) { |
| 649 |
if (this == obj) { |
| 650 |
return true; |
| 651 |
} |
| 652 |
if (!(obj instanceof SelectionEvent)) { |
| 653 |
return false; |
| 654 |
} |
| 655 |
|
| 656 |
final SelectionEvent other = (SelectionEvent) obj; |
| 657 |
return mAbsoluteStart == other.mAbsoluteStart |
| 658 |
&& mAbsoluteEnd == other.mAbsoluteEnd |
| 659 |
&& mEventType == other.mEventType |
| 660 |
&& Objects.equals(mEntityType, other.mEntityType) |
| 661 |
&& Objects.equals(mWidgetVersion, other.mWidgetVersion) |
| 662 |
&& Objects.equals(mPackageName, other.mPackageName) |
| 663 |
&& Objects.equals(mWidgetType, other.mWidgetType) |
| 664 |
&& mInvocationMethod == other.mInvocationMethod |
| 665 |
&& Objects.equals(mResultId, other.mResultId) |
| 666 |
&& mEventTime == other.mEventTime |
| 667 |
&& mDurationSinceSessionStart == other.mDurationSinceSessionStart |
| 668 |
&& mDurationSincePreviousEvent == other.mDurationSincePreviousEvent |
| 669 |
&& mEventIndex == other.mEventIndex |
| 670 |
&& Objects.equals(mSessionId, other.mSessionId) |
| 671 |
&& mStart == other.mStart |
| 672 |
&& mEnd == other.mEnd |
| 673 |
&& mSmartStart == other.mSmartStart |
| 674 |
&& mSmartEnd == other.mSmartEnd |
| 675 |
&& mSystemTcMetadata == other.mSystemTcMetadata; |
| 676 |
} |
| 677 |
|
| 678 |
@Override |
| 679 |
public String toString() { |
| 680 |
return String.format(Locale.US, |
| 681 |
"SelectionEvent {absoluteStart=%d, absoluteEnd=%d, eventType=%d, entityType=%s, " |
| 682 |
+ "widgetVersion=%s, packageName=%s, widgetType=%s, invocationMethod=%s, " |
| 683 |
+ "resultId=%s, eventTime=%d, durationSinceSessionStart=%d, " |
| 684 |
+ "durationSincePreviousEvent=%d, eventIndex=%d," |
| 685 |
+ "sessionId=%s, start=%d, end=%d, smartStart=%d, smartEnd=%d, " |
| 686 |
+ "systemTcMetadata=%s}", |
| 687 |
mAbsoluteStart, mAbsoluteEnd, mEventType, mEntityType, |
| 688 |
mWidgetVersion, mPackageName, mWidgetType, mInvocationMethod, |
| 689 |
mResultId, mEventTime, mDurationSinceSessionStart, mDurationSincePreviousEvent, |
| 690 |
mEventIndex, mSessionId, mStart, mEnd, mSmartStart, mSmartEnd, mSystemTcMetadata); |
| 691 |
} |
| 692 |
|
| 693 |
public static final @android.annotation.NonNull Creator<SelectionEvent> CREATOR = new Creator<SelectionEvent>() { |
| 694 |
@Override |
| 695 |
public SelectionEvent createFromParcel(Parcel in) { |
| 696 |
return new SelectionEvent(in); |
| 697 |
} |
| 698 |
|
| 699 |
@Override |
| 700 |
public SelectionEvent[] newArray(int size) { |
| 701 |
return new SelectionEvent[size]; |
| 702 |
} |
| 703 |
}; |
| 704 |
} |