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


Java Editable.setSpan方法代码示例

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


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

示例1: handleIgnoredTag

import android.text.Editable; //导入方法依赖的package包/类
/**
 * When we come upon an ignored tag, we mark it with an Annotation object with a specific key
 * and value as above. We don't really need to be checking these values since Html.fromHtml()
 * doesn't use Annotation spans, but we should do it now to be safe in case they do start using
 * it in the future.
 * @param opening If this is an opening tag or not.
 * @param output Spannable string that we're working with.
 */
private void handleIgnoredTag(boolean opening, Editable output) {
    int len = output.length();
    if (opening) {
        output.setSpan(new Annotation(IGNORED_ANNOTATION_KEY, IGNORED_ANNOTATION_VALUE), len,
                       len, Spannable.SPAN_MARK_MARK);
    } else {
        Object start = getOpeningAnnotation(output);
        if (start != null) {
            int where = output.getSpanStart(start);
            // Remove the temporary Annotation span.
            output.removeSpan(start);
            // Delete everything between the start of the Annotation and the end of the string
            // (what we've generated so far).
            output.delete(where, len);
        }
    }
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:26,代码来源:HtmlConverter.java

示例2: setItalic

import android.text.Editable; //导入方法依赖的package包/类
void setItalic(boolean isItalic, int index) {
    if (index >= 0 && index < mSections.size()) {
        mSections.get(index).setItalic(isItalic);
    }
    Editable edit = getEditableText();
    int star = getSectionStart();
    int end = getSectionEnd();
    if (isItalic) {
        edit.setSpan(new StyleSpan(Typeface.ITALIC),
                star,
                end,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    } else {
        StyleSpan[] styleSpans = edit.getSpans(star,
                end, StyleSpan.class);
        for (CharacterStyle span : styleSpans) {
            if (span instanceof StyleSpan && ((StyleSpan) span).getStyle() == Typeface.ITALIC)
                edit.removeSpan(span);
        }
    }
}
 
开发者ID:hsj-xiaokang,项目名称:OSchina_resources_android,代码行数:22,代码来源:RichEditText.java

示例3: createSpanForMatchesP

import android.text.Editable; //导入方法依赖的package包/类
/**
 * Create Span for matches in paragraph's. Note that this will highlight the full matched pattern
 * (including optionals) if no group parameters are given.
 *
 * @param editable      Text editable
 * @param pattern       The pattern to match
 * @param creator       A ParcelableSpanCreator for ParcelableSpan
 * @param groupsToMatch (optional) groups to be matched, indexes start at 1.
 */
protected void createSpanForMatchesP(final Editable editable, final Pattern pattern, final ParagraphStyleCreator creator, int... groupsToMatch) {
    if (groupsToMatch == null || groupsToMatch.length < 1) {
        groupsToMatch = new int[]{0};
    }
    int i = 0;
    for (Matcher m = pattern.matcher(editable); m.find(); i++) {
        ParagraphStyle span = creator.create(m, i);
        if (span != null) {
            for (int g : groupsToMatch) {
                if (g == 0 || g <= m.groupCount()) {
                    editable.setSpan(span, m.start(g), m.end(g), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                }
            }
        }
    }
}
 
开发者ID:gsantner,项目名称:markor,代码行数:26,代码来源:Highlighter.java

示例4: handleTag

import android.text.Editable; //导入方法依赖的package包/类
@Override
public void handleTag(final boolean opening, final String tag, Editable output, final XMLReader xmlReader) {

    if (tag.equals("ul") || tag.equals("ol") || tag.equals("dd")) {
        if (opening) {
            mListParents.add(tag);
        } else mListParents.remove(tag);

        mListItemCount = 0;
    } else if (tag.equals("li") && !opening) {
        handleListTag(output);
    }
    else if(tag.equalsIgnoreCase("code")) {
        if(opening) {
            output.setSpan(new TypefaceSpan("monospace"), output.length(), output.length(), Spannable.SPAN_MARK_MARK);
        } else {
            Log.d("COde Tag","Code tag encountered");
            Object obj = getLast(output, TypefaceSpan.class);
            int where = output.getSpanStart(obj);

            output.setSpan(new TypefaceSpan("monospace"), where, output.length(), 0);
        }
    }

}
 
开发者ID:afiqiqmal,项目名称:My-Android-Base-Code,代码行数:26,代码来源:HtmlTagHandler.java

示例5: setMidLine

import android.text.Editable; //导入方法依赖的package包/类
/**
 * 中横线,即删除线
 *
 * @param isMidLine isMidLine
 */
void setMidLine(boolean isMidLine, int index) {
    if (index >= 0 && index < mSections.size()) {
        mSections.get(index).setMidLine(isMidLine);
    }
    Editable edit = getEditableText();
    int star = getSectionStart();
    int end = getSectionEnd();
    if (isMidLine) {
        edit.setSpan(new StrikethroughSpan(),
                star,
                end,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    } else {
        StrikethroughSpan[] styleSpans = edit.getSpans(star,
                end, StrikethroughSpan.class);
        for (StrikethroughSpan span : styleSpans) {
            edit.removeSpan(span);
        }
    }
}
 
开发者ID:hsj-xiaokang,项目名称:OSchina_resources_android,代码行数:26,代码来源:RichEditText.java

示例6: setBold

import android.text.Editable; //导入方法依赖的package包/类
void setBold(boolean isBold) {
    int index = getSelectionIndex();
    if (index >= 0 && index < mSections.size()) {
        mSections.get(index).setBold(isBold);
    }
    Editable edit = getEditableText();
    int star = getSectionStart();
    int end = getSectionEnd();
    if (isBold) {
        edit.setSpan(new StyleSpan(Typeface.BOLD),
                star,
                end,
                Typeface.BOLD);
    } else {
        StyleSpan[] styleSpans = edit.getSpans(star,
                end, StyleSpan.class);
        for (CharacterStyle span : styleSpans) {
            if (span instanceof StyleSpan && ((StyleSpan) span).getStyle() == Typeface.BOLD)
                edit.removeSpan(span);
        }
    }
}
 
开发者ID:hsj-xiaokang,项目名称:OSchina_resources_android,代码行数:23,代码来源:RichEditText.java

示例7: setTextSizeSpan

import android.text.Editable; //导入方法依赖的package包/类
private void setTextSizeSpan(int textSize, int index) {
    Editable edit = getEditableText();
    int star = getSectionStart(index);
    int end = getSectionEnd(index);
    if (star >= end)
        return;
    AbsoluteSizeSpan[] styleSpans = edit.getSpans(star, end, AbsoluteSizeSpan.class);
    for (AbsoluteSizeSpan span : styleSpans) {
        edit.removeSpan(span);
    }
    edit.setSpan(new AbsoluteSizeSpan(UI.dipToPx(getContext(), textSize)), star, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
 
开发者ID:hsj-xiaokang,项目名称:OSchina_resources_android,代码行数:13,代码来源:RichEditText.java

示例8: 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

示例9: endCode

import android.text.Editable; //导入方法依赖的package包/类
private void endCode(Editable output, XMLReader xmlReader) {
    output.append(" ");
    int code_end = output.length();
    output.setSpan(new ForegroundColorSpan(Color.parseColor("#f44336")), code_start, code_end, Spannable.SPAN_MARK_MARK);
    output.setSpan(new BackgroundColorSpan(Color.parseColor("#ffebee")), code_start, code_end, Spannable.SPAN_MARK_MARK);
    //output.append(" ");
}
 
开发者ID:GitaiQAQ,项目名称:AboutView,代码行数:8,代码来源:BaseCustomTagHandler.java

示例10: find

import android.text.Editable; //导入方法依赖的package包/类
/**
 * highlight find word
 *
 * @param what     - input
 * @param regex    - is java regex
 * @param wordOnly - find word only
 */
public void find(String what, boolean regex, boolean wordOnly, boolean matchCase) {
    Pattern pattern;
    if (regex) {
        if (matchCase) {
            pattern = Pattern.compile(what);
        } else {
            pattern = Pattern.compile(what, Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE);
        }
    } else {
        if (wordOnly) {
            if (matchCase) {
                pattern = Pattern.compile("\\s" + what + "\\s");
            } else {
                pattern = Pattern.compile("\\s" + Pattern.quote(what) + "\\s", Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE);
            }
        } else {
            if (matchCase) {
                pattern = Pattern.compile(Pattern.quote(what));
            } else {
                pattern = Pattern.compile(Pattern.quote(what), Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE);
            }
        }
    }
    Editable e = getEditableText();
    //remove all span
    BackgroundColorSpan spans[] = e.getSpans(0, e.length(), BackgroundColorSpan.class);
    for (int n = spans.length; n-- > 0; )
        e.removeSpan(spans[n]);
    //set span

    for (Matcher m = pattern.matcher(e); m.find(); ) {
        e.setSpan(new BackgroundColorSpan(codeTheme.getErrorColor()),
                m.start(),
                m.end(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:45,代码来源:HighlightEditor.java

示例11: 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

示例12: highlightOther

import android.text.Editable; //导入方法依赖的package包/类
private void highlightOther(@NonNull Editable allText,
                                @NonNull CharSequence textToHighlight, int start) {
        //high light number
        for (Matcher m = DECIMAL_NUMBERS.matcher(textToHighlight); m.find(); ) {
            allText.setSpan(new ForegroundColorSpan(codeTheme.getNumberColor()),
                    start + m.start(),
                    start + m.end(),
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        for (Matcher m = JAVA_KEYWORDS.matcher(textToHighlight); m.find(); ) {
            allText.setSpan(new ForegroundColorSpan(codeTheme.getKeywordColor()),
                    start + m.start(),
                    start + m.end(),
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            allText.setSpan(new StyleSpan(Typeface.BOLD),
                    start + m.start(),
                    start + m.end(),
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
//
//        for (Matcher m = SYMBOLS.matcher(textToHighlight); m.find(); ) {
//            allText.setSpan(new ForegroundColorSpan(codeTheme.getOptColor()),
//                    start + m.start(),
//                    start + m.end(),
//                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
//        }
    }
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:28,代码来源:JavaHighlighter.java

示例13: findOpen

import android.text.Editable; //导入方法依赖的package包/类
private void findOpen(char close, int selEnd) {
    Editable text = editText.getText();
    int cursor = selEnd - 1;
    int count = 1;
    boolean find = false;
    char open = getOpen(close);

    while (cursor > 0) {
        char chatAtCursor = text.charAt(cursor);
        if (chatAtCursor == open) {
            count--;
        } else if (chatAtCursor == close) {
            count++;
        }
        if (count == 0) {
            find = true;
            break;
        }
        cursor--;
    }
    BracketSpan[] spans = text.getSpans(0, text.length(), BracketSpan.class);
    for (BracketSpan span : spans) {
        text.removeSpan(span);
    }
    text.setSpan(new BracketSpan(codeTheme.getBracketColor(),
            codeTheme.getTextColor()), selEnd, selEnd + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    if (find) {
        text.setSpan(new BracketSpan(codeTheme.getBracketColor(),
                codeTheme.getTextColor()), cursor, cursor + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:32,代码来源:BracketHighlighter.java

示例14: highlight

import android.text.Editable; //导入方法依赖的package包/类
@Override
public void highlight(@NonNull Editable allText, @NonNull CharSequence textToHighlight, int start) {
    mCommentRegion.clear();
    for (Matcher m = JAVA_COMMENTS.matcher(textToHighlight); m.find(); ) {
        allText.setSpan(new ForegroundColorSpan(codeTheme.getCommentColor()),
                start + m.start(),
                start + m.end(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        mCommentRegion.add(new Pair<>(start + m.start(), start + m.end()));
    }
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:12,代码来源:JavaCommentHighlighter.java

示例15: setColorSpan

import android.text.Editable; //导入方法依赖的package包/类
void setColorSpan(int color, int index) {
    Editable edit = getEditableText();
    int star = getSectionStart(index);
    int end = getSectionEnd(index);
    if (star >= end)
        return;
    ForegroundColorSpan[] styleSpans = edit.getSpans(star, end, ForegroundColorSpan.class);
    for (ForegroundColorSpan span : styleSpans) {
        edit.removeSpan(span);
    }
    edit.setSpan(new ForegroundColorSpan(color), star, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
 
开发者ID:hsj-xiaokang,项目名称:OSchina_resources_android,代码行数:13,代码来源:RichEditText.java


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