Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7059799a authored by Catherine Liang's avatar Catherine Liang Committed by Android (Google) Code Review
Browse files

Merge "Update launcher preview icons on themed icon update" into main

parents 8b188122 d64230f4
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -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:
+41 −0
Original line number Diff line number Diff line
@@ -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<Size> mLauncherWidgetSpanInfo;

    private final Map<BubbleTextView, WorkspaceItemInfo> 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<BubbleTextView, WorkspaceItemInfo> 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:
+7 −0
Original line number Diff line number Diff line
@@ -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