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

Commit 8783e44c authored by Selim Cinek's avatar Selim Cinek Committed by Android (Google) Code Review
Browse files

Merge changes from topic "back_redesign" into qt-dev

* changes:
  Rewrote the back arrow animation
  Made back button sample the color and background protect it that way
  Minor adjustments to the edge back gesture
parents 337f8ce4 94bfbab8
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -41,10 +41,16 @@

    <!-- Size of the nav bar edge panels, should be greater to the
         edge sensitivity + the drag threshold -->
    <dimen name="navigation_edge_panel_width">52dp</dimen>
    <dimen name="navigation_edge_panel_height">52dp</dimen>
    <dimen name="navigation_edge_panel_width">76dp</dimen>
    <!-- Padding at the end of the navigation panel to allow the arrow not to be clipped off -->
    <dimen name="navigation_edge_panel_padding">24dp</dimen>
    <dimen name="navigation_edge_panel_height">84dp</dimen>
    <!-- The threshold to drag to trigger the edge action -->
    <dimen name="navigation_edge_action_drag_threshold">16dp</dimen>
    <!-- The minimum display position of the arrow on the screen -->
    <dimen name="navigation_edge_arrow_min_y">64dp</dimen>
    <!-- The amount by which the arrow is shifted to avoid the finger-->
    <dimen name="navigation_edge_finger_offset">48dp</dimen>

    <!-- Luminance threshold to determine black/white contrast for the navigation affordances -->
    <item name="navigation_luminance_threshold" type="dimen" format="float">0.5</item>
+56 −11
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ import android.view.InputMonitor;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.WindowManager;
import android.view.WindowManagerGlobal;
@@ -126,6 +127,12 @@ public class EdgeBackGestureHandler implements DisplayListener {
    private final float mTouchSlop;
    // Minimum distance to move so that is can be considerd as a back swipe
    private final float mSwipeThreshold;
    // The threshold where the touch needs to be at most, such that the arrow is displayed above the
    // finger, otherwise it will be below
    private final int mMinArrowPosition;
    // The amount by which the arrow is shifted to avoid the finger
    private final int mFingerOffset;


    private final int mNavBarHeight;

@@ -147,6 +154,8 @@ public class EdgeBackGestureHandler implements DisplayListener {

    private NavigationBarEdgePanel mEdgePanel;
    private WindowManager.LayoutParams mEdgePanelLp;
    private final Rect mSamplingRect = new Rect();
    private RegionSamplingHelper mRegionSamplingHelper;

    public EdgeBackGestureHandler(Context context, OverviewProxyService overviewProxyService) {
        final Resources res = context.getResources();
@@ -163,6 +172,9 @@ public class EdgeBackGestureHandler implements DisplayListener {
        mSwipeThreshold = res.getDimension(R.dimen.navigation_edge_action_drag_threshold);

        mNavBarHeight = res.getDimensionPixelSize(R.dimen.navigation_bar_frame_height);
        mMinArrowPosition = res.getDimensionPixelSize(
                R.dimen.navigation_edge_arrow_min_y);
        mFingerOffset = res.getDimensionPixelSize(R.dimen.navigation_edge_finger_offset);
    }

    /**
@@ -208,6 +220,8 @@ public class EdgeBackGestureHandler implements DisplayListener {
        if (mEdgePanel != null) {
            mWm.removeView(mEdgePanel);
            mEdgePanel = null;
            mRegionSamplingHelper.stop();
            mRegionSamplingHelper = null;
        }

        if (!mIsEnabled) {
@@ -261,6 +275,18 @@ public class EdgeBackGestureHandler implements DisplayListener {
            mEdgePanelLp.windowAnimations = 0;
            mEdgePanel.setLayoutParams(mEdgePanelLp);
            mWm.addView(mEdgePanel, mEdgePanelLp);
            mRegionSamplingHelper = new RegionSamplingHelper(mEdgePanel,
                    new RegionSamplingHelper.SamplingCallback() {
                        @Override
                        public void onRegionDarknessChanged(boolean isRegionDark) {
                            mEdgePanel.setIsDark(!isRegionDark, true /* animate */);
                        }

                        @Override
                        public Rect getSampledRegion(View sampledView) {
                            return mSamplingRect;
                        }
                    });
        }
    }

