Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6586062f authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Ensuring that we finish the last transition before starting a new one.

> Finishing the active animation instead of cancelling it. This ansures
  that the animation callbacks are called properly and RecentsAnimaiton is finished
> If a transition is already running, using main thread for next transtion so that
  this new transition is not started before the last transition is finished.
> If the transition is expected to finish at Launcher, directly use the Launcher
  consumer. RunningTaskInfo is not updated until the screen shot is complete.

Bug: 74481901
Change-Id: I2b1128f1f2eff0e6bd94b3adb9cef6ae0578bd0c
parent dcdeffdf
Loading
Loading
Loading
Loading
+6 −0
Original line number Original line Diff line number Diff line
@@ -77,6 +77,12 @@ public class AnimatedFloat {
        }
        }
    }
    }


    public void finishAnimation() {
        if (mValueAnimator != null && mValueAnimator.isRunning()) {
            mValueAnimator.end();
        }
    }

    public ObjectAnimator getCurrentAnimation() {
    public ObjectAnimator getCurrentAnimation() {
        return mValueAnimator;
        return mValueAnimator;
    }
    }
+1 −0
Original line number Original line Diff line number Diff line
@@ -23,6 +23,7 @@ import com.android.quickstep.TouchConsumer.InteractionType;
public abstract class BaseSwipeInteractionHandler extends InternalStateHandler {
public abstract class BaseSwipeInteractionHandler extends InternalStateHandler {


    protected Runnable mGestureEndCallback;
    protected Runnable mGestureEndCallback;
    protected boolean mIsGoingToHome;


