Merge "Use matrix to scale icon for splash starting window" into sc-dev am: 65782cf2c1
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14540930 Change-Id: Ibaadca44308d949ea19e6b31bd3547b3677e60a0
This commit is contained in:
@@ -308,7 +308,7 @@ public class SplashscreenContentDrawer {
|
|||||||
mFinalIconDrawable = SplashscreenIconDrawableFactory.makeIconDrawable(
|
mFinalIconDrawable = SplashscreenIconDrawableFactory.makeIconDrawable(
|
||||||
mTmpAttrs.mIconBgColor != Color.TRANSPARENT
|
mTmpAttrs.mIconBgColor != Color.TRANSPARENT
|
||||||
? mTmpAttrs.mIconBgColor : mThemeColor,
|
? mTmpAttrs.mIconBgColor : mThemeColor,
|
||||||
iconDrawable, mFinalIconSize, mSplashscreenWorkerHandler);
|
iconDrawable, mDefaultIconSize, mFinalIconSize, mSplashscreenWorkerHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean processAdaptiveIcon(Drawable iconDrawable) {
|
private boolean processAdaptiveIcon(Drawable iconDrawable) {
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ import android.annotation.ColorInt;
|
|||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapShader;
|
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.ColorFilter;
|
import android.graphics.ColorFilter;
|
||||||
import android.graphics.Matrix;
|
import android.graphics.Matrix;
|
||||||
@@ -32,7 +31,6 @@ import android.graphics.Paint;
|
|||||||
import android.graphics.Path;
|
import android.graphics.Path;
|
||||||
import android.graphics.PixelFormat;
|
import android.graphics.PixelFormat;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.graphics.Shader;
|
|
||||||
import android.graphics.drawable.AdaptiveIconDrawable;
|
import android.graphics.drawable.AdaptiveIconDrawable;
|
||||||
import android.graphics.drawable.Animatable;
|
import android.graphics.drawable.Animatable;
|
||||||
import android.graphics.drawable.ColorDrawable;
|
import android.graphics.drawable.ColorDrawable;
|
||||||
@@ -51,59 +49,53 @@ import com.android.internal.R;
|
|||||||
public class SplashscreenIconDrawableFactory {
|
public class SplashscreenIconDrawableFactory {
|
||||||
|
|
||||||
static Drawable makeIconDrawable(@ColorInt int backgroundColor,
|
static Drawable makeIconDrawable(@ColorInt int backgroundColor,
|
||||||
@NonNull Drawable foregroundDrawable, int iconSize,
|
@NonNull Drawable foregroundDrawable, int srcIconSize, int iconSize,
|
||||||
Handler splashscreenWorkerHandler) {
|
Handler splashscreenWorkerHandler) {
|
||||||
if (foregroundDrawable instanceof Animatable) {
|
if (foregroundDrawable instanceof Animatable) {
|
||||||
return new AnimatableIconDrawable(backgroundColor, foregroundDrawable);
|
return new AnimatableIconDrawable(backgroundColor, foregroundDrawable);
|
||||||
} else if (foregroundDrawable instanceof AdaptiveIconDrawable) {
|
} else if (foregroundDrawable instanceof AdaptiveIconDrawable) {
|
||||||
return new ImmobileIconDrawable((AdaptiveIconDrawable) foregroundDrawable, iconSize,
|
return new ImmobileIconDrawable((AdaptiveIconDrawable) foregroundDrawable,
|
||||||
splashscreenWorkerHandler);
|
srcIconSize, iconSize, splashscreenWorkerHandler);
|
||||||
} else {
|
} else {
|
||||||
// TODO for legacy icon don't use adaptive icon drawable to wrapper it
|
// TODO for legacy icon don't use adaptive icon drawable to wrapper it
|
||||||
return new ImmobileIconDrawable(new AdaptiveIconDrawable(
|
return new ImmobileIconDrawable(new AdaptiveIconDrawable(
|
||||||
new ColorDrawable(backgroundColor), foregroundDrawable), iconSize,
|
new ColorDrawable(backgroundColor), foregroundDrawable),
|
||||||
splashscreenWorkerHandler);
|
srcIconSize, iconSize, splashscreenWorkerHandler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class ImmobileIconDrawable extends Drawable {
|
private static class ImmobileIconDrawable extends Drawable {
|
||||||
private boolean mCacheComplete;
|
|
||||||
private final Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG
|
private final Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG
|
||||||
| Paint.FILTER_BITMAP_FLAG);
|
| Paint.FILTER_BITMAP_FLAG);
|
||||||
|
private final Matrix mMatrix = new Matrix();
|
||||||
|
private Bitmap mIconBitmap;
|
||||||
|
|
||||||
ImmobileIconDrawable(AdaptiveIconDrawable drawable, int iconSize,
|
ImmobileIconDrawable(AdaptiveIconDrawable drawable, int srcIconSize, int iconSize,
|
||||||
Handler splashscreenWorkerHandler) {
|
Handler splashscreenWorkerHandler) {
|
||||||
splashscreenWorkerHandler.post(() -> cachePaint(drawable, iconSize, iconSize));
|
final float scale = (float) iconSize / srcIconSize;
|
||||||
|
mMatrix.setScale(scale, scale);
|
||||||
|
splashscreenWorkerHandler.post(() -> preDrawIcon(drawable, srcIconSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void cachePaint(AdaptiveIconDrawable drawable, int width, int height) {
|
private void preDrawIcon(AdaptiveIconDrawable drawable, int size) {
|
||||||
synchronized (mPaint) {
|
synchronized (mPaint) {
|
||||||
if (mCacheComplete) {
|
Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "preDrawIcon");
|
||||||
return;
|
mIconBitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
|
||||||
}
|
final Canvas canvas = new Canvas(mIconBitmap);
|
||||||
Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "cachePaint");
|
drawable.setBounds(0, 0, size, size);
|
||||||
final Bitmap layersBitmap = Bitmap.createBitmap(width, height,
|
|
||||||
Bitmap.Config.ARGB_8888);
|
|
||||||
final Canvas canvas = new Canvas(layersBitmap);
|
|
||||||
drawable.setBounds(0, 0, width, height);
|
|
||||||
drawable.draw(canvas);
|
drawable.draw(canvas);
|
||||||
final Shader layersShader = new BitmapShader(layersBitmap, Shader.TileMode.CLAMP,
|
|
||||||
Shader.TileMode.CLAMP);
|
|
||||||
mPaint.setShader(layersShader);
|
|
||||||
Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
|
Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
|
||||||
mCacheComplete = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Canvas canvas) {
|
public void draw(Canvas canvas) {
|
||||||
synchronized (mPaint) {
|
synchronized (mPaint) {
|
||||||
if (mCacheComplete) {
|
if (mIconBitmap != null) {
|
||||||
final Rect bounds = getBounds();
|
canvas.drawBitmap(mIconBitmap, mMatrix, mPaint);
|
||||||
canvas.drawRect(bounds, mPaint);
|
|
||||||
} else {
|
} else {
|
||||||
// this shouldn't happen, but if it really happen, invalidate self to wait
|
// this shouldn't happen, but if it really happen, invalidate self to wait
|
||||||
// for cachePaint finish.
|
// for bitmap to be ready.
|
||||||
invalidateSelf();
|
invalidateSelf();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -111,12 +103,10 @@ public class SplashscreenIconDrawableFactory {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setAlpha(int alpha) {
|
public void setAlpha(int alpha) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setColorFilter(ColorFilter colorFilter) {
|
public void setColorFilter(ColorFilter colorFilter) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user