Example usage for android.text SpannableString setSpan

List of usage examples for android.text SpannableString setSpan

Introduction

In this page you can find the example usage for android.text SpannableString setSpan.

Prototype

public void setSpan(Object what, int start, int end, int flags) 

Source Link

Usage

From source file:com.android.mail.browse.SendersView.java

public static SpannableString getSingularDraftString(Context context) {
    getSenderResources(context, true /* resourceCachingRequired */);
    final SpannableString formattedDraftString = new SpannableString(sDraftSingularString);
    final CharacterStyle readStyle = CharacterStyle.wrap(sDraftsStyleSpan);
    formattedDraftString.setSpan(readStyle, 0, formattedDraftString.length(), 0);
    return formattedDraftString;
}

From source file:Main.java

public static CharSequence replace(Context context, String text) {
    if (TextUtils.isEmpty(text)) {
        return text;
    }/*from   w  w  w .j a  v a 2s  . c o m*/
    SpannableString spannableString = new SpannableString(text);
    Matcher matcher = pattern.matcher(text);
    while (matcher.find()) {
        String factText = matcher.group();
        String key = factText.substring(1, factText.length() - 1);
        if (contain(emojiCodes, factText)) {
            Bitmap bitmap = getEmojiDrawable(context, key);
            ImageSpan image = new ImageSpan(context, bitmap);
            int start = matcher.start();
            int end = matcher.end();
            spannableString.setSpan(image, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
    return spannableString;
}

From source file:nl.mpcjanssen.simpletask.util.Util.java

public static void setColor(SpannableString ss, int color, List<String> items) {
    String data = ss.toString();//from ww w . ja  v  a 2  s . com
    for (String item : items) {
        int i = data.indexOf(item);
        if (i != -1) {
            ss.setSpan(new ForegroundColorSpan(color), i, i + item.length(),
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
}

From source file:com.todotxt.todotxttouch.util.Util.java

public static void setGray(SpannableString ss, List<String> items) {
    String data = ss.toString();//from www  .  jav a  2s .co m

    for (String item : items) {
        int i = data.indexOf("@" + item);

        if (i != -1) {
            ss.setSpan(new ForegroundColorSpan(Color.GRAY), i, i + 1 + item.length(),
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }

        int j = data.indexOf("+" + item);

        if (j != -1) {
            ss.setSpan(new ForegroundColorSpan(Color.GRAY), j, j + 1 + item.length(),
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
}

From source file:org.thoughtcrime.SMP.notifications.MessageNotifier.java

private static void appendPushNotificationState(Context context, MasterSecret masterSecret,
        NotificationState notificationState, Cursor cursor) {
    if (masterSecret != null)
        return;/*from   w  w w.  ja  va2s . c o m*/

    PushDatabase.Reader reader = null;
    TextSecureEnvelope envelope;

    try {
        reader = DatabaseFactory.getPushDatabase(context).readerFor(cursor);

        while ((envelope = reader.getNext()) != null) {
            Recipients recipients = RecipientFactory.getRecipientsFromString(context, envelope.getSource(),
                    false);
            Recipient recipient = recipients.getPrimaryRecipient();
            long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipients);
            SpannableString body = new SpannableString(
                    context.getString(R.string.MessageNotifier_encrypted_message));
            body.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), 0, body.length(),
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

            if (!recipients.isMuted()) {
                notificationState.addNotification(
                        new NotificationItem(recipient, recipients, null, threadId, body, null, 0));
            }
        }
    } finally {
        if (reader != null)
            reader.close();
    }
}

From source file:com.tct.mail.browse.SendersView.java

public static SpannableString getFormattedToHeader() {
    // TS: junwei-xu 2015-03-26 EMAIL BUGFIX-959039 MOD_S
    final SpannableString formattedToHeader = new SpannableString(
            sToHeaderString == null ? "" : sToHeaderString);
    // TS: junwei-xu 2015-03-26 EMAIL BUGFIX-959039 MOD_E
    final CharacterStyle readStyle = CharacterStyle.wrap(sReadStyleSpan);
    formattedToHeader.setSpan(readStyle, 0, formattedToHeader.length(), 0);
    return formattedToHeader;
}

From source file:org.fdroid.enigtext.notifications.MessageNotifier.java

private static NotificationState constructNotificationState(Context context, MasterSecret masterSecret,
        Cursor cursor) {/* ww  w  .  j av  a  2  s .  c  om*/
    NotificationState notificationState = new NotificationState();
    MessageRecord record;
    MmsSmsDatabase.Reader reader;

    if (masterSecret == null)
        reader = DatabaseFactory.getMmsSmsDatabase(context).readerFor(cursor);
    else
        reader = DatabaseFactory.getMmsSmsDatabase(context).readerFor(cursor, masterSecret);

    while ((record = reader.getNext()) != null) {
        Recipient recipient = record.getIndividualRecipient();
        Recipients recipients = record.getRecipients();
        long threadId = record.getThreadId();
        SpannableString body = record.getDisplayBody();
        Uri image = null;

        // XXXX This is so fucked up.  FIX ME!
        if (body.toString().equals(context.getString(R.string.MessageDisplayHelper_decrypting_please_wait))) {
            body = new SpannableString(context.getString(R.string.MessageNotifier_encrypted_message));
            body.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), 0, body.length(),
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }

        notificationState.addNotification(new NotificationItem(recipient, recipients, threadId, body, image));
    }

    reader.close();
    return notificationState;
}

From source file:com.coinblesk.client.utils.UIUtils.java

public static SpannableString toFriendlySnackbarString(Context context, String input) {
    final ForegroundColorSpan whiteSpan = new ForegroundColorSpan(
            ContextCompat.getColor(context, R.color.colorAccent));
    final SpannableString snackbarText = new SpannableString(input);
    snackbarText.setSpan(whiteSpan, 0, snackbarText.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
    return snackbarText;
}

From source file:com.coinblesk.client.utils.UIUtils.java

public static SpannableString toFriendlyFeeString(Context context, Transaction tx) {
    Coin fee = tx.getFee();//from  www .  ja  v a  2 s.  c om
    ExchangeRate exchangeRate = tx.getExchangeRate();
    if (fee == null) {
        return new SpannableString("");
    }

    StringBuffer friendlyFee = new StringBuffer(UIUtils.formatCoin(context, fee));
    int feeLength = friendlyFee.length();

    int exchangeRateLength = feeLength;
    if (exchangeRate != null) {
        friendlyFee.append(" ~ " + exchangeRate.coinToFiat(fee).toFriendlyString());
        exchangeRateLength = friendlyFee.length();
    }

    SpannableString friendlySpannable = new SpannableString(friendlyFee);
    friendlySpannable.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, R.color.main_color_400)),
            feeLength, exchangeRateLength, 0);
    return friendlySpannable;

}

From source file:com.coinblesk.client.utils.UIUtils.java

public static SpannableString toLargeSpannable(Context context, String amount, String currency) {
    final int amountLength = amount.length();
    SpannableString result = new SpannableString(new StringBuffer(amount + " " + currency));
    result.setSpan(new RelativeSizeSpan(2), 0, amountLength, 0);
    result.setSpan(new ForegroundColorSpan(Color.WHITE), 0, amountLength, 0);
    result.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, R.color.colorAccent)), amountLength,
            result.length(), 0);/*  w w w.jav a 2 s.  c o m*/
    return result;
}