| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.os; |
| 18 |
|
| 19 |
import android.annotation.NonNull; |
| 20 |
import android.annotation.TestApi; |
| 21 |
import android.util.SparseArray; |
| 22 |
|
| 23 |
import com.android.internal.util.Preconditions; |
| 24 |
|
| 25 |
import java.util.ArrayList; |
| 26 |
import java.util.List; |
| 27 |
import java.util.Objects; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
@SuppressWarnings({"ParcelNotFinal", "ParcelCreator"}) |
| 38 |
public abstract class CombinedVibration implements Parcelable { |
| 39 |
private static final int PARCEL_TOKEN_MONO = 1; |
| 40 |
private static final int PARCEL_TOKEN_STEREO = 2; |
| 41 |
private static final int PARCEL_TOKEN_SEQUENTIAL = 3; |
| 42 |
|
| 43 |
|
| 44 |
CombinedVibration() { |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
@NonNull |
| 57 |
public static CombinedVibration createParallel(@NonNull VibrationEffect effect) { |
| 58 |
CombinedVibration combined = new Mono(effect); |
| 59 |
combined.validate(); |
| 60 |
return combined; |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
@NonNull |
| 72 |
public static ParallelCombination startParallel() { |
| 73 |
return new ParallelCombination(); |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
@TestApi |
| 87 |
@NonNull |
| 88 |
public static SequentialCombination startSequential() { |
| 89 |
return new SequentialCombination(); |
| 90 |
} |
| 91 |
|
| 92 |
@Override |
| 93 |
public int describeContents() { |
| 94 |
return 0; |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
@TestApi |
| 111 |
public abstract long getDuration(); |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
public boolean isHapticFeedbackCandidate() { |
| 124 |
return false; |
| 125 |
} |
| 126 |
|
| 127 |
|
| 128 |
public abstract void validate(); |
| 129 |
|
| 130 |
|
| 131 |
public abstract boolean hasVibrator(int vibratorId); |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
public static final class ParallelCombination { |
| 139 |
|
| 140 |
private final SparseArray<VibrationEffect> mEffects = new SparseArray<>(); |
| 141 |
|
| 142 |
ParallelCombination() { |
| 143 |
} |
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
@NonNull |
| 155 |
public ParallelCombination addVibrator(int vibratorId, @NonNull VibrationEffect effect) { |
| 156 |
mEffects.put(vibratorId, effect); |
| 157 |
return this; |
| 158 |
} |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
@NonNull |
| 171 |
public CombinedVibration combine() { |
| 172 |
if (mEffects.size() == 0) { |
| 173 |
throw new IllegalStateException( |
| 174 |
"Combination must have at least one element to combine."); |
| 175 |
} |
| 176 |
CombinedVibration combined = new Stereo(mEffects); |
| 177 |
combined.validate(); |
| 178 |
return combined; |
| 179 |
} |
| 180 |
} |
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
@TestApi |
| 189 |
public static final class SequentialCombination { |
| 190 |
|
| 191 |
private final ArrayList<CombinedVibration> mEffects = new ArrayList<>(); |
| 192 |
private final ArrayList<Integer> mDelays = new ArrayList<>(); |
| 193 |
|
| 194 |
SequentialCombination() { |
| 195 |
} |
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
@NonNull |
| 209 |
public SequentialCombination addNext(int vibratorId, @NonNull VibrationEffect effect) { |
| 210 |
return addNext(vibratorId, effect, 0); |
| 211 |
} |
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
@NonNull |
| 228 |
public SequentialCombination addNext(int vibratorId, @NonNull VibrationEffect effect, |
| 229 |
int delay) { |
| 230 |
return addNext( |
| 231 |
CombinedVibration.startParallel().addVibrator(vibratorId, effect).combine(), |
| 232 |
delay); |
| 233 |
} |
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
@NonNull |
| 247 |
public SequentialCombination addNext(@NonNull CombinedVibration effect) { |
| 248 |
return addNext(effect, 0); |
| 249 |
} |
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
@NonNull |
| 265 |
public SequentialCombination addNext(@NonNull CombinedVibration effect, int delay) { |
| 266 |
if (effect instanceof Sequential) { |
| 267 |
Sequential sequentialEffect = (Sequential) effect; |
| 268 |
int firstEffectIndex = mDelays.size(); |
| 269 |
mEffects.addAll(sequentialEffect.getEffects()); |
| 270 |
mDelays.addAll(sequentialEffect.getDelays()); |
| 271 |
mDelays.set(firstEffectIndex, delay + mDelays.get(firstEffectIndex)); |
| 272 |
} else { |
| 273 |
mEffects.add(effect); |
| 274 |
mDelays.add(delay); |
| 275 |
} |
| 276 |
return this; |
| 277 |
} |
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
@NonNull |
| 290 |
public CombinedVibration combine() { |
| 291 |
if (mEffects.size() == 0) { |
| 292 |
throw new IllegalStateException( |
| 293 |
"Combination must have at least one element to combine."); |
| 294 |
} |
| 295 |
CombinedVibration combined = new Sequential(mEffects, mDelays); |
| 296 |
combined.validate(); |
| 297 |
return combined; |
| 298 |
} |
| 299 |
} |
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
@TestApi |
| 308 |
public static final class Mono extends CombinedVibration { |
| 309 |
private final VibrationEffect mEffect; |
| 310 |
|
| 311 |
Mono(Parcel in) { |
| 312 |
mEffect = VibrationEffect.CREATOR.createFromParcel(in); |
| 313 |
} |
| 314 |
|
| 315 |
Mono(@NonNull VibrationEffect effect) { |
| 316 |
mEffect = effect; |
| 317 |
} |
| 318 |
|
| 319 |
@NonNull |
| 320 |
public VibrationEffect getEffect() { |
| 321 |
return mEffect; |
| 322 |
} |
| 323 |
|
| 324 |
@Override |
| 325 |
public long getDuration() { |
| 326 |
return mEffect.getDuration(); |
| 327 |
} |
| 328 |
|
| 329 |
|
| 330 |
@Override |
| 331 |
public boolean isHapticFeedbackCandidate() { |
| 332 |
return mEffect.isHapticFeedbackCandidate(); |
| 333 |
} |
| 334 |
|
| 335 |
|
| 336 |
@Override |
| 337 |
public void validate() { |
| 338 |
mEffect.validate(); |
| 339 |
} |
| 340 |
|
| 341 |
|
| 342 |
@Override |
| 343 |
public boolean hasVibrator(int vibratorId) { |
| 344 |
return true; |
| 345 |
} |
| 346 |
|
| 347 |
@Override |
| 348 |
public boolean equals(Object o) { |
| 349 |
if (!(o instanceof Mono)) { |
| 350 |
return false; |
| 351 |
} |
| 352 |
Mono other = (Mono) o; |
| 353 |
return mEffect.equals(other.mEffect); |
| 354 |
} |
| 355 |
|
| 356 |
@Override |
| 357 |
public int hashCode() { |
| 358 |
return Objects.hash(mEffect); |
| 359 |
} |
| 360 |
|
| 361 |
@Override |
| 362 |
public String toString() { |
| 363 |
return "Mono{mEffect=" + mEffect + '}'; |
| 364 |
} |
| 365 |
|
| 366 |
@Override |
| 367 |
public int describeContents() { |
| 368 |
return 0; |
| 369 |
} |
| 370 |
|
| 371 |
@Override |
| 372 |
public void writeToParcel(@NonNull Parcel out, int flags) { |
| 373 |
out.writeInt(PARCEL_TOKEN_MONO); |
| 374 |
mEffect.writeToParcel(out, flags); |
| 375 |
} |
| 376 |
|
| 377 |
@NonNull |
| 378 |
public static final Parcelable.Creator<Mono> CREATOR = |
| 379 |
new Parcelable.Creator<Mono>() { |
| 380 |
@Override |
| 381 |
public Mono createFromParcel(@NonNull Parcel in) { |
| 382 |
|
| 383 |
in.readInt(); |
| 384 |
return new Mono(in); |
| 385 |
} |
| 386 |
|
| 387 |
@Override |
| 388 |
@NonNull |
| 389 |
public Mono[] newArray(int size) { |
| 390 |
return new Mono[size]; |
| 391 |
} |
| 392 |
}; |
| 393 |
} |
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
@TestApi |
| 402 |
public static final class Stereo extends CombinedVibration { |
| 403 |
|
| 404 |
|
| 405 |
private final SparseArray<VibrationEffect> mEffects; |
| 406 |
|
| 407 |
Stereo(Parcel in) { |
| 408 |
int size = in.readInt(); |
| 409 |
mEffects = new SparseArray<>(size); |
| 410 |
for (int i = 0; i < size; i++) { |
| 411 |
int vibratorId = in.readInt(); |
| 412 |
mEffects.put(vibratorId, VibrationEffect.CREATOR.createFromParcel(in)); |
| 413 |
} |
| 414 |
} |
| 415 |
|
| 416 |
Stereo(@NonNull SparseArray<VibrationEffect> effects) { |
| 417 |
mEffects = new SparseArray<>(effects.size()); |
| 418 |
for (int i = 0; i < effects.size(); i++) { |
| 419 |
mEffects.put(effects.keyAt(i), effects.valueAt(i)); |
| 420 |
} |
| 421 |
} |
| 422 |
|
| 423 |
|
| 424 |
@NonNull |
| 425 |
public SparseArray<VibrationEffect> getEffects() { |
| 426 |
return mEffects; |
| 427 |
} |
| 428 |
|
| 429 |
@Override |
| 430 |
public long getDuration() { |
| 431 |
long maxDuration = Long.MIN_VALUE; |
| 432 |
boolean hasUnknownStep = false; |
| 433 |
for (int i = 0; i < mEffects.size(); i++) { |
| 434 |
long duration = mEffects.valueAt(i).getDuration(); |
| 435 |
if (duration == Long.MAX_VALUE) { |
| 436 |
|
| 437 |
return duration; |
| 438 |
} |
| 439 |
maxDuration = Math.max(maxDuration, duration); |
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
hasUnknownStep |= duration < 0; |
| 444 |
} |
| 445 |
if (hasUnknownStep) { |
| 446 |
|
| 447 |
return -1; |
| 448 |
} |
| 449 |
return maxDuration; |
| 450 |
} |
| 451 |
|
| 452 |
|
| 453 |
@Override |
| 454 |
public boolean isHapticFeedbackCandidate() { |
| 455 |
for (int i = 0; i < mEffects.size(); i++) { |
| 456 |
if (!mEffects.valueAt(i).isHapticFeedbackCandidate()) { |
| 457 |
return false; |
| 458 |
} |
| 459 |
} |
| 460 |
return true; |
| 461 |
} |
| 462 |
|
| 463 |
|
| 464 |
@Override |
| 465 |
public void validate() { |
| 466 |
Preconditions.checkArgument(mEffects.size() > 0, |
| 467 |
"There should be at least one effect set for a combined effect"); |
| 468 |
for (int i = 0; i < mEffects.size(); i++) { |
| 469 |
mEffects.valueAt(i).validate(); |
| 470 |
} |
| 471 |
} |
| 472 |
|
| 473 |
|
| 474 |
@Override |
| 475 |
public boolean hasVibrator(int vibratorId) { |
| 476 |
return mEffects.indexOfKey(vibratorId) >= 0; |
| 477 |
} |
| 478 |
|
| 479 |
@Override |
| 480 |
public boolean equals(Object o) { |
| 481 |
if (!(o instanceof Stereo)) { |
| 482 |
return false; |
| 483 |
} |
| 484 |
Stereo other = (Stereo) o; |
| 485 |
if (mEffects.size() != other.mEffects.size()) { |
| 486 |
return false; |
| 487 |
} |
| 488 |
for (int i = 0; i < mEffects.size(); i++) { |
| 489 |
if (!mEffects.valueAt(i).equals(other.mEffects.get(mEffects.keyAt(i)))) { |
| 490 |
return false; |
| 491 |
} |
| 492 |
} |
| 493 |
return true; |
| 494 |
} |
| 495 |
|
| 496 |
@Override |
| 497 |
public int hashCode() { |
| 498 |
return mEffects.contentHashCode(); |
| 499 |
} |
| 500 |
|
| 501 |
@Override |
| 502 |
public String toString() { |
| 503 |
return "Stereo{mEffects=" + mEffects + '}'; |
| 504 |
} |
| 505 |
|
| 506 |
@Override |
| 507 |
public int describeContents() { |
| 508 |
return 0; |
| 509 |
} |
| 510 |
|
| 511 |
@Override |
| 512 |
public void writeToParcel(@NonNull Parcel out, int flags) { |
| 513 |
out.writeInt(PARCEL_TOKEN_STEREO); |
| 514 |
out.writeInt(mEffects.size()); |
| 515 |
for (int i = 0; i < mEffects.size(); i++) { |
| 516 |
out.writeInt(mEffects.keyAt(i)); |
| 517 |
mEffects.valueAt(i).writeToParcel(out, flags); |
| 518 |
} |
| 519 |
} |
| 520 |
|
| 521 |
@NonNull |
| 522 |
public static final Parcelable.Creator<Stereo> CREATOR = |
| 523 |
new Parcelable.Creator<Stereo>() { |
| 524 |
@Override |
| 525 |
public Stereo createFromParcel(@NonNull Parcel in) { |
| 526 |
|
| 527 |
in.readInt(); |
| 528 |
return new Stereo(in); |
| 529 |
} |
| 530 |
|
| 531 |
@Override |
| 532 |
@NonNull |
| 533 |
public Stereo[] newArray(int size) { |
| 534 |
return new Stereo[size]; |
| 535 |
} |
| 536 |
}; |
| 537 |
} |
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
@TestApi |
| 546 |
public static final class Sequential extends CombinedVibration { |
| 547 |
|
| 548 |
private static final long MAX_HAPTIC_FEEDBACK_SEQUENCE_SIZE = 3; |
| 549 |
|
| 550 |
private final List<CombinedVibration> mEffects; |
| 551 |
private final List<Integer> mDelays; |
| 552 |
|
| 553 |
Sequential(Parcel in) { |
| 554 |
int size = in.readInt(); |
| 555 |
mEffects = new ArrayList<>(size); |
| 556 |
mDelays = new ArrayList<>(size); |
| 557 |
for (int i = 0; i < size; i++) { |
| 558 |
mDelays.add(in.readInt()); |
| 559 |
mEffects.add(CombinedVibration.CREATOR.createFromParcel(in)); |
| 560 |
} |
| 561 |
} |
| 562 |
|
| 563 |
Sequential(@NonNull List<CombinedVibration> effects, |
| 564 |
@NonNull List<Integer> delays) { |
| 565 |
mEffects = new ArrayList<>(effects); |
| 566 |
mDelays = new ArrayList<>(delays); |
| 567 |
} |
| 568 |
|
| 569 |
|
| 570 |
@NonNull |
| 571 |
public List<CombinedVibration> getEffects() { |
| 572 |
return mEffects; |
| 573 |
} |
| 574 |
|
| 575 |
|
| 576 |
@NonNull |
| 577 |
public List<Integer> getDelays() { |
| 578 |
return mDelays; |
| 579 |
} |
| 580 |
|
| 581 |
@Override |
| 582 |
public long getDuration() { |
| 583 |
boolean hasUnknownStep = false; |
| 584 |
long durations = 0; |
| 585 |
final int effectCount = mEffects.size(); |
| 586 |
for (int i = 0; i < effectCount; i++) { |
| 587 |
CombinedVibration effect = mEffects.get(i); |
| 588 |
long duration = effect.getDuration(); |
| 589 |
if (duration == Long.MAX_VALUE) { |
| 590 |
|
| 591 |
return duration; |
| 592 |
} |
| 593 |
durations += duration; |
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
hasUnknownStep |= duration < 0; |
| 598 |
} |
| 599 |
if (hasUnknownStep) { |
| 600 |
|
| 601 |
return -1; |
| 602 |
} |
| 603 |
long delays = 0; |
| 604 |
for (int i = 0; i < effectCount; i++) { |
| 605 |
delays += mDelays.get(i); |
| 606 |
} |
| 607 |
return durations + delays; |
| 608 |
} |
| 609 |
|
| 610 |
|
| 611 |
@Override |
| 612 |
public boolean isHapticFeedbackCandidate() { |
| 613 |
final int effectCount = mEffects.size(); |
| 614 |
if (effectCount > MAX_HAPTIC_FEEDBACK_SEQUENCE_SIZE) { |
| 615 |
return false; |
| 616 |
} |
| 617 |
for (int i = 0; i < effectCount; i++) { |
| 618 |
if (!mEffects.get(i).isHapticFeedbackCandidate()) { |
| 619 |
return false; |
| 620 |
} |
| 621 |
} |
| 622 |
return true; |
| 623 |
} |
| 624 |
|
| 625 |
|
| 626 |
@Override |
| 627 |
public void validate() { |
| 628 |
Preconditions.checkArgument(mEffects.size() > 0, |
| 629 |
"There should be at least one effect set for a combined effect"); |
| 630 |
Preconditions.checkArgument(mEffects.size() == mDelays.size(), |
| 631 |
"Effect and delays should have equal length"); |
| 632 |
final int effectCount = mEffects.size(); |
| 633 |
for (int i = 0; i < effectCount; i++) { |
| 634 |
if (mDelays.get(i) < 0) { |
| 635 |
throw new IllegalArgumentException("Delays must all be >= 0" |
| 636 |
+ " (delays=" + mDelays + ")"); |
| 637 |
} |
| 638 |
} |
| 639 |
for (int i = 0; i < effectCount; i++) { |
| 640 |
CombinedVibration effect = mEffects.get(i); |
| 641 |
if (effect instanceof Sequential) { |
| 642 |
throw new IllegalArgumentException( |
| 643 |
"There should be no nested sequential effects in a combined effect"); |
| 644 |
} |
| 645 |
effect.validate(); |
| 646 |
} |
| 647 |
} |
| 648 |
|
| 649 |
|
| 650 |
@Override |
| 651 |
public boolean hasVibrator(int vibratorId) { |
| 652 |
final int effectCount = mEffects.size(); |
| 653 |
for (int i = 0; i < effectCount; i++) { |
| 654 |
if (mEffects.get(i).hasVibrator(vibratorId)) { |
| 655 |
return true; |
| 656 |
} |
| 657 |
} |
| 658 |
return false; |
| 659 |
} |
| 660 |
|
| 661 |
@Override |
| 662 |
public boolean equals(Object o) { |
| 663 |
if (!(o instanceof Sequential)) { |
| 664 |
return false; |
| 665 |
} |
| 666 |
Sequential other = (Sequential) o; |
| 667 |
return mDelays.equals(other.mDelays) && mEffects.equals(other.mEffects); |
| 668 |
} |
| 669 |
|
| 670 |
@Override |
| 671 |
public int hashCode() { |
| 672 |
return Objects.hash(mEffects, mDelays); |
| 673 |
} |
| 674 |
|
| 675 |
@Override |
| 676 |
public String toString() { |
| 677 |
return "Sequential{mEffects=" + mEffects + ", mDelays=" + mDelays + '}'; |
| 678 |
} |
| 679 |
|
| 680 |
@Override |
| 681 |
public int describeContents() { |
| 682 |
return 0; |
| 683 |
} |
| 684 |
|
| 685 |
@Override |
| 686 |
public void writeToParcel(@NonNull Parcel out, int flags) { |
| 687 |
out.writeInt(PARCEL_TOKEN_SEQUENTIAL); |
| 688 |
out.writeInt(mEffects.size()); |
| 689 |
for (int i = 0; i < mEffects.size(); i++) { |
| 690 |
out.writeInt(mDelays.get(i)); |
| 691 |
mEffects.get(i).writeToParcel(out, flags); |
| 692 |
} |
| 693 |
} |
| 694 |
|
| 695 |
@NonNull |
| 696 |
public static final Parcelable.Creator<Sequential> CREATOR = |
| 697 |
new Parcelable.Creator<Sequential>() { |
| 698 |
@Override |
| 699 |
public Sequential createFromParcel(@NonNull Parcel in) { |
| 700 |
|
| 701 |
in.readInt(); |
| 702 |
return new Sequential(in); |
| 703 |
} |
| 704 |
|
| 705 |
@Override |
| 706 |
@NonNull |
| 707 |
public Sequential[] newArray(int size) { |
| 708 |
return new Sequential[size]; |
| 709 |
} |
| 710 |
}; |
| 711 |
} |
| 712 |
|
| 713 |
@NonNull |
| 714 |
public static final Parcelable.Creator<CombinedVibration> CREATOR = |
| 715 |
new Parcelable.Creator<CombinedVibration>() { |
| 716 |
@Override |
| 717 |
public CombinedVibration createFromParcel(Parcel in) { |
| 718 |
int token = in.readInt(); |
| 719 |
if (token == PARCEL_TOKEN_MONO) { |
| 720 |
return new Mono(in); |
| 721 |
} else if (token == PARCEL_TOKEN_STEREO) { |
| 722 |
return new Stereo(in); |
| 723 |
} else if (token == PARCEL_TOKEN_SEQUENTIAL) { |
| 724 |
return new Sequential(in); |
| 725 |
} else { |
| 726 |
throw new IllegalStateException( |
| 727 |
"Unexpected combined vibration event type token in parcel."); |
| 728 |
} |
| 729 |
} |
| 730 |
|
| 731 |
@Override |
| 732 |
public CombinedVibration[] newArray(int size) { |
| 733 |
return new CombinedVibration[size]; |
| 734 |
} |
| 735 |
}; |
| 736 |
} |