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

Commit dc96d631 authored by Jorim Jaggi's avatar Jorim Jaggi
Browse files

Implement ability to fling to QS in empty space

Bug: 16009808
Change-Id: I0af174a4d97202dae767e4ae56f43599dbee4e05
parent 475b21df
Loading
Loading
Loading
Loading
+57 −7
Original line number Diff line number Diff line
@@ -76,6 +76,12 @@ public class NotificationPanelView extends PanelView implements
    private VelocityTracker mVelocityTracker;
    private boolean mQsTracking;

    /**
     * If set, the ongoing touch gesture might both trigger the expansion in {@link PanelView} and
     * the expansion for quick settings.
     */
    private boolean mConflictingQsExpansionGesture;

    /**
     * Whether we are currently handling a motion gesture in #onInterceptTouchEvent, but haven't
     * intercepted yet.
@@ -423,11 +429,21 @@ public class NotificationPanelView extends PanelView implements

    private void flingQsWithCurrentVelocity() {
        float vel = getCurrentVelocity();
        flingSettings(vel, flingExpandsQs(vel));
    }

        // TODO: Better logic whether we should expand or not.
        flingSettings(vel, vel > 0);
    private boolean flingExpandsQs(float vel) {
        if (Math.abs(vel) < mFlingAnimationUtils.getMinVelocityPxPerSecond()) {
            return getQsExpansionFraction() > 0.5f;
        } else {
            return vel > 0;
        }
    }

    private float getQsExpansionFraction() {
        return (mQsExpansionHeight - mQsMinExpansionHeight)
                / (mQsMaxExpansionHeight - mQsMinExpansionHeight);
    }
    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (mBlockTouches) {
@@ -443,20 +459,48 @@ public class NotificationPanelView extends PanelView implements
                return true;
            }
        }
        if (event.getActionMasked() == MotionEvent.ACTION_DOWN && getExpandedFraction() == 1f
                && mStatusBar.getBarState() != StatusBarState.KEYGUARD) {

            // Down in the empty area while fully expanded - go to QS.
            mQsTracking = true;
            mConflictingQsExpansionGesture = true;
            onQsExpansionStarted();
            mInitialHeightOnTouch = mQsExpansionHeight;
            mInitialTouchY = event.getX();
            mInitialTouchX = event.getY();
        }
        if (mQsTracking || mQsExpanded) {
            return onQsTouch(event);
            onQsTouch(event);
            if (!mConflictingQsExpansionGesture) {
                return true;
            }
        }
        if (event.getActionMasked() == MotionEvent.ACTION_CANCEL
                || event.getActionMasked() == MotionEvent.ACTION_UP) {
            mConflictingQsExpansionGesture = false;
        }

        super.onTouchEvent(event);
        return true;
    }

    @Override
    protected boolean flingExpands(float vel, float vectorVel) {
        boolean expands = super.flingExpands(vel, vectorVel);

        // If we are already running a QS expansion, make sure that we keep the panel open.
        if (mQsExpansionAnimator != null) {
            expands = true;
        }
        return expands;
    }

    @Override
    protected boolean hasConflictingGestures() {
        return mStatusBar.getBarState() != StatusBarState.SHADE;
    }

    private boolean onQsTouch(MotionEvent event) {
    private void onQsTouch(MotionEvent event) {
        int pointerIndex = event.findPointerIndex(mTrackingPointer);
        if (pointerIndex < 0) {
            pointerIndex = 0;
@@ -501,14 +545,17 @@ public class NotificationPanelView extends PanelView implements
                mQsTracking = false;
                mTrackingPointer = -1;
                trackMovement(event);
                float fraction = getQsExpansionFraction();
                if ((fraction != 0f || y >= mInitialTouchY)
                        && (fraction != 1f || y <= mInitialTouchY)) {
                    flingQsWithCurrentVelocity();
                }
                if (mVelocityTracker != null) {
                    mVelocityTracker.recycle();
                    mVelocityTracker = null;
                }
                break;
        }
        return true;
    }

    @Override
@@ -894,6 +941,9 @@ public class NotificationPanelView extends PanelView implements

    @Override
    protected void setOverExpansion(float overExpansion, boolean isPixels) {
        if (mConflictingQsExpansionGesture) {
            return;
        }
        if (mStatusBar.getBarState() != StatusBarState.KEYGUARD) {
            mNotificationStackScroller.setOnHeightChangedListener(null);
            if (isPixels) {
+4 −1
Original line number Diff line number Diff line
@@ -301,6 +301,8 @@ public abstract class PanelView extends FrameLayout {
                mTrackingPointer = -1;
                trackMovement(event);
                if ((mTracking && mTouchSlopExceeded)
                        || Math.abs(x - mInitialTouchX) > mTouchSlop
                        || Math.abs(y - mInitialTouchY) > mTouchSlop
                        || event.getActionMasked() == MotionEvent.ACTION_CANCEL) {
                    float vel = 0f;
                    float vectorVel = 0f;
@@ -317,6 +319,7 @@ public abstract class PanelView extends FrameLayout {
                    boolean expands = onEmptySpaceClick(mInitialTouchX);
                    onTrackingStopped(expands);
                }

                if (mVelocityTracker != null) {
                    mVelocityTracker.recycle();
                    mVelocityTracker = null;
@@ -447,7 +450,7 @@ public abstract class PanelView extends FrameLayout {
     * @param vectorVel the length of the vectorial velocity
     * @return whether a fling should expands the panel; contracts otherwise
     */
    private boolean flingExpands(float vel, float vectorVel) {
    protected boolean flingExpands(float vel, float vectorVel) {
        if (Math.abs(vectorVel) < mFlingAnimationUtils.getMinVelocityPxPerSecond()) {
            return getExpandedFraction() > 0.5f;
        } else {