| 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.PointF; | 9 import android.graphics.PointF; |
| 10 import android.graphics.Rect; | 10 import android.graphics.Rect; |
| 11 import android.util.Pair; | 11 import android.util.Pair; |
| 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 java.util.ArrayList; | 17 import java.util.ArrayList; |
| 18 import java.util.List; | 18 import java.util.List; |
| 19 | 19 |
| 20 /** | 20 /** |
| 21 * This class is responsible for handling Touch input from the user. Touch even
ts which manipulate | 21 * This class is responsible for handling Touch input from the user. Touch even
ts which manipulate |
| 22 * the local canvas are handled in this class and any input which should be sent
to the remote host | 22 * the local canvas are handled in this class and any input which should be sent
to the remote host |
| 23 * are passed to the InputStrategyInterface implementation set by the DesktopVie
w. | 23 * are passed to the InputStrategyInterface implementation set by the DesktopVie
w. |
| 24 */ | 24 */ |
| 25 public class TouchInputHandler { | 25 public class TouchInputHandler { |
| 26 private static final float EPSILON = 0.001f; | 26 private static final float EPSILON = 0.001f; |
| 27 | 27 |
| 28 private final List<Pair<Object, Event<?>>> mAttachedEvents = new ArrayList<>
(); | 28 private final List<Pair<Object, Event<?>>> mAttachedEvents = new ArrayList<>
(); |
| 29 private final DesktopView mViewer; | 29 private final Desktop mDesktop; |
| 30 private final Context mContext; | |
| 31 private final RenderData mRenderData; | 30 private final RenderData mRenderData; |
| 32 private final DesktopCanvas mDesktopCanvas; | 31 private final DesktopCanvas mDesktopCanvas; |
| 33 private final RenderStub mRenderStub; | 32 private final RenderStub mRenderStub; |
| 34 private final GestureDetector mScroller; | 33 private final GestureDetector mScroller; |
| 35 private final ScaleGestureDetector mZoomer; | 34 private final ScaleGestureDetector mZoomer; |
| 36 private final TapGestureDetector mTapDetector; | 35 private final TapGestureDetector mTapDetector; |
| 37 | 36 |
| 38 /** Used to disambiguate a 2-finger gesture as a swipe or a pinch. */ | 37 /** Used to disambiguate a 2-finger gesture as a swipe or a pinch. */ |
| 39 private final SwipePinchDetector mSwipePinchDetector; | 38 private final SwipePinchDetector mSwipePinchDetector; |
| 40 | 39 |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 } | 186 } |
| 188 } | 187 } |
| 189 | 188 |
| 190 public TouchInputHandler(DesktopView viewer, Desktop desktop, RenderStub ren
derStub, | 189 public TouchInputHandler(DesktopView viewer, Desktop desktop, RenderStub ren
derStub, |
| 191 final InputEventSender injector) { | 190 final InputEventSender injector) { |
| 192 Preconditions.notNull(viewer); | 191 Preconditions.notNull(viewer); |
| 193 Preconditions.notNull(desktop); | 192 Preconditions.notNull(desktop); |
| 194 Preconditions.notNull(renderStub); | 193 Preconditions.notNull(renderStub); |
| 195 Preconditions.notNull(injector); | 194 Preconditions.notNull(injector); |
| 196 | 195 |
| 197 mViewer = viewer; | 196 mDesktop = desktop; |
| 198 mContext = desktop; | |
| 199 mRenderStub = renderStub; | 197 mRenderStub = renderStub; |
| 200 mRenderData = new RenderData(); | 198 mRenderData = new RenderData(); |
| 201 mDesktopCanvas = new DesktopCanvas(renderStub, mRenderData); | 199 mDesktopCanvas = new DesktopCanvas(renderStub, mRenderData); |
| 202 | 200 |
| 203 GestureListener listener = new GestureListener(); | 201 GestureListener listener = new GestureListener(); |
| 204 mScroller = new GestureDetector(desktop, listener, null, false); | 202 mScroller = new GestureDetector(desktop, listener, null, false); |
| 205 | 203 |
| 206 // If long-press is enabled, the gesture-detector will not emit any furt
her onScroll | 204 // If long-press is enabled, the gesture-detector will not emit any furt
her onScroll |
| 207 // notifications after the onLongPress notification. Since onScroll is b
eing used for | 205 // notifications after the onLongPress notification. Since onScroll is b
eing used for |
| 208 // moving the cursor, it means that the cursor would become stuck if the
finger were held | 206 // moving the cursor, it means that the cursor would become stuck if the
finger were held |
| (...skipping 17 matching lines...) Expand all Loading... |
| 226 mCursorAnimationJob = new CursorAnimationJob(desktop); | 224 mCursorAnimationJob = new CursorAnimationJob(desktop); |
| 227 mScrollAnimationJob = new ScrollAnimationJob(desktop); | 225 mScrollAnimationJob = new ScrollAnimationJob(desktop); |
| 228 | 226 |
| 229 mProcessAnimationCallback = new Event.ParameterCallback<Boolean, Void>()
{ | 227 mProcessAnimationCallback = new Event.ParameterCallback<Boolean, Void>()
{ |
| 230 @Override | 228 @Override |
| 231 public Boolean run(Void p) { | 229 public Boolean run(Void p) { |
| 232 return processAnimation(); | 230 return processAnimation(); |
| 233 } | 231 } |
| 234 }; | 232 }; |
| 235 | 233 |
| 236 attachEvent(mViewer.onTouch(), new Event.ParameterRunnable<TouchEventPar
ameter>() { | 234 attachEvent(viewer.onTouch(), new Event.ParameterRunnable<TouchEventPara
meter>() { |
| 237 @Override | 235 @Override |
| 238 public void run(TouchEventParameter parameter) { | 236 public void run(TouchEventParameter parameter) { |
| 239 parameter.handled = handleTouchEvent(parameter.event); | 237 parameter.handled = handleTouchEvent(parameter.event); |
| 240 } | 238 } |
| 241 }); | 239 }); |
| 242 | 240 |
| 243 attachEvent(desktop.onInputModeChanged(), | 241 attachEvent(desktop.onInputModeChanged(), |
| 244 new Event.ParameterRunnable<InputModeChangedEventParameter>() { | 242 new Event.ParameterRunnable<InputModeChangedEventParameter>() { |
| 245 @Override | 243 @Override |
| 246 public void run(InputModeChangedEventParameter parameter) { | 244 public void run(InputModeChangedEventParameter parameter) { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 mDesktopCanvas.adjustViewportForSystemUi(true); | 328 mDesktopCanvas.adjustViewportForSystemUi(true); |
| 331 moveCursorToScreenCenter(); | 329 moveCursorToScreenCenter(); |
| 332 break; | 330 break; |
| 333 | 331 |
| 334 case TOUCH: | 332 case TOUCH: |
| 335 mDesktopCanvas.adjustViewportForSystemUi(false); | 333 mDesktopCanvas.adjustViewportForSystemUi(false); |
| 336 if (hostTouchCapability.isSupported()) { | 334 if (hostTouchCapability.isSupported()) { |
| 337 setInputStrategy(new TouchInputStrategy(mRenderData, injecto
r)); | 335 setInputStrategy(new TouchInputStrategy(mRenderData, injecto
r)); |
| 338 } else { | 336 } else { |
| 339 setInputStrategy( | 337 setInputStrategy( |
| 340 new SimulatedTouchInputStrategy(mRenderData, injecto
r, mContext)); | 338 new SimulatedTouchInputStrategy(mRenderData, injecto
r, mDesktop)); |
| 341 } | 339 } |
| 342 break; | 340 break; |
| 343 | 341 |
| 344 default: | 342 default: |
| 345 // Unreachable, but required by Google Java style and findbugs. | 343 // Unreachable, but required by Google Java style and findbugs. |
| 346 assert false : "Unreached"; | 344 assert false : "Unreached"; |
| 347 } | 345 } |
| 348 | 346 |
| 349 // Ensure the cursor state is updated appropriately. | 347 // Ensure the cursor state is updated appropriately. |
| 350 mRenderStub.setCursorVisibility(mRenderData.drawCursor); | 348 mRenderStub.setCursorVisibility(mRenderData.drawCursor); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 mInputStrategy.injectCursorMoveEvent((int) newX, (int) newY); | 470 mInputStrategy.injectCursorMoveEvent((int) newX, (int) newY); |
| 473 } | 471 } |
| 474 | 472 |
| 475 mRenderStub.moveCursor(mRenderData.getCursorPosition()); | 473 mRenderStub.moveCursor(mRenderData.getCursorPosition()); |
| 476 } | 474 } |
| 477 | 475 |
| 478 /** Processes a (multi-finger) swipe gesture. */ | 476 /** Processes a (multi-finger) swipe gesture. */ |
| 479 private boolean onSwipe() { | 477 private boolean onSwipe() { |
| 480 if (mTotalMotionY > mSwipeThreshold) { | 478 if (mTotalMotionY > mSwipeThreshold) { |
| 481 // Swipe down occurred. | 479 // Swipe down occurred. |
| 482 mViewer.showActionBar(); | 480 mDesktop.showSystemUi(); |
| 483 } else if (mTotalMotionY < -mSwipeThreshold) { | 481 } else if (mTotalMotionY < -mSwipeThreshold) { |
| 484 // Swipe up occurred. | 482 // Swipe up occurred. |
| 485 mViewer.showKeyboard(); | 483 mDesktop.showKeyboard(); |
| 486 } else { | 484 } else { |
| 487 return false; | 485 return false; |
| 488 } | 486 } |
| 489 | 487 |
| 490 mSuppressCursorMovement = true; | 488 mSuppressCursorMovement = true; |
| 491 mSuppressFling = true; | 489 mSuppressFling = true; |
| 492 mSwipeCompleted = true; | 490 mSwipeCompleted = true; |
| 493 return true; | 491 return true; |
| 494 } | 492 } |
| 495 | 493 |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 693 float[] mappedPoints = mapScreenPointToImagePoint(screenX, screenY); | 691 float[] mappedPoints = mapScreenPointToImagePoint(screenX, screenY); |
| 694 | 692 |
| 695 float imageWidth = (float) mRenderData.imageWidth + EPSILON; | 693 float imageWidth = (float) mRenderData.imageWidth + EPSILON; |
| 696 float imageHeight = (float) mRenderData.imageHeight + EPSILON; | 694 float imageHeight = (float) mRenderData.imageHeight + EPSILON; |
| 697 | 695 |
| 698 return mappedPoints[0] < -EPSILON || mappedPoints[0] > imageWidth | 696 return mappedPoints[0] < -EPSILON || mappedPoints[0] > imageWidth |
| 699 || mappedPoints[1] < -EPSILON || mappedPoints[1] > imageHeig
ht; | 697 || mappedPoints[1] < -EPSILON || mappedPoints[1] > imageHeig
ht; |
| 700 } | 698 } |
| 701 } | 699 } |
| 702 } | 700 } |
| OLD | NEW |