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

Commit 73d80aa0 authored by Aurélien Pomini's avatar Aurélien Pomini
Browse files

Improve multi-crop forward compatibility logic

Make sure we first adapt the existing crop for the new device before
generating missing crops. This is important if there is a B&R from a
similar device with slightly different screen dimensions: we don't want
to calculate the missing crops based on the crops of a previous device;
we first want to adjust the existing crops for the new device before
calculating other crops for missing orientations.

Flag: aconfig com.android.window.flags.multi_crop DEVELOPMENT
Bug: NA (let's not spam bugs with small fixes)
Test: atest WallpaperManagerTest WallpaperCropperTest
Change-Id: I199d6b2c00314c00ca6c240b942e5b0c4e902be9
parent f37e3002
Loading
Loading
Loading
Loading
+18 −3
Original line number Diff line number Diff line
@@ -357,15 +357,30 @@ public class WallpaperCropper {
     * Given some suggested crops, find cropHints for all orientations of the default display.
     */
    SparseArray<Rect> getDefaultCrops(SparseArray<Rect> suggestedCrops, Point bitmapSize) {
        SparseArray<Rect> result = new SparseArray<>();
        // add missing cropHints for all orientation of the default display

        SparseArray<Point> defaultDisplaySizes = mWallpaperDisplayHelper.getDefaultDisplaySizes();
        boolean rtl = TextUtils.getLayoutDirectionFromLocale(Locale.getDefault())
                == View.LAYOUT_DIRECTION_RTL;

        // adjust existing entries for the default display
        SparseArray<Rect> adjustedSuggestedCrops = new SparseArray<>();
        for (int i = 0; i < defaultDisplaySizes.size(); i++) {
            int orientation = defaultDisplaySizes.keyAt(i);
            Point displaySize = defaultDisplaySizes.valueAt(i);
            Rect suggestedCrop = suggestedCrops.get(orientation);
            if (suggestedCrop != null) {
                adjustedSuggestedCrops.put(orientation,
                        getCrop(displaySize, bitmapSize, suggestedCrops, rtl));
            }
        }

        // add missing cropHints for all orientation of the default display
        SparseArray<Rect> result = adjustedSuggestedCrops.clone();
        for (int i = 0; i < defaultDisplaySizes.size(); i++) {
            int orientation = defaultDisplaySizes.keyAt(i);
            if (result.contains(orientation)) continue;
            Point displaySize = defaultDisplaySizes.valueAt(i);
            Rect newCrop = getCrop(displaySize, bitmapSize, suggestedCrops, rtl);
            Rect newCrop = getCrop(displaySize, bitmapSize, adjustedSuggestedCrops, rtl);
            result.put(orientation, newCrop);
        }
        return result;