| 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 case TRACKPAD: | 326 case TRACKPAD: |
| 329 setInputStrategy(new TrackpadInputStrategy(mRenderData, injector
)); | 327 setInputStrategy(new TrackpadInputStrategy(mRenderData, injector
)); |
| 330 moveCursorToScreenCenter(); | 328 moveCursorToScreenCenter(); |
| 331 break; | 329 break; |
| 332 | 330 |
| 333 case TOUCH: | 331 case TOUCH: |
| 334 if (hostTouchCapability.isSupported()) { | 332 if (hostTouchCapability.isSupported()) { |
| 335 setInputStrategy(new TouchInputStrategy(mRenderData, injecto
r)); | 333 setInputStrategy(new TouchInputStrategy(mRenderData, injecto
r)); |
| 336 } else { | 334 } else { |
| 337 setInputStrategy( | 335 setInputStrategy( |
| 338 new SimulatedTouchInputStrategy(mRenderData, injecto
r, mContext)); | 336 new SimulatedTouchInputStrategy(mRenderData, injecto
r, mDesktop)); |
| 339 } | 337 } |
| 340 break; | 338 break; |
| 341 | 339 |
| 342 default: | 340 default: |
| 343 // Unreachable, but required by Google Java style and findbugs. | 341 // Unreachable, but required by Google Java style and findbugs. |
| 344 assert false : "Unreached"; | 342 assert false : "Unreached"; |
| 345 } | 343 } |
| 346 | 344 |
| 347 // Ensure the cursor state is updated appropriately. | 345 // Ensure the cursor state is updated appropriately. |
| 348 mRenderStub.setCursorVisibility(mRenderData.drawCursor); | 346 mRenderStub.setCursorVisibility(mRenderData.drawCursor); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 mInputStrategy.injectCursorMoveEvent((int) newX, (int) newY); | 468 mInputStrategy.injectCursorMoveEvent((int) newX, (int) newY); |
| 471 } | 469 } |
| 472 | 470 |
| 473 mRenderStub.moveCursor(mRenderData.getCursorPosition()); | 471 mRenderStub.moveCursor(mRenderData.getCursorPosition()); |
| 474 } | 472 } |
| 475 | 473 |
| 476 /** Processes a (multi-finger) swipe gesture. */ | 474 /** Processes a (multi-finger) swipe gesture. */ |
| 477 private boolean onSwipe() { | 475 private boolean onSwipe() { |
| 478 if (mTotalMotionY > mSwipeThreshold) { | 476 if (mTotalMotionY > mSwipeThreshold) { |
| 479 // Swipe down occurred. | 477 // Swipe down occurred. |
| 480 mViewer.showActionBar(); | 478 mDesktop.showSystemUi(); |
| 481 } else if (mTotalMotionY < -mSwipeThreshold) { | 479 } else if (mTotalMotionY < -mSwipeThreshold) { |
| 482 // Swipe up occurred. | 480 // Swipe up occurred. |
| 483 mViewer.showKeyboard(); | 481 mDesktop.showKeyboard(); |
| 484 } else { | 482 } else { |
| 485 return false; | 483 return false; |
| 486 } | 484 } |
| 487 | 485 |
| 488 mSuppressCursorMovement = true; | 486 mSuppressCursorMovement = true; |
| 489 mSuppressFling = true; | 487 mSuppressFling = true; |
| 490 mSwipeCompleted = true; | 488 mSwipeCompleted = true; |
| 491 return true; | 489 return true; |
| 492 } | 490 } |
| 493 | 491 |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 691 float[] mappedPoints = mapScreenPointToImagePoint(screenX, screenY); | 689 float[] mappedPoints = mapScreenPointToImagePoint(screenX, screenY); |
| 692 | 690 |
| 693 float imageWidth = (float) mRenderData.imageWidth + EPSILON; | 691 float imageWidth = (float) mRenderData.imageWidth + EPSILON; |
| 694 float imageHeight = (float) mRenderData.imageHeight + EPSILON; | 692 float imageHeight = (float) mRenderData.imageHeight + EPSILON; |
| 695 | 693 |
| 696 return mappedPoints[0] < -EPSILON || mappedPoints[0] > imageWidth | 694 return mappedPoints[0] < -EPSILON || mappedPoints[0] > imageWidth |
| 697 || mappedPoints[1] < -EPSILON || mappedPoints[1] > imageHeig
ht; | 695 || mappedPoints[1] < -EPSILON || mappedPoints[1] > imageHeig
ht; |
| 698 } | 696 } |
| 699 } | 697 } |
| 700 } | 698 } |
| OLD | NEW |