Scroll before showing the alternates list.
This allows us to have the alternates list properly positioned
AND prevents the dialog from appearing ABOVE the contact.
Change-Id: I78fd1d6ef6b08a1274e7299439b8679f43d1ba86
diff --git a/src/com/android/ex/chips/RecipientEditTextView.java b/src/com/android/ex/chips/RecipientEditTextView.java
index 67dafa4..c11e6a1 100644
--- a/src/com/android/ex/chips/RecipientEditTextView.java
+++ b/src/com/android/ex/chips/RecipientEditTextView.java
@@ -432,10 +432,11 @@
* 2) the height of a chip
* 3) padding built into the edit text view
*/
- private int calculateOffsetFromBottom(int line, int chipHeight) {
+ private int calculateOffsetFromBottom(int line) {
// Line offsets start at zero.
int actualLine = getLineCount() - (line + 1);
- return -((actualLine * (chipHeight + getPaddingBottom())) + getPaddingTop());
+ // TODO: when b/4559727 is fixed, the bottom padding should be applied to each line.
+ return -((actualLine * (int)mChipHeight) + getPaddingBottom() + getPaddingTop());
}
/**
@@ -537,8 +538,7 @@
}
} else {
// There are too many recipients to look up, so just fall back to
- // showing addresses
- // for all of them.
+ // showing addresses for all of them.
mTemporaryRecipients = null;
createMoreChip();
}
@@ -878,11 +878,6 @@
setSelection(getText().length());
commitDefault();
mSelectedChip = selectChip(currentChip);
- if (mSelectedChip != null
- && mSelectedChip.getEntry().getContactId() == INVALID_CONTACT) {
- scrollLineIntoView(getLayout().getLineForOffset(
- getChipStart(mSelectedChip)));
- }
} else {
onClick(mSelectedChip, offset, x, y);
}
@@ -899,14 +894,14 @@
private void scrollLineIntoView(int line) {
if (mScrollView != null) {
- mScrollView.scrollBy(0, calculateOffsetFromBottom(line, (int) mChipHeight));
+ mScrollView.scrollBy(0, calculateOffsetFromBottom(line));
}
}
private void showAlternates(RecipientChip currentChip, ListPopupWindow alternatesPopup,
int width, Context context) {
int line = getLayout().getLineForOffset(getChipStart(currentChip));
- int bottom = calculateOffsetFromBottom(line, (int) mChipHeight);
+ int bottom = calculateOffsetFromBottom(line);
// Align the alternates popup with the left side of the View,
// regardless of the position of the chip tapped.
alternatesPopup.setWidth(width);
@@ -1242,6 +1237,10 @@
editable.replace(start, end, chipText);
}
newChip.setSelected(true);
+ if (newChip.getEntry().getContactId() == INVALID_CONTACT) {
+ scrollLineIntoView(getLayout().getLineForOffset(
+ getChipStart(newChip)));
+ }
showAlternates(newChip, mAlternatesPopup, getWidth(), getContext());
return newChip;
} else {