Revert "Revert "Use color extraction for arrow popup.""

This reverts commit 17fda29bf3.

Reason for revert: Fixing the memory leak

Leak was detected in caused launcher tapl tests to fail.
For instructions on how to debug leaks, see go/launcher-testing.
Using AS memory profiler, the color extractor class is holding
onto a reference to launcher that has already been destroyed.
The fix is to set the listener to null when view is closed.

Bug: 175329686
Test: run profiler in AS, open and close popups, and verify no leaks

Change-Id: I2d4a87f0481cbc88f3587dce91278e85ca113545
This commit is contained in:
Jonathan Miranda authored and Jon Miranda committed 2021-05-04 08:53:58 -07:00
1 parent 30ffc3f95c
commit 21930da9a2
8 files changed
+296 -85

No files matched your search

+50
View File
@@ -33,6 +33,7 @@ import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.ShortcutInfo;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.database.ContentObserver;
import android.graphics.Bitmap;
@@ -84,6 +85,7 @@ import com.android.launcher3.shortcuts.ShortcutKey;
import com.android.launcher3.shortcuts.ShortcutRequest;
import com.android.launcher3.util.IntArray;
import com.android.launcher3.util.PackageManagerHelper;
import com.android.launcher3.views.BaseDragLayer;
import com.android.launcher3.widget.PendingAddShortcutInfo;
import java.lang.reflect.Method;
@@ -104,6 +106,8 @@ public final class Utilities {
private static final Pattern sTrimPattern =
Pattern.compile("^[\\s|\\p{javaSpaceChar}]*(.*)[\\s|\\p{javaSpaceChar}]*$");
private static final float[] sTmpFloatArray = new float[4];
private static final int[] sLoc0 = new int[2];
private static final int[] sLoc1 = new int[2];
private static final Matrix sMatrix = new Matrix();
@@ -133,6 +137,15 @@ public final class Utilities {
Build.TYPE.toLowerCase(Locale.ROOT).contains("debug") ||
Build.TYPE.toLowerCase(Locale.ROOT).equals("eng");
/**
* Returns true if theme is dark.
*/
public static boolean isDarkTheme(Context context) {
Configuration configuration = context.getResources().getConfiguration();
int nightMode = configuration.uiMode & Configuration.UI_MODE_NIGHT_MASK;
return nightMode == Configuration.UI_MODE_NIGHT_YES;
}
public static boolean isDevelopersOptionsEnabled(Context context) {
return Settings.Global.getInt(context.getApplicationContext().getContentResolver(),
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 0;
@@ -218,6 +231,33 @@ public final class Utilities {
return scale;
}
/**
* Returns bounds for a child view of DragLayer, in drag layer coordinates.
*
* see {@link com.android.launcher3.dragndrop.DragLayer}.
*
* @param viewBounds Bounds of the view wanted in drag layer coordinates, relative to the view
* itself. eg. (0, 0, view.getWidth, view.getHeight)
* @param ignoreTransform If true, view transform is ignored
* @param outRect The out rect where we return the bounds of {@param view} in drag layer coords.
*/
public static void getBoundsForViewInDragLayer(BaseDragLayer dragLayer, View view,
Rect viewBounds, boolean ignoreTransform, RectF outRect) {
float[] points = sTmpFloatArray;
points[0] = viewBounds.left;
points[1] = viewBounds.top;
points[2] = viewBounds.right;
points[3] = viewBounds.bottom;
Utilities.getDescendantCoordRelativeToAncestor(view, dragLayer, points,
false, ignoreTransform);
outRect.set(
Math.min(points[0], points[2]),
Math.min(points[1], points[3]),
Math.max(points[0], points[2]),
Math.max(points[1], points[3]));
}
/**
* Inverse of {@link #getDescendantCoordRelativeToAncestor(View, View, float[], boolean)}.
*/
@@ -273,6 +313,16 @@ public final class Utilities {
return new int[] {sLoc1[0] - sLoc0[0], sLoc1[1] - sLoc0[1]};
}
/**
* Helper method to set rectOut with rectFSrc.
*/
public static void setRect(RectF rectFSrc, Rect rectOut) {
rectOut.left = (int) rectFSrc.left;
rectOut.top = (int) rectFSrc.top;
rectOut.right = (int) rectFSrc.right;
rectOut.bottom = (int) rectFSrc.bottom;
}
public static void scaleRectFAboutCenter(RectF r, float scale) {
if (scale != 1.0f) {
float cx = r.centerX();