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

Commit a318b75c authored by Tracy Zhou's avatar Tracy Zhou Committed by Android (Google) Code Review
Browse files

Merge "Add live tile overlay only once across multiple LauncherSwipeHandler"...

Merge "Add live tile overlay only once across multiple LauncherSwipeHandler" into ub-launcher3-master
parents 0493a1e2 054a86bf
Loading
Loading
Loading
Loading
+20 −22
Original line number Diff line number Diff line
@@ -177,8 +177,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;

@@ -548,7 +546,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());
            }
        }
@@ -838,7 +837,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) {
@@ -1025,6 +1024,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();
@@ -1112,13 +1112,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() {
@@ -1129,6 +1123,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();
    }
@@ -1235,20 +1238,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);
        }
    }