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

Commit 09f17b79 authored by Selim Cinek's avatar Selim Cinek
Browse files

Minor adjustments to the edge back gesture

The arrow now comes out a bit above the finger
instead of right on it. This is also a preparation
for a larger back arrow redesign

Bug: 130682266
Test: atest SystemUITests
Change-Id: I58c80fc939934b185929f9b0245999ec0902d652
parent 07806b3d
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -45,6 +45,10 @@
    <dimen name="navigation_edge_panel_height">52dp</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>
+18 −4
Original line number Diff line number Diff line
@@ -126,6 +126,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;

@@ -163,6 +169,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);
    }

    /**
@@ -291,7 +300,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,9 +310,7 @@ 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);
                mEdgePanelLp.y = positionEdgePanelonDown(ev.getY());
                mWm.updateViewLayout(mEdgePanel, mEdgePanelLp);

                mDownPoint.set(ev.getX(), ev.getY());
@@ -350,6 +357,13 @@ public class EdgeBackGestureHandler implements DisplayListener {
        }
    }

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

    @Override
    public void onDisplayAdded(int displayId) { }

+43 −6
Original line number Diff line number Diff line
@@ -24,10 +24,12 @@ import android.os.SystemClock;
import android.os.VibrationEffect;
import android.util.FloatProperty;
import android.util.MathUtils;
import android.view.ContextThemeWrapper;
import android.view.HapticFeedbackConstants;
import android.view.MotionEvent;
import android.view.View;

import com.android.settingslib.Utils;
import com.android.systemui.Dependency;
import com.android.systemui.R;
import com.android.systemui.statusbar.VibratorHelper;
@@ -35,9 +37,6 @@ import com.android.systemui.statusbar.VibratorHelper;
public class NavigationBarEdgePanel extends View {

    // TODO: read from resources once drawing is finalized.
    private static final boolean SHOW_PROTECTION_STROKE = true;
    private static final int PROTECTION_COLOR = 0xffc0c0c0;
    private static final int STROKE_COLOR = 0xffe5e5e5;
    private static final int PROTECTION_WIDTH_PX = 4;
    private static final int BASE_EXTENT = 32;
    private static final int ARROW_HEIGHT_DP = 32;
@@ -65,6 +64,15 @@ public class NavigationBarEdgePanel extends View {

    private final float mSwipeThreshold;

    private boolean mIsDark = false;
    private boolean mShowProtection = false;
    private int mProtectionColorLight;
    private int mArrowColorLight;
    private int mProtectionColorDark;
    private int mArrowColorDark;
    private int mProtectionColor;
    private int mArrowColor;

    private boolean mIsLeftPanel;

    private float mStartX;
@@ -128,14 +136,13 @@ public class NavigationBarEdgePanel extends View {

        mPaint.setStrokeWidth(mStrokeThickness);
        mPaint.setStrokeCap(Paint.Cap.ROUND);
        mPaint.setColor(STROKE_COLOR);
        mPaint.setAntiAlias(true);

        mProtectionPaint.setStrokeWidth(mStrokeThickness + PROTECTION_WIDTH_PX);
        mProtectionPaint.setStrokeCap(Paint.Cap.ROUND);
        mProtectionPaint.setColor(PROTECTION_COLOR);
        mProtectionPaint.setAntiAlias(true);

        loadColors(context);
        // Both panels arrow point the same way
        mArrowsPointLeft = getLayoutDirection() == LAYOUT_DIRECTION_LTR;

@@ -144,6 +151,36 @@ public class NavigationBarEdgePanel extends View {
        setVisibility(GONE);
    }

    private void loadColors(Context context) {
        final int dualToneDarkTheme = Utils.getThemeAttr(context, R.attr.darkIconTheme);
        final int dualToneLightTheme = Utils.getThemeAttr(context, R.attr.lightIconTheme);
        Context lightContext = new ContextThemeWrapper(context, dualToneLightTheme);
        Context darkContext = new ContextThemeWrapper(context, dualToneDarkTheme);
        mArrowColorLight = Utils.getColorAttrDefaultColor(lightContext, R.attr.singleToneColor);
        mArrowColorDark = Utils.getColorAttrDefaultColor(darkContext, R.attr.singleToneColor);
        mProtectionColorDark = mArrowColorLight;
        mProtectionColorLight = mArrowColorDark;
        updateIsDark(false /* animate */);
    }

    private void updateIsDark(boolean animate) {
        mArrowColor = mIsDark ? mArrowColorDark : mArrowColorLight;
        mProtectionColor = mIsDark ? mProtectionColorDark : mProtectionColorLight;
        mProtectionPaint.setColor(mProtectionColor);
        mPaint.setColor(mArrowColor);
        // TODO: add animation
    }

    public void setIsDark(boolean isDark, boolean animate) {
        mIsDark = isDark;
        updateIsDark(animate);
    }

    public void setShowProtection(boolean showProtection) {
        mShowProtection = showProtection;
        invalidate();
    }

    public void setIsLeftPanel(boolean isLeftPanel) {
        mIsLeftPanel = isLeftPanel;
    }
@@ -160,7 +197,7 @@ public class NavigationBarEdgePanel extends View {
        float outsideX = mArrowsPointLeft ? animatedOffset : 0;
        float middleX = mArrowsPointLeft ? 0 : animatedOffset;

        if (SHOW_PROTECTION_STROKE) {
        if (mShowProtection) {
            canvas.drawLine(outsideX, 0, middleX, mHeight * 0.5f, mProtectionPaint);
            canvas.drawLine(middleX, mHeight * 0.5f, outsideX, mHeight, mProtectionPaint);
        }