summaryrefslogtreecommitdiffstats
path: root/chips/src
diff options
context:
space:
mode:
authormindyp <mindyp@google.com>2012-11-06 13:47:59 -0800
committermindyp <mindyp@google.com>2012-11-07 08:26:27 -0800
commitd5f7739013e4e4e392bcfca04c0cf1ed07c04819 (patch)
treee6bc1ac014f4f6d0a8217bcc8838b7dcf786aa67 /chips/src
parentc270a161307eeeee3aac5f5ef91424fbe25ce1e9 (diff)
downloadandroid_frameworks_ex-d5f7739013e4e4e392bcfca04c0cf1ed07c04819.tar.gz
android_frameworks_ex-d5f7739013e4e4e392bcfca04c0cf1ed07c04819.tar.bz2
android_frameworks_ex-d5f7739013e4e4e392bcfca04c0cf1ed07c04819.zip
Update chips to follow new ux spec for replacement
Part of b/7481045 recipient address briefly drawn w/o friendly name Change-Id: I2f3c63f555143c66b3d4f466b60e0ca884d6302b
Diffstat (limited to 'chips/src')
-rw-r--r--chips/src/com/android/ex/chips/RecipientEditTextView.java108
1 files changed, 78 insertions, 30 deletions
diff --git a/chips/src/com/android/ex/chips/RecipientEditTextView.java b/chips/src/com/android/ex/chips/RecipientEditTextView.java
index 9aea16d..215ab60 100644
--- a/chips/src/com/android/ex/chips/RecipientEditTextView.java
+++ b/chips/src/com/android/ex/chips/RecipientEditTextView.java
@@ -224,6 +224,8 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
};
+ private int mMaxLines;
+
public RecipientEditTextView(Context context, AttributeSet attrs) {
super(context, attrs);
setChipDimensions(context, attrs);
@@ -263,6 +265,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
addTextChangedListener(mTextWatcher);
mGestureDetector = new GestureDetector(context, this);
setOnEditorActionListener(this);
+ mMaxLines = getLineCount();
}
@Override
@@ -396,7 +399,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
return;
}
if (mSelectedChip != null
- && mSelectedChip.getEntry().getContactId() != RecipientEntry.INVALID_CONTACT) {
+ && shouldShowEditableText(mSelectedChip)) {
clearSelectedChip();
} else {
if (getWidth() <= 0) {
@@ -507,7 +510,8 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
}
- private Bitmap createUnselectedChip(RecipientEntry contact, TextPaint paint, Layout layout) {
+ private Bitmap createUnselectedChip(RecipientEntry contact, TextPaint paint, Layout layout,
+ boolean leaveBlankIconSpacer) {
// Ellipsize the text so that it takes AT MOST the entire width of the
// autocomplete text entry area. Make sure to leave space for padding
// on the sides.
@@ -531,8 +535,14 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
background.setBounds(0, 0, width, height);
background.draw(canvas);
- // Don't draw photos for recipients that have been typed in.
- if (contact.getContactId() != RecipientEntry.INVALID_CONTACT) {
+ // Don't draw photos for recipients that have been typed in OR generated on the fly.
+ long contactId = contact.getContactId();
+ boolean drawPhotos = isPhoneQuery() ?
+ contactId != RecipientEntry.INVALID_CONTACT
+ : (contactId != RecipientEntry.INVALID_CONTACT
+ && (contactId != RecipientEntry.GENERATED_CONTACT &&
+ !TextUtils.isEmpty(contact.getDisplayName())));
+ if (drawPhotos) {
byte[] photoBytes = contact.getPhotoBytes();
// There may not be a photo yet if anything but the first contact address
// was selected.
@@ -563,8 +573,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
matrix.setRectToRect(src, dst, Matrix.ScaleToFit.FILL);
canvas.drawBitmap(photo, matrix, paint);
}
- } else {
- // Don't leave any space for the icon. It isn't being drawn.
+ } else if (!leaveBlankIconSpacer || isPhoneQuery()) {
iconWidth = 0;
}
paint.setColor(getContext().getResources().getColor(android.R.color.black));
@@ -593,8 +602,8 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
return height - ((height - textHeight) / 2) - (int)paint.descent();
}
- private RecipientChip constructChipSpan(RecipientEntry contact, int offset, boolean pressed)
- throws NullPointerException {
+ private RecipientChip constructChipSpan(RecipientEntry contact, int offset, boolean pressed,
+ boolean leaveIconSpace) throws NullPointerException {
if (mChipBackground == null) {
throw new NullPointerException(
"Unable to render any chips as setChipDimensions was not called.");
@@ -610,7 +619,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
tmpBitmap = createSelectedChip(contact, paint, layout);
} else {
- tmpBitmap = createUnselectedChip(contact, paint, layout);
+ tmpBitmap = createUnselectedChip(contact, paint, layout, leaveIconSpace);
}
// Pass the full text, un-ellipsized, to the chip.
@@ -810,7 +819,13 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
mIndividualReplacements = new IndividualReplacementTask();
mIndividualReplacements.execute(new ArrayList<RecipientChip>(
mTemporaryRecipients.subList(0, CHIP_LIMIT)));
-
+ if (mTemporaryRecipients.size() > CHIP_LIMIT) {
+ mTemporaryRecipients = new ArrayList<RecipientChip>(
+ mTemporaryRecipients.subList(CHIP_LIMIT,
+ mTemporaryRecipients.size()));
+ } else {
+ mTemporaryRecipients = null;
+ }
createMoreChip();
}
} else {
@@ -889,7 +904,14 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
RecipientChip chip = null;
try {
if (!mNoChips) {
- chip = constructChipSpan(entry, start, false);
+ /* leave space for the contact icon if this is not just an email address */
+ chip = constructChipSpan(
+ entry,
+ start,
+ false,
+ TextUtils.isEmpty(entry.getDisplayName())
+ || TextUtils.equals(entry.getDisplayName(),
+ entry.getDestination()));
chipText.setSpan(chip, 0, textLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
} catch (NullPointerException e) {
@@ -934,6 +956,15 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
// this.
display = tokens[0].getName();
if (!TextUtils.isEmpty(display)) {
+ if (!isPhoneQuery()) {
+ if (!TextUtils.isEmpty(token)) {
+ token = token.trim();
+ }
+ char charAt = token.charAt(token.length() - 1);
+ if (charAt == COMMIT_CHAR_COMMA || charAt == COMMIT_CHAR_SEMICOLON) {
+ token = token.substring(0, token.length() - 1);
+ }
+ }
return RecipientEntry.constructGeneratedEntry(display, token);
} else {
display = tokens[0].getAddress();
@@ -1340,8 +1371,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
}
chipWasSelected = true;
handled = true;
- } else if (mSelectedChip != null
- && mSelectedChip.getContactId() == RecipientEntry.INVALID_CONTACT) {
+ } else if (mSelectedChip != null && shouldShowEditableText(mSelectedChip)) {
chipWasSelected = true;
}
}
@@ -1526,7 +1556,8 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
chipText = new SpannableString(displayText);
if (!mNoChips) {
try {
- RecipientChip chip = constructChipSpan(entry, start, pressed);
+ RecipientChip chip = constructChipSpan(entry, start, pressed,
+ false /* leave space for contact icon */);
chipText.setSpan(chip, 0, textLength,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
chip.setOriginalText(chipText.toString());
@@ -1576,7 +1607,10 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
// valid contact, but the destination is invalid, then make this a fake
// recipient that is editable.
String destination = item.getDestination();
- if (RecipientEntry.isCreatedRecipient(item.getContactId())
+ if (!isPhoneQuery() && item.getContactId() == RecipientEntry.GENERATED_CONTACT) {
+ entry = RecipientEntry.constructGeneratedEntry(item.getDisplayName(),
+ destination);
+ } else if (RecipientEntry.isCreatedRecipient(item.getContactId())
&& (TextUtils.isEmpty(item.getDisplayName())
|| TextUtils.equals(item.getDisplayName(), destination)
|| (mValidator != null && !mValidator.isValid(destination)))) {
@@ -1737,7 +1771,6 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
if (!mShouldShrink) {
return;
}
-
ImageSpan[] tempMore = getSpannable().getSpans(0, getText().length(), MoreImageSpan.class);
if (tempMore.length > 0) {
getSpannable().removeSpan(tempMore[0]);
@@ -1780,6 +1813,10 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
chipText.setSpan(moreSpan, 0, chipText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
text.replace(start, end, chipText);
mMoreChip = moreSpan;
+ // If adding the +more chip goes over the limit, resize accordingly.
+ if (!isPhoneQuery() && getLineCount() > mMaxLines) {
+ setMaxLines(getLineCount());
+ }
}
/**
@@ -1839,7 +1876,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
* just contained an email address.
*/
private RecipientChip selectChip(RecipientChip currentChip) {
- if (currentChip.getContactId() == RecipientEntry.INVALID_CONTACT) {
+ if (shouldShowEditableText(currentChip)) {
CharSequence text = currentChip.getValue();
Editable editable = getText();
removeChip(currentChip);
@@ -1856,7 +1893,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
if (mNoChips) {
return null;
}
- newChip = constructChipSpan(currentChip.getEntry(), start, true);
+ newChip = constructChipSpan(currentChip.getEntry(), start, true, false);
} catch (NullPointerException e) {
Log.e(TAG, e.getMessage(), e);
return null;
@@ -1869,7 +1906,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
editable.setSpan(newChip, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
newChip.setSelected(true);
- if (newChip.getEntry().getContactId() == RecipientEntry.INVALID_CONTACT) {
+ if (shouldShowEditableText(newChip)) {
scrollLineIntoView(getLayout().getLineForOffset(getChipStart(newChip)));
}
showAddress(newChip, mAddressPopup, getWidth(), getContext());
@@ -1881,7 +1918,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
getSpannable().removeSpan(currentChip);
RecipientChip newChip;
try {
- newChip = constructChipSpan(currentChip.getEntry(), start, true);
+ newChip = constructChipSpan(currentChip.getEntry(), start, true, false);
} catch (NullPointerException e) {
Log.e(TAG, e.getMessage(), e);
return null;
@@ -1894,7 +1931,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
editable.setSpan(newChip, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
newChip.setSelected(true);
- if (newChip.getEntry().getContactId() == RecipientEntry.INVALID_CONTACT) {
+ if (shouldShowEditableText(newChip)) {
scrollLineIntoView(getLayout().getLineForOffset(getChipStart(newChip)));
}
showAlternates(newChip, mAlternatesPopup, getWidth(), getContext());
@@ -1903,6 +1940,11 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
}
}
+ private boolean shouldShowEditableText(RecipientChip currentChip) {
+ long contactId = currentChip.getContactId();
+ return contactId == RecipientEntry.INVALID_CONTACT
+ || (!isPhoneQuery() && contactId == RecipientEntry.GENERATED_CONTACT);
+ }
private void showAddress(final RecipientChip currentChip, final ListPopupWindow popup,
int width, Context context) {
@@ -1947,8 +1989,8 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
editable.removeSpan(chip);
try {
if (!mNoChips) {
- editable.setSpan(constructChipSpan(chip.getEntry(), start, false), start, end,
- Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+ editable.setSpan(constructChipSpan(chip.getEntry(), start, false, false),
+ start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
} catch (NullPointerException e) {
Log.e(TAG, e.getMessage(), e);
@@ -2093,7 +2135,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
}
// If the user is editing a chip, don't clear it.
if (mSelectedChip != null
- && mSelectedChip.getContactId() != RecipientEntry.INVALID_CONTACT) {
+ && shouldShowEditableText(mSelectedChip)) {
setCursorVisible(true);
setSelection(getText().length());
clearSelectedChip();
@@ -2285,7 +2327,8 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
if (mNoChips) {
return null;
}
- return constructChipSpan(entry, -1, false);
+ return constructChipSpan(entry, -1, false,
+ false /*leave space for contact icon */);
} catch (NullPointerException e) {
Log.e(TAG, e.getMessage(), e);
return null;
@@ -2376,7 +2419,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
// If there is a match, replace that chip with the matching
// chip.
final ArrayList<RecipientChip> originalRecipients =
- (ArrayList<RecipientChip>) params[0];
+ (ArrayList<RecipientChip>) params[0];
ArrayList<String> addresses = new ArrayList<String>();
RecipientChip chip;
for (int i = 0; i < originalRecipients.size(); i++) {
@@ -2391,13 +2434,18 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
if (RecipientEntry.isCreatedRecipient(temp.getEntry().getContactId())
&& getSpannable().getSpanStart(temp) != -1) {
// Replace this.
- final RecipientEntry entry = createValidatedEntry(entries.get(
- tokenizeAddress(temp.getEntry().getDestination()).toLowerCase()));
- if (entry != null) {
+ RecipientEntry entry = createValidatedEntry(entries.get(tokenizeAddress(
+ temp.getEntry().getDestination()).toLowerCase()));
+ if (entry == null && !isPhoneQuery()) {
+ entry = RecipientEntry.constructFakeEntry(Rfc822Tokenizer.tokenize(temp
+ .getEntry().getDestination())[0].getAddress());
+ }
+ final RecipientEntry tempEntry = entry;
+ if (tempEntry != null) {
mHandler.post(new Runnable() {
@Override
public void run() {
- replaceChip(temp, entry);
+ replaceChip(temp, tempEntry);
}
});
}