use of android.text.style.RelativeSizeSpan in project android-client by GenesisVision.
the class StringFormatUtil method getDecimalSpannable.
public static SpannableString getDecimalSpannable(String value) {
boolean isNegative = value.startsWith("-");
final SpannableString text = new SpannableString(value);
if (isNegative) {
text.setSpan(new ForegroundColorSpan(ContextCompat.getColor(GenesisVisionApplication.INSTANCE, R.color.transactionRed)), 0, value.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
}
if (value.contains(".")) {
text.setSpan(new RelativeSizeSpan(0.7f), value.indexOf(".") + 1, value.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
text.setSpan(new ForegroundColorSpan(ContextCompat.getColor(GenesisVisionApplication.INSTANCE, R.color.black38)), value.indexOf("."), value.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
}
return text;
}
use of android.text.style.RelativeSizeSpan in project android_packages_apps_Settings by omnirom.
the class DataUsageSummary method formatUsage.
static CharSequence formatUsage(Context context, String template, long usageLevel, float larger, float smaller) {
final int FLAGS = Spannable.SPAN_INCLUSIVE_INCLUSIVE;
final Formatter.BytesResult usedResult = Formatter.formatBytes(context.getResources(), usageLevel, Formatter.FLAG_CALCULATE_ROUNDED | Formatter.FLAG_IEC_UNITS);
final SpannableString enlargedValue = new SpannableString(usedResult.value);
enlargedValue.setSpan(new RelativeSizeSpan(larger), 0, enlargedValue.length(), FLAGS);
final SpannableString amountTemplate = new SpannableString(context.getString(com.android.internal.R.string.fileSizeSuffix).replace("%1$s", "^1").replace("%2$s", "^2"));
final CharSequence formattedUsage = TextUtils.expandTemplate(amountTemplate, enlargedValue, usedResult.units);
final SpannableString fullTemplate = new SpannableString(template);
fullTemplate.setSpan(new RelativeSizeSpan(smaller), 0, fullTemplate.length(), FLAGS);
return TextUtils.expandTemplate(fullTemplate, BidiFormatter.getInstance().unicodeWrap(formattedUsage.toString()));
}
use of android.text.style.RelativeSizeSpan in project android_packages_apps_Settings by SudaMod.
the class DataUsageSummary method formatTitle.
private static CharSequence formatTitle(Context context, String template, long usageLevel) {
// (1/0.8)^2
final float LARGER_SIZE = 1.25f * 1.25f;
// 0.8^2
final float SMALLER_SIZE = 1.0f / LARGER_SIZE;
final int FLAGS = Spannable.SPAN_INCLUSIVE_INCLUSIVE;
final Formatter.BytesResult usedResult = Formatter.formatBytes(context.getResources(), usageLevel, Formatter.FLAG_SHORTER);
final SpannableString enlargedValue = new SpannableString(usedResult.value);
enlargedValue.setSpan(new RelativeSizeSpan(LARGER_SIZE), 0, enlargedValue.length(), FLAGS);
final SpannableString amountTemplate = new SpannableString(context.getString(com.android.internal.R.string.fileSizeSuffix).replace("%1$s", "^1").replace("%2$s", "^2"));
final CharSequence formattedUsage = TextUtils.expandTemplate(amountTemplate, enlargedValue, usedResult.units);
final SpannableString fullTemplate = new SpannableString(template);
fullTemplate.setSpan(new RelativeSizeSpan(SMALLER_SIZE), 0, fullTemplate.length(), FLAGS);
return TextUtils.expandTemplate(fullTemplate, BidiFormatter.getInstance().unicodeWrap(formattedUsage));
}
use of android.text.style.RelativeSizeSpan in project Pix-Art-Messenger by kriztan.
the class MessageAdapter method displayEmojiMessage.
private void displayEmojiMessage(final ViewHolder viewHolder, final String body) {
viewHolder.download_button.setVisibility(View.GONE);
viewHolder.audioPlayer.setVisibility(View.GONE);
viewHolder.image.setVisibility(View.GONE);
viewHolder.messageBody.setVisibility(View.VISIBLE);
Spannable span = new SpannableString(body);
float size = Emoticons.isEmoji(body) ? 3.0f : 2.0f;
span.setSpan(new RelativeSizeSpan(size), 0, body.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
viewHolder.messageBody.setText(EmojiWrapper.transform(span));
}
use of android.text.style.RelativeSizeSpan in project mapbox-navigation-android by mapbox.
the class TimeUtils method formatTimeRemaining.
public static SpannableStringBuilder formatTimeRemaining(double routeDuration) {
long seconds = (long) routeDuration;
if (seconds < 0) {
throw new IllegalArgumentException("Duration must be greater than zero.");
}
long days = TimeUnit.SECONDS.toDays(seconds);
seconds -= TimeUnit.DAYS.toSeconds(days);
long hours = TimeUnit.SECONDS.toHours(seconds);
seconds -= TimeUnit.HOURS.toSeconds(hours);
long minutes = TimeUnit.SECONDS.toMinutes(seconds);
seconds -= TimeUnit.MINUTES.toSeconds(minutes);
if (seconds >= 30) {
minutes = minutes + 1;
}
List<SpanItem> textSpanItems = new ArrayList<>();
if (days != 0) {
String dayFormat = days > 1 ? DAYS : DAY;
textSpanItems.add(new TextSpanItem(new StyleSpan(Typeface.BOLD), String.valueOf(days)));
textSpanItems.add(new TextSpanItem(new RelativeSizeSpan(1f), dayFormat));
}
if (hours != 0) {
textSpanItems.add(new TextSpanItem(new StyleSpan(Typeface.BOLD), String.valueOf(hours)));
textSpanItems.add(new TextSpanItem(new RelativeSizeSpan(1f), HOUR));
}
if (minutes != 0) {
textSpanItems.add(new TextSpanItem(new StyleSpan(Typeface.BOLD), String.valueOf(minutes)));
textSpanItems.add(new TextSpanItem(new RelativeSizeSpan(1f), MINUTE));
}
if (days == 0 && hours == 0 && minutes == 0) {
textSpanItems.add(new TextSpanItem(new StyleSpan(Typeface.BOLD), String.valueOf(1)));
textSpanItems.add(new TextSpanItem(new RelativeSizeSpan(1f), MINUTE));
}
return SpanUtils.combineSpans(textSpanItems);
}
Aggregations