1c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell/*
2c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell * Copyright (C) 2012 The Android Open Source Project
3c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell *
4c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell * Licensed under the Apache License, Version 2.0 (the "License");
5c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell * you may not use this file except in compliance with the License.
6c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell * You may obtain a copy of the License at
7c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell *
8c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell *      http://www.apache.org/licenses/LICENSE-2.0
9c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell *
10c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell * Unless required by applicable law or agreed to in writing, software
11c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell * distributed under the License is distributed on an "AS IS" BASIS,
12c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell * See the License for the specific language governing permissions and
14c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell * limitations under the License.
15c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell */
16c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
17c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powellpackage android.support.v4.app;
18c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
19c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powellimport android.app.Notification;
20c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powellimport android.app.NotificationManager;
21c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powellimport android.app.PendingIntent;
22c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powellimport android.content.Context;
23c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powellimport android.graphics.Bitmap;
24c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powellimport android.media.AudioManager;
25c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powellimport android.net.Uri;
26c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powellimport android.os.Build;
27c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powellimport android.widget.RemoteViews;
28f021758934b35e3b842c6799344531d7ea2969daChris Wrenimport java.util.ArrayList;
29c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
30080df8ffb0920eccb300baa39180eb956a000a53Chris Wren/**
31080df8ffb0920eccb300baa39180eb956a000a53Chris Wren * Helper for accessing features in {@link android.app.Notification}
32080df8ffb0920eccb300baa39180eb956a000a53Chris Wren * introduced after API level 4 in a backwards compatible fashion.
33080df8ffb0920eccb300baa39180eb956a000a53Chris Wren */
34c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powellpublic class NotificationCompat {
35c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell    /**
36f021758934b35e3b842c6799344531d7ea2969daChris Wren     * Obsolete flag indicating high-priority notifications; use the priority field instead.
37884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     *
38f021758934b35e3b842c6799344531d7ea2969daChris Wren     * @deprecated Use {@link NotificationCompat.Builder#setPriority(int)} with a positive value.
39c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell     */
40c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell    public static final int FLAG_HIGH_PRIORITY = 0x00000080;
41c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
42f021758934b35e3b842c6799344531d7ea2969daChris Wren    /**
43f021758934b35e3b842c6799344531d7ea2969daChris Wren     * Default notification priority for {@link NotificationCompat.Builder#setPriority(int)}.
44f021758934b35e3b842c6799344531d7ea2969daChris Wren     * If your application does not prioritize its own notifications,
45f021758934b35e3b842c6799344531d7ea2969daChris Wren     * use this value for all notifications.
46f021758934b35e3b842c6799344531d7ea2969daChris Wren     */
47f021758934b35e3b842c6799344531d7ea2969daChris Wren    public static final int PRIORITY_DEFAULT = 0;
48f021758934b35e3b842c6799344531d7ea2969daChris Wren
49f021758934b35e3b842c6799344531d7ea2969daChris Wren    /**
50f021758934b35e3b842c6799344531d7ea2969daChris Wren     * Lower notification priority for {@link NotificationCompat.Builder#setPriority(int)},
51f021758934b35e3b842c6799344531d7ea2969daChris Wren     * for items that are less important. The UI may choose to show
52f021758934b35e3b842c6799344531d7ea2969daChris Wren     * these items smaller, or at a different position in the list,
53f021758934b35e3b842c6799344531d7ea2969daChris Wren     * compared with your app's {@link #PRIORITY_DEFAULT} items.
54f021758934b35e3b842c6799344531d7ea2969daChris Wren     */
55f021758934b35e3b842c6799344531d7ea2969daChris Wren    public static final int PRIORITY_LOW = -1;
56f021758934b35e3b842c6799344531d7ea2969daChris Wren
57f021758934b35e3b842c6799344531d7ea2969daChris Wren    /**
58f021758934b35e3b842c6799344531d7ea2969daChris Wren     * Lowest notification priority for {@link NotificationCompat.Builder#setPriority(int)};
59f021758934b35e3b842c6799344531d7ea2969daChris Wren     * these items might not be shown to the user except under
60f021758934b35e3b842c6799344531d7ea2969daChris Wren     * special circumstances, such as detailed notification logs.
61f021758934b35e3b842c6799344531d7ea2969daChris Wren     */
62f021758934b35e3b842c6799344531d7ea2969daChris Wren    public static final int PRIORITY_MIN = -2;
63f021758934b35e3b842c6799344531d7ea2969daChris Wren
64f021758934b35e3b842c6799344531d7ea2969daChris Wren    /**
65f021758934b35e3b842c6799344531d7ea2969daChris Wren     * Higher notification priority for {@link NotificationCompat.Builder#setPriority(int)},
66f021758934b35e3b842c6799344531d7ea2969daChris Wren     * for more important notifications or alerts. The UI may choose
67f021758934b35e3b842c6799344531d7ea2969daChris Wren     * to show these items larger, or at a different position in
68f021758934b35e3b842c6799344531d7ea2969daChris Wren     * notification lists, compared with your app's {@link #PRIORITY_DEFAULT} items.
69f021758934b35e3b842c6799344531d7ea2969daChris Wren     */
70f021758934b35e3b842c6799344531d7ea2969daChris Wren    public static final int PRIORITY_HIGH = 1;
71f021758934b35e3b842c6799344531d7ea2969daChris Wren
72f021758934b35e3b842c6799344531d7ea2969daChris Wren    /**
73f021758934b35e3b842c6799344531d7ea2969daChris Wren     * Highest notification priority for {@link NotificationCompat.Builder#setPriority(int)},
74f021758934b35e3b842c6799344531d7ea2969daChris Wren     * for your application's most important items that require the user's
75f021758934b35e3b842c6799344531d7ea2969daChris Wren     * prompt attention or input.
76f021758934b35e3b842c6799344531d7ea2969daChris Wren     */
77f021758934b35e3b842c6799344531d7ea2969daChris Wren    public static final int PRIORITY_MAX = 2;
78f021758934b35e3b842c6799344531d7ea2969daChris Wren
79c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell    private static final NotificationCompatImpl IMPL;
80c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
81c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell    interface NotificationCompatImpl {
82f021758934b35e3b842c6799344531d7ea2969daChris Wren        public Notification build(Builder b);
83c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell    }
84c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
85c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell    static class NotificationCompatImplBase implements NotificationCompatImpl {
86f021758934b35e3b842c6799344531d7ea2969daChris Wren        public Notification build(Builder b) {
87c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            Notification result = (Notification) b.mNotification;
88c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            result.setLatestEventInfo(b.mContext, b.mContentTitle,
89c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell                    b.mContentText, b.mContentIntent);
90f021758934b35e3b842c6799344531d7ea2969daChris Wren            // translate high priority requests into legacy flag
91f021758934b35e3b842c6799344531d7ea2969daChris Wren            if (b.mPriority > PRIORITY_DEFAULT) {
92884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin                result.flags |= FLAG_HIGH_PRIORITY;
93f021758934b35e3b842c6799344531d7ea2969daChris Wren            }
94c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            return result;
95c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        }
96c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell    }
97c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
98c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell    static class NotificationCompatImplHoneycomb implements NotificationCompatImpl {
99f021758934b35e3b842c6799344531d7ea2969daChris Wren        public Notification build(Builder b) {
100c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            return NotificationCompatHoneycomb.add(b.mContext, b.mNotification,
101c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell                    b.mContentTitle, b.mContentText, b.mContentInfo, b.mTickerView,
102c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell                    b.mNumber, b.mContentIntent, b.mFullScreenIntent, b.mLargeIcon);
103c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        }
104c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell    }
105c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
106f021758934b35e3b842c6799344531d7ea2969daChris Wren    static class NotificationCompatImplIceCreamSandwich implements NotificationCompatImpl {
107f021758934b35e3b842c6799344531d7ea2969daChris Wren        public Notification build(Builder b) {
108f021758934b35e3b842c6799344531d7ea2969daChris Wren            return NotificationCompatIceCreamSandwich.add(b.mContext, b.mNotification,
109f021758934b35e3b842c6799344531d7ea2969daChris Wren                    b.mContentTitle, b.mContentText, b.mContentInfo, b.mTickerView,
110f021758934b35e3b842c6799344531d7ea2969daChris Wren                    b.mNumber, b.mContentIntent, b.mFullScreenIntent, b.mLargeIcon,
111f021758934b35e3b842c6799344531d7ea2969daChris Wren                    b.mProgressMax, b.mProgress, b.mProgressIndeterminate);
112f021758934b35e3b842c6799344531d7ea2969daChris Wren        }
113f021758934b35e3b842c6799344531d7ea2969daChris Wren    }
114f021758934b35e3b842c6799344531d7ea2969daChris Wren
115f021758934b35e3b842c6799344531d7ea2969daChris Wren    static class NotificationCompatImplJellybean implements NotificationCompatImpl {
116f021758934b35e3b842c6799344531d7ea2969daChris Wren        public Notification build(Builder b) {
117f021758934b35e3b842c6799344531d7ea2969daChris Wren            NotificationCompatJellybean jbBuilder = new NotificationCompatJellybean(
118f021758934b35e3b842c6799344531d7ea2969daChris Wren                    b.mContext, b.mNotification, b.mContentTitle, b.mContentText, b.mContentInfo,
119f021758934b35e3b842c6799344531d7ea2969daChris Wren                    b.mTickerView, b.mNumber, b.mContentIntent, b.mFullScreenIntent, b.mLargeIcon,
120f021758934b35e3b842c6799344531d7ea2969daChris Wren                    b.mProgressMax, b.mProgress, b.mProgressIndeterminate,
121f021758934b35e3b842c6799344531d7ea2969daChris Wren                    b.mUseChronometer, b.mPriority, b.mSubText);
122f021758934b35e3b842c6799344531d7ea2969daChris Wren            for (Action action: b.mActions) {
123f021758934b35e3b842c6799344531d7ea2969daChris Wren                jbBuilder.addAction(action.icon, action.title, action.actionIntent);
124f021758934b35e3b842c6799344531d7ea2969daChris Wren            }
125f021758934b35e3b842c6799344531d7ea2969daChris Wren            if (b.mStyle != null) {
126f021758934b35e3b842c6799344531d7ea2969daChris Wren                if (b.mStyle instanceof BigTextStyle) {
127f021758934b35e3b842c6799344531d7ea2969daChris Wren                    BigTextStyle style = (BigTextStyle) b.mStyle;
128f021758934b35e3b842c6799344531d7ea2969daChris Wren                    jbBuilder.addBigTextStyle(style.mBigContentTitle,
129884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin                            style.mSummaryTextSet,
130f021758934b35e3b842c6799344531d7ea2969daChris Wren                            style.mSummaryText,
131f021758934b35e3b842c6799344531d7ea2969daChris Wren                            style.mBigText);
132f021758934b35e3b842c6799344531d7ea2969daChris Wren                } else if (b.mStyle instanceof InboxStyle) {
133f021758934b35e3b842c6799344531d7ea2969daChris Wren                    InboxStyle style = (InboxStyle) b.mStyle;
134f021758934b35e3b842c6799344531d7ea2969daChris Wren                    jbBuilder.addInboxStyle(style.mBigContentTitle,
135884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin                            style.mSummaryTextSet,
136f021758934b35e3b842c6799344531d7ea2969daChris Wren                            style.mSummaryText,
137f021758934b35e3b842c6799344531d7ea2969daChris Wren                            style.mTexts);
138f021758934b35e3b842c6799344531d7ea2969daChris Wren                } else if (b.mStyle instanceof BigPictureStyle) {
139f021758934b35e3b842c6799344531d7ea2969daChris Wren                    BigPictureStyle style = (BigPictureStyle) b.mStyle;
140f021758934b35e3b842c6799344531d7ea2969daChris Wren                    jbBuilder.addBigPictureStyle(style.mBigContentTitle,
141884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin                            style.mSummaryTextSet,
142f021758934b35e3b842c6799344531d7ea2969daChris Wren                            style.mSummaryText,
14349714d665f839c4804a17eea129092f8b472926dRoman Nurik                            style.mPicture,
14449714d665f839c4804a17eea129092f8b472926dRoman Nurik                            style.mBigLargeIcon,
14549714d665f839c4804a17eea129092f8b472926dRoman Nurik                            style.mBigLargeIconSet);
146f021758934b35e3b842c6799344531d7ea2969daChris Wren                }
147f021758934b35e3b842c6799344531d7ea2969daChris Wren            }
148f021758934b35e3b842c6799344531d7ea2969daChris Wren            return(jbBuilder.build());
149f021758934b35e3b842c6799344531d7ea2969daChris Wren        }
150f021758934b35e3b842c6799344531d7ea2969daChris Wren    }
151f021758934b35e3b842c6799344531d7ea2969daChris Wren
152c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell    static {
153f021758934b35e3b842c6799344531d7ea2969daChris Wren        if (Build.VERSION.SDK_INT >= 16) {
154f021758934b35e3b842c6799344531d7ea2969daChris Wren            IMPL = new NotificationCompatImplJellybean();
155080df8ffb0920eccb300baa39180eb956a000a53Chris Wren        } else if (Build.VERSION.SDK_INT >= 14) {
156f021758934b35e3b842c6799344531d7ea2969daChris Wren            IMPL = new NotificationCompatImplIceCreamSandwich();
157f021758934b35e3b842c6799344531d7ea2969daChris Wren        } else if (Build.VERSION.SDK_INT >= 11) {
158c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            IMPL = new NotificationCompatImplHoneycomb();
159c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        } else {
160c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            IMPL = new NotificationCompatImplBase();
161c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        }
162c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell    }
163c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
164c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell    /**
165884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * Builder class for {@link NotificationCompat} objects.  Allows easier control over
166c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell     * all the flags, as well as help constructing the typical notification layouts.
167884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * <p>
168884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * On platform versions that don't offer expanded notifications, methods that depend on
169884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * expanded notifications have no effect.
170884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * </p>
171884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * <p>
172884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * For example, action buttons won't appear on platforms prior to Android 4.1. Action
173884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * buttons depend on expanded notifications, which are only available in Android 4.1
174884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * and later.
175884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * <p>
176884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * For this reason, you should always ensure that UI controls in a notification are also
177884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * available in an {@link android.app.Activity} in your app, and you should always start that
178884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * {@link android.app.Activity} when users click the notification. To do this, use the
179884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * {@link NotificationCompat.Builder#setContentIntent setContentIntent()}
180884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * method.
181884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * </p>
182884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     *
183c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell     */
184c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell    public static class Builder {
185c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        Context mContext;
186c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
187c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        CharSequence mContentTitle;
188c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        CharSequence mContentText;
189c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        PendingIntent mContentIntent;
190c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        PendingIntent mFullScreenIntent;
191c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        RemoteViews mTickerView;
192c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        Bitmap mLargeIcon;
193c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        CharSequence mContentInfo;
194c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        int mNumber;
195f021758934b35e3b842c6799344531d7ea2969daChris Wren        int mPriority;
196f021758934b35e3b842c6799344531d7ea2969daChris Wren        boolean mUseChronometer;
197f021758934b35e3b842c6799344531d7ea2969daChris Wren        Style mStyle;
198f021758934b35e3b842c6799344531d7ea2969daChris Wren        CharSequence mSubText;
199f021758934b35e3b842c6799344531d7ea2969daChris Wren        int mProgressMax;
200f021758934b35e3b842c6799344531d7ea2969daChris Wren        int mProgress;
201f021758934b35e3b842c6799344531d7ea2969daChris Wren        boolean mProgressIndeterminate;
202f021758934b35e3b842c6799344531d7ea2969daChris Wren        ArrayList<Action> mActions = new ArrayList<Action>();
203c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
204c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        Notification mNotification = new Notification();
205c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
206c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        /**
207c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * Constructor.
208c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         *
209c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * Automatically sets the when field to {@link System#currentTimeMillis()
210c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * System.currentTimeMillis()} and the audio stream to the
211c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * {@link Notification#STREAM_DEFAULT}.
212c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         *
213c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * @param context A {@link Context} that will be used to construct the
214c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         *      RemoteViews. The Context will not be held past the lifetime of this
215c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         *      Builder object.
216c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         */
217c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        public Builder(Context context) {
218c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mContext = context;
219c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
220c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            // Set defaults to match the defaults of a Notification
221c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mNotification.when = System.currentTimeMillis();
222c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mNotification.audioStreamType = Notification.STREAM_DEFAULT;
223f021758934b35e3b842c6799344531d7ea2969daChris Wren            mPriority = PRIORITY_DEFAULT;
224c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        }
225c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
226c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        /**
227c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * Set the time that the event occurred.  Notifications in the panel are
228c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * sorted by this time.
229c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         */
230c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        public Builder setWhen(long when) {
231c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mNotification.when = when;
232c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            return this;
233c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        }
234c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
235c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        /**
236f021758934b35e3b842c6799344531d7ea2969daChris Wren         * Show the {@link Notification#when} field as a stopwatch.
237884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin         *
238884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin         * Instead of presenting <code>when</code> as a timestamp, the notification will show an
239f021758934b35e3b842c6799344531d7ea2969daChris Wren         * automatically updating display of the minutes and seconds since <code>when</code>.
240f021758934b35e3b842c6799344531d7ea2969daChris Wren         *
241f021758934b35e3b842c6799344531d7ea2969daChris Wren         * Useful when showing an elapsed time (like an ongoing phone call).
242f021758934b35e3b842c6799344531d7ea2969daChris Wren         *
243f021758934b35e3b842c6799344531d7ea2969daChris Wren         * @see android.widget.Chronometer
244f021758934b35e3b842c6799344531d7ea2969daChris Wren         * @see Notification#when
245f021758934b35e3b842c6799344531d7ea2969daChris Wren         */
246f021758934b35e3b842c6799344531d7ea2969daChris Wren        public Builder setUsesChronometer(boolean b) {
247f021758934b35e3b842c6799344531d7ea2969daChris Wren            mUseChronometer = b;
248f021758934b35e3b842c6799344531d7ea2969daChris Wren            return this;
249f021758934b35e3b842c6799344531d7ea2969daChris Wren        }
250f021758934b35e3b842c6799344531d7ea2969daChris Wren
251f021758934b35e3b842c6799344531d7ea2969daChris Wren        /**
252c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * Set the small icon to use in the notification layouts.  Different classes of devices
253c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * may return different sizes.  See the UX guidelines for more information on how to
254c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * design these icons.
255c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         *
256c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * @param icon A resource ID in the application's package of the drawble to use.
257c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         */
258c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        public Builder setSmallIcon(int icon) {
259c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mNotification.icon = icon;
260c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            return this;
261c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        }
262c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
263c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        /**
264c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * A variant of {@link #setSmallIcon(int) setSmallIcon(int)} that takes an additional
265c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * level parameter for when the icon is a {@link android.graphics.drawable.LevelListDrawable
266c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * LevelListDrawable}.
267c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         *
268c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * @param icon A resource ID in the application's package of the drawble to use.
269c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * @param level The level to use for the icon.
270c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         *
271c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * @see android.graphics.drawable.LevelListDrawable
272c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         */
273c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        public Builder setSmallIcon(int icon, int level) {
274c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mNotification.icon = icon;
275c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mNotification.iconLevel = level;
276c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            return this;
277c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        }
278c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
279c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        /**
280c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * Set the title (first row) of the notification, in a standard notification.
281c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         */
282c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        public Builder setContentTitle(CharSequence title) {
283c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mContentTitle = title;
284c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            return this;
285c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        }
286c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
287c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        /**
288c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * Set the text (second row) of the notification, in a standard notification.
289c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         */
290c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        public Builder setContentText(CharSequence text) {
291c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mContentText = text;
292c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            return this;
293c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        }
294c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
295c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        /**
296884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin         * Set the third line of text in the platform notification template.
297f021758934b35e3b842c6799344531d7ea2969daChris Wren         * Don't use if you're also using {@link #setProgress(int, int, boolean)};
298f021758934b35e3b842c6799344531d7ea2969daChris Wren         * they occupy the same location in the standard template.
299884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin         * <br>
300884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin         * If the platform does not provide large-format notifications, this method has no effect.
301884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin         * The third line of text only appears in expanded view.
302884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin         * <br>
303f021758934b35e3b842c6799344531d7ea2969daChris Wren         */
304f021758934b35e3b842c6799344531d7ea2969daChris Wren        public Builder setSubText(CharSequence text) {
305f021758934b35e3b842c6799344531d7ea2969daChris Wren            mSubText = text;
306f021758934b35e3b842c6799344531d7ea2969daChris Wren            return this;
307f021758934b35e3b842c6799344531d7ea2969daChris Wren        }
308f021758934b35e3b842c6799344531d7ea2969daChris Wren
309f021758934b35e3b842c6799344531d7ea2969daChris Wren        /**
310c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * Set the large number at the right-hand side of the notification.  This is
311c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * equivalent to setContentInfo, although it might show the number in a different
312c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * font size for readability.
313c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         */
314c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        public Builder setNumber(int number) {
315c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mNumber = number;
316c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            return this;
317c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        }
318c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
319c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        /**
320c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * Set the large text at the right-hand side of the notification.
321c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         */
322c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        public Builder setContentInfo(CharSequence info) {
323c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mContentInfo = info;
324c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            return this;
325c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        }
326c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
327c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        /**
328c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * Set the progress this notification represents, which may be
329f021758934b35e3b842c6799344531d7ea2969daChris Wren         * represented as a {@link android.widget.ProgressBar}.
330c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         */
331c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        public Builder setProgress(int max, int progress, boolean indeterminate) {
332c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mProgressMax = max;
333c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mProgress = progress;
334c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mProgressIndeterminate = indeterminate;
335c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            return this;
336f021758934b35e3b842c6799344531d7ea2969daChris Wren        }
337c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
338c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        /**
339c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * Supply a custom RemoteViews to use instead of the standard one.
340c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         */
341c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        public Builder setContent(RemoteViews views) {
342c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mNotification.contentView = views;
343c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            return this;
344c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        }
345c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
346c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        /**
347c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * Supply a {@link PendingIntent} to send when the notification is clicked.
348c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * If you do not supply an intent, you can now add PendingIntents to individual
349c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * views to be launched when clicked by calling {@link RemoteViews#setOnClickPendingIntent
350c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * RemoteViews.setOnClickPendingIntent(int,PendingIntent)}.  Be sure to
351c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * read {@link Notification#contentIntent Notification.contentIntent} for
352c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * how to correctly use this.
353c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         */
354c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        public Builder setContentIntent(PendingIntent intent) {
355c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mContentIntent = intent;
356c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            return this;
357c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        }
358c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
359c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        /**
360c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * Supply a {@link PendingIntent} to send when the notification is cleared by the user
361c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * directly from the notification panel.  For example, this intent is sent when the user
362c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * clicks the "Clear all" button, or the individual "X" buttons on notifications.  This
363c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * intent is not sent when the application calls {@link NotificationManager#cancel
364c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * NotificationManager.cancel(int)}.
365c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         */
366c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        public Builder setDeleteIntent(PendingIntent intent) {
367c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mNotification.deleteIntent = intent;
368c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            return this;
369c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        }
370c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
371c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        /**
372c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * An intent to launch instead of posting the notification to the status bar.
373c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * Only for use with extremely high-priority notifications demanding the user's
374c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * <strong>immediate</strong> attention, such as an incoming phone call or
375c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * alarm clock that the user has explicitly set to a particular time.
376c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * If this facility is used for something else, please give the user an option
377c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * to turn it off and use a normal notification, as this can be extremely
378c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * disruptive.
379c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         *
380c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * @param intent The pending intent to launch.
381c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * @param highPriority Passing true will cause this notification to be sent
382c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         *          even if other notifications are suppressed.
383c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         */
384c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        public Builder setFullScreenIntent(PendingIntent intent, boolean highPriority) {
385c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mFullScreenIntent = intent;
386c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            setFlag(FLAG_HIGH_PRIORITY, highPriority);
387c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            return this;
388c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        }
389c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
390c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        /**
391c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * Set the text that is displayed in the status bar when the notification first
392c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * arrives.
393c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         */
394c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        public Builder setTicker(CharSequence tickerText) {
395c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mNotification.tickerText = tickerText;
396c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            return this;
397c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        }
398c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
399c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        /**
400c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * Set the text that is displayed in the status bar when the notification first
401c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * arrives, and also a RemoteViews object that may be displayed instead on some
402c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * devices.
403c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         */
404c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        public Builder setTicker(CharSequence tickerText, RemoteViews views) {
405c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mNotification.tickerText = tickerText;
406c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mTickerView = views;
407c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            return this;
408c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        }
409c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
410c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        /**
411c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * Set the large icon that is shown in the ticker and notification.
412c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         */
413c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        public Builder setLargeIcon(Bitmap icon) {
414c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mLargeIcon = icon;
415c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            return this;
416c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        }
417c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
418c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        /**
419c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * Set the sound to play.  It will play on the default stream.
420c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         */
421c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        public Builder setSound(Uri sound) {
422c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mNotification.sound = sound;
423c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mNotification.audioStreamType = Notification.STREAM_DEFAULT;
424c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            return this;
425c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        }
426c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
427c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        /**
428c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * Set the sound to play.  It will play on the stream you supply.
429c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         *
430c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * @see #STREAM_DEFAULT
431c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * @see AudioManager for the <code>STREAM_</code> constants.
432c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         */
433c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        public Builder setSound(Uri sound, int streamType) {
434c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mNotification.sound = sound;
435c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mNotification.audioStreamType = streamType;
436c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            return this;
437c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        }
438c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
439c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        /**
440c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * Set the vibration pattern to use.
441c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         *
442c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * @see android.os.Vibrator for a discussion of the <code>pattern</code>
443c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * parameter.
444c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         */
445c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        public Builder setVibrate(long[] pattern) {
446c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mNotification.vibrate = pattern;
447c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            return this;
448c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        }
449c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
450c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        /**
451c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * Set the argb value that you would like the LED on the device to blnk, as well as the
452c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * rate.  The rate is specified in terms of the number of milliseconds to be on
453c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * and then the number of milliseconds to be off.
454c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         */
455c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        public Builder setLights(int argb, int onMs, int offMs) {
456c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mNotification.ledARGB = argb;
457c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mNotification.ledOnMS = onMs;
458c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mNotification.ledOffMS = offMs;
459c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            boolean showLights = mNotification.ledOnMS != 0 && mNotification.ledOffMS != 0;
460c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mNotification.flags = (mNotification.flags & ~Notification.FLAG_SHOW_LIGHTS) |
461c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell                    (showLights ? Notification.FLAG_SHOW_LIGHTS : 0);
462c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            return this;
463c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        }
464c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
465c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        /**
466c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * Set whether this is an ongoing notification.
467c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         *
468c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * <p>Ongoing notifications differ from regular notifications in the following ways:
469c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * <ul>
470c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         *   <li>Ongoing notifications are sorted above the regular notifications in the
471c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         *   notification panel.</li>
472c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         *   <li>Ongoing notifications do not have an 'X' close button, and are not affected
473c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         *   by the "Clear all" button.
474c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * </ul>
475c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         */
476c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        public Builder setOngoing(boolean ongoing) {
477c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            setFlag(Notification.FLAG_ONGOING_EVENT, ongoing);
478c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            return this;
479c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        }
480c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
481c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        /**
482c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * Set this flag if you would only like the sound, vibrate
483c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * and ticker to be played if the notification is not already showing.
484c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         */
485c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        public Builder setOnlyAlertOnce(boolean onlyAlertOnce) {
486c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            setFlag(Notification.FLAG_ONLY_ALERT_ONCE, onlyAlertOnce);
487c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            return this;
488c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        }
489c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
490c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        /**
491c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * Setting this flag will make it so the notification is automatically
492c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * canceled when the user clicks it in the panel.  The PendingIntent
493c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * set with {@link #setDeleteIntent} will be broadcast when the notification
494c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * is canceled.
495c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         */
496c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        public Builder setAutoCancel(boolean autoCancel) {
497c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            setFlag(Notification.FLAG_AUTO_CANCEL, autoCancel);
498c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            return this;
499c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        }
500c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
501c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        /**
502c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * Set the default notification options that will be used.
503c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * <p>
504c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * The value should be one or more of the following fields combined with
505c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * bitwise-or:
506c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * {@link Notification#DEFAULT_SOUND}, {@link Notification#DEFAULT_VIBRATE},
507c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * {@link Notification#DEFAULT_LIGHTS}.
508c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * <p>
509c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * For all default values, use {@link Notification#DEFAULT_ALL}.
510c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         */
511c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        public Builder setDefaults(int defaults) {
512c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mNotification.defaults = defaults;
513c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            if ((defaults & Notification.DEFAULT_LIGHTS) != 0) {
514c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell                mNotification.flags |= Notification.FLAG_SHOW_LIGHTS;
515c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            }
516c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            return this;
517c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        }
518c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
519c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        private void setFlag(int mask, boolean value) {
520c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            if (value) {
521c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell                mNotification.flags |= mask;
522c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            } else {
523c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell                mNotification.flags &= ~mask;
524c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            }
525c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        }
526c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
527c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        /**
528f021758934b35e3b842c6799344531d7ea2969daChris Wren         * Set the relative priority for this notification.
529884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin         *
530f021758934b35e3b842c6799344531d7ea2969daChris Wren         * Priority is an indication of how much of the user's
531f021758934b35e3b842c6799344531d7ea2969daChris Wren         * valuable attention should be consumed by this
532f021758934b35e3b842c6799344531d7ea2969daChris Wren         * notification. Low-priority notifications may be hidden from
533f021758934b35e3b842c6799344531d7ea2969daChris Wren         * the user in certain situations, while the user might be
534884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin         * interrupted for a higher-priority notification.
535884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin         * The system sets a notification's priority based on various factors including the
536884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin         * setPriority value. The effect may differ slightly on different platforms.
537f021758934b35e3b842c6799344531d7ea2969daChris Wren         */
538f021758934b35e3b842c6799344531d7ea2969daChris Wren        public Builder setPriority(int pri) {
539f021758934b35e3b842c6799344531d7ea2969daChris Wren            mPriority = pri;
540f021758934b35e3b842c6799344531d7ea2969daChris Wren            return this;
541f021758934b35e3b842c6799344531d7ea2969daChris Wren        }
542f021758934b35e3b842c6799344531d7ea2969daChris Wren
543f021758934b35e3b842c6799344531d7ea2969daChris Wren        /**
544f021758934b35e3b842c6799344531d7ea2969daChris Wren         * Add an action to this notification. Actions are typically displayed by
545f021758934b35e3b842c6799344531d7ea2969daChris Wren         * the system as a button adjacent to the notification content.
546884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin         * <br>
547884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin         * Action buttons won't appear on platforms prior to Android 4.1. Action
548884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin         * buttons depend on expanded notifications, which are only available in Android 4.1
549884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin         * and later. To ensure that an action button's functionality is always available, first
550884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin         * implement the functionality in the {@link android.app.Activity} that starts when a user
551884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin         * clicks the  notification (see {@link #setContentIntent setContentIntent()}), and then
552884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin         * enhance the notification by implementing the same functionality with
553884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin         * {@link #addAction addAction()}.
554f021758934b35e3b842c6799344531d7ea2969daChris Wren         *
555f021758934b35e3b842c6799344531d7ea2969daChris Wren         * @param icon Resource ID of a drawable that represents the action.
556f021758934b35e3b842c6799344531d7ea2969daChris Wren         * @param title Text describing the action.
557884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin         * @param intent {@link android.app.PendingIntent} to be fired when the action is invoked.
558f021758934b35e3b842c6799344531d7ea2969daChris Wren         */
559f021758934b35e3b842c6799344531d7ea2969daChris Wren        public Builder addAction(int icon, CharSequence title, PendingIntent intent) {
560f021758934b35e3b842c6799344531d7ea2969daChris Wren            mActions.add(new Action(icon, title, intent));
561f021758934b35e3b842c6799344531d7ea2969daChris Wren            return this;
562f021758934b35e3b842c6799344531d7ea2969daChris Wren        }
563f021758934b35e3b842c6799344531d7ea2969daChris Wren
564f021758934b35e3b842c6799344531d7ea2969daChris Wren        /**
565f021758934b35e3b842c6799344531d7ea2969daChris Wren         * Add a rich notification style to be applied at build time.
566884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin         * <br>
567884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin         * If the platform does not provide rich notification styles, this method has no effect. The
568884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin         * user will always see the normal notification style.
569f021758934b35e3b842c6799344531d7ea2969daChris Wren         *
570f021758934b35e3b842c6799344531d7ea2969daChris Wren         * @param style Object responsible for modifying the notification style.
571f021758934b35e3b842c6799344531d7ea2969daChris Wren         */
572f021758934b35e3b842c6799344531d7ea2969daChris Wren        public Builder setStyle(Style style) {
573f021758934b35e3b842c6799344531d7ea2969daChris Wren            if (mStyle != style) {
574f021758934b35e3b842c6799344531d7ea2969daChris Wren                mStyle = style;
575f021758934b35e3b842c6799344531d7ea2969daChris Wren                if (mStyle != null) {
576f021758934b35e3b842c6799344531d7ea2969daChris Wren                    mStyle.setBuilder(this);
577f021758934b35e3b842c6799344531d7ea2969daChris Wren                }
578f021758934b35e3b842c6799344531d7ea2969daChris Wren            }
579f021758934b35e3b842c6799344531d7ea2969daChris Wren            return this;
580f021758934b35e3b842c6799344531d7ea2969daChris Wren        }
581f021758934b35e3b842c6799344531d7ea2969daChris Wren
582f021758934b35e3b842c6799344531d7ea2969daChris Wren        /**
583f021758934b35e3b842c6799344531d7ea2969daChris Wren         * @deprecated Use {@link #build()} instead.
584f021758934b35e3b842c6799344531d7ea2969daChris Wren         */
585f021758934b35e3b842c6799344531d7ea2969daChris Wren        @Deprecated
586f021758934b35e3b842c6799344531d7ea2969daChris Wren        public Notification getNotification() {
587f021758934b35e3b842c6799344531d7ea2969daChris Wren            return (Notification) IMPL.build(this);
588f021758934b35e3b842c6799344531d7ea2969daChris Wren        }
589f021758934b35e3b842c6799344531d7ea2969daChris Wren
590f021758934b35e3b842c6799344531d7ea2969daChris Wren        /**
591c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * Combine all of the options that have been set and return a new {@link Notification}
592c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * object.
593c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         */
594f021758934b35e3b842c6799344531d7ea2969daChris Wren        public Notification build() {
595f021758934b35e3b842c6799344531d7ea2969daChris Wren            return (Notification) IMPL.build(this);
596f021758934b35e3b842c6799344531d7ea2969daChris Wren        }
597f021758934b35e3b842c6799344531d7ea2969daChris Wren    }
598f021758934b35e3b842c6799344531d7ea2969daChris Wren
599f021758934b35e3b842c6799344531d7ea2969daChris Wren    /**
600f021758934b35e3b842c6799344531d7ea2969daChris Wren     * An object that can apply a rich notification style to a {@link Notification.Builder}
601f021758934b35e3b842c6799344531d7ea2969daChris Wren     * object.
602884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * <br>
603884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * If the platform does not provide rich notification styles, methods in this class have no
604884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * effect.
605f021758934b35e3b842c6799344531d7ea2969daChris Wren     */
606f021758934b35e3b842c6799344531d7ea2969daChris Wren    public static abstract class Style
607f021758934b35e3b842c6799344531d7ea2969daChris Wren    {
608f021758934b35e3b842c6799344531d7ea2969daChris Wren        Builder mBuilder;
609f021758934b35e3b842c6799344531d7ea2969daChris Wren        CharSequence mBigContentTitle;
610f021758934b35e3b842c6799344531d7ea2969daChris Wren        CharSequence mSummaryText;
611f021758934b35e3b842c6799344531d7ea2969daChris Wren        boolean mSummaryTextSet = false;
612f021758934b35e3b842c6799344531d7ea2969daChris Wren
613f021758934b35e3b842c6799344531d7ea2969daChris Wren        public void setBuilder(Builder builder) {
614f021758934b35e3b842c6799344531d7ea2969daChris Wren            if (mBuilder != builder) {
615f021758934b35e3b842c6799344531d7ea2969daChris Wren                mBuilder = builder;
616f021758934b35e3b842c6799344531d7ea2969daChris Wren                if (mBuilder != null) {
617f021758934b35e3b842c6799344531d7ea2969daChris Wren                    mBuilder.setStyle(this);
618f021758934b35e3b842c6799344531d7ea2969daChris Wren                }
619f021758934b35e3b842c6799344531d7ea2969daChris Wren            }
620f021758934b35e3b842c6799344531d7ea2969daChris Wren        }
621f021758934b35e3b842c6799344531d7ea2969daChris Wren
622f021758934b35e3b842c6799344531d7ea2969daChris Wren        public Notification build() {
623f021758934b35e3b842c6799344531d7ea2969daChris Wren            Notification notification = null;
624f021758934b35e3b842c6799344531d7ea2969daChris Wren            if (mBuilder != null) {
625f021758934b35e3b842c6799344531d7ea2969daChris Wren                notification = mBuilder.build();
626884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin            }
627f021758934b35e3b842c6799344531d7ea2969daChris Wren            return notification;
628f021758934b35e3b842c6799344531d7ea2969daChris Wren        }
629f021758934b35e3b842c6799344531d7ea2969daChris Wren    }
630f021758934b35e3b842c6799344531d7ea2969daChris Wren
631f021758934b35e3b842c6799344531d7ea2969daChris Wren    /**
632f021758934b35e3b842c6799344531d7ea2969daChris Wren     * Helper class for generating large-format notifications that include a large image attachment.
633884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * <br>
634884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * If the platform does not provide large-format notifications, this method has no effect. The
635884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * user will always see the normal notification view.
636884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * <br>
637f021758934b35e3b842c6799344531d7ea2969daChris Wren     * This class is a "rebuilder": It attaches to a Builder object and modifies its behavior, like so:
638f021758934b35e3b842c6799344531d7ea2969daChris Wren     * <pre class="prettyprint">
639f021758934b35e3b842c6799344531d7ea2969daChris Wren     * Notification noti = new Notification.Builder()
640f021758934b35e3b842c6799344531d7ea2969daChris Wren     *     .setContentTitle(&quot;New photo from &quot; + sender.toString())
641f021758934b35e3b842c6799344531d7ea2969daChris Wren     *     .setContentText(subject)
642f021758934b35e3b842c6799344531d7ea2969daChris Wren     *     .setSmallIcon(R.drawable.new_post)
643f021758934b35e3b842c6799344531d7ea2969daChris Wren     *     .setLargeIcon(aBitmap)
644f021758934b35e3b842c6799344531d7ea2969daChris Wren     *     .setStyle(new Notification.BigPictureStyle()
645f021758934b35e3b842c6799344531d7ea2969daChris Wren     *         .bigPicture(aBigBitmap))
646f021758934b35e3b842c6799344531d7ea2969daChris Wren     *     .build();
647f021758934b35e3b842c6799344531d7ea2969daChris Wren     * </pre>
648884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     *
649f021758934b35e3b842c6799344531d7ea2969daChris Wren     * @see Notification#bigContentView
650f021758934b35e3b842c6799344531d7ea2969daChris Wren     */
651f021758934b35e3b842c6799344531d7ea2969daChris Wren    public static class BigPictureStyle extends Style {
652f021758934b35e3b842c6799344531d7ea2969daChris Wren        Bitmap mPicture;
65349714d665f839c4804a17eea129092f8b472926dRoman Nurik        Bitmap mBigLargeIcon;
65449714d665f839c4804a17eea129092f8b472926dRoman Nurik        boolean mBigLargeIconSet;
655f021758934b35e3b842c6799344531d7ea2969daChris Wren
656f021758934b35e3b842c6799344531d7ea2969daChris Wren        public BigPictureStyle() {
657f021758934b35e3b842c6799344531d7ea2969daChris Wren        }
658f021758934b35e3b842c6799344531d7ea2969daChris Wren
659f021758934b35e3b842c6799344531d7ea2969daChris Wren        public BigPictureStyle(Builder builder) {
660f021758934b35e3b842c6799344531d7ea2969daChris Wren            setBuilder(builder);
661f021758934b35e3b842c6799344531d7ea2969daChris Wren        }
662f021758934b35e3b842c6799344531d7ea2969daChris Wren
663f021758934b35e3b842c6799344531d7ea2969daChris Wren        /**
664f021758934b35e3b842c6799344531d7ea2969daChris Wren         * Overrides ContentTitle in the big form of the template.
665f021758934b35e3b842c6799344531d7ea2969daChris Wren         * This defaults to the value passed to setContentTitle().
666f021758934b35e3b842c6799344531d7ea2969daChris Wren         */
667f021758934b35e3b842c6799344531d7ea2969daChris Wren        public BigPictureStyle setBigContentTitle(CharSequence title) {
668f021758934b35e3b842c6799344531d7ea2969daChris Wren            mBigContentTitle = title;
669f021758934b35e3b842c6799344531d7ea2969daChris Wren            return this;
670f021758934b35e3b842c6799344531d7ea2969daChris Wren        }
671f021758934b35e3b842c6799344531d7ea2969daChris Wren
672f021758934b35e3b842c6799344531d7ea2969daChris Wren        /**
673f021758934b35e3b842c6799344531d7ea2969daChris Wren         * Set the first line of text after the detail section in the big form of the template.
674f021758934b35e3b842c6799344531d7ea2969daChris Wren         */
675f021758934b35e3b842c6799344531d7ea2969daChris Wren        public BigPictureStyle setSummaryText(CharSequence cs) {
676f021758934b35e3b842c6799344531d7ea2969daChris Wren            mSummaryText = cs;
677f021758934b35e3b842c6799344531d7ea2969daChris Wren            mSummaryTextSet = true;
678f021758934b35e3b842c6799344531d7ea2969daChris Wren            return this;
679f021758934b35e3b842c6799344531d7ea2969daChris Wren        }
680f021758934b35e3b842c6799344531d7ea2969daChris Wren
681b41a213761ff07de2fcfdaf16790fdcca1a1ee1bChris Wren        /**
682b41a213761ff07de2fcfdaf16790fdcca1a1ee1bChris Wren         * Provide the bitmap to be used as the payload for the BigPicture notification.
683b41a213761ff07de2fcfdaf16790fdcca1a1ee1bChris Wren         */
684f021758934b35e3b842c6799344531d7ea2969daChris Wren        public BigPictureStyle bigPicture(Bitmap b) {
685f021758934b35e3b842c6799344531d7ea2969daChris Wren            mPicture = b;
686f021758934b35e3b842c6799344531d7ea2969daChris Wren            return this;
687f021758934b35e3b842c6799344531d7ea2969daChris Wren        }
68849714d665f839c4804a17eea129092f8b472926dRoman Nurik
68949714d665f839c4804a17eea129092f8b472926dRoman Nurik        /**
69049714d665f839c4804a17eea129092f8b472926dRoman Nurik         * Override the large icon when the big notification is shown.
69149714d665f839c4804a17eea129092f8b472926dRoman Nurik         */
69249714d665f839c4804a17eea129092f8b472926dRoman Nurik        public BigPictureStyle bigLargeIcon(Bitmap b) {
69349714d665f839c4804a17eea129092f8b472926dRoman Nurik            mBigLargeIcon = b;
69449714d665f839c4804a17eea129092f8b472926dRoman Nurik            mBigLargeIconSet = true;
69549714d665f839c4804a17eea129092f8b472926dRoman Nurik            return this;
69649714d665f839c4804a17eea129092f8b472926dRoman Nurik        }
697f021758934b35e3b842c6799344531d7ea2969daChris Wren    }
698f021758934b35e3b842c6799344531d7ea2969daChris Wren
699f021758934b35e3b842c6799344531d7ea2969daChris Wren    /**
700f021758934b35e3b842c6799344531d7ea2969daChris Wren     * Helper class for generating large-format notifications that include a lot of text.
701884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     *
702884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * <br>
703884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * If the platform does not provide large-format notifications, this method has no effect. The
704884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * user will always see the normal notification view.
705884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * <br>
706f021758934b35e3b842c6799344531d7ea2969daChris Wren     * This class is a "rebuilder": It attaches to a Builder object and modifies its behavior, like so:
707f021758934b35e3b842c6799344531d7ea2969daChris Wren     * <pre class="prettyprint">
708f021758934b35e3b842c6799344531d7ea2969daChris Wren     * Notification noti = new Notification.Builder()
709f021758934b35e3b842c6799344531d7ea2969daChris Wren     *     .setContentTitle(&quot;New mail from &quot; + sender.toString())
710f021758934b35e3b842c6799344531d7ea2969daChris Wren     *     .setContentText(subject)
711f021758934b35e3b842c6799344531d7ea2969daChris Wren     *     .setSmallIcon(R.drawable.new_mail)
712f021758934b35e3b842c6799344531d7ea2969daChris Wren     *     .setLargeIcon(aBitmap)
713f021758934b35e3b842c6799344531d7ea2969daChris Wren     *     .setStyle(new Notification.BigTextStyle()
714f021758934b35e3b842c6799344531d7ea2969daChris Wren     *         .bigText(aVeryLongString))
715f021758934b35e3b842c6799344531d7ea2969daChris Wren     *     .build();
716f021758934b35e3b842c6799344531d7ea2969daChris Wren     * </pre>
717884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     *
718f021758934b35e3b842c6799344531d7ea2969daChris Wren     * @see Notification#bigContentView
719f021758934b35e3b842c6799344531d7ea2969daChris Wren     */
720f021758934b35e3b842c6799344531d7ea2969daChris Wren    public static class BigTextStyle extends Style {
721f021758934b35e3b842c6799344531d7ea2969daChris Wren        CharSequence mBigText;
722f021758934b35e3b842c6799344531d7ea2969daChris Wren
723f021758934b35e3b842c6799344531d7ea2969daChris Wren        public BigTextStyle() {
724f021758934b35e3b842c6799344531d7ea2969daChris Wren        }
725f021758934b35e3b842c6799344531d7ea2969daChris Wren
726f021758934b35e3b842c6799344531d7ea2969daChris Wren        public BigTextStyle(Builder builder) {
727f021758934b35e3b842c6799344531d7ea2969daChris Wren            setBuilder(builder);
728f021758934b35e3b842c6799344531d7ea2969daChris Wren        }
729f021758934b35e3b842c6799344531d7ea2969daChris Wren
730f021758934b35e3b842c6799344531d7ea2969daChris Wren        /**
731f021758934b35e3b842c6799344531d7ea2969daChris Wren         * Overrides ContentTitle in the big form of the template.
732f021758934b35e3b842c6799344531d7ea2969daChris Wren         * This defaults to the value passed to setContentTitle().
733f021758934b35e3b842c6799344531d7ea2969daChris Wren         */
734f021758934b35e3b842c6799344531d7ea2969daChris Wren        public BigTextStyle setBigContentTitle(CharSequence title) {
735f021758934b35e3b842c6799344531d7ea2969daChris Wren            mBigContentTitle = title;
736f021758934b35e3b842c6799344531d7ea2969daChris Wren            return this;
737f021758934b35e3b842c6799344531d7ea2969daChris Wren        }
738f021758934b35e3b842c6799344531d7ea2969daChris Wren
739f021758934b35e3b842c6799344531d7ea2969daChris Wren        /**
740f021758934b35e3b842c6799344531d7ea2969daChris Wren         * Set the first line of text after the detail section in the big form of the template.
741f021758934b35e3b842c6799344531d7ea2969daChris Wren         */
742f021758934b35e3b842c6799344531d7ea2969daChris Wren        public BigTextStyle setSummaryText(CharSequence cs) {
743f021758934b35e3b842c6799344531d7ea2969daChris Wren            mSummaryText = cs;
744f021758934b35e3b842c6799344531d7ea2969daChris Wren            mSummaryTextSet = true;
745f021758934b35e3b842c6799344531d7ea2969daChris Wren            return this;
746f021758934b35e3b842c6799344531d7ea2969daChris Wren        }
747f021758934b35e3b842c6799344531d7ea2969daChris Wren
748b41a213761ff07de2fcfdaf16790fdcca1a1ee1bChris Wren        /**
749b41a213761ff07de2fcfdaf16790fdcca1a1ee1bChris Wren         * Provide the longer text to be displayed in the big form of the
750b41a213761ff07de2fcfdaf16790fdcca1a1ee1bChris Wren         * template in place of the content text.
751b41a213761ff07de2fcfdaf16790fdcca1a1ee1bChris Wren         */
752f021758934b35e3b842c6799344531d7ea2969daChris Wren        public BigTextStyle bigText(CharSequence cs) {
753f021758934b35e3b842c6799344531d7ea2969daChris Wren            mBigText = cs;
754f021758934b35e3b842c6799344531d7ea2969daChris Wren            return this;
755f021758934b35e3b842c6799344531d7ea2969daChris Wren        }
756f021758934b35e3b842c6799344531d7ea2969daChris Wren    }
757f021758934b35e3b842c6799344531d7ea2969daChris Wren
758f021758934b35e3b842c6799344531d7ea2969daChris Wren    /**
759f021758934b35e3b842c6799344531d7ea2969daChris Wren     * Helper class for generating large-format notifications that include a list of (up to 5) strings.
760884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     *
761884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * <br>
762884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * If the platform does not provide large-format notifications, this method has no effect. The
763884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * user will always see the normal notification view.
764884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * <br>
765f021758934b35e3b842c6799344531d7ea2969daChris Wren     * This class is a "rebuilder": It attaches to a Builder object and modifies its behavior, like so:
766f021758934b35e3b842c6799344531d7ea2969daChris Wren     * <pre class="prettyprint">
767f021758934b35e3b842c6799344531d7ea2969daChris Wren     * Notification noti = new Notification.Builder()
768f021758934b35e3b842c6799344531d7ea2969daChris Wren     *     .setContentTitle(&quot;5 New mails from &quot; + sender.toString())
769f021758934b35e3b842c6799344531d7ea2969daChris Wren     *     .setContentText(subject)
770f021758934b35e3b842c6799344531d7ea2969daChris Wren     *     .setSmallIcon(R.drawable.new_mail)
771f021758934b35e3b842c6799344531d7ea2969daChris Wren     *     .setLargeIcon(aBitmap)
772f021758934b35e3b842c6799344531d7ea2969daChris Wren     *     .setStyle(new Notification.InboxStyle()
773f021758934b35e3b842c6799344531d7ea2969daChris Wren     *         .addLine(str1)
774f021758934b35e3b842c6799344531d7ea2969daChris Wren     *         .addLine(str2)
775f021758934b35e3b842c6799344531d7ea2969daChris Wren     *         .setContentTitle(&quot;&quot;)
776f021758934b35e3b842c6799344531d7ea2969daChris Wren     *         .setSummaryText(&quot;+3 more&quot;))
777f021758934b35e3b842c6799344531d7ea2969daChris Wren     *     .build();
778f021758934b35e3b842c6799344531d7ea2969daChris Wren     * </pre>
779884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     *
780f021758934b35e3b842c6799344531d7ea2969daChris Wren     * @see Notification#bigContentView
781f021758934b35e3b842c6799344531d7ea2969daChris Wren     */
782f021758934b35e3b842c6799344531d7ea2969daChris Wren    public static class InboxStyle extends Style {
783f021758934b35e3b842c6799344531d7ea2969daChris Wren        ArrayList<CharSequence> mTexts = new ArrayList<CharSequence>();
784f021758934b35e3b842c6799344531d7ea2969daChris Wren
785f021758934b35e3b842c6799344531d7ea2969daChris Wren        public InboxStyle() {
786f021758934b35e3b842c6799344531d7ea2969daChris Wren        }
787f021758934b35e3b842c6799344531d7ea2969daChris Wren
788f021758934b35e3b842c6799344531d7ea2969daChris Wren        public InboxStyle(Builder builder) {
789f021758934b35e3b842c6799344531d7ea2969daChris Wren            setBuilder(builder);
790f021758934b35e3b842c6799344531d7ea2969daChris Wren        }
791f021758934b35e3b842c6799344531d7ea2969daChris Wren
792f021758934b35e3b842c6799344531d7ea2969daChris Wren        /**
793f021758934b35e3b842c6799344531d7ea2969daChris Wren         * Overrides ContentTitle in the big form of the template.
794f021758934b35e3b842c6799344531d7ea2969daChris Wren         * This defaults to the value passed to setContentTitle().
795f021758934b35e3b842c6799344531d7ea2969daChris Wren         */
796f021758934b35e3b842c6799344531d7ea2969daChris Wren        public InboxStyle setBigContentTitle(CharSequence title) {
797f021758934b35e3b842c6799344531d7ea2969daChris Wren            mBigContentTitle = title;
798f021758934b35e3b842c6799344531d7ea2969daChris Wren            return this;
799f021758934b35e3b842c6799344531d7ea2969daChris Wren        }
800f021758934b35e3b842c6799344531d7ea2969daChris Wren
801f021758934b35e3b842c6799344531d7ea2969daChris Wren        /**
802f021758934b35e3b842c6799344531d7ea2969daChris Wren         * Set the first line of text after the detail section in the big form of the template.
803f021758934b35e3b842c6799344531d7ea2969daChris Wren         */
804f021758934b35e3b842c6799344531d7ea2969daChris Wren        public InboxStyle setSummaryText(CharSequence cs) {
805f021758934b35e3b842c6799344531d7ea2969daChris Wren            mSummaryText = cs;
806f021758934b35e3b842c6799344531d7ea2969daChris Wren            mSummaryTextSet = true;
807f021758934b35e3b842c6799344531d7ea2969daChris Wren            return this;
808f021758934b35e3b842c6799344531d7ea2969daChris Wren        }
809f021758934b35e3b842c6799344531d7ea2969daChris Wren
810b41a213761ff07de2fcfdaf16790fdcca1a1ee1bChris Wren        /**
811b41a213761ff07de2fcfdaf16790fdcca1a1ee1bChris Wren         * Append a line to the digest section of the Inbox notification.
812b41a213761ff07de2fcfdaf16790fdcca1a1ee1bChris Wren         */
813f021758934b35e3b842c6799344531d7ea2969daChris Wren        public InboxStyle addLine(CharSequence cs) {
814f021758934b35e3b842c6799344531d7ea2969daChris Wren            mTexts.add(cs);
815f021758934b35e3b842c6799344531d7ea2969daChris Wren            return this;
816f021758934b35e3b842c6799344531d7ea2969daChris Wren        }
817f021758934b35e3b842c6799344531d7ea2969daChris Wren    }
818f021758934b35e3b842c6799344531d7ea2969daChris Wren
819f021758934b35e3b842c6799344531d7ea2969daChris Wren    public static class Action {
820f021758934b35e3b842c6799344531d7ea2969daChris Wren        public int icon;
821f021758934b35e3b842c6799344531d7ea2969daChris Wren        public CharSequence title;
822f021758934b35e3b842c6799344531d7ea2969daChris Wren        public PendingIntent actionIntent;
823f021758934b35e3b842c6799344531d7ea2969daChris Wren
824f021758934b35e3b842c6799344531d7ea2969daChris Wren        public Action(int icon_, CharSequence title_, PendingIntent intent_) {
825f021758934b35e3b842c6799344531d7ea2969daChris Wren            this.icon = icon_;
826f021758934b35e3b842c6799344531d7ea2969daChris Wren            this.title = title_;
827f021758934b35e3b842c6799344531d7ea2969daChris Wren            this.actionIntent = intent_;
828c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        }
829c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell    }
830c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell}
831