use of android.text.style.AbsoluteSizeSpan in project LuaViewSDK by alibaba.
the class UDSpannableString method initSpannableStringBuilder.
private void initSpannableStringBuilder(LuaValue text, LuaValue config) {
SpannableStringBuilder spannableStringBuilder = getSpannableStringBuilder();
if (text != null && text.isstring()) {
spannableStringBuilder = spannableStringBuilder.append(text.tojstring());
}
if (spannableStringBuilder.length() > 0) {
if (config != null && config.istable()) {
final int end = spannableStringBuilder.length();
final int fontSize = DimenUtil.spToPx(config.get("fontSize").optint(-1));
final Integer fontColor = ColorUtil.parse(LuaUtil.getValue(config, "fontColor"));
final String fontName = config.get("fontName").optjstring(null);
final LuaValue weightValue = config.get("fontWeight");
final int fontWeight = LuaUtil.isNumber(weightValue) ? weightValue.optint(UDFontWeight.WEIGHT_NORMAL_INT) : UDFontWeight.getValue(weightValue.optjstring(UDFontWeight.WEIGHT_NORMAL));
final LuaValue styleValue = config.get("fontStyle");
final int fontStyle = LuaUtil.isNumber(styleValue) ? styleValue.optint(Typeface.NORMAL) : UDFontStyle.getValue(styleValue.optjstring(UDFontStyle.STYLE_NORMAL));
final Integer backgroundColor = ColorUtil.parse(LuaUtil.getValue(config, "backgroundColor"));
final boolean strikethrough = config.get("strikethrough").optboolean(false);
final boolean underline = config.get("underline").optboolean(false);
if (fontSize != -1) {
//字体大小
spannableStringBuilder.setSpan(new AbsoluteSizeSpan(fontSize), 0, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
if (fontColor != null) {
//字体颜色
spannableStringBuilder.setSpan(new ForegroundColorSpan(fontColor), 0, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
if (fontName != null && getLuaResourceFinder() != null) {
//字体
spannableStringBuilder.setSpan(new CustomTypefaceSpan(fontName, getLuaResourceFinder().findTypeface(fontName)), 0, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
if (fontWeight != -1 && fontWeight > UDFontWeight.WEIGHT_NORMAL_INT) {
//文字Weight
spannableStringBuilder.setSpan(new WeightStyleSpan(fontWeight), 0, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
if (fontStyle != -1 && (fontStyle >= Typeface.NORMAL && fontStyle <= Typeface.BOLD_ITALIC)) {
//文字样式
spannableStringBuilder.setSpan(new StyleSpan(fontStyle), 0, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
if (backgroundColor != null) {
//背景色
spannableStringBuilder.setSpan(new BackgroundColorSpan(backgroundColor), 0, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
if (strikethrough) {
//删除线
spannableStringBuilder.setSpan(new StrikethroughSpan(), 0, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
if (underline) {
//下划线
spannableStringBuilder.setSpan(new UnderlineSpan(), 0, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
}
}
use of android.text.style.AbsoluteSizeSpan in project Conductor by bluelinelabs.
the class HomeController method onFabClicked.
private void onFabClicked(boolean fromFab) {
SpannableString details = new SpannableString("A small, yet full-featured framework that allows building View-based Android applications");
details.setSpan(new AbsoluteSizeSpan(16, true), 0, details.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
final String url = "https://github.com/bluelinelabs/Conductor";
SpannableString link = new SpannableString(url);
link.setSpan(new URLSpan(url) {
@Override
public void onClick(View widget) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
}
}, 0, link.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
SpannableStringBuilder description = new SpannableStringBuilder();
description.append(details);
description.append("\n\n");
description.append(link);
ControllerChangeHandler pushHandler = fromFab ? new TransitionChangeHandlerCompat(new FabToDialogTransitionChangeHandler(), new FadeChangeHandler(false)) : new FadeChangeHandler(false);
ControllerChangeHandler popHandler = fromFab ? new TransitionChangeHandlerCompat(new FabToDialogTransitionChangeHandler(), new FadeChangeHandler()) : new FadeChangeHandler();
getRouter().pushController(RouterTransaction.with(new DialogController("Conductor", description)).pushChangeHandler(pushHandler).popChangeHandler(popHandler));
}
use of android.text.style.AbsoluteSizeSpan in project WordPress-Android by wordpress-mobile.
the class WPHtml method withinParagraph.
private static void withinParagraph(StringBuilder out, Spanned text, int start, int end, int nl, boolean last) {
int next;
for (int i = start; i < end; i = next) {
next = text.nextSpanTransition(i, end, CharacterStyle.class);
CharacterStyle[] style = text.getSpans(i, next, CharacterStyle.class);
for (int j = 0; j < style.length; j++) {
if (style[j] instanceof StyleSpan) {
int s = ((StyleSpan) style[j]).getStyle();
if ((s & Typeface.BOLD) != 0) {
out.append("<strong>");
}
if ((s & Typeface.ITALIC) != 0) {
out.append("<em>");
}
}
if (style[j] instanceof TypefaceSpan) {
String s = ((TypefaceSpan) style[j]).getFamily();
if (s.equals("monospace")) {
out.append("<tt>");
}
}
if (style[j] instanceof SuperscriptSpan) {
out.append("<sup>");
}
if (style[j] instanceof SubscriptSpan) {
out.append("<sub>");
}
if (style[j] instanceof WPUnderlineSpan) {
out.append("<u>");
}
if (style[j] instanceof StrikethroughSpan) {
out.append("<strike>");
}
if (style[j] instanceof URLSpan) {
out.append("<a href=\"");
out.append(((URLSpan) style[j]).getURL());
out.append("\">");
}
if (style[j] instanceof MediaGalleryImageSpan) {
out.append(getGalleryShortcode((MediaGalleryImageSpan) style[j]));
} else if (style[j] instanceof WPImageSpan && ((WPImageSpan) style[j]).getMediaFile().getMediaId() != null) {
out.append(getContent((WPImageSpan) style[j]));
} else if (style[j] instanceof WPImageSpan) {
out.append("<img src=\"");
out.append(((WPImageSpan) style[j]).getSource());
out.append("\" android-uri=\"" + ((WPImageSpan) style[j]).getImageSource().toString() + "\"");
out.append(" />");
// Don't output the dummy character underlying the image.
i = next;
}
if (style[j] instanceof AbsoluteSizeSpan) {
out.append("<font size =\"");
out.append(((AbsoluteSizeSpan) style[j]).getSize() / 6);
out.append("\">");
}
if (style[j] instanceof ForegroundColorSpan) {
out.append("<font color =\"#");
String color = Integer.toHexString(((ForegroundColorSpan) style[j]).getForegroundColor() + 0x01000000);
while (color.length() < 6) {
color = "0" + color;
}
out.append(color);
out.append("\">");
}
}
processWPImage(out, text, i, next);
for (int j = style.length - 1; j >= 0; j--) {
if (style[j] instanceof ForegroundColorSpan) {
out.append("</font>");
}
if (style[j] instanceof AbsoluteSizeSpan) {
out.append("</font>");
}
if (style[j] instanceof URLSpan) {
out.append("</a>");
}
if (style[j] instanceof StrikethroughSpan) {
out.append("</strike>");
}
if (style[j] instanceof WPUnderlineSpan) {
out.append("</u>");
}
if (style[j] instanceof SubscriptSpan) {
out.append("</sub>");
}
if (style[j] instanceof SuperscriptSpan) {
out.append("</sup>");
}
if (style[j] instanceof TypefaceSpan) {
String s = ((TypefaceSpan) style[j]).getFamily();
if (s.equals("monospace")) {
out.append("</tt>");
}
}
if (style[j] instanceof StyleSpan) {
int s = ((StyleSpan) style[j]).getStyle();
if ((s & Typeface.BOLD) != 0) {
out.append("</strong>");
}
if ((s & Typeface.ITALIC) != 0) {
out.append("</em>");
}
}
}
}
String p = last ? "" : "</p>\n<p>";
if (nl == 1) {
out.append("<br>\n");
} else if (nl == 2) {
out.append(p);
} else {
for (int i = 2; i < nl; i++) {
out.append("<br>");
}
out.append(p);
}
}
use of android.text.style.AbsoluteSizeSpan in project android_frameworks_base by DirtyUnicorns.
the class Notification method removeTextSizeSpans.
private static CharSequence removeTextSizeSpans(CharSequence charSequence) {
if (charSequence instanceof Spanned) {
Spanned ss = (Spanned) charSequence;
Object[] spans = ss.getSpans(0, ss.length(), Object.class);
SpannableStringBuilder builder = new SpannableStringBuilder(ss.toString());
for (Object span : spans) {
Object resultSpan = span;
if (resultSpan instanceof CharacterStyle) {
resultSpan = ((CharacterStyle) span).getUnderlying();
}
if (resultSpan instanceof TextAppearanceSpan) {
TextAppearanceSpan originalSpan = (TextAppearanceSpan) resultSpan;
resultSpan = new TextAppearanceSpan(originalSpan.getFamily(), originalSpan.getTextStyle(), -1, originalSpan.getTextColor(), originalSpan.getLinkTextColor());
} else if (resultSpan instanceof RelativeSizeSpan || resultSpan instanceof AbsoluteSizeSpan) {
continue;
} else {
resultSpan = span;
}
builder.setSpan(resultSpan, ss.getSpanStart(span), ss.getSpanEnd(span), ss.getSpanFlags(span));
}
return builder;
}
return charSequence;
}
use of android.text.style.AbsoluteSizeSpan in project weex-example by KalicyZhou.
the class WXTextDomObject method createSetSpanOperation.
/**
* Create a task list which contains {@link SetSpanOperation}. The task list will be executed
* in other method.
* @param end the end character of the text.
* @return a task list which contains {@link SetSpanOperation}.
*/
private List<SetSpanOperation> createSetSpanOperation(int end, int spanFlag) {
List<SetSpanOperation> ops = new LinkedList<>();
int start = 0;
if (end >= start) {
if (mTextDecoration == WXTextDecoration.UNDERLINE) {
ops.add(new SetSpanOperation(start, end, new UnderlineSpan(), spanFlag));
}
if (mTextDecoration == WXTextDecoration.LINETHROUGH) {
ops.add(new SetSpanOperation(start, end, new StrikethroughSpan(), spanFlag));
}
if (mIsColorSet) {
ops.add(new SetSpanOperation(start, end, new ForegroundColorSpan(mColor), spanFlag));
}
if (mFontSize != UNSET) {
ops.add(new SetSpanOperation(start, end, new AbsoluteSizeSpan(mFontSize), spanFlag));
}
if (mFontStyle != UNSET || mFontWeight != UNSET || mFontFamily != null) {
ops.add(new SetSpanOperation(start, end, new WXCustomStyleSpan(mFontStyle, mFontWeight, mFontFamily), spanFlag));
}
ops.add(new SetSpanOperation(start, end, new AlignmentSpan.Standard(mAlignment), spanFlag));
if (mLineHeight != UNSET) {
ops.add(new SetSpanOperation(start, end, new WXLineHeightSpan(mLineHeight), spanFlag));
}
}
return ops;
}
Aggregations