List of usage examples for android.text SpannableStringBuilder setSpan
public void setSpan(Object what, int start, int end, int flags)
From source file:com.nttec.everychan.ui.presentation.HtmlParser.java
private static void endFont(SpannableStringBuilder text) { int len = text.length(); Object obj = getLast(text, Font.class); int where = text.getSpanStart(obj); text.removeSpan(obj);//from w w w . j a v a 2s . co m if (where != len) { Font f = (Font) obj; if (!TextUtils.isEmpty(f.mColor)) { if (f.mColor.startsWith("@")) { Resources res = Resources.getSystem(); String name = f.mColor.substring(1); int colorRes = res.getIdentifier(name, "color", "android"); if (colorRes != 0) { ColorStateList colors = CompatibilityUtils.getColorStateList(res, colorRes); text.setSpan(new TextAppearanceSpan(null, 0, 0, colors, null), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } else { int c = ColorHidden.getHtmlColor(f.mColor); if (c != -1) { text.setSpan(new ForegroundColorSpan(c | 0xFF000000), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } if (f.mFace != null) { text.setSpan(new TypefaceSpan(f.mFace), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } if (f.mStyle != null) { List<Object> styleSpans = parseStyleAttributes(f.mStyle); for (Object span : styleSpans) { text.setSpan(span, where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } }
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 w w w .ja 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.softminds.matrixcalculator.base_activities.FillingMatrix.java
@Override protected void onCreate(Bundle savedInstanceState) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); boolean isDark = preferences.getBoolean("DARK_THEME_KEY", false); boolean SmartFit = preferences.getBoolean("SMART_FIT_KEY", false); if (isDark)/*from w w w. jav a2 s.com*/ setTheme(R.style.AppThemeDark_NoActionBar); else setTheme(R.style.AppTheme_NoActionBar); super.onCreate(savedInstanceState); Bundle bundle = getIntent().getExtras(); if (bundle == null) { Log.wtf("FillingMatrix", "How the heck, it got called ??"); Toast.makeText(getApplication(), R.string.unexpected_error, Toast.LENGTH_SHORT).show(); finish(); } else { col = bundle.getInt("COL"); row = bundle.getInt("ROW"); } setContentView(R.layout.filler); adCard = findViewById(R.id.AddCardFiller); if (!((GlobalValues) getApplication()).DonationKeyFound()) { AdView adView = findViewById(R.id.adViewFiller); AdRequest adRequest = new AdRequest.Builder().build(); adView.setAdListener(new AdLoadListener(adCard)); adView.loadAd(adRequest); if (getResources() .getConfiguration().orientation == android.content.res.Configuration.ORIENTATION_LANDSCAPE) adCard.setVisibility(View.INVISIBLE); else adCard.setVisibility(View.VISIBLE); } else ((ViewGroup) adCard.getParent()).removeView(adCard); Toolbar toolbar = findViewById(R.id.toolbarFill); setSupportActionBar(toolbar); CardView cardView = findViewById(R.id.DynamicCard); SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); String string = sharedPreferences.getString("ELEVATE_AMOUNT", "4"); String string2 = sharedPreferences.getString("CARD_CHANGE_KEY", "#bdbdbd"); cardView.setCardElevation(Integer.parseInt(string)); CardView.LayoutParams params1 = new CardView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); GridLayout gridLayout = new GridLayout(getApplicationContext()); gridLayout.setRowCount(row); gridLayout.setColumnCount(col); for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) { EditText editText = new EditText(getApplication()); editText.setBackgroundColor(Color.parseColor(string2)); editText.setId(i * 10 + j); if (isDark) editText.setTextColor(ContextCompat.getColor(this, R.color.white)); editText.setGravity(Gravity.CENTER); SpannableStringBuilder stringBuilder = new SpannableStringBuilder( "a" + String.valueOf(i + 1) + String.valueOf(j + 1)); stringBuilder.setSpan(new SubscriptSpan(), 1, 3, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); stringBuilder.setSpan(new RelativeSizeSpan(0.75f), 1, 3, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); editText.setHint(stringBuilder); if (!PreferenceManager.getDefaultSharedPreferences(this).getBoolean("DECIMAL_USE", true)) { editText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED); } else { editText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_NUMBER_FLAG_SIGNED); } editText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(getLength()) }); if (SmartFit) { editText.setWidth(ConvertTopx(CalculatedWidth(col))); editText.setTextSize(SizeReturner(row, col, PreferenceManager.getDefaultSharedPreferences(getApplicationContext()) .getBoolean("EXTRA_SMALL_FONT", false))); } else { editText.setWidth(ConvertTopx(62)); editText.setTextSize(SizeReturner(3, 3, PreferenceManager.getDefaultSharedPreferences(getApplicationContext()) .getBoolean("EXTRA_SMALL_FONT", false))); } editText.setSingleLine(); GridLayout.Spec Row = GridLayout.spec(i, 1); GridLayout.Spec Col = GridLayout.spec(j, 1); GridLayout.LayoutParams params = new GridLayout.LayoutParams(Row, Col); params.leftMargin = params.topMargin = params.bottomMargin = params.rightMargin = getResources() .getDimensionPixelOffset(R.dimen.border_width); gridLayout.addView(editText, params); } } gridLayout.setLayoutParams(params1); cardView.addView(gridLayout); MakeType((Type) (getIntent().getExtras().getSerializable("TYPE"))); if (GetMaximum() < GetMinimum()) { final Snackbar snackbar; snackbar = Snackbar.make(findViewById(R.id.filling_matrix), R.string.Warning3, Snackbar.LENGTH_INDEFINITE); snackbar.show(); snackbar.setAction(getString(R.string.action_settings), new View.OnClickListener() { @Override public void onClick(View view) { snackbar.dismiss(); Intent intent = new Intent(getApplicationContext(), SettingsTab.class); startActivity(intent); finish(); } }); } }
From source file:org.cnc.mombot.utils.ContactsEditText.java
private SpannableStringBuilder addPeopleToGroupChat(SpannableStringBuilder spannable) { // For tag friends. final Matcher matcherTag = mPatternTagFriend.matcher(spannable); while (matcherTag.find()) { // Set span. group 1 is name View view = createContactTextView(matcherTag.group(1)); BitmapDrawable bd = (BitmapDrawable) convertViewToDrawable(view); spannable.setSpan(new ImageSpan(bd), matcherTag.start(), matcherTag.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); }/*ww w . j ava2s .c o m*/ return spannable; }
From source file:org.chromium.chrome.browser.notifications.NotificationUIManager.java
/** * Creates the ticker text for a notification having |title| and |body|. The notification's * title will be printed in bold, followed by the text of the body. * * @param title Title of the notification. * @param body Textual contents of the notification. * @return A character sequence containing the ticker's text. *///from w ww.ja va 2 s. c om private CharSequence createTickerText(String title, String body) { SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(); spannableStringBuilder.append(title); spannableStringBuilder.append("\n"); spannableStringBuilder.append(body); // Mark the title of the notification as being bold. spannableStringBuilder.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, title.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE); return spannableStringBuilder; }
From source file:com.ruesga.rview.misc.Formatter.java
@BindingAdapter("userMessage") public static void toUserMessage(TextView view, String msg) { if (msg == null) { view.setText(null);/*from w w w .j a va2 s. c om*/ return; } String message = EmojiHelper.createEmoji(msg); // This process mimics the Gerrit formatting process done in class // ./gerrit-gwtexpui/src/main/java/com/google/gwtexpui/safehtml/client/SafeHtml.java // Split message into paragraphs String[] paragraphs = StringHelper.obtainParagraphs(message); StringBuilder sb = new StringBuilder(); boolean formattedMessage = false; for (String p : paragraphs) { if (StringHelper.isQuote(p)) { sb.append(StringHelper.obtainQuote(StringHelper.removeLineBreaks(p))); formattedMessage = true; } else if (StringHelper.isList(p)) { sb.append(p); formattedMessage = true; } else if (StringHelper.isPreFormat(p)) { sb.append(StringHelper.obtainPreFormatMessage(p)); formattedMessage = true; } else { sb.append(p); } sb.append("\n\n"); } String userMessage = StringHelper.removeExtraLines(sb.toString()); if (!formattedMessage) { view.setText(userMessage); return; } if (sQuoteColor == -1) { sQuoteColor = ContextCompat.getColor(view.getContext(), R.color.quote); sQuoteWidth = (int) view.getContext().getResources().getDimension(R.dimen.quote_width); sQuoteMargin = (int) view.getContext().getResources().getDimension(R.dimen.quote_margin); } String[] lines = userMessage.split("\n"); SpannableStringBuilder spannable = new SpannableStringBuilder(userMessage .replaceAll(StringHelper.NON_PRINTABLE_CHAR, "").replaceAll(StringHelper.NON_PRINTABLE_CHAR2, "")); // Pre-Format int start = 0; int spans = 0; while ((start = userMessage.indexOf(StringHelper.NON_PRINTABLE_CHAR2, start)) != -1) { int end = userMessage.indexOf(StringHelper.NON_PRINTABLE_CHAR2, start + 1); if (end == -1) { //? This is supposed to be formatted by us. Skip it break; } // Find quote token occurrences int offset = StringHelper.countOccurrences(StringHelper.NON_PRINTABLE_CHAR, userMessage, 0, start); start -= offset; end -= offset; // Ensure bounds int spanStart = start - spans; int spanEnd = Math.min(end - spans - 1, spannable.length()); if (spanStart < 0 || spanEnd < 0) { //Something was wrong. Skip it break; } spannable.setSpan(new RelativeSizeSpan(0.8f), spanStart, spanEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); spannable.setSpan(new TypefaceSpan("monospace"), spanStart, spanEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); start = end; spans++; } start = 0; for (String line : lines) { // Quotes int maxIndent = StringHelper.countOccurrences(StringHelper.NON_PRINTABLE_CHAR, line); for (int i = 0; i < maxIndent; i++) { QuotedSpan span = new QuotedSpan(sQuoteColor, sQuoteWidth, sQuoteMargin); spannable.setSpan(span, start, Math.min(start + line.length() - maxIndent, spannable.length()), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } // List if (StringHelper.isList(line)) { spannable.replace(start, start + 1, "\u2022"); spannable.setSpan(new LeadingMarginSpan.Standard(sQuoteMargin), start, Math.min(start + line.length(), spannable.length()), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } start += line.length() - maxIndent + 1; } view.setText(spannable); }
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 . jav a 2s . 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:ru.valle.btc.MainActivity.java
private static void setUrlSpanForAddress(String domain, String address, SpannableStringBuilder builder) { int spanBegin = builder.toString().indexOf(domain); if (spanBegin >= 0) { URLSpan urlSpan = new URLSpan("http://" + domain + "/address/" + address); builder.setSpan(urlSpan, spanBegin, spanBegin + domain.length(), SpannableStringBuilder.SPAN_INCLUSIVE_INCLUSIVE); }/*from w w w . j a v a2 s . c o m*/ }
From source file:net.kourlas.voipms_sms.adapters.ConversationRecyclerViewAdapter.java
@Override public void onBindViewHolder(MessageViewHolder messageViewHolder, int i) { Message message = messages.get(i);//from w ww . ja v a2s . c o m int viewType = getItemViewType(i); if (viewType == ITEM_LEFT_PRIMARY || viewType == ITEM_RIGHT_PRIMARY) { QuickContactBadge contactBadge = messageViewHolder.getContactBadge(); if (viewType == ITEM_LEFT_PRIMARY) { contactBadge.assignContactFromPhone(message.getContact(), true); } else { contactBadge.assignContactFromPhone(message.getDid(), true); } String photoUri; if (viewType == ITEM_LEFT_PRIMARY) { photoUri = Utils.getContactPhotoUri(applicationContext, message.getContact()); } else { photoUri = Utils.getContactPhotoUri(applicationContext, ContactsContract.Profile.CONTENT_URI); if (photoUri == null) { photoUri = Utils.getContactPhotoUri(applicationContext, message.getDid()); } } if (photoUri != null) { contactBadge.setImageURI(Uri.parse(photoUri)); } else { contactBadge.setImageToDefault(); } } View smsContainer = messageViewHolder.getSmsContainer(); TextView messageText = messageViewHolder.getMessageText(); SpannableStringBuilder messageTextBuilder = new SpannableStringBuilder(); messageTextBuilder.append(message.getText()); if (!filterConstraint.equals("")) { int index = message.getText().toLowerCase().indexOf(filterConstraint.toLowerCase()); if (index != -1) { messageTextBuilder.setSpan( new BackgroundColorSpan(ContextCompat.getColor(applicationContext, R.color.highlight)), index, index + filterConstraint.length(), SpannableString.SPAN_INCLUSIVE_EXCLUSIVE); messageTextBuilder.setSpan( new ForegroundColorSpan(ContextCompat.getColor(applicationContext, R.color.dark_gray)), index, index + filterConstraint.length(), SpannableString.SPAN_INCLUSIVE_EXCLUSIVE); } } messageText.setText(messageTextBuilder); TextView dateText = messageViewHolder.getDateText(); if (!message.isDelivered()) { if (!message.isDeliveryInProgress()) { SpannableStringBuilder dateTextBuilder = new SpannableStringBuilder(); if (isItemChecked(i)) { dateTextBuilder .append(applicationContext.getString(R.string.conversation_message_not_sent_selected)); } else { dateTextBuilder.append(applicationContext.getString(R.string.conversation_message_not_sent)); } dateTextBuilder.setSpan( new ForegroundColorSpan( isItemChecked(i) ? ContextCompat.getColor(applicationContext, android.R.color.white) : ContextCompat.getColor(applicationContext, android.R.color.holo_red_dark)), 0, dateTextBuilder.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); dateText.setText(dateTextBuilder); dateText.setVisibility(View.VISIBLE); } else { dateText.setText(applicationContext.getString(R.string.conversation_message_sending)); dateText.setVisibility(View.VISIBLE); } } else if (i == messages.size() - 1 || ((viewType == ITEM_LEFT_PRIMARY || viewType == ITEM_LEFT_SECONDARY) && getItemViewType(i + 1) != ITEM_LEFT_SECONDARY) || ((viewType == ITEM_RIGHT_PRIMARY || viewType == ITEM_RIGHT_SECONDARY) && getItemViewType(i + 1) != ITEM_RIGHT_SECONDARY)) { dateText.setText(Utils.getFormattedDate(applicationContext, message.getDate(), false)); dateText.setVisibility(View.VISIBLE); } else { dateText.setVisibility(View.GONE); } if (viewType == ITEM_LEFT_PRIMARY || viewType == ITEM_LEFT_SECONDARY) { smsContainer.setBackgroundResource(isItemChecked(i) ? android.R.color.holo_blue_dark : R.color.primary); } else { smsContainer.setBackgroundResource( isItemChecked(i) ? android.R.color.holo_blue_dark : android.R.color.white); messageText.setTextColor( isItemChecked(i) ? ContextCompat.getColor(applicationContext, android.R.color.white) : ContextCompat.getColor(applicationContext, R.color.dark_gray)); messageText.setLinkTextColor( isItemChecked(i) ? ContextCompat.getColor(applicationContext, android.R.color.white) : ContextCompat.getColor(applicationContext, R.color.dark_gray)); dateText.setTextColor( isItemChecked(i) ? ContextCompat.getColor(applicationContext, R.color.message_translucent_white) : ContextCompat.getColor(applicationContext, R.color.message_translucent_dark_grey)); } }
From source file:cn.zhangls.android.weibo.utils.TextUtil.java
/** * ?? emoji /*from ww w.ja va 2s . c o m*/ * * @param context * @param builder SpannableStringBuilder * @param arrayList ?? */ private static void replaceEmoji(Context context, SpannableStringBuilder builder, ArrayList<StrHolder> arrayList, int textSze) { if (arrayList != null && arrayList.size() > 0) { PinyinUtil pinyinUtils = PinyinUtil.getInstance(context); for (StrHolder emoji : arrayList) { if (!emoji.getName().isEmpty()) { // ??? [] ?? [erha] if (emoji.getName().length() <= 2) { return; } String substring = emoji.getName().substring(1, emoji.getName().length() - 1); String pinyin = pinyinUtils.getPinyin(substring); Log.d("emoji", "replaceEmoji: ======" + substring + "======" + pinyin); if (getResId(pinyin, R.drawable.class) != -1) { //????Id Drawable drawable = ContextCompat.getDrawable(context, getResId(pinyin, R.drawable.class)); drawable.setBounds(0, 0, textSze, textSze); //??ImageSpan ImageSpan imageSpan = new ImageSpan(drawable, ImageSpan.ALIGN_BASELINE); // ??23????startend // ???,[5,12)5125?12 builder.setSpan(imageSpan, emoji.getStart(), emoji.getEnd(), Spannable.SPAN_INCLUSIVE_INCLUSIVE); } } } } }