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


Java Spannable类代码示例

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


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

示例1: applyLetterSpacing

import android.text.Spannable; //导入依赖的package包/类
private SpannableString applyLetterSpacing(String text) {
    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < text.length(); i++) {
        builder.append(text.charAt(i));
        if (i + 1 < text.length() && !isEmojiCharacter(text.charAt(i))) {//avoid adding the blank code between the emoji code
            builder.append("\u00A0");
        }
    }
    SpannableString finalText = new SpannableString(builder.toString());
    if (builder.toString().length() > 1) {
        for (int i = 1; i < builder.toString().length(); i += 2) {
            if (builder.toString().toCharArray()[i] == 160) {//avoid breaking emoji code, u00A0 is text space
                finalText.setSpan(new ScaleXSpan((mLetterSpace + 1) / 10), i, i + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        }
    }
    return finalText;
}
 
开发者ID:MaYatKit,项目名称:Rotatable-Scalable-Font,代码行数:19,代码来源:WidgetTextContent.java

示例2: bind

import android.text.Spannable; //导入依赖的package包/类
@SuppressWarnings("unused")
public void bind(int position, TweetPublishModel model, RequestManager loader) {
    itemView.setTag(model);

    Context context = itemView.getContext();

    Spannable spannable = TweetParser.getInstance().parse(context, model.getContent());
    mTitle.setText(spannable);
    mTitle.setMovementMethod(LinkMovementMethod.getInstance());
    mTitle.setFocusable(false);
    mTitle.setDispatchToParent(true);
    mTitle.setLongClickable(false);

    mLog.setText(String.format("Error:%s.",
            model.getErrorString() == null ? "null" : model.getErrorString()));
    mDate.setText(FORMAT.format(new Date(model.getDate())));
}
 
开发者ID:hsj-xiaokang,项目名称:OSchina_resources_android,代码行数:18,代码来源:TweetQueueAdapter.java

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

示例4: getPressedSpan

import android.text.Spannable; //导入依赖的package包/类
public ITouchableSpan getPressedSpan(TextView textView, Spannable spannable, MotionEvent event) {
    int x = (int) event.getX();
    int y = (int) event.getY();

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

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

    Layout layout = textView.getLayout();
    int line = layout.getLineForVertical(y);
    int off = layout.getOffsetForHorizontal(line, x);
    if (x < layout.getLineLeft(line) || x > layout.getLineRight(line)) {
        // 实际上没点到任何内容
        off = -1;
    }

    ITouchableSpan[] link = spannable.getSpans(off, off, ITouchableSpan.class);
    ITouchableSpan touchedSpan = null;
    if (link.length > 0) {
        touchedSpan = link[0];
    }
    return touchedSpan;
}
 
开发者ID:QMUI,项目名称:QMUI_Android,代码行数:26,代码来源:QMUILinkTouchDecorHelper.java

示例5: getText

import android.text.Spannable; //导入依赖的package包/类
/**
 * @param context
 * @param spannable
 * @param title
 * @return
 */
public static SpannableStringBuilder getText(Activity context, Spannable spannable, String title) {
	if (spannable == null || spannable.length() <= 0) {
		Log.e(TAG, "getText  spannable == null || spannable.length() <= 0 >> return new SpannableStringBuilder();");
		return new SpannableStringBuilder();
	}

	SpannableStringBuilder builder = new SpannableStringBuilder(spannable);
	builder.clearSpans();// should clear old spans
	URLSpan[] urls = spannable.getSpans(0, spannable.length(), URLSpan.class);
	if (urls != null) {
		for (URLSpan urlSpan : urls) {
			if (urlSpan != null) {
				MyURLSpan myURLSpan = new MyURLSpan(context, urlSpan.getURL(), title);
				builder.setSpan(myURLSpan, spannable.getSpanStart(urlSpan), spannable
						.getSpanEnd(urlSpan), Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
			}
		}
	}

	return builder;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:28,代码来源:MyURLSpan.java

示例6: convert

import android.text.Spannable; //导入依赖的package包/类
@Override
public void convert(EasyLVHolder holder, int position, BookMark item) {
    TextView tv = holder.getView(R.id.tvMarkItem);

    SpannableString spanText = new SpannableString((position + 1) + ". " + item.title + ": ");
    spanText.setSpan(new ForegroundColorSpan(ContextCompat.getColor(mContext, R.color.light_coffee)),
            0, spanText.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);

    tv.setText(spanText);

    if (item.desc != null) {
        tv.append(item.desc
                .replaceAll(" ", "")
                .replaceAll(" ", "")
                .replaceAll("\n", ""));
    }

}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:19,代码来源:BookMarkAdapter.java

示例7: formatHash

import android.text.Spannable; //导入依赖的package包/类
public static Editable formatHash(@Nullable final String prefix, final String address, final int groupSize,
        final int lineSize, final char groupSeparator) {
    final SpannableStringBuilder builder = prefix != null ? new SpannableStringBuilder(prefix)
            : new SpannableStringBuilder();

    final int len = address.length();
    for (int i = 0; i < len; i += groupSize) {
        final int end = i + groupSize;
        final String part = address.substring(i, end < len ? end : len);

        builder.append(part);
        builder.setSpan(new TypefaceSpan("monospace"), builder.length() - part.length(), builder.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        if (end < len) {
            final boolean endOfLine = lineSize > 0 && end % lineSize == 0;
            builder.append(endOfLine ? '\n' : groupSeparator);
        }
    }

    return builder;
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:22,代码来源:WalletUtils.java

示例8: onTouchEvent

import android.text.Spannable; //导入依赖的package包/类
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
    if (event.getAction() == 1) {
        this.mLinkClicked = false;
        this.mClickedLink = null;
        int x = (((int) event.getX()) - widget.getTotalPaddingLeft()) + widget.getScrollX();
        int y = (((int) event.getY()) - widget.getTotalPaddingTop()) + widget.getScrollY();
        Layout layout = widget.getLayout();
        int off = layout.getOffsetForHorizontal(layout.getLineForVertical(y), (float) x);
        ClickableSpan[] link = (ClickableSpan[]) buffer.getSpans(off, off, ClickableSpan
                .class);
        if (link.length != 0) {
            SensibleUrlSpan span = link[0];
            this.mLinkClicked = span.onClickSpan(widget);
            this.mClickedLink = span.getURL();
            return this.mLinkClicked;
        }
    }
    super.onTouchEvent(widget, buffer, event);
    return false;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:21,代码来源:LinkUtils.java

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

示例10: replaceWithImages

import android.text.Spannable; //导入依赖的package包/类
/**
 * Replace the system emoticons with the provided custom emoticons drawable. This will find the
 * unicodes with supported emoticons in the provided text and  will replace the emoticons with
 * appropriate images.
 *
 * @param context          instance of caller.
 * @param text             Text to replace
 * @param emoticonProvider {@link EmoticonProvider} for emoticons images
 * @param emoticonSize     Size of the emoticons in dp
 * @return Modified text.
 */
public static void replaceWithImages(@NonNull final Context context,
                                     @NonNull final Spannable text,
                                     @NonNull final EmoticonProvider emoticonProvider,
                                     final int emoticonSize) {

    final EmoticonSpan[] existingSpans = text.getSpans(0, text.length(), EmoticonSpan.class);
    final ArrayList<Integer> existingSpanPositions = new ArrayList<>(existingSpans.length);
    for (EmoticonSpan existingSpan : existingSpans) {
        existingSpanPositions.add(text.getSpanStart(existingSpan));
    }

    //Get location and unicode of all emoticons.
    final List<EmoticonRange> findAllEmojis = findAllEmoticons(context, text, emoticonProvider);

    //Replace all the emoticons with their relatives.
    for (int i = 0; i < findAllEmojis.size(); i++) {
        final EmoticonRange location = findAllEmojis.get(i);
        if (!existingSpanPositions.contains(location.mStartPos)) {
            text.setSpan(new EmoticonSpan(context, location.mEmoticon.getIcon(), emoticonSize),
                    location.mStartPos,
                    location.mEndPos,
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
}
 
开发者ID:kevalpatel2106,项目名称:EmoticonGIFKeyboard,代码行数:37,代码来源:EmoticonUtils.java

示例11: getformatedSearchSnippet

import android.text.Spannable; //导入依赖的package包/类
public CharSequence getformatedSearchSnippet() {
    //TODO implement improved snippet function
    String CleanedSearchString = " " + ArabicUtilities.cleanTextForSearchingWthStingBuilder(searchString) + " ";
    StringBuilder cleanedUnformattedPage = new StringBuilder(ArabicUtilities.cleanTextForSearchingWthStingBuilder(unformatedPage));
    int firstMatchStart = cleanedUnformattedPage.indexOf(CleanedSearchString);
    cleanedUnformattedPage.delete(0, Math.max(firstMatchStart - 100, 0));
    cleanedUnformattedPage.delete(
            Math.min(firstMatchStart + CleanedSearchString.length() + 100, cleanedUnformattedPage.length())
            , cleanedUnformattedPage.length());
    cleanedUnformattedPage.insert(0, "...");
    cleanedUnformattedPage.append("...");

    Spannable snippet = SpannableString.
            valueOf(cleanedUnformattedPage.toString());
    int index = TextUtils.indexOf(snippet, CleanedSearchString);
    while (index >= 0) {

        snippet.setSpan(new BackgroundColorSpan(0xFF8B008B), index, index
                + CleanedSearchString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        index = TextUtils.indexOf(snippet, CleanedSearchString, index + CleanedSearchString.length());
    }

    return snippet;
}
 
开发者ID:fekracomputers,项目名称:IslamicLibraryAndroid,代码行数:25,代码来源:SearchResult.java

示例12: displayPlaylistInfo

import android.text.Spannable; //导入依赖的package包/类
private void displayPlaylistInfo(final Playlist playlist)
{
	final TextView textView = new TextView(this);
	textView.setPadding(5, 5, 5, 5);

	final Spannable message = new SpannableString("Owner: " + playlist.getOwner() + "\nComments: " +
			((playlist.getComment() == null) ? "" : playlist.getComment()) +
			"\nSong Count: " + playlist.getSongCount() +
			((playlist.getPublic() == null) ? "" : ("\nPublic: " + playlist.getPublic()) + ((playlist.getCreated() == null) ? "" : ("\nCreation Date: " + playlist.getCreated().replace('T', ' ')))));

	Linkify.addLinks(message, Linkify.WEB_URLS);
	textView.setText(message);
	textView.setMovementMethod(LinkMovementMethod.getInstance());

	new AlertDialog.Builder(this).setTitle(playlist.getName()).setCancelable(true).setIcon(android.R.drawable.ic_dialog_info).setView(textView).show();
}
 
开发者ID:ultrasonic,项目名称:ultrasonic,代码行数:17,代码来源:SelectPlaylistActivity.java

示例13: createSpanForMatchesP

import android.text.Spannable; //导入依赖的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

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

示例15: gatherPhoneLinks

import android.text.Spannable; //导入依赖的package包/类
private static void gatherPhoneLinks(ArrayList<LinkSpec> links,
                                     Spannable s, Pattern pattern, Pattern[] excepts, String[] schemes,
                                     MatchFilter matchFilter, TransformFilter transformFilter) {
    Matcher m = pattern.matcher(s);

    while (m.find()) {
        if (isInExcepts(m.group(), excepts)) {
            continue;
        }

        int start = m.start();
        int end = m.end();

        if (matchFilter == null || matchFilter.acceptMatch(s, start, end)) {
            LinkSpec spec = new LinkSpec();
            String url = makeUrl(m.group(0), schemes, m, transformFilter);

            spec.url = url;
            spec.start = start;
            spec.end = end;

            links.add(spec);
        }
    }
}
 
开发者ID:coopese,项目名称:qmui,代码行数:26,代码来源:QMUILinkify.java


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