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

Commit a47f4d7c authored by Jorim Jaggi's avatar Jorim Jaggi Committed by Android (Google) Code Review
Browse files

Merge "Position panel dynamically when expanding"

parents 63fc1514 6d4a27fb
Loading
Loading
Loading
Loading
+3 −0
Original line number Original line Diff line number Diff line
@@ -570,4 +570,7 @@
    <!-- Padding to be used on the bottom of the fingerprint icon on Keyguard so it better aligns
    <!-- Padding to be used on the bottom of the fingerprint icon on Keyguard so it better aligns
         with the other icons. -->
         with the other icons. -->
    <dimen name="fingerprint_icon_additional_padding">12dp</dimen>
    <dimen name="fingerprint_icon_additional_padding">12dp</dimen>

    <!-- Minimum margin of the notification panel on the side, when being positioned dynamically -->
    <dimen name="notification_panel_min_side_margin">48dp</dimen>
</resources>
</resources>
+54 −3
Original line number Original line Diff line number Diff line
@@ -187,6 +187,9 @@ public class NotificationPanelView extends PanelView implements
    private boolean mExpansionIsFromHeadsUp;
    private boolean mExpansionIsFromHeadsUp;
    private int mBottomBarHeight;
    private int mBottomBarHeight;
    private boolean mExpandingFromHeadsUp;
    private boolean mExpandingFromHeadsUp;
    private int mPositionMinSideMargin;
    private int mLastOrientation = -1;

    private Runnable mHeadsUpExistenceChangedRunnable = new Runnable() {
    private Runnable mHeadsUpExistenceChangedRunnable = new Runnable() {
        @Override
        @Override
        public void run() {
        public void run() {
@@ -236,6 +239,7 @@ public class NotificationPanelView extends PanelView implements
        mAfforanceHelper = new KeyguardAffordanceHelper(this, getContext());
        mAfforanceHelper = new KeyguardAffordanceHelper(this, getContext());
        mSecureCameraLaunchManager =
        mSecureCameraLaunchManager =
                new SecureCameraLaunchManager(getContext(), mKeyguardBottomArea);
                new SecureCameraLaunchManager(getContext(), mKeyguardBottomArea);
        mLastOrientation = getResources().getConfiguration().orientation;


        // recompute internal state when qspanel height changes
        // recompute internal state when qspanel height changes
        mQsContainer.addOnLayoutChangeListener(new OnLayoutChangeListener() {
        mQsContainer.addOnLayoutChangeListener(new OnLayoutChangeListener() {
@@ -268,6 +272,8 @@ public class NotificationPanelView extends PanelView implements
                getResources().getDimensionPixelSize(R.dimen.notification_scrim_wait_distance);
                getResources().getDimensionPixelSize(R.dimen.notification_scrim_wait_distance);
        mQsFalsingThreshold = getResources().getDimensionPixelSize(
        mQsFalsingThreshold = getResources().getDimensionPixelSize(
                R.dimen.qs_falsing_threshold);
                R.dimen.qs_falsing_threshold);
        mPositionMinSideMargin = getResources().getDimensionPixelSize(
                R.dimen.notification_panel_min_side_margin);
    }
    }


    public void updateResources() {
    public void updateResources() {
@@ -692,6 +698,9 @@ public class NotificationPanelView extends PanelView implements
        if (!mHeadsUpTouchHelper.isTrackingHeadsUp() && handleQSTouch(event)) {
        if (!mHeadsUpTouchHelper.isTrackingHeadsUp() && handleQSTouch(event)) {
            return true;
            return true;
        }
        }
        if (event.getActionMasked() == MotionEvent.ACTION_DOWN && isFullyCollapsed()) {
            updateVerticalPanelPosition(event.getX());
        }
        super.onTouchEvent(event);
        super.onTouchEvent(event);
        return true;
        return true;
    }
    }
@@ -740,7 +749,7 @@ public class NotificationPanelView extends PanelView implements
    }
    }


    private boolean isInQsArea(float x, float y) {
    private boolean isInQsArea(float x, float y) {
        return (x >= mScrollView.getLeft() && x <= mScrollView.getRight()) &&
        return (x >= mScrollView.getX() && x <= mScrollView.getX() + mScrollView.getWidth()) &&
                (y <= mNotificationStackScroller.getBottomMostNotificationBottom()
                (y <= mNotificationStackScroller.getBottomMostNotificationBottom()
                || y <= mQsContainer.getY() + mQsContainer.getHeight());
                || y <= mQsContainer.getY() + mQsContainer.getHeight());
    }
    }
@@ -939,7 +948,7 @@ public class NotificationPanelView extends PanelView implements
            mKeyguardStatusBar.setAlpha(1f);
            mKeyguardStatusBar.setAlpha(1f);
            mKeyguardStatusBar.setVisibility(keyguardShowing ? View.VISIBLE : View.INVISIBLE);
            mKeyguardStatusBar.setVisibility(keyguardShowing ? View.VISIBLE : View.INVISIBLE);
        }
        }

        resetVerticalPanelPosition();
        updateQsState();
        updateQsState();
    }
    }


