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

Commit 054a86bf authored by Tracy Zhou's avatar Tracy Zhou
Browse files

Add live tile overlay only once across multiple LauncherSwipeHandler

- Use singleton on LiveTileOverlay to make sure we only have one LiveTileOverlay instance
- Clean up upon recents animation cancelation

Fixes: 140337263
Test: diligently swipe up and down
Change-Id: I8e0db3c5240135a6deb4f4d91493b8eede7c5ff1
parent 6df83b75
Loading
Loading
Loading
Loading
+20 −22
Original line number Diff line number Diff line
@@ -176,8 +176,6 @@ public class LauncherSwipeHandler<T extends BaseDraggingActivity>
    private boolean mHasLauncherTransitionControllerStarted;

    private AnimationFactory mAnimationFactory = (t) -> { };
    private LiveTileOverlay mLiveTileOverlay = new LiveTileOverlay();
    private boolean mLiveTileOverlayAttached = false;

    private boolean mWasLauncherAlreadyVisible;

@@ -547,7 +545,8 @@ public class LauncherSwipeHandler<T extends BaseDraggingActivity>

        if (ENABLE_QUICKSTEP_LIVE_TILE.get()) {
            if (mRecentsAnimationTargets != null) {
                mLiveTileOverlay.update(mAppWindowAnimationHelper.getCurrentRectWithInsets(),
                LiveTileOverlay.getInstance().update(
                        mAppWindowAnimationHelper.getCurrentRectWithInsets(),
                        mAppWindowAnimationHelper.getCurrentCornerRadius());
            }
        }
@@ -837,7 +836,7 @@ public class LauncherSwipeHandler<T extends BaseDraggingActivity>
            setShelfState(ShelfAnimState.CANCEL, LINEAR, 0);
            duration = Math.max(MIN_OVERSHOOT_DURATION, duration);
        } else if (endTarget == RECENTS) {
            mLiveTileOverlay.startIconAnimation();
            LiveTileOverlay.getInstance().startIconAnimation();
            if (mRecentsView != null) {
                int nearestPage = mRecentsView.getPageNearestToCenterOfScreen();
                if (mRecentsView.getNextPage() != nearestPage) {
@@ -1024,6 +1023,7 @@ public class LauncherSwipeHandler<T extends BaseDraggingActivity>
            // In the off chance that the gesture ends before Launcher is started, we should clear
            // the callback here so that it doesn't update with the wrong state
            mActivity.clearRunOnceOnStartCallback();
            resetLauncherListenersAndOverlays();
        }
        if (mGestureState.getEndTarget() != null && !mGestureState.isRunningAnimationToLauncher()) {
            cancelCurrentAnimation();
@@ -1111,13 +1111,7 @@ public class LauncherSwipeHandler<T extends BaseDraggingActivity>
        endLauncherTransitionController();

        mRecentsView.onGestureAnimationEnd();

        // Reset the callback for deferred activity launches
        if (!ENABLE_QUICKSTEP_LIVE_TILE.get()) {
            mActivityInterface.setOnDeferredActivityLaunchCallback(null);
        }
        mActivity.getRootView().setOnApplyWindowInsetsListener(null);
        removeLiveTileOverlay();
        resetLauncherListenersAndOverlays();
    }

    private void endLauncherTransitionController() {
@@ -1128,6 +1122,15 @@ public class LauncherSwipeHandler<T extends BaseDraggingActivity>
        }
    }

    private void resetLauncherListenersAndOverlays() {
        // Reset the callback for deferred activity launches
        if (!ENABLE_QUICKSTEP_LIVE_TILE.get()) {
            mActivityInterface.setOnDeferredActivityLaunchCallback(null);
        }
        mActivity.getRootView().setOnApplyWindowInsetsListener(null);
        removeLiveTileOverlay();
    }

    private void notifyTransitionCancelled() {
        mAnimationFactory.onTransitionCancelled();
    }
@@ -1232,20 +1235,15 @@ public class LauncherSwipeHandler<T extends BaseDraggingActivity>
        updateFinalShift();
    }

    private synchronized void addLiveTileOverlay() {
        if (!mLiveTileOverlayAttached) {
            mActivity.getRootView().getOverlay().add(mLiveTileOverlay);
            mRecentsView.setLiveTileOverlay(mLiveTileOverlay);
            mLiveTileOverlayAttached = true;
    private void addLiveTileOverlay() {
        if (LiveTileOverlay.getInstance().attach(mActivity.getRootView().getOverlay())) {
            mRecentsView.setLiveTileOverlayAttached(true);
        }
    }

    private synchronized void removeLiveTileOverlay() {
        if (mLiveTileOverlayAttached) {
            mActivity.getRootView().getOverlay().remove(mLiveTileOverlay);
            mRecentsView.setLiveTileOverlay(null);
            mLiveTileOverlayAttached = false;
        }
    private void removeLiveTileOverlay() {
        LiveTileOverlay.getInstance().detach(mActivity.getRootView().getOverlay());
        mRecentsView.setLiveTileOverlayAttached(false);
    }

    public static float getHiddenTargetAlpha(RemoteAnimationTargetCompat app, float expectedAlpha) {
+29 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@ import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.util.FloatProperty;
import android.view.ViewOverlay;

import com.android.launcher3.anim.Interpolators;

@@ -36,6 +37,15 @@ public class LiveTileOverlay extends Drawable {
                }
            };

    private static LiveTileOverlay sInstance;

    public static LiveTileOverlay getInstance() {
        if (sInstance == null) {
            sInstance = new LiveTileOverlay();
        }
        return sInstance;
    }

    private final Paint mPaint = new Paint();

    private Rect mBoundsRect = new Rect();
@@ -46,8 +56,9 @@ public class LiveTileOverlay extends Drawable {

    private boolean mDrawEnabled = true;
    private float mIconAnimationProgress = 0f;
    private boolean mIsAttached;

    public LiveTileOverlay() {
    private LiveTileOverlay() {
        mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
    }

@@ -124,6 +135,23 @@ public class LiveTileOverlay extends Drawable {
        return PixelFormat.TRANSLUCENT;
    }

    public boolean attach(ViewOverlay overlay) {
        if (overlay != null && !mIsAttached) {
            overlay.add(this);
            mIsAttached = true;
            return true;
        }

        return false;
    }

    public void detach(ViewOverlay overlay) {
        if (overlay != null) {
            overlay.remove(this);
            mIsAttached = false;
        }
    }

    private void setIconAnimationProgress(float progress) {
        mIconAnimationProgress = progress;
        invalidateSelf();
+7 −7
Original line number Diff line number Diff line
@@ -308,7 +308,7 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
    private final int mEmptyMessagePadding;
    private boolean mShowEmptyMessage;
    private Layout mEmptyTextLayout;
    private LiveTileOverlay mLiveTileOverlay;
    private boolean mLiveTileOverlayAttached;

    // Keeps track of the index where the first TaskView should be
    private int mTaskViewStartIndex = 0;
@@ -876,8 +876,8 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
     */
    public void onSwipeUpAnimationSuccess() {
        if (getRunningTaskView() != null) {
            float startProgress = ENABLE_QUICKSTEP_LIVE_TILE.get() && mLiveTileOverlay != null
                    ? mLiveTileOverlay.cancelIconAnimation()
            float startProgress = ENABLE_QUICKSTEP_LIVE_TILE.get() && mLiveTileOverlayAttached
                    ? LiveTileOverlay.getInstance().cancelIconAnimation()
                    : 0f;
            animateUpRunningTaskIconScale(startProgress);
        }
@@ -1724,13 +1724,13 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
        mAppWindowAnimationHelper = appWindowAnimationHelper;
    }

    public void setLiveTileOverlay(LiveTileOverlay liveTileOverlay) {
        mLiveTileOverlay = liveTileOverlay;
    public void setLiveTileOverlayAttached(boolean liveTileOverlayAttached) {
        mLiveTileOverlayAttached = liveTileOverlayAttached;
    }

    public void updateLiveTileIcon(Drawable icon) {
        if (mLiveTileOverlay != null) {
            mLiveTileOverlay.setIcon(icon);
        if (mLiveTileOverlayAttached) {
            LiveTileOverlay.getInstance().setIcon(icon);
        }
    }