Android Launcher APP替换图标不随系统固定格式而改变

本文对比了AndroidP和AndroidQ中Launcher3图标加载的代码修改,详细解析了在不同版本中对AdaptiveIconDrawable处理的差异,以及BaseIconFactory类中针对不同API级别的条件判断变化。

Android P 的修改:

--- a/vendor/mediatek/proprietary/packages/apps/Launcher3/src/com/android/launcher3/graphics/LauncherIcons.java
+++ b/vendor/mediatek/proprietary/packages/apps/Launcher3/src/com/android/launcher3/graphics/LauncherIcons.java
@@ -195,7 +195,8 @@ public class LauncherIcons implements AutoCloseable {
         float[] scale = new float[1];
         icon = normalizeAndWrapToAdaptiveIcon(icon, iconAppTargetSdk, null, scale);
         Bitmap bitmap = createIconBitmap(icon, scale[0]);
-        if (Utilities.ATLEAST_OREO && icon instanceof AdaptiveIconDrawable) {
+        if (/*Utilities.ATLEAST_OREO*/false && icon instanceof AdaptiveIconDrawable) {
             mCanvas.setBitmap(bitmap);
             getShadowGenerator().recreateIcon(Bitmap.createBitmap(bitmap), mCanvas);
             mCanvas.setBitmap(null);
@@ -241,7 +242,8 @@ public class LauncherIcons implements AutoCloseable {
     private Drawable normalizeAndWrapToAdaptiveIcon(Drawable icon, int iconAppTargetSdk,
             RectF outIconBounds, float[] outScale) {
         float scale = 1f;
-        if (Utilities.ATLEAST_OREO && iconAppTargetSdk >= Build.VERSION_CODES.O) {
+        if (/*Utilities.ATLEAST_OREO*/false && iconAppTargetSdk >= Build.VERSION_CODES.O) {
             boolean[] outShape = new boolean[1];
             if (mWrapperIcon == null) {
                 mWrapperIcon = mContext.getDrawable(R.drawable.adaptive_icon_drawable_wrapper)
@@ -250,7 +252,8 @@ public class LauncherIcons implements AutoCloseable {
             AdaptiveIconDrawable dr = (AdaptiveIconDrawable) mWrapperIcon;
             dr.setBounds(0, 0, 1, 1);
             scale = getNormalizer().getScale(icon, outIconBounds, dr.getIconMask(), outShape);
-            if (Utilities.ATLEAST_OREO && !outShape[0] && !(icon instanceof AdaptiveIconDrawable)) {
+            if (/*Utilities.ATLEAST_OREO*/false && !outShape[0] && !(icon instanceof AdaptiveIconDrawable)) {
                 FixedScaleDrawable fsd = ((FixedScaleDrawable) dr.getForeground());
                 fsd.setDrawable(icon);
                 fsd.setScale(scale);
@@ -329,7 +332,8 @@ public class LauncherIcons implements AutoCloseable {
         final int top = (textureHeight-height) / 2;
 
         mOldBounds.set(icon.getBounds());
-        if (Utilities.ATLEAST_OREO && icon instanceof AdaptiveIconDrawable) {
+        if (/*Utilities.ATLEAST_OREO*/false && icon instanceof AdaptiveIconDrawable) {
             int offset = Math.max((int) Math.ceil(BLUR_FACTOR * textureWidth), Math.max(left, top));
             int size = Math.max(width, height);
             icon.setBounds(offset, offset, offset + size, offset + size);

Android Q的修改:

--- a/packages/apps/Launcher3/iconloaderlib/src/com/android/launcher3/icons/BaseIconFactory.java
+++ b/packages/apps/Launcher3/iconloaderlib/src/com/android/launcher3/icons/BaseIconFactory.java
@@ -31,7 +31,7 @@ public class BaseIconFactory implements AutoCloseable {
 
     private static final String TAG = "BaseIconFactory";
     private static final int DEFAULT_WRAPPER_BACKGROUND = Color.WHITE;
-    static final boolean ATLEAST_OREO = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O;
+    static final boolean ATLEAST_OREO = false;//Build.VERSION.SDK_INT >= Build.VERSION_CODES.O;
     static final boolean ATLEAST_P = Build.VERSION.SDK_INT >= Build.VERSION_CODES.P;
 
     private final Rect mOldBounds = new Rect();
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

最乱纷飞的code

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值