summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Moghadam <jmoghadam@google.com>2017-02-16 19:40:49 +0000
committerandroid-build-merger <android-build-merger@google.com>2017-02-16 19:40:49 +0000
commit59f1f298306b45f93f1f7e696ff227da01bc503d (patch)
tree4d6b2d820dbc4ffeac45c754fc191081eba38148
parent87a0f613004a32da0d300f503167138167266d24 (diff)
parent42605ce011ea5c5b287968398bf5d56a04ec7cf0 (diff)
downloadchips-59f1f298306b45f93f1f7e696ff227da01bc503d.tar.gz
Bug fix so touching warning icon does not move the edit cursor. am: e2f29e0ad6 am: 4d5a3e045c
am: 42605ce011 Change-Id: Ia6254ff7aaecb7fe6abad29c8b1c6a25bac12c7a
-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 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())