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

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

Merge "Fix Launcher preview display size" into main

parents 493ee688 b0de412e
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
     */