diff --git a/src/com/android/launcher3/graphics/GridCustomizationsProvider.java b/src/com/android/launcher3/graphics/GridCustomizationsProvider.java index 18200f6447..69fa6739ac 100644 --- a/src/com/android/launcher3/graphics/GridCustomizationsProvider.java +++ b/src/com/android/launcher3/graphics/GridCustomizationsProvider.java @@ -169,6 +169,9 @@ public class GridCustomizationsProvider extends ContentProvider { LauncherPrefs.get(getContext()) .put(THEMED_ICONS, values.getAsBoolean(BOOLEAN_VALUE)); getContext().getContentResolver().notifyChange(uri, null); + mActivePreviews.values().forEach(observer -> + observer.renderer.refreshIcons() + ); return 1; } default: diff --git a/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java b/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java index 3330448919..346f64409e 100644 --- a/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java +++ b/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java @@ -35,9 +35,12 @@ import android.appwidget.AppWidgetHostView; import android.appwidget.AppWidgetProviderInfo; import android.content.Context; import android.content.ContextWrapper; +import android.content.pm.LauncherActivityInfo; +import android.content.pm.LauncherApps; import android.content.res.TypedArray; import android.graphics.PointF; import android.graphics.Rect; +import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Handler; import android.os.Looper; @@ -76,6 +79,7 @@ import com.android.launcher3.celllayout.CellLayoutLayoutParams; import com.android.launcher3.celllayout.CellPosMapper; import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.folder.FolderIcon; +import com.android.launcher3.icons.IconProvider; import com.android.launcher3.icons.LauncherIcons; import com.android.launcher3.model.BgDataModel; import com.android.launcher3.model.BgDataModel.FixedContainerItems; @@ -83,6 +87,7 @@ import com.android.launcher3.model.WidgetItem; import com.android.launcher3.model.WidgetsModel; import com.android.launcher3.model.data.FolderInfo; import com.android.launcher3.model.data.ItemInfo; +import com.android.launcher3.model.data.ItemInfoWithIcon; import com.android.launcher3.model.data.LauncherAppWidgetInfo; import com.android.launcher3.model.data.WorkspaceItemInfo; import com.android.launcher3.pm.InstallSessionHelper; @@ -188,6 +193,8 @@ public class LauncherPreviewRenderer extends ContextWrapper private final SparseIntArray mWallpaperColorResources; private final SparseArray mLauncherWidgetSpanInfo; + private final Map mIcons = new HashMap<>(); + public LauncherPreviewRenderer(Context context, InvariantDeviceProfile idp, WallpaperColors wallpaperColorsOverride, @@ -366,11 +373,43 @@ public class LauncherPreviewRenderer extends ContextWrapper return CellPosMapper.DEFAULT; } + /** + * Refreshes icon to update based on resource changes. + */ + public void refreshIcons() { + mUiHandler.post(() -> { + IconProvider iconProvider = null; + int iconDpi = -1; + for (Map.Entry entry : mIcons.entrySet()) { + BubbleTextView icon = entry.getKey(); + ItemInfoWithIcon info = entry.getValue(); + // get monochrome themed icon if it was not initially cached + if (info.bitmap.getMono() == null) { + if (iconProvider == null || iconDpi == -1) { + LauncherAppState appState = LauncherAppState.getInstance(mContext); + iconProvider = appState.getIconProvider(); + iconDpi = appState.getInvariantDeviceProfile().fillResIconDpi; + } + LauncherActivityInfo activityInfo = mContext.getSystemService( + LauncherApps.class) + .resolveActivity(info.getIntent(), info.user); + Drawable iconDrawable = iconProvider.getIcon(activityInfo, iconDpi); + LauncherIcons iconFactory = LauncherIcons.obtain(mContext); + info.bitmap = iconFactory.createBadgedIconBitmap(iconDrawable); + } + // update icon based on whether themed icon is enabled + icon.reapplyItemInfo(info); + } + } + ); + } + private void inflateAndAddIcon(WorkspaceItemInfo info) { CellLayout screen = mWorkspaceScreens.get(info.screenId); BubbleTextView icon = (BubbleTextView) mHomeElementInflater.inflate( R.layout.app_icon, screen, false); icon.applyFromWorkspaceItem(info); + mIcons.put(icon, info); addInScreenFromBind(icon, info); } @@ -477,6 +516,8 @@ public class LauncherPreviewRenderer extends ContextWrapper currentWorkspaceItems, otherWorkspaceItems); filterCurrentWorkspaceItems(currentScreenIds, dataModel.appWidgets, currentAppWidgets, otherAppWidgets); + + mIcons.clear(); for (ItemInfo itemInfo : currentWorkspaceItems) { switch (itemInfo.itemType) { case Favorites.ITEM_TYPE_APPLICATION: diff --git a/src/com/android/launcher3/graphics/PreviewSurfaceRenderer.java b/src/com/android/launcher3/graphics/PreviewSurfaceRenderer.java index 683354bf45..1bac7652cb 100644 --- a/src/com/android/launcher3/graphics/PreviewSurfaceRenderer.java +++ b/src/com/android/launcher3/graphics/PreviewSurfaceRenderer.java @@ -201,6 +201,13 @@ public class PreviewSurfaceRenderer { } } + /** + * Refreshes icon to update based on resource changes. + */ + public void refreshIcons() { + mRenderer.refreshIcons(); + } + /*** * Generates a new context overriding the theme color and the display size without affecting the * main application context