Example usage for android.text SpannableString toString

List of usage examples for android.text SpannableString toString

Introduction

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

Prototype

public String toString();

Source Link

Document

Returns a string containing the characters in this sequence in the same order as this sequence.

Usage

From source file:Main.java

/**
 * Generate a SpannableString that styles a specific sub-sequence of a CharSequence object.
 *
 * @param sequence    The original text.
 * @param subSequence A sub-sequence of the original text.
 * @param styleSpan   The style to be applied to the sub-sequence.
 * @return A SpannableString with the style applied to only the sub-sequence of the original
 * text.//from ww  w  .j a  v a  2  s  .  c  o m
 */
public static SpannableString spanSubstring(CharSequence sequence, CharSequence subSequence,
        StyleSpan styleSpan) {
    SpannableString spannableString = new SpannableString(sequence);
    int startIndex = spannableString.toString().indexOf(subSequence.toString());
    int endIndex = startIndex + subSequence.toString().length();
    spannableString.setSpan(styleSpan, startIndex, endIndex, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    return spannableString;
}

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

private static NotificationState constructNotificationState(Context context, MasterSecret masterSecret,
        Cursor cursor) {/*from ww  w.ja  va  2s.  c o m*/
    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.todotxt.todotxttouch.util.Util.java

public static void setGray(SpannableString ss, List<String> items) {
    String data = ss.toString();

    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);
        }/*  w w w.ja v  a 2  s  . co  m*/

        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:nl.mpcjanssen.simpletask.util.Util.java

public static void setColor(SpannableString ss, int color, List<String> items) {
    String data = ss.toString();
    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  w ww  . jav  a  2s .c  o m
    }
}

From source file:com.securecomcode.text.notifications.MessageNotifier.java

private static NotificationState constructNotificationState(Context context, MasterSecret masterSecret,
        Cursor cursor) {/*from  w  w  w .  j av a  2 s .c  o m*/
    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;
        Recipients threadRecipients = null;

        if (threadId != -1) {
            threadRecipients = DatabaseFactory.getThreadDatabase(context).getRecipientsForThreadId(threadId);
        }

        // 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, threadRecipients, threadId, body, image));
    }

    reader.close();
    return notificationState;
}

From source file:com.google.android.gm.ay.java

public static void a(final Context context, final String s, final String s2, final long n, final int n2) {
    final List<String> b = com.google.android.gm.persistence.b.DD().b(context, true);
    int size;//ww  w.  ja v  a 2  s . c  om
    if (b != null && b.size() > 0) {
        size = b.size();
    } else {
        size = 1;
    }
    final String quantityString = context.getResources().getQuantityString(n2, size);
    final ab ab = new ab(context);
    if (size > 1) {
        final String string = context.getResources().getString(2131297166, new Object[] { s });
        final SpannableString spannableString = new SpannableString(
                (CharSequence) String.format(quantityString, string));
        final int index = spannableString.toString().indexOf(string);
        spannableString.setSpan((Object) new TextAppearanceSpan(context, 2131231210), index,
                index + string.length(), 0);
        ab.b((CharSequence) spannableString);
        ab.e((CharSequence) spannableString);
    } else {
        ab.b(quantityString);
        ab.e((CharSequence) quantityString);
    }
    final int hashCode = Arrays.hashCode(new Object[] { n, s2 });
    final Account x = x(context, s);
    final Folder h = h(context, s, "^^out");
    Intent a;
    if (h == null || s == null) {
        E.f(ay.mW, "Null account or folder.  account: %s folder: %s", x, h);
        a = null;
    } else {
        a = ag.a(context, h.azZ.aPj, x);
    }
    final NotificationManager notificationManager = (NotificationManager) context
            .getSystemService("notification");
    ab.h(17301624);
    ab.a(System.currentTimeMillis());
    ab.c(s2);
    ab.a(PendingIntent.getActivity(context, -1, a, 0));
    ArrayList<Integer> list = ay.aZj.get(s);
    if (list == null) {
        list = new ArrayList<Integer>();
    }
    list.add(hashCode);
    ay.aZj.put(s, list);
    notificationManager.notify(hashCode, ab.build());
}

From source file:eu.lucazanini.arpav.fragment.CreditsFragment.java

private SpannableString getTextWithLink(SpannableString text, String link, String site) {
    int start = text.toString().indexOf(link);
    int end = start + link.length();
    text.setSpan(new URLSpan(site), start, end, 0);
    return text;/*  w  ww  .ja va2 s  . c om*/
}

From source file:com.justwayward.reader.view.BookContentTextView.java

public void setText(String text) {
    int startIndex = 0;
    while (true) {

        int start = text.indexOf("");
        int end = text.indexOf("");
        if (start < 0 || end < 0) {
            append(text.substring(startIndex));
            break;
        }/* w  w w .  j a  va 2s.c  o  m*/

        append(text.substring(startIndex, start));

        SpannableString spanableInfo = new SpannableString(text.substring(start, end + 1));
        spanableInfo.setSpan(new Clickable(spanableInfo.toString()), 0, end + 1 - start,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        append(spanableInfo);
        //setMovementMethod()???
        setMovementMethod(LinkMovementMethod.getInstance());
        text = text.substring(end + 1);

        LogUtils.e(spanableInfo.toString());
    }
}

From source file:uk.co.threeonefour.android.snowball.activities.game.GameActivity.java

private void processOutputText(String text) {

    List<SpannableString> styledLines = formatter.format(text);

    StringBuilder sb = new StringBuilder();
    for (SpannableString styledLine : styledLines) {
        sb.append(styledLine.toString());
        sb.append(" ");
        textView.append(styledLine);//  w w w. jav a 2  s. c  o  m
        textView.append("\n");
    }

    if ((lastCommand == null || isNewLocation(lastCommand)) && !isBumpedInto(text)) {
        lastLocation = sb.toString();
    }

    textScrollView.fullScroll(View.FOCUS_DOWN);
    textScrollView.postDelayed(new Runnable() {
        @Override
        public void run() {
            textScrollView.fullScroll(View.FOCUS_DOWN);
        }
    }, 0);
}

From source file:uk.org.ngo.squeezer.itemlist.AlarmView.java

private void setDowText(AlarmViewHolder viewHolder, int day) {
    SpannableString text = new SpannableString(ServerString.getAlarmShortDayText(day));
    if (viewHolder.alarm.isDayActive(day)) {
        text.setSpan(new StyleSpan(Typeface.BOLD), 0, text.length(), 0);
        text.setSpan(new ForegroundColorSpan(mColorSelected), 0, text.length(), 0);
        Drawable underline = mResources.getDrawable(R.drawable.underline);
        float textSize = (new Paint()).measureText(text.toString());
        underline.setBounds(0, 0, (int) (textSize * mDensity), (int) (1 * mDensity));
        viewHolder.dowTexts[day].setCompoundDrawables(null, null, null, underline);
    } else//  w  w  w  . j  a  v a2s  .  c  om
        viewHolder.dowTexts[day].setCompoundDrawables(null, null, null, null);
    viewHolder.dowTexts[day].setText(text);
}