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

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

Issue 2281983004: [Remoting Android] Move setAnimationEnabled to TouchInputHandler (Closed)
Patch Set: Resolve merge error Created 4 years, 3 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 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;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 * trigger more swipe actions. 86 * trigger more swipe actions.
87 */ 87 */
88 private boolean mSwipeCompleted = false; 88 private boolean mSwipeCompleted = false;
89 89
90 /** 90 /**
91 * Set to true when a 1 finger pan gesture originates with a longpress. Thi s means the user 91 * Set to true when a 1 finger pan gesture originates with a longpress. Thi s means the user
92 * is performing a drag operation. 92 * is performing a drag operation.
93 */ 93 */
94 private boolean mIsDragging = false; 94 private boolean mIsDragging = false;
95 95
96 private Object mOnCanvasRenderedListenerKey;
97
98 private Event.ParameterRunnable<Void> mProcessAnimationRunnable;
99
96 /** 100 /**
97 * This class implements fling animation for cursor 101 * This class implements fling animation for cursor
98 */ 102 */
99 private class CursorAnimationJob extends FlingAnimationJob { 103 private class CursorAnimationJob extends FlingAnimationJob {
100 public CursorAnimationJob(Context context) { 104 public CursorAnimationJob(Context context) {
101 super(context); 105 super(context);
102 } 106 }
103 107
104 @Override 108 @Override
105 protected void processAction(float deltaX, float deltaY) { 109 protected void processAction(float deltaX, float deltaY) {
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 float density = context.getResources().getDisplayMetrics().density; 207 float density = context.getResources().getDisplayMetrics().density;
204 mSwipeThreshold = 40 * density; 208 mSwipeThreshold = 40 * density;
205 209
206 mEdgeSlopInPx = ViewConfiguration.get(context).getScaledEdgeSlop(); 210 mEdgeSlopInPx = ViewConfiguration.get(context).getScaledEdgeSlop();
207 211
208 mInputStrategy = new NullInputStrategy(); 212 mInputStrategy = new NullInputStrategy();
209 213
210 mCursorAnimationJob = new CursorAnimationJob(context); 214 mCursorAnimationJob = new CursorAnimationJob(context);
211 mScrollAnimationJob = new ScrollAnimationJob(context); 215 mScrollAnimationJob = new ScrollAnimationJob(context);
212 216
217 mProcessAnimationRunnable = new Event.ParameterRunnable<Void>() {
Hzj_jie 2016/08/29 22:20:23 Why do not use SelfRemovableParameterRunner? It se
Yuwei 2016/08/29 23:24:25 Agreed. Done.
218 @Override
219 public void run(Void p) {
220 processAnimation();
221 }
222 };
223
213 attachViewEvents(viewer); 224 attachViewEvents(viewer);
214 } 225 }
215 226
216 public void processAnimation() { 227 public void processAnimation() {
217 boolean active = mCursorAnimationJob.processAnimation(); 228 boolean active = mCursorAnimationJob.processAnimation();
218 active |= mScrollAnimationJob.processAnimation(); 229 active |= mScrollAnimationJob.processAnimation();
219 230
220 if (!active) { 231 if (!active) {
221 mViewer.setAnimationEnabled(false); 232 setAnimationEnabled(false);
222 } 233 }
223 } 234 }
224 235
225 public void init(Desktop desktop, final InputEventSender injector) { 236 public void init(Desktop desktop, final InputEventSender injector) {
226 Preconditions.notNull(injector); 237 Preconditions.notNull(injector);
227 desktop.onInputModeChanged().add( 238 desktop.onInputModeChanged().add(
228 new Event.ParameterRunnable<InputModeChangedEventParameter>() { 239 new Event.ParameterRunnable<InputModeChangedEventParameter>() {
229 @Override 240 @Override
230 public void run(InputModeChangedEventParameter parameter) { 241 public void run(InputModeChangedEventParameter parameter) {
231 handleInputModeChanged(parameter, injector); 242 handleInputModeChanged(parameter, injector);
232 } 243 }
233 }); 244 });
234 245
235 desktop.onSystemUiVisibilityChanged().add( 246 desktop.onSystemUiVisibilityChanged().add(
236 new Event.ParameterRunnable<SystemUiVisibilityChangedEventParame ter>() { 247 new Event.ParameterRunnable<SystemUiVisibilityChangedEventParame ter>() {
237 @Override 248 @Override
238 public void run(SystemUiVisibilityChangedEventParameter para meter) { 249 public void run(SystemUiVisibilityChangedEventParameter para meter) {
239 handleSystemUiVisibilityChanged(parameter); 250 handleSystemUiVisibilityChanged(parameter);
240 } 251 }
241 }); 252 });
242 } 253 }
243 254
255 private void setAnimationEnabled(boolean enabled) {
256 if (enabled && mOnCanvasRenderedListenerKey == null) {
257 mOnCanvasRenderedListenerKey = mViewer.onCanvasRendered()
258 .add(mProcessAnimationRunnable);
259 processAnimation();
260 } else if (!enabled && mOnCanvasRenderedListenerKey != null) {
261 mViewer.onCanvasRendered().remove(mOnCanvasRenderedListenerKey);
262 mOnCanvasRenderedListenerKey = null;
Hzj_jie 2016/08/29 22:20:23 This seems a little bit strange to me. Is there an
Yuwei 2016/08/29 23:24:25 I think that case would never happen. I probably h
263 }
264 }
265
244 private void attachViewEvents(DesktopView viewer) { 266 private void attachViewEvents(DesktopView viewer) {
245 viewer.onTouch().add(new Event.ParameterRunnable<TouchEventParameter>() { 267 viewer.onTouch().add(new Event.ParameterRunnable<TouchEventParameter>() {
246 @Override 268 @Override
247 public void run(TouchEventParameter parameter) { 269 public void run(TouchEventParameter parameter) {
248 parameter.handled = handleTouchEvent(parameter.event); 270 parameter.handled = handleTouchEvent(parameter.event);
249 } 271 }
250 }); 272 });
251 viewer.onClientSizeChanged().add(new Event.ParameterRunnable<SizeChanged EventParameter>() { 273 viewer.onClientSizeChanged().add(new Event.ParameterRunnable<SizeChanged EventParameter>() {
252 @Override 274 @Override
253 public void run(SizeChangedEventParameter parameter) { 275 public void run(SizeChangedEventParameter parameter) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 339
318 // Avoid short-circuit logic evaluation - ensure all gesture detectors s ee all events so 340 // Avoid short-circuit logic evaluation - ensure all gesture detectors s ee all events so
319 // that they generate correct notifications. 341 // that they generate correct notifications.
320 boolean handled = mScroller.onTouchEvent(event); 342 boolean handled = mScroller.onTouchEvent(event);
321 handled |= mZoomer.onTouchEvent(event); 343 handled |= mZoomer.onTouchEvent(event);
322 handled |= mTapDetector.onTouchEvent(event); 344 handled |= mTapDetector.onTouchEvent(event);
323 mSwipePinchDetector.onTouchEvent(event); 345 mSwipePinchDetector.onTouchEvent(event);
324 346
325 switch (event.getActionMasked()) { 347 switch (event.getActionMasked()) {
326 case MotionEvent.ACTION_DOWN: 348 case MotionEvent.ACTION_DOWN:
327 mViewer.setAnimationEnabled(false); 349 setAnimationEnabled(false);
328 mSuppressCursorMovement = false; 350 mSuppressCursorMovement = false;
329 mSuppressFling = false; 351 mSuppressFling = false;
330 mSwipeCompleted = false; 352 mSwipeCompleted = false;
331 mIsDragging = false; 353 mIsDragging = false;
332 break; 354 break;
333 355
334 case MotionEvent.ACTION_POINTER_DOWN: 356 case MotionEvent.ACTION_POINTER_DOWN:
335 mTotalMotionY = 0; 357 mTotalMotionY = 0;
336 break; 358 break;
337 359
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 * Called when a fling gesture is recognized. 534 * Called when a fling gesture is recognized.
513 */ 535 */
514 @Override 536 @Override
515 public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { 537 public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
516 if (mSuppressFling) { 538 if (mSuppressFling) {
517 return false; 539 return false;
518 } 540 }
519 541
520 if (mScrollFling) { 542 if (mScrollFling) {
521 mScrollAnimationJob.startAnimation(velocityX, velocityY); 543 mScrollAnimationJob.startAnimation(velocityX, velocityY);
522 mViewer.setAnimationEnabled(true); 544 setAnimationEnabled(true);
523 mScrollFling = false; 545 mScrollFling = false;
524 return true; 546 return true;
525 } 547 }
526 548
527 if (mSuppressCursorMovement) { 549 if (mSuppressCursorMovement) {
528 return false; 550 return false;
529 } 551 }
530 552
531 // If cursor movement is suppressed, fling also needs to be suppress ed, as the 553 // If cursor movement is suppressed, fling also needs to be suppress ed, as the
532 // gesture-detector will still generate onFling() notifications base d on movement of 554 // gesture-detector will still generate onFling() notifications base d on movement of
533 // the fingers, which would result in unwanted cursor movement. 555 // the fingers, which would result in unwanted cursor movement.
534 mCursorAnimationJob.startAnimation(velocityX, velocityY); 556 mCursorAnimationJob.startAnimation(velocityX, velocityY);
535 mViewer.setAnimationEnabled(true); 557 setAnimationEnabled(true);
536 return true; 558 return true;
537 } 559 }
538 560
539 /** Called when the user is in the process of pinch-zooming. */ 561 /** Called when the user is in the process of pinch-zooming. */
540 @Override 562 @Override
541 public boolean onScale(ScaleGestureDetector detector) { 563 public boolean onScale(ScaleGestureDetector detector) {
542 if (!mSwipePinchDetector.isPinching()) { 564 if (!mSwipePinchDetector.isPinching()) {
543 return false; 565 return false;
544 } 566 }
545 567
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 float[] mappedPoints = mapScreenPointToImagePoint(screenX, screenY); 664 float[] mappedPoints = mapScreenPointToImagePoint(screenX, screenY);
643 665
644 float imageWidth = (float) mRenderData.imageWidth + EPSILON; 666 float imageWidth = (float) mRenderData.imageWidth + EPSILON;
645 float imageHeight = (float) mRenderData.imageHeight + EPSILON; 667 float imageHeight = (float) mRenderData.imageHeight + EPSILON;
646 668
647 return mappedPoints[0] < -EPSILON || mappedPoints[0] > imageWidth 669 return mappedPoints[0] < -EPSILON || mappedPoints[0] > imageWidth
648 || mappedPoints[1] < -EPSILON || mappedPoints[1] > imageHeig ht; 670 || mappedPoints[1] < -EPSILON || mappedPoints[1] > imageHeig ht;
649 } 671 }
650 } 672 }
651 } 673 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698