From b0de412e4770ec5cf01222783e37eda7774480ec Mon Sep 17 00:00:00 2001 From: Catherine Liang Date: Tue, 12 Dec 2023 21:16:22 +0000 Subject: [PATCH] Fix Launcher preview display size When previewing the Launcher in the Wallpaper Picker for a different display size than the current screen, the preview no longer adapts to that screen size. Flag: ACONFIG com.android.wallpaper.multi_crop_preview_ui_flag DEVELOPMENT Bug: 316000567 Test: manually verified Change-Id: Ib10f2c9acec98ed99cadd40a588e2ffdea900ba6 --- .../graphics/LauncherPreviewRenderer.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java b/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java index 3330448919..7dcc8a8637 100644 --- a/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java +++ b/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java @@ -35,6 +35,7 @@ import android.appwidget.AppWidgetHostView; import android.appwidget.AppWidgetProviderInfo; import android.content.Context; import android.content.ContextWrapper; +import android.content.res.Configuration; import android.content.res.TypedArray; import android.graphics.PointF; import android.graphics.Rect; @@ -197,7 +198,7 @@ public class LauncherPreviewRenderer extends ContextWrapper mUiHandler = new Handler(Looper.getMainLooper()); mContext = context; mIdp = idp; - mDp = idp.getDeviceProfile(context).toBuilder(context).setViewScaleProvider( + mDp = getDeviceProfileForPreview(context).toBuilder(context).setViewScaleProvider( this::getAppWidgetScale).build(); if (context instanceof PreviewContext) { Context tempContext = ((PreviewContext) context).getBaseContext(); @@ -259,6 +260,21 @@ public class LauncherPreviewRenderer extends ContextWrapper mAppWidgetHost = new LauncherPreviewAppWidgetHost(context); } + /** + * Returns the device profile based on resource configuration for previewing various display + * sizes + */ + private DeviceProfile getDeviceProfileForPreview(Context context) { + float density = context.getResources().getDisplayMetrics().density; + Configuration config = context.getResources().getConfiguration(); + + return mIdp.getBestMatch( + config.screenWidthDp * density, + config.screenHeightDp * density, + WindowManagerProxy.INSTANCE.get(context).getRotation(context) + ); + } + /** * Returns the insets of the screen closest to the display given by the context */