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


Java Spannable.removeSpan方法代码示例

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


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

示例1: findStartPosition

import android.text.Spannable; //导入方法依赖的package包/类
/**
 * 检查当前位置是否命中在spannable上, 如果是, 返回spannable的start position
 */
private int findStartPosition(Spannable spannable, int startWidthPosition) {
    CharacterStyle[] oldSpans = spannable.getSpans(startWidthPosition, spannable.length(), CharacterStyle.class);
    int position = startWidthPosition;
    for (CharacterStyle oldSpan : oldSpans) {
        int spanStart = spannable.getSpanStart(oldSpan);
        int spanEnd = spannable.getSpanEnd(oldSpan);

        if (spanStart <= startWidthPosition && spanEnd > startWidthPosition) {
            position = spanStart;
        }

        if (spanStart >= startWidthPosition) {
            spannable.removeSpan(oldSpan);
        }
    }
    //L.e("call: findStartPosition([spannable, startWidthPosition]) " + startWidthPosition + " -> " + position);
    return position;
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:22,代码来源:RExTextView.java

示例2: setAndMergeSpans

import android.text.Spannable; //导入方法依赖的package包/类
public static void setAndMergeSpans(Spannable text, Object what, int start, int end, int flags) {
    Object[] spans = text.getSpans(Math.max(start - 1, 0), Math.min(end + 1, 0), what.getClass());
    for (Object span : spans) {
        if (!areSpansEqual(span, what))
            continue;
        int sFlags = text.getSpanFlags(span);
        if ((sFlags & Spanned.SPAN_COMPOSING) != 0)
            continue;

        int sStart = text.getSpanStart(span);
        int sEnd = text.getSpanEnd(span);
        if (sEnd < start || sStart > end)
            continue;
        text.removeSpan(span);
        if (sStart < start)
            start = sStart;
        if (sEnd > end)
            end = sEnd;
    }
    text.setSpan(what, start, end, flags);
}
 
开发者ID:MCMrARM,项目名称:revolution-irc,代码行数:22,代码来源:SpannableStringHelper.java

示例3: invalidateSpannables

import android.text.Spannable; //导入方法依赖的package包/类
public void invalidateSpannables() {
    log("invalidating all spannables -- consider everything nullified");
    final Spannable spans = getText();
    final String text = spans.toString();

    // Remove existing spans
    for (CharacterStyle style : mSpans) {
        spans.removeSpan(style);
    }

    // Loop over the text, looking for new spans
    for (int i = 0; i < text.length(); i++) {
        for (SpanComponent component : mComponents) {
            String equation = component.parse(text.substring(i));
            if (equation != null) {
                MathSpannable span = component.getSpan(equation);
                spans.setSpan(span, i, i + equation.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                i += equation.length();
                break;
            }
        }
    }

    setSelection(getSelectionStart());
}
 
开发者ID:tranleduy2000,项目名称:floating_calc,代码行数:26,代码来源:CalculatorEditText.java

示例4: replaceQuoteSpans

import android.text.Spannable; //导入方法依赖的package包/类
/**
 * Replaces the blue line produced by <blockquote>s with something more visible
 *
 * @param spannable parsed comment text #fromHtml
 */
private void replaceQuoteSpans(Spannable spannable) {
    QuoteSpan[] quoteSpans = spannable.getSpans(0, spannable.length(), QuoteSpan.class);

    for (QuoteSpan quoteSpan : quoteSpans) {
        final int start = spannable.getSpanStart(quoteSpan);
        final int end = spannable.getSpanEnd(quoteSpan);
        final int flags = spannable.getSpanFlags(quoteSpan);

        spannable.removeSpan(quoteSpan);

        //If the theme is Light or Sepia, use a darker blue; otherwise, use a lighter blue
        final int barColor =
                (SettingValues.currentTheme == 1 || SettingValues.currentTheme == 5)
                        ? ContextCompat.getColor(getContext(), R.color.md_blue_600)
                        : ContextCompat.getColor(getContext(), R.color.md_blue_400);

        final int BAR_WIDTH = 4;
        final int GAP = 5;

        spannable.setSpan(new CustomQuoteSpan(Color.TRANSPARENT, //background color
                        barColor, //bar color
                        BAR_WIDTH, //bar width
                        GAP), //bar + text gap
                start, end, flags);
    }
}
 
开发者ID:ccrama,项目名称:Slide-RSS,代码行数:32,代码来源:SpoilerRobotoTextView.java

示例5: onDismiss

import android.text.Spannable; //导入方法依赖的package包/类
@Override
public void onDismiss(Spannable text) {
    // Remove any span added by shouldShow. Should be useless, but anyway.
    QuerySpan[] span = text.getSpans(0, text.length(), QuerySpan.class);
    for (QuerySpan s : span) {
        text.removeSpan(s);
    }
}
 
开发者ID:natario1,项目名称:Autocomplete,代码行数:9,代码来源:CharPolicy.java

示例6: setSpanFromMark

import android.text.Spannable; //导入方法依赖的package包/类
private void setSpanFromMark(String tag, Spannable text, Object mark, Object... spans) {
    int where = text.getSpanStart(mark);
    text.removeSpan(mark);
    int len = text.length();
    if (where != len) {
        for (Object span : spans) {
            if (mSpanCallback != null) {
                span = mSpanCallback.onSpanCreated(tag, span);
            }
            text.setSpan(span, where, len, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
}
 
开发者ID:Pixplicity,项目名称:HtmlCompat,代码行数:14,代码来源:HtmlToSpannedConverter.java

示例7: clearSpan

import android.text.Spannable; //导入方法依赖的package包/类
private void clearSpan(Spannable spannable, int start, int end) {
    if (start == end) {
        return;
    }
    EmoticonSpan[] oldSpans = spannable.getSpans(start, end, EmoticonSpan.class);
    for (int i = 0; i < oldSpans.length; i++) {
        spannable.removeSpan(oldSpans[i]);
    }
}
 
开发者ID:Zyj163,项目名称:yyox,代码行数:10,代码来源:QQFilter.java

示例8: addEmojis

import android.text.Spannable; //导入方法依赖的package包/类
public static void addEmojis(Context context, Spannable text, int emojiSize, int index, int
        length, boolean useSystemDefault) {
    if (!useSystemDefault) {
        int textLength = text.length();
        int textLengthToProcess = (length < 0 || length >= textLength - index) ? textLength :
                length + index;
        EmojiconSpan[] oldSpans = (EmojiconSpan[]) text.getSpans(0, textLength, EmojiconSpan
                .class);
        for (Object removeSpan : oldSpans) {
            text.removeSpan(removeSpan);
        }
        int i = index;
        while (i < textLengthToProcess) {
            int skip = 0;
            int icon = 0;
            char c = text.charAt(i);
            if (isSoftBankEmoji(c)) {
                icon = getSoftbankEmojiResource(c);
                skip = icon == 0 ? 0 : 1;
            }
            if (icon == 0) {
                int unicode = Character.codePointAt(text, i);
                skip = Character.charCount(unicode);
                if (unicode > 255) {
                    icon = getEmojiResource(context, unicode);
                }
                if (icon == 0 && i + skip < textLengthToProcess) {
                    Character.codePointAt(text, i + skip);
                }
            }
            if (icon > 0) {
                text.setSpan(new EmojiconSpan(context, icon, emojiSize), i, i + skip, 33);
            }
            i += skip;
        }
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:38,代码来源:EmojiconHandler.java

示例9: removeOldHighlightedSpans

import android.text.Spannable; //导入方法依赖的package包/类
@Override
public void removeOldHighlightedSpans() {
  Spannable spannableString = (Spannable) payloadTextView.getText();
  BackgroundColorSpan[] backgroundSpans = spannableString.getSpans(0, spannableString.length(), BackgroundColorSpan.class);
  for (BackgroundColorSpan span : backgroundSpans) {
    spannableString.removeSpan(span);
  }
}
 
开发者ID:jainsahab,项目名称:AndroidSnooper,代码行数:9,代码来源:HttpCallFragment.java

示例10: stripUnderlines

import android.text.Spannable; //导入方法依赖的package包/类
public static void stripUnderlines(TextView textView) {
    Spannable s = new SpannableString(textView.getText());
    URLSpan[] spans = s.getSpans(0, s.length(), URLSpan.class);
    for (URLSpan span: spans) {
        int start = s.getSpanStart(span);
        int end = s.getSpanEnd(span);
        s.removeSpan(span);
        span = new URLSpanNoUnderline(span.getURL());
        s.setSpan(span, start, end, 0);
    }
    textView.setText(s);
}
 
开发者ID:Dnet3,项目名称:CustomAndroidOneSheeld,代码行数:13,代码来源:URLSpanNoUnderline.java

示例11: addSmiles

import android.text.Spannable; //导入方法依赖的package包/类
/**
 * replace existing spannable with smiles
 * @param context
 * @param spannable
 * @return
 */
public static boolean addSmiles(Context context, Spannable spannable) {
    boolean hasChanges = false;
    for (Entry<Pattern, Object> entry : emoticons.entrySet()) {
        Matcher matcher = entry.getKey().matcher(spannable);
        while (matcher.find()) {
            boolean set = true;
            for (ImageSpan span : spannable.getSpans(matcher.start(),
                    matcher.end(), ImageSpan.class))
                if (spannable.getSpanStart(span) >= matcher.start()
                        && spannable.getSpanEnd(span) <= matcher.end())
                    spannable.removeSpan(span);
                else {
                    set = false;
                    break;
                }
            if (set) {
                hasChanges = true;
                Object value = entry.getValue();
                if(value instanceof String && !((String) value).startsWith("http")){
                    File file = new File((String) value);
                    if(!file.exists() || file.isDirectory()){
                        return false;
                    }
                    spannable.setSpan(new ImageSpan(context, Uri.fromFile(file)),
                            matcher.start(), matcher.end(),
                            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                }else{
                    spannable.setSpan(new ImageSpan(context, (Integer)value),
                            matcher.start(), matcher.end(),
                            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                }
            }
        }
    }
    
    return hasChanges;
}
 
开发者ID:zuoweitan,项目名称:Hitalk,代码行数:44,代码来源:SmileUtils.java

示例12: replaceSpan

import android.text.Spannable; //导入方法依赖的package包/类
/**
 * Add {@code newSpan} at the same start and end indices as {@code oldSpan} and remove
 * {@code oldSpan} from the {@code spannable}.
 */
public static void replaceSpan(Spannable spannable, Object oldSpan, Object newSpan) {
    final int spanStart = spannable.getSpanStart(oldSpan);
    final int spanEnd = spannable.getSpanEnd(oldSpan);
    spannable.removeSpan(oldSpan);
    spannable.setSpan(newSpan, spanStart, spanEnd, 0);
}
 
开发者ID:Trumeet,项目名称:SetupWizardLibCompat,代码行数:11,代码来源:SpanHelper.java

示例13: addSmiles

import android.text.Spannable; //导入方法依赖的package包/类
/**
 * replace existing spannable with smiles
 * @param context
 * @param spannable
 * @return
 */
public static boolean addSmiles(Context context, Spannable spannable) {
    boolean hasChanges = false;
    for (Map.Entry<Pattern, Object> entry : emoticons.entrySet()) {
        Matcher matcher = entry.getKey().matcher(spannable);
        while (matcher.find()) {
            boolean set = true;
            for (ImageSpan span : spannable.getSpans(matcher.start(),
                    matcher.end(), ImageSpan.class))
                if (spannable.getSpanStart(span) >= matcher.start()
                        && spannable.getSpanEnd(span) <= matcher.end())
                    spannable.removeSpan(span);
                else {
                    set = false;
                    break;
                }
            if (set) {
                hasChanges = true;
                Object value = entry.getValue();
                if(value instanceof String && !((String) value).startsWith("http")){
                    File file = new File((String) value);
                    if(!file.exists() || file.isDirectory()){
                        return false;
                    }
                    spannable.setSpan(new ImageSpan(context, Uri.fromFile(file)),
                            matcher.start(), matcher.end(),
                            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                }else{
                    spannable.setSpan(new ImageSpan(context, (Integer)value),
                            matcher.start(), matcher.end(),
                            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                }
            }
        }
    }

    return hasChanges;
}
 
开发者ID:funnyzhaov,项目名称:Tribe,代码行数:44,代码来源:EaseSmileUtils.java

示例14: removeUrlHighlightColor

import android.text.Spannable; //导入方法依赖的package包/类
private void removeUrlHighlightColor(TextView textView) {
    if (this.isUrlHighlighted) {
        this.isUrlHighlighted = false;
        Spannable text = (Spannable) textView.getText();
        BackgroundColorSpan[] highlightSpans = text.getSpans(0, text.length(), BackgroundColorSpan.class);
        for (BackgroundColorSpan highlightSpan : highlightSpans) {
            text.removeSpan(highlightSpan);
        }
        try {
            textView.setText(text);
            Selection.removeSelection(text);
        } catch (Exception ignored) {}
    }
}
 
开发者ID:duyp,项目名称:mvvm-template,代码行数:15,代码来源:BetterLinkMovementExtended.java

示例15: onTouchEvent

import android.text.Spannable; //导入方法依赖的package包/类
public boolean onTouchEvent(TextView widget, Spannable buffer,
                            MotionEvent event) {

    int action = event.getAction();
    if(action == MotionEvent.ACTION_DOWN){
        int x = (int) event.getX();
        int y = (int) event.getY();

        x -= widget.getTotalPaddingLeft();
        y -= widget.getTotalPaddingTop();

        x += widget.getScrollX();
        y += widget.getScrollY();

        Layout layout = widget.getLayout();
        int line = layout.getLineForVertical(y);
        int off = layout.getOffsetForHorizontal(line, x);

        mClickLinks = buffer.getSpans(off, off, ClickableSpan.class);
        if(mClickLinks.length > 0){
            // 点击的是Span区域,不要把点击事件传递
            setPassToTv(false);
            Selection.setSelection(buffer,
                    buffer.getSpanStart(mClickLinks[0]),
                    buffer.getSpanEnd(mClickLinks[0]));
            //设置点击区域的背景色
            mBgSpan = new BackgroundColorSpan(AppApplication.getAppResources().getColor(mClickableSpanBgClorId));
            buffer.setSpan(mBgSpan,
                    buffer.getSpanStart(mClickLinks[0]),
                    buffer.getSpanEnd(mClickLinks[0]),
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }else{
            setPassToTv(true);
            // textview选中效果
            widget.setBackgroundResource(mTextViewBgColorId);
        }

    }else if(action == MotionEvent.ACTION_UP){
        if(mClickLinks.length > 0){
            mClickLinks[0].onClick(widget);
            if(mBgSpan != null){
                buffer.removeSpan(mBgSpan);
            }
        }else{
            if(mBgSpan != null){
                buffer.removeSpan(mBgSpan);
            }
        }
        Selection.removeSelection(buffer);
        widget.setBackgroundResource(DEFAULT_COLOR);
    }else if(action == MotionEvent.ACTION_MOVE){

    }else{
        if(mBgSpan != null){
            buffer.removeSpan(mBgSpan);
        }
        widget.setBackgroundResource(DEFAULT_COLOR);
    }
    return Touch.onTouchEvent(widget, buffer, event);
}
 
开发者ID:wp521,项目名称:MyFire,代码行数:61,代码来源:CircleMovementMethod.java


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