当前位置: 首页>>代码示例>>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;未经允许,请勿转载。