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

Commit 4a763158 authored by Brian Isganitis's avatar Brian Isganitis
Browse files

Use wallpaper colors for widgets in wallpaper change preview

Test: Widgets should adapt to new wallpaper colors in launcher preview.
Bug: 191499358
Change-Id: I3fb76b6036cb909771b789eac15742df78c2c742
parent 0ac02319
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -573,4 +573,15 @@
            column="42"/>
    </issue>

    <issue
        id="NewApi"
        message="Call requires API level 31 (current min is 26): `android.appwidget.AppWidgetHostView#setColorResources`"
        errorLine1="                setColorResources(mWallpaperColorResources);"
        errorLine2="                ~~~~~~~~~~~~~~~~~">
        <location
            file="packages/apps/Launcher3/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java"
            line="528"
            column="17"/>
    </issue>

</issues>
+22 −6
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import static com.android.launcher3.model.ModelUtils.sortWorkspaceItemsSpatially

import android.annotation.TargetApi;
import android.app.Fragment;
import android.app.WallpaperColors;
import android.appwidget.AppWidgetHost;
import android.appwidget.AppWidgetHostView;
import android.appwidget.AppWidgetProviderInfo;
@@ -42,6 +43,7 @@ import android.os.Handler;
import android.os.Looper;
import android.os.Process;
import android.util.AttributeSet;
import android.util.SparseIntArray;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
@@ -87,6 +89,7 @@ import com.android.launcher3.views.BaseDragLayer;
import com.android.launcher3.widget.BaseLauncherAppWidgetHostView;
import com.android.launcher3.widget.LauncherAppWidgetHost;
import com.android.launcher3.widget.LauncherAppWidgetProviderInfo;
import com.android.launcher3.widget.LocalColorExtractor;
import com.android.launcher3.widget.NavigableAppWidgetHostView;
import com.android.launcher3.widget.custom.CustomWidgetManager;

@@ -206,8 +209,12 @@ public class LauncherPreviewRenderer extends ContextWrapper
    private final Hotseat mHotseat;
    private final CellLayout mWorkspace;
    private final AppWidgetHost mAppWidgetHost;
    private final SparseIntArray mWallpaperColorResources;

    public LauncherPreviewRenderer(Context context,
            InvariantDeviceProfile idp,
            WallpaperColors wallpaperColors) {

    public LauncherPreviewRenderer(Context context, InvariantDeviceProfile idp) {
        super(context);
        mUiHandler = new Handler(Looper.getMainLooper());
        mContext = context;
@@ -260,9 +267,16 @@ public class LauncherPreviewRenderer extends ContextWrapper
                mDp.workspacePadding.right + mDp.cellLayoutPaddingLeftRightPx,
                mDp.workspacePadding.bottom);

        mAppWidgetHost = FeatureFlags.WIDGETS_IN_LAUNCHER_PREVIEW.get()
                ? new LauncherPreviewAppWidgetHost(context)
        if (FeatureFlags.WIDGETS_IN_LAUNCHER_PREVIEW.get()) {
            mAppWidgetHost = new LauncherPreviewAppWidgetHost(context);
            mWallpaperColorResources =  wallpaperColors != null
                    ? LocalColorExtractor.newInstance(context)
                            .generateColorsOverride(wallpaperColors)
                    : null;
        } else {
            mAppWidgetHost = null;
            mWallpaperColorResources = null;
        }
    }

    /** Populate preview and render it. */
@@ -507,10 +521,12 @@ public class LauncherPreviewRenderer extends ContextWrapper
        }
    }

    private static class LauncherPreviewAppWidgetHostView extends BaseLauncherAppWidgetHostView {

    private class LauncherPreviewAppWidgetHostView extends BaseLauncherAppWidgetHostView {
        private LauncherPreviewAppWidgetHostView(Context context) {
            super(context);
            if (Utilities.ATLEAST_S && mWallpaperColorResources != null) {
                setColorResources(mWallpaperColorResources);
            }
        }

        @Override
+1 −1
Original line number Diff line number Diff line
@@ -209,7 +209,7 @@ public class PreviewSurfaceRenderer {
        if (mDestroyed) {
            return;
        }
        View view = new LauncherPreviewRenderer(inflationContext, mIdp)
        View view = new LauncherPreviewRenderer(inflationContext, mIdp, mWallpaperColors)
                .getRenderedView(dataModel, widgetProviderInfoMap);
        // This aspect scales the view to fit in the surface and centers it
        final float scale = Math.min(mWidth / (float) view.getMeasuredWidth(),
+8 −0
Original line number Diff line number Diff line
@@ -75,6 +75,14 @@ public class LocalColorExtractor implements ResourceBasedOverride {
     */
    public void applyColorsOverride(Context base, WallpaperColors colors) { }

    /**
     * Generates color resource overrides from {@link WallpaperColors}.
     */
    @Nullable
    public SparseIntArray generateColorsOverride(WallpaperColors colors) {
        return null;
    }

    /**
     * Takes a view and returns its rect that can be used by the wallpaper local color extractor.
     *