NotificationCompatApi20.java revision 47702147608084fec16a50640da54b412c737b9c
1/*
2 * Copyright (C) 2014 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.os.Bundle;
24import android.widget.RemoteViews;
25
26class NotificationCompatApi20 {
27    public static class Builder implements NotificationBuilderWithBuilderAccessor,
28            NotificationBuilderWithActions {
29        private Notification.Builder b;
30
31        public Builder(Context context, Notification n,
32                CharSequence contentTitle, CharSequence contentText, CharSequence contentInfo,
33                RemoteViews tickerView, int number,
34                PendingIntent contentIntent, PendingIntent fullScreenIntent, Bitmap largeIcon,
35                int mProgressMax, int mProgress, boolean mProgressIndeterminate,
36                boolean useChronometer, int priority, CharSequence subText, boolean localOnly,
37                Bundle extras) {
38            b = new Notification.Builder(context)
39                .setWhen(n.when)
40                .setSmallIcon(n.icon, n.iconLevel)
41                .setContent(n.contentView)
42                .setTicker(n.tickerText, tickerView)
43                .setSound(n.sound, n.audioStreamType)
44                .setVibrate(n.vibrate)
45                .setLights(n.ledARGB, n.ledOnMS, n.ledOffMS)
46                .setOngoing((n.flags & Notification.FLAG_ONGOING_EVENT) != 0)
47                .setOnlyAlertOnce((n.flags & Notification.FLAG_ONLY_ALERT_ONCE) != 0)
48                .setAutoCancel((n.flags & Notification.FLAG_AUTO_CANCEL) != 0)
49                .setDefaults(n.defaults)
50                .setContentTitle(contentTitle)
51                .setContentText(contentText)
52                .setSubText(subText)
53                .setContentInfo(contentInfo)
54                .setContentIntent(contentIntent)
55                .setDeleteIntent(n.deleteIntent)
56                .setFullScreenIntent(fullScreenIntent,
57                        (n.flags & Notification.FLAG_HIGH_PRIORITY) != 0)
58                .setLargeIcon(largeIcon)
59                .setNumber(number)
60                .setUsesChronometer(useChronometer)
61                .setPriority(priority)
62                .setProgress(mProgressMax, mProgress, mProgressIndeterminate)
63                .setLocalOnly(localOnly)
64                .setExtras(extras);
65        }
66
67        @Override
68        public void addAction(int icon, CharSequence title, PendingIntent intent) {
69            b.addAction(icon, title, intent);
70        }
71
72        @Override
73        public Notification.Builder getBuilder() {
74            return b;
75        }
76
77        public Notification build() {
78            return b.build();
79        }
80    }
81
82    public static boolean getLocalOnly(Notification notif) {
83        return (notif.flags & Notification.FLAG_LOCAL_ONLY) != 0;
84    }
85}
86