Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package org.chromium.chromoting; | |
| 6 | |
| 7 /** | |
| 8 * A state machine to indicate user input actions. It stores the start action (t ap or long tap), | |
| 9 * finger count, detected action, etc. This class is not thread-safe. | |
|
Lambros
2016/07/14 18:58:07
You can remove the thread-safety comment if you li
Hzj_jie
2016/07/14 23:18:06
Done.
| |
| 10 */ | |
| 11 public class InputState { | |
| 12 /** | |
| 13 * A settable {@link InputState}. | |
| 14 */ | |
| 15 public static final class Settable extends InputState { | |
| 16 public void setFingerCount(int fingerCount) { | |
| 17 mFingerCount = fingerCount; | |
| 18 if (mFingerCount == 0) { | |
| 19 mStartAction = StartAction.UNDEFINED; | |
| 20 mDetectedAction = DetectedAction.UNDEFINED; | |
| 21 } | |
| 22 } | |
| 23 | |
| 24 public void setStartAction(StartAction startAction) { | |
| 25 Preconditions.isTrue(startAction != StartAction.UNDEFINED); | |
| 26 mStartAction = startAction; | |
| 27 } | |
| 28 | |
| 29 public void setDetectedAction(DetectedAction detectedAction) { | |
| 30 Preconditions.isTrue(detectedAction != DetectedAction.UNDEFINED); | |
| 31 mDetectedAction = detectedAction; | |
| 32 } | |
| 33 } | |
| 34 | |
| 35 public enum StartAction { | |
| 36 UNDEFINED, | |
| 37 // The action started from a long press. Note, a tap won't need to impac t InputState. | |
| 38 LONG_PRESS, | |
| 39 } | |
| 40 | |
| 41 public enum DetectedAction { | |
| 42 UNDEFINED, | |
| 43 SCROLL, | |
| 44 SCROLL_FLING, | |
| 45 // AFTER_SCROLL_FLING is a fake action to indicate the state after a scr oll fling has been | |
| 46 // performed. | |
| 47 AFTER_SCROLL_FLING, | |
| 48 FLING, | |
| 49 SCALE, | |
| 50 SWIPE, | |
| 51 MOVE, | |
| 52 SCROLL_EDGE, | |
| 53 } | |
| 54 | |
| 55 protected int mFingerCount; | |
| 56 protected StartAction mStartAction; | |
| 57 protected DetectedAction mDetectedAction; | |
| 58 | |
| 59 public InputState() { | |
| 60 mStartAction = StartAction.UNDEFINED; | |
| 61 mFingerCount = 0; | |
| 62 mDetectedAction = DetectedAction.UNDEFINED; | |
| 63 } | |
| 64 | |
| 65 public int getFingerCount() { | |
| 66 return mFingerCount; | |
| 67 } | |
| 68 | |
| 69 public StartAction getStartAction() { | |
| 70 return mStartAction; | |
| 71 } | |
| 72 | |
| 73 public DetectedAction getDetectedAction() { | |
| 74 return mDetectedAction; | |
| 75 } | |
| 76 | |
| 77 public boolean suppressCursorMovement() { | |
|
Lambros
2016/07/14 18:58:07
Name this as a boolean-noun instead of a verb? Per
Hzj_jie
2016/07/14 23:18:06
Done.
| |
| 78 return mDetectedAction == DetectedAction.SWIPE | |
| 79 || mDetectedAction == DetectedAction.SCROLL_FLING | |
| 80 || mDetectedAction == DetectedAction.SCROLL_EDGE; | |
| 81 } | |
| 82 | |
| 83 public boolean suppressFling() { | |
|
Lambros
2016/07/14 18:58:07
Same here.
Hzj_jie
2016/07/14 23:18:06
Done.
| |
| 84 return mDetectedAction == DetectedAction.SWIPE | |
| 85 || mStartAction == StartAction.LONG_PRESS; | |
| 86 } | |
| 87 | |
| 88 public boolean scrollFling() { | |
|
Lambros
2016/07/14 18:58:07
isScrollFling()
Hzj_jie
2016/07/14 23:18:06
Done.
| |
| 89 return mDetectedAction == DetectedAction.SCROLL_FLING; | |
| 90 } | |
| 91 | |
| 92 public boolean swipeCompleted() { | |
| 93 return mDetectedAction == DetectedAction.SWIPE; | |
| 94 } | |
| 95 | |
| 96 public boolean isDragging() { | |
| 97 return mStartAction == StartAction.LONG_PRESS; | |
| 98 } | |
| 99 } | |
| OLD | NEW |