summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Moghadam <jmoghadam@google.com>2017-02-15 17:37:21 -0800
committerJoseph Moghadam <jmoghadam@google.com>2017-02-16 10:47:02 -0800
commite2f29e0ad6e5426955852217686a3d55ec0a7ad7 (patch)
tree4d4441f3de78ca973a0de34bc856caffc9fc5dff
parent8cd6353bdce56d423a9381f2efbc20d26f600710 (diff)
downloadchips-e2f29e0ad6e5426955852217686a3d55ec0a7ad7.tar.gz
Bug fix so touching warning icon does not move the edit cursor.
Before, touching the warning icon would move the edit cursor backwards 1 space. Bug: 33000434 Test: manual - built in google3 and tried on my device. Change-Id: Ie6378e3924f2da1f97c9e35bd77279e9877caba1
-rw-r--r--src/com/android/ex/chips/RecipientEditTextView.java55
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 33f54a2..af30154 100644
--- a/src/com/android/ex/chips/RecipientEditTextView.java
+++ b/src/com/android/ex/chips/RecipientEditTextView.java
@@ -1932,29 +1932,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.
@@ -1964,9 +1952,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) {
@@ -1987,6 +1972,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;
@@ -1998,6 +1987,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())