diff options
author | Justin Klaassen <justinklaassen@google.com> | 2016-12-09 08:11:33 -0800 |
---|---|---|
committer | Justin Klaassen <justinklaassen@google.com> | 2016-12-09 08:33:57 -0800 |
commit | 8e367265e6499b2fb79dd18256ffe444320aa325 (patch) | |
tree | 7ea197f0dc09ef1382ae387cef7aaab4385ce37b | |
parent | c4dce219670f539e26b8145ab3262ea4ab914f55 (diff) | |
download | android_packages_apps_ExactCalculator-8e367265e6499b2fb79dd18256ffe444320aa325.tar.gz android_packages_apps_ExactCalculator-8e367265e6499b2fb79dd18256ffe444320aa325.tar.bz2 android_packages_apps_ExactCalculator-8e367265e6499b2fb79dd18256ffe444320aa325.zip |
Intercept touches from secondary pointers
Fixes: 33480687
Test: manually verified secondary pointers are intercepted
Change-Id: Ie70a3cdb2ca79483add5ed07d214f98d3959e322
-rw-r--r-- | src/com/android/calculator2/CalculatorPadViewPager.java | 46 |
1 files changed, 27 insertions, 19 deletions
diff --git a/src/com/android/calculator2/CalculatorPadViewPager.java b/src/com/android/calculator2/CalculatorPadViewPager.java index 560260b..dded4a9 100644 --- a/src/com/android/calculator2/CalculatorPadViewPager.java +++ b/src/com/android/calculator2/CalculatorPadViewPager.java @@ -188,38 +188,46 @@ public class CalculatorPadViewPager extends ViewPager { public boolean onInterceptTouchEvent(MotionEvent ev) { // Always intercept touch events when a11y focused since otherwise they will be // incorrectly offset by a11y before being dispatched to children. - boolean shouldIntercept = isAccessibilityFocused() || super.onInterceptTouchEvent(ev); + if (isAccessibilityFocused() || super.onInterceptTouchEvent(ev)) { + return true; + } // Only allow the current item to receive touch events. - if (!shouldIntercept && ev.getActionMasked() == MotionEvent.ACTION_DOWN) { - final int x = (int) ev.getX() + getScrollX(); - final int y = (int) ev.getY() + getScrollY(); + final int action = ev.getActionMasked(); + if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_POINTER_DOWN) { + // If a child is a11y focused then we must always intercept the touch event + // since it will be incorrectly offset by a11y. + final int childCount = getChildCount(); + for (int childIndex = childCount - 1; childIndex >= 0; --childIndex) { + if (getChildAt(childIndex).isAccessibilityFocused()) { + mClickedItemIndex = childIndex; + return true; + } + } - // Reset the previously clicked item index. - mClickedItemIndex = -1; + if (action == MotionEvent.ACTION_DOWN) { + mClickedItemIndex = -1; + } - final int childCount = getChildCount(); + // Otherwise if touch is on a non-current item then intercept. + final int actionIndex = ev.getActionIndex(); + final float x = ev.getX(actionIndex) + getScrollX(); + final float y = ev.getY(actionIndex) + getScrollY(); for (int i = childCount - 1; i >= 0; --i) { final int childIndex = getChildDrawingOrder(childCount, i); final View child = getChildAt(childIndex); - if (child.isAccessibilityFocused()) { - // If a child is a11y focused then we must always intercept the touch event - // since it will be incorrectly offset by a11y. - shouldIntercept = true; - mClickedItemIndex = childIndex; - break; - } else if (mClickedItemIndex == -1 - && child.getVisibility() == VISIBLE + if (child.getVisibility() == VISIBLE && x >= child.getLeft() && x < child.getRight() && y >= child.getTop() && y < child.getBottom()) { - shouldIntercept = childIndex != getCurrentItem(); - mClickedItemIndex = childIndex; - // continue; since another child may be a11y focused. + if (action == MotionEvent.ACTION_DOWN) { + mClickedItemIndex = childIndex; + } + return childIndex != getCurrentItem(); } } } - return shouldIntercept; + return false; } @Override |