Java 类android.support.v4.app.NotificationCompat.Style 实例源码

项目:Onosendai    文件:Notifications.java   
private static void updateColumn (final Context context, final DbInterface db, final Column col, final NotificationManager nm) {
    final int nId = idForColumn(col);
    final int count = db.getUnreadCount(col);
    if (count > 0) {
        final Intent showMainActI = new Intent(context, MainActivity.class)
                .setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
                .putExtra(MainActivity.ARG_FOCUS_COLUMN_ID, col.getId());
        final PendingIntent showMainActPi = PendingIntent.getActivity(context, col.getId(), showMainActI, PendingIntent.FLAG_CANCEL_CURRENT);

        final List<Tweet> tweets = db.getTweets(col.getId(), Math.min(count, 5),
                Selection.FILTERED, col.getExcludeColumnIds(),
                col.getInlineMediaStyle() == InlineMediaStyle.SEAMLESS,
                col.getNotificationStyle().isExcludeRetweets(),
                !col.getNotificationStyle().isIncludeOwnTweets());

        final String msg = makeMsg(col, tweets, count);
        final Style style = makePreview(tweets, count);
        final PendingIntent markAsReadPi = MarkAsReadReceiver.makePi(context, col, tweets);

        final Builder nb = new NotificationCompat.Builder(context)
                .setOnlyAlertOnce(true)
                .setSmallIcon(notificationIcon())
                .setContentTitle(col.getTitle())
                .setContentText(msg)
                .setTicker(msg)
                .setNumber(count)
                .setContentIntent(showMainActPi)
                .setAutoCancel(true)
                .setWhen(System.currentTimeMillis())
                .setStyle(style);
        if (markAsReadPi != null) nb.addAction(android.R.drawable.ic_menu_close_clear_cancel, "Mark as read", markAsReadPi); //ES
        applyStyle(nb, col.getNotificationStyle());
        nm.notify(nId, nb.build());
    }
    else {
        nm.cancel(nId);
    }
}
项目:Onosendai    文件:Notifications.java   
private static Style makePreview (final List<Tweet> tweets, final int count) {
    if (tweets == null || tweets.size() < 1) return null;

    if (tweets.size() == 1) return new NotificationCompat.BigTextStyle()
            .bigText(tweetToSpanable(tweets.iterator().next()));

    final InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
    for (final Tweet tweet : tweets) {
        inboxStyle.addLine(tweetToSpanable(tweet));
    }
    if (tweets.size() < count) {
        inboxStyle.setSummaryText(String.format("+%s more", count - tweets.size()));
    }
    return inboxStyle;
}
项目:boohee_v5.6    文件:NotificationCompat.java   
private static void addMediaStyleToBuilderLollipop(NotificationBuilderWithBuilderAccessor builder, Style style) {
    if (style instanceof MediaStyle) {
        MediaStyle mediaStyle = (MediaStyle) style;
        NotificationCompatImpl21.addMediaStyle(builder, mediaStyle.mActionsToShowInCompact, mediaStyle.mToken != null ? mediaStyle.mToken.getToken() : null);
    }
}