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

Commit 785f7a59 authored by Tony Wickham's avatar Tony Wickham
Browse files

Previews in the wallpaper picker are offset to match the homescreen parallax.

When "Wallpapers" is selected from the overlay, the current wallpaper parallax
offset is sent to the WallpaperPickerActivity as an Intent extra. The CropView
then uses that offset when previewing new wallpapers to ensure the preview looks
exactly the same as the actual wallpaper will when set.

Note that this fix doesn't seem to work for DefaultWallpaperInfo - that will
come in a future CL.

Bug: 23568800
Change-Id: I41c5bbbfdabfeb4e20d77e9b5804842a03211edf
parent 009a724c
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@ import android.view.ScaleGestureDetector.OnScaleGestureListener;
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;

@@ -189,6 +188,16 @@ public class CropView extends TiledImageView implements OnScaleGestureListener {
    public void onScaleEnd(ScaleGestureDetector detector) {
    }

    /**
     * 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) {
        offset = Math.max(0, Math.min(offset, 1)); // Make sure the offset is in the correct range.
        mCenterX += offset * (getSourceDimensions().x - getWidth() / mRenderer.scale);
        updateCenter();
    }

    public void moveToLeft() {
        if (getWidth() == 0 || getHeight() == 0) {
            final ViewTreeObserver observer = getViewTreeObserver();
+9 −7
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import android.app.Activity;
import android.app.WallpaperManager;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Matrix;
@@ -250,8 +249,9 @@ public class WallpaperCropActivity extends BaseActivity implements Handler.Callb
            if (req.moveToLeft) {
                mCropView.moveToLeft();
            }
            if (req.scaleProvider != null) {
                mCropView.setScale(req.scaleProvider.getScale(req.result));
            if (req.scaleAndOffsetProvider != null) {
                mCropView.setScale(req.scaleAndOffsetProvider.getScale(req.result));
                mCropView.addParallaxOffset(req.scaleAndOffsetProvider.getParallaxOffset());
            }

            // Free last image
@@ -270,13 +270,14 @@ public class WallpaperCropActivity extends BaseActivity implements Handler.Callb

    @TargetApi(Build.VERSION_CODES.KITKAT)
    public final void setCropViewTileSource(BitmapSource bitmapSource, boolean touchEnabled,
            boolean moveToLeft, CropViewScaleProvider scaleProvider, Runnable postExecute) {
            boolean moveToLeft, CropViewScaleAndOffsetProvider scaleAndOffsetProvider,
            Runnable postExecute) {
        final LoadRequest req = new LoadRequest();
        req.moveToLeft = moveToLeft;
        req.src = bitmapSource;
        req.touchEnabled = touchEnabled;
        req.postExecute = postExecute;
        req.scaleProvider = scaleProvider;
        req.scaleAndOffsetProvider = scaleAndOffsetProvider;
        mCurrentLoadRequest = req;

        // Remove any pending requests
@@ -436,12 +437,13 @@ public class WallpaperCropActivity extends BaseActivity implements Handler.Callb
        boolean touchEnabled;
        boolean moveToLeft;
        Runnable postExecute;
        CropViewScaleProvider scaleProvider;
        CropViewScaleAndOffsetProvider scaleAndOffsetProvider;

        TileSource result;
    }

    public interface CropViewScaleProvider {
    public interface CropViewScaleAndOffsetProvider {
        float getScale(TileSource src);
        float getParallaxOffset();
    }
}
+14 −1
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.view.WindowManager;
import android.widget.HorizontalScrollView;
import android.widget.LinearLayout;

import com.android.launcher3.util.Thunk;
import com.android.launcher3.wallpapertileinfo.DefaultWallpaperInfo;
import com.android.launcher3.wallpapertileinfo.FileWallpaperInfo;
@@ -55,6 +56,7 @@ import com.android.launcher3.wallpapertileinfo.ResourceWallpaperInfo;
import com.android.launcher3.wallpapertileinfo.ThirdPartyWallpaperInfo;
import com.android.launcher3.wallpapertileinfo.UriWallpaperInfo;
import com.android.launcher3.wallpapertileinfo.WallpaperTileInfo;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
@@ -65,11 +67,14 @@ public class WallpaperPickerActivity extends WallpaperCropActivity

    public static final int IMAGE_PICK = 5;
    public static final int PICK_WALLPAPER_THIRD_PARTY_ACTIVITY = 6;
    /** An Intent extra used when opening the wallpaper picker from the workspace overlay. */
    public static final String EXTRA_WALLPAPER_OFFSET = "com.android.launcher3.WALLPAPER_OFFSET";
    private static final String TEMP_WALLPAPER_TILES = "TEMP_WALLPAPER_TILES";
    private static final String SELECTED_INDEX = "SELECTED_INDEX";
    private static final int FLAG_POST_DELAY_MILLIS = 200;

    @Thunk View mSelectedTile;
    @Thunk
    View mSelectedTile;

    @Thunk LinearLayout mWallpapersView;
    @Thunk HorizontalScrollView mWallpaperScrollContainer;
@@ -80,6 +85,8 @@ public class WallpaperPickerActivity extends WallpaperCropActivity
    ArrayList<Uri> mTempWallpaperTiles = new ArrayList<Uri>();
    private SavedWallpaperImages mSavedImages;
    @Thunk int mSelectedIndex = -1;
    private float mWallpaperParallaxOffset;

    /**
     * shows the system wallpaper behind the window and hides the {@link #mCropView} if visible
     * @param visible should the system wallpaper be shown
@@ -137,6 +144,8 @@ public class WallpaperPickerActivity extends WallpaperCropActivity
        mWallpaperStrip = findViewById(R.id.wallpaper_strip);
        mCropView.setTouchCallback(new ToggleOnTapCallback(mWallpaperStrip));

        mWallpaperParallaxOffset = getIntent().getFloatExtra(EXTRA_WALLPAPER_OFFSET, 0);

        mWallpapersView = (LinearLayout) findViewById(R.id.wallpaper_list);
        // Populate the saved wallpapers
        mSavedImages = new SavedWallpaperImages(getContext());
@@ -266,6 +275,10 @@ public class WallpaperPickerActivity extends WallpaperCropActivity
        mSetWallpaperButton.setEnabled(enabled);
    }

    public float getWallpaperParallaxOffset() {
        return mWallpaperParallaxOffset;
    }

    public void selectTile(View v) {
        if (mSelectedTile != null) {
            mSelectedTile.setSelected(false);
+7 −2
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@ import android.util.Log;
import com.android.gallery3d.common.BitmapUtils;
import com.android.launcher3.LauncherFiles;
import com.android.launcher3.Utilities;
import com.android.launcher3.WallpaperCropActivity.CropViewScaleProvider;
import com.android.launcher3.WallpaperCropActivity.CropViewScaleAndOffsetProvider;
import com.android.launcher3.WallpaperPickerActivity;
import com.android.photos.views.TiledImageRenderer.TileSource;

@@ -35,12 +35,17 @@ public class DefaultWallpaperInfo extends DrawableThumbWallpaperInfo {

    @Override
    public void onClick(WallpaperPickerActivity a) {
        a.setCropViewTileSource(null, false, false, new CropViewScaleProvider() {
        a.setCropViewTileSource(null, false, false, new CropViewScaleAndOffsetProvider() {

            @Override
            public float getScale(TileSource src) {
                return 1f;
            }

            @Override
            public float getParallaxOffset() {
                return 0;
            }
        }, null);
    }

+7 −3
Original line number Diff line number Diff line
@@ -4,9 +4,8 @@ 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.CropViewScaleProvider;
import com.android.launcher3.WallpaperCropActivity.CropViewScaleAndOffsetProvider;
import com.android.launcher3.WallpaperPickerActivity;
import com.android.launcher3.util.WallpaperUtils;
import com.android.photos.BitmapRegionTileSource;
@@ -29,7 +28,7 @@ public class ResourceWallpaperInfo extends DrawableThumbWallpaperInfo {
        a.setWallpaperButtonEnabled(false);
        final BitmapRegionTileSource.ResourceBitmapSource bitmapSource =
                new BitmapRegionTileSource.ResourceBitmapSource(mResources, mResId, a);
        a.setCropViewTileSource(bitmapSource, false, false, new CropViewScaleProvider() {
        a.setCropViewTileSource(bitmapSource, false, true, new CropViewScaleAndOffsetProvider() {

            @Override
            public float getScale(TileSource src) {
@@ -40,6 +39,11 @@ public class ResourceWallpaperInfo extends DrawableThumbWallpaperInfo {
                        wallpaperSize.x, wallpaperSize.y, false);
                return wallpaperSize.x / crop.width();
            }

            @Override
            public float getParallaxOffset() {
                return a.getWallpaperParallaxOffset();
            }
        }, new Runnable() {

            @Override
Loading