Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(397)

Side by Side Diff: remoting/android/java/src/org/chromium/chromoting/SimulatedTouchInputStrategy.java

Issue 1687873002: Revert of Refactor Chromoting JNI code to use jni/Client (Java changes only). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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.Client; 13 import org.chromium.chromoting.jni.JniInterface;
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;
26 25
27 /** 26 /**
28 * Stores the time of the most recent left button single tap processed. 27 * Stores the time of the most recent left button single tap processed.
29 */ 28 */
30 private long mLastTapTimeInMs = 0; 29 private long mLastTapTimeInMs = 0;
31 30
32 /** 31 /**
33 * Stores the position of the last left button single tap processed. 32 * Stores the position of the last left button single tap processed.
34 */ 33 */
35 private Point mLastTapPoint; 34 private Point mLastTapPoint;
36 35
37 /** 36 /**
38 * The maximum distance, in pixels, between two points in order for them to be considered a 37 * The maximum distance, in pixels, between two points in order for them to be considered a
39 * double tap gesture. 38 * double tap gesture.
40 */ 39 */
41 private final int mDoubleTapSlopSquareInPx; 40 private final int mDoubleTapSlopSquareInPx;
42 41
43 /** 42 /**
44 * The interval, measured in milliseconds, in which two consecutive left but ton taps must 43 * The interval, measured in milliseconds, in which two consecutive left but ton taps must
45 * occur in order to be considered a double tap gesture. 44 * occur in order to be considered a double tap gesture.
46 */ 45 */
47 private final long mDoubleTapDurationInMs; 46 private final long mDoubleTapDurationInMs;
48 47
49 /** Mouse-button currently held down, or BUTTON_UNDEFINED otherwise. */ 48 /** Mouse-button currently held down, or BUTTON_UNDEFINED otherwise. */
50 private int mHeldButton = TouchInputHandlerInterface.BUTTON_UNDEFINED; 49 private int mHeldButton = TouchInputHandlerInterface.BUTTON_UNDEFINED;
51 50
52 public SimulatedTouchInputStrategy(RenderData renderData, Client client, Con text context) { 51 public SimulatedTouchInputStrategy(RenderData renderData, Context context) {
53 mRenderData = renderData; 52 mRenderData = renderData;
54 mClient = client;
55 53
56 ViewConfiguration config = ViewConfiguration.get(context); 54 ViewConfiguration config = ViewConfiguration.get(context);
57 mDoubleTapDurationInMs = config.getDoubleTapTimeout(); 55 mDoubleTapDurationInMs = config.getDoubleTapTimeout();
58 56
59 // In order to detect whether the user is attempting to double tap a tar get, we define a 57 // In order to detect whether the user is attempting to double tap a tar get, we define a
60 // region around the first point within which the second tap must occur. The standard way 58 // region around the first point within which the second tap must occur. The standard way
61 // to do this in an Android UI (meaning a UI comprised of UI elements wh ich conform to the 59 // to do this in an Android UI (meaning a UI comprised of UI elements wh ich conform to the
62 // visual guidelines for the platform which are 'Touch Friendly') is to use the 60 // visual guidelines for the platform which are 'Touch Friendly') is to use the
63 // getScaledDoubleTapSlop() value for checking this distance (or use a G estureDetector). 61 // getScaledDoubleTapSlop() value for checking this distance (or use a G estureDetector).
64 // Our scenario is a bit different as our UI consists of an image of a r emote machine where 62 // 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
116 114
117 @Override 115 @Override
118 public boolean onPressAndHold(int button) { 116 public boolean onPressAndHold(int button) {
119 injectMouseButtonEvent(button, true, getCursorPosition()); 117 injectMouseButtonEvent(button, true, getCursorPosition());
120 mHeldButton = button; 118 mHeldButton = button;
121 return true; 119 return true;
122 } 120 }
123 121
124 @Override 122 @Override
125 public void onScroll(float distanceX, float distanceY) { 123 public void onScroll(float distanceX, float distanceY) {
126 mClient.sendMouseWheelEvent((int) -distanceX, (int) -distanceY); 124 JniInterface.sendMouseWheelEvent((int) -distanceX, (int) -distanceY);
127 } 125 }
128 126
129 @Override 127 @Override
130 public void onMotionEvent(MotionEvent event) { 128 public void onMotionEvent(MotionEvent event) {
131 if (event.getActionMasked() == MotionEvent.ACTION_UP 129 if (event.getActionMasked() == MotionEvent.ACTION_UP
132 && mHeldButton != TouchInputHandlerInterface.BUTTON_UNDEFINED) { 130 && mHeldButton != TouchInputHandlerInterface.BUTTON_UNDEFINED) {
133 injectMouseButtonEvent(mHeldButton, false, getCursorPosition()); 131 injectMouseButtonEvent(mHeldButton, false, getCursorPosition());
134 mHeldButton = TouchInputHandlerInterface.BUTTON_UNDEFINED; 132 mHeldButton = TouchInputHandlerInterface.BUTTON_UNDEFINED;
135 } 133 }
136 } 134 }
137 135
138 @Override 136 @Override
139 public void injectCursorMoveEvent(int x, int y) { 137 public void injectCursorMoveEvent(int x, int y) {
140 mClient.sendMouseEvent(x, y, TouchInputHandlerInterface.BUTTON_UNDEFINED , false); 138 JniInterface.sendMouseEvent(x, y, TouchInputHandlerInterface.BUTTON_UNDE FINED, false);
141 } 139 }
142 140
143 @Override 141 @Override
144 public DesktopView.InputFeedbackType getShortPressFeedbackType() { 142 public DesktopView.InputFeedbackType getShortPressFeedbackType() {
145 return DesktopView.InputFeedbackType.SMALL_ANIMATION; 143 return DesktopView.InputFeedbackType.SMALL_ANIMATION;
146 } 144 }
147 145
148 @Override 146 @Override
149 public DesktopView.InputFeedbackType getLongPressFeedbackType() { 147 public DesktopView.InputFeedbackType getLongPressFeedbackType() {
150 return DesktopView.InputFeedbackType.LARGE_ANIMATION; 148 return DesktopView.InputFeedbackType.LARGE_ANIMATION;
(...skipping 24 matching lines...) Expand all
175 mRenderData.transform.mapPoints(currentValues); 173 mRenderData.transform.mapPoints(currentValues);
176 mRenderData.transform.mapPoints(previousValues); 174 mRenderData.transform.mapPoints(previousValues);
177 } 175 }
178 176
179 int deltaX = (int) (currentValues[0] - previousValues[0]); 177 int deltaX = (int) (currentValues[0] - previousValues[0]);
180 int deltaY = (int) (currentValues[1] - previousValues[1]); 178 int deltaY = (int) (currentValues[1] - previousValues[1]);
181 return ((deltaX * deltaX + deltaY * deltaY) <= mDoubleTapSlopSquareInPx) ; 179 return ((deltaX * deltaX + deltaY * deltaY) <= mDoubleTapSlopSquareInPx) ;
182 } 180 }
183 181
184 private void injectMouseButtonEvent(int button, boolean pressed, Point tapPo int) { 182 private void injectMouseButtonEvent(int button, boolean pressed, Point tapPo int) {
185 mClient.sendMouseEvent(tapPoint.x, tapPoint.y, button, pressed); 183 JniInterface.sendMouseEvent(tapPoint.x, tapPoint.y, button, pressed);
186 } 184 }
187 } 185 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698