修改android N的Launcher3桌面应用图标

修改android N的Launcher3桌面应用图标

修改桌面应用默认图标的话修改的是IconCache.java这个文件
IconCache会保存应用的图标和title等信息。我想更改图标的话就从这个文件下手。我也可以找到每个原生应用的project 然后更改他们的launcher icon,但是我并不想这么做。所以我就在Launcher3 桌面应用图标显示的时候去修改它。
主要修改的地方在cacheLocked 这个方法里

private CacheEntry cacheLocked(ComponentName componentName, LauncherActivityInfoCompat info,
UserHandleCompat user, boolean usePackageIcon, boolean useLowResIcon, int unreadNum) {
ComponentKey cacheKey = new ComponentKey(componentName, user);
CacheEntry entry = mCache.get(cacheKey);
if (entry == null || (entry.isLowResIcon && !useLowResIcon) || unreadNum >= 0) {
entry = new CacheEntry();
mCache.put(cacheKey, entry);

// Check the DB first.
if (!getEntryFromDB(cacheKey, entry, useLowResIcon) || DEBUG_IGNORE_CACHE || unreadNum >= 0) {
if (info != null) {
entry.icon = Utilities.createBadgedIconBitmap(
mIconProvider.getIcon(info, mIconDpi), info.getUser(),
mContext, unreadNum);
} 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.icon = packageEntry.icon;
entry.title = packageEntry.title;
entry.contentDescription = packageEntry.contentDescription;
}
}
if (entry.icon == null) {
if (DEBUG) Log.d(TAG, "using default icon for " +
componentName.toShortString());
entry.icon = getDefaultIcon(user);
}
}
}

if (TextUtils.isEmpty(entry.title) && info != null) {
entry.title = info.getLabel();
entry.contentDescription = mUserManager.getBadgedLabelForUser(entry.title, user);
}
            //Modify by yy,change to our icon
            //新的ICON在这里修改,上面是读取应用ICON和其他信息的,Title 信息什么的也可以在这改
            if(entry.icon != null){
                Drawable ltIcon = LtLauncherIconUtils.getIconDrawable(mContext,componentName.getPackageName());
                if(ltIcon != null)
                    entry.icon = Utilities.createIconBitmap(ltIcon, mContext);
            }
            //end Modify by yy
}
return entry;
}

这个文件就是控制要更改icon的应用和更改的icon图标

public class LtLauncherIconUtils {
private static final String TAG = LtLauncherIconUtils.class.getSimpleName();
private static final String[] PACKAGE_NAMES = {
"com.android.dialer",
"com.android.messaging",
"com.android.contacts",
"com.android.calculator2",
"com.android.settings",
"com.android.deskclock",
"org.codeaurora.gallery",
"org.codeaurora.snapcam"
};
private static final int[] PACKAGE_ICONS = {
R.mipmap.icon_lt_dialer,
R.mipmap.icon_lt_messaging,
R.mipmap.icon_lt_contacts,
R.mipmap.icon_lt_calculator2,
R.mipmap.icon_lt_settings,
R.mipmap.icon_lt_deskclock,
R.mipmap.icon_lt_gallery3d,
R.mipmap.icon_lt_camera
};

public static Drawable getIconDrawable(Context context, String packageName) {
Log.e(TAG, "packageName=" + packageName);
int i = Arrays.asList(PACKAGE_NAMES).indexOf(packageName);
if (i != -1)
return context.getResources().getDrawable(PACKAGE_ICONS[i], null);
else return null;
}
    }

你可能感兴趣的:(修改android N的Launcher3桌面应用图标)