Avoids vibration over deadzone in navigationbar

Removed the deadzone as a view and converted to a class that is attached
to NavigationBarView to determine if the incoming touch events should be
consumed by the deadzone.

Change-Id: I5bf6a9e48ba9fa2305ec98acfc537d14cb8cf725
Fixes: 77235132
Test: tap just above the home button in portrait
This commit is contained in:
Matthew Ng
2018-03-30 17:15:39 -07:00
parent 50228a6471
commit 603b3298ff
9 changed files with 57 additions and 84 deletions

View File

@@ -41,16 +41,4 @@
</FrameLayout>
<com.android.systemui.statusbar.policy.DeadZone
android:id="@+id/deadzone"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_gravity="top"
systemui:minSize="@dimen/navigation_bar_deadzone_size"
systemui:maxSize="@dimen/navigation_bar_deadzone_size_max"
systemui:holdTime="@integer/navigation_bar_deadzone_hold"
systemui:decayTime="@integer/navigation_bar_deadzone_decay"
systemui:orientation="horizontal"
/>
</FrameLayout>

View File

@@ -46,16 +46,4 @@
</com.android.systemui.statusbar.phone.NearestTouchFrame>
<com.android.systemui.statusbar.policy.DeadZone
android:id="@+id/deadzone"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_gravity="top"
systemui:minSize="@dimen/navigation_bar_deadzone_size"
systemui:maxSize="@dimen/navigation_bar_deadzone_size_max"
systemui:holdTime="@integer/navigation_bar_deadzone_hold"
systemui:decayTime="@integer/navigation_bar_deadzone_decay"
systemui:orientation="horizontal"
/>
</FrameLayout>

View File

@@ -46,16 +46,4 @@
</com.android.systemui.statusbar.phone.NearestTouchFrame>
<com.android.systemui.statusbar.policy.DeadZone
android:id="@+id/deadzone"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_gravity="top"
systemui:minSize="@dimen/navigation_bar_deadzone_size"
systemui:maxSize="@dimen/navigation_bar_deadzone_size_max"
systemui:holdTime="@integer/navigation_bar_deadzone_hold"
systemui:decayTime="@integer/navigation_bar_deadzone_decay"
systemui:orientation="vertical"
/>
</FrameLayout>

View File

@@ -28,4 +28,7 @@
<!-- We have only space for one notification on phone landscape layouts. -->
<integer name="keyguard_max_notification_count">1</integer>
<!-- orientation of the dead zone when touches have recently occurred elsewhere on screen -->
<integer name="navigation_bar_deadzone_orientation">1</integer>
</resources>

View File

@@ -35,4 +35,7 @@
<!-- Animation duration when using long press on recents to dock -->
<integer name="long_press_dock_anim_duration">290</integer>
<!-- orientation of the dead zone when touches have recently occurred elsewhere on screen -->
<integer name="navigation_bar_deadzone_orientation">0</integer>
</resources>

View File

@@ -93,6 +93,9 @@
<integer name="navigation_bar_deadzone_hold">333</integer>
<integer name="navigation_bar_deadzone_decay">333</integer>
<!-- orientation of the dead zone when touches have recently occurred elsewhere on screen -->
<integer name="navigation_bar_deadzone_orientation">0</integer>
<bool name="config_dead_zone_flash">false</bool>
<!-- Whether to enable dimming navigation buttons when wallpaper is not visible, should be

View File

