当前位置:   article > 正文

MTK Android 11 Launcher 替换第三方应用图标_iconloaderlib更换图标

iconloaderlib更换图标

背景

系统三方图标规则不统一,第三方应用的 icon 不美观,或者跟系统主题风格不一致,此时就有替换三方 Launcher 图标的需求,需要系统 Launcher 通过包名在程序中替换图标。

核心代码

修改类

frameworks/libs/systemui/iconloaderlib/src/com/android/launcher3/icons/cache
  • 1

方法

 protected CacheEntry cacheLocked(
            @NonNull ComponentName componentName, @NonNull UserHandle user,
            @NonNull Supplier<T> infoProvider, @NonNull CachingLogic<T> cachingLogic,
            boolean usePackageIcon, boolean useLowResIcon) {
            assertWorkerThread();
        ComponentKey cacheKey = new ComponentKey(componentName, user);
        CacheEntry entry = mCache.get(cacheKey);
        if (entry == null || (entry.bitmap.isLowRes() !useLowResIcon)) {
            entry = new CacheEntry();
            if (cachingLogic.addToMemCache()) {
                mCache.put(cacheKey, entry);
            }

            // Check the DB first.
            T object = null;
            boolean providerFetchedOnce = false;

            if (!getEntryFromDB(cacheKey, entry, useLowResIcon)) {
                object = infoProvider.get();
                providerFetchedOnce = true;

                if (object != null) {
                    entry.bitmap = cachingLogic.loadIcon(mContext, object);
                } else {
                    if (usePackageIcon) {
                        CacheEntry packageEntry = getEntryForPackageLocked(
                                componentName.getPackageName(), user, false);
                        if (packageEntry != null) {
                            if (DEBUG) Log.d(TAG, "using package default icon for " +
                                    componentName.toShortString());
                            entry.bitmap = packageEntry.bitmap;
                            entry.title = packageEntry.title;
                            entry.contentDescription = packageEntry.contentDescription;
                        }
                    }
                    if (entry.bitmap == null) {
                        if (DEBUG) Log.d(TAG, "using default icon for " +
                                componentName.toShortString());
                        entry.bitmap = getDefaultIcon(user);
                    }
                }
            }
            f (TextUtils.isEmpty(entry.title)) {
                if (object == null && !providerFetchedOnce) {
                    object = infoProvider.get();
                    providerFetchedOnce = true;
                }
                if (object != null) {
                    entry.title = cachingLogic.getLabel(object);
                    entry.contentDescription = mPackageManager.getUserBadgedLabel(
                            cachingLogic.getDescription(object, entry.title), user);
                }
            }
        }

  // **替换修改图标 start **
  if("替换应用的包名".equals(componentName.getPackageName().toString())) {
            entry.bitmap = BitmapInfo.of(BitmapFactory.decodeResource(mContext.getResources(),
                    mContext.getResources().getIdentifier("替换应用的图标", "mipmap", mContext.getPackageName())), 0);
   } 
   // **替换修改图标 end.**
   return entry;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63

编译刷机,可以看到第三方应用图标已经替换成功,此方法经过验证有效,希望能帮到做系统开发的同学,大家多多交流,欢迎大家留言!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/787723
推荐阅读
相关标签
  

闽ICP备14008679号