Change addParallaxOffset() to setParallaxOffset() in CropView.

This is less prone to error, because calling setParallaxOffset() multiple times
will always lead to the same result. Plus, this works regardless of whether
moveToLeft() was called first.

While the parallax offset ensures that previews of built-in wallpapers match
the actual wallpaper you get upon saving, it does not work in all cases.
Specifically, it does not work for a couple (1 or 2 on the devices I've tested)
of the larger built-in wallpapers. However, this seems to be due to a mismatch
between the size of the preview wallpaper and the actual wallpaper (the latter
is larger). This sounds like a separate bug.

Bug: 23568800
Change-Id: I69afa3f8cc59c77e9c4c25e29e8db8c4beb87462
diff --git a/WallpaperPicker/src/com/android/launcher3/CropView.java b/WallpaperPicker/src/com/android/launcher3/CropView.java
index 34c7084..0ead365 100644
--- a/WallpaperPicker/src/com/android/launcher3/CropView.java
+++ b/WallpaperPicker/src/com/android/launcher3/CropView.java
@@ -27,6 +27,7 @@
 import android.view.ViewConfiguration;
 import android.view.ViewTreeObserver;
 import android.view.ViewTreeObserver.OnGlobalLayoutListener;
+
 import com.android.photos.views.TiledImageRenderer.TileSource;
 import com.android.photos.views.TiledImageView;
 
@@ -192,9 +193,10 @@
      * 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 addParallaxOffset(float offset) {
+    public void setParallaxOffset(float offset) {
         offset = Math.max(0, Math.min(offset, 1)); // Make sure the offset is in the correct range.
-        mCenterX += offset * (getSourceDimensions().x - getWidth() / mRenderer.scale);
+        float screenWidth = getWidth() / mRenderer.scale;
+        mCenterX = screenWidth / 2 + offset * (getSourceDimensions().x - screenWidth);
         updateCenter();
     }
 
diff --git a/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java b/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java
index b3a81ae..871eef2 100644
--- a/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java
+++ b/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java
@@ -251,7 +251,7 @@
             }
             if (req.scaleAndOffsetProvider != null) {
                 mCropView.setScale(req.scaleAndOffsetProvider.getScale(req.result));
-                mCropView.addParallaxOffset(req.scaleAndOffsetProvider.getParallaxOffset());
+                mCropView.setParallaxOffset(req.scaleAndOffsetProvider.getParallaxOffset());
             }
 
             // Free last image