@@ -124,7 +124,7 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav
private TintedKeyButtonDrawable mRotateSuggestionIcon;
private GestureHelper mGestureHelper;
private DeadZone mDeadZone;
private final DeadZone mDeadZone;
private final NavigationBarTransitions mBarTransitions;
private final OverviewProxyService mOverviewProxyService;
@@ -263,6 +263,7 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav
new ButtonDispatcher(R.id.accessibility_button));
mButtonDispatchers.put(R.id.rotate_suggestion,
new ButtonDispatcher(R.id.rotate_suggestion));
mDeadZone = new DeadZone(this);
}
public BarTransitions getBarTransitions() {
@@ -297,6 +298,10 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
if (mDeadZone.onTouchEvent(event)) {
// Consumed the touch event
return true;
}
switch (event.getActionMasked()) {
case ACTION_DOWN:
int x = (int) event.getX();
@@ -319,6 +324,10 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav
@Override
public boolean onTouchEvent(MotionEvent event) {
if (mDeadZone.onTouchEvent(event)) {
// Consumed the touch event
return true;
}
if (mGestureHelper.onTouchEvent(event)) {
return true;
}
@@ -818,6 +827,7 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav
@Override
protected void onDraw(Canvas canvas) {
mGestureHelper.onDraw(canvas);
mDeadZone.onDraw(canvas);
super.onDraw(canvas);
}
@@ -889,10 +899,8 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav
public void reorient() {
updateCurrentView();
mDeadZone = (DeadZone) mCurrentView.findViewById(R.id.deadzone);
((NavigationBarFrame) getRootView()).setDeadZone(mDeadZone);
mDeadZone.setDisplayRotation(mCurrentRotation);
mDeadZone.onConfigurationChanged(mCurrentRotation);
// force the low profile & disabled states into compliance
mBarTransitions.init();

View File

@@ -199,7 +199,7 @@ public class QuickStepController implements GestureHelper {
break;
}
case MotionEvent.ACTION_MOVE: {
if (mQuickStepStarted || !mAllowGestureDetection){
if (mQuickStepStarted || !mAllowGestureDetection || mHomeButtonView == null){
break;
}
int x = (int) event.getX();

View File

@@ -17,18 +17,16 @@
package com.android.systemui.statusbar.policy;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.content.res.TypedArray;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.os.SystemClock;
import android.util.AttributeSet;
import android.util.Slog;
import android.view.MotionEvent;
import android.view.Surface;
import android.view.View;
import com.android.systemui.R;
import com.android.systemui.SysUiServiceProvider;
import com.android.systemui.statusbar.phone.NavigationBarView;
import com.android.systemui.statusbar.phone.StatusBar;
/**
@@ -38,7 +36,7 @@ import com.android.systemui.statusbar.phone.StatusBar;
* outside the navigation bar (since this is when accidental taps are more likely), then contracts
* back over time (since a later tap might be intended for the top of the bar).
*/
public class DeadZone extends View {
public class DeadZone {
public static final String TAG = "DeadZone";
public static final boolean DEBUG = false;
@@ -47,6 +45,7 @@ public class DeadZone extends View {
private static final boolean CHATTY = true; // print to logcat when we eat a click
private final StatusBar mStatusBar;
private final NavigationBarView mNavigationBarView;
private boolean mShouldFlash;
private float mFlashFrac = 0f;
@@ -67,31 +66,11 @@ public class DeadZone extends View {
}
};
public DeadZone(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public DeadZone(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DeadZone,
defStyle, 0);
mHold = a.getInteger(R.styleable.DeadZone_holdTime, 0);
mDecay = a.getInteger(R.styleable.DeadZone_decayTime, 0);
mSizeMin = a.getDimensionPixelSize(R.styleable.DeadZone_minSize, 0);
mSizeMax = a.getDimensionPixelSize(R.styleable.DeadZone_maxSize, 0);
int index = a.getInt(R.styleable.DeadZone_orientation, -1);
mVertical = (index == VERTICAL);
if (DEBUG)
Slog.v(TAG, this + " size=[" + mSizeMin + "-" + mSizeMax + "] hold=" + mHold
+ (mVertical ? " vertical" : " horizontal"));
setFlashOnTouchCapture(context.getResources().getBoolean(R.bool.config_dead_zone_flash));
mStatusBar = SysUiServiceProvider.getComponent(context, StatusBar.class);
public DeadZone(NavigationBarView view) {
mNavigationBarView = view;
mStatusBar = SysUiServiceProvider.getComponent(mNavigationBarView.getContext(),
StatusBar.class);
onConfigurationChanged(HORIZONTAL);
}
static float lerp(float a, float b, float f) {
@@ -112,11 +91,29 @@ public class DeadZone extends View {
public void setFlashOnTouchCapture(boolean dbg) {
mShouldFlash = dbg;
mFlashFrac = 0f;
postInvalidate();
mNavigationBarView.postInvalidate();
}
public void onConfigurationChanged(int rotation) {
mDisplayRotation = rotation;
final Resources res = mNavigationBarView.getResources();
mHold = res.getInteger(R.integer.navigation_bar_deadzone_hold);
mDecay = res.getInteger(R.integer.navigation_bar_deadzone_decay);
mSizeMin = res.getDimensionPixelSize(R.dimen.navigation_bar_deadzone_size);
mSizeMax = res.getDimensionPixelSize(R.dimen.navigation_bar_deadzone_size_max);
int index = res.getInteger(R.integer.navigation_bar_deadzone_orientation);
mVertical = (index == VERTICAL);
if (DEBUG) {
Slog.v(TAG, this + " size=[" + mSizeMin + "-" + mSizeMax + "] hold=" + mHold
+ (mVertical ? " vertical" : " horizontal"));
}
setFlashOnTouchCapture(res.getBoolean(R.bool.config_dead_zone_flash));
}
// I made you a touch event...
@Override
public boolean onTouchEvent(MotionEvent event) {
if (DEBUG) {
Slog.v(TAG, this + " onTouch: " + MotionEvent.actionToString(event.getAction()));
@@ -143,7 +140,7 @@ public class DeadZone extends View {
final boolean consumeEvent;
if (mVertical) {
if (mDisplayRotation == Surface.ROTATION_270) {
consumeEvent = event.getX() > getWidth() - size;
consumeEvent = event.getX() > mNavigationBarView.getWidth() - size;
} else {
consumeEvent = event.getX() < size;
}
@@ -155,8 +152,8 @@ public class DeadZone extends View {
Slog.v(TAG, "consuming errant click: (" + event.getX() + "," + event.getY() + ")");
}
if (mShouldFlash) {
post(mDebugFlash);
postInvalidate();
mNavigationBarView.post(mDebugFlash);
mNavigationBarView.postInvalidate();
}
return true; // ...but I eated it
}
@@ -168,19 +165,18 @@ public class DeadZone extends View {
mLastPokeTime = event.getEventTime();
if (DEBUG)
Slog.v(TAG, "poked! size=" + getSize(mLastPokeTime));
if (mShouldFlash) postInvalidate();
if (mShouldFlash) mNavigationBarView.postInvalidate();
}
public void setFlash(float f) {
mFlashFrac = f;
postInvalidate();
mNavigationBarView.postInvalidate();
}
public float getFlash() {
return mFlashFrac;
}
@Override
public void onDraw(Canvas can) {
if (!mShouldFlash || mFlashFrac <= 0f) {
return;
@@ -202,10 +198,6 @@ public class DeadZone extends View {
if (DEBUG && size > mSizeMin)
// crazy aggressive redrawing here, for debugging only
postInvalidateDelayed(100);
}
public void setDisplayRotation(int rotation) {
mDisplayRotation = rotation;
mNavigationBarView.postInvalidateDelayed(100);
}
}