当前位置: 首页>>代码示例>>Java>>正文


Java Editable.subSequence方法代码示例

本文整理汇总了Java中android.text.Editable.subSequence方法的典型用法代码示例。如果您正苦于以下问题:Java Editable.subSequence方法的具体用法?Java Editable.subSequence怎么用?Java Editable.subSequence使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.text.Editable的用法示例。


在下文中一共展示了Editable.subSequence方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createPasswordSpans

import android.text.Editable; //导入方法依赖的package包/类
private void createPasswordSpans() {
    Editable text = getText();
    for (int start = 0; start < text.length(); start++) {
        int end;
        for (end = start; end < text.length(); end++) {
            if (text.charAt(end) == '\n')
                break;
        }
        CharSequence line = text.subSequence(start, end);

        int passwordStart = getPasswordStart(line.toString());
        if (passwordStart != -1 && (line.length() != passwordStart + 1 ||
                line.charAt(passwordStart) != '-')) {
            String replacedText = getTextWithPasswords(line.subSequence(passwordStart,
                    line.length()));
            getText().replace(start + passwordStart, end, "-");
            getText().setSpan(new PasswordSpan(getContext(), replacedText),
                    start + passwordStart, start + passwordStart + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            start = start + passwordStart + 2;
            continue;
        }
        start = end;
    }
}
 
开发者ID:MCMrARM,项目名称:revolution-irc,代码行数:25,代码来源:AutoRunCommandListEditText.java

示例2: replaceEmoticons

import android.text.Editable; //导入方法依赖的package包/类
public static void replaceEmoticons(Context context, Editable editable, int start, int count) {
	if (count <= 0 || editable.length() < start + count) 
		return;
	
	CharSequence s = editable.subSequence(start, start + count);
	Matcher matcher = EmojiManager.getPattern().matcher(s);
	while (matcher.find()) {
		int from = start + matcher.start();
		int to = start + matcher.end();
		String emot = editable.subSequence(from, to).toString();
		Drawable d = getEmotDrawable(context, emot, SMALL_SCALE);
		if (d != null) {
			ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BOTTOM);
			editable.setSpan(span, from, to, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
		}
	}
}
 
开发者ID:newDeepLearing,项目名称:decoy,代码行数:18,代码来源:MoonUtil.java

示例3: prepareSpans

import android.text.Editable; //导入方法依赖的package包/类
/**
 * Ensures that a {@link CategorySpan} is in {@param textToSpannify} if required.
 * Will firstly remove all existing category spans, and then add back one if neccesary.
 * In addition, also adds a {@link TtsSpan} to indicate to screen readers that the category
 * span has semantic meaning representing a category.
 */
@TargetApi(21)
private void prepareSpans(Editable textToSpannify) {
    if (textToSpannify == null) {
        return;
    }

    removeSpans(textToSpannify, CategorySpan.class);
    if (Build.VERSION.SDK_INT >= 21) {
        removeSpans(textToSpannify, TtsSpan.class);
    }

    int colonIndex = textToSpannify.toString().indexOf(':');
    if (colonIndex > 0) {
        CategorySpan span = new CategorySpan(context);
        textToSpannify.setSpan(span, 0, colonIndex + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

        if (Build.VERSION.SDK_INT >= 21) {
            // For accessibility reasons, make this more clear to screen readers that the
            // span we just added semantically represents a category.
            CharSequence categoryName = textToSpannify.subSequence(0, colonIndex);
            TtsSpan ttsSpan = new TtsSpan.TextBuilder(context.getString(R.string.tts_category_name,
                    categoryName)).build();
            textToSpannify.setSpan(ttsSpan, 0, 0, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:33,代码来源:CategoryTextWatcher.java

示例4: extractSpanText

import android.text.Editable; //导入方法依赖的package包/类
/**
 * Returns the text contained within a span and deletes it from the output string
 */
private CharSequence extractSpanText(Editable output, Class kind) {
    final Object obj = getLast(output, kind);
    // start of the tag
    final int where = output.getSpanStart(obj);
    // end of the tag
    final int len = output.length();

    final CharSequence extractedSpanText = output.subSequence(where, len);
    output.delete(where, len);
    return extractedSpanText;
}
 
开发者ID:RanKKI,项目名称:PSNine,代码行数:15,代码来源:HtmlTagHandler.java

示例5: getPrevLine

import android.text.Editable; //导入方法依赖的package包/类
/**
 * @return the line above current cursor
 */
@Nullable
private CharSequence getPrevLine(Editable editable, Layout layout, int currentLine) {
    if (currentLine - 1 < 0) return null;
    int lineStart = layout.getLineStart(currentLine - 1);
    int lineEnd = layout.getLineEnd(currentLine - 1);
    return editable.subSequence(lineStart, lineEnd);
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:11,代码来源:IndentEditText.java

示例6: getNextLine

import android.text.Editable; //导入方法依赖的package包/类
@Nullable
protected CharSequence getNextLine(Editable editable, Layout layout, int currentLine) {
    if (currentLine + 1 > layout.getLineCount() - 1) return null;
    int lineStart = layout.getLineStart(currentLine + 1);
    int lineEnd = layout.getLineEnd(currentLine + 1);
    return editable.subSequence(lineStart, lineEnd);
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:8,代码来源:IndentEditText.java

示例7: getWordInCursor

import android.text.Editable; //导入方法依赖的package包/类
@Nullable
protected CharSequence getWordInCursor() {
    int pos = getSelectionStart();
    if (pos == -1) return "";
    Editable editableText = getEditableText();
    int start = pos, end = pos;
    while (start > 0 && Character.isLetterOrDigit(editableText.charAt(start))) start--;
    while (end < editableText.length() && Character.isLetterOrDigit(editableText.charAt(start)))
        end++;
    return editableText.subSequence(start, end);
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:12,代码来源:IndentEditText.java

示例8: highlight

import android.text.Editable; //导入方法依赖的package包/类
public void highlight(boolean newText) {
    if (mHighlighter == null) return;
    Editable editable = getText();
    if (editable.length() == 0) return;

    int editorHeight = getHeightVisible();

    int firstVisibleIndex;
    int lastVisibleIndex;
    if (!newText && editorHeight > 0) {
        if (verticalScroll != null && getLayout() != null) {
            firstVisibleIndex = getLayout().getLineStart(Math.max(0, getFirstLineIndex() - 3));
        } else {
            firstVisibleIndex = 0;
        }
        if (verticalScroll != null && getLayout() != null) {
            lastVisibleIndex = getLayout().getLineStart(Math.min(getLayout().getLineCount() - 1, getLastLineIndex() + 3));
        } else {
            lastVisibleIndex = getText().length();
        }
    } else {
        firstVisibleIndex = 0;
        lastVisibleIndex = CHARS_TO_COLOR;
    }
    // normalize
    if (firstVisibleIndex < 0) firstVisibleIndex = 0;
    if (lastVisibleIndex > editable.length()) lastVisibleIndex = editable.length();
    if (firstVisibleIndex > lastVisibleIndex) firstVisibleIndex = lastVisibleIndex;

    //clear all span for firstVisibleIndex to lastVisibleIndex
    clearSpans(editable, firstVisibleIndex, lastVisibleIndex);

    CharSequence textToHighlight = editable.subSequence(firstVisibleIndex, lastVisibleIndex);
    mHighlighter.highlight(editable, textToHighlight, firstVisibleIndex);
    applyTabWidth(editable, firstVisibleIndex, lastVisibleIndex);
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:37,代码来源:HighlightEditor.java

示例9: afterTextChanged

import android.text.Editable; //导入方法依赖的package包/类
/**
 * @param editable 变化后的Editable
 * @param start    text 变化区块的起始index
 * @param count    text 变化区块的大小
 * @param delete   是否是删除
 */
private void afterTextChanged(Editable editable, int start, int count, boolean delete) {
    curPos = delete ? start : count + start;
    if (ignoreTextChange) {
        return;
    }
    if (delete) {
        int before = start + count;
        if (deleteSegment(before, count)) {
            return;
        }
        aitContactsModel.onDeleteText(before, count);

    } else {
        if (count <= 0 || editable.length() < start + count) {
            return;
        }
        CharSequence s = editable.subSequence(start, start + count);
        if (s == null) {
            return;
        }
        if (s.toString().equals("@")) {
            // 启动@联系人界面
            AitContactSelectorActivity.start(context, tid, robot);
        }
        aitContactsModel.onInsertText(start, s.toString());
    }
}
 
开发者ID:newDeepLearing,项目名称:decoy,代码行数:34,代码来源:AitManager.java

示例10: acceptSpace

import android.text.Editable; //导入方法依赖的package包/类
public boolean acceptSpace(int space) {
    // This can happen, I don't know, let's consume.
    if (!mView.isLaidOut()) return true;

    String logPrefix = logPrefix();
    // Returning FALSE means that the pager will try to:
    // 1. Pass the first view of this page to the previous page
    //    ^ FIXED THIS IN THE PAGER. It won't happen.
    // 2. Accept the first view of the nextView page at the end of this page
    //
    // So if we are not last(), we must ensure we never return FALSE.
    // That is, if !isLast(), return true. This is well handler here.

    int height = mView.getLayout().getHeight();
    int target = height + space;
    LOG.w(logPrefix, "acceptSpace:", "asked to accept:", space, "height:", height, "target:", target);
    if (isLast()) {
        // No one to accept from. We can safely return false. The pager will not try to move
        // us to the previous page, due to specific behavior for AutoSplitViews.
        LOG.w(logPrefix, "acceptSpace:", "quick end because we are the last. Returning false");
        return false;
    }

    if (mPost.length() == 0) {
        // Next view is empty. Remove it and try again with the following. Should be null though.
        LOG.w(logPrefix, "acceptSpace:", "quick end: nextView view empty, removing.");
        removeFromChain(mPost);
        return acceptSpace(space);
    }

    setActionInProgress(true);
    Editable source = edit(mPost);
    Editable dest = edit(mView);
    Pattern pattern = Pattern.compile("\\s"); // TODO: We only support ' ' and '\n', don't catch others
    CharSequence word = "";
    int wordCount = 0;
    while (mView.getLayout().getHeight() <= target) {
        if (source.length() == 0) break;
        Matcher matcher = pattern.matcher(source);
        int end;
        if (matcher.find()) {
            end = matcher.end();
            if (end > 1 && source.charAt(end - 1) == '\n') {
                end--;
            }
        } else {
            end = source.length();
        }
        word = source.subSequence(0, end);
        LOG.v(logPrefix, "acceptSpace:", "Found!", "end:", end, "word:(" + word + ")");
        source.replace(0, end, "");
        dest.append(word);
        wordCount++;
    }

    // The while loops ends when the source is empty, or when we took to much.
    if (mView.getLayout().getHeight() > target) {
        LOG.i(logPrefix, "acceptSpace:", "Out of the loop. We took to much. Returning word:", word);
        dest.replace(dest.length() - word.length(), dest.length(), "");
        source.insert(0, word);
        wordCount--;
    }

    setActionInProgress(false);
    if (mPost.length() == 0) {
        LOG.w(logPrefix, "acceptSpace:", "We took everything from post view. Removing.", next().isLast());
        // View is empty. Remove it, and try again with the nextView mPost.
        // This is a bit flaky, I should think more about it.
        removeFromChain(mPost);
        int remaining = target - mView.getLayout().getHeight(); // >= 0
        return acceptSpace(remaining);
    } else {
        // Post is not empty, but if we take something else, we take too much.
        // I would say that we can return true here.
        LOG.i(logPrefix, "acceptSpace:", "ENDED.", "words:", wordCount, "finalHeight:", mView.getLayout().getHeight());
        return true;
    }
}
 
开发者ID:natario1,项目名称:ViewPrinter,代码行数:79,代码来源:AutoSplitTextHelper.java


注:本文中的android.text.Editable.subSequence方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。