1/**
2 * Copyright (C) 2017 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.support.annotation.RequiresApi;
25import android.widget.RemoteViews;
26
27import java.util.ArrayList;
28
29@RequiresApi(26)
30class NotificationCompatApi26 {
31    public static class Builder implements NotificationBuilderWithBuilderAccessor,
32            NotificationBuilderWithActions {
33
34        private Notification.Builder mB;
35
36        Builder(Context context, Notification n,
37                CharSequence contentTitle, CharSequence contentText, CharSequence contentInfo,
38                RemoteViews tickerView, int number,
39                PendingIntent contentIntent, PendingIntent fullScreenIntent, Bitmap largeIcon,
40                int progressMax, int progress, boolean progressIndeterminate, boolean showWhen,
41                boolean useChronometer, int priority, CharSequence subText, boolean localOnly,
42                String category, ArrayList<String> people, Bundle extras, int color,
43                int visibility, Notification publicVersion, String groupKey, boolean groupSummary,
44                String sortKey, CharSequence[] remoteInputHistory, RemoteViews contentView,
45                RemoteViews bigContentView, RemoteViews headsUpContentView,
46                String channelId, int badgeIcon, String shortcutId, long timeoutMs,
47                boolean colorized, boolean colorizedSet, int groupAlertBehavior) {
48            mB = new Notification.Builder(context, channelId)
49                    .setWhen(n.when)
50                    .setShowWhen(showWhen)
51                    .setSmallIcon(n.icon, n.iconLevel)
52                    .setContent(n.contentView)
53                    .setTicker(n.tickerText, tickerView)
54                    .setSound(n.sound, n.audioStreamType)
55                    .setVibrate(n.vibrate)
56                    .setLights(n.ledARGB, n.ledOnMS, n.ledOffMS)
57                    .setOngoing((n.flags & Notification.FLAG_ONGOING_EVENT) != 0)
58                    .setOnlyAlertOnce((n.flags & Notification.FLAG_ONLY_ALERT_ONCE) != 0)
59                    .setAutoCancel((n.flags & Notification.FLAG_AUTO_CANCEL) != 0)
60                    .setDefaults(n.defaults)
61                    .setContentTitle(contentTitle)
62                    .setContentText(contentText)
63                    .setSubText(subText)
64                    .setContentInfo(contentInfo)
65                    .setContentIntent(contentIntent)
66                    .setDeleteIntent(n.deleteIntent)
67                    .setFullScreenIntent(fullScreenIntent,
68                            (n.flags & Notification.FLAG_HIGH_PRIORITY) != 0)
69                    .setLargeIcon(largeIcon)
70                    .setNumber(number)
71                    .setUsesChronometer(useChronometer)
72                    .setPriority(priority)
73                    .setProgress(progressMax, progress, progressIndeterminate)
74                    .setLocalOnly(localOnly)
75                    .setExtras(extras)
76                    .setGroup(groupKey)
77                    .setGroupSummary(groupSummary)
78                    .setSortKey(sortKey)
79                    .setCategory(category)
80                    .setColor(color)
81                    .setVisibility(visibility)
82                    .setPublicVersion(publicVersion)
83                    .setRemoteInputHistory(remoteInputHistory)
84                    .setChannelId(channelId)
85                    .setBadgeIconType(badgeIcon)
86                    .setShortcutId(shortcutId)
87                    .setTimeoutAfter(timeoutMs)
88                    .setGroupAlertBehavior(groupAlertBehavior);
89            if (colorizedSet) {
90                mB.setColorized(colorized);
91            }
92            if (contentView != null) {
93                mB.setCustomContentView(contentView);
94            }
95            if (bigContentView != null) {
96                mB.setCustomBigContentView(bigContentView);
97            }
98            if (headsUpContentView != null) {
99                mB.setCustomHeadsUpContentView(headsUpContentView);
100            }
101            for (String person : people) {
102                mB.addPerson(person);
103            }
104        }
105
106        @Override
107        public void addAction(NotificationCompatBase.Action action) {
108            NotificationCompatApi24.addAction(mB, action);
109        }
110
111        @Override
112        public Notification.Builder getBuilder() {
113            return mB;
114        }
115
116        @Override
117        public Notification build() {
118            return mB.build();
119        }
120    }
121}
122