    public void setGestureEndCallback(Runnable gestureEndCallback) {
    public void setGestureEndCallback(Runnable gestureEndCallback) {
        mGestureEndCallback = gestureEndCallback;
        mGestureEndCallback = gestureEndCallback;
+99 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.quickstep;

import android.annotation.TargetApi;
import android.os.Build;
import android.view.Choreographer;
import android.view.MotionEvent;
import android.view.VelocityTracker;

/**
 * A TouchConsumer which defers all events on the UIThread until the consumer is created.
 */
@TargetApi(Build.VERSION_CODES.P)
public class DeferredTouchConsumer implements TouchConsumer {

    private final VelocityTracker mVelocityTracker;
    private final DeferredTouchProvider mTouchProvider;

    private MotionEventQueue mMyQueue;
    private TouchConsumer mTarget;

    public DeferredTouchConsumer(DeferredTouchProvider touchProvider) {
        mVelocityTracker = VelocityTracker.obtain();
        mTouchProvider = touchProvider;
    }

    @Override
    public void accept(MotionEvent event) {
        mTarget.accept(event);
    }

    @Override
    public void reset() {
        mTarget.reset();
    }

    @Override
    public void updateTouchTracking(int interactionType) {
        mTarget.updateTouchTracking(interactionType);
    }

    @Override
    public void onQuickScrubEnd() {
        mTarget.onQuickScrubEnd();
    }

    @Override
    public void onQuickScrubProgress(float progress) {
        mTarget.onQuickScrubProgress(progress);
    }

    @Override
    public void preProcessMotionEvent(MotionEvent ev) {
        mVelocityTracker.addMovement(ev);
    }

    @Override
    public Choreographer getIntrimChoreographer(MotionEventQueue queue) {
        mMyQueue = queue;
        return null;
    }

    @Override
    public void deferInit() {
        mTarget = mTouchProvider.createTouchConsumer(mVelocityTracker);
        mTarget.getIntrimChoreographer(mMyQueue);
    }

    @Override
    public boolean forceToLauncherConsumer() {
        return mTarget.forceToLauncherConsumer();
    }

    @Override
    public boolean deferNextEventToMainThread() {
        // If our target is still null, defer the next target as well
        TouchConsumer target = mTarget;
        return target == null ? true : target.deferNextEventToMainThread();
    }

    public interface DeferredTouchProvider {

        TouchConsumer createTouchConsumer(VelocityTracker tracker);
    }
}
+15 −2
Original line number Original line Diff line number Diff line
@@ -53,6 +53,8 @@ public class MotionEventQueue {
            ACTION_VIRTUAL | (4 << ACTION_POINTER_INDEX_SHIFT);
            ACTION_VIRTUAL | (4 << ACTION_POINTER_INDEX_SHIFT);
    private static final int ACTION_RESET =
    private static final int ACTION_RESET =
            ACTION_VIRTUAL | (5 << ACTION_POINTER_INDEX_SHIFT);
            ACTION_VIRTUAL | (5 << ACTION_POINTER_INDEX_SHIFT);
    private static final int ACTION_DEFER_INIT =
            ACTION_VIRTUAL | (6 << ACTION_POINTER_INDEX_SHIFT);


    private final EventArray mEmptyArray = new EventArray();
    private final EventArray mEmptyArray = new EventArray();
    private final Object mExecutionLock = new Object();
    private final Object mExecutionLock = new Object();
@@ -76,10 +78,10 @@ public class MotionEventQueue {
    public MotionEventQueue(Choreographer choreographer, TouchConsumer consumer) {
    public MotionEventQueue(Choreographer choreographer, TouchConsumer consumer) {
        mMainChoreographer = choreographer;
        mMainChoreographer = choreographer;
        mConsumer = consumer;
        mConsumer = consumer;

        mCurrentChoreographer = mMainChoreographer;
        mCurrentChoreographer = mMainChoreographer;
        mCurrentRunnable = mMainFrameCallback;
        mCurrentRunnable = mMainFrameCallback;
        setInterimChoreographerLocked(consumer.getIntrimChoreographer(this));

        setInterimChoreographer(consumer.getIntrimChoreographer(this));
    }
    }


    public void setInterimChoreographer(Choreographer choreographer) {
    public void setInterimChoreographer(Choreographer choreographer) {
@@ -156,6 +158,9 @@ public class MotionEventQueue {
                        case ACTION_RESET:
                        case ACTION_RESET:
                            mConsumer.reset();
                            mConsumer.reset();
                            break;
                            break;
                        case ACTION_DEFER_INIT:
                            mConsumer.deferInit();
                            break;
                        default:
                        default:
                            Log.e(TAG, "Invalid virtual event: " + event.getAction());
                            Log.e(TAG, "Invalid virtual event: " + event.getAction());
                    }
                    }
@@ -204,6 +209,14 @@ public class MotionEventQueue {
        queueVirtualAction(ACTION_RESET, 0);
        queueVirtualAction(ACTION_RESET, 0);
    }
    }


    public void deferInit() {
        queueVirtualAction(ACTION_DEFER_INIT, 0);
    }

    public TouchConsumer getConsumer() {
        return mConsumer;
    }

    private static class EventArray extends ArrayList<MotionEvent> {
    private static class EventArray extends ArrayList<MotionEvent> {


        public int lastEventAction = ACTION_CANCEL;
        public int lastEventAction = ACTION_CANCEL;
+3 −2
Original line number Original line Diff line number Diff line
@@ -319,13 +319,14 @@ public class NavBarSwipeInteractionHandler extends BaseSwipeInteractionHandler i


    /** Animates to the given progress, where 0 is the current app and 1 is overview. */
    /** Animates to the given progress, where 0 is the current app and 1 is overview. */
    private void animateToProgress(float progress, long duration) {
    private void animateToProgress(float progress, long duration) {
        mIsGoingToHome = Float.compare(progress, 1) == 0;
        ObjectAnimator anim = mCurrentShift.animateToValue(progress).setDuration(duration);
        ObjectAnimator anim = mCurrentShift.animateToValue(progress).setDuration(duration);
        anim.setInterpolator(Interpolators.SCROLL);
        anim.setInterpolator(Interpolators.SCROLL);
        anim.addListener(new AnimationSuccessListener() {
        anim.addListener(new AnimationSuccessListener() {
            @Override
            @Override
            public void onAnimationSuccess(Animator animator) {
            public void onAnimationSuccess(Animator animator) {
                mStateCallback.setState((Float.compare(mCurrentShift.value, 0) == 0)
                mStateCallback.setState(mIsGoingToHome
                        ? STATE_SCALED_SNAPSHOT_APP : STATE_SCALED_SNAPSHOT_RECENTS);
                        ? STATE_SCALED_SNAPSHOT_RECENTS : STATE_SCALED_SNAPSHOT_APP);
            }
            }
        });
        });
        anim.start();
        anim.start();
Loading