Chromium Code Reviews| Index: remoting/android/java/src/org/chromium/chromoting/InputState.java |
| diff --git a/remoting/android/java/src/org/chromium/chromoting/InputState.java b/remoting/android/java/src/org/chromium/chromoting/InputState.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5cab4d02b5997330d38c413cffa92e7e66e18f59 |
| --- /dev/null |
| +++ b/remoting/android/java/src/org/chromium/chromoting/InputState.java |
| @@ -0,0 +1,99 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.chromoting; |
| + |
| +/** |
| + * A state machine to indicate user input actions. It stores the start action (tap or long tap), |
| + * 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.
|
| + */ |
| +public class InputState { |
| + /** |
| + * A settable {@link InputState}. |
| + */ |
| + public static final class Settable extends InputState { |
| + public void setFingerCount(int fingerCount) { |
| + mFingerCount = fingerCount; |
| + if (mFingerCount == 0) { |
| + mStartAction = StartAction.UNDEFINED; |
| + mDetectedAction = DetectedAction.UNDEFINED; |
| + } |
| + } |
| + |
| + public void setStartAction(StartAction startAction) { |
| + Preconditions.isTrue(startAction != StartAction.UNDEFINED); |
| + mStartAction = startAction; |
| + } |
| + |
| + public void setDetectedAction(DetectedAction detectedAction) { |
| + Preconditions.isTrue(detectedAction != DetectedAction.UNDEFINED); |
| + mDetectedAction = detectedAction; |
| + } |
| + } |
| + |
| + public enum StartAction { |
| + UNDEFINED, |
| + // The action started from a long press. Note, a tap won't need to impact InputState. |
| + LONG_PRESS, |
| + } |
| + |
| + public enum DetectedAction { |
| + UNDEFINED, |
| + SCROLL, |
| + SCROLL_FLING, |
| + // AFTER_SCROLL_FLING is a fake action to indicate the state after a scroll fling has been |
| + // performed. |
| + AFTER_SCROLL_FLING, |
| + FLING, |
| + SCALE, |
| + SWIPE, |
| + MOVE, |
| + SCROLL_EDGE, |
| + } |
| + |
| + protected int mFingerCount; |
| + protected StartAction mStartAction; |
| + protected DetectedAction mDetectedAction; |
| + |
| + public InputState() { |
| + mStartAction = StartAction.UNDEFINED; |
| + mFingerCount = 0; |
| + mDetectedAction = DetectedAction.UNDEFINED; |
| + } |
| + |
| + public int getFingerCount() { |
| + return mFingerCount; |
| + } |
| + |
| + public StartAction getStartAction() { |
| + return mStartAction; |
| + } |
| + |
| + public DetectedAction getDetectedAction() { |
| + return mDetectedAction; |
| + } |
| + |
| + 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.
|
| + return mDetectedAction == DetectedAction.SWIPE |
| + || mDetectedAction == DetectedAction.SCROLL_FLING |
| + || mDetectedAction == DetectedAction.SCROLL_EDGE; |
| + } |
| + |
| + public boolean suppressFling() { |
|
Lambros
2016/07/14 18:58:07
Same here.
Hzj_jie
2016/07/14 23:18:06
Done.
|
| + return mDetectedAction == DetectedAction.SWIPE |
| + || mStartAction == StartAction.LONG_PRESS; |
| + } |
| + |
| + public boolean scrollFling() { |
|
Lambros
2016/07/14 18:58:07
isScrollFling()
Hzj_jie
2016/07/14 23:18:06
Done.
|
| + return mDetectedAction == DetectedAction.SCROLL_FLING; |
| + } |
| + |
| + public boolean swipeCompleted() { |
| + return mDetectedAction == DetectedAction.SWIPE; |
| + } |
| + |
| + public boolean isDragging() { |
| + return mStartAction == StartAction.LONG_PRESS; |
| + } |
| +} |