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

Commit 2ce1ddd2 authored by Matthew Ng's avatar Matthew Ng Committed by android-build-merger
Browse files

Merge "Added two touch slops for easier home press (1/3)" into pi-dev

am: e81e6faf

Change-Id: I1e60584781c7ba7dfa2c301f9da2cfd9cad14ae9
parents 19dc30ff e81e6faf
Loading
Loading
Loading
Loading
+21 −1
Original line number Original line Diff line number Diff line
@@ -17,10 +17,27 @@
package com.android.systemui.shared.system;
package com.android.systemui.shared.system;


import android.annotation.IntDef;
import android.annotation.IntDef;
import android.content.Context;
import android.content.res.Resources;
import android.util.DisplayMetrics;

import java.lang.annotation.Retention;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.RetentionPolicy;


import sun.misc.Resource;

public class NavigationBarCompat {
public class NavigationBarCompat {
    /**
     * Touch slopes and thresholds for quick step operations. Drag slop is the point where the
     * home button press/long press over are ignored and will start to drag when exceeded and the
     * touch slop is when the respected operation will occur when exceeded. Touch slop must be
     * larger than the drag slop.
     */
    public static final int QUICK_STEP_DRAG_SLOP_PX = convertDpToPixel(10);
    public static final int QUICK_SCRUB_DRAG_SLOP_PX = convertDpToPixel(20);
    public static final int QUICK_STEP_TOUCH_SLOP_PX = convertDpToPixel(40);
    public static final int QUICK_SCRUB_TOUCH_SLOP_PX = convertDpToPixel(35);

