Loading iconloaderlib/src/com/android/launcher3/icons/IconProvider.java +35 −1 Original line number Diff line number Diff line Loading @@ -69,6 +69,8 @@ public class IconProvider { public static final boolean ATLEAST_T = BuildCompat.isAtLeastT(); private static final String ICON_METADATA_KEY_PREFIX = ".dynamic_icons"; private static final String MONTH_BG_ICON_METADATA_KEY_PREFIX = ".month_dynamic_icons"; private static final String DAY_FG_ICON_METADATA_KEY_PREFIX = ".day_dynamic_icons"; private static final String SYSTEM_STATE_SEPARATOR = " "; Loading Loading @@ -173,7 +175,9 @@ public class IconProvider { .metaData; final Resources resources = pm.getResourcesForApplication(mCalendar.getPackageName()); final int id = getDynamicIconId(metadata, resources); if (id != ID_NULL) { final int[] monthDayIds = getDynamicBackgroundIconId(metadata, resources); if (id != ID_NULL && (monthDayIds == null || monthDayIds[0] == ID_NULL || monthDayIds[1] == ID_NULL )) { if (DEBUG) Log.d(TAG, "Got icon #" + id); Drawable drawable = resources.getDrawableForDensity(id, iconDpi, null /* theme */); if (ATLEAST_T && drawable instanceof AdaptiveIconDrawable && td != null) { Loading @@ -191,6 +195,10 @@ public class IconProvider { } } return drawable; } else if (monthDayIds != null) { Drawable background = resources.getDrawableForDensity(monthDayIds[0], iconDpi, null /* theme */); Drawable foreground = resources.getDrawableForDensity(monthDayIds[1], iconDpi, null /* theme */); return new AdaptiveIconDrawable(background, foreground); } } catch (PackageManager.NameNotFoundException e) { if (DEBUG) { Loading Loading @@ -225,6 +233,28 @@ public class IconProvider { } } private int[] getDynamicBackgroundIconId(Bundle metadata, Resources resources) { if (metadata == null) { return null; } String bgKey = mCalendar.getPackageName() + MONTH_BG_ICON_METADATA_KEY_PREFIX; String fgKey = mCalendar.getPackageName() + DAY_FG_ICON_METADATA_KEY_PREFIX; final int bgArrayId = metadata.getInt(bgKey, ID_NULL); final int fgArrayId = metadata.getInt(fgKey, ID_NULL); if (bgArrayId == ID_NULL || fgArrayId == ID_NULL) { return null; } try { return new int[] {resources.obtainTypedArray(bgArrayId).getResourceId(getMonth(), ID_NULL), resources.obtainTypedArray(fgArrayId).getResourceId(getDay(), ID_NULL)}; } catch (Resources.NotFoundException e) { if (DEBUG) { Log.d(TAG, "package defines '" + bgKey + " and " + fgKey + "' but corresponding array not found"); } return null; } } /** * @return Today's day of the month, zero-indexed. */ Loading @@ -232,6 +262,10 @@ public class IconProvider { return Calendar.getInstance().get(Calendar.DAY_OF_MONTH) - 1; } private static int getMonth() { return Calendar.getInstance().get(Calendar.MONTH); } private static ComponentName parseComponentOrNull(Context context, int resId) { String cn = context.getString(resId); return TextUtils.isEmpty(cn) ? null : ComponentName.unflattenFromString(cn); Loading Loading
iconloaderlib/src/com/android/launcher3/icons/IconProvider.java +35 −1 Original line number Diff line number Diff line Loading @@ -69,6 +69,8 @@ public class IconProvider { public static final boolean ATLEAST_T = BuildCompat.isAtLeastT(); private static final String ICON_METADATA_KEY_PREFIX = ".dynamic_icons"; private static final String MONTH_BG_ICON_METADATA_KEY_PREFIX = ".month_dynamic_icons"; private static final String DAY_FG_ICON_METADATA_KEY_PREFIX = ".day_dynamic_icons"; private static final String SYSTEM_STATE_SEPARATOR = " "; Loading Loading @@ -173,7 +175,9 @@ public class IconProvider { .metaData; final Resources resources = pm.getResourcesForApplication(mCalendar.getPackageName()); final int id = getDynamicIconId(metadata, resources); if (id != ID_NULL) { final int[] monthDayIds = getDynamicBackgroundIconId(metadata, resources); if (id != ID_NULL && (monthDayIds == null || monthDayIds[0] == ID_NULL || monthDayIds[1] == ID_NULL )) { if (DEBUG) Log.d(TAG, "Got icon #" + id); Drawable drawable = resources.getDrawableForDensity(id, iconDpi, null /* theme */); if (ATLEAST_T && drawable instanceof AdaptiveIconDrawable && td != null) { Loading @@ -191,6 +195,10 @@ public class IconProvider { } } return drawable; } else if (monthDayIds != null) { Drawable background = resources.getDrawableForDensity(monthDayIds[0], iconDpi, null /* theme */); Drawable foreground = resources.getDrawableForDensity(monthDayIds[1], iconDpi, null /* theme */); return new AdaptiveIconDrawable(background, foreground); } } catch (PackageManager.NameNotFoundException e) { if (DEBUG) { Loading Loading @@ -225,6 +233,28 @@ public class IconProvider { } } private int[] getDynamicBackgroundIconId(Bundle metadata, Resources resources) { if (metadata == null) { return null; } String bgKey = mCalendar.getPackageName() + MONTH_BG_ICON_METADATA_KEY_PREFIX; String fgKey = mCalendar.getPackageName() + DAY_FG_ICON_METADATA_KEY_PREFIX; final int bgArrayId = metadata.getInt(bgKey, ID_NULL); final int fgArrayId = metadata.getInt(fgKey, ID_NULL); if (bgArrayId == ID_NULL || fgArrayId == ID_NULL) { return null; } try { return new int[] {resources.obtainTypedArray(bgArrayId).getResourceId(getMonth(), ID_NULL), resources.obtainTypedArray(fgArrayId).getResourceId(getDay(), ID_NULL)}; } catch (Resources.NotFoundException e) { if (DEBUG) { Log.d(TAG, "package defines '" + bgKey + " and " + fgKey + "' but corresponding array not found"); } return null; } } /** * @return Today's day of the month, zero-indexed. */ Loading @@ -232,6 +262,10 @@ public class IconProvider { return Calendar.getInstance().get(Calendar.DAY_OF_MONTH) - 1; } private static int getMonth() { return Calendar.getInstance().get(Calendar.MONTH); } private static ComponentName parseComponentOrNull(Context context, int resId) { String cn = context.getString(resId); return TextUtils.isEmpty(cn) ? null : ComponentName.unflattenFromString(cn); Loading