List of usage examples for android.graphics Typeface BOLD
int BOLD
To view the source code for android.graphics Typeface BOLD.
Click Source Link
From source file:com.android.contacts.common.list.ContactListItemView.java
/** * Returns the text view for the data label, creating it if necessary. *//*from w w w . ja va 2 s . co m*/ public TextView getLabelView() { if (mLabelView == null) { mLabelView = new TextView(getContext()); mLabelView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); mLabelView.setSingleLine(true); mLabelView.setEllipsize(getTextEllipsis()); mLabelView.setTextAppearance(getContext(), R.style.TextAppearanceSmall); if (mPhotoPosition == PhotoPosition.LEFT) { mLabelView.setAllCaps(true); } else { mLabelView.setTypeface(mLabelView.getTypeface(), Typeface.BOLD); } mLabelView.setActivated(isActivated()); mLabelView.setId(R.id.cliv_label_textview); addView(mLabelView); } return mLabelView; }
From source file:com.esri.android.mapsapp.MapFragment.java
/** * Shows the Routing result layout after successful routing * // w w w . jav a 2s .c o m * @param time * @param distance * */ private void showRoutingResultLayout(double distance, double time) { // Remove the layours mMapContainer.removeView(mSearchResult); mMapContainer.removeView(mSearchBox); // Inflate the new layout from the xml file mSearchResult = mInflater.inflate(R.layout.routing_result, null); mSearchResult.setLayoutParams(mlayoutParams); // Shorten the start and end location by finding the first comma if // present int index_from = mStartLocation.indexOf(","); int index_to = mEndLocation.indexOf(","); if (index_from != -1) mStartLocation = mStartLocation.substring(0, index_from); if (index_to != -1) mEndLocation = mEndLocation.substring(0, index_to); // Initialize the textvieww and display the text TextView tv_from = (TextView) mSearchResult.findViewById(R.id.tv_from); tv_from.setTypeface(null, Typeface.BOLD); tv_from.setText(" " + mStartLocation); TextView tv_to = (TextView) mSearchResult.findViewById(R.id.tv_to); tv_to.setTypeface(null, Typeface.BOLD); tv_to.setText(" " + mEndLocation); // Rounding off the values distance = Math.round(distance * 10.0) / 10.0; time = Math.round(time * 10.0) / 10.0; TextView tv_time = (TextView) mSearchResult.findViewById(R.id.tv_time); tv_time.setTypeface(null, Typeface.BOLD); tv_time.setText(time + " mins"); TextView tv_dist = (TextView) mSearchResult.findViewById(R.id.tv_dist); tv_dist.setTypeface(null, Typeface.BOLD); tv_dist.setText(" (" + distance + " miles)"); // Adding the layout mMapContainer.addView(mSearchResult); // Setup the listener for the "Cancel" icon ImageView iv_cancel = (ImageView) mSearchResult.findViewById(R.id.imageView3); iv_cancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // Remove the search result view mMapContainer.removeView(mSearchResult); // Add the default search box view showSearchBoxLayout(); // Remove all graphics from the map resetGraphicsLayers(); } }); // Set up the listener for the "Show Directions" icon ImageView iv_directions = (ImageView) mSearchResult.findViewById(R.id.imageView2); iv_directions.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { showDirectionsDialogFragment(); } }); // Add the compass after getting the height of the layout mSearchResult.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { addCompass(mSearchResult.getHeight()); mSearchResult.getViewTreeObserver().removeGlobalOnLayoutListener(this); } }); }
From source file:org.getlantern.firetweet.provider.FiretweetDataProvider.java
private void showMentionsNotification(AccountPreferences pref, long position) { final long accountId = pref.getAccountId(); final Context context = getContext(); final Resources resources = context.getResources(); final NotificationManager nm = getNotificationManager(); final Expression selection; if (pref.isNotificationFollowingOnly()) { selection = Expression.and(Expression.equals(Statuses.ACCOUNT_ID, accountId), Expression.greaterThan(Statuses.STATUS_ID, position), Expression.equals(Statuses.IS_FOLLOWING, 1)); } else {//from w w w. j a v a2s.com selection = Expression.and(Expression.equals(Statuses.ACCOUNT_ID, accountId), Expression.greaterThan(Statuses.STATUS_ID, position)); } final String filteredSelection = Utils.buildStatusFilterWhereClause(Mentions.TABLE_NAME, selection) .getSQL(); final String[] userProjection = { Statuses.USER_ID, Statuses.USER_NAME, Statuses.USER_SCREEN_NAME }; final String[] statusProjection = { Statuses.STATUS_ID, Statuses.USER_ID, Statuses.USER_NAME, Statuses.USER_SCREEN_NAME, Statuses.TEXT_UNESCAPED, Statuses.STATUS_TIMESTAMP }; final Cursor statusCursor = mDatabaseWrapper.query(Mentions.TABLE_NAME, statusProjection, filteredSelection, null, null, null, Statuses.SORT_ORDER_TIMESTAMP_DESC); final Cursor userCursor = mDatabaseWrapper.query(Mentions.TABLE_NAME, userProjection, filteredSelection, null, Statuses.USER_ID, null, Statuses.SORT_ORDER_TIMESTAMP_DESC); try { final int usersCount = userCursor.getCount(); final int statusesCount = statusCursor.getCount(); if (statusesCount == 0 || usersCount == 0) return; final String accountName = Utils.getAccountName(context, accountId); final String accountScreenName = Utils.getAccountScreenName(context, accountId); final int idxStatusText = statusCursor.getColumnIndex(Statuses.TEXT_UNESCAPED), idxStatusId = statusCursor.getColumnIndex(Statuses.STATUS_ID), idxStatusTimestamp = statusCursor.getColumnIndex(Statuses.STATUS_TIMESTAMP), idxStatusUserName = statusCursor.getColumnIndex(Statuses.USER_NAME), idxStatusUserScreenName = statusCursor.getColumnIndex(Statuses.USER_SCREEN_NAME), idxUserName = userCursor.getColumnIndex(Statuses.USER_NAME), idxUserScreenName = userCursor.getColumnIndex(Statuses.USER_NAME), idxUserId = userCursor.getColumnIndex(Statuses.USER_NAME); final CharSequence notificationTitle = resources.getQuantityString(R.plurals.N_new_mentions, statusesCount, statusesCount); final String notificationContent; userCursor.moveToFirst(); final String displayName = UserColorNameUtils.getUserNickname(context, userCursor.getLong(idxUserId), mNameFirst ? userCursor.getString(idxUserName) : userCursor.getString(idxUserScreenName)); if (usersCount == 1) { notificationContent = context.getString(R.string.notification_mention, displayName); } else { notificationContent = context.getString(R.string.notification_mention_multiple, displayName, usersCount - 1); } // Add rich notification and get latest tweet timestamp long when = -1, statusId = -1; final InboxStyle style = new InboxStyle(); for (int i = 0, j = Math.min(statusesCount, 5); statusCursor.moveToPosition(i) && i < j; i++) { if (when == -1) { when = statusCursor.getLong(idxStatusTimestamp); } if (statusId == -1) { statusId = statusCursor.getLong(idxStatusId); } final SpannableStringBuilder sb = new SpannableStringBuilder(); sb.append(UserColorNameUtils.getUserNickname(context, statusCursor.getLong(idxUserId), mNameFirst ? statusCursor.getString(idxStatusUserName) : statusCursor.getString(idxStatusUserScreenName))); sb.setSpan(new StyleSpan(Typeface.BOLD), 0, sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); sb.append(' '); sb.append(statusCursor.getString(idxStatusText)); style.addLine(sb); } if (mNameFirst) { style.setSummaryText(accountName); } else { style.setSummaryText("@" + accountScreenName); } // Setup notification final NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setAutoCancel(true); builder.setSmallIcon(R.drawable.ic_stat_mention); builder.setTicker(notificationTitle); builder.setContentTitle(notificationTitle); builder.setContentText(notificationContent); builder.setCategory(NotificationCompat.CATEGORY_SOCIAL); builder.setContentIntent(getContentIntent(context, AUTHORITY_MENTIONS, accountId)); builder.setDeleteIntent(getDeleteIntent(context, AUTHORITY_MENTIONS, accountId, statusId)); builder.setNumber(statusesCount); builder.setWhen(when); builder.setStyle(style); builder.setColor(pref.getNotificationLightColor()); setNotificationPreferences(builder, pref, pref.getMentionsNotificationType()); nm.notify("mentions_" + accountId, NOTIFICATION_ID_MENTIONS_TIMELINE, builder.build()); Utils.sendPebbleNotification(context, notificationContent); } finally { statusCursor.close(); userCursor.close(); } }
From source file:com.android.messaging.datamodel.BugleNotifications.java
/** * buildBoldedMessage - build a formatted message where the title is bold, there's a * separator, then the message./*w w w. jav a 2s . com*/ */ private static CharSequence buildBoldedMessage(final String title, final CharSequence message, final Uri attachmentUri, final String attachmentType, final int separatorId) { final Context context = Factory.get().getApplicationContext(); final SpannableStringBuilder spanBuilder = new SpannableStringBuilder(); // Boldify the title (which is the sender's name) if (!TextUtils.isEmpty(title)) { spanBuilder.append(title); spanBuilder.setSpan(new StyleSpan(Typeface.BOLD), 0, title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } if (!TextUtils.isEmpty(message)) { if (spanBuilder.length() > 0) { spanBuilder.append(context.getString(separatorId)); } spanBuilder.append(message); } if (attachmentUri != null) { if (spanBuilder.length() > 0) { final String separator = context.getString(R.string.notification_separator); spanBuilder.append(separator); } spanBuilder.append(formatAttachmentTag(null, attachmentType)); } return spanBuilder; }
From source file:com.concentriclivers.mms.com.android.mms.transaction.MessagingNotification.java
protected static CharSequence buildTickerMessage(Context context, String address, String subject, String body) { String displayAddress = Contact.get(address, true).getName(); StringBuilder buf = new StringBuilder( displayAddress == null ? "" : displayAddress.replace('\n', ' ').replace('\r', ' ')); buf.append(':').append(' '); int offset = buf.length(); if (!TextUtils.isEmpty(subject)) { subject = subject.replace('\n', ' ').replace('\r', ' '); buf.append(subject);/*from w ww .j a va2s . co m*/ buf.append(' '); } if (!TextUtils.isEmpty(body)) { body = body.replace('\n', ' ').replace('\r', ' '); buf.append(body); } SpannableString spanText = new SpannableString(buf.toString()); spanText.setSpan(new StyleSpan(Typeface.BOLD), 0, offset, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); return spanText; }
From source file:es.usc.citius.servando.calendula.fragments.ScheduleImportFragment.java
void checkSelectedDays(View rootView, boolean[] days) { Log.d(TAG, "Checking selected days: " + Arrays.toString(days)); schedule.setDays(days);//from www . j a v a 2 s . co m TextView mo = ((TextView) rootView.findViewById(R.id.day_mo)); TextView tu = ((TextView) rootView.findViewById(R.id.day_tu)); TextView we = ((TextView) rootView.findViewById(R.id.day_we)); TextView th = ((TextView) rootView.findViewById(R.id.day_th)); TextView fr = ((TextView) rootView.findViewById(R.id.day_fr)); TextView sa = ((TextView) rootView.findViewById(R.id.day_sa)); TextView su = ((TextView) rootView.findViewById(R.id.day_su)); TextView[] daysTvs = new TextView[] { mo, tu, we, th, fr, sa, su }; for (int i = 0; i < daysTvs.length; i++) { boolean isSelected = days[i]; StateListDrawable sld = (StateListDrawable) daysTvs[i].getBackground(); GradientDrawable shape = (GradientDrawable) sld.getCurrent(); shape.setColor(isSelected ? color : Color.WHITE); daysTvs[i].setTextColor(isSelected ? Color.WHITE : color); daysTvs[i].setTypeface(null, isSelected ? Typeface.BOLD : Typeface.NORMAL); } }
From source file:es.usc.citius.servando.calendula.fragments.ScheduleTimetableFragment.java
void checkSelectedDays(View rootView, boolean[] days) { Log.d(TAG, "Checking selected days: " + Arrays.toString(days)); schedule.setDays(days);/* w w w. j ava 2 s . c om*/ TextView mo = ((TextView) rootView.findViewById(R.id.day_mo)); TextView tu = ((TextView) rootView.findViewById(R.id.day_tu)); TextView we = ((TextView) rootView.findViewById(R.id.day_we)); TextView th = ((TextView) rootView.findViewById(R.id.day_th)); TextView fr = ((TextView) rootView.findViewById(R.id.day_fr)); TextView sa = ((TextView) rootView.findViewById(R.id.day_sa)); TextView su = ((TextView) rootView.findViewById(R.id.day_su)); TextView[] daysTvs = new TextView[] { mo, tu, we, th, fr, sa, su }; for (int i = 0; i < daysTvs.length; i++) { boolean isSelected = days[i]; StateListDrawable sld = (StateListDrawable) daysTvs[i].getBackground(); GradientDrawable shape = (GradientDrawable) sld.getCurrent(); shape.setColor(isSelected ? color : Color.WHITE); daysTvs[i].setTypeface(null, isSelected ? Typeface.BOLD : Typeface.NORMAL); daysTvs[i].setTextColor(isSelected ? Color.WHITE : Color.BLACK); } }
From source file:com.wanikani.androidnotifier.ItemsFragment.java
/** * Internal implementation of the {@link #selectLevel(Filter, int, boolean)} * logic. This gets called when it is certain that we are being called * by the correct filter, or no filter is involved, so checks are skipped. * In addition, this method may be called also to <i>unselect</i> a level. * @param row the level row on which to act. This parameter may be <code>null</code>, * if the label is not visible. Calling the method is still important, to * show the levels list, if hidden//from w w w .ja va 2s . c o m * @param select <code>true</code> if the level should be selected. * Otherwise it is unselected * @param spin <code>true</code> if the spinner should be displayed. * Otherwise it is hidden. Makes sense only if <code>select</code> * is <code>true</code> too */ private void selectLevel(View row, boolean select, boolean spin) { TextView tw; View sw; selectOtherFilter(false, false); if (row == null) return; tw = (TextView) row.findViewById(R.id.tgr_level); sw = row.findViewById(R.id.pb_level); if (spin) { tw.setVisibility(View.GONE); sw.setVisibility(View.VISIBLE); } else { tw.setVisibility(View.VISIBLE); sw.setVisibility(View.GONE); } if (select) { tw.setTextColor(selectedColor); tw.setTypeface(null, Typeface.BOLD); } else { tw.setTextColor(unselectedColor); tw.setTypeface(null, Typeface.NORMAL); } }
From source file:org.telegram.ui.ArticleViewer.java
private TextPaint getTextPaint(TLRPC.RichText parentRichText, TLRPC.RichText richText, TLRPC.PageBlock parentBlock) {/*from ww w. j av a2 s. c o m*/ int flags = getTextFlags(richText); HashMap<Integer, TextPaint> currentMap = null; int textSize = AndroidUtilities.dp(14); int textColor = 0xffff0000; if (parentBlock instanceof TLRPC.TL_pageBlockPhoto) { currentMap = captionTextPaints; textSize = AndroidUtilities.dp(14); textColor = 0xff838c96; } else if (parentBlock instanceof TLRPC.TL_pageBlockTitle) { currentMap = titleTextPaints; textSize = AndroidUtilities.dp(24); textColor = 0xff000000; } else if (parentBlock instanceof TLRPC.TL_pageBlockAuthorDate) { currentMap = authorTextPaints; textSize = AndroidUtilities.dp(14); textColor = 0xff838c96; } else if (parentBlock instanceof TLRPC.TL_pageBlockFooter) { currentMap = footerTextPaints; textSize = AndroidUtilities.dp(14); textColor = 0xff838c96; } else if (parentBlock instanceof TLRPC.TL_pageBlockSubtitle) { currentMap = subtitleTextPaints; textSize = AndroidUtilities.dp(21); textColor = 0xff000000; } else if (parentBlock instanceof TLRPC.TL_pageBlockHeader) { currentMap = headerTextPaints; textSize = AndroidUtilities.dp(21); textColor = 0xff000000; } else if (parentBlock instanceof TLRPC.TL_pageBlockSubheader) { currentMap = subheaderTextPaints; textSize = AndroidUtilities.dp(18); textColor = 0xff000000; } else if (parentBlock instanceof TLRPC.TL_pageBlockBlockquote || parentBlock instanceof TLRPC.TL_pageBlockPullquote) { if (parentBlock.text == parentRichText) { currentMap = quoteTextPaints; textSize = AndroidUtilities.dp(15); textColor = 0xff000000; } else if (parentBlock.caption == parentRichText) { currentMap = subquoteTextPaints; textSize = AndroidUtilities.dp(14); textColor = 0xff838c96; } } else if (parentBlock instanceof TLRPC.TL_pageBlockPreformatted) { currentMap = preformattedTextPaints; textSize = AndroidUtilities.dp(14); textColor = 0xff000000; } else if (parentBlock instanceof TLRPC.TL_pageBlockParagraph) { if (parentBlock.caption == parentRichText) { currentMap = embedPostCaptionTextPaints; textSize = AndroidUtilities.dp(14); textColor = 0xff838c96; } else { currentMap = paragraphTextPaints; textSize = AndroidUtilities.dp(16); textColor = 0xff000000; } } else if (parentBlock instanceof TLRPC.TL_pageBlockList) { currentMap = listTextPaints; textSize = AndroidUtilities.dp(15); textColor = 0xff000000; } else if (parentBlock instanceof TLRPC.TL_pageBlockEmbed) { currentMap = embedTextPaints; textSize = AndroidUtilities.dp(14); textColor = 0xff838c96; } else if (parentBlock instanceof TLRPC.TL_pageBlockSlideshow) { currentMap = slideshowTextPaints; textSize = AndroidUtilities.dp(14); textColor = 0xff838c96; } else if (parentBlock instanceof TLRPC.TL_pageBlockEmbedPost) { if (richText != null) { currentMap = embedPostTextPaints; textSize = AndroidUtilities.dp(14); textColor = 0xff000000; } } else if (parentBlock instanceof TLRPC.TL_pageBlockVideo) { currentMap = videoTextPaints; textSize = AndroidUtilities.dp(14); textColor = 0xff000000; } if (currentMap == null) { if (errorTextPaint == null) { errorTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG); errorTextPaint.setColor(0xffff0000); } errorTextPaint.setTextSize(AndroidUtilities.dp(14)); return errorTextPaint; } TextPaint paint = currentMap.get(flags); if (paint == null) { paint = new TextPaint(Paint.ANTI_ALIAS_FLAG); if ((flags & TEXT_FLAG_MONO) != 0) { paint.setTypeface(AndroidUtilities.getTypeface("fonts/rmono.ttf")); } else { if (parentBlock instanceof TLRPC.TL_pageBlockTitle || parentBlock instanceof TLRPC.TL_pageBlockHeader || parentBlock instanceof TLRPC.TL_pageBlockSubtitle || parentBlock instanceof TLRPC.TL_pageBlockSubheader) { if ((flags & TEXT_FLAG_MEDIUM) != 0 && (flags & TEXT_FLAG_ITALIC) != 0) { paint.setTypeface(Typeface.create("serif", Typeface.BOLD_ITALIC)); } else if ((flags & TEXT_FLAG_MEDIUM) != 0) { paint.setTypeface(Typeface.create("serif", Typeface.BOLD)); } else if ((flags & TEXT_FLAG_ITALIC) != 0) { paint.setTypeface(Typeface.create("serif", Typeface.ITALIC)); } else { paint.setTypeface(Typeface.create("serif", Typeface.NORMAL)); } } else { if ((flags & TEXT_FLAG_MEDIUM) != 0 && (flags & TEXT_FLAG_ITALIC) != 0) { paint.setTypeface(AndroidUtilities.getTypeface("fonts/rmediumitalic.ttf")); } else if ((flags & TEXT_FLAG_MEDIUM) != 0) { paint.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); } else if ((flags & TEXT_FLAG_ITALIC) != 0) { paint.setTypeface(AndroidUtilities.getTypeface("fonts/ritalic.ttf")); } } } if ((flags & TEXT_FLAG_STRIKE) != 0) { paint.setFlags(paint.getFlags() | TextPaint.STRIKE_THRU_TEXT_FLAG); } if ((flags & TEXT_FLAG_UNDERLINE) != 0) { paint.setFlags(paint.getFlags() | TextPaint.UNDERLINE_TEXT_FLAG); } if ((flags & TEXT_FLAG_URL) != 0) { textColor = 0xff4d83b3; } paint.setColor(textColor); currentMap.put(flags, paint); } paint.setTextSize(textSize); return paint; }
From source file:org.getlantern.firetweet.provider.FiretweetDataProvider.java
private void showMessagesNotification(AccountPreferences pref, StringLongPair[] pairs, ContentValues[] valuesArray) {//www . ja v a 2s. c om final long accountId = pref.getAccountId(); final long prevOldestId = mReadStateManager.getPosition(TAG_OLDEST_MESSAGES, String.valueOf(accountId)); long oldestId = -1; for (final ContentValues contentValues : valuesArray) { final long messageId = contentValues.getAsLong(DirectMessages.MESSAGE_ID); oldestId = oldestId < 0 ? messageId : Math.min(oldestId, messageId); if (messageId <= prevOldestId) return; } mReadStateManager.setPosition(TAG_OLDEST_MESSAGES, String.valueOf(accountId), oldestId, false); final Context context = getContext(); final Resources resources = context.getResources(); final NotificationManager nm = getNotificationManager(); final ArrayList<Expression> orExpressions = new ArrayList<>(); final String prefix = accountId + "-"; final int prefixLength = prefix.length(); final Set<Long> senderIds = new CompactHashSet<>(); for (StringLongPair pair : pairs) { final String key = pair.getKey(); if (key.startsWith(prefix)) { final long senderId = Long.parseLong(key.substring(prefixLength)); senderIds.add(senderId); final Expression expression = Expression.and(Expression.equals(DirectMessages.SENDER_ID, senderId), Expression.greaterThan(DirectMessages.MESSAGE_ID, pair.getValue())); orExpressions.add(expression); } } orExpressions .add(Expression.notIn(new Column(DirectMessages.SENDER_ID), new RawItemArray(senderIds.toArray()))); final Expression selection = Expression.and(Expression.equals(DirectMessages.ACCOUNT_ID, accountId), Expression.greaterThan(DirectMessages.MESSAGE_ID, prevOldestId), Expression.or(orExpressions.toArray(new Expression[orExpressions.size()]))); final String filteredSelection = selection.getSQL(); final String[] userProjection = { DirectMessages.SENDER_ID, DirectMessages.SENDER_NAME, DirectMessages.SENDER_SCREEN_NAME }; final String[] messageProjection = { DirectMessages.MESSAGE_ID, DirectMessages.SENDER_ID, DirectMessages.SENDER_NAME, DirectMessages.SENDER_SCREEN_NAME, DirectMessages.TEXT_UNESCAPED, DirectMessages.MESSAGE_TIMESTAMP }; final Cursor messageCursor = mDatabaseWrapper.query(DirectMessages.Inbox.TABLE_NAME, messageProjection, filteredSelection, null, null, null, DirectMessages.DEFAULT_SORT_ORDER); final Cursor userCursor = mDatabaseWrapper.query(DirectMessages.Inbox.TABLE_NAME, userProjection, filteredSelection, null, DirectMessages.SENDER_ID, null, DirectMessages.DEFAULT_SORT_ORDER); try { final int usersCount = userCursor.getCount(); final int messagesCount = messageCursor.getCount(); if (messagesCount == 0 || usersCount == 0) return; final String accountName = Utils.getAccountName(context, accountId); final String accountScreenName = Utils.getAccountScreenName(context, accountId); final int idxMessageText = messageCursor.getColumnIndex(DirectMessages.TEXT_UNESCAPED), idxMessageTimestamp = messageCursor.getColumnIndex(DirectMessages.MESSAGE_TIMESTAMP), idxMessageId = messageCursor.getColumnIndex(DirectMessages.MESSAGE_ID), idxMessageUserId = messageCursor.getColumnIndex(DirectMessages.SENDER_ID), idxMessageUserName = messageCursor.getColumnIndex(DirectMessages.SENDER_NAME), idxMessageUserScreenName = messageCursor.getColumnIndex(DirectMessages.SENDER_SCREEN_NAME), idxUserName = userCursor.getColumnIndex(DirectMessages.SENDER_NAME), idxUserScreenName = userCursor.getColumnIndex(DirectMessages.SENDER_NAME), idxUserId = userCursor.getColumnIndex(DirectMessages.SENDER_NAME); final CharSequence notificationTitle = resources.getQuantityString(R.plurals.N_new_messages, messagesCount, messagesCount); final String notificationContent; userCursor.moveToFirst(); final String displayName = UserColorNameUtils.getUserNickname(context, userCursor.getLong(idxUserId), mNameFirst ? userCursor.getString(idxUserName) : userCursor.getString(idxUserScreenName)); if (usersCount == 1) { if (messagesCount == 1) { notificationContent = context.getString(R.string.notification_direct_message, displayName); } else { notificationContent = context.getString(R.string.notification_direct_message_multiple_messages, displayName, messagesCount); } } else { notificationContent = context.getString(R.string.notification_direct_message_multiple_users, displayName, usersCount - 1, messagesCount); } final LongSparseArray<Long> idsMap = new LongSparseArray<>(); // Add rich notification and get latest tweet timestamp long when = -1; final InboxStyle style = new InboxStyle(); for (int i = 0; messageCursor.moveToPosition(i) && i < messagesCount; i++) { if (when < 0) { when = messageCursor.getLong(idxMessageTimestamp); } if (i < 5) { final SpannableStringBuilder sb = new SpannableStringBuilder(); sb.append(UserColorNameUtils.getUserNickname(context, messageCursor.getLong(idxUserId), mNameFirst ? messageCursor.getString(idxMessageUserName) : messageCursor.getString(idxMessageUserScreenName))); sb.setSpan(new StyleSpan(Typeface.BOLD), 0, sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); sb.append(' '); sb.append(messageCursor.getString(idxMessageText)); style.addLine(sb); } final long userId = messageCursor.getLong(idxMessageUserId); final long messageId = messageCursor.getLong(idxMessageId); idsMap.put(userId, Math.max(idsMap.get(userId, -1L), messageId)); } if (mNameFirst) { style.setSummaryText(accountName); } else { style.setSummaryText("@" + accountScreenName); } final StringLongPair[] positions = new StringLongPair[idsMap.size()]; for (int i = 0, j = idsMap.size(); i < j; i++) { positions[i] = new StringLongPair(String.valueOf(idsMap.keyAt(i)), idsMap.valueAt(i)); } // Setup notification final NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setAutoCancel(true); builder.setSmallIcon(R.drawable.ic_stat_direct_message); builder.setTicker(notificationTitle); builder.setContentTitle(notificationTitle); builder.setContentText(notificationContent); builder.setCategory(NotificationCompat.CATEGORY_SOCIAL); builder.setContentIntent(getContentIntent(context, AUTHORITY_DIRECT_MESSAGES, accountId)); builder.setContentIntent(getDeleteIntent(context, AUTHORITY_DIRECT_MESSAGES, accountId, positions)); builder.setNumber(messagesCount); builder.setWhen(when); builder.setStyle(style); builder.setColor(pref.getNotificationLightColor()); setNotificationPreferences(builder, pref, pref.getDirectMessagesNotificationType()); nm.notify("messages_" + accountId, NOTIFICATION_ID_DIRECT_MESSAGES, builder.build()); Utils.sendPebbleNotification(context, notificationContent); } finally { messageCursor.close(); userCursor.close(); } }