Merge "VisD update for the PipAppIconOverlay" into tm-qpr-dev
This commit is contained in:
@@ -36,6 +36,7 @@ import android.window.TaskSnapshot;
|
|||||||
|
|
||||||
import com.android.internal.annotations.VisibleForTesting;
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
import com.android.internal.graphics.SfVsyncFrameCallbackProvider;
|
import com.android.internal.graphics.SfVsyncFrameCallbackProvider;
|
||||||
|
import com.android.launcher3.icons.IconProvider;
|
||||||
import com.android.wm.shell.animation.Interpolators;
|
import com.android.wm.shell.animation.Interpolators;
|
||||||
import com.android.wm.shell.transition.Transitions;
|
import com.android.wm.shell.transition.Transitions;
|
||||||
|
|
||||||
@@ -372,7 +373,8 @@ public class PipAnimationController {
|
|||||||
|
|
||||||
void setAppIconContentOverlay(Context context, Rect bounds, ActivityInfo activityInfo) {
|
void setAppIconContentOverlay(Context context, Rect bounds, ActivityInfo activityInfo) {
|
||||||
reattachContentOverlay(
|
reattachContentOverlay(
|
||||||
new PipContentOverlay.PipAppIconOverlay(context, bounds, activityInfo));
|
new PipContentOverlay.PipAppIconOverlay(context, bounds,
|
||||||
|
() -> new IconProvider(context).getIcon(activityInfo)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void reattachContentOverlay(PipContentOverlay overlay) {
|
private void reattachContentOverlay(PipContentOverlay overlay) {
|
||||||
|
|||||||
@@ -20,9 +20,6 @@ import static android.util.TypedValue.COMPLEX_UNIT_DIP;
|
|||||||
|
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.ActivityInfo;
|
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.content.res.Resources;
|
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
@@ -35,6 +32,8 @@ import android.view.SurfaceControl;
|
|||||||
import android.view.SurfaceSession;
|
import android.view.SurfaceSession;
|
||||||
import android.window.TaskSnapshot;
|
import android.window.TaskSnapshot;
|
||||||
|
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the content overlay used during the entering PiP animation.
|
* Represents the content overlay used during the entering PiP animation.
|
||||||
*/
|
*/
|
||||||
@@ -177,7 +176,9 @@ public abstract class PipContentOverlay {
|
|||||||
/** A {@link PipContentOverlay} shows app icon on solid color background. */
|
/** A {@link PipContentOverlay} shows app icon on solid color background. */
|
||||||
public static final class PipAppIconOverlay extends PipContentOverlay {
|
public static final class PipAppIconOverlay extends PipContentOverlay {
|
||||||
private static final String TAG = PipAppIconOverlay.class.getSimpleName();
|
private static final String TAG = PipAppIconOverlay.class.getSimpleName();
|
||||||
private static final int APP_ICON_SIZE_DP = 48;
|
// Align with the practical / reasonable launcher:iconImageSize as in
|
||||||
|
// vendor/unbundled_google/packages/NexusLauncher/res/xml/device_profiles.xml
|
||||||
|
private static final int APP_ICON_SIZE_DP = 66;
|
||||||
|
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
private final int mAppIconSizePx;
|
private final int mAppIconSizePx;
|
||||||
@@ -187,14 +188,14 @@ public abstract class PipContentOverlay {
|
|||||||
|
|
||||||
private Bitmap mBitmap;
|
private Bitmap mBitmap;
|
||||||
|
|
||||||
public PipAppIconOverlay(Context context, Rect appBounds, ActivityInfo activityInfo) {
|
public PipAppIconOverlay(Context context, Rect appBounds, Supplier<Drawable> iconSupplier) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mAppIconSizePx = (int) TypedValue.applyDimension(COMPLEX_UNIT_DIP, APP_ICON_SIZE_DP,
|
mAppIconSizePx = (int) TypedValue.applyDimension(COMPLEX_UNIT_DIP, APP_ICON_SIZE_DP,
|
||||||
context.getResources().getDisplayMetrics());
|
context.getResources().getDisplayMetrics());
|
||||||
mAppBounds = new Rect(appBounds);
|
mAppBounds = new Rect(appBounds);
|
||||||
mBitmap = Bitmap.createBitmap(appBounds.width(), appBounds.height(),
|
mBitmap = Bitmap.createBitmap(appBounds.width(), appBounds.height(),
|
||||||
Bitmap.Config.ARGB_8888);
|
Bitmap.Config.ARGB_8888);
|
||||||
prepareAppIconOverlay(activityInfo);
|
prepareAppIconOverlay(iconSupplier);
|
||||||
mLeash = new SurfaceControl.Builder(new SurfaceSession())
|
mLeash = new SurfaceControl.Builder(new SurfaceSession())
|
||||||
.setCallsite(TAG)
|
.setCallsite(TAG)
|
||||||
.setName(LAYER_NAME)
|
.setName(LAYER_NAME)
|
||||||
@@ -237,7 +238,7 @@ public abstract class PipContentOverlay {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void prepareAppIconOverlay(ActivityInfo activityInfo) {
|
private void prepareAppIconOverlay(Supplier<Drawable> iconSupplier) {
|
||||||
final Canvas canvas = new Canvas();
|
final Canvas canvas = new Canvas();
|
||||||
canvas.setBitmap(mBitmap);
|
canvas.setBitmap(mBitmap);
|
||||||
final TypedArray ta = mContext.obtainStyledAttributes(new int[] {
|
final TypedArray ta = mContext.obtainStyledAttributes(new int[] {
|
||||||
@@ -251,8 +252,7 @@ public abstract class PipContentOverlay {
|
|||||||
} finally {
|
} finally {
|
||||||
ta.recycle();
|
ta.recycle();
|
||||||
}
|
}
|
||||||
final Drawable appIcon = loadActivityInfoIcon(activityInfo,
|
final Drawable appIcon = iconSupplier.get();
|
||||||
mContext.getResources().getConfiguration().densityDpi);
|
|
||||||
final Rect appIconBounds = new Rect(
|
final Rect appIconBounds = new Rect(
|
||||||
mAppBounds.centerX() - mAppIconSizePx / 2,
|
mAppBounds.centerX() - mAppIconSizePx / 2,
|
||||||
mAppBounds.centerY() - mAppIconSizePx / 2,
|
mAppBounds.centerY() - mAppIconSizePx / 2,
|
||||||
@@ -262,24 +262,5 @@ public abstract class PipContentOverlay {
|
|||||||
appIcon.draw(canvas);
|
appIcon.draw(canvas);
|
||||||
mBitmap = mBitmap.copy(Bitmap.Config.HARDWARE, false /* mutable */);
|
mBitmap = mBitmap.copy(Bitmap.Config.HARDWARE, false /* mutable */);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copied from com.android.launcher3.icons.IconProvider#loadActivityInfoIcon
|
|
||||||
private Drawable loadActivityInfoIcon(ActivityInfo ai, int density) {
|
|
||||||
final int iconRes = ai.getIconResource();
|
|
||||||
Drawable icon = null;
|
|
||||||
// Get the preferred density icon from the app's resources
|
|
||||||
if (density != 0 && iconRes != 0) {
|
|
||||||
try {
|
|
||||||
final Resources resources = mContext.getPackageManager()
|
|
||||||
.getResourcesForApplication(ai.applicationInfo);
|
|
||||||
icon = resources.getDrawableForDensity(iconRes, density);
|
|
||||||
} catch (PackageManager.NameNotFoundException | Resources.NotFoundException exc) { }
|
|
||||||
}
|
|
||||||
// Get the default density icon
|
|
||||||
if (icon == null) {
|
|
||||||
icon = ai.loadIcon(mContext.getPackageManager());
|
|
||||||
}
|
|
||||||
return icon;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user