diff options
| author | Adrian Roos <roosa@google.com> | 2019-08-06 16:43:31 +0200 |
|---|---|---|
| committer | Adrian Roos <roosa@google.com> | 2019-08-07 15:09:26 +0200 |
| commit | 7c7898e74f077455864891b869d5ddd62e99e5ef (patch) | |
| tree | fc0de049864f319e6d6455a2b55b35d3b5ed12d4 /core/java/android | |
| parent | 33c07d1c382b7e4a61fb48ce981944b255bfdbb5 (diff) | |
GestureNav: Fix AbsSeekBar thumb exclusion
Fix two issues that caused the exclusion for SeekBar thumbs to be to small and offset
from the thumb:
Account for padding and thumb offset; the thumb drawable is drawn with an offset
from the View's Canvas; the same offset must be applied when udpating the exclusion
rects.
The thumb is typically much smaller than the drag zone; the thumb rect alone doesn't
provide an appropriately large exclusion for reliably hitting it, so it is enlarged
to the height of the seek bar (up to 48dp).
Bug: 138992366
Test: manual, show exclusion zones with: adb shell setprop debug.pointerlocation.showexclusion 150 && adb shell settings put system pointer_location 1
Test: atest android.widget.AbsSeekBarTest
Change-Id: I2b670c6f3f33451bdccdfd3d75a75e90260257ff
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/widget/AbsSeekBar.java | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/core/java/android/widget/AbsSeekBar.java b/core/java/android/widget/AbsSeekBar.java index 50bb6883b903..1db91233aefb 100644 --- a/core/java/android/widget/AbsSeekBar.java +++ b/core/java/android/widget/AbsSeekBar.java @@ -91,6 +91,7 @@ public abstract class AbsSeekBar extends ProgressBar { @UnsupportedAppUsage private float mDisabledAlpha; + private int mThumbExclusionMaxSize; private int mScaledTouchSlop; private float mTouchDownX; @UnsupportedAppUsage @@ -170,6 +171,8 @@ public abstract class AbsSeekBar extends ProgressBar { applyTickMarkTint(); mScaledTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); + mThumbExclusionMaxSize = getResources().getDimensionPixelSize( + com.android.internal.R.dimen.seekbar_thumb_exclusion_max_size); } /** @@ -762,12 +765,30 @@ public abstract class AbsSeekBar extends ProgressBar { } mGestureExclusionRects.clear(); thumb.copyBounds(mThumbRect); + mThumbRect.offset(mPaddingLeft - mThumbOffset, mPaddingTop); + growRectTo(mThumbRect, Math.min(getHeight(), mThumbExclusionMaxSize)); mGestureExclusionRects.add(mThumbRect); mGestureExclusionRects.addAll(mUserGestureExclusionRects); super.setSystemGestureExclusionRects(mGestureExclusionRects); } /** + * Grows {@code r} from its center such that each dimension is at least {@code minimumSize}. + */ + private void growRectTo(Rect r, int minimumSize) { + int dy = (minimumSize - r.height()) / 2; + if (dy > 0) { + r.top -= dy; + r.bottom += dy; + } + int dx = (minimumSize - r.width()) / 2; + if (dx > 0) { + r.left -= dx; + r.right += dx; + } + } + + /** * @hide */ @Override |
