use of android.text.style.ImageSpan in project android_frameworks_base by ParanoidAndroid.
the class SearchView method getDecoratedHint.
private CharSequence getDecoratedHint(CharSequence hintText) {
// If the field is always expanded, then don't add the search icon to the hint
if (!mIconifiedByDefault)
return hintText;
// for the icon
SpannableStringBuilder ssb = new SpannableStringBuilder(" ");
ssb.append(hintText);
Drawable searchIcon = getContext().getResources().getDrawable(getSearchIconId());
int textSize = (int) (mQueryTextView.getTextSize() * 1.25);
searchIcon.setBounds(0, 0, textSize, textSize);
ssb.setSpan(new ImageSpan(searchIcon), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
return ssb;
}
use of android.text.style.ImageSpan in project platform_frameworks_base by android.
the class RecentsCreateFragment method appendDrawable.
private static void appendDrawable(SpannableStringBuilder b, Drawable d) {
final int length = b.length();
b.append("〉");
b.setSpan(new ImageSpan(d), length, b.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
use of android.text.style.ImageSpan in project platform_frameworks_base by android.
the class RestrictedLockUtils method setTextViewPadlock.
public static void setTextViewPadlock(Context context, TextView textView, boolean showPadlock) {
final SpannableStringBuilder sb = new SpannableStringBuilder(textView.getText());
removeExistingRestrictedSpans(sb);
if (showPadlock) {
final ImageSpan image = new RestrictedLockImageSpan(context);
sb.append(" ", image, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
textView.setText(sb);
}
use of android.text.style.ImageSpan in project platform_frameworks_base by android.
the class RestrictedLockUtils method removeExistingRestrictedSpans.
private static void removeExistingRestrictedSpans(SpannableStringBuilder sb) {
final int length = sb.length();
RestrictedLockImageSpan[] imageSpans = sb.getSpans(length - 1, length, RestrictedLockImageSpan.class);
for (ImageSpan span : imageSpans) {
final int start = sb.getSpanStart(span);
final int end = sb.getSpanEnd(span);
sb.removeSpan(span);
sb.delete(start, end);
}
ForegroundColorSpan[] colorSpans = sb.getSpans(0, length, ForegroundColorSpan.class);
for (ForegroundColorSpan span : colorSpans) {
sb.removeSpan(span);
}
}
use of android.text.style.ImageSpan 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>");
}
}
}
}
}
Aggregations