summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnnie Chin <afchin@google.com>2017-02-01 12:48:00 -0800
committerAnnie Chin <afchin@google.com>2017-02-02 13:01:19 -0800
commit13cd100ed0438cdcf918d3b3e3f42c506c0c52d1 (patch)
tree5d960c4c32903b598094800c1926fe0ee51f4ea5
parentb61d00b7f578689c15b21516c5436e286cf98c1d (diff)
downloadandroid_packages_apps_ExactCalculator-13cd100ed0438cdcf918d3b3e3f42c506c0c52d1.tar.gz
android_packages_apps_ExactCalculator-13cd100ed0438cdcf918d3b3e3f42c506c0c52d1.tar.bz2
android_packages_apps_ExactCalculator-13cd100ed0438cdcf918d3b3e3f42c506c0c52d1.zip
Catch IllegalArgumentException in CalculatorPadViewPager.
Test: Swipe/fling of panels still works with and without talkback enabled. Fixes: 34804495 Prevent crashes resulting from invalid pointer ids (probably caused by multitouch). Change-Id: Icadcc91fe744e45cb66ada98d438cb778042f4e8
-rw-r--r--src/com/android/calculator2/CalculatorPadViewPager.java89
1 files changed, 50 insertions, 39 deletions
diff --git a/src/com/android/calculator2/CalculatorPadViewPager.java b/src/com/android/calculator2/CalculatorPadViewPager.java
index dded4a9..9197342 100644
--- a/src/com/android/calculator2/CalculatorPadViewPager.java
+++ b/src/com/android/calculator2/CalculatorPadViewPager.java
@@ -21,6 +21,7 @@ import android.graphics.Color;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
+import android.util.Log;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
@@ -186,56 +187,66 @@ public class CalculatorPadViewPager extends ViewPager {
@Override
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.
- if (isAccessibilityFocused() || super.onInterceptTouchEvent(ev)) {
- return true;
- }
+ try {
+ // Always intercept touch events when a11y focused since otherwise they will be
+ // incorrectly offset by a11y before being dispatched to children.
+ if (isAccessibilityFocused() || super.onInterceptTouchEvent(ev)) {
+ return true;
+ }
- // Only allow the current item to receive touch events.
- 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;
+ // Only allow the current item to receive touch events.
+ 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;
+ }
}
- }
- if (action == MotionEvent.ACTION_DOWN) {
- mClickedItemIndex = -1;
- }
+ if (action == MotionEvent.ACTION_DOWN) {
+ mClickedItemIndex = -1;
+ }
- // 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.getVisibility() == VISIBLE
- && x >= child.getLeft() && x < child.getRight()
- && y >= child.getTop() && y < child.getBottom()) {
- if (action == MotionEvent.ACTION_DOWN) {
- mClickedItemIndex = childIndex;
+ // 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.getVisibility() == VISIBLE
+ && x >= child.getLeft() && x < child.getRight()
+ && y >= child.getTop() && y < child.getBottom()) {
+ if (action == MotionEvent.ACTION_DOWN) {
+ mClickedItemIndex = childIndex;
+ }
+ return childIndex != getCurrentItem();
}
- return childIndex != getCurrentItem();
}
}
- }
- return false;
+ return false;
+ } catch (IllegalArgumentException e) {
+ Log.e("Calculator", "Error intercepting touch event", e);
+ return false;
+ }
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
- // Allow both the gesture detector and super to handle the touch event so they both see
- // the full sequence of events. This should be safe since the gesture detector only
- // handle clicks and super only handles swipes.
- mGestureDetector.onTouchEvent(ev);
- return super.onTouchEvent(ev);
+ try {
+ // Allow both the gesture detector and super to handle the touch event so they both see
+ // the full sequence of events. This should be safe since the gesture detector only
+ // handle clicks and super only handles swipes.
+ mGestureDetector.onTouchEvent(ev);
+ return super.onTouchEvent(ev);
+ } catch (IllegalArgumentException e) {
+ Log.e("Calculator", "Error processing touch event", e);
+ return false;
+ }
}
}