本文整理汇总了Java中android.text.ParcelableSpan类的典型用法代码示例。如果您正苦于以下问题:Java ParcelableSpan类的具体用法?Java ParcelableSpan怎么用?Java ParcelableSpan使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ParcelableSpan类属于android.text包,在下文中一共展示了ParcelableSpan类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createSpanForMatches
import android.text.ParcelableSpan; //导入依赖的package包/类
/**
* Create Span for matches in ParcelableSpan'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 createSpanForMatches(final Editable editable, final Pattern pattern, final ParcelableSpanCreator 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++) {
ParcelableSpan 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);
}
}
}
}
}
示例2: createSpan
import android.text.ParcelableSpan; //导入依赖的package包/类
/**
* Returns a {@link Spannable} which attaches the specified {@link ParcelableSpan} to the given
* substring
*
* @param text Text
* @param span array of {@link ParcelableSpan} that will be applied
* @param spanTexts array of substrings that will be modified
*
* @return {@link Spannable}
*/
@NonNull public Spannable createSpan(String text, ParcelableSpan[] span, String... spanTexts) {
Spannable result = new SpannableString(text);
if (span != null && spanTexts != null && span.length <= spanTexts.length) {
for (int i = 0; i < span.length; i++) {
String spanText = spanTexts[i];
int spanTextStart = text.indexOf(spanText);
if (spanTextStart >= 0
&& spanTextStart < text.length()
&& spanText.length() <= text.length()) {
result.setSpan(span[i], spanTextStart, (spanTextStart + spanText.length()),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
}
return result;
}
示例3: createMultiSpan
import android.text.ParcelableSpan; //导入依赖的package包/类
@NonNull
public Spannable createMultiSpan(String text, ParcelableSpan[] span, String... spanTexts) {
Spannable result = new SpannableString(text);
for (ParcelableSpan parcelableSpan : span) {
for (String spanText : spanTexts) {
int spanTextStart = text.indexOf(spanText);
if (spanTextStart >= 0
&& spanTextStart < text.length()
&& spanText.length() <= text.length()) {
result.setSpan(parcelableSpan, spanTextStart, (spanTextStart + spanText.length()),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
}
return result;
}
示例4: setPost
import android.text.ParcelableSpan; //导入依赖的package包/类
@Override public void setPost(TimelineUser card, int position) {
followers.setText(spannableFactory.createSpan(itemView.getContext()
.getString(R.string.timeline_button_followers, card.getFollowers()),
new ParcelableSpan[] { new ForegroundColorSpan(Color.BLACK) },
String.valueOf(card.getFollowers()), String.valueOf(card.getFollowers())));
following.setText(spannableFactory.createSpan(itemView.getContext()
.getString(R.string.timeline_button_followed, card.getFollowing()),
new ParcelableSpan[] { new ForegroundColorSpan(Color.BLACK) },
String.valueOf(card.getFollowing()), String.valueOf(card.getFollowing())));
followers.setOnClickListener(click -> cardTouchEventPublishSubject.onNext(
new TimelineStatsTouchEvent(card, TimelineStatsTouchEvent.ButtonClicked.FOLLOWERS,
CardTouchEvent.Type.TIMELINE_STATS, position)));
following.setOnClickListener(click -> cardTouchEventPublishSubject.onNext(
new TimelineStatsTouchEvent(card, TimelineStatsTouchEvent.ButtonClicked.FOLLOWING,
CardTouchEvent.Type.TIMELINE_STATS, position)));
}
示例5: create
import android.text.ParcelableSpan; //导入依赖的package包/类
public ParcelableSpan create(Matcher m, int iM) {
final char[] charSequence = extractMatchingRange(m);
Float proportion = calculateProportionBasedOnHeaderType(charSequence);
Float size = calculateAdjustedSize(proportion);
return new TextAppearanceSpan(_highlighter._fontType, Typeface.BOLD, (int) size.byteValue(),
ColorStateList.valueOf(_color), null);
}
示例6: getFollowersText
import android.text.ParcelableSpan; //导入依赖的package包/类
CharSequence getFollowersText(Context context) {
return spannableFactory.createSpan(context.getString(R.string.timeline_button_followers,
getPojo().getData()
.getFollowers()), new ParcelableSpan[] { new ForegroundColorSpan(Color.BLACK) },
String.valueOf(getPojo().getData()
.getFollowers()), String.valueOf(getPojo().getData()
.getFollowers()));
}
示例7: getFollowingText
import android.text.ParcelableSpan; //导入依赖的package包/类
CharSequence getFollowingText(Context context) {
return spannableFactory.createSpan(context.getString(R.string.timeline_button_followed,
getPojo().getData()
.getFollowing()), new ParcelableSpan[] { new ForegroundColorSpan(Color.BLACK) },
String.valueOf(getPojo().getData()
.getFollowing()), String.valueOf(getPojo().getData()
.getFollowing()));
}
示例8: createSpan
import android.text.ParcelableSpan; //导入依赖的package包/类
private Spannable createSpan(String text, ParcelableSpan span, String[] spanTexts) {
final Spannable result = new SpannableString(text);
for (String spanText : spanTexts) {
int spanTextStart = text.indexOf(spanText);
if (spanTextStart >= 0
&& spanTextStart < text.length()
&& spanText.length() <= text.length()) {
result.setSpan(span, spanTextStart, (spanTextStart + spanText.length()),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
return result;
}
示例9: showAppsCount
import android.text.ParcelableSpan; //导入依赖的package包/类
private void showAppsCount(long appsCount, ParcelableSpan[] textStyle, boolean showApps,
long storeName) {
if (showApps) {
appsCountTv.setVisibility(View.VISIBLE);
String count = AptoideUtils.StringU.withSuffix(appsCount);
String followingText =
String.format(getContext().getString(R.string.storehometab_short_apps), count);
appsCountTv.setText(spannableFactory.createMultiSpan(followingText, textStyle, count));
appsCountTv.setOnClickListener(v -> navigateToAppsListScreen(storeName));
} else {
appsCountTv.setVisibility(View.GONE);
}
}
示例10: removeParcelableSpans
import android.text.ParcelableSpan; //导入依赖的package包/类
/**
* This is used to remove all style-impacting spans from text before new
* extracted text is being replaced into it, so that we don't have any
* lingering spans applied during the replace.
*/
static void removeParcelableSpans(Spannable spannable, int start, int end) {
Object[] spans = spannable.getSpans(start, end, ParcelableSpan.class);
int i = spans.length;
while (i > 0) {
i--;
spannable.removeSpan(spans[i]);
}
}
示例11: clear
import android.text.ParcelableSpan; //导入依赖的package包/类
public static void clear(final Editable editable) {
final int end = editable.length() - 1;
for (Class<? extends ParcelableSpan> clazz : SPAN_CLASSES) {
for (ParcelableSpan span : editable.getSpans(0, end, clazz)) {
editable.removeSpan(span);
}
}
}
示例12: createSpanForStyle
import android.text.ParcelableSpan; //导入依赖的package包/类
private static ParcelableSpan createSpanForStyle(ImStyleParser.Style style) {
switch (style.getKeyword()) {
case "*":
return new StyleSpan(Typeface.BOLD);
case "_":
return new StyleSpan(Typeface.ITALIC);
case "~":
return new StrikethroughSpan();
case "`":
case "```":
return new TypefaceSpan("monospace");
default:
throw new AssertionError("Unknown Style");
}
}
示例13: clear
import android.text.ParcelableSpan; //导入依赖的package包/类
public static void clear(final Editable editable) {
final int end = editable.length() - 1;
for (Class<? extends ParcelableSpan> clazz : SPAN_CLASSES) {
for (ParcelableSpan span : editable.getSpans(0, end, clazz)) {
editable.removeSpan(span);
}
}
}
示例14: createSpanForStyle
import android.text.ParcelableSpan; //导入依赖的package包/类
private static ParcelableSpan createSpanForStyle(ImStyleParser.Style style) {
switch (style.getKeyword()) {
case "*":
return new StyleSpan(Typeface.BOLD);
case "_":
return new StyleSpan(Typeface.ITALIC);
case "~":
return new StrikethroughSpan();
case "`":
case "```":
return new TypefaceSpan("monospace");
default:
throw new AssertionError("Unknown Style");
}
}
示例15: create
import android.text.ParcelableSpan; //导入依赖的package包/类
public ParcelableSpan create(Matcher m) {
final char[] charSequence = extractMatchingRange(m);
Float proportion = calculateProportionBasedOnHeaderType(charSequence);
Float size = calculateAdjustedSize(proportion);
return new TextAppearanceSpan(highlighter.fontType, Typeface.BOLD, (int) size.byteValue(),
ColorStateList.valueOf(color), null);
}