當前位置: 首頁>>代碼示例>>Java>>正文


Java Editable.getSpanEnd方法代碼示例

本文整理匯總了Java中android.text.Editable.getSpanEnd方法的典型用法代碼示例。如果您正苦於以下問題:Java Editable.getSpanEnd方法的具體用法?Java Editable.getSpanEnd怎麽用?Java Editable.getSpanEnd使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.text.Editable的用法示例。


在下文中一共展示了Editable.getSpanEnd方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onSelectionChanged

import android.text.Editable; //導入方法依賴的package包/類
@Override
protected void onSelectionChanged(int handle, int selEnd) {
    super.onSelectionChanged(handle, selEnd);
    Editable text = getText();
    MathSpannable[] spans = text.getSpans(0, text.length(), MathSpannable.class);
    for (MathSpannable span : spans) {
        log("onSelectionChanged " + handle + " " + selEnd);
        int start = text.getSpanStart(span);
        int end = text.getSpanEnd(span);
        if (handle > start && handle < end) {
            log("notifying span(" + span.getEquation() + ") that its cursor is " + (handle - start));
            span.setCursor(handle - start);
        } else {
            log("removing span(" + span.getEquation() + ")'s cursor");
            span.setCursor(-1);
        }
    }
}
 
開發者ID:tranleduy2000,項目名稱:floating_calc,代碼行數:19,代碼來源:CalculatorEditText.java

示例2: afterTextChanged

import android.text.Editable; //導入方法依賴的package包/類
@Override
public void afterTextChanged(Editable s) {
    final RichEditText.TagSpan span = willDelSpan;
    log("TagSpanTextWatcher#willRemove#span:" + (span == null ? "null" : span.toString()));
    if (span != null && span.willRemove) {
        int start = s.getSpanStart(span);
        int end = s.getSpanEnd(span);

        // Remove the span
        s.removeSpan(span);

        // Remove the remaining emoticon text.
        if (start != end) {
            s.delete(start, end);
        }
    }
}
 
開發者ID:hsj-xiaokang,項目名稱:OSchina_resources_android,代碼行數:18,代碼來源:RichEditText.java

示例3: backspace

import android.text.Editable; //導入方法依賴的package包/類
@Override
public void backspace() {
    final int selectionHandle = getSelectionStart();
    final Editable editable = getText();
    if (selectionHandle > 0) {
        MathSpannable[] spans = editable.getSpans(selectionHandle, selectionHandle, MathSpannable.class);
        if (spans.length != 0) {
            String text = editable.toString();
            String textBeforeInsertionHandle = text.substring(0, selectionHandle);
            String textAfterInsertionHandle = text.substring(selectionHandle, text.length());

            int deletionLength = -1;
            if (selectionHandle == editable.getSpanEnd(spans[0]) && spans[0].removeOnBackspace()) {
                deletionLength = spans[0].getEquation().length();
            } else if (selectionHandle != editable.getSpanStart(spans[0])) {
                deletionLength = spans[0].backspace();
            }

            if (deletionLength != -1) {
                String newText = textBeforeInsertionHandle.substring(0, textBeforeInsertionHandle.length() - deletionLength) + textAfterInsertionHandle;
                setText(newText);
                setSelection(selectionHandle - deletionLength);

                return;
            }
        }
    }

    super.backspace();
}
 
開發者ID:tranleduy2000,項目名稱:floating_calc,代碼行數:31,代碼來源:CalculatorEditText.java

示例4: changeRemoveState

import android.text.Editable; //導入方法依賴的package包/類
void changeRemoveState(boolean willRemove, Editable message) {
    if (this.willRemove == willRemove)
        return;
    this.willRemove = willRemove;
    int cacheSpanStart = message.getSpanStart(this);
    int cacheSpanEnd = message.getSpanEnd(this);
    if (cacheSpanStart >= 0 && cacheSpanEnd >= cacheSpanStart) {
        message.setSpan(this, cacheSpanStart, cacheSpanEnd,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
}
 
開發者ID:hsj-xiaokang,項目名稱:OSchina_resources_android,代碼行數:12,代碼來源:RichEditText.java

示例5: onTopicKeyArrived

import android.text.Editable; //導入方法依賴的package包/類
@Override
public boolean onTopicKeyArrived(RichEditText editText) {
    Editable msg = editText.getText();
    String msgStr = msg.toString();
    int selStartIndex = editText.getSelectionStart();
    int selEndIndex = editText.getSelectionEnd();

    if (TextUtils.isEmpty(msgStr.trim()) || selStartIndex <= 0) {
        skipTopic(editText);
        return true;
    }

    int startIndex = 0;
    RichEditText.TagSpan[] spans = msg.getSpans(0, selStartIndex, RichEditText.TagSpan.class);
    if (spans.length > 0) {
        startIndex = msg.getSpanEnd(spans[spans.length - 1]);
    }

    boolean isMatcher = false;
    String tagStr = msgStr.substring(startIndex, selStartIndex) + "#";
    Pattern pattern = Pattern.compile(RichEditText.MATCH_TOPIC);
    Matcher matcher = pattern.matcher(tagStr);
    while (matcher.find()) {
        String str = matcher.group();
        int matcherStart = matcher.start() + startIndex;
        int matcherEnd = matcher.end() + startIndex;
        if (matcherEnd == selStartIndex + 1)
            msg.replace(selStartIndex, selEndIndex, "#");
        msg.setSpan(new RichEditText.TagSpan(str), matcherStart, matcherEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        isMatcher = true;
    }
    if (isMatcher) {
        editText.setSelection(selEndIndex);
        return false;
    }

    skipTopic(editText);
    return true;
}
 
開發者ID:hsj-xiaokang,項目名稱:OSchina_resources_android,代碼行數:40,代碼來源:OnKeyArrivedListenerAdapter.java


注:本文中的android.text.Editable.getSpanEnd方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。