Adjust the wallpaper preview parallax according to the crop that will be saved.

To get the crop, the wallpaper is first scaled down as much as possible (i.e.
until either the width or height matches that of the device screen), then a
center crop is performed (the excess width or height is chopped off). The
preview's parallax was previously incorrect if the width was the victim of this
cropping, because in that case the parallax started and ended at a different
point than in the actual wallpaper. This is fixed by adjusting the parallax of
the preview to match the final crop.

The end result is that all wallpaper previews match the actual wallpaper upon
setting, except for the default wallpaper because it follows a different flow.

Bug: 23568800
Change-Id: I82b7ba506d51ee4b3812af5fbdf95d3303b37aef
This commit is contained in:
Tony Wickham
2015-09-03 15:35:29 -07:00
parent 01649e3481
commit 8010486e8b
4 changed files with 16 additions and 18 deletions
@@ -193,10 +193,10 @@ public class CropView extends TiledImageView implements OnScaleGestureListener {
* Offsets wallpaper preview according to the state it will be displayed in upon returning home.
* @param offset Ranges from 0 to 1, where 0 is the leftmost parallax and 1 is the rightmost.
*/
public void setParallaxOffset(float offset) {
public void setParallaxOffset(float offset, RectF crop) {
offset = Math.max(0, Math.min(offset, 1)); // Make sure the offset is in the correct range.
float screenWidth = getWidth() / mRenderer.scale;
mCenterX = screenWidth / 2 + offset * (getSourceDimensions().x - screenWidth);
mCenterX = screenWidth / 2 + offset * (crop.width() - screenWidth) + crop.left;
updateCenter();
}
@@ -250,8 +250,13 @@ public class WallpaperCropActivity extends BaseActivity implements Handler.Callb
mCropView.moveToLeft();
}
if (req.scaleAndOffsetProvider != null) {
mCropView.setScale(req.scaleAndOffsetProvider.getScale(req.result));
mCropView.setParallaxOffset(req.scaleAndOffsetProvider.getParallaxOffset());
TileSource src = req.result;
Point wallpaperSize = WallpaperUtils.getDefaultWallpaperSize(
getResources(), getWindowManager());
RectF crop = Utils.getMaxCropRect(src.getImageWidth(), src.getImageHeight(),
wallpaperSize.x, wallpaperSize.y, false /* leftAligned */);
mCropView.setScale(req.scaleAndOffsetProvider.getScale(wallpaperSize, crop));
mCropView.setParallaxOffset(req.scaleAndOffsetProvider.getParallaxOffset(), crop);
}
// Free last image
@@ -443,7 +448,7 @@ public class WallpaperCropActivity extends BaseActivity implements Handler.Callb
}
public interface CropViewScaleAndOffsetProvider {
float getScale(TileSource src);
float getScale(Point wallpaperSize, RectF crop);
float getParallaxOffset();
}
}
@@ -9,6 +9,7 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Point;
import android.graphics.RectF;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
@@ -19,7 +20,6 @@ import com.android.launcher3.LauncherFiles;
import com.android.launcher3.Utilities;
import com.android.launcher3.WallpaperCropActivity.CropViewScaleAndOffsetProvider;
import com.android.launcher3.WallpaperPickerActivity;
import com.android.photos.views.TiledImageRenderer.TileSource;
import java.io.File;
import java.io.FileOutputStream;
@@ -38,7 +38,7 @@ public class DefaultWallpaperInfo extends DrawableThumbWallpaperInfo {
a.setCropViewTileSource(null, false, false, new CropViewScaleAndOffsetProvider() {
@Override
public float getScale(TileSource src) {
public float getScale(Point wallpaperSize, RectF crop) {
return 1f;
}
@@ -4,13 +4,11 @@ import android.content.res.Resources;
import android.graphics.Point;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import com.android.gallery3d.common.Utils;
import com.android.launcher3.WallpaperCropActivity.CropViewScaleAndOffsetProvider;
import com.android.launcher3.WallpaperPickerActivity;
import com.android.launcher3.util.WallpaperUtils;
import com.android.photos.BitmapRegionTileSource;
import com.android.photos.BitmapRegionTileSource.BitmapSource;
import com.android.photos.views.TiledImageRenderer.TileSource;
public class ResourceWallpaperInfo extends DrawableThumbWallpaperInfo {
@@ -28,16 +26,11 @@ public class ResourceWallpaperInfo extends DrawableThumbWallpaperInfo {
a.setWallpaperButtonEnabled(false);
final BitmapRegionTileSource.ResourceBitmapSource bitmapSource =
new BitmapRegionTileSource.ResourceBitmapSource(mResources, mResId, a);
a.setCropViewTileSource(bitmapSource, false, true, new CropViewScaleAndOffsetProvider() {
a.setCropViewTileSource(bitmapSource, false, false, new CropViewScaleAndOffsetProvider() {
@Override
public float getScale(TileSource src) {
Point wallpaperSize = WallpaperUtils.getDefaultWallpaperSize(
a.getResources(), a.getWindowManager());
RectF crop = Utils.getMaxCropRect(
src.getImageWidth(), src.getImageHeight(),
wallpaperSize.x, wallpaperSize.y, false);
return wallpaperSize.x / crop.width();
public float getScale(Point wallpaperSize, RectF crop) {
return wallpaperSize.x /crop.width();
}
@Override