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

Commit 8caabadd authored by Adam Cohen's avatar Adam Cohen
Browse files

Making challenge come back if within the same gesture you return to the...

Making challenge come back if within the same gesture you return to the original page (issue 7422999)

Change-Id: I8ada54ca39ebebc15295f93a2d9029f3b7915acb
parent 7f6bb6e4
Loading
Loading
Loading
Loading
+31 −16
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ public class KeyguardViewStateManager implements SlidingChallengeLayout.OnChalle
    // Paged view state
    private int mPageListeningToSlider = -1;
    private int mCurrentPage = -1;
    private int mPageIndexOnPageBeginMoving = -1;

    int mChallengeTop = 0;

@@ -87,11 +88,24 @@ public class KeyguardViewStateManager implements SlidingChallengeLayout.OnChalle
        mKeyguardSecurityContainer = container;
    }

    public void showBouncer(boolean show) {
        mChallengeLayout.showBouncer();
    }

    public void fadeOutSecurity(int duration) {
        ((View) mKeyguardSecurityContainer).animate().alpha(0).setDuration(duration);
    }

    public void fadeInSecurity(int duration) {
        ((View) mKeyguardSecurityContainer).animate().alpha(1f).setDuration(duration);
    }

    public void onPageBeginMoving() {
        if (mChallengeLayout.isChallengeShowing() &&
        if (mChallengeLayout.isChallengeOverlapping() &&
                mChallengeLayout instanceof SlidingChallengeLayout) {
            SlidingChallengeLayout scl = (SlidingChallengeLayout) mChallengeLayout;
            scl.dismissChallengeWithFade();
            scl.fadeOutChallenge();
            mPageIndexOnPageBeginMoving = mKeyguardWidgetPager.getCurrentPage();
        }
        if (mHideHintsRunnable != null) {
            mMainQueue.removeCallbacks(mHideHintsRunnable);
@@ -100,18 +114,7 @@ public class KeyguardViewStateManager implements SlidingChallengeLayout.OnChalle
    }

    public void onPageEndMoving() {
    }

    public void showBouncer(boolean show) {
        mChallengeLayout.showBouncer();
    }

    public void fadeOutSecurity(int duration) {
        ((View) mKeyguardSecurityContainer).animate().alpha(0).setDuration(duration);
    }

    public void fadeInSecurity(int duration) {
        ((View) mKeyguardSecurityContainer).animate().alpha(1f).setDuration(duration);
        mPageIndexOnPageBeginMoving = -1;
    }

    public void onPageSwitching(View newPage, int newPageIndex) {
@@ -119,6 +122,16 @@ public class KeyguardViewStateManager implements SlidingChallengeLayout.OnChalle
            boolean isCameraPage = newPage instanceof CameraWidgetFrame;
            ((SlidingChallengeLayout) mChallengeLayout).setChallengeInteractive(!isCameraPage);
        }

        // If the page we're settling to is the same as we started on, and the action of
        // moving the page hid the security, we restore it immediately.
        if (mPageIndexOnPageBeginMoving == mKeyguardWidgetPager.getNextPage() &&
                mChallengeLayout instanceof SlidingChallengeLayout) {
            SlidingChallengeLayout scl = (SlidingChallengeLayout) mChallengeLayout;
            scl.fadeInChallenge();
            mKeyguardWidgetPager.setWidgetToResetOnPageFadeOut(-1);
        }
        mPageIndexOnPageBeginMoving = -1;
    }

    public void onPageSwitched(View newPage, int newPageIndex) {
@@ -131,7 +144,8 @@ public class KeyguardViewStateManager implements SlidingChallengeLayout.OnChalle

        if (mKeyguardWidgetPager != null && mChallengeLayout != null) {
            KeyguardWidgetFrame prevPage = mKeyguardWidgetPager.getWidgetPageAt(mCurrentPage);
            if (prevPage != null && mCurrentPage != mPageListeningToSlider) {
            if (prevPage != null && mCurrentPage != mPageListeningToSlider && mCurrentPage
                    != mKeyguardWidgetPager.getWidgetToResetOnPageFadeOut()) {
                prevPage.resetSize();
            }

@@ -142,6 +156,7 @@ public class KeyguardViewStateManager implements SlidingChallengeLayout.OnChalle
                newCurPage.shrinkWidget();
            }
        }

        mCurrentPage = newPageIndex;
    }

@@ -187,7 +202,7 @@ public class KeyguardViewStateManager implements SlidingChallengeLayout.OnChalle
                if (!mKeyguardWidgetPager.isPageMoving()) {
                    frame.resetSize();
                } else {
                    mKeyguardWidgetPager.resetWidgetSizeOnPagesFaded(frame);
                    mKeyguardWidgetPager.setWidgetToResetOnPageFadeOut(mPageListeningToSlider);
                }
            }
            frame.hideFrame(this);
