Search in sources :

Example 81 with RelativeSizeSpan

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;
}
Also used : SpannableString(android.text.SpannableString) ForegroundColorSpan(android.text.style.ForegroundColorSpan) RelativeSizeSpan(android.text.style.RelativeSizeSpan)

Example 82 with RelativeSizeSpan

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()));
}
Also used : SpannableString(android.text.SpannableString) BidiFormatter(android.text.BidiFormatter) Formatter(android.text.format.Formatter) RelativeSizeSpan(android.text.style.RelativeSizeSpan)

Example 83 with RelativeSizeSpan

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));
}
Also used : SpannableString(android.text.SpannableString) Formatter(android.text.format.Formatter) BidiFormatter(android.text.BidiFormatter) RelativeSizeSpan(android.text.style.RelativeSizeSpan)

Example 84 with RelativeSizeSpan

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));
}
Also used : SpannableString(android.text.SpannableString) RelativeSizeSpan(android.text.style.RelativeSizeSpan) Spannable(android.text.Spannable)

Example 85 with RelativeSizeSpan

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);
}
Also used : StyleSpan(android.text.style.StyleSpan) ArrayList(java.util.ArrayList) RelativeSizeSpan(android.text.style.RelativeSizeSpan) TextSpanItem(com.mapbox.services.android.navigation.v5.utils.span.TextSpanItem) TextSpanItem(com.mapbox.services.android.navigation.v5.utils.span.TextSpanItem) SpanItem(com.mapbox.services.android.navigation.v5.utils.span.SpanItem)

Aggregations

RelativeSizeSpan (android.text.style.RelativeSizeSpan)233 SpannableString (android.text.SpannableString)121 StyleSpan (android.text.style.StyleSpan)91 ForegroundColorSpan (android.text.style.ForegroundColorSpan)72 SpannableStringBuilder (android.text.SpannableStringBuilder)52 TypefaceSpan (android.text.style.TypefaceSpan)43 StrikethroughSpan (android.text.style.StrikethroughSpan)33 SuperscriptSpan (android.text.style.SuperscriptSpan)32 UnderlineSpan (android.text.style.UnderlineSpan)31 Spannable (android.text.Spannable)29 AbsoluteSizeSpan (android.text.style.AbsoluteSizeSpan)28 SubscriptSpan (android.text.style.SubscriptSpan)25 BackgroundColorSpan (android.text.style.BackgroundColorSpan)24 View (android.view.View)24 BidiFormatter (android.text.BidiFormatter)20 Formatter (android.text.format.Formatter)20 CharacterStyle (android.text.style.CharacterStyle)20 TextView (android.widget.TextView)20 SuppressLint (android.annotation.SuppressLint)17 URLSpan (android.text.style.URLSpan)17