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