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

Commit ccb71776 authored by Chihhang Chuang's avatar Chihhang Chuang
Browse files

Apply the current system window insets to launcher preview

For wallpaper picker, the position of app icon on the wallpaper preview would match to the launcher after applying the wallpaper.

Wallpaper picker: https://screenshot.googleplex.com/JZazpgZLgzacZMZ.png
Launcher: https://screenshot.googleplex.com/9uTTQwdmcnFZ7Vi.png
Gesture mode: https://screenshot.googleplex.com/3YaKbBerYgtHBFb.png
3-button mode: https://screenshot.googleplex.com/7sA5nE3GmbuKf62.png

Fixes: 188539072
Test: Manually
Change-Id: I553000e6ae646207eb94fa33e97d00a3990043c8
parent fd3ad5d7
Loading
Loading
Loading
Loading
+16 −4
Original line number Diff line number Diff line
@@ -45,6 +45,8 @@ import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowInsets;
import android.view.WindowManager;
import android.widget.TextClock;

import com.android.launcher3.BubbleTextView;
@@ -56,6 +58,7 @@ import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherSettings.Favorites;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.WorkspaceLayoutManager;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.folder.FolderIcon;
@@ -205,10 +208,19 @@ public class LauncherPreviewRenderer extends ContextWrapper
        mIdp = idp;
        mDp = idp.getDeviceProfile(context).copy(context);

        // TODO: get correct insets once display cutout API is available.
        if (Utilities.ATLEAST_R) {
            WindowInsets currentWindowInsets = context.getSystemService(WindowManager.class)
                    .getCurrentWindowMetrics().getWindowInsets();
            mInsets = new Rect(
                    currentWindowInsets.getSystemWindowInsetLeft(),
                    currentWindowInsets.getSystemWindowInsetTop(),
                    currentWindowInsets.getSystemWindowInsetRight(),
                    currentWindowInsets.getSystemWindowInsetBottom());
        } else {
            mInsets = new Rect();
            mInsets.left = mInsets.right = (mDp.widthPx - mDp.availableWidthPx) / 2;
            mInsets.top = mInsets.bottom = (mDp.heightPx - mDp.availableHeightPx) / 2;
        }
        mDp.updateInsets(mInsets);

        BaseIconFactory iconFactory =
+6 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.view.Display;
import android.view.SurfaceControlViewHost;
import android.view.SurfaceControlViewHost.SurfacePackage;
import android.view.View;
import android.view.WindowManager.LayoutParams;
import android.view.animation.AccelerateDecelerateInterpolator;

import androidx.annotation.UiThread;
@@ -41,6 +42,7 @@ import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.graphics.LauncherPreviewRenderer.PreviewContext;
import com.android.launcher3.model.BgDataModel;
import com.android.launcher3.model.GridSizeMigrationTask;
@@ -139,6 +141,10 @@ public class PreviewSurfaceRenderer {
        if (mWallpaperColors != null) {
            // Create a themed context, without affecting the main application context
            Context context = mContext.createDisplayContext(mDisplay);
            if (Utilities.ATLEAST_R) {
                context = context.createWindowContext(
                        LayoutParams.TYPE_APPLICATION_OVERLAY, null);
            }
            LocalColorExtractor.newInstance(mContext)
                    .applyColorsOverride(context, mWallpaperColors);
            inflationContext = new ContextThemeWrapper(context,