From 57c8d68001f210f3fafa4eb93e1f920699231b8f Mon Sep 17 00:00:00 2001 From: Brian Isganitis Date: Mon, 19 Jul 2021 14:36:06 -0400 Subject: [PATCH] Use global color extraction in widgets for wallpaper preview Test: Widgets in wallpaper app should use wallpaper colors Bug: 192205054 Change-Id: I4da9ad1cc88be251f97e86b6c8c9b346ed20f586 --- lint-baseline-launcher3.xml | 11 +++++++ .../graphics/LauncherPreviewRenderer.java | 29 +++++++++++-------- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/lint-baseline-launcher3.xml b/lint-baseline-launcher3.xml index e77c88926d..94345a6c75 100644 --- a/lint-baseline-launcher3.xml +++ b/lint-baseline-launcher3.xml @@ -584,4 +584,15 @@ column="17"/> + + + + diff --git a/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java b/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java index 1da8028814..94778a2e8e 100644 --- a/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java +++ b/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java @@ -15,6 +15,7 @@ */ package com.android.launcher3.graphics; +import static android.app.WallpaperManager.FLAG_SYSTEM; import static android.view.View.MeasureSpec.EXACTLY; import static android.view.View.MeasureSpec.makeMeasureSpec; import static android.view.View.VISIBLE; @@ -27,6 +28,7 @@ import static com.android.launcher3.model.ModelUtils.sortWorkspaceItemsSpatially import android.annotation.TargetApi; import android.app.Fragment; import android.app.WallpaperColors; +import android.app.WallpaperManager; import android.appwidget.AppWidgetHost; import android.appwidget.AppWidgetHostView; import android.appwidget.AppWidgetProviderInfo; @@ -214,7 +216,7 @@ public class LauncherPreviewRenderer extends ContextWrapper public LauncherPreviewRenderer(Context context, InvariantDeviceProfile idp, - WallpaperColors wallpaperColors) { + WallpaperColors wallpaperColorsOverride) { super(context); mUiHandler = new Handler(Looper.getMainLooper()); @@ -280,16 +282,18 @@ public class LauncherPreviewRenderer extends ContextWrapper mDp.workspacePadding.bottom); mWorkspaceScreens.put(FIRST_SCREEN_ID, firstScreen); - if (FeatureFlags.WIDGETS_IN_LAUNCHER_PREVIEW.get()) { - mAppWidgetHost = new LauncherPreviewAppWidgetHost(context); - mWallpaperColorResources = wallpaperColors != null - ? LocalColorExtractor.newInstance(context) - .generateColorsOverride(wallpaperColors) - : null; + if (Utilities.ATLEAST_S) { + WallpaperColors wallpaperColors = wallpaperColorsOverride != null + ? wallpaperColorsOverride + : WallpaperManager.getInstance(context).getWallpaperColors(FLAG_SYSTEM); + mWallpaperColorResources = LocalColorExtractor.newInstance(context) + .generateColorsOverride(wallpaperColors); } else { - mAppWidgetHost = null; mWallpaperColorResources = null; } + mAppWidgetHost = FeatureFlags.WIDGETS_IN_LAUNCHER_PREVIEW.get() + ? new LauncherPreviewAppWidgetHost(context) + : null; } /** Populate preview and render it. */ @@ -405,6 +409,10 @@ public class LauncherPreviewRenderer extends ContextWrapper view.updateAppWidget(null); } + if (mWallpaperColorResources != null) { + view.setColorResources(mWallpaperColorResources); + } + view.setTag(info); addInScreenFromBind(view, info); } @@ -537,12 +545,9 @@ public class LauncherPreviewRenderer extends ContextWrapper } } - private class LauncherPreviewAppWidgetHostView extends BaseLauncherAppWidgetHostView { + private static class LauncherPreviewAppWidgetHostView extends BaseLauncherAppWidgetHostView { private LauncherPreviewAppWidgetHostView(Context context) { super(context); - if (Utilities.ATLEAST_S && mWallpaperColorResources != null) { - setColorResources(mWallpaperColorResources); - } } @Override