java类android.text.method.QwertyKeyListener的实例源码

TokenCompleteTextView.java 文件源码 项目:TokenAutoComplete 阅读 21 收藏 0 点赞 0 评论 0
@Override
protected void replaceText(CharSequence ignore) {
    clearComposingText();

    // Don't build a token for an empty String
    if (selectedObject == null || selectedObject.toString().equals("")) return;

    TokenImageSpan tokenSpan = buildSpanForObject(selectedObject);

    Editable editable = getText();
    int cursorPosition = getSelectionEnd();
    int end = cursorPosition;
    int start = cursorPosition;
    if (!hintVisible) {
        //If you force the drop down to show when the hint is visible, you can run a completion
        //on the hint. If the hint includes commas, this truncates and inserts the hint in the field
        end = getCorrectedTokenEnd();
        start = getCorrectedTokenBeginning(end);
    }

    String original = TextUtils.substring(editable, start, end);

    //Keep track of  replacements for a bug workaround
    if (original.length() > 0) {
        lastCompletionText = original;
    }

    if (editable != null) {
        if (tokenSpan == null) {
            editable.replace(start, end, "");
        } else if (!allowDuplicates && objects.contains(tokenSpan.getToken())) {
            editable.replace(start, end, "");
            if (listener != null) {
                listener.onDuplicateRemoved(tokenSpan.getToken());
            }
        } else {
            QwertyKeyListener.markAsReplaced(editable, start, end, original);
            SpannableStringBuilder ssb = buildTokenSpannable();
            editable.replace(start, end, ssb);
            editable.setSpan(tokenSpan, start, start + ssb.length() - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
}


问题


面经


文章

微信
公众号

扫码关注公众号