Merge "Using BaseIconFactory to draw legacy icon." into sc-dev
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/startingsurface/SplashscreenContentDrawer.java b/libs/WindowManager/Shell/src/com/android/wm/shell/startingsurface/SplashscreenContentDrawer.java
index 107a3f8..56ad2be 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/startingsurface/SplashscreenContentDrawer.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/startingsurface/SplashscreenContentDrawer.java
@@ -37,6 +37,7 @@
import android.graphics.Color;
import android.graphics.Rect;
import android.graphics.drawable.AdaptiveIconDrawable;
+import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
@@ -57,6 +58,7 @@
import com.android.internal.graphics.palette.Palette;
import com.android.internal.graphics.palette.Quantizer;
import com.android.internal.graphics.palette.VariationalKMeansQuantizer;
+import com.android.launcher3.icons.BaseIconFactory;
import com.android.launcher3.icons.IconProvider;
import com.android.wm.shell.common.TransactionPool;
@@ -368,8 +370,14 @@
if (DEBUG) {
Slog.d(TAG, "The icon is not an AdaptiveIconDrawable");
}
- // TODO process legacy icon(bitmap)
- createIconDrawable(iconDrawable, true);
+ Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "legacy_icon_factory");
+ final ShapeIconFactory factory = new ShapeIconFactory(
+ SplashscreenContentDrawer.this.mContext,
+ scaledIconDpi, mFinalIconSize);
+ final Bitmap bitmap = factory.createScaledBitmapWithoutShadow(
+ iconDrawable, true /* shrinkNonAdaptiveIcons */);
+ Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
+ createIconDrawable(new BitmapDrawable(bitmap), true);
}
animationDuration = 0;
}
@@ -377,11 +385,15 @@
return fillViewWithIcon(mFinalIconSize, mFinalIconDrawable, animationDuration);
}
+ private class ShapeIconFactory extends BaseIconFactory {
+ protected ShapeIconFactory(Context context, int fillResIconDpi, int iconBitmapSize) {
+ super(context, fillResIconDpi, iconBitmapSize, true /* shapeDetection */);
+ }
+ }
+
private void createIconDrawable(Drawable iconDrawable, boolean legacy) {
if (legacy) {
mFinalIconDrawable = SplashscreenIconDrawableFactory.makeLegacyIconDrawable(
- mTmpAttrs.mIconBgColor != Color.TRANSPARENT
- ? mTmpAttrs.mIconBgColor : Color.WHITE,
iconDrawable, mDefaultIconSize, mFinalIconSize, mSplashscreenWorkerHandler);
} else {
mFinalIconDrawable = SplashscreenIconDrawableFactory.makeIconDrawable(
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/startingsurface/SplashscreenIconDrawableFactory.java b/libs/WindowManager/Shell/src/com/android/wm/shell/startingsurface/SplashscreenIconDrawableFactory.java
index 211941f..ba9123d 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/startingsurface/SplashscreenIconDrawableFactory.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/startingsurface/SplashscreenIconDrawableFactory.java
@@ -64,11 +64,10 @@
}
}
- static Drawable makeLegacyIconDrawable(@ColorInt int backgroundColor,
- @NonNull Drawable foregroundDrawable, int srcIconSize, int iconSize,
- Handler splashscreenWorkerHandler) {
- return new ImmobileIconDrawable(new LegacyIconDrawable(backgroundColor,
- foregroundDrawable), srcIconSize, iconSize, splashscreenWorkerHandler);
+ static Drawable makeLegacyIconDrawable(@NonNull Drawable iconDrawable, int srcIconSize,
+ int iconSize, Handler splashscreenWorkerHandler) {
+ return new ImmobileIconDrawable(iconDrawable, srcIconSize, iconSize,
+ splashscreenWorkerHandler);
}
private static class ImmobileIconDrawable extends Drawable {
@@ -179,65 +178,6 @@
}
}
- private static class LegacyIconDrawable extends MaskBackgroundDrawable {
- // reference FixedScaleDrawable
- // iconBounds = 0.7 * X * outerBounds, X is the scale of diagonal
- private static final float LEGACY_ICON_SCALE = .7f * .8f;
- private final Drawable mForegroundDrawable;
- private float mScaleX, mScaleY, mTransX, mTransY;
-
- LegacyIconDrawable(@ColorInt int backgroundColor, Drawable foregroundDrawable) {
- super(backgroundColor);
- mForegroundDrawable = foregroundDrawable;
- mScaleX = LEGACY_ICON_SCALE;
- mScaleY = LEGACY_ICON_SCALE;
- }
-
- @Override
- protected void updateLayerBounds(Rect bounds) {
- super.updateLayerBounds(bounds);
-
- if (mForegroundDrawable == null) {
- return;
- }
- float outerBoundsWidth = bounds.width();
- float outerBoundsHeight = bounds.height();
- float h = mForegroundDrawable.getIntrinsicHeight();
- float w = mForegroundDrawable.getIntrinsicWidth();
- mScaleX = LEGACY_ICON_SCALE;
- mScaleY = LEGACY_ICON_SCALE;
- if (h > w && w > 0) {
- mScaleX *= w / h;
- } else if (w > h && h > 0) {
- mScaleY *= h / w;
- }
- int innerBoundsWidth = (int) (0.5 + outerBoundsWidth * mScaleX);
- int innerBoundsHeight = (int) (0.5 + outerBoundsHeight * mScaleY);
- final Rect rect = new Rect(0, 0, innerBoundsWidth, innerBoundsHeight);
- mForegroundDrawable.setBounds(rect);
- mTransX = (outerBoundsWidth - innerBoundsWidth) / 2;
- mTransY = (outerBoundsHeight - innerBoundsHeight) / 2;
- invalidateSelf();
- }
-
- @Override
- public void draw(Canvas canvas) {
- super.draw(canvas);
- int saveCount = canvas.save();
- canvas.translate(mTransX, mTransY);
- if (mForegroundDrawable != null) {
- mForegroundDrawable.draw(canvas);
- }
- canvas.restoreToCount(saveCount);
- }
-
- @Override
- public void setColorFilter(ColorFilter colorFilter) {
- if (mForegroundDrawable != null) {
- mForegroundDrawable.setColorFilter(colorFilter);
- }
- }
- }
/**
* A lightweight AdaptiveIconDrawable which support foreground to be Animatable, and keep this
* drawable masked by config_icon_mask.