+11 −8
Original line number Diff line number Diff line
@@ -70,7 +70,7 @@ public class KeyguardWidgetPager extends PagedView implements PagedView.PageSwit

    private boolean mCameraWidgetEnabled;

    private KeyguardWidgetFrame mWidgetToResetAfterFadeOut;
    private int mWidgetToResetAfterFadeOut;

    // Background worker thread: used here for persistence, also made available to widget frames
    private final HandlerThread mBackgroundWorkerThread;
@@ -594,10 +594,14 @@ public class KeyguardWidgetPager extends PagedView implements PagedView.PageSwit
        animateOutlinesAndSidePages(show, -1);
    }

    public void resetWidgetSizeOnPagesFaded(KeyguardWidgetFrame widget) {
    public void setWidgetToResetOnPageFadeOut(int widget) {
        mWidgetToResetAfterFadeOut = widget;
    }

    public int getWidgetToResetOnPageFadeOut() {
        return mWidgetToResetAfterFadeOut;
    }

    void animateOutlinesAndSidePages(final boolean show, int duration) {
        if (mChildrenOutlineFadeAnimation != null) {
            mChildrenOutlineFadeAnimation.cancel();
@@ -648,13 +652,12 @@ public class KeyguardWidgetPager extends PagedView implements PagedView.PageSwit
            public void onAnimationEnd(Animator animation) {
                if (!show) {
                    disablePageContentLayers();
                    if (mWidgetToResetAfterFadeOut != null) {
                        if (!(getWidgetPageAt(mCurrentPage) == mWidgetToResetAfterFadeOut &&
                                mViewStateManager.isChallengeShowing())) {
                            mWidgetToResetAfterFadeOut.resetSize();
                        }
                        mWidgetToResetAfterFadeOut = null;
                    KeyguardWidgetFrame frame = getWidgetPageAt(mWidgetToResetAfterFadeOut);
                    if (frame != null && !(frame == getWidgetPageAt(mCurrentPage) &&
                            mViewStateManager.isChallengeOverlapping())) {
                        frame.resetSize();
                    }
                    mWidgetToResetAfterFadeOut = -1;
                }
            }
        });
+82 −45
Original line number Diff line number Diff line
@@ -86,7 +86,8 @@ public class SlidingChallengeLayout extends ViewGroup implements ChallengeLayout
    public static final int SCROLL_STATE_SETTLING = 2;
    public static final int SCROLL_STATE_FADING = 3;

    private static final int CHALLENGE_FADE_DURATION = 70;
    private static final int CHALLENGE_FADE_OUT_DURATION = 100;
    private static final int CHALLENGE_FADE_IN_DURATION = 160;

    private static final int MAX_SETTLE_DURATION = 600; // ms

@@ -442,9 +443,7 @@ public class SlidingChallengeLayout extends ViewGroup implements ChallengeLayout
            return;
        }

        if (mFader != null) {
            mFader.cancel();
        }
        cancelTransitionsInProgress();

        mChallengeInteractiveInternal = false;
        mChallengeView.setLayerType(LAYER_TYPE_HARDWARE, null);
@@ -984,6 +983,83 @@ public class SlidingChallengeLayout extends ViewGroup implements ChallengeLayout
        }
    }

    private void cancelTransitionsInProgress() {
        if (!mScroller.isFinished()) {
            mScroller.abortAnimation();
            completeChallengeScroll();
        }
        if (mFader != null) {
            mFader.cancel();
        }
    }

    public void fadeInChallenge() {
        fadeChallenge(true);
    }

    public void fadeOutChallenge() {
        fadeChallenge(false);
    }

    public void fadeChallenge(final boolean show) {
        if (mChallengeView != null) {

            cancelTransitionsInProgress();
            float alpha = show ? 1f : 0f;
            int duration = show ? CHALLENGE_FADE_IN_DURATION : CHALLENGE_FADE_OUT_DURATION;
            mFader = ObjectAnimator.ofFloat(mChallengeView, "alpha", alpha);
            mFader.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationStart(Animator animation) {
                    onFadeStart(show);
                }
                @Override
                public void onAnimationEnd(Animator animation) {
                    onFadeEnd(show);
                }
            });
            mFader.setDuration(duration);
            mFader.start();
        }
    }

    private int getMaxChallengeBottom() {
        if (mChallengeView == null) return 0;
        final int layoutBottom = getLayoutBottom();
        final int challengeHeight = mChallengeView.getMeasuredHeight();

        return (layoutBottom + challengeHeight - mChallengeBottomBound);
    }

    private int getMinChallengeBottom() {
        return getLayoutBottom();
    }


    private void onFadeStart(boolean show) {
        mChallengeInteractiveInternal = false;
        mChallengeView.setLayerType(LAYER_TYPE_HARDWARE, null);

        if (show) {
            moveChallengeTo(getMinChallengeBottom());
        }

        setScrollState(SCROLL_STATE_FADING);
    }

    private void onFadeEnd(boolean show) {
        mChallengeInteractiveInternal = true;
        setChallengeShowing(show);

        if (!show) {
            moveChallengeTo(getMaxChallengeBottom());
        }

        mChallengeView.setLayerType(LAYER_TYPE_NONE, null);
        mFader = null;
        setScrollState(SCROLL_STATE_IDLE);
    }

    public int getMaxChallengeTop() {
        if (mChallengeView == null) return 0;

@@ -1009,8 +1085,8 @@ public class SlidingChallengeLayout extends ViewGroup implements ChallengeLayout
        final int layoutBottom = getLayoutBottom();
        final int challengeHeight = mChallengeView.getHeight();

        bottom = Math.max(layoutBottom,
                Math.min(bottom, layoutBottom + challengeHeight - mChallengeBottomBound));
        bottom = Math.max(getMinChallengeBottom(),
                Math.min(bottom, getMaxChallengeBottom()));

        float offset = 1.f - (float) (bottom - layoutBottom) /
                (challengeHeight - mChallengeBottomBound);
@@ -1064,45 +1140,6 @@ public class SlidingChallengeLayout extends ViewGroup implements ChallengeLayout
        }
    }

    public void dismissChallengeWithFade() {
        if (mChallengeView != null) {
            if (!mScroller.isFinished()) {
                mScroller.abortAnimation();
                completeChallengeScroll();
            }

            mFader = ObjectAnimator.ofFloat(mChallengeView, "alpha", 0f);
            mFader.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationStart(Animator animation) {
                    onFadeStart();
                }
                @Override
                public void onAnimationEnd(Animator animation) {
                    onFadeEnd();
                }
            });
            mFader.setDuration(CHALLENGE_FADE_DURATION);
            mFader.start();
        }
    }

    private void onFadeStart() {
        mChallengeInteractiveInternal = false;
        mChallengeView.setLayerType(LAYER_TYPE_HARDWARE, null);
        setScrollState(SCROLL_STATE_FADING);
    }

    private void onFadeEnd() {
        mChallengeInteractiveInternal = true;
        setChallengeShowing(false);
        moveChallengeTo(getLayoutBottom() + mChallengeView.getMeasuredHeight());
        mChallengeView.setAlpha(1f);
        mChallengeView.setLayerType(LAYER_TYPE_NONE, null);
        mFader = null;
        setScrollState(SCROLL_STATE_IDLE);
    }

    private void showChallenge(int velocity) {
        boolean show = false;
        if (Math.abs(velocity) > mMinVelocity) {