OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chromoting; | 5 package org.chromium.chromoting; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.graphics.Point; | 8 import android.graphics.Point; |
9 import android.os.SystemClock; | 9 import android.os.SystemClock; |
10 import android.view.MotionEvent; | 10 import android.view.MotionEvent; |
11 import android.view.ViewConfiguration; | 11 import android.view.ViewConfiguration; |
12 | 12 |
13 import org.chromium.chromoting.jni.JniInterface; | 13 import org.chromium.chromoting.jni.Client; |
14 | 14 |
15 /** | 15 /** |
16 * This class receives local touch events and translates them into the appropria
te mouse based | 16 * This class receives local touch events and translates them into the appropria
te mouse based |
17 * events for the remote host. The net result is that the local input method fe
els like a touch | 17 * events for the remote host. The net result is that the local input method fe
els like a touch |
18 * interface but the remote host will be given mouse events to inject. | 18 * interface but the remote host will be given mouse events to inject. |
19 */ | 19 */ |
20 public class SimulatedTouchInputStrategy implements InputStrategyInterface { | 20 public class SimulatedTouchInputStrategy implements InputStrategyInterface { |
21 /** Used to adjust the size of the region used for double tap detection. */ | 21 /** Used to adjust the size of the region used for double tap detection. */ |
22 private static final float DOUBLE_TAP_SLOP_SCALE_FACTOR = 0.25f; | 22 private static final float DOUBLE_TAP_SLOP_SCALE_FACTOR = 0.25f; |
23 | 23 |
24 private final RenderData mRenderData; | 24 private final RenderData mRenderData; |
| 25 private final Client mClient; |
25 | 26 |
26 /** | 27 /** |
27 * Stores the time of the most recent left button single tap processed. | 28 * Stores the time of the most recent left button single tap processed. |
28 */ | 29 */ |
29 private long mLastTapTimeInMs = 0; | 30 private long mLastTapTimeInMs = 0; |
30 | 31 |
31 /** | 32 /** |
32 * Stores the position of the last left button single tap processed. | 33 * Stores the position of the last left button single tap processed. |
33 */ | 34 */ |
34 private Point mLastTapPoint; | 35 private Point mLastTapPoint; |
35 | 36 |
36 /** | 37 /** |
37 * The maximum distance, in pixels, between two points in order for them to
be considered a | 38 * The maximum distance, in pixels, between two points in order for them to
be considered a |
38 * double tap gesture. | 39 * double tap gesture. |
39 */ | 40 */ |
40 private final int mDoubleTapSlopSquareInPx; | 41 private final int mDoubleTapSlopSquareInPx; |
41 | 42 |
42 /** | 43 /** |
43 * The interval, measured in milliseconds, in which two consecutive left but
ton taps must | 44 * The interval, measured in milliseconds, in which two consecutive left but
ton taps must |
44 * occur in order to be considered a double tap gesture. | 45 * occur in order to be considered a double tap gesture. |
45 */ | 46 */ |
46 private final long mDoubleTapDurationInMs; | 47 private final long mDoubleTapDurationInMs; |
47 | 48 |
48 /** Mouse-button currently held down, or BUTTON_UNDEFINED otherwise. */ | 49 /** Mouse-button currently held down, or BUTTON_UNDEFINED otherwise. */ |
49 private int mHeldButton = TouchInputHandlerInterface.BUTTON_UNDEFINED; | 50 private int mHeldButton = TouchInputHandlerInterface.BUTTON_UNDEFINED; |
50 | 51 |
51 public SimulatedTouchInputStrategy(RenderData renderData, Context context) { | 52 public SimulatedTouchInputStrategy(RenderData renderData, Client client, Con
text context) { |
52 mRenderData = renderData; | 53 mRenderData = renderData; |
| 54 mClient = client; |
53 | 55 |
54 ViewConfiguration config = ViewConfiguration.get(context); | 56 ViewConfiguration config = ViewConfiguration.get(context); |
55 mDoubleTapDurationInMs = config.getDoubleTapTimeout(); | 57 mDoubleTapDurationInMs = config.getDoubleTapTimeout(); |
56 | 58 |
57 // In order to detect whether the user is attempting to double tap a tar
get, we define a | 59 // In order to detect whether the user is attempting to double tap a tar
get, we define a |
58 // region around the first point within which the second tap must occur.
The standard way | 60 // region around the first point within which the second tap must occur.
The standard way |
59 // to do this in an Android UI (meaning a UI comprised of UI elements wh
ich conform to the | 61 // to do this in an Android UI (meaning a UI comprised of UI elements wh
ich conform to the |
60 // visual guidelines for the platform which are 'Touch Friendly') is to
use the | 62 // visual guidelines for the platform which are 'Touch Friendly') is to
use the |
61 // getScaledDoubleTapSlop() value for checking this distance (or use a G
estureDetector). | 63 // getScaledDoubleTapSlop() value for checking this distance (or use a G
estureDetector). |
62 // Our scenario is a bit different as our UI consists of an image of a r
emote machine where | 64 // Our scenario is a bit different as our UI consists of an image of a r
emote machine where |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 | 116 |
115 @Override | 117 @Override |
116 public boolean onPressAndHold(int button) { | 118 public boolean onPressAndHold(int button) { |
117 injectMouseButtonEvent(button, true, getCursorPosition()); | 119 injectMouseButtonEvent(button, true, getCursorPosition()); |
118 mHeldButton = button; | 120 mHeldButton = button; |
119 return true; | 121 return true; |
120 } | 122 } |
121 | 123 |
122 @Override | 124 @Override |
123 public void onScroll(float distanceX, float distanceY) { | 125 public void onScroll(float distanceX, float distanceY) { |
124 JniInterface.sendMouseWheelEvent((int) -distanceX, (int) -distanceY); | 126 mClient.sendMouseWheelEvent((int) -distanceX, (int) -distanceY); |
125 } | 127 } |
126 | 128 |
127 @Override | 129 @Override |
128 public void onMotionEvent(MotionEvent event) { | 130 public void onMotionEvent(MotionEvent event) { |
129 if (event.getActionMasked() == MotionEvent.ACTION_UP | 131 if (event.getActionMasked() == MotionEvent.ACTION_UP |
130 && mHeldButton != TouchInputHandlerInterface.BUTTON_UNDEFINED) { | 132 && mHeldButton != TouchInputHandlerInterface.BUTTON_UNDEFINED) { |
131 injectMouseButtonEvent(mHeldButton, false, getCursorPosition()); | 133 injectMouseButtonEvent(mHeldButton, false, getCursorPosition()); |
132 mHeldButton = TouchInputHandlerInterface.BUTTON_UNDEFINED; | 134 mHeldButton = TouchInputHandlerInterface.BUTTON_UNDEFINED; |
133 } | 135 } |
134 } | 136 } |
135 | 137 |
136 @Override | 138 @Override |
137 public void injectCursorMoveEvent(int x, int y) { | 139 public void injectCursorMoveEvent(int x, int y) { |
138 JniInterface.sendMouseEvent(x, y, TouchInputHandlerInterface.BUTTON_UNDE
FINED, false); | 140 mClient.sendMouseEvent(x, y, TouchInputHandlerInterface.BUTTON_UNDEFINED
, false); |
139 } | 141 } |
140 | 142 |
141 @Override | 143 @Override |
142 public DesktopView.InputFeedbackType getShortPressFeedbackType() { | 144 public DesktopView.InputFeedbackType getShortPressFeedbackType() { |
143 return DesktopView.InputFeedbackType.SMALL_ANIMATION; | 145 return DesktopView.InputFeedbackType.SMALL_ANIMATION; |
144 } | 146 } |
145 | 147 |
146 @Override | 148 @Override |
147 public DesktopView.InputFeedbackType getLongPressFeedbackType() { | 149 public DesktopView.InputFeedbackType getLongPressFeedbackType() { |
148 return DesktopView.InputFeedbackType.LARGE_ANIMATION; | 150 return DesktopView.InputFeedbackType.LARGE_ANIMATION; |
(...skipping 24 matching lines...) Expand all Loading... |
173 mRenderData.transform.mapPoints(currentValues); | 175 mRenderData.transform.mapPoints(currentValues); |
174 mRenderData.transform.mapPoints(previousValues); | 176 mRenderData.transform.mapPoints(previousValues); |
175 } | 177 } |
176 | 178 |
177 int deltaX = (int) (currentValues[0] - previousValues[0]); | 179 int deltaX = (int) (currentValues[0] - previousValues[0]); |
178 int deltaY = (int) (currentValues[1] - previousValues[1]); | 180 int deltaY = (int) (currentValues[1] - previousValues[1]); |
179 return ((deltaX * deltaX + deltaY * deltaY) <= mDoubleTapSlopSquareInPx)
; | 181 return ((deltaX * deltaX + deltaY * deltaY) <= mDoubleTapSlopSquareInPx)
; |
180 } | 182 } |
181 | 183 |
182 private void injectMouseButtonEvent(int button, boolean pressed, Point tapPo
int) { | 184 private void injectMouseButtonEvent(int button, boolean pressed, Point tapPo
int) { |
183 JniInterface.sendMouseEvent(tapPoint.x, tapPoint.y, button, pressed); | 185 mClient.sendMouseEvent(tapPoint.x, tapPoint.y, button, pressed); |
184 } | 186 } |
185 } | 187 } |
OLD | NEW |