Merge "Using BaseIconFactory to draw legacy icon." into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
61d71ccaae
@@ -37,6 +37,7 @@ import android.graphics.Canvas;
|
|||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.graphics.drawable.AdaptiveIconDrawable;
|
import android.graphics.drawable.AdaptiveIconDrawable;
|
||||||
|
import android.graphics.drawable.BitmapDrawable;
|
||||||
import android.graphics.drawable.ColorDrawable;
|
import android.graphics.drawable.ColorDrawable;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.graphics.drawable.LayerDrawable;
|
import android.graphics.drawable.LayerDrawable;
|
||||||
@@ -57,6 +58,7 @@ import com.android.internal.annotations.VisibleForTesting;
|
|||||||
import com.android.internal.graphics.palette.Palette;
|
import com.android.internal.graphics.palette.Palette;
|
||||||
import com.android.internal.graphics.palette.Quantizer;
|
import com.android.internal.graphics.palette.Quantizer;
|
||||||
import com.android.internal.graphics.palette.VariationalKMeansQuantizer;
|
import com.android.internal.graphics.palette.VariationalKMeansQuantizer;
|
||||||
|
import com.android.launcher3.icons.BaseIconFactory;
|
||||||
import com.android.launcher3.icons.IconProvider;
|
import com.android.launcher3.icons.IconProvider;
|
||||||
import com.android.wm.shell.common.TransactionPool;
|
import com.android.wm.shell.common.TransactionPool;
|
||||||
|
|
||||||
@@ -368,8 +370,14 @@ public class SplashscreenContentDrawer {
|
|||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Slog.d(TAG, "The icon is not an AdaptiveIconDrawable");
|
Slog.d(TAG, "The icon is not an AdaptiveIconDrawable");
|
||||||
}
|
}
|
||||||
// TODO process legacy icon(bitmap)
|
Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "legacy_icon_factory");
|
||||||
createIconDrawable(iconDrawable, true);
|
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;
|
animationDuration = 0;
|
||||||
}
|
}
|
||||||
@@ -377,11 +385,15 @@ public class SplashscreenContentDrawer {
|
|||||||
return fillViewWithIcon(mFinalIconSize, mFinalIconDrawable, animationDuration);
|
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) {
|
private void createIconDrawable(Drawable iconDrawable, boolean legacy) {
|
||||||
if (legacy) {
|
if (legacy) {
|
||||||
mFinalIconDrawable = SplashscreenIconDrawableFactory.makeLegacyIconDrawable(
|
mFinalIconDrawable = SplashscreenIconDrawableFactory.makeLegacyIconDrawable(
|
||||||
mTmpAttrs.mIconBgColor != Color.TRANSPARENT
|
|
||||||
? mTmpAttrs.mIconBgColor : Color.WHITE,
|
|
||||||
iconDrawable, mDefaultIconSize, mFinalIconSize, mSplashscreenWorkerHandler);
|
iconDrawable, mDefaultIconSize, mFinalIconSize, mSplashscreenWorkerHandler);
|
||||||
} else {
|
} else {
|
||||||
mFinalIconDrawable = SplashscreenIconDrawableFactory.makeIconDrawable(
|
mFinalIconDrawable = SplashscreenIconDrawableFactory.makeIconDrawable(
|
||||||
|
|||||||
@@ -64,11 +64,10 @@ public class SplashscreenIconDrawableFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Drawable makeLegacyIconDrawable(@ColorInt int backgroundColor,
|
static Drawable makeLegacyIconDrawable(@NonNull Drawable iconDrawable, int srcIconSize,
|
||||||
@NonNull Drawable foregroundDrawable, int srcIconSize, int iconSize,
|
int iconSize, Handler splashscreenWorkerHandler) {
|
||||||
Handler splashscreenWorkerHandler) {
|
return new ImmobileIconDrawable(iconDrawable, srcIconSize, iconSize,
|
||||||
return new ImmobileIconDrawable(new LegacyIconDrawable(backgroundColor,
|
splashscreenWorkerHandler);
|
||||||
foregroundDrawable), srcIconSize, iconSize, splashscreenWorkerHandler);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class ImmobileIconDrawable extends Drawable {
|
private static class ImmobileIconDrawable extends Drawable {
|
||||||
@@ -179,65 +178,6 @@ public class SplashscreenIconDrawableFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
* A lightweight AdaptiveIconDrawable which support foreground to be Animatable, and keep this
|
||||||
* drawable masked by config_icon_mask.
|
* drawable masked by config_icon_mask.
|
||||||
|
|||||||
Reference in New Issue
Block a user