From 2c0ca1809ebc46afccf2e0e67b98a815aafd19a6 Mon Sep 17 00:00:00 2001 From: Raj Yengisetty Date: Mon, 6 Apr 2015 18:09:12 -0700 Subject: Chips: Add a view attribute for maximum number of chips parsed Additionally add a dynamic way to set maxChipsParsed Change-Id: I8e88d4268b8e2ecc6de26d8cf69a985821c8e9f0 (cherry picked from commit c274746186af89f4c11499771678696d18158476) --- res/values/attrs.xml | 3 ++- .../android/ex/chips/RecipientEditTextView.java | 29 +++++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/res/values/attrs.xml b/res/values/attrs.xml index d3500aa..7803de0 100644 --- a/res/values/attrs.xml +++ b/res/values/attrs.xml @@ -31,5 +31,6 @@ + - \ No newline at end of file + diff --git a/src/com/android/ex/chips/RecipientEditTextView.java b/src/com/android/ex/chips/RecipientEditTextView.java index fe814da..8a979a9 100644 --- a/src/com/android/ex/chips/RecipientEditTextView.java +++ b/src/com/android/ex/chips/RecipientEditTextView.java @@ -156,6 +156,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements private boolean mDisableDelete; private int mMaxLines; private int mActionBarHeight; + private int mMaxChipsParsed; /** * Enumerator for avatar position. See attr.xml for more details. @@ -963,6 +964,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements mActionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, getResources() .getDisplayMetrics()); } + mMaxChipsParsed = a.getInt(R.styleable.RecipientEditTextView_maxChips, MAX_CHIPS_PARSED); a.recycle(); } @@ -1057,7 +1059,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements synchronized (mPendingChips) { Editable editable = getText(); // Tokenize! - if (mPendingChipsCount <= MAX_CHIPS_PARSED) { + if (mPendingChipsCount <= mMaxChipsParsed) { for (int i = 0; i < mPendingChips.size(); i++) { String current = mPendingChips.get(i); int tokenStart = editable.toString().indexOf(current); @@ -3133,4 +3135,29 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements float right; float bottom; } + + /** + * Get the current max chips limits. + * @return The value used to cap the number of contacts that this field will tokenize. + */ + protected int getMaxChipsParsed() { + return mMaxChipsParsed; + } + + /** + * Set the current max chips limit. + * @param maxChipsParsed - This value will cap the number of contacts that this field will + * tokenize. + */ + protected void setMaxChipsParsed(int maxChipsParsed) { + mMaxChipsParsed = maxChipsParsed; + } + + /** + * Get whether we are still tokenizing input + * @return true if still tokenizing contacts, false otherwise + */ + protected boolean isChipping() { + return !mNoChips; + } } -- cgit v1.2.3