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


Java SpannableString.getSpanEnd方法代码示例

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


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

示例1: hasBackgroundSpanOn

import android.text.SpannableString; //导入方法依赖的package包/类
public static Matcher<View> hasBackgroundSpanOn(final String text, @ColorRes final int colorResource) {
  return new CustomTypeSafeMatcher<View>("") {
    @Override
    protected boolean matchesSafely(View view) {
      if (view == null || !(view instanceof TextView))
        return false;
      SpannableString spannableString = (SpannableString) ((TextView) view).getText();
      BackgroundColorSpan[] spans = spannableString.getSpans(0, spannableString.length(), BackgroundColorSpan.class);
      for (BackgroundColorSpan span : spans) {
        int start = spannableString.getSpanStart(span);
        int end = spannableString.getSpanEnd(span);
        CharSequence highlightedString = spannableString.subSequence(start, end);
        if (text.equals(highlightedString.toString())) {
          return span.getBackgroundColor() == view.getContext().getResources().getColor(colorResource);
        }
      }
      return false;
    }
  };
}
 
开发者ID:jainsahab,项目名称:AndroidSnooper,代码行数:21,代码来源:EspressoViewMatchers.java

示例2: replaceAll

import android.text.SpannableString; //导入方法依赖的package包/类
public static <A extends CharacterStyle, B extends CharacterStyle> Spannable replaceAll(Spanned original,
                                                                                        Class<A> sourceType,
                                                                                        SpanConverter<A, B> converter,
                                                                                        final ClickSpan.OnClickListener listener) {
    SpannableString result = new SpannableString(original);
    A[] spans = result.getSpans(0, result.length(), sourceType);

    for (A span : spans) {
        int start = result.getSpanStart(span);
        int end = result.getSpanEnd(span);
        int flags = result.getSpanFlags(span);

        result.removeSpan(span);
        result.setSpan(converter.convert(span, listener), start, end, flags);
    }

    return (result);
}
 
开发者ID:gbl08ma,项目名称:underlx,代码行数:19,代码来源:RichTextUtils.java

示例3: linkifyMessageBody

import android.text.SpannableString; //导入方法依赖的package包/类
private SpannableString linkifyMessageBody(SpannableString messageBody, boolean shouldLinkifyAllLinks) {
  boolean hasLinks = Linkify.addLinks(messageBody, shouldLinkifyAllLinks ? Linkify.ALL : 0);

  if (hasLinks) {
    URLSpan[] urlSpans = messageBody.getSpans(0, messageBody.length(), URLSpan.class);
    for (URLSpan urlSpan : urlSpans) {
      int start = messageBody.getSpanStart(urlSpan);
      int end = messageBody.getSpanEnd(urlSpan);
      messageBody.setSpan(new LongClickCopySpan(urlSpan.getURL()), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
  }
  return messageBody;
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:14,代码来源:ConversationItem.java

示例4: clickClickableSpan

import android.text.SpannableString; //导入方法依赖的package包/类
public static ViewAction clickClickableSpan(final CharSequence textToClick) {
    return new ViewAction() {
        @Override
        public Matcher<View> getConstraints() {
            return instanceOf(TextView.class);
        }

        @Override
        public String getDescription() {
            return "clicking on a ClickableSpan";
        }

        @Override
        public void perform(UiController uiController, View view) {
            TextView textView = (TextView) view;
            SpannableString spannableString = (SpannableString) textView.getText();

            if (spannableString.length() == 0) {
                // TextView is empty, nothing to do
                throw new NoMatchingViewException.Builder()
                        .includeViewHierarchy(true)
                        .withRootView(textView)
                        .build();
            }

            // Get the links inside the TextView and check if we find textToClick
            ClickableSpan[] spans = spannableString.getSpans(0, spannableString.length(), ClickableSpan.class);
            if (spans.length > 0) {
                ClickableSpan spanCandidate;
                for (ClickableSpan span : spans) {
                    spanCandidate = span;
                    int start = spannableString.getSpanStart(spanCandidate);
                    int end = spannableString.getSpanEnd(spanCandidate);
                    CharSequence sequence = spannableString.subSequence(start, end);
                    if (textToClick.toString().equals(sequence.toString())) {
                        span.onClick(textView);
                        return;
                    }
                }
            }

            // textToClick not found in TextView
            throw new NoMatchingViewException.Builder()
                    .includeViewHierarchy(true)
                    .withRootView(textView)
                    .build();

        }
    };
}
 
开发者ID:charafau,项目名称:TurboChat,代码行数:51,代码来源:EspressoTestUtils.java


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