List of usage examples for android.text SpannableString length
int length();
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 ww. j a v a2s .com*/ 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.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:org.fdroid.enigtext.notifications.MessageNotifier.java
private static NotificationState constructNotificationState(Context context, MasterSecret masterSecret, Cursor cursor) {// w w w. jav 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; // 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 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); return result; }
From source file:com.coinblesk.client.utils.UIUtils.java
public static SpannableString toLargeSpannable(Context context, String amount, String currency, float sizeSpan) { final int amountLength = amount.length(); SpannableString result = new SpannableString(new StringBuffer(amount + " " + currency)); result.setSpan(new RelativeSizeSpan(sizeSpan), 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); return result; }
From source file:com.securecomcode.text.notifications.MessageNotifier.java
private static NotificationState constructNotificationState(Context context, MasterSecret masterSecret, Cursor cursor) {/* ww w . ja va 2 s .co 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.just.agentweb.AgentWebUtils.java
static void show(View parent, CharSequence text, int duration, @ColorInt int textColor, @ColorInt int bgColor, CharSequence actionText, @ColorInt int actionTextColor, View.OnClickListener listener) { SpannableString spannableString = new SpannableString(text); ForegroundColorSpan colorSpan = new ForegroundColorSpan(textColor); spannableString.setSpan(colorSpan, 0, spannableString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); snackbarWeakReference = new WeakReference<>(Snackbar.make(parent, spannableString, duration)); Snackbar snackbar = snackbarWeakReference.get(); View view = snackbar.getView(); view.setBackgroundColor(bgColor);// ww w. j a v a 2s. co m if (actionText != null && actionText.length() > 0 && listener != null) { snackbar.setActionTextColor(actionTextColor); snackbar.setAction(actionText, listener); } snackbar.show(); }
From source file:com.example.sample2.MainActivity.java
private void setActionBarTitle() { if (getSupportActionBar() == null) return;//w w w . j a v a 2 s . c o m TypefaceSpan span = new TypefaceSpan(this, "Audiowide-Regular"); ForegroundColorSpan colorSpan = new ForegroundColorSpan(Color.CYAN); SpannableString title = new SpannableString("TextViews2"); title.setSpan(span, 0, title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); title.setSpan(colorSpan, 4, title.length() - 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); getSupportActionBar().setTitle(title); }
From source file:io.github.hidroh.materialistic.widget.preference.HelpListView.java
private Spannable makeAsteriskSpan() { SpannableString sb = new SpannableString("*"); sb.setSpan(new AsteriskSpan(getContext()), sb.length() - 1, sb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return sb;/* w w w. j av a 2s .c om*/ }
From source file:io.github.hidroh.materialistic.widget.preference.HelpListView.java
@Override protected void onFinishInflate() { super.onFinishInflate(); ((TextView) findViewById(R.id.item_new).findViewById(R.id.rank)).append(makeAsteriskSpan()); SpannableString spannable = new SpannableString("+5"); spannable.setSpan(new SuperscriptSpan(), 0, spannable.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); spannable.setSpan(new RelativeSizeSpan(0.6f), 0, spannable.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); spannable.setSpan(new ForegroundColorSpan(ContextCompat.getColor(getContext(), R.color.greenA700)), 0, spannable.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); ((TextView) findViewById(R.id.item_promoted).findViewById(R.id.rank)).append(spannable); TextView comments = (TextView) findViewById(R.id.item_new_comments).findViewById(R.id.comment); SpannableStringBuilder sb = new SpannableStringBuilder("46"); sb.append(makeAsteriskSpan());/*from ww w.ja v a2s .c om*/ comments.setText(sb); }