Esempio n. 1
0
 /**
  * Get the list of all the chips in this view
  *
  * @return All the chips in this view
  */
 public ArrayList<Chip> getChips() {
   ArrayList<Chip> ret = new ArrayList<Chip>();
   for (ChipSpan chipSpans :
       Arrays.asList(getText().getSpans(0, getText().length(), ChipSpan.class))) {
     ret.add(chipSpans.getChip());
   }
   return ret;
 }
Esempio n. 2
0
 /**
  * Get a chip for certain text
  *
  * @param text The text to find in a chip
  * @return The chip that matches, or null
  */
 @Nullable
 public Chip getChip(String text) {
   for (ChipSpan chipSpan : getChipSpans()) {
     if (chipSpan.getChip().getText().equals(text)) {
       return chipSpan.getChip();
     }
   }
   return null;
 }
Esempio n. 3
0
 @Override
 public final void beforeTextChanged(CharSequence s, int start, int count, int after) {
   if (after < count) {
     if (s instanceof Spanned) {
       ChipSpan[] removed = ((Spanned) s).getSpans(start, start + count, ChipSpan.class);
       for (ChipSpan removedSpan : removed) {
         onChipRemoved(removedSpan.getChip());
       }
     }
   }
 }
Esempio n. 4
0
 /**
  * Remove the chip from this view
  *
  * @param chip The chip to remove
  * @return Whether or not a chip was removed
  */
 public boolean removeChip(Chip chip) {
   for (ChipSpan chipSpan : getChipSpans()) {
     if (chipSpan.getChip().equals(chip)) {
       int start = getText().getSpanStart(chipSpan);
       Editable editText = getText().replace(start, start + 1, "");
       setText(editText);
       if (mChipChangedListener != null) {
         mChipChangedListener.onChipRemoved(chipSpan.getChip());
       }
       return true;
     }
   }
   return false;
 }