Add getRecipients
Method gives the calling application a plain editable containing
all of the recipient addresses
Also added larger assets for the delete icon as the others were
untappable!
Change-Id: Ib02dfcffc3d9e739586f5b502cf92f726cd5c0ef
diff --git a/res/drawable-hdpi/delete.png b/res/drawable-hdpi/delete.png
index 200eae4..ca277ba 100644
--- a/res/drawable-hdpi/delete.png
+++ b/res/drawable-hdpi/delete.png
Binary files differ
diff --git a/res/drawable-mdpi/delete.png b/res/drawable-mdpi/delete.png
index 200eae4..ca277ba 100644
--- a/res/drawable-mdpi/delete.png
+++ b/res/drawable-mdpi/delete.png
Binary files differ
diff --git a/src/com/android/ex/chips/RecipientEditTextView.java b/src/com/android/ex/chips/RecipientEditTextView.java
index 8fc953c..e12518e 100644
--- a/src/com/android/ex/chips/RecipientEditTextView.java
+++ b/src/com/android/ex/chips/RecipientEditTextView.java
@@ -45,6 +45,8 @@
import android.widget.ListPopupWindow;
import android.widget.MultiAutoCompleteTextView;
+import java.util.ArrayList;
+
/**
* RecipientEditTextView is an auto complete text view for use with applications
* that use the new Chips UI for addressing a message to recipients.
@@ -77,10 +79,13 @@
private int mChipDeleteWidth;
+ private ArrayList<RecipientChip> mRecipients;
+
public RecipientEditTextView(Context context, AttributeSet attrs) {
super(context, attrs);
mHandler = new Handler();
setOnItemClickListener(this);
+ mRecipients = new ArrayList<RecipientChip>();
}
public RecipientChip constructChipSpan(RecipientEntry contact, int offset, boolean pressed)
@@ -284,6 +289,7 @@
int action = event.getAction();
boolean handled = super.onTouchEvent(event);
boolean chipWasSelected = false;
+
if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_DOWN) {
Spannable span = getSpannable();
int offset = getOffsetForPosition(event.getX(), event.getY());
@@ -351,6 +357,18 @@
QwertyKeyListener.markAsReplaced(editable, start, end, "");
}
+ public Editable getRecipients() {
+ StringBuilder plainText = new StringBuilder();
+ int size = mRecipients.size();
+ for (int i = 0; i < size; i++) {
+ plainText.append(mRecipients.get(i).getValue());
+ if (i != size-1) {
+ plainText.append(',');
+ }
+ }
+ return Editable.Factory.getInstance().newEditable(plainText);
+ }
+
/**
* RecipientChip defines an ImageSpan that contains information relevant to
* a particular recipient.
@@ -391,6 +409,7 @@
mAnchorView.setTop(bounds.bottom);
mAnchorView.setBottom(bounds.bottom);
mAnchorView.setVisibility(View.GONE);
+ mRecipients.add(this);
}
public void unselectChip() {
@@ -432,6 +451,7 @@
int spanEnd = getChipEnd();
QwertyKeyListener.markAsReplaced(getText(), spanStart, spanEnd, "");
spannable.removeSpan(this);
+ mRecipients.remove(this);
spannable.setSpan(newChip, spanStart, spanEnd, 0);
}
@@ -442,6 +462,7 @@
QwertyKeyListener.markAsReplaced(getText(), spanStart, spanEnd, "");
spannable.removeSpan(this);
+ mRecipients.remove(this);
spannable.setSpan(null, spanStart, spanEnd, 0);
getText().delete(spanStart, spanEnd);
}