use of android.text.SpannableStringBuilder in project android_frameworks_base by DirtyUnicorns.
the class NotificationTests method BOLD.
static SpannableStringBuilder BOLD(CharSequence str) {
final SpannableStringBuilder ssb = new SpannableStringBuilder(str);
ssb.setSpan(new StyleSpan(Typeface.BOLD), 0, ssb.length(), 0);
return ssb;
}
use of android.text.SpannableStringBuilder in project android_frameworks_base by DirtyUnicorns.
the class Clock method getSmallTime.
private final CharSequence getSmallTime() {
Context context = getContext();
boolean is24 = DateFormat.is24HourFormat(context, ActivityManager.getCurrentUser());
LocaleData d = LocaleData.get(context.getResources().getConfiguration().locale);
final char MAGIC1 = '';
final char MAGIC2 = '';
SimpleDateFormat sdf;
String format = mShowSeconds ? is24 ? d.timeFormat_Hms : d.timeFormat_hms : is24 ? d.timeFormat_Hm : d.timeFormat_hm;
if (!format.equals(mClockFormatString)) {
mContentDescriptionFormat = new SimpleDateFormat(format);
/*
* Search for an unquoted "a" in the format string, so we can
* add dummy characters around it to let us find it again after
* formatting and change its size.
*/
if (mAmPmStyle != AM_PM_STYLE_NORMAL) {
int a = -1;
boolean quoted = false;
for (int i = 0; i < format.length(); i++) {
char c = format.charAt(i);
if (c == '\'') {
quoted = !quoted;
}
if (!quoted && c == 'a') {
a = i;
break;
}
}
if (a >= 0) {
// Move a back so any whitespace before AM/PM is also in the alternate size.
final int b = a;
while (a > 0 && Character.isWhitespace(format.charAt(a - 1))) {
a--;
}
format = format.substring(0, a) + MAGIC1 + format.substring(a, b) + "a" + MAGIC2 + format.substring(b + 1);
}
}
mClockFormat = sdf = new SimpleDateFormat(format);
mClockFormatString = format;
} else {
sdf = mClockFormat;
}
CharSequence dateString = null;
String result = "";
String timeResult = sdf.format(mCalendar.getTime());
String dateResult = "";
int clockDatePosition = Settings.System.getInt(getContext().getContentResolver(), Settings.System.STATUSBAR_CLOCK_DATE_POSITION, 0);
if (mClockDateDisplay != CLOCK_DATE_DISPLAY_GONE) {
Date now = new Date();
String clockDateFormat = Settings.System.getString(getContext().getContentResolver(), Settings.System.STATUSBAR_CLOCK_DATE_FORMAT);
if (clockDateFormat == null || clockDateFormat.isEmpty()) {
// Set dateString to short uppercase Weekday (Default for AOKP) if empty
dateString = DateFormat.format("EEE", now);
} else {
dateString = DateFormat.format(clockDateFormat, now);
}
if (mClockDateStyle == CLOCK_DATE_STYLE_LOWERCASE) {
// When Date style is small, convert date to uppercase
dateResult = dateString.toString().toLowerCase();
} else if (mClockDateStyle == CLOCK_DATE_STYLE_UPPERCASE) {
dateResult = dateString.toString().toUpperCase();
} else {
dateResult = dateString.toString();
}
result = (clockDatePosition == STYLE_DATE_LEFT) ? dateResult + " " + timeResult : timeResult + " " + dateResult;
} else {
// No date, just show time
result = timeResult;
}
SpannableStringBuilder formatted = new SpannableStringBuilder(result);
if (mClockDateDisplay != CLOCK_DATE_DISPLAY_NORMAL) {
if (dateString != null) {
int dateStringLen = dateString.length();
int timeStringOffset = (clockDatePosition == STYLE_DATE_RIGHT) ? timeResult.length() + 1 : 0;
if (mClockDateDisplay == CLOCK_DATE_DISPLAY_GONE) {
formatted.delete(0, dateStringLen);
} else {
if (mClockDateDisplay == CLOCK_DATE_DISPLAY_SMALL) {
CharacterStyle style = new RelativeSizeSpan(0.7f);
formatted.setSpan(style, timeStringOffset, timeStringOffset + dateStringLen, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
}
}
}
}
if (mAmPmStyle != AM_PM_STYLE_NORMAL) {
int magic1 = result.indexOf(MAGIC1);
int magic2 = result.indexOf(MAGIC2);
if (magic1 >= 0 && magic2 > magic1) {
if (mAmPmStyle == AM_PM_STYLE_GONE) {
formatted.delete(magic1, magic2 + 1);
} else {
if (mAmPmStyle == AM_PM_STYLE_SMALL) {
CharacterStyle style = new RelativeSizeSpan(0.7f);
formatted.setSpan(style, magic1, magic2, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
}
formatted.delete(magic2, magic2 + 1);
formatted.delete(magic1, magic1 + 1);
}
}
}
return formatted;
}
use of android.text.SpannableStringBuilder in project android_frameworks_base by DirtyUnicorns.
the class NotificationColorUtil method invertCharSequenceColors.
/**
* Inverts all the grayscale colors set by {@link android.text.style.TextAppearanceSpan}s on
* the text.
*
* @param charSequence The text to process.
* @return The color inverted text.
*/
public CharSequence invertCharSequenceColors(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 (span instanceof TextAppearanceSpan) {
resultSpan = processTextAppearanceSpan((TextAppearanceSpan) span);
}
builder.setSpan(resultSpan, ss.getSpanStart(span), ss.getSpanEnd(span), ss.getSpanFlags(span));
}
return builder;
}
return charSequence;
}
use of android.text.SpannableStringBuilder in project android_frameworks_base by DirtyUnicorns.
the class CustomTile method handleUpdateState.
@Override
protected void handleUpdateState(State state, Object arg) {
int tileState = mTile.getState();
if (mServiceManager.hasPendingBind()) {
tileState = Tile.STATE_UNAVAILABLE;
}
Drawable drawable;
boolean mHasRes = false;
android.graphics.drawable.Icon icon = mTile.getIcon();
try {
drawable = icon.loadDrawable(mAppContext);
mHasRes = icon.getType() == android.graphics.drawable.Icon.TYPE_RESOURCE;
} catch (Exception e) {
Log.w(TAG, "Invalid icon, forcing into unavailable state");
tileState = Tile.STATE_UNAVAILABLE;
drawable = mDefaultIcon.loadDrawable(mAppContext);
}
int color = mContext.getColor(getColor(tileState));
drawable.setTint(color);
state.icon = mHasRes ? new DrawableIconWithRes(drawable, icon.getResId(), color) : new DrawableIcon(drawable);
state.label = mTile.getLabel();
if (tileState == Tile.STATE_UNAVAILABLE) {
state.label = new SpannableStringBuilder().append(state.label, new ForegroundColorSpan(color), SpannableStringBuilder.SPAN_INCLUSIVE_INCLUSIVE);
}
if (mTile.getContentDescription() != null) {
state.contentDescription = mTile.getContentDescription();
} else {
state.contentDescription = state.label;
}
}
use of android.text.SpannableStringBuilder 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;
}
Aggregations