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

Commit c42087e5 authored by Winson Chung's avatar Winson Chung Committed by Android (Google) Code Review
Browse files

Merge changes I33da0d7f,I36c31609 into ub-launcher3-calgary

* changes:
  Working around incorrect wallpaper offsets being calculated in RTL.
  Fixing RTL wallpaper scrolling.
parents fdaa46fb c7d2e83c
Loading
Loading
Loading
Loading
+8 −0
Original line number Original line Diff line number Diff line
@@ -1376,6 +1376,9 @@ public class Launcher extends Activity
        mWorkspace.setHapticFeedbackEnabled(false);
        mWorkspace.setHapticFeedbackEnabled(false);
        mWorkspace.setOnLongClickListener(this);
        mWorkspace.setOnLongClickListener(this);
        mWorkspace.setup(mDragController);
        mWorkspace.setup(mDragController);
        // Until the workspace is bound, ensure that we keep the wallpaper offset locked to the
        // default state, otherwise we will update to the wrong offsets in RTL
        mWorkspace.lockWallpaperToDefaultPage();
        mWorkspace.bindAndInitFirstWorkspaceScreen(null /* recycled qsb */);
        mWorkspace.bindAndInitFirstWorkspaceScreen(null /* recycled qsb */);
        mDragController.addDragListener(mWorkspace);
        mDragController.addDragListener(mWorkspace);


