Commit 706c49eb authored by yuweih's avatar yuweih Committed by Commit bot

[Remoting Android] Move setAnimationEnabled to TouchInputHandler

Since GlDisplay already triggers an onCanvasRendered() event, TouchInputHandler
just simply needs to listen to that event decide what to do inside its scope.
This CL moves the setAnimationEnabled logic into TouchInputHandler since
DesktopView doesn't need to do anything in this process.

BUG=641123

Review-Url: https://codereview.chromium.org/2281983004
Cr-Commit-Position: refs/heads/master@{#415558}
parent 3166b5e2
......@@ -43,6 +43,11 @@ public abstract class DesktopView extends SurfaceView {
protected final Event.Raisable<SizeChangedEventParameter> mOnHostSizeChanged =
new Event.Raisable<>();
/**
* Subclass should trigger this event when a frame is rendered.
*/
protected final Event.Raisable<Void> mOnCanvasRendered = new Event.Raisable<>();
private final int mTinyFeedbackPixelRadius;
private final int mSmallFeedbackPixelRadius;
private final int mLargeFeedbackPixelRadius;
......@@ -101,6 +106,11 @@ public abstract class DesktopView extends SurfaceView {
return mOnHostSizeChanged;
}
/** An {@link Event} which is triggered when a frame is rendered. */
public final Event<Void> onCanvasRendered() {
return mOnCanvasRendered;
}
// View overrides.
/** Called when a software keyboard is requested, and specifies its options. */
@Override
......@@ -172,10 +182,4 @@ public abstract class DesktopView extends SurfaceView {
* the TouchInputHandler, which requires repainting.
*/
public abstract void cursorVisibilityChanged(boolean visible);
/**
* Starts or stops an animation. Whilst the animation is running, the DesktopView will
* periodically call TouchInputHandler.processAnimation() and repaint itself.
*/
public abstract void setAnimationEnabled(boolean enabled);
}
......@@ -21,8 +21,6 @@ public class GlDesktopView extends DesktopView implements SurfaceHolder.Callback
private Object mOnHostSizeChangedListenerKey;
private Object mOnCanvasRenderedListenerKey;
private Event.ParameterRunnable<Void> mProcessAnimationRunnable;
private float mScaleFactor;
public GlDesktopView(GlDisplay display, Desktop desktop, Client client) {
......@@ -30,13 +28,6 @@ public class GlDesktopView extends DesktopView implements SurfaceHolder.Callback
Preconditions.notNull(display);
mDisplay = display;
mProcessAnimationRunnable = new Event.ParameterRunnable<Void>() {
@Override
public void run(Void p) {
mInputHandler.processAnimation();
}
};
mScaleFactor = 0;
getHolder().addCallback(this);
......@@ -69,18 +60,6 @@ public class GlDesktopView extends DesktopView implements SurfaceHolder.Callback
mDisplay.cursorVisibilityChanged(visible);
}
@Override
public void setAnimationEnabled(boolean enabled) {
if (enabled && mOnCanvasRenderedListenerKey == null) {
mOnCanvasRenderedListenerKey = mDisplay.onCanvasRendered()
.add(mProcessAnimationRunnable);
mInputHandler.processAnimation();
} else if (!enabled && mOnCanvasRenderedListenerKey != null) {
mDisplay.onCanvasRendered().remove(mOnCanvasRenderedListenerKey);
mOnCanvasRenderedListenerKey = null;
}
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
mOnHostSizeChangedListenerKey = mDisplay
......@@ -91,6 +70,14 @@ public class GlDesktopView extends DesktopView implements SurfaceHolder.Callback
}
});
mOnCanvasRenderedListenerKey = mDisplay
.onCanvasRendered().add(new Event.ParameterRunnable<Void>() {
@Override
public void run(Void p) {
mOnCanvasRendered.raise(p);
}
});
mDisplay.surfaceCreated(holder.getSurface());
}
......
......@@ -93,6 +93,8 @@ public class TouchInputHandler {
*/
private boolean mIsDragging = false;
private Event.ParameterCallback<Boolean, Void> mProcessAnimationCallback;
/**
* This class implements fling animation for cursor
*/
......@@ -210,16 +212,37 @@ public class TouchInputHandler {
mCursorAnimationJob = new CursorAnimationJob(context);
mScrollAnimationJob = new ScrollAnimationJob(context);
mProcessAnimationCallback = new Event.ParameterCallback<Boolean, Void>() {
@Override
public Boolean run(Void p) {
return processAnimation();
}
};
attachViewEvents(viewer);
}
public void processAnimation() {
boolean active = mCursorAnimationJob.processAnimation();
active |= mScrollAnimationJob.processAnimation();
/**
* Steps forward the animation.
* @return true if the animation is not finished yet.
*/
private boolean processAnimation() {
return mCursorAnimationJob.processAnimation() || mScrollAnimationJob.processAnimation();
}
if (!active) {
mViewer.setAnimationEnabled(false);
}
/**
* Start stepping animation when onCanvasRendered is triggered.
*/
private void startAnimation() {
mViewer.onCanvasRendered().addSelfRemovable(mProcessAnimationCallback);
}
/**
* Abort all animations.
*/
private void abortAnimation() {
mCursorAnimationJob.abortAnimation();
mScrollAnimationJob.abortAnimation();
}
public void init(Desktop desktop, final InputEventSender injector) {
......@@ -324,7 +347,7 @@ public class TouchInputHandler {
switch (event.getActionMasked()) {
case MotionEvent.ACTION_DOWN:
mViewer.setAnimationEnabled(false);
abortAnimation();
mSuppressCursorMovement = false;
mSuppressFling = false;
mSwipeCompleted = false;
......@@ -373,8 +396,7 @@ public class TouchInputHandler {
private void setInputStrategy(InputStrategyInterface inputStrategy) {
// Since the rules for flinging differ between input modes, we want to stop running the
// current fling animation when the mode changes to prevent a wonky experience.
mCursorAnimationJob.abortAnimation();
mScrollAnimationJob.abortAnimation();
abortAnimation();
mInputStrategy = inputStrategy;
}
......@@ -519,7 +541,7 @@ public class TouchInputHandler {
if (mScrollFling) {
mScrollAnimationJob.startAnimation(velocityX, velocityY);
mViewer.setAnimationEnabled(true);
startAnimation();
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);
startAnimation();
return true;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment