summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/SystemUI/shared/src/com/android/systemui/shared/system/NavigationBarCompat.java22
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickStepController.java94
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyButtonView.java14
3 files changed, 88 insertions, 42 deletions
diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/system/NavigationBarCompat.java b/packages/SystemUI/shared/src/com/android/systemui/shared/system/NavigationBarCompat.java
index 79c1cb17d0ef..bff0d9b84616 100644
--- a/packages/SystemUI/shared/src/com/android/systemui/shared/system/NavigationBarCompat.java
+++ b/packages/SystemUI/shared/src/com/android/systemui/shared/system/NavigationBarCompat.java
@@ -17,10 +17,27 @@
package com.android.systemui.shared.system;
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.RetentionPolicy;
+import sun.misc.Resource;
+
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)
@IntDef({HIT_TARGET_NONE, HIT_TARGET_BACK, HIT_TARGET_HOME, HIT_TARGET_OVERVIEW})
public @interface HitTarget{}
@@ -42,7 +59,6 @@ public class NavigationBarCompat {
* Interaction type: whether the gesture to swipe up from the navigation bar will trigger
* launcher to show overview
*/
-
public static final int FLAG_DISABLE_SWIPE_UP = 0x1;
/**
* 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
*/
public static final int FLAG_HIDE_BACK_BUTTON = 0x8;
+
+ private static int convertDpToPixel(float dp){
+ return (int) (dp * Resources.getSystem().getDisplayMetrics().density);
+ }
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickStepController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickStepController.java
index af778045456b..d3790d440687 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickStepController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickStepController.java
@@ -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.TAG_OPS;
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.
@@ -69,6 +73,7 @@ public class QuickStepController implements GestureHelper {
private float mTranslation;
private int mTouchDownX;
private int mTouchDownY;
+ private boolean mDragScrubActive;
private boolean mDragPositive;
private boolean mIsVertical;
private boolean mIsRTL;
@@ -82,7 +87,6 @@ public class QuickStepController implements GestureHelper {
private final Interpolator mQuickScrubEndInterpolator = new DecelerateInterpolator();
private final Rect mTrackRect = new Rect();
private final Paint mTrackPaint = new Paint();
- private final int mScrollTouchSlop;
private final OverviewProxyService mOverviewEventSender;
private final int mTrackThickness;
private final int mTrackPadding;
@@ -115,6 +119,7 @@ public class QuickStepController implements GestureHelper {
@Override
public void onAnimationEnd(Animator animation) {
mQuickScrubActive = false;
+ mDragScrubActive = false;
mTranslation = 0;
mQuickScrubEndAnimator.setCurrentPlayTime(mQuickScrubEndAnimator.getDuration());
mHomeButtonView = null;
@@ -123,7 +128,6 @@ public class QuickStepController implements GestureHelper {
public QuickStepController(Context context) {
mContext = context;
- mScrollTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
mOverviewEventSender = Dependency.get(OverviewProxyService.class);
mTrackThickness = getDimensionPixelSize(mContext, R.dimen.nav_quick_scrub_track_thickness);
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 boolean homePressed = mNavigationBarView.getDownHitTarget() == HIT_TARGET_HOME;
- int action = event.getAction();
- switch (action & MotionEvent.ACTION_MASK) {
+ int action = event.getActionMasked();
+ switch (action) {
case MotionEvent.ACTION_DOWN: {
int x = (int) event.getX();
int y = (int) event.getY();
@@ -206,21 +210,22 @@ public class QuickStepController implements GestureHelper {
int y = (int) event.getY();
int xDiff = Math.abs(x - mTouchDownX);
int yDiff = Math.abs(y - mTouchDownY);
- boolean exceededTouchSlopX = xDiff > mScrollTouchSlop && xDiff > yDiff;
- boolean exceededTouchSlopY = yDiff > mScrollTouchSlop && yDiff > xDiff;
- boolean exceededTouchSlop, exceededPerpendicularTouchSlop;
+
+ boolean exceededScrubTouchSlop, exceededSwipeUpTouchSlop, exceededScrubDragSlop;
int pos, touchDown, offset, trackSize;
if (mIsVertical) {
- exceededTouchSlop = exceededTouchSlopY;
- exceededPerpendicularTouchSlop = exceededTouchSlopX;
+ exceededScrubTouchSlop = yDiff > QUICK_STEP_TOUCH_SLOP_PX && yDiff > xDiff;
+ exceededSwipeUpTouchSlop = xDiff > QUICK_STEP_DRAG_SLOP_PX && xDiff > yDiff;
+ exceededScrubDragSlop = yDiff > QUICK_SCRUB_DRAG_SLOP_PX && yDiff > xDiff;
pos = y;
touchDown = mTouchDownY;
offset = pos - mTrackRect.top;
trackSize = mTrackRect.height();
} else {
- exceededTouchSlop = exceededTouchSlopX;
- exceededPerpendicularTouchSlop = exceededTouchSlopY;
+ exceededScrubTouchSlop = xDiff > QUICK_STEP_TOUCH_SLOP_PX && xDiff > yDiff;
+ exceededSwipeUpTouchSlop = yDiff > QUICK_SCRUB_TOUCH_SLOP_PX && yDiff > xDiff;
+ exceededScrubDragSlop = xDiff > QUICK_SCRUB_DRAG_SLOP_PX && xDiff > yDiff;
pos = x;
touchDown = mTouchDownX;
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
// the parallel direction, decide to start quickscrub. Only one may run.
- if (!mQuickScrubActive && exceededPerpendicularTouchSlop) {
+ if (!mQuickScrubActive && exceededSwipeUpTouchSlop) {
if (mNavigationBarView.isQuickStepSwipeUpEnabled()) {
startQuickStep(event);
}
@@ -244,29 +249,38 @@ public class QuickStepController implements GestureHelper {
offset -= mIsVertical ? mTrackRect.height() : mTrackRect.width();
}
- // Control the button movement
- if (!mQuickScrubActive && exceededTouchSlop) {
- boolean allowDrag = !mDragPositive
- ? offset < 0 && pos < touchDown : offset >= 0 && pos > touchDown;
- if (allowDrag) {
+ final boolean allowDrag = !mDragPositive
+ ? offset < 0 && pos < touchDown : offset >= 0 && pos > touchDown;
+ if (allowDrag) {
+ // Passing the drag slop is for visual feedback and will not initiate anything
+ if (!mDragScrubActive && exceededScrubDragSlop) {
mDownOffset = offset;
+ mDragScrubActive = true;
+ }
+
+ // Passing the drag slop then touch slop will start quick step
+ if (!mQuickScrubActive && exceededScrubTouchSlop) {
homeButton.abortCurrentGesture();
startQuickScrub();
}
}
- if (mQuickScrubActive && (mDragPositive && offset >= 0
+
+ if ((mQuickScrubActive || mDragScrubActive) && (mDragPositive && offset >= 0
|| !mDragPositive && offset <= 0)) {
- float scrubFraction = Utilities.clamp(Math.abs(offset) * 1f / trackSize, 0, 1);
mTranslation = !mDragPositive
- ? Utilities.clamp(offset - mDownOffset, -trackSize, 0)
- : Utilities.clamp(offset - mDownOffset, 0, trackSize);
- try {
- mOverviewEventSender.getProxy().onQuickScrubProgress(scrubFraction);
- if (DEBUG_OVERVIEW_PROXY) {
- Log.d(TAG_OPS, "Quick Scrub Progress:" + scrubFraction);
+ ? Utilities.clamp(offset - mDownOffset, -trackSize, 0)
+ : Utilities.clamp(offset - mDownOffset, 0, trackSize);
+ if (mQuickScrubActive) {
+ float scrubFraction =
+ Utilities.clamp(Math.abs(offset) * 1f / trackSize, 0, 1);
+ try {
+ mOverviewEventSender.getProxy().onQuickScrubProgress(scrubFraction);
+ if (DEBUG_OVERVIEW_PROXY) {
+ Log.d(TAG_OPS, "Quick Scrub Progress:" + scrubFraction);
+ }
+ } catch (RemoteException e) {
+ Log.e(TAG, "Failed to send progress of quick scrub.", e);
}
- } catch (RemoteException e) {
- Log.e(TAG, "Failed to send progress of quick scrub.", e);
}
if (mIsVertical) {
mHomeButtonView.setTranslationY(mTranslation);
@@ -283,7 +297,9 @@ public class QuickStepController implements GestureHelper {
}
// 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);
}
return mQuickScrubActive || mQuickStepStarted;
@@ -370,10 +386,14 @@ public class QuickStepController implements GestureHelper {
mOverviewEventSender.notifyQuickStepStarted();
mNavigationBarView.getHomeButton().abortCurrentGesture();
mHandler.removeCallbacksAndMessages(null);
+
+ if (mDragScrubActive) {
+ animateEnd();
+ }
}
private void startQuickScrub() {
- if (!mQuickScrubActive) {
+ if (!mQuickScrubActive && mDragScrubActive) {
mQuickScrubActive = true;
mLightTrackColor = mContext.getColor(R.color.quick_step_track_background_light);
mDarkTrackColor = mContext.getColor(R.color.quick_step_track_background_dark);
@@ -391,15 +411,17 @@ public class QuickStepController implements GestureHelper {
}
private void endQuickScrub(boolean animate) {
- if (mQuickScrubActive) {
+ if (mQuickScrubActive || mDragScrubActive) {
animateEnd();
- try {
- mOverviewEventSender.getProxy().onQuickScrubEnd();
- if (DEBUG_OVERVIEW_PROXY) {
- Log.d(TAG_OPS, "Quick Scrub End");
+ if (mQuickScrubActive) {
+ try {
+ mOverviewEventSender.getProxy().onQuickScrubEnd();
+ if (DEBUG_OVERVIEW_PROXY) {
+ Log.d(TAG_OPS, "Quick Scrub End");
+ }
+ } catch (RemoteException e) {
+ Log.e(TAG, "Failed to send end of quick scrub.", e);
}
- } catch (RemoteException e) {
- Log.e(TAG, "Failed to send end of quick scrub.", e);
}
}
if (mHomeButtonView != null && !animate) {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyButtonView.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyButtonView.java
index 1c9579d4c4ab..2fed3fca24e5 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyButtonView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyButtonView.java
@@ -55,6 +55,8 @@ import com.android.systemui.statusbar.VibratorHelper;
import static android.view.KeyEvent.KEYCODE_HOME;
import static android.view.accessibility.AccessibilityNodeInfo.ACTION_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 {
private static final String TAG = KeyButtonView.class.getSimpleName();
@@ -63,9 +65,9 @@ public class KeyButtonView extends ImageView implements ButtonInterface {
private int mContentDescriptionRes;
private long mDownTime;
private int mCode;
- private int mTouchSlop;
private int mTouchDownX;
private int mTouchDownY;
+ private boolean mIsVertical;
private boolean mSupportsLongpress = true;
private AudioManager mAudioManager;
private boolean mGestureAborted;
@@ -116,7 +118,6 @@ public class KeyButtonView extends ImageView implements ButtonInterface {
a.recycle();
setClickable(true);
- mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
mRipple = new KeyButtonRipple(context, this);
@@ -236,8 +237,11 @@ public class KeyButtonView extends ImageView implements ButtonInterface {
case MotionEvent.ACTION_MOVE:
x = (int)ev.getRawX();
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) {
// When quick step is enabled, prevent animating the ripple triggered by
// setPressed and decide to run it on touch up
@@ -347,7 +351,7 @@ public class KeyButtonView extends ImageView implements ButtonInterface {
@Override
public void setVertical(boolean vertical) {
- //no op
+ mIsVertical = vertical;
}
}