@@ -3679,6 +3682,11 @@ public class Launcher extends Activity
            mWorkspace.createCustomContentContainer();
            mWorkspace.createCustomContentContainer();
            populateCustomContentContainer();
            populateCustomContentContainer();
        }
        }

        // After we have added all the screens, if the wallpaper was locked to the default state,
        // then notify to indicate that it can be released and a proper wallpaper offset can be
        // computed before the next layout
        mWorkspace.unlockWallpaperFromDefaultPageOnNextLayout();
    }
    }


    private void bindAddScreens(ArrayList<Long> orderedScreenIds) {
    private void bindAddScreens(ArrayList<Long> orderedScreenIds) {
+16 −1
Original line number Original line Diff line number Diff line
@@ -90,7 +90,6 @@ import com.android.launcher3.widget.PendingAddWidgetInfo;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashMap;
import java.util.HashSet;
import java.util.HashSet;
import java.util.concurrent.atomic.AtomicInteger;


/**
/**
 * The workspace is a wide area with a wallpaper and a finite number of pages.
 * The workspace is a wide area with a wallpaper and a finite number of pages.
@@ -253,6 +252,7 @@ public class Workspace extends PagedView
    private boolean mWorkspaceFadeInAdjacentScreens;
    private boolean mWorkspaceFadeInAdjacentScreens;


    final WallpaperOffsetInterpolator mWallpaperOffset;
    final WallpaperOffsetInterpolator mWallpaperOffset;
    private boolean mUnlockWallpaperFromDefaultPageOnLayout;


    @Thunk Runnable mDelayedResizeRunnable;
    @Thunk Runnable mDelayedResizeRunnable;
    private Runnable mDelayedSnapToPageRunnable;
    private Runnable mDelayedSnapToPageRunnable;
@@ -1616,6 +1616,17 @@ public class Workspace extends PagedView
        });
        });
    }
    }


    public void lockWallpaperToDefaultPage() {
        mWallpaperOffset.setLockToDefaultPage(true);
    }

    public void unlockWallpaperFromDefaultPageOnNextLayout() {
        if (mWallpaperOffset.isLockedToDefaultPage()) {
            mUnlockWallpaperFromDefaultPageOnLayout = true;
            requestLayout();
        }
    }

    protected void snapToPage(int whichPage, Runnable r) {
    protected void snapToPage(int whichPage, Runnable r) {
        snapToPage(whichPage, SLOW_PAGE_SNAP_ANIMATION_DURATION, r);
        snapToPage(whichPage, SLOW_PAGE_SNAP_ANIMATION_DURATION, r);
    }
    }
@@ -1797,6 +1808,10 @@ public class Workspace extends PagedView


    @Override
    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        if (mUnlockWallpaperFromDefaultPageOnLayout) {
            mWallpaperOffset.setLockToDefaultPage(false);
            mUnlockWallpaperFromDefaultPageOnLayout = false;
        }
        if (mFirstLayout && mCurrentPage >= 0 && mCurrentPage < getChildCount()) {
        if (mFirstLayout && mCurrentPage >= 0 && mCurrentPage < getChildCount()) {
            mWallpaperOffset.syncWithScroll();
            mWallpaperOffset.syncWithScroll();
            mWallpaperOffset.jumpToFinal();
            mWallpaperOffset.jumpToFinal();
+58 −43
Original line number Original line Diff line number Diff line
@@ -18,7 +18,7 @@ public class WallpaperOffsetInterpolator implements Choreographer.FrameCallback
    private static final int ANIMATION_DURATION = 250;
    private static final int ANIMATION_DURATION = 250;


    // Don't use all the wallpaper for parallax until you have at least this many pages
    // Don't use all the wallpaper for parallax until you have at least this many pages
    private static final int MIN_PARALLAX_PAGE_SPAN = 3;
    private static final int MIN_PARALLAX_PAGE_SPAN = 4;


    private final Choreographer mChoreographer;
    private final Choreographer mChoreographer;
    private final Interpolator mInterpolator;
    private final Interpolator mInterpolator;
@@ -33,6 +33,7 @@ public class WallpaperOffsetInterpolator implements Choreographer.FrameCallback
    private float mFinalOffset = 0.0f;
    private float mFinalOffset = 0.0f;
    private float mCurrentOffset = 0.5f; // to force an initial update
    private float mCurrentOffset = 0.5f; // to force an initial update
    private boolean mWaitingForUpdate;
    private boolean mWaitingForUpdate;
    private boolean mLockedToDefaultPage;


    private boolean mAnimating;
    private boolean mAnimating;
    private long mAnimationStartTime;
    private long mAnimationStartTime;
@@ -68,6 +69,17 @@ public class WallpaperOffsetInterpolator implements Choreographer.FrameCallback
        }
        }
    }
    }


    /**
     * Locks the wallpaper offset to the offset in the default state of Launcher.
     */
    public void setLockToDefaultPage(boolean lockToDefaultPage) {
        mLockedToDefaultPage = lockToDefaultPage;
    }

    public boolean isLockedToDefaultPage() {
        return mLockedToDefaultPage;
    }

    public boolean computeScrollOffset() {
    public boolean computeScrollOffset() {
        final float oldOffset = mCurrentOffset;
        final float oldOffset = mCurrentOffset;
        if (mAnimating) {
        if (mAnimating) {
@@ -90,57 +102,60 @@ public class WallpaperOffsetInterpolator implements Choreographer.FrameCallback
        return false;
        return false;
    }
    }


    /**
     * TODO: do different behavior if it's  a live wallpaper?
     */
    public float wallpaperOffsetForScroll(int scroll) {
    public float wallpaperOffsetForScroll(int scroll) {
        // TODO: do different behavior if it's  a live wallpaper?
        // To match the default wallpaper behavior in the system, we default to either the left
        // Don't use up all the wallpaper parallax until you have at least
        // or right edge on initialization
        // MIN_PARALLAX_PAGE_SPAN pages
        int numScrollingPages = getNumScreensExcludingEmptyAndCustom();
        int numScrollingPages = getNumScreensExcludingEmptyAndCustom();
        int parallaxPageSpan;
        if (mLockedToDefaultPage || numScrollingPages <= 1) {
            return mIsRtl ? 1f : 0f;
        }

        // Distribute the wallpaper parallax over a minimum of MIN_PARALLAX_PAGE_SPAN workspace
        // screens, not including the custom screen, and empty screens (if > MIN_PARALLAX_PAGE_SPAN)
        if (mWallpaperIsLiveWallpaper) {
        if (mWallpaperIsLiveWallpaper) {
            parallaxPageSpan = numScrollingPages - 1;
            mNumPagesForWallpaperParallax = numScrollingPages;
        } else {
        } else {
            parallaxPageSpan = Math.max(MIN_PARALLAX_PAGE_SPAN, numScrollingPages - 1);
            mNumPagesForWallpaperParallax = Math.max(MIN_PARALLAX_PAGE_SPAN, numScrollingPages);
        }
        }
        mNumPagesForWallpaperParallax = parallaxPageSpan;


        if (mWorkspace.getChildCount() <= 1) {
        // Offset by the custom screen
        int leftPageIndex;
        int rightPageIndex;
        if (mIsRtl) {
        if (mIsRtl) {
                return 1 - 1.0f/mNumPagesForWallpaperParallax;
            rightPageIndex = mWorkspace.numCustomPages();
            }
            leftPageIndex = rightPageIndex + numScrollingPages - 1;
            return 0;
        } else {
            leftPageIndex = mWorkspace.numCustomPages();
            rightPageIndex = leftPageIndex + numScrollingPages - 1;
        }
        }


        // Exclude the leftmost page
        // Calculate the scroll range
        int emptyExtraPages = numEmptyScreensToIgnore();
        int leftPageScrollX = mWorkspace.getScrollForPage(leftPageIndex);
        int firstIndex = mWorkspace.numCustomPages();
        int rightPageScrollX = mWorkspace.getScrollForPage(rightPageIndex);
        // Exclude the last extra empty screen (if we have > MIN_PARALLAX_PAGE_SPAN pages)
        int scrollRange = rightPageScrollX - leftPageScrollX;
        int lastIndex = mWorkspace.getChildCount() - 1 - emptyExtraPages;
        if (scrollRange == 0) {
        if (mIsRtl) {
            return 0f;
            int temp = firstIndex;
            firstIndex = lastIndex;
            lastIndex = temp;
        }
        }


        int firstPageScrollX = mWorkspace.getScrollForPage(firstIndex);
        int scrollRange = mWorkspace.getScrollForPage(lastIndex) - firstPageScrollX;
        if (scrollRange == 0) {
            return 0;
        } else {
        // Sometimes the left parameter of the pages is animated during a layout transition;
        // Sometimes the left parameter of the pages is animated during a layout transition;
        // this parameter offsets it to keep the wallpaper from animating as well
        // this parameter offsets it to keep the wallpaper from animating as well
            int adjustedScroll =
        int adjustedScroll = scroll - leftPageScrollX -
                    scroll - firstPageScrollX - mWorkspace.getLayoutTransitionOffsetForPage(0);
                mWorkspace.getLayoutTransitionOffsetForPage(0);
            float offset = Math.min(1, adjustedScroll / (float) scrollRange);
        float offset = Utilities.boundToRange((float) adjustedScroll / scrollRange, 0f, 1f);
            offset = Math.max(0, offset);


            // On RTL devices, push the wallpaper offset to the right if we don't have enough
        // The offset is now distributed 0..1 between the left and right pages that we care about,
            // pages (ie if numScrollingPages < MIN_PARALLAX_PAGE_SPAN)
        // so we just map that between the pages that we are using for parallax
            if (!mWallpaperIsLiveWallpaper && numScrollingPages < MIN_PARALLAX_PAGE_SPAN
        float rtlOffset = 0;
                    && mIsRtl) {
        if (mIsRtl) {
                return offset * (parallaxPageSpan - numScrollingPages + 1) / parallaxPageSpan;
            // In RTL, the pages are right aligned, so adjust the offset from the end
            }
            rtlOffset = (float) ((mNumPagesForWallpaperParallax - 1) - (numScrollingPages - 1)) /
            return offset * (numScrollingPages - 1) / parallaxPageSpan;
                    (mNumPagesForWallpaperParallax - 1);
        }
        }
        return rtlOffset + offset *
                ((float) (numScrollingPages - 1) / (mNumPagesForWallpaperParallax - 1));
    }
    }


    private float wallpaperOffsetForCurrentScroll() {
    private float wallpaperOffsetForCurrentScroll() {
@@ -182,7 +197,7 @@ public class WallpaperOffsetInterpolator implements Choreographer.FrameCallback


    private void setWallpaperOffsetSteps() {
    private void setWallpaperOffsetSteps() {
        // Set wallpaper offset steps (1 / (number of screens - 1))
        // Set wallpaper offset steps (1 / (number of screens - 1))
        float xOffset = 1.0f / mNumPagesForWallpaperParallax;
        float xOffset = 1.0f / (mNumPagesForWallpaperParallax - 1);
        if (xOffset != mLastSetWallpaperOffsetSteps) {
        if (xOffset != mLastSetWallpaperOffsetSteps) {
            mWallpaperManager.setWallpaperOffsetSteps(xOffset, 1.0f);
            mWallpaperManager.setWallpaperOffsetSteps(xOffset, 1.0f);
            mLastSetWallpaperOffsetSteps = xOffset;
            mLastSetWallpaperOffsetSteps = xOffset;
@@ -191,7 +206,7 @@ public class WallpaperOffsetInterpolator implements Choreographer.FrameCallback


    public void setFinalX(float x) {
    public void setFinalX(float x) {
        scheduleUpdate();
        scheduleUpdate();
        mFinalOffset = Math.max(0f, Math.min(x, 1.0f));
        mFinalOffset = Math.max(0f, Math.min(x, 1f));
        if (getNumScreensExcludingEmptyAndCustom() != mNumScreens) {
        if (getNumScreensExcludingEmptyAndCustom() != mNumScreens) {
            if (mNumScreens > 0) {
            if (mNumScreens > 0) {
                // Don't animate if we're going from 0 screens
                // Don't animate if we're going from 0 screens