Chromium Code Reviews| Index: remoting/android/java/src/org/chromium/chromoting/TouchInputHandler.java |
| diff --git a/remoting/android/java/src/org/chromium/chromoting/TouchInputHandler.java b/remoting/android/java/src/org/chromium/chromoting/TouchInputHandler.java |
| index 83af5bcf9809fab329ae28472c92da12f608517c..3270f02acd9fdf185a9da5e635a5b0a1c8f0b4cd 100644 |
| --- a/remoting/android/java/src/org/chromium/chromoting/TouchInputHandler.java |
| +++ b/remoting/android/java/src/org/chromium/chromoting/TouchInputHandler.java |
| @@ -93,6 +93,10 @@ public class TouchInputHandler { |
| */ |
| private boolean mIsDragging = false; |
| + private Object mOnCanvasRenderedListenerKey; |
| + |
| + private Event.ParameterRunnable<Void> mProcessAnimationRunnable; |
| + |
| /** |
| * This class implements fling animation for cursor |
| */ |
| @@ -210,6 +214,13 @@ public class TouchInputHandler { |
| mCursorAnimationJob = new CursorAnimationJob(context); |
| mScrollAnimationJob = new ScrollAnimationJob(context); |
| + 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.
|
| + @Override |
| + public void run(Void p) { |
| + processAnimation(); |
| + } |
| + }; |
| + |
| attachViewEvents(viewer); |
| } |
| @@ -218,7 +229,7 @@ public class TouchInputHandler { |
| active |= mScrollAnimationJob.processAnimation(); |
| if (!active) { |
| - mViewer.setAnimationEnabled(false); |
| + setAnimationEnabled(false); |
| } |
| } |
| @@ -241,6 +252,17 @@ public class TouchInputHandler { |
| }); |
| } |
| + private void setAnimationEnabled(boolean enabled) { |
| + if (enabled && mOnCanvasRenderedListenerKey == null) { |
| + mOnCanvasRenderedListenerKey = mViewer.onCanvasRendered() |
| + .add(mProcessAnimationRunnable); |
| + processAnimation(); |
| + } else if (!enabled && mOnCanvasRenderedListenerKey != null) { |
| + mViewer.onCanvasRendered().remove(mOnCanvasRenderedListenerKey); |
| + 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
|
| + } |
| + } |
| + |
| private void attachViewEvents(DesktopView viewer) { |
| viewer.onTouch().add(new Event.ParameterRunnable<TouchEventParameter>() { |
| @Override |
| @@ -324,7 +346,7 @@ public class TouchInputHandler { |
| switch (event.getActionMasked()) { |
| case MotionEvent.ACTION_DOWN: |
| - mViewer.setAnimationEnabled(false); |
| + setAnimationEnabled(false); |
| mSuppressCursorMovement = false; |
| mSuppressFling = false; |
| mSwipeCompleted = false; |
| @@ -519,7 +541,7 @@ public class TouchInputHandler { |
| if (mScrollFling) { |
| mScrollAnimationJob.startAnimation(velocityX, velocityY); |
| - mViewer.setAnimationEnabled(true); |
| + setAnimationEnabled(true); |
| mScrollFling = false; |
| return true; |
| } |
| @@ -532,7 +554,7 @@ public class TouchInputHandler { |
| // gesture-detector will still generate onFling() notifications based on movement of |
| // the fingers, which would result in unwanted cursor movement. |
| mCursorAnimationJob.startAnimation(velocityX, velocityY); |
| - mViewer.setAnimationEnabled(true); |
| + setAnimationEnabled(true); |
| return true; |
| } |