Skip to content

Commit

Permalink
Properly cancel looping before triggering another drawing loop
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrouget committed Nov 12, 2018
1 parent e94d1c4 commit 6b2d9bf
Showing 1 changed file with 11 additions and 3 deletions.
Expand Up @@ -133,7 +133,7 @@ public void flushGLBuffers() {

public void animationStateChanged(boolean animating) {
if (!mAnimating && animating) {
post(() -> Choreographer.getInstance().postFrameCallback(ServoView.this));
post(() -> startLooping());
}
mAnimating = animating;
}
Expand Down Expand Up @@ -182,6 +182,13 @@ private void initGestures(Context context) {
mScroller = new OverScroller(context);
}

private void startLooping() {
// In case we were already drawing.
Choreographer.getInstance().removeFrameCallback(this);

Choreographer.getInstance().postFrameCallback(this);
}

public void doFrame(long frameTimeNanos) {
if (!mRedrawing) {
mRedrawing = true;
Expand Down Expand Up @@ -264,9 +271,10 @@ public boolean onTouchEvent(final MotionEvent e) {
mCurY = (int) e.getY();
mLastY = mCurY;
mScroller.forceFinished(true);
mFlinging = false;
mServo.scrollStart(0, 0, mCurX, mCurY);
mScrolling = true;
Choreographer.getInstance().postFrameCallback(this);
startLooping();
return true;
case (MotionEvent.ACTION_MOVE):
mCurX = (int) e.getX();
Expand Down Expand Up @@ -305,7 +313,7 @@ public boolean onScaleBegin(ScaleGestureDetector detector) {
mZoomFactor = detector.getScaleFactor();
mZooming = true;
mServo.pinchZoomStart(mZoomFactor, 0, 0);
Choreographer.getInstance().postFrameCallback(this);
startLooping();
return true;
} else {
return false;
Expand Down

0 comments on commit 6b2d9bf

Please sign in to comment.