當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。