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

Commit 3c8657e0 authored by Iavor-Valentin Iftime's avatar Iavor-Valentin Iftime Committed by Android (Google) Code Review
Browse files

Merge "Crop wallpaper image to preserve screen aspect ratio"

parents e6707b8a 3047bb11
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -89,6 +89,7 @@ import android.util.SparseArray;
import android.util.SparseBooleanArray;
import android.util.Xml;
import android.view.Display;
import android.view.DisplayInfo;
import android.view.IWindowManager;

import com.android.internal.R;
@@ -600,6 +601,20 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
            // scale if the crop height winds up not matching the recommended metrics
            needScale = (wpData.mHeight != cropHint.height());

            //make sure screen aspect ratio is preserved if width is scaled under screen size
            if (needScale) {
                final DisplayInfo displayInfo = new DisplayInfo();
                mDisplayManager.getDisplay(DEFAULT_DISPLAY).getDisplayInfo(displayInfo);
                final float scaleByHeight = (float) wpData.mHeight / (float) cropHint.height();
                final int newWidth = (int) (cropHint.width() * scaleByHeight);
                if (newWidth < displayInfo.logicalWidth) {
                    final float screenAspectRatio =
                            (float) displayInfo.logicalHeight / (float) displayInfo.logicalWidth;
                    cropHint.bottom = (int) (cropHint.width() * screenAspectRatio);
                    needCrop = true;
                }
            }

            if (DEBUG) {
                Slog.v(TAG, "crop: w=" + cropHint.width() + " h=" + cropHint.height());
                Slog.v(TAG, "dims: w=" + wpData.mWidth + " h=" + wpData.mHeight);