Fix advanced icon will incorrect on some device

Use the fixed value to locate the center of icon instead
of use value of density. Because the value of density will
different between the device according the resolution.

Bug: 156689249
Test: build pass
Change-Id: I6d3a53e68058232871dd281ec4736179090a6580
This commit is contained in:
Hugh Chen
2020-06-15 15:56:02 +08:00
parent 5463497bed
commit c06745b3d3

View File

@@ -30,9 +30,7 @@ import android.graphics.Rect;
import android.graphics.drawable.AdaptiveIconDrawable;
import android.graphics.drawable.DrawableWrapper;
import android.os.RemoteException;
import android.util.DisplayMetrics;
import android.util.PathParser;
import android.view.Display;
import android.view.IWindowManager;
import android.view.WindowManagerGlobal;
@@ -47,6 +45,9 @@ import java.lang.annotation.RetentionPolicy;
*/
public class AdaptiveOutlineDrawable extends DrawableWrapper {
private static final float ADVANCED_ICON_CENTER = 50f;
private static final float ADVANCED_ICON_RADIUS = 48f;
@Retention(RetentionPolicy.SOURCE)
@IntDef({TYPE_DEFAULT, TYPE_ADVANCED})
public @interface AdaptiveOutlineIconType {
@@ -61,7 +62,6 @@ public class AdaptiveOutlineDrawable extends DrawableWrapper {
private int mStrokeWidth;
private Bitmap mBitmap;
private int mType;
private float mDensity;
public AdaptiveOutlineDrawable(Resources resources, Bitmap bitmap) {
super(new AdaptiveIconShapeDrawable(resources));
@@ -83,7 +83,6 @@ public class AdaptiveOutlineDrawable extends DrawableWrapper {
mPath = new Path(PathParser.createPathFromPathData(
resources.getString(com.android.internal.R.string.config_icon_mask)));
mStrokeWidth = resources.getDimensionPixelSize(R.dimen.adaptive_outline_stroke);
mDensity = resources.getDisplayMetrics().density;
mOutlinePaint = new Paint();
mOutlinePaint.setColor(getColor(resources, type));
mOutlinePaint.setStyle(Paint.Style.STROKE);
@@ -137,12 +136,7 @@ public class AdaptiveOutlineDrawable extends DrawableWrapper {
if (mType == TYPE_DEFAULT) {
canvas.drawPath(mPath, mOutlinePaint);
} else {
final float defaultDensity = getDefaultDisplayDensity(Display.DEFAULT_DISPLAY)
/ (float) DisplayMetrics.DENSITY_DEFAULT;
final int insetPx =
Math.round(mInsetPx / (float) (Math.floor(
(mDensity / defaultDensity) * 100) / 100.0));
canvas.drawCircle(2 * insetPx, 2 * insetPx, 2 * insetPx - mStrokeWidth,
canvas.drawCircle(ADVANCED_ICON_CENTER, ADVANCED_ICON_CENTER, ADVANCED_ICON_RADIUS,
mOutlinePaint);
}
canvas.restoreToCount(count);