Example usage for android.text Editable subSequence

List of usage examples for android.text Editable subSequence

Introduction

In this page you can find the example usage for android.text Editable subSequence.

Prototype

CharSequence subSequence(int start, int end);

Source Link

Document

Returns a CharSequence that is a subsequence of this sequence.

Usage

From source file:com.ruesga.rview.widget.TagEditTextView.java

private void performComputeChipsLocked(Editable s) {
    // If we are removing skip chip creation code
    if (mLockEdit) {
        return;//w  w w  . j  a  v a2 s  .  c o  m
    }

    // Check if we need to create a new chip
    mLockEdit = true;
    try {
        String text = s.toString();
        int textLength = text.length();
        boolean isCreateChip = false;
        boolean nextIsTag = false;
        if (textLength > 0) {
            String lastChar = text.substring(textLength - 1);
            if (lastChar.charAt(0) != VALID_TAGS.charAt(1) || mSupportsUserTags) {
                isCreateChip = NON_UNICODE_CHAR_PATTERN.matcher(lastChar).matches();
                nextIsTag = VALID_TAGS.contains(lastChar);
            }
        }
        if (isCreateChip || nextIsTag) {
            createChip(s, nextIsTag);
            notifyComputeTagEnded();
        } else if (mTriggerTagCreationThreshold > 0) {
            int start = mTagList.size();
            String tagText = s.subSequence(start, textLength).toString().trim();
            if (tagText.length() >= CREATE_CHIP_LENGTH_THRESHOLD) {
                mHandler.removeMessages(MESSAGE_CREATE_CHIP);
                mHandler.sendMessageDelayed(mHandler.obtainMessage(MESSAGE_CREATE_CHIP),
                        mTriggerTagCreationThreshold);
            }
        }
    } finally {
        mLockEdit = false;
    }
}

From source file:org.zywx.wbpalmstar.plugin.chatkeyboard.ACEChatKeyboardView.java

private void jsonSendDataJsonCallback() {
    // TODO send callback Json
    if (mUexBaseObj != null) {
        JSONObject jsonObject = new JSONObject();
        try {// ww w  . j av  a  2s . c om
            Editable editable = mEditText.getText();
            jsonObject.put(EChatKeyboardUtils.CHATKEYBOARD_PARAMS_JSON_KEY_EMOJICONS_TEXT, editable.toString());
            JSONArray array = new JSONArray();
            ForegroundColorSpan[] spans = editable.getSpans(0, editable.length(), ForegroundColorSpan.class);
            for (ForegroundColorSpan span : spans) {
                JSONObject insertObj = new JSONObject();
                int spanStart = editable.getSpanStart(span);
                int spanEnd = editable.getSpanEnd(span);
                String insertText = editable.subSequence(spanStart, spanEnd).toString();
                String insertTextColor = "#" + Integer.toHexString(span.getForegroundColor()).substring(2);
                insertObj.put(EChatKeyboardUtils.CHATKEYBOARD_PARAMS_JSON_KEY_START, spanStart);
                insertObj.put(EChatKeyboardUtils.CHATKEYBOARD_PARAMS_JSON_KEY_END, spanEnd);
                insertObj.put(EChatKeyboardUtils.CHATKEYBOARD_PARAMS_JSON_KEY_INSERTTEXT, insertText);
                insertObj.put(EChatKeyboardUtils.CHATKEYBOARD_PARAMS_JSON_KEY_INSERTTEXTCOLOR, insertTextColor);
                array.put(insertObj);
            }
            jsonObject.put(EChatKeyboardUtils.CHATKEYBOARD_PARAMS_JSON_KEY_INSERTTEXTS, array);
            String js = EUExChatKeyboard.SCRIPT_HEADER + "if("
                    + EChatKeyboardUtils.CHATKEYBOARD_FUN_ON_COMMIT_JSON + "){"
                    + EChatKeyboardUtils.CHATKEYBOARD_FUN_ON_COMMIT_JSON + "(" + jsonObject.toString() + ");}";
            mUexBaseObj.onCallback(js);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:com.android.ex.chips.RecipientEditTextView.java

void createMoreChipPlainText() {
    // Take the first <= CHIP_LIMIT addresses and get to the end of the second one.
    final Editable text = getText();
    int start = 0;
    int end = start;
    for (int i = 0; i < CHIP_LIMIT; i++) {
        end = movePastTerminators(mTokenizer.findTokenEnd(text, start));
        start = end; // move to the next token and get its end.
    }//w  w w.  j  a v a 2s  .  c o m
    // Now, count total addresses.
    start = 0;
    final int tokenCount = countTokens(text);
    final MoreImageSpan moreSpan = createMoreSpan(tokenCount - CHIP_LIMIT);
    final SpannableString chipText = new SpannableString(text.subSequence(end, text.length()));
    chipText.setSpan(moreSpan, 0, chipText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    text.replace(end, text.length(), chipText);
    mMoreChip = moreSpan;
}

From source file:com.android.ex.chips.RecipientEditTextView.java

/**
 * Create the more chip. The more chip is text that replaces any chips that do not fit in the pre-defined available
 * space when the RecipientEditTextView loses focus.
 *///from w  w w .  ja v a2 s  .  co m
// Visible for testing.
/* package */void createMoreChip() {
    if (mNoChips) {
        createMoreChipPlainText();
        return;
    }
    if (!mShouldShrink)
        return;
    final ImageSpan[] tempMore = getSpannable().getSpans(0, getText().length(), MoreImageSpan.class);
    if (tempMore.length > 0)
        getSpannable().removeSpan(tempMore[0]);
    final DrawableRecipientChip[] recipients = getSortedRecipients();
    if (recipients == null || recipients.length <= CHIP_LIMIT) {
        mMoreChip = null;
        return;
    }
    final Spannable spannable = getSpannable();
    final int numRecipients = recipients.length;
    final int overage = numRecipients - CHIP_LIMIT;
    final MoreImageSpan moreSpan = createMoreSpan(overage);
    mRemovedSpans = new ArrayList<DrawableRecipientChip>();
    int totalReplaceStart = 0;
    int totalReplaceEnd = 0;
    final Editable text = getText();
    for (int i = numRecipients - overage; i < recipients.length; i++) {
        mRemovedSpans.add(recipients[i]);
        if (i == numRecipients - overage)
            totalReplaceStart = spannable.getSpanStart(recipients[i]);
        if (i == recipients.length - 1)
            totalReplaceEnd = spannable.getSpanEnd(recipients[i]);
        if (mTemporaryRecipients == null || !mTemporaryRecipients.contains(recipients[i])) {
            final int spanStart = spannable.getSpanStart(recipients[i]);
            final int spanEnd = spannable.getSpanEnd(recipients[i]);
            recipients[i].setOriginalText(text.toString().substring(spanStart, spanEnd));
        }
        spannable.removeSpan(recipients[i]);
    }
    if (totalReplaceEnd < text.length())
        totalReplaceEnd = text.length();
    final int end = Math.max(totalReplaceStart, totalReplaceEnd);
    final int start = Math.min(totalReplaceStart, totalReplaceEnd);
    final SpannableString chipText = new SpannableString(text.subSequence(start, end));
    chipText.setSpan(moreSpan, 0, chipText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    text.replace(start, end, chipText);
    mMoreChip = moreSpan;
    // If adding the +more chip goes over the limit, resize accordingly.
    if (!isPhoneQuery() && getLineCount() > mMaxLines)
        setMaxLines(getLineCount());
}