@@ -1376,7 +1385,7 @@ public class NotificationPanelView extends PanelView implements
            return false;
            return false;
        }
        }
        View header = mKeyguardShowing ? mKeyguardStatusBar : mHeader;
        View header = mKeyguardShowing ? mKeyguardStatusBar : mHeader;
        boolean onHeader = x >= header.getLeft() && x <= header.getRight()
        boolean onHeader = x >= header.getX() && x <= header.getX() + header.getWidth()
                && y >= header.getTop() && y <= header.getBottom();
                && y >= header.getTop() && y <= header.getBottom();
        if (mQsExpanded) {
        if (mQsExpanded) {
            return onHeader || (mScrollView.isScrolledToBottom() && yDiff < 0) && isInQsArea(x, y);
            return onHeader || (mScrollView.isScrolledToBottom() && yDiff < 0) && isInQsArea(x, y);
@@ -1771,6 +1780,10 @@ public class NotificationPanelView extends PanelView implements
    protected void onConfigurationChanged(Configuration newConfig) {
    protected void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        super.onConfigurationChanged(newConfig);
        mAfforanceHelper.onConfigurationChanged();
        mAfforanceHelper.onConfigurationChanged();
        if (newConfig.orientation != mLastOrientation) {
            resetVerticalPanelPosition();
        }
        mLastOrientation = newConfig.orientation;
    }
    }


    @Override
    @Override
@@ -2185,4 +2198,42 @@ public class NotificationPanelView extends PanelView implements
            mExpandingFromHeadsUp = true;
            mExpandingFromHeadsUp = true;
        }
        }
    }
    }

    @Override
    protected void onClosingFinished() {
        super.onClosingFinished();
        resetVerticalPanelPosition();
    }

    /**
     * Updates the vertical position of the panel so it is positioned closer to the touch
     * responsible for opening the panel.
     *
     * @param x the x-coordinate the touch event
     */
    private void updateVerticalPanelPosition(float x) {
        if (mNotificationStackScroller.getWidth() * 1.75f > getWidth()) {
            resetVerticalPanelPosition();
            return;
        }
        float leftMost = mPositionMinSideMargin + mNotificationStackScroller.getWidth() / 2;
        float rightMost = getWidth() - mPositionMinSideMargin
                - mNotificationStackScroller.getWidth() / 2;
        if (Math.abs(x - getWidth() / 2) < mNotificationStackScroller.getWidth() / 4) {
            x = getWidth() / 2;
        }
        x = Math.min(rightMost, Math.max(leftMost, x));
        setVerticalPanelTranslation(x -
                (mNotificationStackScroller.getLeft() + mNotificationStackScroller.getWidth()/2));
     }

    private void resetVerticalPanelPosition() {
        setVerticalPanelTranslation(0f);
    }

    private void setVerticalPanelTranslation(float translation) {
        mNotificationStackScroller.setTranslationX(translation);
        mScrollView.setTranslationX(translation);
        mHeader.setTranslationX(translation);
    }
}
}