Use larger crop surface size to allow for parallax scrolling
In ImagePreviewFragment, we were always limiting the width of the wallpaper
to match the hostViewSize, so the wallpaper ended up cropped to one screen
size.
The current solution still forces one screen size for wallpapers whose
size actually matches the screen, but we need a better longer term solution
Fixes: 160111671
Change-Id: Ic5e6547569eb40ca3a7799bf5519ca32dcedc169
diff --git a/src/com/android/wallpaper/picker/ImagePreviewFragment.java b/src/com/android/wallpaper/picker/ImagePreviewFragment.java
index 5c2a904..41df2ba 100755
--- a/src/com/android/wallpaper/picker/ImagePreviewFragment.java
+++ b/src/com/android/wallpaper/picker/ImagePreviewFragment.java
@@ -26,6 +26,7 @@
import android.animation.AnimatorListenerAdapter;
import android.app.Activity;
import android.content.Context;
+import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Point;
@@ -397,9 +398,20 @@
int cropWidth = mWorkspaceSurface.getMeasuredWidth();
int cropHeight = mWorkspaceSurface.getMeasuredHeight();
+ int maxCrop = Math.max(cropWidth, cropHeight);
+ int minCrop = Math.min(cropWidth, cropHeight);
Point hostViewSize = new Point(cropWidth, cropHeight);
+
+ // Workaround for now to force wallpapers designed to fit one screen size to not adjust for
+ // parallax scrolling (with an extra 1 pixel to account for rounding)
+ // TODO (santie): implement a better solution
+ boolean shouldForceScreenSize = mRawWallpaperSize.x - mScreenSize.x <= 1;
+ Resources res = context.getResources();
+ Point cropSurfaceSize = shouldForceScreenSize ? hostViewSize :
+ WallpaperCropUtils.calculateCropSurfaceSize(res, maxCrop, minCrop);
+
Rect cropRect = WallpaperCropUtils.calculateCropRect(context, hostViewSize,
- hostViewSize, mRawWallpaperSize, visibleFileRect, wallpaperZoom);
+ cropSurfaceSize, mRawWallpaperSize, visibleFileRect, wallpaperZoom);
WallpaperCropUtils.adjustCropRect(context, cropRect, false /* zoomIn */);
return cropRect;
}