summaryrefslogtreecommitdiffstats
path: root/WallpaperPicker/src/com/android
diff options
context:
space:
mode:
authorTony Wickham <twickham@google.com>2015-09-03 15:35:29 -0700
committerTony Wickham <twickham@google.com>2015-09-04 12:42:57 -0700
commit8010486e8badc563fdd6e309a5ddba2e1fecfbf5 (patch)
tree7b77b0414f9762ee16ae4e10cb5cd44783011527 /WallpaperPicker/src/com/android
parent01649e348142dd9c4ab81063047e2956dea3729e (diff)
downloadandroid_packages_apps_Trebuchet-8010486e8badc563fdd6e309a5ddba2e1fecfbf5.tar.gz
android_packages_apps_Trebuchet-8010486e8badc563fdd6e309a5ddba2e1fecfbf5.tar.bz2
android_packages_apps_Trebuchet-8010486e8badc563fdd6e309a5ddba2e1fecfbf5.zip
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
Diffstat (limited to 'WallpaperPicker/src/com/android')
-rw-r--r--WallpaperPicker/src/com/android/launcher3/CropView.java4
-rw-r--r--WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java11
-rw-r--r--WallpaperPicker/src/com/android/launcher3/wallpapertileinfo/DefaultWallpaperInfo.java4
-rw-r--r--WallpaperPicker/src/com/android/launcher3/wallpapertileinfo/ResourceWallpaperInfo.java15
4 files changed, 16 insertions, 18 deletions
diff --git a/WallpaperPicker/src/com/android/launcher3/CropView.java b/WallpaperPicker/src/com/android/launcher3/CropView.java
index 0ead365b2..4770a7177 100644
--- a/WallpaperPicker/src/com/android/launcher3/CropView.java
+++ b/WallpaperPicker/src/com/android/launcher3/CropView.java
@@ -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();
}
diff --git a/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java b/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java
index 871eef20c..efa1181ae 100644
--- a/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java
+++ b/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java
@@ -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();
}
}
diff --git a/WallpaperPicker/src/com/android/launcher3/wallpapertileinfo/DefaultWallpaperInfo.java b/WallpaperPicker/src/com/android/launcher3/wallpapertileinfo/DefaultWallpaperInfo.java
index 2b508f1e5..7ede26096 100644
--- a/WallpaperPicker/src/com/android/launcher3/wallpapertileinfo/DefaultWallpaperInfo.java
+++ b/WallpaperPicker/src/com/android/launcher3/wallpapertileinfo/DefaultWallpaperInfo.java
@@ -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;
}
diff --git a/WallpaperPicker/src/com/android/launcher3/wallpapertileinfo/ResourceWallpaperInfo.java b/WallpaperPicker/src/com/android/launcher3/wallpapertileinfo/ResourceWallpaperInfo.java
index 9180c4637..a5becf1e7 100644
--- a/WallpaperPicker/src/com/android/launcher3/wallpapertileinfo/ResourceWallpaperInfo.java
+++ b/WallpaperPicker/src/com/android/launcher3/wallpapertileinfo/ResourceWallpaperInfo.java
@@ -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