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,
143f021758934b35e3b842c6799344531d7ea2969daChris Wren                            style.mPicture);
144f021758934b35e3b842c6799344531d7ea2969daChris Wren                }
145f021758934b35e3b842c6799344531d7ea2969daChris Wren            }
146f021758934b35e3b842c6799344531d7ea2969daChris Wren            return(jbBuilder.build());
147f021758934b35e3b842c6799344531d7ea2969daChris Wren        }
148f021758934b35e3b842c6799344531d7ea2969daChris Wren    }
149f021758934b35e3b842c6799344531d7ea2969daChris Wren
150c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell    static {
151f021758934b35e3b842c6799344531d7ea2969daChris Wren        if (Build.VERSION.SDK_INT >= 16) {
152f021758934b35e3b842c6799344531d7ea2969daChris Wren            IMPL = new NotificationCompatImplJellybean();
153080df8ffb0920eccb300baa39180eb956a000a53Chris Wren        } else if (Build.VERSION.SDK_INT >= 14) {
154f021758934b35e3b842c6799344531d7ea2969daChris Wren            IMPL = new NotificationCompatImplIceCreamSandwich();
155f021758934b35e3b842c6799344531d7ea2969daChris Wren        } else if (Build.VERSION.SDK_INT >= 11) {
156c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            IMPL = new NotificationCompatImplHoneycomb();
157c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        } else {
158c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            IMPL = new NotificationCompatImplBase();
159c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        }
160c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell    }
161c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
162c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell    /**
163884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * Builder class for {@link NotificationCompat} objects.  Allows easier control over
164c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell     * all the flags, as well as help constructing the typical notification layouts.
165884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * <p>
166884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * On platform versions that don't offer expanded notifications, methods that depend on
167884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * expanded notifications have no effect.
168884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * </p>
169884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * <p>
170884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * For example, action buttons won't appear on platforms prior to Android 4.1. Action
171884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * buttons depend on expanded notifications, which are only available in Android 4.1
172884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * and later.
173884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * <p>
174884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * For this reason, you should always ensure that UI controls in a notification are also
175884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * available in an {@link android.app.Activity} in your app, and you should always start that
176884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * {@link android.app.Activity} when users click the notification. To do this, use the
177884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * {@link NotificationCompat.Builder#setContentIntent setContentIntent()}
178884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * method.
179884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * </p>
180884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     *
181c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell     */
182c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell    public static class Builder {
183c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        Context mContext;
184c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
185c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        CharSequence mContentTitle;
186c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        CharSequence mContentText;
187c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        PendingIntent mContentIntent;
188c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        PendingIntent mFullScreenIntent;
189c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        RemoteViews mTickerView;
190c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        Bitmap mLargeIcon;
191c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        CharSequence mContentInfo;
192c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        int mNumber;
193f021758934b35e3b842c6799344531d7ea2969daChris Wren        int mPriority;
194f021758934b35e3b842c6799344531d7ea2969daChris Wren        boolean mUseChronometer;
195f021758934b35e3b842c6799344531d7ea2969daChris Wren        Style mStyle;
196f021758934b35e3b842c6799344531d7ea2969daChris Wren        CharSequence mSubText;
197f021758934b35e3b842c6799344531d7ea2969daChris Wren        int mProgressMax;
198f021758934b35e3b842c6799344531d7ea2969daChris Wren        int mProgress;
199f021758934b35e3b842c6799344531d7ea2969daChris Wren        boolean mProgressIndeterminate;
200f021758934b35e3b842c6799344531d7ea2969daChris Wren        ArrayList<Action> mActions = new ArrayList<Action>();
201c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
202c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        Notification mNotification = new Notification();
203c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
204c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        /**
205c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * Constructor.
206c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         *
207c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * Automatically sets the when field to {@link System#currentTimeMillis()
208c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * System.currentTimeMillis()} and the audio stream to the
209c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * {@link Notification#STREAM_DEFAULT}.
210c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         *
211c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * @param context A {@link Context} that will be used to construct the
212c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         *      RemoteViews. The Context will not be held past the lifetime of this
213c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         *      Builder object.
214c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         */
215c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        public Builder(Context context) {
216c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mContext = context;
217c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
218c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            // Set defaults to match the defaults of a Notification
219c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mNotification.when = System.currentTimeMillis();
220c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mNotification.audioStreamType = Notification.STREAM_DEFAULT;
221f021758934b35e3b842c6799344531d7ea2969daChris Wren            mPriority = PRIORITY_DEFAULT;
222c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        }
223c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
224c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        /**
225c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * Set the time that the event occurred.  Notifications in the panel are
226c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * sorted by this time.
227c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         */
228c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        public Builder setWhen(long when) {
229c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mNotification.when = when;
230c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            return this;
231c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        }
232c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
233c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        /**
234f021758934b35e3b842c6799344531d7ea2969daChris Wren         * Show the {@link Notification#when} field as a stopwatch.
235884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin         *
236884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin         * Instead of presenting <code>when</code> as a timestamp, the notification will show an
237f021758934b35e3b842c6799344531d7ea2969daChris Wren         * automatically updating display of the minutes and seconds since <code>when</code>.
238f021758934b35e3b842c6799344531d7ea2969daChris Wren         *
239f021758934b35e3b842c6799344531d7ea2969daChris Wren         * Useful when showing an elapsed time (like an ongoing phone call).
240f021758934b35e3b842c6799344531d7ea2969daChris Wren         *
241f021758934b35e3b842c6799344531d7ea2969daChris Wren         * @see android.widget.Chronometer
242f021758934b35e3b842c6799344531d7ea2969daChris Wren         * @see Notification#when
243f021758934b35e3b842c6799344531d7ea2969daChris Wren         */
244f021758934b35e3b842c6799344531d7ea2969daChris Wren        public Builder setUsesChronometer(boolean b) {
245f021758934b35e3b842c6799344531d7ea2969daChris Wren            mUseChronometer = b;
246f021758934b35e3b842c6799344531d7ea2969daChris Wren            return this;
247f021758934b35e3b842c6799344531d7ea2969daChris Wren        }
248f021758934b35e3b842c6799344531d7ea2969daChris Wren
249f021758934b35e3b842c6799344531d7ea2969daChris Wren        /**
250c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * Set the small icon to use in the notification layouts.  Different classes of devices
251c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * may return different sizes.  See the UX guidelines for more information on how to
252c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * design these icons.
253c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         *
254c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * @param icon A resource ID in the application's package of the drawble to use.
255c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         */
256c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        public Builder setSmallIcon(int icon) {
257c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mNotification.icon = icon;
258c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            return this;
259c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        }
260c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
261c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        /**
262c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * A variant of {@link #setSmallIcon(int) setSmallIcon(int)} that takes an additional
263c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * level parameter for when the icon is a {@link android.graphics.drawable.LevelListDrawable
264c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * LevelListDrawable}.
265c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         *
266c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * @param icon A resource ID in the application's package of the drawble to use.
267c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * @param level The level to use for the icon.
268c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         *
269c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * @see android.graphics.drawable.LevelListDrawable
270c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         */
271c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        public Builder setSmallIcon(int icon, int level) {
272c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mNotification.icon = icon;
273c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mNotification.iconLevel = level;
274c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            return this;
275c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        }
276c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
277c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        /**
278c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * Set the title (first row) of the notification, in a standard notification.
279c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         */
280c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        public Builder setContentTitle(CharSequence title) {
281c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mContentTitle = title;
282c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            return this;
283c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        }
284c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
285c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        /**
286c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * Set the text (second row) of the notification, in a standard notification.
287c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         */
288c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        public Builder setContentText(CharSequence text) {
289c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mContentText = text;
290c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            return this;
291c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        }
292c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
293c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        /**
294884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin         * Set the third line of text in the platform notification template.
295f021758934b35e3b842c6799344531d7ea2969daChris Wren         * Don't use if you're also using {@link #setProgress(int, int, boolean)};
296f021758934b35e3b842c6799344531d7ea2969daChris Wren         * they occupy the same location in the standard template.
297884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin         * <br>
298884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin         * If the platform does not provide large-format notifications, this method has no effect.
299884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin         * The third line of text only appears in expanded view.
300884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin         * <br>
301f021758934b35e3b842c6799344531d7ea2969daChris Wren         */
302f021758934b35e3b842c6799344531d7ea2969daChris Wren        public Builder setSubText(CharSequence text) {
303f021758934b35e3b842c6799344531d7ea2969daChris Wren            mSubText = text;
304f021758934b35e3b842c6799344531d7ea2969daChris Wren            return this;
305f021758934b35e3b842c6799344531d7ea2969daChris Wren        }
306f021758934b35e3b842c6799344531d7ea2969daChris Wren
307f021758934b35e3b842c6799344531d7ea2969daChris Wren        /**
308c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * Set the large number at the right-hand side of the notification.  This is
309c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * equivalent to setContentInfo, although it might show the number in a different
310c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * font size for readability.
311c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         */
312c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        public Builder setNumber(int number) {
313c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mNumber = number;
314c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            return this;
315c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        }
316c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
317c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        /**
318c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * Set the large text at the right-hand side of the notification.
319c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         */
320c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        public Builder setContentInfo(CharSequence info) {
321c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mContentInfo = info;
322c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            return this;
323c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        }
324c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
325c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        /**
326c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * Set the progress this notification represents, which may be
327f021758934b35e3b842c6799344531d7ea2969daChris Wren         * represented as a {@link android.widget.ProgressBar}.
328c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         */
329c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        public Builder setProgress(int max, int progress, boolean indeterminate) {
330c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mProgressMax = max;
331c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mProgress = progress;
332c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mProgressIndeterminate = indeterminate;
333c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            return this;
334f021758934b35e3b842c6799344531d7ea2969daChris Wren        }
335c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
336c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        /**
337c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * Supply a custom RemoteViews to use instead of the standard one.
338c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         */
339c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        public Builder setContent(RemoteViews views) {
340c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mNotification.contentView = views;
341c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            return this;
342c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        }
343c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
344c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        /**
345c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * Supply a {@link PendingIntent} to send when the notification is clicked.
346c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * If you do not supply an intent, you can now add PendingIntents to individual
347c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * views to be launched when clicked by calling {@link RemoteViews#setOnClickPendingIntent
348c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * RemoteViews.setOnClickPendingIntent(int,PendingIntent)}.  Be sure to
349c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * read {@link Notification#contentIntent Notification.contentIntent} for
350c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * how to correctly use this.
351c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         */
352c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        public Builder setContentIntent(PendingIntent intent) {
353c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mContentIntent = intent;
354c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            return this;
355c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        }
356c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
357c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        /**
358c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * Supply a {@link PendingIntent} to send when the notification is cleared by the user
359c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * directly from the notification panel.  For example, this intent is sent when the user
360c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * clicks the "Clear all" button, or the individual "X" buttons on notifications.  This
361c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * intent is not sent when the application calls {@link NotificationManager#cancel
362c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * NotificationManager.cancel(int)}.
363c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         */
364c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        public Builder setDeleteIntent(PendingIntent intent) {
365c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mNotification.deleteIntent = intent;
366c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            return this;
367c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        }
368c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
369c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        /**
370c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * An intent to launch instead of posting the notification to the status bar.
371c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * Only for use with extremely high-priority notifications demanding the user's
372c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * <strong>immediate</strong> attention, such as an incoming phone call or
373c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * alarm clock that the user has explicitly set to a particular time.
374c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * If this facility is used for something else, please give the user an option
375c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * to turn it off and use a normal notification, as this can be extremely
376c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * disruptive.
377c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         *
378c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * @param intent The pending intent to launch.
379c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * @param highPriority Passing true will cause this notification to be sent
380c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         *          even if other notifications are suppressed.
381c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         */
382c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        public Builder setFullScreenIntent(PendingIntent intent, boolean highPriority) {
383c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mFullScreenIntent = intent;
384c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            setFlag(FLAG_HIGH_PRIORITY, highPriority);
385c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            return this;
386c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        }
387c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
388c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        /**
389c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * Set the text that is displayed in the status bar when the notification first
390c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * arrives.
391c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         */
392c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        public Builder setTicker(CharSequence tickerText) {
393c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mNotification.tickerText = tickerText;
394c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            return this;
395c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        }
396c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
397c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        /**
398c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * Set the text that is displayed in the status bar when the notification first
399c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * arrives, and also a RemoteViews object that may be displayed instead on some
400c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * devices.
401c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         */
402c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        public Builder setTicker(CharSequence tickerText, RemoteViews views) {
403c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mNotification.tickerText = tickerText;
404c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mTickerView = views;
405c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            return this;
406c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        }
407c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
408c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        /**
409c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * Set the large icon that is shown in the ticker and notification.
410c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         */
411c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        public Builder setLargeIcon(Bitmap icon) {
412c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mLargeIcon = icon;
413c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            return this;
414c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        }
415c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
416c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        /**
417c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * Set the sound to play.  It will play on the default stream.
418c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         */
419c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        public Builder setSound(Uri sound) {
420c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mNotification.sound = sound;
421c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mNotification.audioStreamType = Notification.STREAM_DEFAULT;
422c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            return this;
423c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        }
424c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
425c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        /**
426c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * Set the sound to play.  It will play on the stream you supply.
427c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         *
428c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * @see #STREAM_DEFAULT
429c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * @see AudioManager for the <code>STREAM_</code> constants.
430c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         */
431c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        public Builder setSound(Uri sound, int streamType) {
432c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mNotification.sound = sound;
433c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mNotification.audioStreamType = streamType;
434c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            return this;
435c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        }
436c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
437c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        /**
438c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * Set the vibration pattern to use.
439c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         *
440c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * @see android.os.Vibrator for a discussion of the <code>pattern</code>
441c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * parameter.
442c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         */
443c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        public Builder setVibrate(long[] pattern) {
444c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mNotification.vibrate = pattern;
445c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            return this;
446c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        }
447c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
448c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        /**
449c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * Set the argb value that you would like the LED on the device to blnk, as well as the
450c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * rate.  The rate is specified in terms of the number of milliseconds to be on
451c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * and then the number of milliseconds to be off.
452c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         */
453c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        public Builder setLights(int argb, int onMs, int offMs) {
454c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mNotification.ledARGB = argb;
455c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mNotification.ledOnMS = onMs;
456c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mNotification.ledOffMS = offMs;
457c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            boolean showLights = mNotification.ledOnMS != 0 && mNotification.ledOffMS != 0;
458c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mNotification.flags = (mNotification.flags & ~Notification.FLAG_SHOW_LIGHTS) |
459c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell                    (showLights ? Notification.FLAG_SHOW_LIGHTS : 0);
460c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            return this;
461c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        }
462c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
463c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        /**
464c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * Set whether this is an ongoing notification.
465c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         *
466c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * <p>Ongoing notifications differ from regular notifications in the following ways:
467c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * <ul>
468c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         *   <li>Ongoing notifications are sorted above the regular notifications in the
469c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         *   notification panel.</li>
470c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         *   <li>Ongoing notifications do not have an 'X' close button, and are not affected
471c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         *   by the "Clear all" button.
472c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * </ul>
473c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         */
474c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        public Builder setOngoing(boolean ongoing) {
475c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            setFlag(Notification.FLAG_ONGOING_EVENT, ongoing);
476c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            return this;
477c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        }
478c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
479c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        /**
480c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * Set this flag if you would only like the sound, vibrate
481c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * and ticker to be played if the notification is not already showing.
482c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         */
483c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        public Builder setOnlyAlertOnce(boolean onlyAlertOnce) {
484c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            setFlag(Notification.FLAG_ONLY_ALERT_ONCE, onlyAlertOnce);
485c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            return this;
486c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        }
487c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
488c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        /**
489c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * Setting this flag will make it so the notification is automatically
490c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * canceled when the user clicks it in the panel.  The PendingIntent
491c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * set with {@link #setDeleteIntent} will be broadcast when the notification
492c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * is canceled.
493c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         */
494c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        public Builder setAutoCancel(boolean autoCancel) {
495c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            setFlag(Notification.FLAG_AUTO_CANCEL, autoCancel);
496c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            return this;
497c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        }
498c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
499c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        /**
500c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * Set the default notification options that will be used.
501c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * <p>
502c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * The value should be one or more of the following fields combined with
503c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * bitwise-or:
504c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * {@link Notification#DEFAULT_SOUND}, {@link Notification#DEFAULT_VIBRATE},
505c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * {@link Notification#DEFAULT_LIGHTS}.
506c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * <p>
507c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * For all default values, use {@link Notification#DEFAULT_ALL}.
508c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         */
509c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        public Builder setDefaults(int defaults) {
510c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            mNotification.defaults = defaults;
511c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            if ((defaults & Notification.DEFAULT_LIGHTS) != 0) {
512c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell                mNotification.flags |= Notification.FLAG_SHOW_LIGHTS;
513c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            }
514c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            return this;
515c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        }
516c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
517c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        private void setFlag(int mask, boolean value) {
518c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            if (value) {
519c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell                mNotification.flags |= mask;
520c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            } else {
521c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell                mNotification.flags &= ~mask;
522c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell            }
523c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        }
524c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell
525c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        /**
526f021758934b35e3b842c6799344531d7ea2969daChris Wren         * Set the relative priority for this notification.
527884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin         *
528f021758934b35e3b842c6799344531d7ea2969daChris Wren         * Priority is an indication of how much of the user's
529f021758934b35e3b842c6799344531d7ea2969daChris Wren         * valuable attention should be consumed by this
530f021758934b35e3b842c6799344531d7ea2969daChris Wren         * notification. Low-priority notifications may be hidden from
531f021758934b35e3b842c6799344531d7ea2969daChris Wren         * the user in certain situations, while the user might be
532884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin         * interrupted for a higher-priority notification.
533884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin         * The system sets a notification's priority based on various factors including the
534884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin         * setPriority value. The effect may differ slightly on different platforms.
535f021758934b35e3b842c6799344531d7ea2969daChris Wren         */
536f021758934b35e3b842c6799344531d7ea2969daChris Wren        public Builder setPriority(int pri) {
537f021758934b35e3b842c6799344531d7ea2969daChris Wren            mPriority = pri;
538f021758934b35e3b842c6799344531d7ea2969daChris Wren            return this;
539f021758934b35e3b842c6799344531d7ea2969daChris Wren        }
540f021758934b35e3b842c6799344531d7ea2969daChris Wren
541f021758934b35e3b842c6799344531d7ea2969daChris Wren        /**
542f021758934b35e3b842c6799344531d7ea2969daChris Wren         * Add an action to this notification. Actions are typically displayed by
543f021758934b35e3b842c6799344531d7ea2969daChris Wren         * the system as a button adjacent to the notification content.
544884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin         * <br>
545884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin         * Action buttons won't appear on platforms prior to Android 4.1. Action
546884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin         * buttons depend on expanded notifications, which are only available in Android 4.1
547884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin         * and later. To ensure that an action button's functionality is always available, first
548884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin         * implement the functionality in the {@link android.app.Activity} that starts when a user
549884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin         * clicks the  notification (see {@link #setContentIntent setContentIntent()}), and then
550884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin         * enhance the notification by implementing the same functionality with
551884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin         * {@link #addAction addAction()}.
552f021758934b35e3b842c6799344531d7ea2969daChris Wren         *
553f021758934b35e3b842c6799344531d7ea2969daChris Wren         * @param icon Resource ID of a drawable that represents the action.
554f021758934b35e3b842c6799344531d7ea2969daChris Wren         * @param title Text describing the action.
555884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin         * @param intent {@link android.app.PendingIntent} to be fired when the action is invoked.
556f021758934b35e3b842c6799344531d7ea2969daChris Wren         */
557f021758934b35e3b842c6799344531d7ea2969daChris Wren        public Builder addAction(int icon, CharSequence title, PendingIntent intent) {
558f021758934b35e3b842c6799344531d7ea2969daChris Wren            mActions.add(new Action(icon, title, intent));
559f021758934b35e3b842c6799344531d7ea2969daChris Wren            return this;
560f021758934b35e3b842c6799344531d7ea2969daChris Wren        }
561f021758934b35e3b842c6799344531d7ea2969daChris Wren
562f021758934b35e3b842c6799344531d7ea2969daChris Wren        /**
563f021758934b35e3b842c6799344531d7ea2969daChris Wren         * Add a rich notification style to be applied at build time.
564884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin         * <br>
565884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin         * If the platform does not provide rich notification styles, this method has no effect. The
566884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin         * user will always see the normal notification style.
567f021758934b35e3b842c6799344531d7ea2969daChris Wren         *
568f021758934b35e3b842c6799344531d7ea2969daChris Wren         * @param style Object responsible for modifying the notification style.
569f021758934b35e3b842c6799344531d7ea2969daChris Wren         */
570f021758934b35e3b842c6799344531d7ea2969daChris Wren        public Builder setStyle(Style style) {
571f021758934b35e3b842c6799344531d7ea2969daChris Wren            if (mStyle != style) {
572f021758934b35e3b842c6799344531d7ea2969daChris Wren                mStyle = style;
573f021758934b35e3b842c6799344531d7ea2969daChris Wren                if (mStyle != null) {
574f021758934b35e3b842c6799344531d7ea2969daChris Wren                    mStyle.setBuilder(this);
575f021758934b35e3b842c6799344531d7ea2969daChris Wren                }
576f021758934b35e3b842c6799344531d7ea2969daChris Wren            }
577f021758934b35e3b842c6799344531d7ea2969daChris Wren            return this;
578f021758934b35e3b842c6799344531d7ea2969daChris Wren        }
579f021758934b35e3b842c6799344531d7ea2969daChris Wren
580f021758934b35e3b842c6799344531d7ea2969daChris Wren        /**
581f021758934b35e3b842c6799344531d7ea2969daChris Wren         * @deprecated Use {@link #build()} instead.
582f021758934b35e3b842c6799344531d7ea2969daChris Wren         */
583f021758934b35e3b842c6799344531d7ea2969daChris Wren        @Deprecated
584f021758934b35e3b842c6799344531d7ea2969daChris Wren        public Notification getNotification() {
585f021758934b35e3b842c6799344531d7ea2969daChris Wren            return (Notification) IMPL.build(this);
586f021758934b35e3b842c6799344531d7ea2969daChris Wren        }
587f021758934b35e3b842c6799344531d7ea2969daChris Wren
588f021758934b35e3b842c6799344531d7ea2969daChris Wren        /**
589c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * Combine all of the options that have been set and return a new {@link Notification}
590c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         * object.
591c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell         */
592f021758934b35e3b842c6799344531d7ea2969daChris Wren        public Notification build() {
593f021758934b35e3b842c6799344531d7ea2969daChris Wren            return (Notification) IMPL.build(this);
594f021758934b35e3b842c6799344531d7ea2969daChris Wren        }
595f021758934b35e3b842c6799344531d7ea2969daChris Wren    }
596f021758934b35e3b842c6799344531d7ea2969daChris Wren
597f021758934b35e3b842c6799344531d7ea2969daChris Wren    /**
598f021758934b35e3b842c6799344531d7ea2969daChris Wren     * An object that can apply a rich notification style to a {@link Notification.Builder}
599f021758934b35e3b842c6799344531d7ea2969daChris Wren     * object.
600884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * <br>
601884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * If the platform does not provide rich notification styles, methods in this class have no
602884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * effect.
603f021758934b35e3b842c6799344531d7ea2969daChris Wren     */
604f021758934b35e3b842c6799344531d7ea2969daChris Wren    public static abstract class Style
605f021758934b35e3b842c6799344531d7ea2969daChris Wren    {
606f021758934b35e3b842c6799344531d7ea2969daChris Wren        Builder mBuilder;
607f021758934b35e3b842c6799344531d7ea2969daChris Wren        CharSequence mBigContentTitle;
608f021758934b35e3b842c6799344531d7ea2969daChris Wren        CharSequence mSummaryText;
609f021758934b35e3b842c6799344531d7ea2969daChris Wren        boolean mSummaryTextSet = false;
610f021758934b35e3b842c6799344531d7ea2969daChris Wren
611f021758934b35e3b842c6799344531d7ea2969daChris Wren        public void setBuilder(Builder builder) {
612f021758934b35e3b842c6799344531d7ea2969daChris Wren            if (mBuilder != builder) {
613f021758934b35e3b842c6799344531d7ea2969daChris Wren                mBuilder = builder;
614f021758934b35e3b842c6799344531d7ea2969daChris Wren                if (mBuilder != null) {
615f021758934b35e3b842c6799344531d7ea2969daChris Wren                    mBuilder.setStyle(this);
616f021758934b35e3b842c6799344531d7ea2969daChris Wren                }
617f021758934b35e3b842c6799344531d7ea2969daChris Wren            }
618f021758934b35e3b842c6799344531d7ea2969daChris Wren        }
619f021758934b35e3b842c6799344531d7ea2969daChris Wren
620f021758934b35e3b842c6799344531d7ea2969daChris Wren        public Notification build() {
621f021758934b35e3b842c6799344531d7ea2969daChris Wren            Notification notification = null;
622f021758934b35e3b842c6799344531d7ea2969daChris Wren            if (mBuilder != null) {
623f021758934b35e3b842c6799344531d7ea2969daChris Wren                notification = mBuilder.build();
624884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin            }
625f021758934b35e3b842c6799344531d7ea2969daChris Wren            return notification;
626f021758934b35e3b842c6799344531d7ea2969daChris Wren        }
627f021758934b35e3b842c6799344531d7ea2969daChris Wren    }
628f021758934b35e3b842c6799344531d7ea2969daChris Wren
629f021758934b35e3b842c6799344531d7ea2969daChris Wren    /**
630f021758934b35e3b842c6799344531d7ea2969daChris Wren     * Helper class for generating large-format notifications that include a large image attachment.
631884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * <br>
632884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * If the platform does not provide large-format notifications, this method has no effect. The
633884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * user will always see the normal notification view.
634884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * <br>
635f021758934b35e3b842c6799344531d7ea2969daChris Wren     * This class is a "rebuilder": It attaches to a Builder object and modifies its behavior, like so:
636f021758934b35e3b842c6799344531d7ea2969daChris Wren     * <pre class="prettyprint">
637f021758934b35e3b842c6799344531d7ea2969daChris Wren     * Notification noti = new Notification.Builder()
638f021758934b35e3b842c6799344531d7ea2969daChris Wren     *     .setContentTitle(&quot;New photo from &quot; + sender.toString())
639f021758934b35e3b842c6799344531d7ea2969daChris Wren     *     .setContentText(subject)
640f021758934b35e3b842c6799344531d7ea2969daChris Wren     *     .setSmallIcon(R.drawable.new_post)
641f021758934b35e3b842c6799344531d7ea2969daChris Wren     *     .setLargeIcon(aBitmap)
642f021758934b35e3b842c6799344531d7ea2969daChris Wren     *     .setStyle(new Notification.BigPictureStyle()
643f021758934b35e3b842c6799344531d7ea2969daChris Wren     *         .bigPicture(aBigBitmap))
644f021758934b35e3b842c6799344531d7ea2969daChris Wren     *     .build();
645f021758934b35e3b842c6799344531d7ea2969daChris Wren     * </pre>
646884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     *
647f021758934b35e3b842c6799344531d7ea2969daChris Wren     * @see Notification#bigContentView
648f021758934b35e3b842c6799344531d7ea2969daChris Wren     */
649f021758934b35e3b842c6799344531d7ea2969daChris Wren    public static class BigPictureStyle extends Style {
650f021758934b35e3b842c6799344531d7ea2969daChris Wren        Bitmap mPicture;
651f021758934b35e3b842c6799344531d7ea2969daChris Wren
652f021758934b35e3b842c6799344531d7ea2969daChris Wren        public BigPictureStyle() {
653f021758934b35e3b842c6799344531d7ea2969daChris Wren        }
654f021758934b35e3b842c6799344531d7ea2969daChris Wren
655f021758934b35e3b842c6799344531d7ea2969daChris Wren        public BigPictureStyle(Builder builder) {
656f021758934b35e3b842c6799344531d7ea2969daChris Wren            setBuilder(builder);
657f021758934b35e3b842c6799344531d7ea2969daChris Wren        }
658f021758934b35e3b842c6799344531d7ea2969daChris Wren
659f021758934b35e3b842c6799344531d7ea2969daChris Wren        /**
660f021758934b35e3b842c6799344531d7ea2969daChris Wren         * Overrides ContentTitle in the big form of the template.
661f021758934b35e3b842c6799344531d7ea2969daChris Wren         * This defaults to the value passed to setContentTitle().
662f021758934b35e3b842c6799344531d7ea2969daChris Wren         */
663f021758934b35e3b842c6799344531d7ea2969daChris Wren        public BigPictureStyle setBigContentTitle(CharSequence title) {
664f021758934b35e3b842c6799344531d7ea2969daChris Wren            mBigContentTitle = title;
665f021758934b35e3b842c6799344531d7ea2969daChris Wren            return this;
666f021758934b35e3b842c6799344531d7ea2969daChris Wren        }
667f021758934b35e3b842c6799344531d7ea2969daChris Wren
668f021758934b35e3b842c6799344531d7ea2969daChris Wren        /**
669f021758934b35e3b842c6799344531d7ea2969daChris Wren         * Set the first line of text after the detail section in the big form of the template.
670f021758934b35e3b842c6799344531d7ea2969daChris Wren         */
671f021758934b35e3b842c6799344531d7ea2969daChris Wren        public BigPictureStyle setSummaryText(CharSequence cs) {
672f021758934b35e3b842c6799344531d7ea2969daChris Wren            mSummaryText = cs;
673f021758934b35e3b842c6799344531d7ea2969daChris Wren            mSummaryTextSet = true;
674f021758934b35e3b842c6799344531d7ea2969daChris Wren            return this;
675f021758934b35e3b842c6799344531d7ea2969daChris Wren        }
676f021758934b35e3b842c6799344531d7ea2969daChris Wren
677b41a213761ff07de2fcfdaf16790fdcca1a1ee1bChris Wren        /**
678b41a213761ff07de2fcfdaf16790fdcca1a1ee1bChris Wren         * Provide the bitmap to be used as the payload for the BigPicture notification.
679b41a213761ff07de2fcfdaf16790fdcca1a1ee1bChris Wren         */
680f021758934b35e3b842c6799344531d7ea2969daChris Wren        public BigPictureStyle bigPicture(Bitmap b) {
681f021758934b35e3b842c6799344531d7ea2969daChris Wren            mPicture = b;
682f021758934b35e3b842c6799344531d7ea2969daChris Wren            return this;
683f021758934b35e3b842c6799344531d7ea2969daChris Wren        }
684f021758934b35e3b842c6799344531d7ea2969daChris Wren    }
685f021758934b35e3b842c6799344531d7ea2969daChris Wren
686f021758934b35e3b842c6799344531d7ea2969daChris Wren    /**
687f021758934b35e3b842c6799344531d7ea2969daChris Wren     * Helper class for generating large-format notifications that include a lot of text.
688884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     *
689884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * <br>
690884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * If the platform does not provide large-format notifications, this method has no effect. The
691884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * user will always see the normal notification view.
692884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * <br>
693f021758934b35e3b842c6799344531d7ea2969daChris Wren     * This class is a "rebuilder": It attaches to a Builder object and modifies its behavior, like so:
694f021758934b35e3b842c6799344531d7ea2969daChris Wren     * <pre class="prettyprint">
695f021758934b35e3b842c6799344531d7ea2969daChris Wren     * Notification noti = new Notification.Builder()
696f021758934b35e3b842c6799344531d7ea2969daChris Wren     *     .setContentTitle(&quot;New mail from &quot; + sender.toString())
697f021758934b35e3b842c6799344531d7ea2969daChris Wren     *     .setContentText(subject)
698f021758934b35e3b842c6799344531d7ea2969daChris Wren     *     .setSmallIcon(R.drawable.new_mail)
699f021758934b35e3b842c6799344531d7ea2969daChris Wren     *     .setLargeIcon(aBitmap)
700f021758934b35e3b842c6799344531d7ea2969daChris Wren     *     .setStyle(new Notification.BigTextStyle()
701f021758934b35e3b842c6799344531d7ea2969daChris Wren     *         .bigText(aVeryLongString))
702f021758934b35e3b842c6799344531d7ea2969daChris Wren     *     .build();
703f021758934b35e3b842c6799344531d7ea2969daChris Wren     * </pre>
704884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     *
705f021758934b35e3b842c6799344531d7ea2969daChris Wren     * @see Notification#bigContentView
706f021758934b35e3b842c6799344531d7ea2969daChris Wren     */
707f021758934b35e3b842c6799344531d7ea2969daChris Wren    public static class BigTextStyle extends Style {
708f021758934b35e3b842c6799344531d7ea2969daChris Wren        CharSequence mBigText;
709f021758934b35e3b842c6799344531d7ea2969daChris Wren
710f021758934b35e3b842c6799344531d7ea2969daChris Wren        public BigTextStyle() {
711f021758934b35e3b842c6799344531d7ea2969daChris Wren        }
712f021758934b35e3b842c6799344531d7ea2969daChris Wren
713f021758934b35e3b842c6799344531d7ea2969daChris Wren        public BigTextStyle(Builder builder) {
714f021758934b35e3b842c6799344531d7ea2969daChris Wren            setBuilder(builder);
715f021758934b35e3b842c6799344531d7ea2969daChris Wren        }
716f021758934b35e3b842c6799344531d7ea2969daChris Wren
717f021758934b35e3b842c6799344531d7ea2969daChris Wren        /**
718f021758934b35e3b842c6799344531d7ea2969daChris Wren         * Overrides ContentTitle in the big form of the template.
719f021758934b35e3b842c6799344531d7ea2969daChris Wren         * This defaults to the value passed to setContentTitle().
720f021758934b35e3b842c6799344531d7ea2969daChris Wren         */
721f021758934b35e3b842c6799344531d7ea2969daChris Wren        public BigTextStyle setBigContentTitle(CharSequence title) {
722f021758934b35e3b842c6799344531d7ea2969daChris Wren            mBigContentTitle = title;
723f021758934b35e3b842c6799344531d7ea2969daChris Wren            return this;
724f021758934b35e3b842c6799344531d7ea2969daChris Wren        }
725f021758934b35e3b842c6799344531d7ea2969daChris Wren
726f021758934b35e3b842c6799344531d7ea2969daChris Wren        /**
727f021758934b35e3b842c6799344531d7ea2969daChris Wren         * Set the first line of text after the detail section in the big form of the template.
728f021758934b35e3b842c6799344531d7ea2969daChris Wren         */
729f021758934b35e3b842c6799344531d7ea2969daChris Wren        public BigTextStyle setSummaryText(CharSequence cs) {
730f021758934b35e3b842c6799344531d7ea2969daChris Wren            mSummaryText = cs;
731f021758934b35e3b842c6799344531d7ea2969daChris Wren            mSummaryTextSet = true;
732f021758934b35e3b842c6799344531d7ea2969daChris Wren            return this;
733f021758934b35e3b842c6799344531d7ea2969daChris Wren        }
734f021758934b35e3b842c6799344531d7ea2969daChris Wren
735b41a213761ff07de2fcfdaf16790fdcca1a1ee1bChris Wren        /**
736b41a213761ff07de2fcfdaf16790fdcca1a1ee1bChris Wren         * Provide the longer text to be displayed in the big form of the
737b41a213761ff07de2fcfdaf16790fdcca1a1ee1bChris Wren         * template in place of the content text.
738b41a213761ff07de2fcfdaf16790fdcca1a1ee1bChris Wren         */
739f021758934b35e3b842c6799344531d7ea2969daChris Wren        public BigTextStyle bigText(CharSequence cs) {
740f021758934b35e3b842c6799344531d7ea2969daChris Wren            mBigText = cs;
741f021758934b35e3b842c6799344531d7ea2969daChris Wren            return this;
742f021758934b35e3b842c6799344531d7ea2969daChris Wren        }
743f021758934b35e3b842c6799344531d7ea2969daChris Wren    }
744f021758934b35e3b842c6799344531d7ea2969daChris Wren
745f021758934b35e3b842c6799344531d7ea2969daChris Wren    /**
746f021758934b35e3b842c6799344531d7ea2969daChris Wren     * Helper class for generating large-format notifications that include a list of (up to 5) strings.
747884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     *
748884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * <br>
749884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * If the platform does not provide large-format notifications, this method has no effect. The
750884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * user will always see the normal notification view.
751884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     * <br>
752f021758934b35e3b842c6799344531d7ea2969daChris Wren     * This class is a "rebuilder": It attaches to a Builder object and modifies its behavior, like so:
753f021758934b35e3b842c6799344531d7ea2969daChris Wren     * <pre class="prettyprint">
754f021758934b35e3b842c6799344531d7ea2969daChris Wren     * Notification noti = new Notification.Builder()
755f021758934b35e3b842c6799344531d7ea2969daChris Wren     *     .setContentTitle(&quot;5 New mails from &quot; + sender.toString())
756f021758934b35e3b842c6799344531d7ea2969daChris Wren     *     .setContentText(subject)
757f021758934b35e3b842c6799344531d7ea2969daChris Wren     *     .setSmallIcon(R.drawable.new_mail)
758f021758934b35e3b842c6799344531d7ea2969daChris Wren     *     .setLargeIcon(aBitmap)
759f021758934b35e3b842c6799344531d7ea2969daChris Wren     *     .setStyle(new Notification.InboxStyle()
760f021758934b35e3b842c6799344531d7ea2969daChris Wren     *         .addLine(str1)
761f021758934b35e3b842c6799344531d7ea2969daChris Wren     *         .addLine(str2)
762f021758934b35e3b842c6799344531d7ea2969daChris Wren     *         .setContentTitle(&quot;&quot;)
763f021758934b35e3b842c6799344531d7ea2969daChris Wren     *         .setSummaryText(&quot;+3 more&quot;))
764f021758934b35e3b842c6799344531d7ea2969daChris Wren     *     .build();
765f021758934b35e3b842c6799344531d7ea2969daChris Wren     * </pre>
766884c97b0015a71381bc2a534438b2a0e7e7abd6aJoe Malin     *
767f021758934b35e3b842c6799344531d7ea2969daChris Wren     * @see Notification#bigContentView
768f021758934b35e3b842c6799344531d7ea2969daChris Wren     */
769f021758934b35e3b842c6799344531d7ea2969daChris Wren    public static class InboxStyle extends Style {
770f021758934b35e3b842c6799344531d7ea2969daChris Wren        ArrayList<CharSequence> mTexts = new ArrayList<CharSequence>();
771f021758934b35e3b842c6799344531d7ea2969daChris Wren
772f021758934b35e3b842c6799344531d7ea2969daChris Wren        public InboxStyle() {
773f021758934b35e3b842c6799344531d7ea2969daChris Wren        }
774f021758934b35e3b842c6799344531d7ea2969daChris Wren
775f021758934b35e3b842c6799344531d7ea2969daChris Wren        public InboxStyle(Builder builder) {
776f021758934b35e3b842c6799344531d7ea2969daChris Wren            setBuilder(builder);
777f021758934b35e3b842c6799344531d7ea2969daChris Wren        }
778f021758934b35e3b842c6799344531d7ea2969daChris Wren
779f021758934b35e3b842c6799344531d7ea2969daChris Wren        /**
780f021758934b35e3b842c6799344531d7ea2969daChris Wren         * Overrides ContentTitle in the big form of the template.
781f021758934b35e3b842c6799344531d7ea2969daChris Wren         * This defaults to the value passed to setContentTitle().
782f021758934b35e3b842c6799344531d7ea2969daChris Wren         */
783f021758934b35e3b842c6799344531d7ea2969daChris Wren        public InboxStyle setBigContentTitle(CharSequence title) {
784f021758934b35e3b842c6799344531d7ea2969daChris Wren            mBigContentTitle = title;
785f021758934b35e3b842c6799344531d7ea2969daChris Wren            return this;
786f021758934b35e3b842c6799344531d7ea2969daChris Wren        }
787f021758934b35e3b842c6799344531d7ea2969daChris Wren
788f021758934b35e3b842c6799344531d7ea2969daChris Wren        /**
789f021758934b35e3b842c6799344531d7ea2969daChris Wren         * Set the first line of text after the detail section in the big form of the template.
790f021758934b35e3b842c6799344531d7ea2969daChris Wren         */
791f021758934b35e3b842c6799344531d7ea2969daChris Wren        public InboxStyle setSummaryText(CharSequence cs) {
792f021758934b35e3b842c6799344531d7ea2969daChris Wren            mSummaryText = cs;
793f021758934b35e3b842c6799344531d7ea2969daChris Wren            mSummaryTextSet = true;
794f021758934b35e3b842c6799344531d7ea2969daChris Wren            return this;
795f021758934b35e3b842c6799344531d7ea2969daChris Wren        }
796f021758934b35e3b842c6799344531d7ea2969daChris Wren
797b41a213761ff07de2fcfdaf16790fdcca1a1ee1bChris Wren        /**
798b41a213761ff07de2fcfdaf16790fdcca1a1ee1bChris Wren         * Append a line to the digest section of the Inbox notification.
799b41a213761ff07de2fcfdaf16790fdcca1a1ee1bChris Wren         */
800f021758934b35e3b842c6799344531d7ea2969daChris Wren        public InboxStyle addLine(CharSequence cs) {
801f021758934b35e3b842c6799344531d7ea2969daChris Wren            mTexts.add(cs);
802f021758934b35e3b842c6799344531d7ea2969daChris Wren            return this;
803f021758934b35e3b842c6799344531d7ea2969daChris Wren        }
804f021758934b35e3b842c6799344531d7ea2969daChris Wren    }
805f021758934b35e3b842c6799344531d7ea2969daChris Wren
806f021758934b35e3b842c6799344531d7ea2969daChris Wren    public static class Action {
807f021758934b35e3b842c6799344531d7ea2969daChris Wren        public int icon;
808f021758934b35e3b842c6799344531d7ea2969daChris Wren        public CharSequence title;
809f021758934b35e3b842c6799344531d7ea2969daChris Wren        public PendingIntent actionIntent;
810f021758934b35e3b842c6799344531d7ea2969daChris Wren
811f021758934b35e3b842c6799344531d7ea2969daChris Wren        public Action(int icon_, CharSequence title_, PendingIntent intent_) {
812f021758934b35e3b842c6799344531d7ea2969daChris Wren            this.icon = icon_;
813f021758934b35e3b842c6799344531d7ea2969daChris Wren            this.title = title_;
814f021758934b35e3b842c6799344531d7ea2969daChris Wren            this.actionIntent = intent_;
815c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell        }
816c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell    }
817c9cf2eb0a9b6694d0fda3dbc313844955db60820Adam Powell}
818