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

Commit f5f23ba1 authored by Cyrus Boadway's avatar Cyrus Boadway Committed by Automerger Merge Worker
Browse files

Merge "Defer onColorsChanged updates during widget-to-home animation" into sc-dev am: 1edaed87

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/15147896

Change-Id: I93c3c42dc173182c7625dea719bbc540a544234a
parents 70b8341b 1edaed87
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -152,6 +152,7 @@ public class FloatingWidgetView extends FrameLayout implements AnimatorListener,
            RectF widgetBackgroundPosition, Size windowSize, float windowCornerRadius,
            RectF widgetBackgroundPosition, Size windowSize, float windowCornerRadius,
            boolean appTargetIsTranslucent, int fallbackBackgroundColor) {
            boolean appTargetIsTranslucent, int fallbackBackgroundColor) {
        mAppWidgetView = originalView;
        mAppWidgetView = originalView;
        // Deferrals must begin before GhostView is created. See b/190818220
        mAppWidgetView.beginDeferringUpdates();
        mAppWidgetView.beginDeferringUpdates();
        mBackgroundPosition = widgetBackgroundPosition;
        mBackgroundPosition = widgetBackgroundPosition;
        mAppTargetIsTranslucent = appTargetIsTranslucent;
        mAppTargetIsTranslucent = appTargetIsTranslucent;
@@ -240,6 +241,7 @@ public class FloatingWidgetView extends FrameLayout implements AnimatorListener,
        ((ViewGroup) dragLayer.getParent()).removeView(this);
        ((ViewGroup) dragLayer.getParent()).removeView(this);
        dragLayer.removeView(mListenerView);
        dragLayer.removeView(mListenerView);
        mBackgroundView.finish();
        mBackgroundView.finish();
        // Removing GhostView must occur before ending deferrals. See b/190818220
        mAppWidgetView.endDeferringUpdates();
        mAppWidgetView.endDeferringUpdates();
        recycle();
        recycle();
        mLauncher.getViewCache().recycleView(R.layout.floating_widget_view, this);
        mLauncher.getViewCache().recycleView(R.layout.floating_widget_view, this);
+36 −9
Original line number Original line Diff line number Diff line
@@ -52,6 +52,7 @@ import com.android.launcher3.views.BaseDragLayer.TouchCompleteListener;
import com.android.launcher3.widget.dragndrop.AppWidgetHostViewDragListener;
import com.android.launcher3.widget.dragndrop.AppWidgetHostViewDragListener;


import java.util.List;
import java.util.List;
import java.util.Optional;


/**
/**
 * {@inheritDoc}
 * {@inheritDoc}
@@ -97,7 +98,8 @@ public class LauncherAppWidgetHostView extends BaseLauncherAppWidgetHostView
    private final Object mUpdateLock = new Object();
    private final Object mUpdateLock = new Object();
    private final ViewGroupFocusHelper mDragLayerRelativeCoordinateHelper;
    private final ViewGroupFocusHelper mDragLayerRelativeCoordinateHelper;
    private long mDeferUpdatesUntilMillis = 0;
    private long mDeferUpdatesUntilMillis = 0;
    private RemoteViews mMostRecentRemoteViews;
    private RemoteViews mDeferredRemoteViews;
    private Optional<SparseIntArray> mDeferredColorChange = Optional.empty();


    public LauncherAppWidgetHostView(Context context) {
    public LauncherAppWidgetHostView(Context context) {
        super(context);
        super(context);
@@ -146,8 +148,11 @@ public class LauncherAppWidgetHostView extends BaseLauncherAppWidgetHostView
    @Override
    @Override
    public void updateAppWidget(RemoteViews remoteViews) {
    public void updateAppWidget(RemoteViews remoteViews) {
        synchronized (mUpdateLock) {
        synchronized (mUpdateLock) {
            mMostRecentRemoteViews = remoteViews;
            if (isDeferringUpdates()) {
            if (SystemClock.uptimeMillis() < mDeferUpdatesUntilMillis) return;
                mDeferredRemoteViews = remoteViews;
                return;
            }
            mDeferredRemoteViews = null;
        }
        }


        super.updateAppWidget(remoteViews);
        super.updateAppWidget(remoteViews);
@@ -183,11 +188,20 @@ public class LauncherAppWidgetHostView extends BaseLauncherAppWidgetHostView
        return false;
        return false;
    }
    }


    /**
     * Returns true if the application of {@link RemoteViews} through {@link #updateAppWidget} and
     * colors through {@link #onColorsChanged} are currently being deferred.
     * @see #beginDeferringUpdates()
     */
    private boolean isDeferringUpdates() {
        return SystemClock.uptimeMillis() < mDeferUpdatesUntilMillis;
    }

    /**
    /**
     * Begin deferring the application of any {@link RemoteViews} updates made through
     * Begin deferring the application of any {@link RemoteViews} updates made through
     * {@link #updateAppWidget(RemoteViews)} until {@link #endDeferringUpdates()} has been called or
     * {@link #updateAppWidget} and color changes through {@link #onColorsChanged} until
     * the next {@link #updateAppWidget(RemoteViews)} call after {@link #UPDATE_LOCK_TIMEOUT_MILLIS}
     * {@link #endDeferringUpdates()} has been called or the next {@link #updateAppWidget} or
     * have elapsed.
     * {@link #onColorsChanged} call after {@link #UPDATE_LOCK_TIMEOUT_MILLIS} have elapsed.
     */
     */
    public void beginDeferringUpdates() {
    public void beginDeferringUpdates() {
        synchronized (mUpdateLock) {
        synchronized (mUpdateLock) {
@@ -197,18 +211,23 @@ public class LauncherAppWidgetHostView extends BaseLauncherAppWidgetHostView


    /**
    /**
     * Stop deferring the application of {@link RemoteViews} updates made through
     * Stop deferring the application of {@link RemoteViews} updates made through
     * {@link #updateAppWidget(RemoteViews)} and apply the most recently received update.
     * {@link #updateAppWidget} and color changes made through {@link #onColorsChanged} and apply
     * any deferred updates.
     */
     */
    public void endDeferringUpdates() {
    public void endDeferringUpdates() {
        RemoteViews remoteViews;
        RemoteViews remoteViews;
        Optional<SparseIntArray> deferredColors;
        synchronized (mUpdateLock) {
        synchronized (mUpdateLock) {
            mDeferUpdatesUntilMillis = 0;
            mDeferUpdatesUntilMillis = 0;
            remoteViews = mMostRecentRemoteViews;
            remoteViews = mDeferredRemoteViews;
            mMostRecentRemoteViews = null;
            mDeferredRemoteViews = null;
            deferredColors = mDeferredColorChange;
            mDeferredColorChange = Optional.empty();
        }
        }
        if (remoteViews != null) {
        if (remoteViews != null) {
            updateAppWidget(remoteViews);
            updateAppWidget(remoteViews);
        }
        }
        deferredColors.ifPresent(colors -> onColorsChanged(null /* rectF */, colors));
    }
    }


    public boolean onInterceptTouchEvent(MotionEvent ev) {
    public boolean onInterceptTouchEvent(MotionEvent ev) {
@@ -344,6 +363,14 @@ public class LauncherAppWidgetHostView extends BaseLauncherAppWidgetHostView


    @Override
    @Override
    public void onColorsChanged(RectF rectF, SparseIntArray colors) {
    public void onColorsChanged(RectF rectF, SparseIntArray colors) {
        synchronized (mUpdateLock) {
            if (isDeferringUpdates()) {
                mDeferredColorChange = Optional.ofNullable(colors);
                return;
            }
            mDeferredColorChange = Optional.empty();
        }

        // setColorResources will reapply the view, which must happen in the UI thread.
        // setColorResources will reapply the view, which must happen in the UI thread.
        post(() -> setColorResources(colors));
        post(() -> setColorResources(colors));
    }
    }