diff options
author | Joseph Moghadam <jmoghadam@google.com> | 2017-02-16 19:32:29 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-02-16 19:32:29 +0000 |
commit | 4d5a3e045c34f3c96e1a937c883e5f8e0fdd9661 (patch) | |
tree | 9c53dbc1cf96165ee16ae2a5c8ba5a0789a57d8d /src/com | |
parent | 553a9d403c6ef55c2f26f1f17a843dd1d39b92d6 (diff) | |
parent | e2f29e0ad6e5426955852217686a3d55ec0a7ad7 (diff) | |
download | chips-4d5a3e045c34f3c96e1a937c883e5f8e0fdd9661.tar.gz |
Bug fix so touching warning icon does not move the edit cursor.
am: e2f29e0ad6
Change-Id: Id29e041c494cc419de730111b40c74edc618fafd
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/android/ex/chips/RecipientEditTextView.java | 55 |
1 files changed, 30 insertions, 25 deletions
diff --git a/src/com/android/ex/chips/RecipientEditTextView.java b/src/com/android/ex/chips/RecipientEditTextView.java index 7140f24..29ecbd2 100644 --- a/src/com/android/ex/chips/RecipientEditTextView.java +++ b/src/com/android/ex/chips/RecipientEditTextView.java @@ -1930,29 +1930,17 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements public boolean onTouchEvent(@NonNull MotionEvent event) { boolean handled; int action = event.getAction(); + final float x = event.getX(); + final float y = event.getY(); + final int offset = putOffsetInRange(x, y); + final DrawableRecipientChip currentChip = findChip(offset); if (action == MotionEvent.ACTION_UP) { - final float x = event.getX(); - final float y = event.getY(); - final int offset = putOffsetInRange(x, y); - final DrawableRecipientChip currentChip = findChip(offset); - - // Handle touching the warning icon - boolean touchedWarningIcon = false; - if (currentChip != null) { - Rect outOfDomainWarningBounds = currentChip.getWarningIconBounds(); - if (outOfDomainWarningBounds != null) { - final RectF touchOutOfDomainWarning = new RectF( - outOfDomainWarningBounds.left, - outOfDomainWarningBounds.top + getTotalPaddingTop(), - outOfDomainWarningBounds.right, - outOfDomainWarningBounds.bottom + getTotalPaddingTop()); - if (touchOutOfDomainWarning.contains(event.getX(), event.getY())) { - String warningText = String.format(mWarningTextTemplate, - currentChip.getEntry().getDestination()); - showWarningDialog(warningText); - touchedWarningIcon = true; - } - } + boolean touchedWarningIcon = touchedWarningIcon(x, y, currentChip); + if (touchedWarningIcon) { + String warningText = String.format(mWarningTextTemplate, + currentChip.getEntry().getDestination()); + showWarningDialog(warningText); + return true; } if (!isFocused()) { // Ignore further chip taps until this view is focused. @@ -1962,9 +1950,6 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements if (mSelectedChip == null) { mGestureDetector.onTouchEvent(event); } - if (touchedWarningIcon) { - return true; - } boolean chipWasSelected = false; if (currentChip != null) { if (mSelectedChip != null && mSelectedChip != currentChip) { @@ -1985,6 +1970,10 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements clearSelectedChip(); } } else { + boolean touchedWarningIcon = touchedWarningIcon(x, y, currentChip); + if (touchedWarningIcon) { + return true; + } handled = super.onTouchEvent(event); if (!isFocused()) { return handled; @@ -1996,6 +1985,22 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements return handled; } + private boolean touchedWarningIcon(float x, float y, DrawableRecipientChip currentChip) { + boolean touchedWarningIcon = false; + if (currentChip != null) { + Rect outOfDomainWarningBounds = currentChip.getWarningIconBounds(); + if (outOfDomainWarningBounds != null) { + final RectF touchOutOfDomainWarning = new RectF( + outOfDomainWarningBounds.left, + outOfDomainWarningBounds.top + getTotalPaddingTop(), + outOfDomainWarningBounds.right, + outOfDomainWarningBounds.bottom + getTotalPaddingTop()); + touchedWarningIcon = touchOutOfDomainWarning.contains(x, y); + } + } + return touchedWarningIcon; + } + private void showWarningDialog(String warningText) { mCurrentWarningText = warningText; new AlertDialog.Builder(RecipientEditTextView.this.getContext()) |