Example usage for android.text SpannableStringBuilder append

List of usage examples for android.text SpannableStringBuilder append

Introduction

In this page you can find the example usage for android.text SpannableStringBuilder append.

Prototype

public SpannableStringBuilder append(char text) 

Source Link

Usage

From source file:it.rainbowbreeze.keepmoving.ui.TimetableActivity.java

/**
 * Updates the text of the notification/*from ww w .  j a  v a  2  s.  co  m*/
 */
private void updateNotification() {
    TimetableModel mModel = mController.getModel();

    // Get an instance of the NotificationManager service
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);

    if (mModel.hasNoRoutes() || mModel.hasInvalidLeavingTimestamp()) {
        notificationManager.cancel(Utils.NOTIFICATION_ID);
        return;
    }

    Route route = mModel.getRoutes().get(0);

    NotificationCompat.BigTextStyle stepsStyle = new NotificationCompat.BigTextStyle()
            .setBigContentTitle(getString(R.string.timetable_msgNotifStepsTitle));
    SpannableStringBuilder sb = new SpannableStringBuilder();
    for (GeoPoint point : route.getSteps()) {
        String line = String.format(getString(R.string.timetable_msgNotifStepsLine),
                point.isValidForAllTime() ? "--" : Utils.getTimeFromTimestamp(point.getValidTime()),
                point.getName(), point.getType().toString());
        sb.append(Html.fromHtml(line));
    }
    stepsStyle.bigText(sb);

    // Notification only for the wear
    Notification stepsNotif = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_launcher)
            .setContentTitle(String.format(getString(R.string.timetable_msgNotifTitle),
                    Utils.getRemainingMinutesToRoute(route)))
            .setContentText(String.format(getString(R.string.timetable_msgNotifContent),
                    Utils.getRemainingMinutesToRoute(route),
                    Utils.getTimeFromTimestamp(route.getArrivalTimestamp())))
            .setStyle(stepsStyle).build();

    WearableExtender extender = new WearableExtender().addPage(stepsNotif)
    //                .setHintHideIcon(true)
    ;

    // Notification displayed on the device
    Notification nextMoveNotif = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_launcher)
            .setContentTitle(String.format(getString(R.string.timetable_msgNotifTitle),
                    Utils.getRemainingMinutesToRoute(route)))
            .setContentText(String.format(getString(R.string.timetable_msgNotifContent),
                    Utils.getRemainingMinutesToRoute(route),
                    Utils.getTimeFromTimestamp(route.getArrivalTimestamp())))
            .extend(extender).build();

    // Build the notification and issues it with notification manager.
    notificationManager.notify(Utils.NOTIFICATION_ID, nextMoveNotif);
}

