/**
* Show specified chip as selected. If the RecipientChip is just an email address,
* selecting the chip will take the contents of the chip and place it at
* the end of the RecipientEditTextView for inline editing. If the
* RecipientChip is a complete contact, then selecting the chip
* will change the background color of the chip, show the delete icon,
* and a popup window with the address in use highlighted and any other
* alternate addresses for the contact.
* @param currentChip Chip to select.
* @return A RecipientChip in the selected state or null if the chip
* just contained an email address.
*/
private DrawableChip selectChip(DrawableChip currentChip) {
// small additinal feature.
if(!currentChip.isSelectable()) {
return null;
}
CharSequence text = currentChip.getText();
Editable editable = getText();
Spannable spannable = getSpannable();
DrawableChip newChip = null;
if (currentChip.isEditable()) {
int spanStart = spannable.getSpanStart(currentChip);
int spanEnd = spannable.getSpanEnd(currentChip);
spannable.removeSpan(currentChip);
editable.delete(spanStart, spanEnd);
setCursorVisible(true);
setSelection(editable.length());
editable.append(text);
newChip = constructChipSpan(currentChip.getDelegate(), true);
} else {
int start = getChipStart(currentChip);
int end = getChipEnd(currentChip);
spannable.removeSpan(currentChip);
try {
newChip = constructChipSpan(currentChip.getDelegate(), true);
} catch (NullPointerException e) {
Log.e(TAG, e.getMessage(), e);
return null;
}
QwertyKeyListener.markAsReplaced(editable, start, end, "");
if (start == -1 || end == -1) {
Log.d(TAG, "The chip being selected no longer exists but should.");
} else {
editable.setSpan(newChip, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
newChip.setSelected(true);
if (newChip.isEditable()) {
scrollLineIntoView(getLayout().getLineForOffset(getChipStart(newChip)));
}
setCursorVisible(false);
}
// transfer the original text.
newChip.setOriginalText(currentChip.getOriginalText());
return newChip;
}
ChipEditTextView.java 文件源码
java
阅读 25
收藏 0
点赞 0
评论 0
项目:android-chip-edittextview
作者:
评论列表
文章目录