Use relative bounds for app widget color extraction

Fix 2 bugs in this CL
1. Before this CL, getBoundsForViewInDragLayer returns absolute bounds
   for widgets. What we want is the bounds of a widget when it is
   visible in the drag layer. ViewGroupFocusHelper#viewToRect has
   taken PagedView into account. This makes it a prefect candidate to
   calculate relative bounds of a widget.
2. requestLayout at the end of endDrag is problematic due to the drop
   animation. If the drop animation is still in progress when onLayout
   is called, the bounds of the widget isn't final. Since the color of
   app widget right before is already the final color. We don't really
   need to update the color extraction.

Test: Set the wallpaper and clock widget according to the bug. Then,
      reboot the device. The clock widget color shown right after
      reboot is the expected color. Long pressing the widget doesn't
      cause a color change.
Fix: 191114337
Change-Id: I466c8102dba0e5b207b3768e0935472cbd523235
This commit is contained in:
Steven Ng 2021-06-17 23:19:31 +01:00
parent 10d4edade1
commit 058308098b
1 changed files with 4 additions and 12 deletions

View File

@ -16,9 +16,6 @@
package com.android.launcher3.widget;
import static com.android.launcher3.Utilities.getBoundsForViewInDragLayer;
import static com.android.launcher3.Utilities.setRect;
import android.appwidget.AppWidgetProviderInfo;
import android.content.Context;
import android.content.res.Configuration;
@ -51,6 +48,7 @@ import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.Workspace;
import com.android.launcher3.dragndrop.DragLayer;
import com.android.launcher3.keyboard.ViewGroupFocusHelper;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.model.data.LauncherAppWidgetInfo;
import com.android.launcher3.util.Executors;
@ -102,7 +100,6 @@ public class LauncherAppWidgetHostView extends NavigableAppWidgetHostView
private final Rect mCurrentWidgetSize = new Rect();
private final Rect mWidgetSizeAtDrag = new Rect();
private final float[] mTmpFloatArray = new float[4];
private final RectF mTempRectF = new RectF();
private final Rect mEnforcedRectangle = new Rect();
private final float mEnforcedCornerRadius;
@ -117,6 +114,7 @@ public class LauncherAppWidgetHostView extends NavigableAppWidgetHostView
}
};
private final Object mUpdateLock = new Object();
private final ViewGroupFocusHelper mDragLayerRelativeCoordinateHelper;
private long mDeferUpdatesUntilMillis = 0;
private RemoteViews mMostRecentRemoteViews;
@ -137,6 +135,7 @@ public class LauncherAppWidgetHostView extends NavigableAppWidgetHostView
mColorExtractor.setListener(this);
mEnforcedCornerRadius = RoundedCornerEnforcement.computeEnforcedRadius(getContext());
mDragLayerRelativeCoordinateHelper = new ViewGroupFocusHelper(mLauncher.getDragLayer());
}
@Override
@ -325,15 +324,9 @@ public class LauncherAppWidgetHostView extends NavigableAppWidgetHostView
mIsScrollable = checkScrollableRecursively(this);
if (!mIsInDragMode && getTag() instanceof LauncherAppWidgetInfo) {
mCurrentWidgetSize.left = left;
mCurrentWidgetSize.right = right;
mCurrentWidgetSize.top = top;
mCurrentWidgetSize.bottom = bottom;
LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) getTag();
getBoundsForViewInDragLayer(mLauncher.getDragLayer(), (View) getParent(),
mCurrentWidgetSize, true, mTmpFloatArray, mTempRectF);
setRect(mTempRectF, mCurrentWidgetSize);
mDragLayerRelativeCoordinateHelper.viewToRect(this, mCurrentWidgetSize);
updateColorExtraction(mCurrentWidgetSize,
mWorkspace.getPageIndexForScreenId(info.screenId));
}
@ -358,7 +351,6 @@ public class LauncherAppWidgetHostView extends NavigableAppWidgetHostView
mIsInDragMode = false;
mDragListener = null;
mWidgetSizeAtDrag.setEmpty();
requestLayout();
}
/**