From source file:org.telegram.ui.GroupCreateActivity.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (fragmentView == null) {
        fragmentView = inflater.inflate(R.layout.group_create_layout, container, false);

        epmtyTextView = (TextView) fragmentView.findViewById(R.id.searchEmptyView);
        userSelectEditText = (EditText) fragmentView.findViewById(R.id.bubble_input_text);
        countTextView = (TextView) fragmentView.findViewById(R.id.bubble_counter_text);
        if (Build.VERSION.SDK_INT >= 11) {
            userSelectEditText.setTextIsSelectable(false);
        }// w w  w . j  a  v a2s. c o  m
        userSelectEditText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int start, int count, int after) {
                if (!ignoreChange) {
                    beforeChangeIndex = userSelectEditText.getSelectionStart();
                    changeString = new SpannableString(charSequence);
                }
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                if (!ignoreChange) {
                    boolean search = false;
                    int afterChangeIndex = userSelectEditText.getSelectionEnd();
                    if (editable.toString().length() < changeString.toString().length()) {
                        String deletedString = "";
                        try {
                            deletedString = changeString.toString().substring(afterChangeIndex,
                                    beforeChangeIndex);
                        } catch (Exception e) {
                            FileLog.e("tmessages", e);
                        }
                        if (deletedString.length() > 0) {
                            if (searching && searchWas) {
                                search = true;
                            }
                            Spannable span = userSelectEditText.getText();
                            for (int a = 0; a < allSpans.size(); a++) {
                                Emoji.XImageSpan sp = allSpans.get(a);
                                if (span.getSpanStart(sp) == -1) {
                                    allSpans.remove(sp);
                                    selectedContacts.remove(sp.uid);
                                }
                            }
                            if (selectedContacts.isEmpty()) {
                                doneTextView.setText(getStringEntry(R.string.Done));
                            } else {
                                doneTextView.setText(
                                        getStringEntry(R.string.Done) + " (" + selectedContacts.size() + ")");
                            }
                            countTextView.setText(selectedContacts.size() + "/200");
                            listView.invalidateViews();
                        } else {
                            search = true;
                        }
                    } else {
                        search = true;
                    }
                    if (search) {
                        String text = userSelectEditText.getText().toString().replace("<", "");
                        if (text.length() != 0) {
                            searchDialogs(text);
                            searching = true;
                            searchWas = true;
                            epmtyTextView.setText(getStringEntry(R.string.NoResult));
                            listViewAdapter.notifyDataSetChanged();
                        } else {
                            searchResult = null;
                            searchResultNames = null;
                            searching = false;
                            searchWas = false;
                            epmtyTextView.setText(getStringEntry(R.string.NoContacts));
                            listViewAdapter.notifyDataSetChanged();
                        }
                    }
                }
            }
        });

        listView = (PinnedHeaderListView) fragmentView.findViewById(R.id.listView);
        listView.setEmptyView(epmtyTextView);
        listView.setVerticalScrollBarEnabled(false);

        listView.setAdapter(listViewAdapter = new ListAdapter(parentActivity));
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                TLRPC.User user;
                int section = listViewAdapter.getSectionForPosition(i);
                int row = listViewAdapter.getPositionInSectionForPosition(i);
                if (searching && searchWas) {
                    user = searchResult.get(row);
                } else {
                    ArrayList<TLRPC.TL_contact> arr = ContactsController.Instance.usersSectionsDict
                            .get(ContactsController.Instance.sortedUsersSectionsArray.get(section));
                    user = MessagesController.Instance.users.get(arr.get(row).user_id);
                    listView.invalidateViews();
                }
                if (selectedContacts.containsKey(user.id)) {
                    Emoji.XImageSpan span = selectedContacts.get(user.id);
                    selectedContacts.remove(user.id);
                    SpannableStringBuilder text = new SpannableStringBuilder(userSelectEditText.getText());
                    text.delete(text.getSpanStart(span), text.getSpanEnd(span));
                    allSpans.remove(span);
                    ignoreChange = true;
                    userSelectEditText.setText(text);
                    userSelectEditText.setSelection(text.length());
                    ignoreChange = false;
                } else {
                    if (selectedContacts.size() == 200) {
                        return;
                    }
                    ignoreChange = true;
                    Emoji.XImageSpan span = createAndPutChipForUser(user);
                    span.uid = user.id;
                    ignoreChange = false;
                }
                if (selectedContacts.isEmpty()) {
                    doneTextView.setText(getStringEntry(R.string.Done));
                } else {
                    doneTextView.setText(getStringEntry(R.string.Done) + " (" + selectedContacts.size() + ")");
                }
                countTextView.setText(selectedContacts.size() + "/200");
                if (searching || searchWas) {
                    searching = false;
                    searchWas = false;
                    epmtyTextView.setText(getStringEntry(R.string.NoContacts));

                    ignoreChange = true;
                    SpannableStringBuilder ssb = new SpannableStringBuilder("");
                    for (ImageSpan sp : allSpans) {
                        ssb.append("<<");
                        ssb.setSpan(sp, ssb.length() - 2, ssb.length(),
                                SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE);
                    }
                    userSelectEditText.setText(ssb);
                    userSelectEditText.setSelection(ssb.length());
                    ignoreChange = false;

                    listViewAdapter.notifyDataSetChanged();
                } else {
                    listView.invalidateViews();
                }
            }
        });
    } else {
        ViewGroup parent = (ViewGroup) fragmentView.getParent();
        if (parent != null) {
            parent.removeView(fragmentView);
        }
    }
    return fragmentView;
}

