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

Commit b0de412e authored by Catherine Liang's avatar Catherine Liang
Browse files

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
parent 820460b1
Loading
Loading
Loading
Loading
+17 −1
Original line number Diff line number Diff line
@@ -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
     */