use of android.text.style.RelativeSizeSpan in project platform_frameworks_base by android.
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.RelativeSizeSpan in project platform_frameworks_base by android.
the class HtmlToSpannedConverter method endHeading.
private static void endHeading(Editable text) {
// RelativeSizeSpan and StyleSpan are CharacterStyles
// Their ranges should not include the newlines at the end
Heading h = getLast(text, Heading.class);
if (h != null) {
setSpanFromMark(text, h, new RelativeSizeSpan(HEADING_SIZES[h.mLevel]), new StyleSpan(Typeface.BOLD));
}
endBlockElement(text);
}
use of android.text.style.RelativeSizeSpan in project platform_frameworks_base by android.
the class HtmlToSpannedConverter method withinParagraph.
private static void withinParagraph(StringBuilder out, Spanned text, int start, int end) {
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("<b>");
}
if ((s & Typeface.ITALIC) != 0) {
out.append("<i>");
}
}
if (style[j] instanceof TypefaceSpan) {
String s = ((TypefaceSpan) style[j]).getFamily();
if ("monospace".equals(s)) {
out.append("<tt>");
}
}
if (style[j] instanceof SuperscriptSpan) {
out.append("<sup>");
}
if (style[j] instanceof SubscriptSpan) {
out.append("<sub>");
}
if (style[j] instanceof UnderlineSpan) {
out.append("<u>");
}
if (style[j] instanceof StrikethroughSpan) {
out.append("<span style=\"text-decoration:line-through;\">");
}
if (style[j] instanceof URLSpan) {
out.append("<a href=\"");
out.append(((URLSpan) style[j]).getURL());
out.append("\">");
}
if (style[j] instanceof ImageSpan) {
out.append("<img src=\"");
out.append(((ImageSpan) style[j]).getSource());
out.append("\">");
// Don't output the dummy character underlying the image.
i = next;
}
if (style[j] instanceof AbsoluteSizeSpan) {
AbsoluteSizeSpan s = ((AbsoluteSizeSpan) style[j]);
float sizeDip = s.getSize();
if (!s.getDip()) {
Application application = ActivityThread.currentApplication();
sizeDip /= application.getResources().getDisplayMetrics().density;
}
// px in CSS is the equivalance of dip in Android
out.append(String.format("<span style=\"font-size:%.0fpx\";>", sizeDip));
}
if (style[j] instanceof RelativeSizeSpan) {
float sizeEm = ((RelativeSizeSpan) style[j]).getSizeChange();
out.append(String.format("<span style=\"font-size:%.2fem;\">", sizeEm));
}
if (style[j] instanceof ForegroundColorSpan) {
int color = ((ForegroundColorSpan) style[j]).getForegroundColor();
out.append(String.format("<span style=\"color:#%06X;\">", 0xFFFFFF & color));
}
if (style[j] instanceof BackgroundColorSpan) {
int color = ((BackgroundColorSpan) style[j]).getBackgroundColor();
out.append(String.format("<span style=\"background-color:#%06X;\">", 0xFFFFFF & color));
}
}
withinStyle(out, text, i, next);
for (int j = style.length - 1; j >= 0; j--) {
if (style[j] instanceof BackgroundColorSpan) {
out.append("</span>");
}
if (style[j] instanceof ForegroundColorSpan) {
out.append("</span>");
}
if (style[j] instanceof RelativeSizeSpan) {
out.append("</span>");
}
if (style[j] instanceof AbsoluteSizeSpan) {
out.append("</span>");
}
if (style[j] instanceof URLSpan) {
out.append("</a>");
}
if (style[j] instanceof StrikethroughSpan) {
out.append("</span>");
}
if (style[j] instanceof UnderlineSpan) {
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("</b>");
}
if ((s & Typeface.ITALIC) != 0) {
out.append("</i>");
}
}
}
}
}
use of android.text.style.RelativeSizeSpan in project CoCoin by Nightonke.
the class CoCoinUtil method init.
public static void init(Context context) {
typefaceLatoRegular = Typeface.createFromAsset(context.getAssets(), "fonts/Lato-Regular.ttf");
typefaceLatoHairline = Typeface.createFromAsset(context.getAssets(), "fonts/Lato-Hairline.ttf");
typefaceLatoLight = Typeface.createFromAsset(context.getAssets(), "fonts/LatoLatin-Light.ttf");
relativeSizeSpan = new RelativeSizeSpan(2f);
redForegroundSpan = new ForegroundColorSpan(Color.parseColor("#ff5252"));
greenForegroundSpan = new ForegroundColorSpan(Color.parseColor("#4ca550"));
whiteForegroundSpan = new ForegroundColorSpan(Color.parseColor("#ffffff"));
lastColor0 = "";
lastColor1 = "";
lastColor2 = "";
random = new Random();
MY_BLUE = ContextCompat.getColor(CoCoinApplication.getAppContext(), R.color.my_blue);
}
use of android.text.style.RelativeSizeSpan in project Etar-Calendar by Etar-Group.
the class AlertReceiver method makeExpandingNotification.
/**
* Creates an expanding notification. The initial expanded state is decided by
* the notification manager based on the priority.
*/
public static NotificationWrapper makeExpandingNotification(Context context, String title, String summaryText, String description, long startMillis, long endMillis, long eventId, int notificationId, boolean doPopup, int priority) {
Notification.Builder basicBuilder = new Notification.Builder(context);
Notification notification = buildBasicNotification(basicBuilder, context, title, summaryText, startMillis, endMillis, eventId, notificationId, doPopup, priority, true);
if (Utils.isJellybeanOrLater()) {
// Create a new-style expanded notification
Notification.BigTextStyle expandedBuilder = new Notification.BigTextStyle(basicBuilder);
if (description != null) {
description = mBlankLinePattern.matcher(description).replaceAll("");
description = description.trim();
}
CharSequence text;
if (TextUtils.isEmpty(description)) {
text = summaryText;
} else {
SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
stringBuilder.append(summaryText);
stringBuilder.append("\n\n");
stringBuilder.setSpan(new RelativeSizeSpan(0.5f), summaryText.length(), stringBuilder.length(), 0);
stringBuilder.append(description);
text = stringBuilder;
}
expandedBuilder.bigText(text);
notification = expandedBuilder.build();
}
return new NotificationWrapper(notification, notificationId, eventId, startMillis, endMillis, doPopup);
}
Aggregations