@@ -291,7 +317,7 @@ public class EdgeBackGestureHandler implements DisplayListener {
            // Verify if this is in within the touch region and we aren't in immersive mode, and
            // either the bouncer is showing or the notification panel is hidden
            int stateFlags = mOverviewProxyService.getSystemUiStateFlags();
            mIsOnLeftEdge = ev.getX() < mEdgeWidth;
            mIsOnLeftEdge = ev.getX() <= mEdgeWidth;
            mAllowGesture = (stateFlags & SYSUI_STATE_NAV_BAR_HIDDEN) == 0
                    && ((stateFlags & SYSUI_STATE_BOUNCER_SHOWING) == SYSUI_STATE_BOUNCER_SHOWING
                            || (stateFlags & SYSUI_STATE_NOTIFICATION_PANEL_EXPANDED) == 0)
@@ -301,14 +327,13 @@ public class EdgeBackGestureHandler implements DisplayListener {
                        ? (Gravity.LEFT | Gravity.TOP)
                        : (Gravity.RIGHT | Gravity.TOP);
                mEdgePanel.setIsLeftPanel(mIsOnLeftEdge);
                mEdgePanelLp.y = MathUtils.constrain(
                        (int) (ev.getY() - mEdgePanelLp.height / 2),
                        0, mDisplaySize.y);
                mEdgePanel.handleTouch(ev);
                updateEdgePanelPosition(ev.getY());
                mWm.updateViewLayout(mEdgePanel, mEdgePanelLp);
                mRegionSamplingHelper.start(mSamplingRect);

                mDownPoint.set(ev.getX(), ev.getY());
                mThresholdCrossed = false;
                mEdgePanel.handleTouch(ev);
            }
        } else if (mAllowGesture) {
            if (!mThresholdCrossed && ev.getAction() == MotionEvent.ACTION_MOVE) {
@@ -333,12 +358,9 @@ public class EdgeBackGestureHandler implements DisplayListener {
            // forward touch
            mEdgePanel.handleTouch(ev);

            if (ev.getAction() == MotionEvent.ACTION_UP) {
                float xDiff = ev.getX() - mDownPoint.x;
                boolean exceedsThreshold = mIsOnLeftEdge
                        ? (xDiff > mSwipeThreshold) : (-xDiff > mSwipeThreshold);
                boolean performAction = exceedsThreshold
                        && Math.abs(xDiff) > Math.abs(ev.getY() - mDownPoint.y);
            boolean isUp = ev.getAction() == MotionEvent.ACTION_UP;
            if (isUp) {
                boolean performAction = mEdgePanel.shouldTriggerBack();
                if (performAction) {
                    // Perform back
                    sendEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK);
@@ -347,7 +369,30 @@ public class EdgeBackGestureHandler implements DisplayListener {
                mOverviewProxyService.notifyBackAction(performAction, (int) mDownPoint.x,
                        (int) mDownPoint.y, false /* isButton */, !mIsOnLeftEdge);
            }
            if (isUp || ev.getAction() == MotionEvent.ACTION_CANCEL) {
                mRegionSamplingHelper.stop();
            } else {
                updateSamplingRect();
                mRegionSamplingHelper.updateSamplingRect();
            }
        }
    }

    private void updateEdgePanelPosition(float touchY) {
        float position = touchY - mFingerOffset;
        position = Math.max(position, mMinArrowPosition);
        position = (position - mEdgePanelLp.height / 2.0f);
        mEdgePanelLp.y = MathUtils.constrain((int) position, 0, mDisplaySize.y);
        updateSamplingRect();
    }

    private void updateSamplingRect() {
        int top = mEdgePanelLp.y;
        int left = mIsOnLeftEdge ? 0 : mDisplaySize.x - mEdgePanelLp.width;
        int right = left + mEdgePanelLp.width;
        int bottom = top + mEdgePanelLp.height;
        mSamplingRect.set(left, top, right, bottom);
        mEdgePanel.adjustRectToBoundingBox(mSamplingRect);
    }

    @Override