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

Commit db1c5d59 authored by Adam Cohen's avatar Adam Cohen
Browse files

Updating UI to new design, widget shouldn't expand until page settles (issue 7467435)

-> If the challenge is showing and the page is swiped, instead of immediately
   sliding down the security and expanding the small widget, we instead
   quickly fade out the security and keep the widget+frame small until
   the page settles and fades out.

Change-Id: I0f376dcd863744b977a1c5ccc7a46a5c6fdb891d
parent 7cefef7c
Loading
Loading
Loading
Loading
+10 −4
Original line number Diff line number Diff line
@@ -76,8 +76,10 @@ public class KeyguardViewStateManager implements SlidingChallengeLayout.OnChalle
    }

    public void onPageBeginMoving() {
        if (mChallengeLayout.isChallengeShowing()) {
            mChallengeLayout.showChallenge(false);
        if (mChallengeLayout.isChallengeShowing() &&
                mChallengeLayout instanceof SlidingChallengeLayout) {
            SlidingChallengeLayout scl = (SlidingChallengeLayout) mChallengeLayout;
            scl.dismissChallengeWithFade();
        }
        if (mHideHintsRunnable != null) {
            mMainQueue.removeCallbacks(mHideHintsRunnable);
@@ -170,7 +172,11 @@ public class KeyguardViewStateManager implements SlidingChallengeLayout.OnChalle
            if (frame == null) return;

            if (!challengeOverlapping) {
                if (!mPagedView.isPageMoving()) {
                    frame.resetSize();
                } else {
                    mPagedView.resetWidgetSizeOnPagesFaded(frame);
                }
            }
            frame.hideFrame(this);

@@ -213,7 +219,7 @@ public class KeyguardViewStateManager implements SlidingChallengeLayout.OnChalle
    public void onScrollPositionChanged(float scrollPosition, int challengeTop) {
        mChallengeTop = challengeTop;
        KeyguardWidgetFrame frame = mPagedView.getWidgetPageAt(mPageListeningToSlider);
        if (frame != null) {
        if (frame != null && !mPagedView.isPageMoving()) {
            frame.adjustFrame(getChallengeTopRelativeToFrame(frame, mChallengeTop));
        }
    }
+3 −2
Original line number Diff line number Diff line
@@ -366,11 +366,12 @@ public class KeyguardWidgetFrame extends FrameLayout {
    }

    public void hideFrame(Object caller) {
        fadeFrame(caller, false, 0f, 150);
        fadeFrame(caller, false, 0f, KeyguardWidgetPager.CHILDREN_OUTLINE_FADE_OUT_DURATION);
    }

    public void showFrame(Object caller) {
        fadeFrame(caller, true, OUTLINE_ALPHA_MULTIPLIER, 150);
        fadeFrame(caller, true, OUTLINE_ALPHA_MULTIPLIER,
                KeyguardWidgetPager.CHILDREN_OUTLINE_FADE_IN_DURATION);
    }

    public void fadeFrame(Object caller, boolean takeControl, float alpha, int duration) {
+16 −2
Original line number Diff line number Diff line
@@ -55,8 +55,8 @@ public class KeyguardWidgetPager extends PagedView implements PagedView.PageSwit
    private LockPatternUtils mLockPatternUtils;

    // Related to the fading in / out background outlines
    private static final int CHILDREN_OUTLINE_FADE_OUT_DURATION = 375;
    private static final int CHILDREN_OUTLINE_FADE_IN_DURATION = 75;
    public static final int CHILDREN_OUTLINE_FADE_OUT_DURATION = 375;
    public static final int CHILDREN_OUTLINE_FADE_IN_DURATION = 100;
    protected AnimatorSet mChildrenOutlineFadeAnimation;
    protected int mScreenCenter;
    private boolean mHasMeasure = false;
@@ -70,6 +70,8 @@ public class KeyguardWidgetPager extends PagedView implements PagedView.PageSwit

    private boolean mCameraWidgetEnabled;

    private KeyguardWidgetFrame mWidgetToResetAfterFadeOut;

    // Background threads to deal with persistence
    private HandlerThread mBgPersistenceWorkerThread;
    private Handler mBgPersistenceWorkerHandler;
@@ -587,6 +589,10 @@ public class KeyguardWidgetPager extends PagedView implements PagedView.PageSwit
        animateOutlinesAndSidePages(show, -1);
    }

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

    void animateOutlinesAndSidePages(final boolean show, int duration) {
        if (mChildrenOutlineFadeAnimation != null) {
            mChildrenOutlineFadeAnimation.cancel();
@@ -632,10 +638,18 @@ public class KeyguardWidgetPager extends PagedView implements PagedView.PageSwit
                    enablePageLayers();
                }
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                if (!show) {
                    disablePageLayers();
                    if (mWidgetToResetAfterFadeOut != null) {
                        if (!(getWidgetPageAt(mCurrentPage) == mWidgetToResetAfterFadeOut &&
                                mViewStateManager.isChallengeShowing())) {
                            mWidgetToResetAfterFadeOut.resetSize();
                        }
                        mWidgetToResetAfterFadeOut = null;
                    }
                }
            }
        });
+65 −7
Original line number Diff line number Diff line
@@ -76,6 +76,7 @@ public class SlidingChallengeLayout extends ViewGroup implements ChallengeLayout
    private boolean mIsBouncing = false;

    private final Scroller mScroller;
    private ObjectAnimator mFader;
    private int mScrollState;
    private OnChallengeScrolledListener mScrollListener;
    private OnBouncerStateChangedListener mBouncerListener;
@@ -83,6 +84,9 @@ public class SlidingChallengeLayout extends ViewGroup implements ChallengeLayout
    public static final int SCROLL_STATE_IDLE = 0;
    public static final int SCROLL_STATE_DRAGGING = 1;
    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 MAX_SETTLE_DURATION = 600; // ms

@@ -122,7 +126,10 @@ public class SlidingChallengeLayout extends ViewGroup implements ChallengeLayout
    private final Rect mTempRect = new Rect();

    private boolean mHasGlowpad;
    private boolean mChallengeInteractive = true;

    // We have an internal and external version, and we and them together.
    private boolean mChallengeInteractiveExternal = true;
    private boolean mChallengeInteractiveInternal = true;

    static final Property<SlidingChallengeLayout, Float> HANDLE_ALPHA =
            new FloatProperty<SlidingChallengeLayout>("handleAlpha") {
@@ -277,7 +284,7 @@ public class SlidingChallengeLayout extends ViewGroup implements ChallengeLayout
    }

    public void setChallengeInteractive(boolean interactive) {
        mChallengeInteractive = interactive;
        mChallengeInteractiveExternal = interactive;
        if (mExpandChallengeView != null) {
            mExpandChallengeView.setEnabled(interactive);
        }
@@ -409,6 +416,7 @@ public class SlidingChallengeLayout extends ViewGroup implements ChallengeLayout
    void completeChallengeScroll() {
        setChallengeShowing(mChallengeOffset != 0);
        setScrollState(SCROLL_STATE_IDLE);
        mChallengeInteractiveInternal = true;
        mChallengeView.setLayerType(LAYER_TYPE_NONE, null);
    }

@@ -433,6 +441,13 @@ public class SlidingChallengeLayout extends ViewGroup implements ChallengeLayout
            // Nothing to do.
            return;
        }

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

        mChallengeInteractiveInternal = false;
        mChallengeView.setLayerType(LAYER_TYPE_HARDWARE, null);
        final int sy = mChallengeView.getBottom();
        final int dy = y - sy;
        if (dy == 0) {
@@ -592,7 +607,7 @@ public class SlidingChallengeLayout extends ViewGroup implements ChallengeLayout
                for (int i = 0; i < count; i++) {
                    final float x = ev.getX(i);
                    final float y = ev.getY(i);
                    if (!mIsBouncing && mChallengeInteractive && mActivePointerId == INVALID_POINTER
                    if (!mIsBouncing && mActivePointerId == INVALID_POINTER
                                && (crossedDragHandle(x, y, mGestureStartY)
                                || (isInChallengeView(x, y) &&
                                        mScrollState == SCROLL_STATE_SETTLING))) {
@@ -609,7 +624,7 @@ public class SlidingChallengeLayout extends ViewGroup implements ChallengeLayout
                break;
        }

        if (mBlockDrag) {
        if (mBlockDrag || isChallengeInteractionBlocked()) {
            mActivePointerId = INVALID_POINTER;
            mDragging = false;
        }
@@ -617,6 +632,10 @@ public class SlidingChallengeLayout extends ViewGroup implements ChallengeLayout
        return mDragging;
    }

    private boolean isChallengeInteractionBlocked() {
        return !mChallengeInteractiveExternal || !mChallengeInteractiveInternal;
    }

    private void resetTouch() {
        mVelocityTracker.recycle();
        mVelocityTracker = null;
@@ -640,7 +659,7 @@ public class SlidingChallengeLayout extends ViewGroup implements ChallengeLayout
                break;

            case MotionEvent.ACTION_CANCEL:
                if (mDragging && mChallengeInteractive) {
                if (mDragging && !isChallengeInteractionBlocked()) {
                    showChallenge(0);
                }
                resetTouch();
@@ -651,7 +670,7 @@ public class SlidingChallengeLayout extends ViewGroup implements ChallengeLayout
                    break;
                }
            case MotionEvent.ACTION_UP:
                if (mDragging && mChallengeInteractive) {
                if (mDragging && !isChallengeInteractionBlocked()) {
                    mVelocityTracker.computeCurrentVelocity(1000, mMaxVelocity);
                    showChallenge((int) mVelocityTracker.getYVelocity(mActivePointerId));
                }
@@ -668,7 +687,7 @@ public class SlidingChallengeLayout extends ViewGroup implements ChallengeLayout
                        if ((isInDragHandle(x, y) || crossedDragHandle(x, y, mGestureStartY) ||
                                (isInChallengeView(x, y) && mScrollState == SCROLL_STATE_SETTLING))
                                && mActivePointerId == INVALID_POINTER
                                && mChallengeInteractive) {
                                && !isChallengeInteractionBlocked()) {
                            mGestureStartX = x;
                            mGestureStartY = y;
                            mActivePointerId = ev.getPointerId(i);
@@ -1045,6 +1064,45 @@ 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) {