From source file:org.telegram.ui.GroupCreateActivity.java

public Emoji.XImageSpan createAndPutChipForUser(TLRPC.User user) {
    LayoutInflater lf = (LayoutInflater) parentActivity.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
    View textView = lf.inflate(R.layout.group_create_bubble, null);
    TextView text = (TextView) textView.findViewById(R.id.bubble_text_view);
    text.setText(Utilities.formatName(user.first_name, user.last_name));

    int spec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    textView.measure(spec, spec);//from  ww w. j  a va2  s  . c  om
    textView.layout(0, 0, textView.getMeasuredWidth(), textView.getMeasuredHeight());
    Bitmap b = Bitmap.createBitmap(textView.getWidth(), textView.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(b);
    canvas.translate(-textView.getScrollX(), -textView.getScrollY());
    textView.draw(canvas);
    textView.setDrawingCacheEnabled(true);
    Bitmap cacheBmp = textView.getDrawingCache();
    Bitmap viewBmp = cacheBmp.copy(Bitmap.Config.ARGB_8888, true);
    textView.destroyDrawingCache();

    final BitmapDrawable bmpDrawable = new BitmapDrawable(b);
    bmpDrawable.setBounds(0, 0, b.getWidth(), b.getHeight());

    SpannableStringBuilder ssb = new SpannableStringBuilder("");
    Emoji.XImageSpan span = new Emoji.XImageSpan(bmpDrawable, ImageSpan.ALIGN_BASELINE);
    allSpans.add(span);
    selectedContacts.put(user.id, span);
    for (ImageSpan sp : allSpans) {
        ssb.append("<<");
        ssb.setSpan(sp, ssb.length() - 2, ssb.length(), SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    userSelectEditText.setText(ssb);
    userSelectEditText.setSelection(ssb.length());
    return span;
}

From source file:com.kncwallet.wallet.ui.TransactionsListFragment.java

@Override
public void onViewCreated(final View view, final Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    final SpannableStringBuilder emptyText = new SpannableStringBuilder(
            getString(direction == Direction.SENT ? R.string.wallet_transactions_fragment_empty_text_sent
                    : R.string.wallet_transactions_fragment_empty_text_received));
    emptyText.setSpan(new StyleSpan(Typeface.BOLD), 0, emptyText.length(),
            SpannableStringBuilder.SPAN_POINT_MARK);
    if (direction != Direction.SENT)
        emptyText.append("\n\n").append(getString(R.string.wallet_transactions_fragment_empty_text_howto));

    Drawable divider = getResources().getDrawable(R.drawable.transaction_list_divider);
    this.getListView().setDivider(divider);
    this.getListView().setDividerHeight(1);

    setEmptyText(emptyText);//from   www.  j  ava  2s . c o  m
}

From source file:com.todoroo.astrid.adapter.TaskAdapter.java

private void setupDueDateAndTags(ViewHolder viewHolder, Task task) {
    // due date / completion date
    final TextView dueDateView = viewHolder.dueDate;
    {//from   w ww  .  ja va  2  s  . c  o m
        if (!task.isCompleted() && task.hasDueDate()) {
            long dueDate = task.getDueDate();
            if (task.isOverdue()) {
                dueDateView.setTextColor(textColorOverdue);
            } else {
                dueDateView.setTextColor(textColorSecondary);
            }
            String dateValue = DateUtilities.getRelativeDateStringWithTime(context, dueDate);
            dueDateView.setText(dateValue);
            dueDateView.setVisibility(View.VISIBLE);
        } else if (task.isCompleted()) {
            String dateValue = DateUtilities.getRelativeDateStringWithTime(context, task.getCompletionDate());
            dueDateView.setText(resources.getString(R.string.TAd_completed, dateValue));
            dueDateView.setTextColor(textColorHint);
            dueDateView.setVisibility(View.VISIBLE);
        } else {
            dueDateView.setVisibility(View.GONE);
        }

        if (task.isCompleted()) {
            viewHolder.tagBlock.setVisibility(View.GONE);
        } else {
            String tags = viewHolder.tagsString;
            List<String> tagUuids = tags != null ? newArrayList(tags.split(",")) : Lists.newArrayList();
            Iterable<TagData> t = filter(transform(tagUuids, uuidToTag), Predicates.notNull());
            List<TagData> firstFourByName = orderByName.leastOf(t, 4);
            int numTags = firstFourByName.size();
            if (numTags > 0) {
                List<TagData> firstFourByNameLength = orderByLength.sortedCopy(firstFourByName);
                float maxLength = tagCharacters / numTags;
                for (int i = 0; i < numTags - 1; i++) {
                    TagData tagData = firstFourByNameLength.get(i);
                    String name = tagData.getName();
                    if (name.length() >= maxLength) {
                        break;
                    }
                    float excess = maxLength - name.length();
                    int beneficiaries = numTags - i - 1;
                    float additional = excess / beneficiaries;
                    maxLength += additional;
                }
                List<SpannableString> tagStrings = transform(firstFourByName, tagToString(maxLength));
                SpannableStringBuilder builder = new SpannableStringBuilder();
                for (SpannableString tagString : tagStrings) {
                    if (builder.length() > 0) {
                        builder.append(HAIR_SPACE);
                    }
                    builder.append(tagString);
                }
                viewHolder.tagBlock.setText(builder);
                viewHolder.tagBlock.setVisibility(View.VISIBLE);
            } else {
                viewHolder.tagBlock.setVisibility(View.GONE);
            }
        }
    }
}

From source file:eu.veldsoft.adsbobball.ActivityStateEnum.java

public SpannableStringBuilder formatPerPlayer(String fixed, playstat query) {
    SpannableStringBuilder sps = SpannableStringBuilder.valueOf(fixed);

    for (Player p : gameManager.getCurrGameState().getPlayers()) {
        if (p.getPlayerId() == 0)
            continue;
        SpannableString s = new SpannableString(String.valueOf(query.call(p)) + " ");
        s.setSpan(new ForegroundColorSpan(p.getColor()), 0, s.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        sps.append(s);
    }//from  www  .java  2s . co  m
    return sps;
}

From source file:com.matthewmitchell.peercoin_android_wallet.ui.TransactionsListFragment.java

@Override
public void onLoadFinished(final Loader<List<Transaction>> loader, final List<Transaction> transactions) {
    adapter.replace(transactions);//from  w  w w . j a  va  2 s . c  o  m

    final SpannableStringBuilder emptyText = new SpannableStringBuilder(
            getString(direction == Direction.SENT ? R.string.wallet_transactions_fragment_empty_text_sent
                    : R.string.wallet_transactions_fragment_empty_text_received));
    emptyText.setSpan(new StyleSpan(Typeface.BOLD), 0, emptyText.length(),
            SpannableStringBuilder.SPAN_POINT_MARK);
    if (direction != Direction.SENT)
        emptyText.append("\n\n").append(getString(R.string.wallet_transactions_fragment_empty_text_howto));

    setEmptyText(emptyText);
}

From source file:org.kontalk.ui.GroupInfoFragment.java

private void showIdentityDialog(Contact c, boolean subscribed) {
    final String jid = c.getJID();
    final String dialogFingerprint;
    final String fingerprint;
    final boolean selfJid = Authenticator.isSelfJID(getContext(), jid);
    int titleResId = R.string.title_identity;
    String uid;/*from   w  w w.ja  v  a2 s. co m*/

    PGPPublicKeyRing publicKey = Keyring.getPublicKey(getContext(), jid, MyUsers.Keys.TRUST_UNKNOWN);
    if (publicKey != null) {
        PGPPublicKey pk = PGP.getMasterKey(publicKey);
        String rawFingerprint = PGP.getFingerprint(pk);
        fingerprint = PGP.formatFingerprint(rawFingerprint);

        uid = PGP.getUserId(pk, XmppStringUtils.parseDomain(jid));
        dialogFingerprint = selfJid ? null : rawFingerprint;
    } else {
        // FIXME using another string
        fingerprint = getString(R.string.peer_unknown);
        uid = null;
        dialogFingerprint = null;
    }

    if (Authenticator.isSelfJID(getContext(), jid)) {
        titleResId = R.string.title_identity_self;
    }

    SpannableStringBuilder text = new SpannableStringBuilder();

    if (c.getName() != null && c.getNumber() != null) {
        text.append(c.getName()).append('\n').append(c.getNumber());
    } else {
        int start = text.length();
        text.append(uid != null ? uid : c.getJID());
        text.setSpan(SystemUtils.getTypefaceSpan(Typeface.BOLD), start, text.length(),
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }

    text.append('\n').append(getString(R.string.text_invitation2)).append('\n');

    int start = text.length();
    text.append(fingerprint);
    text.setSpan(SystemUtils.getTypefaceSpan(Typeface.BOLD), start, text.length(),
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    int trustStringId;
    CharacterStyle[] trustSpans;

    if (subscribed) {
        int trustedLevel;
        if (c.isKeyChanged()) {
            // the key has changed and was not trusted yet
            trustedLevel = MyUsers.Keys.TRUST_UNKNOWN;
        } else {
            trustedLevel = c.getTrustedLevel();
        }

        switch (trustedLevel) {
        case MyUsers.Keys.TRUST_IGNORED:
            trustStringId = R.string.trust_ignored;
            trustSpans = new CharacterStyle[] { SystemUtils.getTypefaceSpan(Typeface.BOLD),
                    SystemUtils.getColoredSpan(getContext(), R.color.button_danger) };
            break;

        case MyUsers.Keys.TRUST_VERIFIED:
            trustStringId = R.string.trust_verified;
            trustSpans = new CharacterStyle[] { SystemUtils.getTypefaceSpan(Typeface.BOLD),
                    SystemUtils.getColoredSpan(getContext(), R.color.button_success) };
            break;

        case MyUsers.Keys.TRUST_UNKNOWN:
        default:
            trustStringId = R.string.trust_unknown;
            trustSpans = new CharacterStyle[] { SystemUtils.getTypefaceSpan(Typeface.BOLD),
                    SystemUtils.getColoredSpan(getContext(), R.color.button_danger) };
            break;
        }
    } else {
        trustStringId = R.string.status_notsubscribed;
        trustSpans = new CharacterStyle[] { SystemUtils.getTypefaceSpan(Typeface.BOLD), };
    }

    text.append('\n').append(getString(R.string.status_label));
    start = text.length();
    text.append(getString(trustStringId));
    for (CharacterStyle span : trustSpans)
        text.setSpan(span, start, text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    MaterialDialog.Builder builder = new MaterialDialog.Builder(getContext()).content(text).title(titleResId);

    if (dialogFingerprint != null && subscribed) {
        builder.onAny(new MaterialDialog.SingleButtonCallback() {
            @Override
            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                switch (which) {
                case POSITIVE:
                    // trust the key
                    trustKey(jid, dialogFingerprint, MyUsers.Keys.TRUST_VERIFIED);
                    break;
                case NEUTRAL:
                    // ignore the key
                    trustKey(jid, dialogFingerprint, MyUsers.Keys.TRUST_IGNORED);
                    break;
                case NEGATIVE:
                    // untrust the key
                    trustKey(jid, dialogFingerprint, MyUsers.Keys.TRUST_UNKNOWN);
                    break;
                }
            }
        }).positiveText(R.string.button_accept).positiveColorRes(R.color.button_success)
                .neutralText(R.string.button_ignore).negativeText(R.string.button_refuse)
                .negativeColorRes(R.color.button_danger);
    } else if (!selfJid) {
        builder.onPositive(new MaterialDialog.SingleButtonCallback() {
            @Override
            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                openChat(jid);
            }
        }).positiveText(R.string.button_private_chat);
    }

    builder.show();
}

From source file:com.yahala.ui.GroupCreateActivity.java

public XImageSpan createAndPutChipForUser(TLRPC.User user) {
    LayoutInflater lf = (LayoutInflater) parentActivity.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
    View textView = lf.inflate(R.layout.group_create_bubble, null);
    TextView text = (TextView) textView.findViewById(R.id.bubble_text_view);
    String name = Utilities.formatName(user.first_name, user.last_name);
    if (name.length() == 0 && user.phone != null && user.phone.length() != 0) {
        name = PhoneFormat.getInstance().format("+" + user.phone);
    }/*from   w ww .  j  av  a  2 s  .  c om*/
    text.setText(name + ", ");

    int spec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    textView.measure(spec, spec);
    textView.layout(0, 0, textView.getMeasuredWidth(), textView.getMeasuredHeight());
    Bitmap b = Bitmap.createBitmap(textView.getWidth(), textView.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(b);
    canvas.translate(-textView.getScrollX(), -textView.getScrollY());
    textView.draw(canvas);
    textView.setDrawingCacheEnabled(true);
    Bitmap cacheBmp = textView.getDrawingCache();
    Bitmap viewBmp = cacheBmp.copy(Bitmap.Config.ARGB_8888, true);
    textView.destroyDrawingCache();

    final BitmapDrawable bmpDrawable = new BitmapDrawable(b);
    bmpDrawable.setBounds(0, 0, b.getWidth(), b.getHeight());

    SpannableStringBuilder ssb = new SpannableStringBuilder("");
    XImageSpan span = new XImageSpan(bmpDrawable, ImageSpan.ALIGN_BASELINE);
    allSpans.add(span);
    selectedContacts.put(user.jid, span);
    for (ImageSpan sp : allSpans) {
        ssb.append("<<");
        ssb.setSpan(sp, ssb.length() - 2, ssb.length(), SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    userSelectEditText.setText(ssb);
    userSelectEditText.setSelection(ssb.length());
    return span;
}

From source file:com.yahala.ui.GroupCreateActivity.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (fragmentView == null) {

        searching = false;//  w  w w  .  j a  v  a 2s. c  o  m
        searchWas = false;

        fragmentView = inflater.inflate(R.layout.group_create_layout, container, false);

        emptyTextView = (TextView) fragmentView.findViewById(R.id.searchEmptyView);
        emptyTextView.setText(LocaleController.getString("NoContacts", R.string.NoContacts));
        userSelectEditText = (EditText) fragmentView.findViewById(R.id.bubble_input_text);
        userSelectEditText.setHint(LocaleController.getString("SendMessageTo", R.string.SendMessageTo));
        if (Build.VERSION.SDK_INT >= 11) {
            userSelectEditText.setTextIsSelectable(false);
        }
        userSelectEditText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int start, int count, int after) {
                if (!ignoreChange) {
                    beforeChangeIndex = userSelectEditText.getSelectionStart();
                    changeString = new SpannableString(charSequence);
                }
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                if (!ignoreChange) {
                    boolean search = false;
                    int afterChangeIndex = userSelectEditText.getSelectionEnd();
                    if (editable.toString().length() < changeString.toString().length()) {
                        String deletedString = "";
                        try {
                            deletedString = changeString.toString().substring(afterChangeIndex,
                                    beforeChangeIndex);
                        } catch (Exception e) {
                            FileLog.e("tmessages", e);
                        }
                        if (deletedString.length() > 0) {
                            if (searching && searchWas) {
                                search = true;
                            }
                            Spannable span = userSelectEditText.getText();
                            for (int a = 0; a < allSpans.size(); a++) {
                                XImageSpan sp = allSpans.get(a);
                                if (span.getSpanStart(sp) == -1) {
                                    allSpans.remove(sp);
                                    selectedContacts.remove(sp.jid);
                                }
                            }
                            if (parentActivity != null) {
                                ActionBar actionBar = parentActivity.getSupportActionBar();
                                actionBar.setSubtitle(String.format("%d/200 %s", selectedContacts.size(),
                                        LocaleController.getString("Members", R.string.Members)));
                            }
                            listView.invalidateViews();
                        } else {
                            search = true;
                        }
                    } else {
                        search = true;
                    }
                    if (search) {
                        String text = userSelectEditText.getText().toString().replace("<", "");
                        if (text.length() != 0) {
                            searchDialogs(text);
                            searching = true;
                            searchWas = true;
                            emptyTextView.setText(LocaleController.getString("NoResult", R.string.NoResult));
                            listViewAdapter.notifyDataSetChanged();
                        } else {
                            searchResult = null;
                            searchResultNames = null;
                            searching = false;
                            searchWas = false;
                            emptyTextView
                                    .setText(LocaleController.getString("NoContacts", R.string.NoContacts));
                            listViewAdapter.notifyDataSetChanged();
                        }
                    }
                }
            }
        });

        listView = (PinnedHeaderListView) fragmentView.findViewById(R.id.listView);
        listView.setEmptyView(emptyTextView);
        listView.setVerticalScrollBarEnabled(false);

        listView.setAdapter(listViewAdapter = new ListAdapter(parentActivity));
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                TLRPC.User user;
                int section = listViewAdapter.getSectionForPosition(i);
                int row = listViewAdapter.getPositionInSectionForPosition(i);
                if (searching && searchWas) {
                    user = searchResult.get(row);
                } else {
                    ArrayList<TLRPC.User> arr = com.yahala.xmpp.ContactsController
                            .getInstance().usersSectionsDict.get(
                                    com.yahala.xmpp.ContactsController.getInstance().sortedUsersSectionsArray
                                            .get(section));
                    user = com.yahala.xmpp.ContactsController.getInstance().friendsDict.get(arr.get(row).jid);
                    listView.invalidateViews();
                }
                if (selectedContacts.containsKey(user.jid)) {
                    XImageSpan span = selectedContacts.get(user.jid);
                    selectedContacts.remove(user.jid);
                    SpannableStringBuilder text = new SpannableStringBuilder(userSelectEditText.getText());
                    text.delete(text.getSpanStart(span), text.getSpanEnd(span));
                    allSpans.remove(span);
                    ignoreChange = true;
                    userSelectEditText.setText(text);
                    userSelectEditText.setSelection(text.length());
                    ignoreChange = false;
                } else {
                    if (selectedContacts.size() == 200) {
                        return;
                    }
                    ignoreChange = true;
                    XImageSpan span = createAndPutChipForUser(user);
                    span.jid = user.jid;
                    ignoreChange = false;
                }
                if (parentActivity != null) {
                    ActionBar actionBar = parentActivity.getSupportActionBar();
                    actionBar.setSubtitle(String.format("%d/200 %s", selectedContacts.size(),
                            LocaleController.getString("Members", R.string.Members)));
                }
                if (searching || searchWas) {
                    searching = false;
                    searchWas = false;
                    emptyTextView.setText(LocaleController.getString("NoContacts", R.string.NoContacts));

                    ignoreChange = true;
                    SpannableStringBuilder ssb = new SpannableStringBuilder("");
                    for (ImageSpan sp : allSpans) {
                        ssb.append("<<");
                        ssb.setSpan(sp, ssb.length() - 2, ssb.length(),
                                SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE);
                    }
                    userSelectEditText.setText(ssb);
                    userSelectEditText.setSelection(ssb.length());
                    ignoreChange = false;

                    listViewAdapter.notifyDataSetChanged();
                } else {
                    listView.invalidateViews();
                }
            }
        });
    } else {
        ViewGroup parent = (ViewGroup) fragmentView.getParent();
        if (parent != null) {
            parent.removeView(fragmentView);
        }
    }
    return fragmentView;
}