diff options
author | Jin Cao <jinyan@google.com> | 2014-12-15 17:58:28 -0800 |
---|---|---|
committer | Jin Cao <jinyan@google.com> | 2014-12-15 17:58:28 -0800 |
commit | 696941803b049304a28a2b074899b98a8b5ca629 (patch) | |
tree | c6ad69596dcc9309a6628478ad80ffd5a0a47b55 | |
parent | ef862b79ffd6a272ccadf2872c977dd7d16da199 (diff) | |
parent | ffc0111fa742c72f2457cecc1116e4ea3c6c8c6e (diff) | |
download | chips-696941803b049304a28a2b074899b98a8b5ca629.tar.gz |
resolved conflicts for merge of ffc0111f to master
Change-Id: I92bcf75bdb01503aa652890859c589441d0a1a0f
-rw-r--r-- | res/values/attrs.xml | 1 | ||||
-rw-r--r-- | src/com/android/ex/chips/DropdownChipLayouter.java | 22 | ||||
-rw-r--r-- | src/com/android/ex/chips/RecipientEditTextView.java | 231 |
3 files changed, 97 insertions, 157 deletions
diff --git a/res/values/attrs.xml b/res/values/attrs.xml index be838bf..8cc5470 100644 --- a/res/values/attrs.xml +++ b/res/values/attrs.xml @@ -20,7 +20,6 @@ <enum name="start" value="1" /> </attr> <attr name="chipBackground" format="reference" /> - <attr name="chipBackgroundPressed" format="reference" /> <attr name="chipDelete" format="reference" /> <attr name="chipFontSize" format="reference" /> <attr name="chipHeight" format="reference" /> diff --git a/src/com/android/ex/chips/DropdownChipLayouter.java b/src/com/android/ex/chips/DropdownChipLayouter.java index f88ea7d..a3b809c 100644 --- a/src/com/android/ex/chips/DropdownChipLayouter.java +++ b/src/com/android/ex/chips/DropdownChipLayouter.java @@ -220,18 +220,18 @@ public class DropdownChipLayouter { } if (drawable == null) { view.setVisibility(View.GONE); - } - - view.setImageDrawable(drawable); - if (mDeleteListener != null) { - view.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (drawable.getCurrent() != null) { - mDeleteListener.onChipDelete(); + } else { + view.setImageDrawable(drawable); + if (mDeleteListener != null) { + view.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (drawable.getCurrent() != null) { + mDeleteListener.onChipDelete(); + } } - } - }); + }); + } } } diff --git a/src/com/android/ex/chips/RecipientEditTextView.java b/src/com/android/ex/chips/RecipientEditTextView.java index f1d49c6..ae27c32 100644 --- a/src/com/android/ex/chips/RecipientEditTextView.java +++ b/src/com/android/ex/chips/RecipientEditTextView.java @@ -17,6 +17,7 @@ package com.android.ex.chips; +import android.annotation.TargetApi; import android.app.Dialog; import android.content.ClipData; import android.content.ClipDescription; @@ -47,6 +48,7 @@ import android.os.Handler; import android.os.Looper; import android.os.Message; import android.os.Parcelable; +import android.support.annotation.NonNull; import android.text.Editable; import android.text.InputType; import android.text.Layout; @@ -152,7 +154,6 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements private Drawable mChipBackground = null; private Drawable mChipDelete = null; private Drawable mInvalidChipBackground; - private Drawable mChipBackgroundPressed; // Possible attr overrides private float mChipHeight; @@ -307,7 +308,6 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements } private void setupPopupWindow(ListPopupWindow popup) { - popup.setModal(true); popup.setOnDismissListener(new PopupWindow.OnDismissListener() { @Override public void onDismiss() { @@ -390,7 +390,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements } @Override - public InputConnection onCreateInputConnection(EditorInfo outAttrs) { + public InputConnection onCreateInputConnection(@NonNull EditorInfo outAttrs) { InputConnection connection = super.onCreateInputConnection(outAttrs); int imeActions = outAttrs.imeOptions&EditorInfo.IME_MASK_ACTION; if ((imeActions&EditorInfo.IME_ACTION_DONE) != 0) { @@ -427,7 +427,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements public List<RecipientEntry> getSelectedRecipients() { DrawableRecipientChip[] chips = getText().getSpans(0, getText().length(), DrawableRecipientChip.class); - List<RecipientEntry> results = new ArrayList(); + List<RecipientEntry> results = new ArrayList<RecipientEntry>(); if (chips == null) { return results; } @@ -443,8 +443,9 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements public void onSelectionChanged(int start, int end) { // When selection changes, see if it is inside the chips area. // If so, move the cursor back after the chips again. + // Only exception is when we change the selection due to a selected chip. DrawableRecipientChip last = getLastChip(); - if (last != null && start < getSpannable().getSpanEnd(last)) { + if (mSelectedChip == null && last != null && start < getSpannable().getSpanEnd(last)) { // Grab the last chip and set the cursor to after it. setSelection(Math.min(getSpannable().getSpanEnd(last) + 1, getText().length())); } @@ -514,7 +515,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements } @Override - public <T extends ListAdapter & Filterable> void setAdapter(T adapter) { + public <T extends ListAdapter & Filterable> void setAdapter(@NonNull T adapter) { super.setAdapter(adapter); BaseRecipientAdapter baseAdapter = (BaseRecipientAdapter) adapter; baseAdapter.registerUpdateObserver(new BaseRecipientAdapter.EntriesUpdatedObserver() { @@ -545,8 +546,9 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements baseAdapter.setDropdownChipLayouter(mDropdownChipLayouter); } + @TargetApi(Build.VERSION_CODES.JELLY_BEAN) private void announceForAccessibilityCompat(String text) { - if (mIsAccessibilityOn && Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { + if (mIsAccessibilityOn && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { final ViewParent parent = getParent(); if (parent != null) { AccessibilityEvent event = AccessibilityEvent.obtain( @@ -673,25 +675,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements * @param contact The recipient entry to pull data from. * @param paint The paint to use to draw the bitmap. */ - private Bitmap createSelectedChip(RecipientEntry contact, TextPaint paint) { - paint.setColor(mSelectedChipTextColor); - final ChipBitmapContainer bitmapContainer = createChipBitmap(contact, paint, - mChipBackgroundPressed, mSelectedChipBackgroundColor); - - if (bitmapContainer.loadIcon) { - loadAvatarIcon(contact, bitmapContainer); - } - - return bitmapContainer.bitmap; - } - - /** - * Creates a bitmap of the given contact on a selected chip. - * - * @param contact The recipient entry to pull data from. - * @param paint The paint to use to draw the bitmap. - */ - private Bitmap createUnselectedChip(RecipientEntry contact, TextPaint paint) { + private Bitmap createChipBitmap(RecipientEntry contact, TextPaint paint) { paint.setColor(getDefaultChipTextColor(contact)); ChipBitmapContainer bitmapContainer = createChipBitmap(contact, paint, getChipBackground(contact), getDefaultChipBackgroundColor(contact)); @@ -785,8 +769,8 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements * the layout direction is LTR or RTL. */ private boolean shouldPositionAvatarOnRight() { - final boolean isRtl = Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 ? - getLayoutDirection() == LAYOUT_DIRECTION_RTL : false; + final boolean isRtl = Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && + getLayoutDirection() == LAYOUT_DIRECTION_RTL; final boolean assignedPosition = mAvatarPosition == AVATAR_POSITION_END; // If in Rtl mode, the position should be flipped. return isRtl ? !assignedPosition : assignedPosition; @@ -914,23 +898,18 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements mWorkPaint.setStyle(Style.STROKE); mWorkPaint.setStrokeWidth(borderWidth); mWorkPaint.setAntiAlias(true); - canvas.drawCircle(dst.centerX(), dst.centerY(), dst.width() / 2f - borderWidth / 2, mWorkPaint); + canvas.drawCircle(dst.centerX(), dst.centerY(), dst.width() / 2f - borderWidth / 2, + mWorkPaint); mWorkPaint.reset(); } - private DrawableRecipientChip constructChipSpan(RecipientEntry contact, boolean pressed) { + private DrawableRecipientChip constructChipSpan(RecipientEntry contact) { TextPaint paint = getPaint(); float defaultSize = paint.getTextSize(); int defaultColor = paint.getColor(); - Bitmap tmpBitmap; - if (pressed) { - tmpBitmap = createSelectedChip(contact, paint); - - } else { - tmpBitmap = createUnselectedChip(contact, paint); - } + Bitmap tmpBitmap = createChipBitmap(contact, paint); // Pass the full text, un-ellipsized, to the chip. Drawable result = new BitmapDrawable(getResources(), tmpBitmap); @@ -982,8 +961,6 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements Resources r = getContext().getResources(); mChipBackground = a.getDrawable(R.styleable.RecipientEditTextView_chipBackground); - mChipBackgroundPressed = a - .getDrawable(R.styleable.RecipientEditTextView_chipBackgroundPressed); mInvalidChipBackground = a .getDrawable(R.styleable.RecipientEditTextView_invalidChipBackground); mChipDelete = a.getDrawable(R.styleable.RecipientEditTextView_chipDelete); @@ -1248,8 +1225,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements DrawableRecipientChip chip = null; try { if (!mNoChips) { - chip = visible ? - constructChipSpan(entry, false) : new InvisibleRecipientChip(entry); + chip = visible ? constructChipSpan(entry) : new InvisibleRecipientChip(entry); } } catch (NullPointerException e) { Log.e(TAG, e.getMessage(), e); @@ -1287,12 +1263,11 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements return RecipientEntry.constructFakePhoneEntry(token, true); } Rfc822Token[] tokens = Rfc822Tokenizer.tokenize(token); - String display = null; boolean isValid = isValid(token); if (isValid && tokens != null && tokens.length > 0) { // If we can get a name from tokenizing, then generate an entry from // this. - display = tokens[0].getName(); + String display = tokens[0].getName(); if (!TextUtils.isEmpty(display)) { return RecipientEntry.constructGeneratedEntry(display, tokens[0].getAddress(), isValid); @@ -1373,7 +1348,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements * Dismiss any selected chips when the back key is pressed. */ @Override - public boolean onKeyPreIme(int keyCode, KeyEvent event) { + public boolean onKeyPreIme(int keyCode, @NonNull KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && mSelectedChip != null) { clearSelectedChip(); return true; @@ -1390,7 +1365,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements * a commit key, then create a chip from the text they have entered. */ @Override - public boolean onKeyUp(int keyCode, KeyEvent event) { + public boolean onKeyUp(int keyCode, @NonNull KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_TAB: if (event.hasNoModifiers()) { @@ -1486,11 +1461,11 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements } String text = editable.toString().substring(start, tokenEnd).trim(); clearComposingText(); - if (text != null && text.length() > 0 && !text.equals(" ")) { + if (text.length() > 0 && !text.equals(" ")) { RecipientEntry entry = createTokenizedEntry(text); if (entry != null) { QwertyKeyListener.markAsReplaced(editable, start, end, ""); - CharSequence chipText = createChip(entry, false); + CharSequence chipText = createChip(entry); if (chipText != null && start > -1 && end > -1) { editable.replace(start, end, chipText); } @@ -1552,10 +1527,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements } DrawableRecipientChip[] chips = getSpannable().getSpans(start, end, DrawableRecipientChip.class); - if ((chips == null || chips.length == 0)) { - return false; - } - return true; + return chips != null && chips.length > 0; } private void handleEdit(int start, int end) { @@ -1572,7 +1544,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements if (!TextUtils.isEmpty(text)) { RecipientEntry entry = RecipientEntry.constructFakeEntry(text, isValid(text)); QwertyKeyListener.markAsReplaced(editable, start, end, ""); - CharSequence chipText = createChip(entry, false); + CharSequence chipText = createChip(entry); int selEnd = getSelectionEnd(); if (chipText != null && start > -1 && selEnd > -1) { editable.replace(start, selEnd, chipText); @@ -1586,7 +1558,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements * to the selected chip. */ @Override - public boolean onKeyDown(int keyCode, KeyEvent event) { + public boolean onKeyDown(int keyCode, @NonNull KeyEvent event) { if (mSelectedChip != null && keyCode == KeyEvent.KEYCODE_DEL) { if (mAlternatesPopup != null && mAlternatesPopup.isShowing()) { mAlternatesPopup.dismiss(); @@ -1635,7 +1607,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements * and makes sure that the range is not already a Chip. */ @Override - protected void performFiltering(CharSequence text, int keyCode) { + protected void performFiltering(@NonNull CharSequence text, int keyCode) { boolean isCompletedToken = isCompletedToken(text); if (enoughToFilter() && !isCompletedToken) { int end = getSelectionEnd(); @@ -1681,6 +1653,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements mSelectedChip = null; } setCursorVisible(true); + setSelection(getText().length()); } /** @@ -1692,7 +1665,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements * If it isn't, then select that chip. */ @Override - public boolean onTouchEvent(MotionEvent event) { + public boolean onTouchEvent(@NonNull MotionEvent event) { if (!isFocused()) { // Ignore any chip taps until this view is focused. return super.onTouchEvent(event); @@ -1709,17 +1682,14 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements int offset = putOffsetInRange(x, y); DrawableRecipientChip currentChip = findChip(offset); if (currentChip != null) { - if (action == MotionEvent.ACTION_UP) { - if (mSelectedChip != null && mSelectedChip != currentChip) { - clearSelectedChip(); - mSelectedChip = selectChip(currentChip); - } else if (mSelectedChip == null) { - setSelection(getText().length()); - commitDefault(); - mSelectedChip = selectChip(currentChip); - } else { - onClick(mSelectedChip); - } + if (mSelectedChip != null && mSelectedChip != currentChip) { + clearSelectedChip(); + selectChip(currentChip); + } else if (mSelectedChip == null) { + commitDefault(); + selectChip(currentChip); + } else { + onClick(mSelectedChip); } chipWasSelected = true; handled = true; @@ -1733,12 +1703,6 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements return handled; } - private void scrollLineIntoView(int line) { - if (mScrollView != null) { - mScrollView.smoothScrollBy(0, calculateOffsetFromBottom(line)); - } - } - private void showAlternates(final DrawableRecipientChip currentChip, final ListPopupWindow alternatesPopup) { new AsyncTask<Void, Void, ListAdapter>() { @@ -1860,11 +1824,11 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements } private DrawableRecipientChip findChip(int offset) { - DrawableRecipientChip[] chips = - getSpannable().getSpans(0, getText().length(), DrawableRecipientChip.class); + final Spannable span = getSpannable(); + final DrawableRecipientChip[] chips = + span.getSpans(0, span.length(), DrawableRecipientChip.class); // Find the chip that contains this offset. - for (int i = 0; i < chips.length; i++) { - DrawableRecipientChip chip = chips[i]; + for (DrawableRecipientChip chip : chips) { int start = getChipStart(chip); int end = getChipEnd(chip); if (offset >= start && offset <= end) { @@ -1920,7 +1884,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements } } - private CharSequence createChip(RecipientEntry entry, boolean pressed) { + private CharSequence createChip(RecipientEntry entry) { final String displayText = createAddressText(entry); if (TextUtils.isEmpty(displayText)) { return null; @@ -1930,7 +1894,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements final SpannableString chipText = new SpannableString(displayText); if (!mNoChips) { try { - DrawableRecipientChip chip = constructChipSpan(entry, pressed); + DrawableRecipientChip chip = constructChipSpan(entry); chipText.setSpan(chip, 0, textLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); chip.setOriginalText(chipText.toString()); @@ -1978,7 +1942,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements Editable editable = getText(); QwertyKeyListener.markAsReplaced(editable, start, end, ""); - CharSequence chip = createChip(entry, false); + CharSequence chip = createChip(entry); if (chip != null && start >= 0 && end >= 0) { editable.replace(start, end, chip); } @@ -2097,7 +2061,6 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements start = end; // move to the next token and get its end. } // Now, count total addresses. - start = 0; int tokenCount = countTokens(text); MoreImageSpan moreSpan = createMoreSpan(tokenCount - CHIP_LIMIT); SpannableString chipText = new SpannableString(text.subSequence(end, text.length())); @@ -2233,14 +2196,11 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements * 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 + * will show 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 DrawableRecipientChip selectChip(DrawableRecipientChip currentChip) { + private void selectChip(DrawableRecipientChip currentChip) { if (shouldShowEditableText(currentChip)) { CharSequence text = currentChip.getValue(); Editable editable = getText(); @@ -2256,44 +2216,24 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements setCursorVisible(true); setSelection(editable.length()); editable.append(text); - return constructChipSpan( - RecipientEntry.constructFakeEntry((String) text, isValid(text.toString())), - true); + mSelectedChip = constructChipSpan( + RecipientEntry.constructFakeEntry((String) text, isValid(text.toString()))); } else { - int start = getChipStart(currentChip); - int end = getChipEnd(currentChip); - getSpannable().removeSpan(currentChip); - DrawableRecipientChip newChip; final boolean showAddress = currentChip.getContactId() == RecipientEntry.GENERATED_CONTACT || getAdapter().forceShowAddress(); - try { - if (showAddress && mNoChips) { - return null; - } - newChip = constructChipSpan(currentChip.getEntry(), true); - } catch (NullPointerException e) { - Log.e(TAG, e.getMessage(), e); - return null; - } - Editable editable = getText(); - 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 (shouldShowEditableText(newChip)) { - scrollLineIntoView(getLayout().getLineForOffset(getChipStart(newChip))); + if (showAddress && mNoChips) { + return; } + mSelectedChip = currentChip; + setSelection(getText().getSpanEnd(mSelectedChip)); + setCursorVisible(false); + if (showAddress) { - showAddress(newChip, mAddressPopup); + showAddress(currentChip, mAddressPopup); } else { - showAlternates(newChip, mAlternatesPopup); + showAlternates(currentChip, mAlternatesPopup); } - setCursorVisible(false); - return newChip; } } @@ -2347,7 +2287,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements editable.removeSpan(chip); try { if (!mNoChips) { - editable.setSpan(constructChipSpan(chip.getEntry(), false), + editable.setSpan(constructChipSpan(chip.getEntry()), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } } catch (NullPointerException e) { @@ -2366,8 +2306,17 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements if (mSelectedChip != null) { removeChip(mSelectedChip); } - mAddressPopup.dismiss(); - mAlternatesPopup.dismiss(); + dismissPopups(); + } + + private void dismissPopups() { + if (mAlternatesPopup != null && mAlternatesPopup.isShowing()) { + mAlternatesPopup.dismiss(); + } + if (mAddressPopup != null && mAddressPopup.isShowing()) { + mAddressPopup.dismiss(); + } + setSelection(getText().length()); } /** @@ -2412,7 +2361,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements int end = getChipEnd(chip); getSpannable().removeSpan(chip); Editable editable = getText(); - CharSequence chipText = createChip(entry, false); + CharSequence chipText = createChip(entry); if (chipText != null) { if (start == -1 || end == -1) { Log.e(TAG, "The chip to replace does not exist but should."); @@ -2542,16 +2491,16 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements DrawableRecipientChip.class); if (repl.length > 0) { // There is a chip there! Just remove it. + DrawableRecipientChip toDelete = repl[0]; Editable editable = getText(); // Add the separator token. - int tokenStart = mTokenizer.findTokenStart(editable, selStart); - int tokenEnd = mTokenizer.findTokenEnd(editable, tokenStart); - tokenEnd = tokenEnd + 1; - if (tokenEnd > editable.length()) { - tokenEnd = editable.length(); + int deleteStart = editable.getSpanStart(toDelete); + int deleteEnd = editable.getSpanEnd(toDelete) + 1; + if (deleteEnd > editable.length()) { + deleteEnd = editable.length(); } - editable.delete(tokenStart, tokenEnd); - getSpannable().removeSpan(repl[0]); + editable.removeSpan(toDelete); + editable.delete(deleteStart, deleteEnd); } } else if (count > before) { if (mSelectedChip != null @@ -2731,7 +2680,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements if (mNoChips) { return null; } - return constructChipSpan(entry, false); + return constructChipSpan(entry); } catch (NullPointerException e) { Log.e(TAG, e.getMessage(), e); return null; @@ -2745,9 +2694,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements final List<DrawableRecipientChip> originalRecipients = new ArrayList<DrawableRecipientChip>(); final DrawableRecipientChip[] existingChips = getSortedRecipients(); - for (int i = 0; i < existingChips.length; i++) { - originalRecipients.add(existingChips[i]); - } + Collections.addAll(originalRecipients, existingChips); if (mRemovedSpans != null) { originalRecipients.addAll(mRemovedSpans); } @@ -2778,16 +2725,12 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements final ArrayList<DrawableRecipientChip> recipients = new ArrayList<DrawableRecipientChip>(); DrawableRecipientChip[] existingChips = getSortedRecipients(); - for (int i = 0; i < existingChips.length; i++) { - recipients.add(existingChips[i]); - } + Collections.addAll(recipients, existingChips); if (mRemovedSpans != null) { recipients.addAll(mRemovedSpans); } ArrayList<String> addresses = new ArrayList<String>(); - DrawableRecipientChip chip; - for (int i = 0; i < recipients.size(); i++) { - chip = recipients.get(i); + for (DrawableRecipientChip chip : recipients) { if (chip != null) { addresses.add(createAddressText(chip.getEntry())); } @@ -2912,9 +2855,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements // chip. final ArrayList<DrawableRecipientChip> originalRecipients = params[0]; ArrayList<String> addresses = new ArrayList<String>(); - DrawableRecipientChip chip; - for (int i = 0; i < originalRecipients.size(); i++) { - chip = originalRecipients.get(i); + for (DrawableRecipientChip chip : originalRecipients) { if (chip != null) { addresses.add(createAddressText(chip.getEntry())); } @@ -3002,8 +2943,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements private int supportGetOffsetForPosition(float x, float y) { if (getLayout() == null) return -1; final int line = supportGetLineAtCoordinate(y); - final int offset = supportGetOffsetAtCoordinate(line, x); - return offset; + return supportGetOffsetAtCoordinate(line, x); } private float supportConvertToLocalHorizontalCoordinate(float x) { @@ -3056,7 +2996,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements * Handles drag event. */ @Override - public boolean onDragEvent(DragEvent event) { + public boolean onDragEvent(@NonNull DragEvent event) { switch (event.getAction()) { case DragEvent.ACTION_DRAG_STARTED: // Only handle plain text drag and drop. @@ -3082,14 +3022,15 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements } @Override - public void onProvideShadowMetrics(Point shadowSize, Point shadowTouchPoint) { + public void onProvideShadowMetrics(@NonNull Point shadowSize, + @NonNull Point shadowTouchPoint) { Rect rect = mChip.getBounds(); shadowSize.set(rect.width(), rect.height()); shadowTouchPoint.set(rect.centerX(), rect.centerY()); } @Override - public void onDrawShadow(Canvas canvas) { + public void onDrawShadow(@NonNull Canvas canvas) { mChip.draw(canvas); } } @@ -3177,7 +3118,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements chipInsertionPoint = editable.getSpanEnd(last) + 1; } - final CharSequence chip = createChip(entry, false); + final CharSequence chip = createChip(entry); if (chip != null) { editable.insert(chipInsertionPoint, chip); } |