1/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.support.v4.app;
18
19import android.app.Notification;
20import android.app.PendingIntent;
21import android.content.Context;
22import android.graphics.Bitmap;
23import android.widget.RemoteViews;
24import java.util.ArrayList;
25
26class NotificationCompatJellybean {
27    private Notification.Builder b;
28    public NotificationCompatJellybean(Context context, Notification n,
29            CharSequence contentTitle, CharSequence contentText, CharSequence contentInfo,
30            RemoteViews tickerView, int number,
31            PendingIntent contentIntent, PendingIntent fullScreenIntent, Bitmap largeIcon,
32            int mProgressMax, int mProgress, boolean mProgressIndeterminate,
33            boolean useChronometer, int priority, CharSequence subText) {
34        b = new Notification.Builder(context)
35            .setWhen(n.when)
36            .setSmallIcon(n.icon, n.iconLevel)
37            .setContent(n.contentView)
38            .setTicker(n.tickerText, tickerView)
39            .setSound(n.sound, n.audioStreamType)
40            .setVibrate(n.vibrate)
41            .setLights(n.ledARGB, n.ledOnMS, n.ledOffMS)
42            .setOngoing((n.flags & Notification.FLAG_ONGOING_EVENT) != 0)
43            .setOnlyAlertOnce((n.flags & Notification.FLAG_ONLY_ALERT_ONCE) != 0)
44            .setAutoCancel((n.flags & Notification.FLAG_AUTO_CANCEL) != 0)
45            .setDefaults(n.defaults)
46            .setContentTitle(contentTitle)
47            .setContentText(contentText)
48            .setSubText(subText)
49            .setContentInfo(contentInfo)
50            .setContentIntent(contentIntent)
51            .setDeleteIntent(n.deleteIntent)
52            .setFullScreenIntent(fullScreenIntent,
53                    (n.flags & Notification.FLAG_HIGH_PRIORITY) != 0)
54            .setLargeIcon(largeIcon)
55            .setNumber(number)
56            .setUsesChronometer(useChronometer)
57            .setPriority(priority)
58            .setProgress(mProgressMax, mProgress, mProgressIndeterminate);
59    }
60
61    public void addAction(int icon, CharSequence title, PendingIntent intent) {
62        b.addAction(icon, title, intent);
63    }
64
65    public void addBigTextStyle(CharSequence bigContentTitle, boolean useSummary,
66            CharSequence summaryText, CharSequence bigText) {
67        Notification.BigTextStyle style = new Notification.BigTextStyle(b)
68            .setBigContentTitle(bigContentTitle)
69            .bigText(bigText);
70        if (useSummary) {
71            style.setSummaryText(summaryText);
72         }
73    }
74
75    public void addBigPictureStyle(CharSequence bigContentTitle, boolean useSummary,
76            CharSequence summaryText, Bitmap bigPicture) {
77       Notification.BigPictureStyle style = new Notification.BigPictureStyle(b)
78           .setBigContentTitle(bigContentTitle)
79           .bigPicture(bigPicture);
80        if (useSummary) {
81            style.setSummaryText(summaryText);
82         }
83    }
84
85    public void addInboxStyle(CharSequence bigContentTitle, boolean useSummary,
86            CharSequence summaryText, ArrayList<CharSequence> texts) {
87        Notification.InboxStyle style = new Notification.InboxStyle(b)
88            .setBigContentTitle(bigContentTitle);
89        if (useSummary) {
90            style.setSummaryText(summaryText);
91        }
92        for (CharSequence text: texts) {
93            style.addLine(text);
94        }
95    }
96
97    public Notification build() {
98        return b.build();
99    }
100}
101