OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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.Matrix; | 8 import android.graphics.Matrix; |
9 import android.graphics.Point; | 9 import android.graphics.Point; |
10 import android.graphics.PointF; | 10 import android.graphics.PointF; |
11 import android.graphics.Rect; | 11 import android.graphics.Rect; |
12 import android.view.GestureDetector; | 12 import android.view.GestureDetector; |
13 import android.view.MotionEvent; | 13 import android.view.MotionEvent; |
14 import android.view.ScaleGestureDetector; | 14 import android.view.ScaleGestureDetector; |
15 import android.view.ViewConfiguration; | 15 import android.view.ViewConfiguration; |
16 | 16 |
17 import org.chromium.chromoting.jni.Client; | |
18 | |
17 /** | 19 /** |
18 * This class is responsible for handling Touch input from the user. Touch even ts which manipulate | 20 * This class is responsible for handling Touch input from the user. Touch even ts which manipulate |
19 * the local canvas are handled in this class and any input which should be sent to the remote host | 21 * the local canvas are handled in this class and any input which should be sent to the remote host |
20 * are passed to the InputStrategyInterface implementation set by the DesktopVie w. | 22 * are passed to the InputStrategyInterface implementation set by the DesktopVie w. |
21 */ | 23 */ |
22 public class TouchInputHandler implements TouchInputHandlerInterface { | 24 public class TouchInputHandler implements TouchInputHandlerInterface { |
23 private final DesktopViewInterface mViewer; | 25 private final DesktopViewInterface mViewer; |
26 private final Context mContext; | |
24 private final RenderData mRenderData; | 27 private final RenderData mRenderData; |
25 private final DesktopCanvas mDesktopCanvas; | 28 private final DesktopCanvas mDesktopCanvas; |
26 private InputStrategyInterface mInputStrategy; | 29 private InputStrategyInterface mInputStrategy; |
27 | 30 |
28 private GestureDetector mScroller; | 31 private GestureDetector mScroller; |
29 private ScaleGestureDetector mZoomer; | 32 private ScaleGestureDetector mZoomer; |
30 private TapGestureDetector mTapDetector; | 33 private TapGestureDetector mTapDetector; |
31 | 34 |
32 /** Used to disambiguate a 2-finger gesture as a swipe or a pinch. */ | 35 /** Used to disambiguate a 2-finger gesture as a swipe or a pinch. */ |
33 private SwipePinchDetector mSwipePinchDetector; | 36 private SwipePinchDetector mSwipePinchDetector; |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
173 } | 176 } |
174 | 177 |
175 @Override | 178 @Override |
176 public boolean isIndirectInputMode() { | 179 public boolean isIndirectInputMode() { |
177 return false; | 180 return false; |
178 } | 181 } |
179 } | 182 } |
180 | 183 |
181 public TouchInputHandler(DesktopViewInterface viewer, Context context, Rende rData renderData) { | 184 public TouchInputHandler(DesktopViewInterface viewer, Context context, Rende rData renderData) { |
182 mViewer = viewer; | 185 mViewer = viewer; |
186 mContext = context; | |
183 mRenderData = renderData; | 187 mRenderData = renderData; |
184 mDesktopCanvas = new DesktopCanvas(mViewer, mRenderData); | 188 mDesktopCanvas = new DesktopCanvas(mViewer, mRenderData); |
185 | 189 |
186 GestureListener listener = new GestureListener(); | 190 GestureListener listener = new GestureListener(); |
187 mScroller = new GestureDetector(context, listener, null, false); | 191 mScroller = new GestureDetector(context, listener, null, false); |
188 | 192 |
189 // If long-press is enabled, the gesture-detector will not emit any furt her onScroll | 193 // If long-press is enabled, the gesture-detector will not emit any furt her onScroll |
190 // notifications after the onLongPress notification. Since onScroll is b eing used for | 194 // notifications after the onLongPress notification. Since onScroll is b eing used for |
191 // moving the cursor, it means that the cursor would become stuck if the finger were held | 195 // moving the cursor, it means that the cursor would become stuck if the finger were held |
192 // down too long. | 196 // down too long. |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
250 mDesktopCanvas.repositionImageWithZoom(true); | 254 mDesktopCanvas.repositionImageWithZoom(true); |
251 } | 255 } |
252 | 256 |
253 @Override | 257 @Override |
254 public void onHostSizeChanged(int width, int height) { | 258 public void onHostSizeChanged(int width, int height) { |
255 moveViewport((float) width / 2, (float) height / 2); | 259 moveViewport((float) width / 2, (float) height / 2); |
256 mDesktopCanvas.resizeImageToFitScreen(); | 260 mDesktopCanvas.resizeImageToFitScreen(); |
257 } | 261 } |
258 | 262 |
259 @Override | 263 @Override |
260 public void onSoftInputMethodVisibilityChanged(boolean inputMethodVisible, R ect bounds) { | |
261 synchronized (mRenderData) { | |
262 if (inputMethodVisible) { | |
263 mDesktopCanvas.setInputMethodOffsetValues(mRenderData.screenWidt h - bounds.right, | |
264 mRenderData.screenHeig ht - bounds.bottom); | |
265 } else { | |
266 mDesktopCanvas.setInputMethodOffsetValues(0, 0); | |
267 } | |
268 } | |
269 | |
270 mDesktopCanvas.repositionImage(true); | |
271 } | |
272 | |
273 @Override | |
274 public void processAnimation() { | 264 public void processAnimation() { |
275 boolean active = mCursorAnimationJob.processAnimation(); | 265 boolean active = mCursorAnimationJob.processAnimation(); |
276 active |= mScrollAnimationJob.processAnimation(); | 266 active |= mScrollAnimationJob.processAnimation(); |
277 | 267 |
278 if (!active) { | 268 if (!active) { |
279 mViewer.setAnimationEnabled(false); | 269 mViewer.setAnimationEnabled(false); |
280 } | 270 } |
281 } | 271 } |
282 | 272 |
283 @Override | 273 @Override |
284 public void setInputStrategy(InputStrategyInterface inputStrategy) { | 274 public void init(Desktop desktop, final Client client) { |
275 desktop.onInputModeChanged().add( | |
276 new Event.ParameterRunnable<InputModeChangedEventParameter>() { | |
277 @Override | |
278 public void run(InputModeChangedEventParameter parameter) { | |
279 final Desktop.InputMode inputMode = parameter.inputMode; | |
Lambros
2016/06/06 22:11:34
I think this would be more readable if you pull th
Hzj_jie
2016/06/07 01:26:13
Done.
| |
280 final CapabilityManager.HostCapability hostTouchCapabili ty = | |
281 parameter.hostCapability; | |
282 // We need both input mode and host input capabilities t o select the input | |
283 // strategy. | |
284 if (!inputMode.isSet() || !hostTouchCapability.isSet()) { | |
285 return; | |
286 } | |
287 | |
288 switch (inputMode) { | |
289 case TRACKPAD: | |
290 setInputStrategy(new TrackpadInputStrategy(mRend erData, client)); | |
291 break; | |
292 | |
293 case TOUCH: | |
294 if (hostTouchCapability.isSupported()) { | |
295 setInputStrategy(new TouchInputStrategy(mRen derData, client)); | |
296 } else { | |
297 setInputStrategy(new SimulatedTouchInputStra tegy( | |
298 mRenderData, client, mContext)); | |
299 } | |
300 break; | |
301 | |
302 default: | |
303 // Unreachable, but required by Google Java styl e and findbugs. | |
304 assert false : "Unreached"; | |
305 } | |
306 | |
307 // Ensure the cursor state is updated appropriately. | |
308 // TODO (zijiehe): Move repaint control out of DesktopVi ew. | |
309 if (mViewer instanceof DesktopView) { | |
310 ((DesktopView) mViewer).requestRepaint(); | |
311 } | |
312 } | |
313 }); | |
314 | |
315 desktop.onSoftInputMethodVisibilityChanged().add( | |
316 new Event.ParameterRunnable<SoftInputMethodVisibilityChangedEven tParameter>() { | |
317 @Override | |
318 public void run(SoftInputMethodVisibilityChangedEventParamet er parameter) { | |
319 synchronized (mRenderData) { | |
Lambros
2016/06/06 22:11:34
And this.
Hzj_jie
2016/06/07 01:26:13
Done.
| |
320 if (parameter.visible) { | |
321 mDesktopCanvas.setInputMethodOffsetValues( | |
322 mRenderData.screenWidth - parameter.righ t, | |
323 mRenderData.screenHeight - parameter.bot tom); | |
324 } else { | |
325 mDesktopCanvas.setInputMethodOffsetValues(0, 0); | |
326 } | |
327 } | |
328 | |
329 mDesktopCanvas.repositionImage(true); | |
330 } | |
331 }); | |
332 } | |
333 | |
334 private void setInputStrategy(InputStrategyInterface inputStrategy) { | |
285 // Since the rules for flinging differ between input modes, we want to s top running the | 335 // Since the rules for flinging differ between input modes, we want to s top running the |
286 // current fling animation when the mode changes to prevent a wonky expe rience. | 336 // current fling animation when the mode changes to prevent a wonky expe rience. |
287 mCursorAnimationJob.abortAnimation(); | 337 mCursorAnimationJob.abortAnimation(); |
288 mScrollAnimationJob.abortAnimation(); | 338 mScrollAnimationJob.abortAnimation(); |
289 mInputStrategy = inputStrategy; | 339 mInputStrategy = inputStrategy; |
290 } | 340 } |
291 | 341 |
292 /** Moves the desired center of the viewport using the specified deltas. */ | 342 /** Moves the desired center of the viewport using the specified deltas. */ |
293 private void moveViewportWithOffset(float deltaX, float deltaY) { | 343 private void moveViewportWithOffset(float deltaX, float deltaY) { |
294 // If we are in an indirect mode or are in the middle of a drag operatio n, then we want to | 344 // If we are in an indirect mode or are in the middle of a drag operatio n, then we want to |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
567 case 2: | 617 case 2: |
568 return BUTTON_RIGHT; | 618 return BUTTON_RIGHT; |
569 case 3: | 619 case 3: |
570 return BUTTON_MIDDLE; | 620 return BUTTON_MIDDLE; |
571 default: | 621 default: |
572 return BUTTON_UNDEFINED; | 622 return BUTTON_UNDEFINED; |
573 } | 623 } |
574 } | 624 } |
575 } | 625 } |
576 } | 626 } |
OLD | NEW |