Revert "Use color extraction for arrow popup."

This reverts commit 242c805f82.

Reason for revert: Introduces a leak. I haven't seen a bug for it yet, but this CL is the only in the culprit list; the leak can block multiple teams presubmits, and the leak is via ArrowPopup. Enough evidence.
https://fusion2.corp.google.com/invocations/4b50db71-d598-4e52-9076-e91d42b65014/targets

Change-Id: I1700a9eea8705983598aee43c0a63e67c1d9cf71
Bug: 187075409
This commit is contained in:
Vadim Tryshev
2021-05-03 18:27:41 +00:00
parent 242c805f82
commit 17fda29bf3
9 changed files with 86 additions and 299 deletions
@@ -16,10 +16,6 @@
package com.android.launcher3.widget;
import static com.android.launcher3.Utilities.getBoundsForViewInDragLayer;
import static com.android.launcher3.Utilities.setRect;
import static com.android.launcher3.util.ColorExtractionUtils.getColorExtractionRect;
import android.appwidget.AppWidgetProviderInfo;
import android.content.Context;
import android.content.res.Configuration;
@@ -29,6 +25,7 @@ import android.graphics.Rect;
import android.graphics.RectF;
import android.os.Handler;
import android.os.SystemClock;
import android.util.Log;
import android.util.SparseBooleanArray;
import android.util.SparseIntArray;
import android.view.LayoutInflater;
@@ -98,11 +95,11 @@ public class LauncherAppWidgetHostView extends NavigableAppWidgetHostView
private RectF mLastLocationRegistered = null;
@Nullable private AppWidgetHostViewDragListener mDragListener;
// Used to store the widget sizes in drag layer coordinates.
// Used to store the widget size during onLayout.
private final Rect mCurrentWidgetSize = new Rect();
private final Rect mWidgetSizeAtDrag = new Rect();
private final RectF mTempRectF = new RectF();
private final boolean mIsRtl;
private final Rect mEnforcedRectangle = new Rect();
private final float mEnforcedCornerRadius;
private final ViewOutlineProvider mCornerRadiusEnforcementOutline = new ViewOutlineProvider() {
@@ -132,6 +129,7 @@ public class LauncherAppWidgetHostView extends NavigableAppWidgetHostView
if (Utilities.ATLEAST_Q && Themes.getAttrBoolean(mLauncher, R.attr.isWorkspaceDarkText)) {
setOnLightBackground(true);
}
mIsRtl = Utilities.isRtl(context.getResources());
mColorExtractor = LocalColorExtractor.newInstance(getContext());
mColorExtractor.setListener(this);
@@ -321,12 +319,13 @@ public class LauncherAppWidgetHostView extends NavigableAppWidgetHostView
mIsScrollable = checkScrollableRecursively(this);
if (!mIsInDragMode && getTag() instanceof LauncherAppWidgetInfo) {
mCurrentWidgetSize.left = left;
mCurrentWidgetSize.top = top;
mCurrentWidgetSize.right = right;
mCurrentWidgetSize.bottom = bottom;
LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) getTag();
getBoundsForViewInDragLayer(mLauncher.getDragLayer(), this, mCurrentWidgetSize, true,
mTempRectF);
setRect(mTempRectF, mCurrentWidgetSize);
updateColorExtraction(mCurrentWidgetSize,
mWorkspace.getPageIndexForScreenId(info.screenId));
int pageId = mWorkspace.getPageIndexForScreenId(info.screenId);
updateColorExtraction(mCurrentWidgetSize, pageId);
}
enforceRoundedCorners();
@@ -339,8 +338,8 @@ public class LauncherAppWidgetHostView extends NavigableAppWidgetHostView
}
/** Handles a drag event occurred on a workspace page, {@code pageId}. */
public void handleDrag(Rect rectInDragLayer, int pageId) {
mWidgetSizeAtDrag.set(rectInDragLayer);
public void handleDrag(Rect rect, int pageId) {
mWidgetSizeAtDrag.set(rect);
updateColorExtraction(mWidgetSizeAtDrag, pageId);
}
@@ -352,14 +351,53 @@ public class LauncherAppWidgetHostView extends NavigableAppWidgetHostView
requestLayout();
}
/**
* @param rectInDragLayer Rect of widget in drag layer coordinates.
* @param pageId The workspace page the widget is on.
*/
private void updateColorExtraction(Rect rectInDragLayer, int pageId) {
getColorExtractionRect(mLauncher, pageId, rectInDragLayer, mTempRectF);
if (mTempRectF.isEmpty()) {
private void updateColorExtraction(Rect widgetLocation, int pageId) {
// If the widget hasn't been measured and laid out, we cannot do this.
if (widgetLocation.isEmpty()) {
return;
}
int screenWidth = mLauncher.getDeviceProfile().widthPx;
int screenHeight = mLauncher.getDeviceProfile().heightPx;
int numScreens = mWorkspace.getNumPagesForWallpaperParallax();
pageId = mIsRtl ? numScreens - pageId - 1 : pageId;
float relativeScreenWidth = 1f / numScreens;
float absoluteTop = widgetLocation.top;
float absoluteBottom = widgetLocation.bottom;
View v = this;
while (v.getParent() instanceof View) {
v = (View) v.getParent();
if (v.getId() != R.id.launcher) {
break;
}
absoluteBottom += v.getTop();
absoluteTop += v.getTop();
}
float xOffset = 0;
View parentView = (View) getParent();
// The layout depends on the orientation.
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
int parentViewWidth = parentView == null ? 0 : parentView.getWidth();
xOffset = screenWidth - mWorkspace.getPaddingRight() - parentViewWidth;
} else {
int parentViewPaddingLeft = parentView == null ? 0 : parentView.getPaddingLeft();
xOffset = mWorkspace.getPaddingLeft() + parentViewPaddingLeft;
}
// This is the position of the widget relative to the wallpaper, as expected by the
// local color extraction of the WallpaperManager.
// The coordinate system is such that, on the horizontal axis, each screen has a
// distinct range on the [0,1] segment. So if there are 3 screens, they will have the
// ranges [0, 1/3], [1/3, 2/3] and [2/3, 1]. The position on the subrange should be
// the position of the widget relative to the screen. For the vertical axis, this is
// simply the location of the widget relative to the screen.
mTempRectF.left = ((widgetLocation.left + xOffset) / screenWidth + pageId)
* relativeScreenWidth;
mTempRectF.right = ((widgetLocation.right + xOffset) / screenWidth + pageId)
* relativeScreenWidth;
mTempRectF.top = absoluteTop / screenHeight;
mTempRectF.bottom = absoluteBottom / screenHeight;
if (mTempRectF.left < 0 || mTempRectF.right > 1 || mTempRectF.top < 0
|| mTempRectF.bottom > 1) {
Log.e(LOG_TAG, " Error, invalid relative position");
return;
}
if (!mTempRectF.equals(mLastLocationRegistered)) {