    @Retention(RetentionPolicy.SOURCE)
    @Retention(RetentionPolicy.SOURCE)
    @IntDef({HIT_TARGET_NONE, HIT_TARGET_BACK, HIT_TARGET_HOME, HIT_TARGET_OVERVIEW})
    @IntDef({HIT_TARGET_NONE, HIT_TARGET_BACK, HIT_TARGET_HOME, HIT_TARGET_OVERVIEW})
    public @interface HitTarget{}
    public @interface HitTarget{}
@@ -42,7 +59,6 @@ public class NavigationBarCompat {
     * Interaction type: whether the gesture to swipe up from the navigation bar will trigger
     * Interaction type: whether the gesture to swipe up from the navigation bar will trigger
     * launcher to show overview
     * launcher to show overview
     */
     */

    public static final int FLAG_DISABLE_SWIPE_UP = 0x1;
    public static final int FLAG_DISABLE_SWIPE_UP = 0x1;
    /**
    /**
     * Interaction type: enable quick scrub interaction on the home button
     * Interaction type: enable quick scrub interaction on the home button
@@ -58,4 +74,8 @@ public class NavigationBarCompat {
     * Interaction type: show/hide the back button while this service is connected to launcher
     * Interaction type: show/hide the back button while this service is connected to launcher
     */
     */
    public static final int FLAG_HIDE_BACK_BUTTON = 0x8;
    public static final int FLAG_HIDE_BACK_BUTTON = 0x8;

    private static int convertDpToPixel(float dp){
        return (int) (dp * Resources.getSystem().getDisplayMetrics().density);
    }
}
}
+58 −36
Original line number Original line Diff line number Diff line
@@ -51,6 +51,10 @@ import static android.view.WindowManagerPolicyConstants.NAV_BAR_BOTTOM;
import static com.android.systemui.OverviewProxyService.DEBUG_OVERVIEW_PROXY;
import static com.android.systemui.OverviewProxyService.DEBUG_OVERVIEW_PROXY;
import static com.android.systemui.OverviewProxyService.TAG_OPS;
import static com.android.systemui.OverviewProxyService.TAG_OPS;
import static com.android.systemui.shared.system.NavigationBarCompat.HIT_TARGET_HOME;
import static com.android.systemui.shared.system.NavigationBarCompat.HIT_TARGET_HOME;
import static com.android.systemui.shared.system.NavigationBarCompat.QUICK_SCRUB_DRAG_SLOP_PX;
import static com.android.systemui.shared.system.NavigationBarCompat.QUICK_SCRUB_TOUCH_SLOP_PX;
import static com.android.systemui.shared.system.NavigationBarCompat.QUICK_STEP_DRAG_SLOP_PX;
import static com.android.systemui.shared.system.NavigationBarCompat.QUICK_STEP_TOUCH_SLOP_PX;


/**
/**
 * Class to detect gestures on the navigation bar and implement quick scrub.
 * Class to detect gestures on the navigation bar and implement quick scrub.
@@ -69,6 +73,7 @@ public class QuickStepController implements GestureHelper {
    private float mTranslation;
    private float mTranslation;
    private int mTouchDownX;
    private int mTouchDownX;
    private int mTouchDownY;
    private int mTouchDownY;
    private boolean mDragScrubActive;
    private boolean mDragPositive;
    private boolean mDragPositive;
    private boolean mIsVertical;
    private boolean mIsVertical;
    private boolean mIsRTL;
    private boolean mIsRTL;
@@ -82,7 +87,6 @@ public class QuickStepController implements GestureHelper {
    private final Interpolator mQuickScrubEndInterpolator = new DecelerateInterpolator();
    private final Interpolator mQuickScrubEndInterpolator = new DecelerateInterpolator();
    private final Rect mTrackRect = new Rect();
    private final Rect mTrackRect = new Rect();
    private final Paint mTrackPaint = new Paint();
    private final Paint mTrackPaint = new Paint();
    private final int mScrollTouchSlop;
    private final OverviewProxyService mOverviewEventSender;
    private final OverviewProxyService mOverviewEventSender;
    private final int mTrackThickness;
    private final int mTrackThickness;
    private final int mTrackPadding;
    private final int mTrackPadding;
@@ -115,6 +119,7 @@ public class QuickStepController implements GestureHelper {
        @Override
        @Override
        public void onAnimationEnd(Animator animation) {
        public void onAnimationEnd(Animator animation) {
            mQuickScrubActive = false;
            mQuickScrubActive = false;
            mDragScrubActive = false;
            mTranslation = 0;
            mTranslation = 0;
            mQuickScrubEndAnimator.setCurrentPlayTime(mQuickScrubEndAnimator.getDuration());
            mQuickScrubEndAnimator.setCurrentPlayTime(mQuickScrubEndAnimator.getDuration());
            mHomeButtonView = null;
            mHomeButtonView = null;
@@ -123,7 +128,6 @@ public class QuickStepController implements GestureHelper {


    public QuickStepController(Context context) {
    public QuickStepController(Context context) {
        mContext = context;
        mContext = context;
        mScrollTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
        mOverviewEventSender = Dependency.get(OverviewProxyService.class);
        mOverviewEventSender = Dependency.get(OverviewProxyService.class);
        mTrackThickness = getDimensionPixelSize(mContext, R.dimen.nav_quick_scrub_track_thickness);
        mTrackThickness = getDimensionPixelSize(mContext, R.dimen.nav_quick_scrub_track_thickness);
        mTrackPadding = getDimensionPixelSize(mContext, R.dimen.nav_quick_scrub_track_edge_padding);
        mTrackPadding = getDimensionPixelSize(mContext, R.dimen.nav_quick_scrub_track_edge_padding);
@@ -177,8 +181,8 @@ public class QuickStepController implements GestureHelper {


        final ButtonDispatcher homeButton = mNavigationBarView.getHomeButton();
        final ButtonDispatcher homeButton = mNavigationBarView.getHomeButton();
        final boolean homePressed = mNavigationBarView.getDownHitTarget() == HIT_TARGET_HOME;
        final boolean homePressed = mNavigationBarView.getDownHitTarget() == HIT_TARGET_HOME;
        int action = event.getAction();
        int action = event.getActionMasked();
        switch (action & MotionEvent.ACTION_MASK) {
        switch (action) {
            case MotionEvent.ACTION_DOWN: {
            case MotionEvent.ACTION_DOWN: {
                int x = (int) event.getX();
                int x = (int) event.getX();
                int y = (int) event.getY();
                int y = (int) event.getY();
@@ -206,21 +210,22 @@ public class QuickStepController implements GestureHelper {
                int y = (int) event.getY();
                int y = (int) event.getY();
                int xDiff = Math.abs(x - mTouchDownX);
                int xDiff = Math.abs(x - mTouchDownX);
                int yDiff = Math.abs(y - mTouchDownY);
                int yDiff = Math.abs(y - mTouchDownY);
                boolean exceededTouchSlopX = xDiff > mScrollTouchSlop && xDiff > yDiff;

                boolean exceededTouchSlopY = yDiff > mScrollTouchSlop && yDiff > xDiff;
                boolean exceededScrubTouchSlop, exceededSwipeUpTouchSlop, exceededScrubDragSlop;
                boolean exceededTouchSlop, exceededPerpendicularTouchSlop;
                int pos, touchDown, offset, trackSize;
                int pos, touchDown, offset, trackSize;


                if (mIsVertical) {
                if (mIsVertical) {
                    exceededTouchSlop = exceededTouchSlopY;
                    exceededScrubTouchSlop = yDiff > QUICK_STEP_TOUCH_SLOP_PX && yDiff > xDiff;
                    exceededPerpendicularTouchSlop = exceededTouchSlopX;
                    exceededSwipeUpTouchSlop = xDiff > QUICK_STEP_DRAG_SLOP_PX && xDiff > yDiff;
                    exceededScrubDragSlop = yDiff > QUICK_SCRUB_DRAG_SLOP_PX && yDiff > xDiff;
                    pos = y;
                    pos = y;
                    touchDown = mTouchDownY;
                    touchDown = mTouchDownY;
                    offset = pos - mTrackRect.top;
                    offset = pos - mTrackRect.top;
                    trackSize = mTrackRect.height();
                    trackSize = mTrackRect.height();
                } else {
                } else {
                    exceededTouchSlop = exceededTouchSlopX;
                    exceededScrubTouchSlop = xDiff > QUICK_STEP_TOUCH_SLOP_PX && xDiff > yDiff;
                    exceededPerpendicularTouchSlop = exceededTouchSlopY;
                    exceededSwipeUpTouchSlop = yDiff > QUICK_SCRUB_TOUCH_SLOP_PX && yDiff > xDiff;
                    exceededScrubDragSlop = xDiff > QUICK_SCRUB_DRAG_SLOP_PX && xDiff > yDiff;
                    pos = x;
                    pos = x;
                    touchDown = mTouchDownX;
                    touchDown = mTouchDownX;
                    offset = pos - mTrackRect.left;
                    offset = pos - mTrackRect.left;
@@ -228,7 +233,7 @@ public class QuickStepController implements GestureHelper {
                }
                }
                // Decide to start quickstep if dragging away from the navigation bar, otherwise in
                // Decide to start quickstep if dragging away from the navigation bar, otherwise in
                // the parallel direction, decide to start quickscrub. Only one may run.
                // the parallel direction, decide to start quickscrub. Only one may run.
                if (!mQuickScrubActive && exceededPerpendicularTouchSlop) {
                if (!mQuickScrubActive && exceededSwipeUpTouchSlop) {
                    if (mNavigationBarView.isQuickStepSwipeUpEnabled()) {
                    if (mNavigationBarView.isQuickStepSwipeUpEnabled()) {
                        startQuickStep(event);
                        startQuickStep(event);
                    }
                    }
@@ -244,22 +249,30 @@ public class QuickStepController implements GestureHelper {
                    offset -= mIsVertical ? mTrackRect.height() : mTrackRect.width();
                    offset -= mIsVertical ? mTrackRect.height() : mTrackRect.width();
                }
                }


                // Control the button movement
                final boolean allowDrag = !mDragPositive
                if (!mQuickScrubActive && exceededTouchSlop) {
                    boolean allowDrag = !mDragPositive
                        ? offset < 0 && pos < touchDown : offset >= 0 && pos > touchDown;
                        ? offset < 0 && pos < touchDown : offset >= 0 && pos > touchDown;
                if (allowDrag) {
                if (allowDrag) {
                    // Passing the drag slop is for visual feedback and will not initiate anything
                    if (!mDragScrubActive && exceededScrubDragSlop) {
                        mDownOffset = offset;
                        mDownOffset = offset;
                        mDragScrubActive = true;
                    }

                    // Passing the drag slop then touch slop will start quick step
                    if (!mQuickScrubActive && exceededScrubTouchSlop) {
                        homeButton.abortCurrentGesture();
                        homeButton.abortCurrentGesture();
                        startQuickScrub();
                        startQuickScrub();
                    }
                    }
                }
                }
                if (mQuickScrubActive && (mDragPositive && offset >= 0

                if ((mQuickScrubActive || mDragScrubActive) && (mDragPositive && offset >= 0
                        || !mDragPositive && offset <= 0)) {
                        || !mDragPositive && offset <= 0)) {
                    float scrubFraction = Utilities.clamp(Math.abs(offset) * 1f / trackSize, 0, 1);
                    mTranslation = !mDragPositive
                    mTranslation = !mDragPositive
                            ? Utilities.clamp(offset - mDownOffset, -trackSize, 0)
                            ? Utilities.clamp(offset - mDownOffset, -trackSize, 0)
                            : Utilities.clamp(offset - mDownOffset, 0, trackSize);
                            : Utilities.clamp(offset - mDownOffset, 0, trackSize);
                    if (mQuickScrubActive) {
                        float scrubFraction =
                                Utilities.clamp(Math.abs(offset) * 1f / trackSize, 0, 1);
                        try {
                        try {
                            mOverviewEventSender.getProxy().onQuickScrubProgress(scrubFraction);
                            mOverviewEventSender.getProxy().onQuickScrubProgress(scrubFraction);
                            if (DEBUG_OVERVIEW_PROXY) {
                            if (DEBUG_OVERVIEW_PROXY) {
@@ -268,6 +281,7 @@ public class QuickStepController implements GestureHelper {
                        } catch (RemoteException e) {
                        } catch (RemoteException e) {
                            Log.e(TAG, "Failed to send progress of quick scrub.", e);
                            Log.e(TAG, "Failed to send progress of quick scrub.", e);
                        }
                        }
                    }
                    if (mIsVertical) {
                    if (mIsVertical) {
                        mHomeButtonView.setTranslationY(mTranslation);
                        mHomeButtonView.setTranslationY(mTranslation);
                    } else {
                    } else {
@@ -283,7 +297,9 @@ public class QuickStepController implements GestureHelper {
        }
        }


        // Proxy motion events to launcher if not handled by quick scrub
        // Proxy motion events to launcher if not handled by quick scrub
        if (!mQuickScrubActive && mAllowGestureDetection) {
        // Proxy motion events up/cancel that would be sent after long press on any nav button
        if (!mQuickScrubActive && (mAllowGestureDetection || action == MotionEvent.ACTION_CANCEL
                || action == MotionEvent.ACTION_UP)) {
            proxyMotionEvents(event);
            proxyMotionEvents(event);
        }
        }
        return mQuickScrubActive || mQuickStepStarted;
        return mQuickScrubActive || mQuickStepStarted;
@@ -370,10 +386,14 @@ public class QuickStepController implements GestureHelper {
        mOverviewEventSender.notifyQuickStepStarted();
        mOverviewEventSender.notifyQuickStepStarted();
        mNavigationBarView.getHomeButton().abortCurrentGesture();
        mNavigationBarView.getHomeButton().abortCurrentGesture();
        mHandler.removeCallbacksAndMessages(null);
        mHandler.removeCallbacksAndMessages(null);

        if (mDragScrubActive) {
            animateEnd();
        }
    }
    }


    private void startQuickScrub() {
    private void startQuickScrub() {
        if (!mQuickScrubActive) {
        if (!mQuickScrubActive && mDragScrubActive) {
            mQuickScrubActive = true;
            mQuickScrubActive = true;
            mLightTrackColor = mContext.getColor(R.color.quick_step_track_background_light);
            mLightTrackColor = mContext.getColor(R.color.quick_step_track_background_light);
            mDarkTrackColor = mContext.getColor(R.color.quick_step_track_background_dark);
            mDarkTrackColor = mContext.getColor(R.color.quick_step_track_background_dark);
@@ -391,8 +411,9 @@ public class QuickStepController implements GestureHelper {
    }
    }


    private void endQuickScrub(boolean animate) {
    private void endQuickScrub(boolean animate) {
        if (mQuickScrubActive) {
        if (mQuickScrubActive || mDragScrubActive) {
            animateEnd();
            animateEnd();
            if (mQuickScrubActive) {
                try {
                try {
                    mOverviewEventSender.getProxy().onQuickScrubEnd();
                    mOverviewEventSender.getProxy().onQuickScrubEnd();
                    if (DEBUG_OVERVIEW_PROXY) {
                    if (DEBUG_OVERVIEW_PROXY) {
@@ -402,6 +423,7 @@ public class QuickStepController implements GestureHelper {
                    Log.e(TAG, "Failed to send end of quick scrub.", e);
                    Log.e(TAG, "Failed to send end of quick scrub.", e);
                }
                }
            }
            }
        }
        if (mHomeButtonView != null && !animate) {
        if (mHomeButtonView != null && !animate) {
            mQuickScrubEndAnimator.end();
            mQuickScrubEndAnimator.end();
        }
        }
+9 −5
Original line number Original line Diff line number Diff line
@@ -55,6 +55,8 @@ import com.android.systemui.statusbar.VibratorHelper;
import static android.view.KeyEvent.KEYCODE_HOME;
import static android.view.KeyEvent.KEYCODE_HOME;
import static android.view.accessibility.AccessibilityNodeInfo.ACTION_CLICK;
import static android.view.accessibility.AccessibilityNodeInfo.ACTION_CLICK;
import static android.view.accessibility.AccessibilityNodeInfo.ACTION_LONG_CLICK;
import static android.view.accessibility.AccessibilityNodeInfo.ACTION_LONG_CLICK;
import static com.android.systemui.shared.system.NavigationBarCompat.QUICK_SCRUB_TOUCH_SLOP_PX;
import static com.android.systemui.shared.system.NavigationBarCompat.QUICK_STEP_TOUCH_SLOP_PX;


public class KeyButtonView extends ImageView implements ButtonInterface {
public class KeyButtonView extends ImageView implements ButtonInterface {
    private static final String TAG = KeyButtonView.class.getSimpleName();
    private static final String TAG = KeyButtonView.class.getSimpleName();
@@ -63,9 +65,9 @@ public class KeyButtonView extends ImageView implements ButtonInterface {
    private int mContentDescriptionRes;
    private int mContentDescriptionRes;
    private long mDownTime;
    private long mDownTime;
    private int mCode;
    private int mCode;
    private int mTouchSlop;
    private int mTouchDownX;
    private int mTouchDownX;
    private int mTouchDownY;
    private int mTouchDownY;
    private boolean mIsVertical;
    private boolean mSupportsLongpress = true;
    private boolean mSupportsLongpress = true;
    private AudioManager mAudioManager;
    private AudioManager mAudioManager;
    private boolean mGestureAborted;
    private boolean mGestureAborted;
@@ -116,7 +118,6 @@ public class KeyButtonView extends ImageView implements ButtonInterface {
        a.recycle();
        a.recycle();


        setClickable(true);
        setClickable(true);
        mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
        mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
        mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);


        mRipple = new KeyButtonRipple(context, this);
        mRipple = new KeyButtonRipple(context, this);
@@ -236,8 +237,11 @@ public class KeyButtonView extends ImageView implements ButtonInterface {
            case MotionEvent.ACTION_MOVE:
            case MotionEvent.ACTION_MOVE:
                x = (int)ev.getRawX();
                x = (int)ev.getRawX();
                y = (int)ev.getRawY();
                y = (int)ev.getRawY();
                boolean exceededTouchSlopX = Math.abs(x - mTouchDownX) > mTouchSlop;

                boolean exceededTouchSlopY = Math.abs(y - mTouchDownY) > mTouchSlop;
                boolean exceededTouchSlopX = Math.abs(x - mTouchDownX) >
                        (mIsVertical ? QUICK_SCRUB_TOUCH_SLOP_PX : QUICK_STEP_TOUCH_SLOP_PX);
                boolean exceededTouchSlopY = Math.abs(y - mTouchDownY) >
                        (mIsVertical ? QUICK_STEP_TOUCH_SLOP_PX : QUICK_SCRUB_TOUCH_SLOP_PX);
                if (exceededTouchSlopX || exceededTouchSlopY) {
                if (exceededTouchSlopX || exceededTouchSlopY) {
                    // When quick step is enabled, prevent animating the ripple triggered by
                    // When quick step is enabled, prevent animating the ripple triggered by
                    // setPressed and decide to run it on touch up
                    // setPressed and decide to run it on touch up
@@ -347,7 +351,7 @@ public class KeyButtonView extends ImageView implements ButtonInterface {


    @Override
    @Override
    public void setVertical(boolean vertical) {
    public void setVertical(boolean vertical) {
        //no op
        mIsVertical = vertical;
    }
    }
}
}