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

Commit 9dc99230 authored by Winson Chung's avatar Winson Chung
Browse files

Deferring zoom out animation until after snapToPage and animateDragViewToOriginalPosition.

- Fixing issue where you can long press a widget to reorder while the challenge is up

Change-Id: I6ef2fa050a5ebc35d1c3e373bb27519580ebe03d
parent 3e31a0dc
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -49,6 +49,13 @@ public class KeyguardViewStateManager implements SlidingChallengeLayout.OnChalle
        mChallengeLayout = layout;
    }

    public boolean isChallengeShowing() {
        if (mChallengeLayout != null) {
            return mChallengeLayout.isChallengeShowing();
        }
        return false;
    }

    public void setSecurityViewContainer(KeyguardSecurityView container) {
        mKeyguardSecurityContainer = container;
    }
+2 −1
Original line number Diff line number Diff line
@@ -510,7 +510,8 @@ public class KeyguardWidgetPager extends PagedView implements PagedView.PageSwit

    @Override
    public boolean onLongClick(View v) {
        if (startReordering()) {
        // Disallow long pressing to reorder if the challenge is showing
        if (!mViewStateManager.isChallengeShowing() && startReordering()) {
            return true;
        }
        return false;
+42 −13
Original line number Diff line number Diff line
@@ -201,9 +201,9 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
    // We use the min scale to determine how much to expand the actually PagedView measured
    // dimensions such that when we are zoomed out, the view is not clipped
    private int REORDERING_DROP_REPOSITION_DURATION = 200;
    protected int REORDERING_REORDER_REPOSITION_DURATION = 350;
    protected int REORDERING_REORDER_REPOSITION_DURATION = 300;
    protected int REORDERING_ZOOM_IN_OUT_DURATION = 250;
    private int REORDERING_SIDE_PAGE_HOVER_TIMEOUT = 500;
    private int REORDERING_SIDE_PAGE_HOVER_TIMEOUT = 300;
    private float REORDERING_SIDE_PAGE_BUFFER_PERCENTAGE = 0.1f;
    private float mMinScale = 1f;
    protected View mDragView;
@@ -215,6 +215,10 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
    // This variable's scope is for the duration of startReordering() and after the zoomIn()
    // animation after endReordering()
    private boolean mIsReordering;
    // The runnable that settles the page after snapToPage and animateDragViewToOriginalPosition
    private int NUM_ANIMATIONS_RUNNING_BEFORE_ZOOM_OUT = 2;
    private int mPostReorderingPreZoomInRemainingAnimationCount;
    private Runnable mPostReorderingPreZoomInRunnable;

    // Edge swiping
    private boolean mOnlyAllowEdgeSwipes = false;
@@ -536,6 +540,8 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
                pageEndMoving();
            }

            onPostReorderingAnimationCompleted();

            // Notify the user when the page changes
            AccessibilityManager accessibilityManager = (AccessibilityManager)
                    getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
@@ -1971,13 +1977,19 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
    }

    // Animate the drag view back to the original position
    void animateChildrenToOriginalPosition() {
    void animateDragViewToOriginalPosition() {
        if (mDragView != null) {
            AnimatorSet anim = new AnimatorSet();
            anim.setDuration(REORDERING_DROP_REPOSITION_DURATION);
            anim.playTogether(
                    ObjectAnimator.ofFloat(mDragView, "translationX", 0f),
                    ObjectAnimator.ofFloat(mDragView, "translationY", 0f));
            anim.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    onPostReorderingAnimationCompleted();
                }
            });
            anim.start();
        }
    }
@@ -2010,6 +2022,16 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
        invalidate();
    }

    private void onPostReorderingAnimationCompleted() {
        // Trigger the callback when reordering has settled
        --mPostReorderingPreZoomInRemainingAnimationCount;
        if (mPostReorderingPreZoomInRunnable != null &&
                mPostReorderingPreZoomInRemainingAnimationCount == 0) {
            mPostReorderingPreZoomInRunnable.run();
            mPostReorderingPreZoomInRunnable = null;
        }
    }

    protected void onEndReordering() {
        mIsReordering = false;
    }
@@ -2047,6 +2069,12 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
        // In that case, we don't want to do anything.
        if (!mReorderingStarted) return;
        mReorderingStarted = false;

        // If we haven't flung-to-delete the current child, then we just animate the drag view
        // back into position
        if (!mIsFlingingToDelete) {
            mPostReorderingPreZoomInRunnable = new Runnable() {
                public void run() {
                    Runnable onCompleteRunnable = new Runnable() {
                        @Override
                        public void run() {
@@ -2054,14 +2082,15 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
                        }
                    };
                    zoomIn(onCompleteRunnable);
                };
            };

        // If we haven't flung-to-delete the current child, then we just animate the drag view
        // back into position
        if (!mIsFlingingToDelete) {
            mPostReorderingPreZoomInRemainingAnimationCount =
                    NUM_ANIMATIONS_RUNNING_BEFORE_ZOOM_OUT;
            // Snap to the current page
            snapToDestination();

            animateChildrenToOriginalPosition();
            snapToPage(indexOfChild(mDragView), 0);
            // Animate the drag view back to the front position
            animateDragViewToOriginalPosition();
        }
    }