List of usage examples for android.text SpannableStringBuilder length
public int length()
From source file:org.sufficientlysecure.keychain.ui.ViewKeyKeybaseFragment.java
@Override public void onCryptoOperationSuccess(KeybaseVerificationResult result) { result.createNotify(getActivity()).show(); String proofUrl = result.mProofUrl; String presenceUrl = result.mPresenceUrl; String presenceLabel = result.mPresenceLabel; Proof proof = mProof; // TODO: should ideally be contained in result String proofLabel;//from ww w . j a v a 2 s.c o m switch (proof.getType()) { case Proof.PROOF_TYPE_TWITTER: proofLabel = getString(R.string.keybase_twitter_proof); break; case Proof.PROOF_TYPE_DNS: proofLabel = getString(R.string.keybase_dns_proof); break; case Proof.PROOF_TYPE_WEB_SITE: proofLabel = getString(R.string.keybase_web_site_proof); break; case Proof.PROOF_TYPE_GITHUB: proofLabel = getString(R.string.keybase_github_proof); break; case Proof.PROOF_TYPE_REDDIT: proofLabel = getString(R.string.keybase_reddit_proof); break; default: proofLabel = getString(R.string.keybase_a_post); break; } SpannableStringBuilder ssb = new SpannableStringBuilder(); ssb.append(getString(R.string.keybase_proof_succeeded)); StyleSpan bold = new StyleSpan(Typeface.BOLD); ssb.setSpan(bold, 0, ssb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); ssb.append("\n\n"); int length = ssb.length(); ssb.append(proofLabel); if (proofUrl != null) { URLSpan postLink = new URLSpan(proofUrl); ssb.setSpan(postLink, length, length + proofLabel.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } if (Proof.PROOF_TYPE_DNS == proof.getType()) { ssb.append(" ").append(getString(R.string.keybase_for_the_domain)).append(" "); } else { ssb.append(" ").append(getString(R.string.keybase_fetched_from)).append(" "); } length = ssb.length(); URLSpan presenceLink = new URLSpan(presenceUrl); ssb.append(presenceLabel); ssb.setSpan(presenceLink, length, length + presenceLabel.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); if (Proof.PROOF_TYPE_REDDIT == proof.getType()) { ssb.append(", ").append(getString(R.string.keybase_reddit_attribution)).append(" ") .append(proof.getHandle()).append("?, "); } ssb.append(" ").append(getString(R.string.keybase_contained_signature)); displaySpannableResult(ssb); }
From source file:com.kncwallet.wallet.ui.TransactionsListFragment.java
@Override public void onViewCreated(final View view, final Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); final SpannableStringBuilder emptyText = new SpannableStringBuilder( getString(direction == Direction.SENT ? R.string.wallet_transactions_fragment_empty_text_sent : R.string.wallet_transactions_fragment_empty_text_received)); emptyText.setSpan(new StyleSpan(Typeface.BOLD), 0, emptyText.length(), SpannableStringBuilder.SPAN_POINT_MARK); if (direction != Direction.SENT) emptyText.append("\n\n").append(getString(R.string.wallet_transactions_fragment_empty_text_howto)); Drawable divider = getResources().getDrawable(R.drawable.transaction_list_divider); this.getListView().setDivider(divider); this.getListView().setDividerHeight(1); setEmptyText(emptyText);//from ww w .j a v a2s. co m }
From source file:tw.idv.gasolin.pycontw2012.ui.SessionDetailFragment.java
/** * Handle {@link SessionsQuery} {@link Cursor}. *//*from ww w .j a va 2 s . c om*/ private void onSessionQueryComplete(Cursor cursor) { try { mSessionCursor = true; if (!cursor.moveToFirst()) { return; } // Format time block this session occupies final long blockStart = cursor.getLong(SessionsQuery.BLOCK_START); final long blockEnd = cursor.getLong(SessionsQuery.BLOCK_END); final Locale locale = getResources().getConfiguration().locale; final String roomName = UIUtils.getBestLocaleString(locale, cursor.getString(SessionsQuery.ROOM_NAME), cursor.getString(SessionsQuery.ROOM_NAME_ZH_TW), cursor.getString(SessionsQuery.ROOM_NAME_ZH_CN)); final String subtitle = UIUtils.formatSessionSubtitle(blockStart, blockEnd, roomName, getActivity()); mTitleString = cursor.getString(SessionsQuery.TITLE); mTitle.setText(mTitleString); mSubtitle.setText(subtitle); mUrl = cursor.getString(SessionsQuery.URL); if (TextUtils.isEmpty(mUrl)) { mUrl = ""; } mHashtag = cursor.getString(SessionsQuery.HASHTAG); mTagDisplay = (TextView) mRootView.findViewById(R.id.session_tags_button); if (!TextUtils.isEmpty(mHashtag)) { // Create the button text SpannableStringBuilder sb = new SpannableStringBuilder(); sb.append(getString(R.string.tag_stream) + " "); int boldStart = sb.length(); sb.append(getHashtagsString()); sb.setSpan(sBoldSpan, boldStart, sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); mTagDisplay.setText(sb); mTagDisplay.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent intent = new Intent(getActivity(), TagStreamActivity.class); intent.putExtra(TagStreamFragment.EXTRA_QUERY, getHashtagsString()); startActivity(intent); } }); } else { mTagDisplay.setVisibility(View.GONE); } mRoomId = cursor.getString(SessionsQuery.ROOM_ID); // Unregister around setting checked state to avoid triggering // listener since change isn't user generated. mStarred.setOnCheckedChangeListener(null); mStarred.setChecked(cursor.getInt(SessionsQuery.STARRED) != 0); mStarred.setOnCheckedChangeListener(this); final String sessionAbstract = cursor.getString(SessionsQuery.ABSTRACT); if (!TextUtils.isEmpty(sessionAbstract)) { UIUtils.setTextMaybeHtml(mAbstract, sessionAbstract); mAbstract.setVisibility(View.VISIBLE); mHasSummaryContent = true; } else { mAbstract.setVisibility(View.GONE); } // Show empty message when all data is loaded, and nothing to show if (mSpeakersCursor && !mHasSummaryContent) { mRootView.findViewById(android.R.id.empty).setVisibility(View.VISIBLE); } AnalyticsUtils.getInstance(getActivity()).trackPageView("/Sessions/" + mTitleString); updateLinksTab(cursor); } finally { cursor.close(); } }
From source file:com.matthewmitchell.peercoin_android_wallet.ui.TransactionsListFragment.java
@Override public void onLoadFinished(final Loader<List<Transaction>> loader, final List<Transaction> transactions) { adapter.replace(transactions);/*from w w w . jav a 2 s . co m*/ final SpannableStringBuilder emptyText = new SpannableStringBuilder( getString(direction == Direction.SENT ? R.string.wallet_transactions_fragment_empty_text_sent : R.string.wallet_transactions_fragment_empty_text_received)); emptyText.setSpan(new StyleSpan(Typeface.BOLD), 0, emptyText.length(), SpannableStringBuilder.SPAN_POINT_MARK); if (direction != Direction.SENT) emptyText.append("\n\n").append(getString(R.string.wallet_transactions_fragment_empty_text_howto)); setEmptyText(emptyText); }
From source file:com.goliathonline.android.kegbot.ui.DrinkDetailFragment.java
/** * Handle {@link SessionsQuery} {@link Cursor}. *//*from w ww. j a va2s . c o m*/ private void onDrinkQueryComplete(Cursor cursor) { try { mSessionCursor = true; if (!cursor.moveToFirst()) { return; } // Format time block this session occupies //final long blockStart = cursor.getLong(DrinksQuery.BLOCK_START); //final long blockEnd = cursor.getLong(DrinksQuery.BLOCK_END); //final String roomName = cursor.getString(DrinksQuery.ROOM_NAME); //final String subtitle = UIUtils.formatSessionSubtitle(blockStart, // blockEnd, roomName, getActivity()); mTitleString = "Drink " + cursor.getString(DrinksQuery.DRINK_ID); mTitle.setText(mTitleString); String userId = cursor.getString(DrinksQuery.USER_ID); if (TextUtils.isEmpty(userId)) userId = "guest"; mSubtitle.setText(userId); //mUrl = cursor.getString(DrinksQuery.URL); if (TextUtils.isEmpty(mUrl)) { mUrl = ""; } //mHashtag = cursor.getString(DrinksQuery.HASHTAG); mTagDisplay = (TextView) mRootView.findViewById(R.id.session_tags_button); if (!TextUtils.isEmpty(mHashtag)) { // Create the button text SpannableStringBuilder sb = new SpannableStringBuilder(); sb.append(getString(R.string.tag_stream) + " "); int boldStart = sb.length(); sb.append(getHashtagsString()); sb.setSpan(sBoldSpan, boldStart, sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); mTagDisplay.setText(sb); mTagDisplay.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent intent = new Intent(getActivity(), TagStreamActivity.class); intent.putExtra(TagStreamFragment.EXTRA_QUERY, getHashtagsString()); startActivity(intent); } }); } else { mTagDisplay.setVisibility(View.GONE); } //mRoomId = cursor.getString(DrinksQuery.ROOM_ID); // Unregister around setting checked state to avoid triggering // listener since change isn't user generated. mStarred.setOnCheckedChangeListener(null); mStarred.setChecked(cursor.getInt(DrinksQuery.STARRED) != 0); mStarred.setOnCheckedChangeListener(this); final String sessionAbstract = ""; //cursor.getString(DrinksQuery.ABSTRACT); if (!TextUtils.isEmpty(sessionAbstract)) { UIUtils.setTextMaybeHtml(mAbstract, sessionAbstract); mAbstract.setVisibility(View.VISIBLE); mHasSummaryContent = true; } else { mAbstract.setVisibility(View.GONE); } final View requirementsBlock = mRootView.findViewById(R.id.drink_pour_block); final String sessionRequirements = UnitUtils.mlToOz(cursor.getString(DrinksQuery.VOLUME)) + "oz"; if (!TextUtils.isEmpty(sessionRequirements)) { UIUtils.setTextMaybeHtml(mRequirements, sessionRequirements); requirementsBlock.setVisibility(View.VISIBLE); mHasSummaryContent = true; } else { requirementsBlock.setVisibility(View.GONE); } // Show empty message when all data is loaded, and nothing to show if (mSpeakersCursor && !mHasSummaryContent) { mRootView.findViewById(android.R.id.empty).setVisibility(View.VISIBLE); } AnalyticsUtils.getInstance(getActivity()).trackPageView("/Drinks/" + mTitleString); updateLinksTab(cursor); updateNotesTab(); } finally { cursor.close(); } }
From source file:com.battlelancer.seriesguide.ui.dialogs.AddShowDialogFragment.java
private void populateShowViews(Show show) { if (show == null) { mButtonPositive.setEnabled(false); if (!AndroidUtils.isNetworkConnected(getActivity())) { overview.setText(R.string.offline); }/*from w ww.ja va 2 s .c o m*/ return; } mButtonPositive.setEnabled(true); ButterKnife.apply(labelViews, VISIBLE, true); // title, overview title.setText(show.title); overview.setText(show.overview); SpannableStringBuilder meta = new SpannableStringBuilder(); // status boolean isContinuing = JsonExportTask.ShowStatusExport.CONTINUING.equals(show.status); meta.append(getString(isContinuing ? R.string.show_isalive : R.string.show_isnotalive)); // if continuing, paint status green meta.setSpan( new TextAppearanceSpan(getActivity(), isContinuing ? R.style.TextAppearance_Subhead_Green : R.style.TextAppearance_Subhead_Dim), 0, meta.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); meta.append("\n"); // release day and time String[] values = TimeTools.formatToShowReleaseTimeAndDay(getActivity(), show.airtime, show.country, show.airday); meta.append(values[1]).append(" ").append(values[0]); meta.append("\n"); // network, runtime meta.append(show.network); meta.append("\n"); meta.append(getString(R.string.runtime_minutes, show.runtime)); showmeta.setText(meta); // TheTVDB rating tvdbRating.setText(show.rating > 0 ? String.valueOf(show.rating) : getString(R.string.norating)); // genres Utils.setValueOrPlaceholder(genres, Utils.splitAndKitTVDBStrings(show.genres)); // original release Utils.setValueOrPlaceholder(released, TimeTools.getShowReleaseYear(show.firstAired, show.airtime, show.country)); // poster Utils.loadPosterThumbnail(getActivity(), poster, show.poster); }
From source file:com.googlecode.eyesfree.brailleback.BrailleIME.java
public void updateDisplay() { if (mExtractedText == null) { return;//from w w w . java2 s .c o m } DisplayManager displayManager = getCurrentDisplayManager(); if (displayManager == null) { return; } EditorInfo ei = getCurrentInputEditorInfo(); if (ei == null) { LogUtils.log(this, Log.WARN, "No input editor info"); return; } CharSequence label = ei.label; CharSequence hint = ei.hintText; if (TextUtils.isEmpty(label)) { label = hint; hint = null; } SpannableStringBuilder text = new SpannableStringBuilder(); if (!TextUtils.isEmpty(label)) { text.append(label); text.append(": "); // TODO: Put in a resource. } int editStart = text.length(); text.append(mCurrentText); addMarkingSpan(text, EDIT_TEXT_SPAN, editStart); CharSequence actionLabel = getActionLabel(); if (actionLabel != null) { text.append(" ["); text.append(actionLabel); text.append("]"); addMarkingSpan(text, ACTION_LABEL_SPAN, text.length() - (actionLabel.length() + 2)); } DisplaySpans.addSelection(text, editStart + mSelectionStart, editStart + mSelectionEnd); displayManager.setContent(new DisplayManager.Content(text).setPanStrategy(DisplayManager.Content.PAN_CURSOR) .setSplitParagraphs(isMultiLineField())); }
From source file:com.battlelancer.seriesguide.service.NotificationService.java
private void onNotify(final Cursor upcomingEpisodes, List<Integer> notifyPositions, long latestAirtime) { final Context context = getApplicationContext(); CharSequence tickerText;//from w w w. ja v a 2 s . co m CharSequence contentTitle; CharSequence contentText; PendingIntent contentIntent; // base intent for task stack final Intent showsIntent = new Intent(context, ShowsActivity.class); showsIntent.putExtra(ShowsActivity.InitBundle.SELECTED_TAB, ShowsActivity.InitBundle.INDEX_TAB_UPCOMING); final int count = notifyPositions.size(); if (count == 1) { // notify in detail about one episode Timber.d("Notifying about 1 new episode"); upcomingEpisodes.moveToPosition(notifyPositions.get(0)); final String showTitle = upcomingEpisodes.getString(NotificationQuery.SHOW_TITLE); tickerText = getString(R.string.upcoming_show, showTitle); contentTitle = showTitle + " " + Utils.getEpisodeNumber(this, upcomingEpisodes.getInt(NotificationQuery.SEASON), upcomingEpisodes.getInt(NotificationQuery.NUMBER)); // "8:00 PM on Network" final String releaseTime = TimeTools.formatToLocalReleaseTime(this, TimeTools.getEpisodeReleaseTime( this, upcomingEpisodes.getLong(NotificationQuery.EPISODE_FIRST_RELEASE_MS))); final String network = upcomingEpisodes.getString(NotificationQuery.NETWORK); contentText = getString(R.string.upcoming_show_detailed, releaseTime, network); Intent episodeDetailsIntent = new Intent(context, EpisodesActivity.class); episodeDetailsIntent.putExtra(EpisodesActivity.InitBundle.EPISODE_TVDBID, upcomingEpisodes.getInt(NotificationQuery._ID)); episodeDetailsIntent.putExtra(KEY_EPISODE_CLEARED_TIME, latestAirtime); contentIntent = TaskStackBuilder.create(context).addNextIntent(showsIntent) .addNextIntent(episodeDetailsIntent) .getPendingIntent(REQUEST_CODE_SINGLE_EPISODE, PendingIntent.FLAG_CANCEL_CURRENT); } else { // notify about multiple episodes Timber.d("Notifying about " + count + " new episodes"); tickerText = getString(R.string.upcoming_episodes); contentTitle = getString(R.string.upcoming_episodes_number, count); contentText = getString(R.string.upcoming_display); contentIntent = TaskStackBuilder.create(context) .addNextIntent(showsIntent.putExtra(KEY_EPISODE_CLEARED_TIME, latestAirtime)) .getPendingIntent(REQUEST_CODE_MULTIPLE_EPISODES, PendingIntent.FLAG_CANCEL_CURRENT); } final NotificationCompat.Builder nb = new NotificationCompat.Builder(context); if (AndroidUtils.isJellyBeanOrHigher()) { Timber.d("Building rich notification (JB+)"); // JELLY BEAN and above if (count == 1) { // single episode upcomingEpisodes.moveToPosition(notifyPositions.get(0)); maybeSetPoster(context, nb, upcomingEpisodes.getString(NotificationQuery.POSTER)); final String episodeTitle = upcomingEpisodes.getString(NotificationQuery.TITLE); final String episodeSummary = upcomingEpisodes.getString(NotificationQuery.OVERVIEW); final SpannableStringBuilder bigText = new SpannableStringBuilder(); bigText.append(TextUtils.isEmpty(episodeTitle) ? "" : episodeTitle); bigText.setSpan(new StyleSpan(Typeface.BOLD), 0, bigText.length(), 0); bigText.append("\n"); bigText.append(TextUtils.isEmpty(episodeSummary) ? "" : episodeSummary); nb.setStyle(new NotificationCompat.BigTextStyle().bigText(bigText).setSummaryText(contentText)); // Action button to check in Intent checkInActionIntent = new Intent(context, QuickCheckInActivity.class); checkInActionIntent.putExtra(QuickCheckInActivity.InitBundle.EPISODE_TVDBID, upcomingEpisodes.getInt(NotificationQuery._ID)); checkInActionIntent .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); PendingIntent checkInIntent = PendingIntent.getActivity(context, REQUEST_CODE_ACTION_CHECKIN, checkInActionIntent, PendingIntent.FLAG_CANCEL_CURRENT); nb.addAction(R.drawable.ic_action_checkin, getString(R.string.checkin), checkInIntent); } else { // multiple episodes NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); // display at most the first five for (int displayIndex = 0; displayIndex < Math.min(count, 5); displayIndex++) { if (!upcomingEpisodes.moveToPosition(notifyPositions.get(displayIndex))) { // could not go to the desired position (testing just in case) break; } final SpannableStringBuilder lineText = new SpannableStringBuilder(); // show title String showTitle = upcomingEpisodes.getString(NotificationQuery.SHOW_TITLE); lineText.append(TextUtils.isEmpty(showTitle) ? "" : showTitle); lineText.setSpan(new StyleSpan(Typeface.BOLD), 0, lineText.length(), 0); lineText.append(" "); // "8:00 PM on Network" String releaseTime = TimeTools.formatToLocalReleaseTime(this, TimeTools.getEpisodeReleaseTime( this, upcomingEpisodes.getLong(NotificationQuery.EPISODE_FIRST_RELEASE_MS))); String network = upcomingEpisodes.getString(NotificationQuery.NETWORK); lineText.append(getString(R.string.upcoming_show_detailed, releaseTime, network)); inboxStyle.addLine(lineText); } // tell if we could not display all episodes if (count > 5) { inboxStyle.setSummaryText(getString(R.string.more, count - 5)); } nb.setStyle(inboxStyle); nb.setContentInfo(String.valueOf(count)); } } else { // ICS and below if (count == 1) { // single episode upcomingEpisodes.moveToPosition(notifyPositions.get(0)); maybeSetPoster(context, nb, upcomingEpisodes.getString(NotificationQuery.POSTER)); } } // notification sound final String ringtoneUri = NotificationSettings.getNotificationsRingtone(context); // If the string is empty, the user chose silent... if (ringtoneUri.length() != 0) { // ...otherwise set the specified ringtone Timber.d("Notification has sound"); nb.setSound(Uri.parse(ringtoneUri)); } // vibration if (NotificationSettings.isNotificationVibrating(context)) { Timber.d("Notification vibrates"); nb.setVibrate(VIBRATION_PATTERN); } nb.setDefaults(Notification.DEFAULT_LIGHTS); nb.setWhen(System.currentTimeMillis()); nb.setAutoCancel(true); nb.setTicker(tickerText); nb.setContentTitle(contentTitle); nb.setContentText(contentText); nb.setContentIntent(contentIntent); nb.setSmallIcon(R.drawable.ic_notification); nb.setColor(getResources().getColor(R.color.accent_primary)); nb.setPriority(NotificationCompat.PRIORITY_DEFAULT); nb.setCategory(NotificationCompat.CATEGORY_EVENT); Timber.d("Setting delete intent with episode time: " + latestAirtime); Intent i = new Intent(this, NotificationService.class); i.putExtra(KEY_EPISODE_CLEARED_TIME, latestAirtime); PendingIntent deleteIntent = PendingIntent.getService(this, REQUEST_CODE_DELETE_INTENT, i, PendingIntent.FLAG_CANCEL_CURRENT); nb.setDeleteIntent(deleteIntent); // build the notification Notification notification = nb.build(); // use string resource id, always unique within app final NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(R.string.upcoming_show, notification); }
From source file:com.todoroo.astrid.adapter.TaskAdapter.java
private void setupDueDateAndTags(ViewHolder viewHolder, Task task) { // due date / completion date final TextView dueDateView = viewHolder.dueDate; {//w ww . j a va 2 s . com if (!task.isCompleted() && task.hasDueDate()) { long dueDate = task.getDueDate(); if (task.isOverdue()) { dueDateView.setTextColor(textColorOverdue); } else { dueDateView.setTextColor(textColorSecondary); } String dateValue = DateUtilities.getRelativeDateStringWithTime(context, dueDate); dueDateView.setText(dateValue); dueDateView.setVisibility(View.VISIBLE); } else if (task.isCompleted()) { String dateValue = DateUtilities.getRelativeDateStringWithTime(context, task.getCompletionDate()); dueDateView.setText(resources.getString(R.string.TAd_completed, dateValue)); dueDateView.setTextColor(textColorHint); dueDateView.setVisibility(View.VISIBLE); } else { dueDateView.setVisibility(View.GONE); } if (task.isCompleted()) { viewHolder.tagBlock.setVisibility(View.GONE); } else { String tags = viewHolder.tagsString; List<String> tagUuids = tags != null ? newArrayList(tags.split(",")) : Lists.newArrayList(); Iterable<TagData> t = filter(transform(tagUuids, uuidToTag), Predicates.notNull()); List<TagData> firstFourByName = orderByName.leastOf(t, 4); int numTags = firstFourByName.size(); if (numTags > 0) { List<TagData> firstFourByNameLength = orderByLength.sortedCopy(firstFourByName); float maxLength = tagCharacters / numTags; for (int i = 0; i < numTags - 1; i++) { TagData tagData = firstFourByNameLength.get(i); String name = tagData.getName(); if (name.length() >= maxLength) { break; } float excess = maxLength - name.length(); int beneficiaries = numTags - i - 1; float additional = excess / beneficiaries; maxLength += additional; } List<SpannableString> tagStrings = transform(firstFourByName, tagToString(maxLength)); SpannableStringBuilder builder = new SpannableStringBuilder(); for (SpannableString tagString : tagStrings) { if (builder.length() > 0) { builder.append(HAIR_SPACE); } builder.append(tagString); } viewHolder.tagBlock.setText(builder); viewHolder.tagBlock.setVisibility(View.VISIBLE); } else { viewHolder.tagBlock.setVisibility(View.GONE); } } } }
From source file:pct.droid.fragments.VideoPlayerFragment.java
@Override protected void showTimedCaptionText(final Caption text) { mDisplayHandler.post(new Runnable() { @Override// ww w .j av a 2 s.c om public void run() { if (text == null) { if (mSubtitleText.getText().length() > 0) { mSubtitleText.setText(""); } return; } SpannableStringBuilder styledString = (SpannableStringBuilder) Html.fromHtml(text.content); ForegroundColorSpan[] toRemoveSpans = styledString.getSpans(0, styledString.length(), ForegroundColorSpan.class); for (ForegroundColorSpan remove : toRemoveSpans) { styledString.removeSpan(remove); } if (!mSubtitleText.getText().toString().equals(styledString.toString())) { mSubtitleText.setText(styledString); } } }); }