| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.app; |
| 18 |
|
| 19 |
import static android.annotation.Dimension.DP; |
| 20 |
import static android.app.admin.DevicePolicyResources.Drawables.Source.NOTIFICATION; |
| 21 |
import static android.app.admin.DevicePolicyResources.Drawables.Style.SOLID_COLORED; |
| 22 |
import static android.app.admin.DevicePolicyResources.Drawables.WORK_PROFILE_ICON; |
| 23 |
import static android.app.admin.DevicePolicyResources.UNDEFINED; |
| 24 |
import static android.graphics.drawable.Icon.TYPE_URI; |
| 25 |
import static android.graphics.drawable.Icon.TYPE_URI_ADAPTIVE_BITMAP; |
| 26 |
|
| 27 |
import static java.util.Objects.requireNonNull; |
| 28 |
|
| 29 |
import android.annotation.ColorInt; |
| 30 |
import android.annotation.ColorRes; |
| 31 |
import android.annotation.DimenRes; |
| 32 |
import android.annotation.Dimension; |
| 33 |
import android.annotation.DrawableRes; |
| 34 |
import android.annotation.IdRes; |
| 35 |
import android.annotation.IntDef; |
| 36 |
import android.annotation.NonNull; |
| 37 |
import android.annotation.Nullable; |
| 38 |
import android.annotation.RequiresPermission; |
| 39 |
import android.annotation.SdkConstant; |
| 40 |
import android.annotation.SdkConstant.SdkConstantType; |
| 41 |
import android.annotation.StringRes; |
| 42 |
import android.annotation.StyleableRes; |
| 43 |
import android.annotation.SuppressLint; |
| 44 |
import android.annotation.SystemApi; |
| 45 |
import android.annotation.TestApi; |
| 46 |
import android.app.admin.DevicePolicyManager; |
| 47 |
import android.compat.annotation.UnsupportedAppUsage; |
| 48 |
import android.content.Context; |
| 49 |
import android.content.Intent; |
| 50 |
import android.content.LocusId; |
| 51 |
import android.content.pm.ApplicationInfo; |
| 52 |
import android.content.pm.PackageManager; |
| 53 |
import android.content.pm.PackageManager.NameNotFoundException; |
| 54 |
import android.content.pm.ShortcutInfo; |
| 55 |
import android.content.res.ColorStateList; |
| 56 |
import android.content.res.Configuration; |
| 57 |
import android.content.res.Resources; |
| 58 |
import android.content.res.TypedArray; |
| 59 |
import android.graphics.Bitmap; |
| 60 |
import android.graphics.Canvas; |
| 61 |
import android.graphics.Color; |
| 62 |
import android.graphics.PorterDuff; |
| 63 |
import android.graphics.drawable.Drawable; |
| 64 |
import android.graphics.drawable.Icon; |
| 65 |
import android.media.AudioAttributes; |
| 66 |
import android.media.AudioManager; |
| 67 |
import android.media.PlayerBase; |
| 68 |
import android.media.session.MediaSession; |
| 69 |
import android.net.Uri; |
| 70 |
import android.os.BadParcelableException; |
| 71 |
import android.os.Build; |
| 72 |
import android.os.Bundle; |
| 73 |
import android.os.IBinder; |
| 74 |
import android.os.Parcel; |
| 75 |
import android.os.Parcelable; |
| 76 |
import android.os.SystemClock; |
| 77 |
import android.os.SystemProperties; |
| 78 |
import android.os.UserHandle; |
| 79 |
import android.os.UserManager; |
| 80 |
import android.provider.Settings; |
| 81 |
import android.text.BidiFormatter; |
| 82 |
import android.text.SpannableStringBuilder; |
| 83 |
import android.text.Spanned; |
| 84 |
import android.text.TextUtils; |
| 85 |
import android.text.style.AbsoluteSizeSpan; |
| 86 |
import android.text.style.CharacterStyle; |
| 87 |
import android.text.style.ForegroundColorSpan; |
| 88 |
import android.text.style.RelativeSizeSpan; |
| 89 |
import android.text.style.TextAppearanceSpan; |
| 90 |
import android.util.ArraySet; |
| 91 |
import android.util.Log; |
| 92 |
import android.util.Pair; |
| 93 |
import android.util.SparseArray; |
| 94 |
import android.util.TypedValue; |
| 95 |
import android.util.proto.ProtoOutputStream; |
| 96 |
import android.view.ContextThemeWrapper; |
| 97 |
import android.view.Gravity; |
| 98 |
import android.view.View; |
| 99 |
import android.view.contentcapture.ContentCaptureContext; |
| 100 |
import android.widget.ProgressBar; |
| 101 |
import android.widget.RemoteViews; |
| 102 |
|
| 103 |
import com.android.internal.R; |
| 104 |
import com.android.internal.annotations.VisibleForTesting; |
| 105 |
import com.android.internal.graphics.ColorUtils; |
| 106 |
import com.android.internal.util.ArrayUtils; |
| 107 |
import com.android.internal.util.ContrastColorUtil; |
| 108 |
|
| 109 |
import java.lang.annotation.Retention; |
| 110 |
import java.lang.annotation.RetentionPolicy; |
| 111 |
import java.lang.reflect.Array; |
| 112 |
import java.lang.reflect.Constructor; |
| 113 |
import java.util.ArrayList; |
| 114 |
import java.util.Arrays; |
| 115 |
import java.util.Collections; |
| 116 |
import java.util.List; |
| 117 |
import java.util.Objects; |
| 118 |
import java.util.Set; |
| 119 |
import java.util.function.Consumer; |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
public class Notification implements Parcelable |
| 136 |
{ |
| 137 |
private static final String TAG = "Notification"; |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
@Retention(RetentionPolicy.SOURCE) |
| 143 |
@IntDef({ |
| 144 |
FOREGROUND_SERVICE_DEFAULT, |
| 145 |
FOREGROUND_SERVICE_IMMEDIATE, |
| 146 |
FOREGROUND_SERVICE_DEFERRED |
| 147 |
}) |
| 148 |
public @interface ServiceNotificationPolicy {}; |
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
public static final @ServiceNotificationPolicy int FOREGROUND_SERVICE_DEFAULT = 0; |
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
public static final @ServiceNotificationPolicy int FOREGROUND_SERVICE_IMMEDIATE = 1; |
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
public static final @ServiceNotificationPolicy int FOREGROUND_SERVICE_DEFERRED = 2; |
| 182 |
|
| 183 |
@ServiceNotificationPolicy |
| 184 |
private int mFgsDeferBehavior; |
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
@SdkConstant(SdkConstantType.INTENT_CATEGORY) |
| 191 |
public static final String INTENT_CATEGORY_NOTIFICATION_PREFERENCES |
| 192 |
= "android.intent.category.NOTIFICATION_PREFERENCES"; |
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
public static final String EXTRA_CHANNEL_ID = "android.intent.extra.CHANNEL_ID"; |
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
public static final String EXTRA_CHANNEL_GROUP_ID = "android.intent.extra.CHANNEL_GROUP_ID"; |
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
public static final String EXTRA_NOTIFICATION_TAG = "android.intent.extra.NOTIFICATION_TAG"; |
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
public static final String EXTRA_NOTIFICATION_ID = "android.intent.extra.NOTIFICATION_ID"; |
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
public static final int DEFAULT_ALL = ~0; |
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
public static final int DEFAULT_SOUND = 1; |
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
public static final int DEFAULT_VIBRATE = 2; |
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
public static final int DEFAULT_LIGHTS = 4; |
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
private static final int MAX_CHARSEQUENCE_LENGTH = 1024; |
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
private static final int MAX_REPLY_HISTORY = 5; |
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
private static final float MAX_LARGE_ICON_ASPECT_RATIO = 16f / 9f; |
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
public static final int MAX_ACTION_BUTTONS = 3; |
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
public static final String EXTRA_REMOTE_INPUT_DRAFT = "android.remoteInputDraft"; |
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
public long when; |
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
private long creationTime; |
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
@Deprecated |
| 336 |
@DrawableRes |
| 337 |
public int icon; |
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
public int iconLevel; |
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
public int number = 0; |
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
public PendingIntent contentIntent; |
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
public PendingIntent deleteIntent; |
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
public PendingIntent fullScreenIntent; |
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
public CharSequence tickerText; |
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
@Deprecated |
| 409 |
public RemoteViews tickerView; |
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
@Deprecated |
| 420 |
public RemoteViews contentView; |
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
@Deprecated |
| 432 |
public RemoteViews bigContentView; |
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
@Deprecated |
| 446 |
public RemoteViews headsUpContentView; |
| 447 |
|
| 448 |
private boolean mUsesStandardHeader; |
| 449 |
|
| 450 |
private static final ArraySet<Integer> STANDARD_LAYOUTS = new ArraySet<>(); |
| 451 |
static { |
| 452 |
STANDARD_LAYOUTS.add(R.layout.notification_template_material_base); |
| 453 |
STANDARD_LAYOUTS.add(R.layout.notification_template_material_heads_up_base); |
| 454 |
STANDARD_LAYOUTS.add(R.layout.notification_template_material_big_base); |
| 455 |
STANDARD_LAYOUTS.add(R.layout.notification_template_material_big_picture); |
| 456 |
STANDARD_LAYOUTS.add(R.layout.notification_template_material_big_text); |
| 457 |
STANDARD_LAYOUTS.add(R.layout.notification_template_material_inbox); |
| 458 |
STANDARD_LAYOUTS.add(R.layout.notification_template_material_messaging); |
| 459 |
STANDARD_LAYOUTS.add(R.layout.notification_template_material_big_messaging); |
| 460 |
STANDARD_LAYOUTS.add(R.layout.notification_template_material_conversation); |
| 461 |
STANDARD_LAYOUTS.add(R.layout.notification_template_material_media); |
| 462 |
STANDARD_LAYOUTS.add(R.layout.notification_template_material_big_media); |
| 463 |
STANDARD_LAYOUTS.add(R.layout.notification_template_material_call); |
| 464 |
STANDARD_LAYOUTS.add(R.layout.notification_template_material_big_call); |
| 465 |
STANDARD_LAYOUTS.add(R.layout.notification_template_header); |
| 466 |
} |
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
@Deprecated |
| 474 |
public Bitmap largeIcon; |
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
@Deprecated |
| 489 |
public Uri sound; |
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
@Deprecated |
| 499 |
public static final int STREAM_DEFAULT = -1; |
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
@Deprecated |
| 509 |
public int audioStreamType = STREAM_DEFAULT; |
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
public static final AudioAttributes AUDIO_ATTRIBUTES_DEFAULT = new AudioAttributes.Builder() |
| 515 |
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) |
| 516 |
.setUsage(AudioAttributes.USAGE_NOTIFICATION) |
| 517 |
.build(); |
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
@Deprecated |
| 525 |
public AudioAttributes audioAttributes = AUDIO_ATTRIBUTES_DEFAULT; |
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
@Deprecated |
| 538 |
public long[] vibrate; |
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
@ColorInt |
| 548 |
@Deprecated |
| 549 |
public int ledARGB; |
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
@Deprecated |
| 560 |
public int ledOnMS; |
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
@Deprecated |
| 572 |
public int ledOffMS; |
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
@Deprecated |
| 587 |
public int defaults; |
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
@Deprecated |
| 609 |
public static final int FLAG_SHOW_LIGHTS = 0x00000001; |
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
public static final int FLAG_ONGOING_EVENT = 0x00000002; |
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
public static final int FLAG_INSISTENT = 0x00000004; |
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
public static final int FLAG_ONLY_ALERT_ONCE = 0x00000008; |
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
public static final int FLAG_AUTO_CANCEL = 0x00000010; |
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
public static final int FLAG_NO_CLEAR = 0x00000020; |
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
public static final int FLAG_FOREGROUND_SERVICE = 0x00000040; |
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
@Deprecated |
| 664 |
public static final int FLAG_HIGH_PRIORITY = 0x00000080; |
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
public static final int FLAG_LOCAL_ONLY = 0x00000100; |
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
public static final int FLAG_GROUP_SUMMARY = 0x00000200; |
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
@SystemApi |
| 688 |
public static final int FLAG_AUTOGROUP_SUMMARY = 0x00000400; |
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
public static final int FLAG_CAN_COLORIZE = 0x00000800; |
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
public static final int FLAG_BUBBLE = 0x00001000; |
| 705 |
|
| 706 |
private static final List<Class<? extends Style>> PLATFORM_STYLE_CLASSES = Arrays.asList( |
| 707 |
BigTextStyle.class, BigPictureStyle.class, InboxStyle.class, MediaStyle.class, |
| 708 |
DecoratedCustomViewStyle.class, DecoratedMediaCustomViewStyle.class, |
| 709 |
MessagingStyle.class, CallStyle.class); |
| 710 |
|
| 711 |
|
| 712 |
@IntDef(flag = true, prefix = { "FLAG_" }, value = {FLAG_SHOW_LIGHTS, FLAG_ONGOING_EVENT, |
| 713 |
FLAG_INSISTENT, FLAG_ONLY_ALERT_ONCE, |
| 714 |
FLAG_AUTO_CANCEL, FLAG_NO_CLEAR, FLAG_FOREGROUND_SERVICE, FLAG_HIGH_PRIORITY, |
| 715 |
FLAG_LOCAL_ONLY, FLAG_GROUP_SUMMARY, FLAG_AUTOGROUP_SUMMARY, FLAG_BUBBLE}) |
| 716 |
@Retention(RetentionPolicy.SOURCE) |
| 717 |
public @interface NotificationFlags{}; |
| 718 |
|
| 719 |
public int flags; |
| 720 |
|
| 721 |
|
| 722 |
@IntDef(prefix = { "PRIORITY_" }, value = { |
| 723 |
PRIORITY_DEFAULT, |
| 724 |
PRIORITY_LOW, |
| 725 |
PRIORITY_MIN, |
| 726 |
PRIORITY_HIGH, |
| 727 |
PRIORITY_MAX |
| 728 |
}) |
| 729 |
@Retention(RetentionPolicy.SOURCE) |
| 730 |
public @interface Priority {} |
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
@Deprecated |
| 739 |
public static final int PRIORITY_DEFAULT = 0; |
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
@Deprecated |
| 749 |
public static final int PRIORITY_LOW = -1; |
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
@Deprecated |
| 758 |
public static final int PRIORITY_MIN = -2; |
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
@Deprecated |
| 768 |
public static final int PRIORITY_HIGH = 1; |
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
@Deprecated |
| 777 |
public static final int PRIORITY_MAX = 2; |
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
@Priority |
| 796 |
@Deprecated |
| 797 |
public int priority; |
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
@ColorInt |
| 808 |
public int color = COLOR_DEFAULT; |
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
@ColorInt |
| 815 |
public static final int COLOR_DEFAULT = 0; |
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
@ColorInt |
| 822 |
public static final int COLOR_INVALID = 1; |
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
—see |
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
public @Visibility int visibility; |
| 843 |
|
| 844 |
|
| 845 |
@IntDef(prefix = { "VISIBILITY_" }, value = { |
| 846 |
VISIBILITY_PUBLIC, |
| 847 |
VISIBILITY_PRIVATE, |
| 848 |
VISIBILITY_SECRET, |
| 849 |
}) |
| 850 |
@Retention(RetentionPolicy.SOURCE) |
| 851 |
public @interface Visibility {} |
| 852 |
|
| 853 |
|
| 854 |
|
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
public static final int VISIBILITY_PUBLIC = 1; |
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
|
| 866 |
public static final int VISIBILITY_PRIVATE = 0; |
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
public static final int VISIBILITY_SECRET = -1; |
| 874 |
|
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
@IntDef(prefix = "VISIBILITY_", value = { |
| 879 |
VISIBILITY_PUBLIC, |
| 880 |
VISIBILITY_PRIVATE, |
| 881 |
VISIBILITY_SECRET, |
| 882 |
NotificationManager.VISIBILITY_NO_OVERRIDE |
| 883 |
}) |
| 884 |
public @interface NotificationVisibilityOverride{}; |
| 885 |
|
| 886 |
|
| 887 |
|
| 888 |
|
| 889 |
public static final String CATEGORY_CALL = "call"; |
| 890 |
|
| 891 |
|
| 892 |
|
| 893 |
|
| 894 |
public static final String CATEGORY_NAVIGATION = "navigation"; |
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
|
| 899 |
public static final String CATEGORY_MESSAGE = "msg"; |
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
|
| 904 |
public static final String CATEGORY_EMAIL = "email"; |
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
|
| 909 |
public static final String CATEGORY_EVENT = "event"; |
| 910 |
|
| 911 |
|
| 912 |
|
| 913 |
|
| 914 |
public static final String CATEGORY_PROMO = "promo"; |
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
public static final String CATEGORY_ALARM = "alarm"; |
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
|
| 924 |
public static final String CATEGORY_PROGRESS = "progress"; |
| 925 |
|
| 926 |
|
| 927 |
|
| 928 |
|
| 929 |
public static final String CATEGORY_SOCIAL = "social"; |
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
public static final String CATEGORY_ERROR = "err"; |
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
public static final String CATEGORY_TRANSPORT = "transport"; |
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
public static final String CATEGORY_SYSTEM = "sys"; |
| 945 |
|
| 946 |
|
| 947 |
|
| 948 |
|
| 949 |
public static final String CATEGORY_SERVICE = "service"; |
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
public static final String CATEGORY_RECOMMENDATION = "recommendation"; |
| 957 |
|
| 958 |
|
| 959 |
|
| 960 |
|
| 961 |
public static final String CATEGORY_STATUS = "status"; |
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
public static final String CATEGORY_REMINDER = "reminder"; |
| 967 |
|
| 968 |
|
| 969 |
|
| 970 |
|
| 971 |
|
| 972 |
@SystemApi |
| 973 |
public static final String CATEGORY_CAR_EMERGENCY = "car_emergency"; |
| 974 |
|
| 975 |
|
| 976 |
|
| 977 |
|
| 978 |
|
| 979 |
@SystemApi |
| 980 |
public static final String CATEGORY_CAR_WARNING = "car_warning"; |
| 981 |
|
| 982 |
|
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
@SystemApi |
| 987 |
public static final String CATEGORY_CAR_INFORMATION = "car_information"; |
| 988 |
|
| 989 |
|
| 990 |
|
| 991 |
|
| 992 |
public static final String CATEGORY_WORKOUT = "workout"; |
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
|
| 997 |
public static final String CATEGORY_LOCATION_SHARING = "location_sharing"; |
| 998 |
|
| 999 |
|
| 1000 |
|
| 1001 |
|
| 1002 |
public static final String CATEGORY_STOPWATCH = "stopwatch"; |
| 1003 |
|
| 1004 |
|
| 1005 |
|
| 1006 |
|
| 1007 |
public static final String CATEGORY_MISSED_CALL = "missed_call"; |
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
public String category; |
| 1014 |
|
| 1015 |
@UnsupportedAppUsage |
| 1016 |
private String mGroupKey; |
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
|
| 1022 |
public String getGroup() { |
| 1023 |
return mGroupKey; |
| 1024 |
} |
| 1025 |
|
| 1026 |
private String mSortKey; |
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
|
| 1031 |
|
| 1032 |
|
| 1033 |
|
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
|
| 1039 |
|
| 1040 |
public String getSortKey() { |
| 1041 |
return mSortKey; |
| 1042 |
} |
| 1043 |
|
| 1044 |
|
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
|
| 1052 |
public Bundle extras = new Bundle(); |
| 1053 |
|
| 1054 |
|
| 1055 |
|
| 1056 |
|
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
|
| 1061 |
@UnsupportedAppUsage |
| 1062 |
public ArraySet<PendingIntent> allPendingIntents; |
| 1063 |
|
| 1064 |
|
| 1065 |
|
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
|
| 1070 |
private IBinder mAllowlistToken; |
| 1071 |
|
| 1072 |
|
| 1073 |
|
| 1074 |
|
| 1075 |
|
| 1076 |
|
| 1077 |
|
| 1078 |
static public IBinder processAllowlistToken; |
| 1079 |
|
| 1080 |
|
| 1081 |
|
| 1082 |
|
| 1083 |
|
| 1084 |
public static final String EXTRA_TITLE = "android.title"; |
| 1085 |
|
| 1086 |
|
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
public static final String EXTRA_TITLE_BIG = EXTRA_TITLE + ".big"; |
| 1091 |
|
| 1092 |
|
| 1093 |
|
| 1094 |
|
| 1095 |
|
| 1096 |
public static final String EXTRA_TEXT = "android.text"; |
| 1097 |
|
| 1098 |
|
| 1099 |
|
| 1100 |
|
| 1101 |
|
| 1102 |
public static final String EXTRA_SUB_TEXT = "android.subText"; |
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
|
| 1109 |
|
| 1110 |
|
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
public static final String EXTRA_REMOTE_INPUT_HISTORY = "android.remoteInputHistory"; |
| 1119 |
|
| 1120 |
|
| 1121 |
|
| 1122 |
|
| 1123 |
|
| 1124 |
|
| 1125 |
|
| 1126 |
|
| 1127 |
|
| 1128 |
|
| 1129 |
|
| 1130 |
|
| 1131 |
|
| 1132 |
|
| 1133 |
|
| 1134 |
|
| 1135 |
|
| 1136 |
|
| 1137 |
|
| 1138 |
|
| 1139 |
|
| 1140 |
|
| 1141 |
|
| 1142 |
|
| 1143 |
public static final String EXTRA_REMOTE_INPUT_HISTORY_ITEMS = "android.remoteInputHistoryItems"; |
| 1144 |
|
| 1145 |
|
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
|
| 1155 |
public static final String EXTRA_SHOW_REMOTE_INPUT_SPINNER = "android.remoteInputSpinner"; |
| 1156 |
|
| 1157 |
|
| 1158 |
|
| 1159 |
|
| 1160 |
|
| 1161 |
|
| 1162 |
|
| 1163 |
|
| 1164 |
|
| 1165 |
|
| 1166 |
public static final String EXTRA_HIDE_SMART_REPLIES = "android.hideSmartReplies"; |
| 1167 |
|
| 1168 |
|
| 1169 |
|
| 1170 |
|
| 1171 |
|
| 1172 |
public static final String EXTRA_INFO_TEXT = "android.infoText"; |
| 1173 |
|
| 1174 |
|
| 1175 |
|
| 1176 |
|
| 1177 |
|
| 1178 |
|
| 1179 |
public static final String EXTRA_SUMMARY_TEXT = "android.summaryText"; |
| 1180 |
|
| 1181 |
|
| 1182 |
|
| 1183 |
|
| 1184 |
|
| 1185 |
|
| 1186 |
public static final String EXTRA_BIG_TEXT = "android.bigText"; |
| 1187 |
|
| 1188 |
|
| 1189 |
|
| 1190 |
|
| 1191 |
|
| 1192 |
|
| 1193 |
|
| 1194 |
@Deprecated |
| 1195 |
public static final String EXTRA_SMALL_ICON = "android.icon"; |
| 1196 |
|
| 1197 |
|
| 1198 |
|
| 1199 |
|
| 1200 |
|
| 1201 |
|
| 1202 |
|
| 1203 |
|
| 1204 |
@Deprecated |
| 1205 |
public static final String EXTRA_LARGE_ICON = "android.largeIcon"; |
| 1206 |
|
| 1207 |
|
| 1208 |
|
| 1209 |
|
| 1210 |
|
| 1211 |
|
| 1212 |
|
| 1213 |
public static final String EXTRA_LARGE_ICON_BIG = EXTRA_LARGE_ICON + ".big"; |
| 1214 |
|
| 1215 |
|
| 1216 |
|
| 1217 |
|
| 1218 |
|
| 1219 |
public static final String EXTRA_PROGRESS = "android.progress"; |
| 1220 |
|
| 1221 |
|
| 1222 |
|
| 1223 |
|
| 1224 |
|
| 1225 |
public static final String EXTRA_PROGRESS_MAX = "android.progressMax"; |
| 1226 |
|
| 1227 |
|
| 1228 |
|
| 1229 |
|
| 1230 |
|
| 1231 |
public static final String EXTRA_PROGRESS_INDETERMINATE = "android.progressIndeterminate"; |
| 1232 |
|
| 1233 |
|
| 1234 |
|
| 1235 |
|
| 1236 |
|
| 1237 |
|
| 1238 |
public static final String EXTRA_SHOW_CHRONOMETER = "android.showChronometer"; |
| 1239 |
|
| 1240 |
|
| 1241 |
|
| 1242 |
|
| 1243 |
|
| 1244 |
|
| 1245 |
public static final String EXTRA_CHRONOMETER_COUNT_DOWN = "android.chronometerCountDown"; |
| 1246 |
|
| 1247 |
|
| 1248 |
|
| 1249 |
|
| 1250 |
|
| 1251 |
public static final String EXTRA_SHOW_WHEN = "android.showWhen"; |
| 1252 |
|
| 1253 |
|
| 1254 |
|
| 1255 |
|
| 1256 |
|
| 1257 |
public static final String EXTRA_PICTURE = "android.picture"; |
| 1258 |
|
| 1259 |
|
| 1260 |
|
| 1261 |
|
| 1262 |
|
| 1263 |
|
| 1264 |
public static final String EXTRA_PICTURE_ICON = "android.pictureIcon"; |
| 1265 |
|
| 1266 |
|
| 1267 |
|
| 1268 |
|
| 1269 |
|
| 1270 |
|
| 1271 |
public static final String EXTRA_PICTURE_CONTENT_DESCRIPTION = |
| 1272 |
"android.pictureContentDescription"; |
| 1273 |
|
| 1274 |
|
| 1275 |
|
| 1276 |
|
| 1277 |
|
| 1278 |
|
| 1279 |
|
| 1280 |
public static final String EXTRA_SHOW_BIG_PICTURE_WHEN_COLLAPSED = |
| 1281 |
"android.showBigPictureWhenCollapsed"; |
| 1282 |
|
| 1283 |
|
| 1284 |
|
| 1285 |
|
| 1286 |
|
| 1287 |
public static final String EXTRA_TEXT_LINES = "android.textLines"; |
| 1288 |
|
| 1289 |
|
| 1290 |
|
| 1291 |
|
| 1292 |
|
| 1293 |
public static final String EXTRA_TEMPLATE = "android.template"; |
| 1294 |
|
| 1295 |
|
| 1296 |
|
| 1297 |
|
| 1298 |
|
| 1299 |
|
| 1300 |
|
| 1301 |
public static final String EXTRA_PEOPLE = "android.people"; |
| 1302 |
|
| 1303 |
|
| 1304 |
|
| 1305 |
|
| 1306 |
|
| 1307 |
public static final String EXTRA_PEOPLE_LIST = "android.people.list"; |
| 1308 |
|
| 1309 |
|
| 1310 |
|
| 1311 |
|
| 1312 |
|
| 1313 |
|
| 1314 |
@SystemApi |
| 1315 |
@RequiresPermission(android.Manifest.permission.NOTIFICATION_DURING_SETUP) |
| 1316 |
public static final String EXTRA_ALLOW_DURING_SETUP = "android.allowDuringSetup"; |
| 1317 |
|
| 1318 |
|
| 1319 |
|
| 1320 |
|
| 1321 |
|
| 1322 |
|
| 1323 |
|
| 1324 |
|
| 1325 |
|
| 1326 |
public static final String EXTRA_BACKGROUND_IMAGE_URI = "android.backgroundImageUri"; |
| 1327 |
|
| 1328 |
|
| 1329 |
|
| 1330 |
|
| 1331 |
|
| 1332 |
|
| 1333 |
public static final String EXTRA_MEDIA_SESSION = "android.mediaSession"; |
| 1334 |
|
| 1335 |
|
| 1336 |
|
| 1337 |
|
| 1338 |
|
| 1339 |
|
| 1340 |
|
| 1341 |
@TestApi |
| 1342 |
public static final String EXTRA_MEDIA_REMOTE_DEVICE = "android.mediaRemoteDevice"; |
| 1343 |
|
| 1344 |
|
| 1345 |
|
| 1346 |
|
| 1347 |
|
| 1348 |
|
| 1349 |
@TestApi |
| 1350 |
public static final String EXTRA_MEDIA_REMOTE_ICON = "android.mediaRemoteIcon"; |
| 1351 |
|
| 1352 |
|
| 1353 |
|
| 1354 |
|
| 1355 |
|
| 1356 |
|
| 1357 |
|
| 1358 |
@TestApi |
| 1359 |
public static final String EXTRA_MEDIA_REMOTE_INTENT = "android.mediaRemoteIntent"; |
| 1360 |
|
| 1361 |
|
| 1362 |
|
| 1363 |
|
| 1364 |
|
| 1365 |
public static final String EXTRA_COMPACT_ACTIONS = "android.compactActions"; |
| 1366 |
|
| 1367 |
|
| 1368 |
|
| 1369 |
|
| 1370 |
|
| 1371 |
|
| 1372 |
|
| 1373 |
|
| 1374 |
|
| 1375 |
public static final String EXTRA_SELF_DISPLAY_NAME = "android.selfDisplayName"; |
| 1376 |
|
| 1377 |
|
| 1378 |
|
| 1379 |
|
| 1380 |
|
| 1381 |
|
| 1382 |
|
| 1383 |
public static final String EXTRA_MESSAGING_PERSON = "android.messagingUser"; |
| 1384 |
|
| 1385 |
|
| 1386 |
|
| 1387 |
|
| 1388 |
|
| 1389 |
public static final String EXTRA_CONVERSATION_TITLE = "android.conversationTitle"; |
| 1390 |
|
| 1391 |
|
| 1392 |
public static final String EXTRA_CONVERSATION_ICON = "android.conversationIcon"; |
| 1393 |
|
| 1394 |
|
| 1395 |
public static final String EXTRA_CONVERSATION_UNREAD_MESSAGE_COUNT = |
| 1396 |
"android.conversationUnreadMessageCount"; |
| 1397 |
|
| 1398 |
|
| 1399 |
|
| 1400 |
|
| 1401 |
|
| 1402 |
|
| 1403 |
|
| 1404 |
public static final String EXTRA_MESSAGES = "android.messages"; |
| 1405 |
|
| 1406 |
|
| 1407 |
|
| 1408 |
|
| 1409 |
|
| 1410 |
|
| 1411 |
|
| 1412 |
|
| 1413 |
public static final String EXTRA_HISTORIC_MESSAGES = "android.messages.historic"; |
| 1414 |
|
| 1415 |
|
| 1416 |
|
| 1417 |
|
| 1418 |
|
| 1419 |
public static final String EXTRA_IS_GROUP_CONVERSATION = "android.isGroupConversation"; |
| 1420 |
|
| 1421 |
|
| 1422 |
|
| 1423 |
|
| 1424 |
|
| 1425 |
|
| 1426 |
public static final String EXTRA_CALL_TYPE = "android.callType"; |
| 1427 |
|
| 1428 |
|
| 1429 |
|
| 1430 |
|
| 1431 |
|
| 1432 |
public static final String EXTRA_CALL_IS_VIDEO = "android.callIsVideo"; |
| 1433 |
|
| 1434 |
|
| 1435 |
|
| 1436 |
|
| 1437 |
|
| 1438 |
public static final String EXTRA_CALL_PERSON = "android.callPerson"; |
| 1439 |
|
| 1440 |
|
| 1441 |
|
| 1442 |
|
| 1443 |
|
| 1444 |
public static final String EXTRA_VERIFICATION_ICON = "android.verificationIcon"; |
| 1445 |
|
| 1446 |
|
| 1447 |
|
| 1448 |
|
| 1449 |
|
| 1450 |
|
| 1451 |
public static final String EXTRA_VERIFICATION_TEXT = "android.verificationText"; |
| 1452 |
|
| 1453 |
|
| 1454 |
|
| 1455 |
|
| 1456 |
|
| 1457 |
|
| 1458 |
public static final String EXTRA_ANSWER_INTENT = "android.answerIntent"; |
| 1459 |
|
| 1460 |
|
| 1461 |
|
| 1462 |
|
| 1463 |
|
| 1464 |
|
| 1465 |
public static final String EXTRA_DECLINE_INTENT = "android.declineIntent"; |
| 1466 |
|
| 1467 |
|
| 1468 |
|
| 1469 |
|
| 1470 |
|
| 1471 |
|
| 1472 |
public static final String EXTRA_HANG_UP_INTENT = "android.hangUpIntent"; |
| 1473 |
|
| 1474 |
|
| 1475 |
|
| 1476 |
|
| 1477 |
|
| 1478 |
public static final String EXTRA_ANSWER_COLOR = "android.answerColor"; |
| 1479 |
|
| 1480 |
|
| 1481 |
|
| 1482 |
|
| 1483 |
|
| 1484 |
public static final String EXTRA_DECLINE_COLOR = "android.declineColor"; |
| 1485 |
|
| 1486 |
|
| 1487 |
|
| 1488 |
|
| 1489 |
|
| 1490 |
public static final String EXTRA_COLORIZED = "android.colorized"; |
| 1491 |
|
| 1492 |
|
| 1493 |
|
| 1494 |
|
| 1495 |
public static final String EXTRA_BUILDER_APPLICATION_INFO = "android.appInfo"; |
| 1496 |
|
| 1497 |
|
| 1498 |
|
| 1499 |
|
| 1500 |
public static final String EXTRA_CONTAINS_CUSTOM_VIEW = "android.contains.customView"; |
| 1501 |
|
| 1502 |
|
| 1503 |
|
| 1504 |
|
| 1505 |
public static final String EXTRA_REDUCED_IMAGES = "android.reduced.images"; |
| 1506 |
|
| 1507 |
|
| 1508 |
|
| 1509 |
|
| 1510 |
|
| 1511 |
|
| 1512 |
|
| 1513 |
|
| 1514 |
|
| 1515 |
|
| 1516 |
|
| 1517 |
|
| 1518 |
|
| 1519 |
|
| 1520 |
|
| 1521 |
|
| 1522 |
|
| 1523 |
|
| 1524 |
|
| 1525 |
|
| 1526 |
|
| 1527 |
|
| 1528 |
|
| 1529 |
|
| 1530 |
|
| 1531 |
public static final String EXTRA_AUDIO_CONTENTS_URI = "android.audioContents"; |
| 1532 |
|
| 1533 |
|
| 1534 |
@SystemApi |
| 1535 |
@RequiresPermission(android.Manifest.permission.SUBSTITUTE_NOTIFICATION_APP_NAME) |
| 1536 |
public static final String EXTRA_SUBSTITUTE_APP_NAME = "android.substName"; |
| 1537 |
|
| 1538 |
|
| 1539 |
|
| 1540 |
|
| 1541 |
|
| 1542 |
|
| 1543 |
|
| 1544 |
|
| 1545 |
|
| 1546 |
public static final String EXTRA_FOREGROUND_APPS = "android.foregroundApps"; |
| 1547 |
|
| 1548 |
@UnsupportedAppUsage |
| 1549 |
private Icon mSmallIcon; |
| 1550 |
@UnsupportedAppUsage |
| 1551 |
private Icon mLargeIcon; |
| 1552 |
|
| 1553 |
@UnsupportedAppUsage |
| 1554 |
private String mChannelId; |
| 1555 |
private long mTimeout; |
| 1556 |
|
| 1557 |
private String mShortcutId; |
| 1558 |
private LocusId mLocusId; |
| 1559 |
private CharSequence mSettingsText; |
| 1560 |
|
| 1561 |
private BubbleMetadata mBubbleMetadata; |
| 1562 |
|
| 1563 |
|
| 1564 |
@IntDef(prefix = { "GROUP_ALERT_" }, value = { |
| 1565 |
GROUP_ALERT_ALL, GROUP_ALERT_CHILDREN, GROUP_ALERT_SUMMARY |
| 1566 |
}) |
| 1567 |
@Retention(RetentionPolicy.SOURCE) |
| 1568 |
public @interface GroupAlertBehavior {} |
| 1569 |
|
| 1570 |
|
| 1571 |
|
| 1572 |
|
| 1573 |
|
| 1574 |
|
| 1575 |
public static final int GROUP_ALERT_ALL = 0; |
| 1576 |
|
| 1577 |
|
| 1578 |
|
| 1579 |
|
| 1580 |
|
| 1581 |
|
| 1582 |
|
| 1583 |
|
| 1584 |
|
| 1585 |
|
| 1586 |
|
| 1587 |
|
| 1588 |
public static final int GROUP_ALERT_SUMMARY = 1; |
| 1589 |
|
| 1590 |
|
| 1591 |
|
| 1592 |
|
| 1593 |
|
| 1594 |
|
| 1595 |
|
| 1596 |
|
| 1597 |
|
| 1598 |
|
| 1599 |
|
| 1600 |
public static final int GROUP_ALERT_CHILDREN = 2; |
| 1601 |
|
| 1602 |
private int mGroupAlertBehavior = GROUP_ALERT_ALL; |
| 1603 |
|
| 1604 |
|
| 1605 |
|
| 1606 |
|
| 1607 |
public static final int BADGE_ICON_NONE = 0; |
| 1608 |
|
| 1609 |
|
| 1610 |
|
| 1611 |
|
| 1612 |
|
| 1613 |
public static final int BADGE_ICON_SMALL = 1; |
| 1614 |
|
| 1615 |
|
| 1616 |
|
| 1617 |
|
| 1618 |
|
| 1619 |
public static final int BADGE_ICON_LARGE = 2; |
| 1620 |
private int mBadgeIcon = BADGE_ICON_NONE; |
| 1621 |
|
| 1622 |
|
| 1623 |
|
| 1624 |
|
| 1625 |
private boolean mAllowSystemGeneratedContextualActions = true; |
| 1626 |
|
| 1627 |
|
| 1628 |
|
| 1629 |
|
| 1630 |
|
| 1631 |
|
| 1632 |
|
| 1633 |
|
| 1634 |
|
| 1635 |
|
| 1636 |
|
| 1637 |
|
| 1638 |
|
| 1639 |
|
| 1640 |
|
| 1641 |
public static class Action implements Parcelable { |
| 1642 |
|
| 1643 |
|
| 1644 |
|
| 1645 |
|
| 1646 |
|
| 1647 |
|
| 1648 |
|
| 1649 |
|
| 1650 |
|
| 1651 |
|
| 1652 |
|
| 1653 |
|
| 1654 |
|
| 1655 |
private static final String EXTRA_DATA_ONLY_INPUTS = "android.extra.DATA_ONLY_INPUTS"; |
| 1656 |
|
| 1657 |
|
| 1658 |
|
| 1659 |
|
| 1660 |
public static final int SEMANTIC_ACTION_NONE = 0; |
| 1661 |
|
| 1662 |
|
| 1663 |
|
| 1664 |
|
| 1665 |
|
| 1666 |
public static final int SEMANTIC_ACTION_REPLY = 1; |
| 1667 |
|
| 1668 |
|
| 1669 |
|
| 1670 |
|
| 1671 |
public static final int SEMANTIC_ACTION_MARK_AS_READ = 2; |
| 1672 |
|
| 1673 |
|
| 1674 |
|
| 1675 |
|
| 1676 |
public static final int SEMANTIC_ACTION_MARK_AS_UNREAD = 3; |
| 1677 |
|
| 1678 |
|
| 1679 |
|
| 1680 |
|
| 1681 |
|
| 1682 |
public static final int SEMANTIC_ACTION_DELETE = 4; |
| 1683 |
|
| 1684 |
|
| 1685 |
|
| 1686 |
|
| 1687 |
|
| 1688 |
public static final int SEMANTIC_ACTION_ARCHIVE = 5; |
| 1689 |
|
| 1690 |
|
| 1691 |
|
| 1692 |
|
| 1693 |
|
| 1694 |
public static final int SEMANTIC_ACTION_MUTE = 6; |
| 1695 |
|
| 1696 |
|
| 1697 |
|
| 1698 |
|
| 1699 |
|
| 1700 |
public static final int SEMANTIC_ACTION_UNMUTE = 7; |
| 1701 |
|
| 1702 |
|
| 1703 |
|
| 1704 |
|
| 1705 |
public static final int SEMANTIC_ACTION_THUMBS_UP = 8; |
| 1706 |
|
| 1707 |
|
| 1708 |
|
| 1709 |
|
| 1710 |
public static final int SEMANTIC_ACTION_THUMBS_DOWN = 9; |
| 1711 |
|
| 1712 |
|
| 1713 |
|
| 1714 |
|
| 1715 |
public static final int SEMANTIC_ACTION_CALL = 10; |
| 1716 |
|
| 1717 |
|
| 1718 |
|
| 1719 |
|
| 1720 |
|
| 1721 |
|
| 1722 |
|
| 1723 |
@SystemApi |
| 1724 |
public static final int SEMANTIC_ACTION_MARK_CONVERSATION_AS_PRIORITY = 11; |
| 1725 |
|
| 1726 |
|
| 1727 |
|
| 1728 |
|
| 1729 |
|
| 1730 |
|
| 1731 |
|
| 1732 |
@SystemApi |
| 1733 |
public static final int SEMANTIC_ACTION_CONVERSATION_IS_PHISHING = 12; |
| 1734 |
|
| 1735 |
private final Bundle mExtras; |
| 1736 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
| 1737 |
private Icon mIcon; |
| 1738 |
private final RemoteInput[] mRemoteInputs; |
| 1739 |
private boolean mAllowGeneratedReplies = true; |
| 1740 |
private final @SemanticAction int mSemanticAction; |
| 1741 |
private final boolean mIsContextual; |
| 1742 |
private boolean mAuthenticationRequired; |
| 1743 |
|
| 1744 |
|
| 1745 |
|
| 1746 |
|
| 1747 |
|
| 1748 |
|
| 1749 |
@Deprecated |
| 1750 |
public int icon; |
| 1751 |
|
| 1752 |
|
| 1753 |
|
| 1754 |
|
| 1755 |
public CharSequence title; |
| 1756 |
|
| 1757 |
|
| 1758 |
|
| 1759 |
|
| 1760 |
|
| 1761 |
public PendingIntent actionIntent; |
| 1762 |
|
| 1763 |
private Action(Parcel in) { |
| 1764 |
if (in.readInt() != 0) { |
| 1765 |
mIcon = Icon.CREATOR.createFromParcel(in); |
| 1766 |
if (mIcon.getType() == Icon.TYPE_RESOURCE) { |
| 1767 |
icon = mIcon.getResId(); |
| 1768 |
} |
| 1769 |
} |
| 1770 |
title = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); |
| 1771 |
if (in.readInt() == 1) { |
| 1772 |
actionIntent = PendingIntent.CREATOR.createFromParcel(in); |
| 1773 |
} |
| 1774 |
mExtras = Bundle.setDefusable(in.readBundle(), true); |
| 1775 |
mRemoteInputs = in.createTypedArray(RemoteInput.CREATOR); |
| 1776 |
mAllowGeneratedReplies = in.readInt() == 1; |
| 1777 |
mSemanticAction = in.readInt(); |
| 1778 |
mIsContextual = in.readInt() == 1; |
| 1779 |
mAuthenticationRequired = in.readInt() == 1; |
| 1780 |
} |
| 1781 |
|
| 1782 |
|
| 1783 |
|
| 1784 |
|
| 1785 |
@Deprecated |
| 1786 |
public Action(int icon, CharSequence title, @Nullable PendingIntent intent) { |
| 1787 |
this(Icon.createWithResource("", icon), title, intent, new Bundle(), null, true, |
| 1788 |
SEMANTIC_ACTION_NONE, false , false ); |
| 1789 |
} |
| 1790 |
|
| 1791 |
|
| 1792 |
private Action(Icon icon, CharSequence title, PendingIntent intent, Bundle extras, |
| 1793 |
RemoteInput[] remoteInputs, boolean allowGeneratedReplies, |
| 1794 |
@SemanticAction int semanticAction, boolean isContextual, |
| 1795 |
boolean requireAuth) { |
| 1796 |
this.mIcon = icon; |
| 1797 |
if (icon != null && icon.getType() == Icon.TYPE_RESOURCE) { |
| 1798 |
this.icon = icon.getResId(); |
| 1799 |
} |
| 1800 |
this.title = title; |
| 1801 |
this.actionIntent = intent; |
| 1802 |
this.mExtras = extras != null ? extras : new Bundle(); |
| 1803 |
this.mRemoteInputs = remoteInputs; |
| 1804 |
this.mAllowGeneratedReplies = allowGeneratedReplies; |
| 1805 |
this.mSemanticAction = semanticAction; |
| 1806 |
this.mIsContextual = isContextual; |
| 1807 |
this.mAuthenticationRequired = requireAuth; |
| 1808 |
} |
| 1809 |
|
| 1810 |
|
| 1811 |
|
| 1812 |
|
| 1813 |
public Icon getIcon() { |
| 1814 |
if (mIcon == null && icon != 0) { |
| 1815 |
|
| 1816 |
mIcon = Icon.createWithResource("", icon); |
| 1817 |
} |
| 1818 |
return mIcon; |
| 1819 |
} |
| 1820 |
|
| 1821 |
|
| 1822 |
|
| 1823 |
|
| 1824 |
public Bundle getExtras() { |
| 1825 |
return mExtras; |
| 1826 |
} |
| 1827 |
|
| 1828 |
|
| 1829 |
|
| 1830 |
|
| 1831 |
|
| 1832 |
public boolean getAllowGeneratedReplies() { |
| 1833 |
return mAllowGeneratedReplies; |
| 1834 |
} |
| 1835 |
|
| 1836 |
|
| 1837 |
|
| 1838 |
|
| 1839 |
|
| 1840 |
|
| 1841 |
public RemoteInput[] getRemoteInputs() { |
| 1842 |
return mRemoteInputs; |
| 1843 |
} |
| 1844 |
|
| 1845 |
|
| 1846 |
|
| 1847 |
|
| 1848 |
|
| 1849 |
|
| 1850 |
public @SemanticAction int getSemanticAction() { |
| 1851 |
return mSemanticAction; |
| 1852 |
} |
| 1853 |
|
| 1854 |
|
| 1855 |
|
| 1856 |
|
| 1857 |
|
| 1858 |
|
| 1859 |
public boolean isContextual() { |
| 1860 |
return mIsContextual; |
| 1861 |
} |
| 1862 |
|
| 1863 |
|
| 1864 |
|
| 1865 |
|
| 1866 |
|
| 1867 |
|
| 1868 |
|
| 1869 |
|
| 1870 |
|
| 1871 |
|
| 1872 |
|
| 1873 |
public RemoteInput[] getDataOnlyRemoteInputs() { |
| 1874 |
return getParcelableArrayFromBundle(mExtras, EXTRA_DATA_ONLY_INPUTS, RemoteInput.class); |
| 1875 |
} |
| 1876 |
|
| 1877 |
|
| 1878 |
|
| 1879 |
|
| 1880 |
|
| 1881 |
|
| 1882 |
|
| 1883 |
|
| 1884 |
public boolean isAuthenticationRequired() { |
| 1885 |
return mAuthenticationRequired; |
| 1886 |
} |
| 1887 |
|
| 1888 |
|
| 1889 |
|
| 1890 |
|
| 1891 |
public static final class Builder { |
| 1892 |
@Nullable private final Icon mIcon; |
| 1893 |
@Nullable private final CharSequence mTitle; |
| 1894 |
@Nullable private final PendingIntent mIntent; |
| 1895 |
private boolean mAllowGeneratedReplies = true; |
| 1896 |
@NonNull private final Bundle mExtras; |
| 1897 |
@Nullable private ArrayList<RemoteInput> mRemoteInputs; |
| 1898 |
private @SemanticAction int mSemanticAction; |
| 1899 |
private boolean mIsContextual; |
| 1900 |
private boolean mAuthenticationRequired; |
| 1901 |
|
| 1902 |
|
| 1903 |
|
| 1904 |
|
| 1905 |
|
| 1906 |
|
| 1907 |
|
| 1908 |
|
| 1909 |
|
| 1910 |
|
| 1911 |
|
| 1912 |
|
| 1913 |
|
| 1914 |
|
| 1915 |
@Deprecated |
| 1916 |
public Builder(int icon, CharSequence title, @Nullable PendingIntent intent) { |
| 1917 |
this(Icon.createWithResource("", icon), title, intent); |
| 1918 |
} |
| 1919 |
|
| 1920 |
|
| 1921 |
|
| 1922 |
|
| 1923 |
|
| 1924 |
|
| 1925 |
|
| 1926 |
|
| 1927 |
|
| 1928 |
|
| 1929 |
|
| 1930 |
|
| 1931 |
|
| 1932 |
|
| 1933 |
|
| 1934 |
|
| 1935 |
|
| 1936 |
|
| 1937 |
|
| 1938 |
|
| 1939 |
|
| 1940 |
|
| 1941 |
|
| 1942 |
|
| 1943 |
|
| 1944 |
|
| 1945 |
|
| 1946 |
|
| 1947 |
|
| 1948 |
|
| 1949 |
public Builder(Icon icon, CharSequence title, @Nullable PendingIntent intent) { |
| 1950 |
this(icon, title, intent, new Bundle(), null, true, SEMANTIC_ACTION_NONE, false); |
| 1951 |
} |
| 1952 |
|
| 1953 |
|
| 1954 |
|
| 1955 |
|
| 1956 |
|
| 1957 |
|
| 1958 |
public Builder(Action action) { |
| 1959 |
this(action.getIcon(), action.title, action.actionIntent, |
| 1960 |
new Bundle(action.mExtras), action.getRemoteInputs(), |
| 1961 |
action.getAllowGeneratedReplies(), action.getSemanticAction(), |
| 1962 |
action.isAuthenticationRequired()); |
| 1963 |
} |
| 1964 |
|
| 1965 |
private Builder(@Nullable Icon icon, @Nullable CharSequence title, |
| 1966 |
@Nullable PendingIntent intent, @NonNull Bundle extras, |
| 1967 |
@Nullable RemoteInput[] remoteInputs, boolean allowGeneratedReplies, |
| 1968 |
@SemanticAction int semanticAction, boolean authRequired) { |
| 1969 |
mIcon = icon; |
| 1970 |
mTitle = title; |
| 1971 |
mIntent = intent; |
| 1972 |
mExtras = extras; |
| 1973 |
if (remoteInputs != null) { |
| 1974 |
mRemoteInputs = new ArrayList<>(remoteInputs.length); |
| 1975 |
Collections.addAll(mRemoteInputs, remoteInputs); |
| 1976 |
} |
| 1977 |
mAllowGeneratedReplies = allowGeneratedReplies; |
| 1978 |
mSemanticAction = semanticAction; |
| 1979 |
mAuthenticationRequired = authRequired; |
| 1980 |
} |
| 1981 |
|
| 1982 |
|
| 1983 |
|
| 1984 |
|
| 1985 |
|
| 1986 |
|
| 1987 |
|
| 1988 |
|
| 1989 |
@NonNull |
| 1990 |
public Builder addExtras(Bundle extras) { |
| 1991 |
if (extras != null) { |
| 1992 |
mExtras.putAll(extras); |
| 1993 |
} |
| 1994 |
return this; |
| 1995 |
} |
| 1996 |
|
| 1997 |
|
| 1998 |
|
| 1999 |
|
| 2000 |
|
| 2001 |
|
| 2002 |
@NonNull |
| 2003 |
public Bundle getExtras() { |
| 2004 |
return mExtras; |
| 2005 |
} |
| 2006 |
|
| 2007 |
|
| 2008 |
|
| 2009 |
|
| 2010 |
|
| 2011 |
|
| 2012 |
|
| 2013 |
|
| 2014 |
@NonNull |
| 2015 |
public Builder addRemoteInput(RemoteInput remoteInput) { |
| 2016 |
if (mRemoteInputs == null) { |
| 2017 |
mRemoteInputs = new ArrayList<RemoteInput>(); |
| 2018 |
} |
| 2019 |
mRemoteInputs.add(remoteInput); |
| 2020 |
return this; |
| 2021 |
} |
| 2022 |
|
| 2023 |
|
| 2024 |
|
| 2025 |
|
| 2026 |
|
| 2027 |
|
| 2028 |
|
| 2029 |
|
| 2030 |
|
| 2031 |
|
| 2032 |
@NonNull |
| 2033 |
public Builder setAllowGeneratedReplies(boolean allowGeneratedReplies) { |
| 2034 |
mAllowGeneratedReplies = allowGeneratedReplies; |
| 2035 |
return this; |
| 2036 |
} |
| 2037 |
|
| 2038 |
|
| 2039 |
|
| 2040 |
|
| 2041 |
|
| 2042 |
|
| 2043 |
|
| 2044 |
|
| 2045 |
|
| 2046 |
@NonNull |
| 2047 |
public Builder setSemanticAction(@SemanticAction int semanticAction) { |
| 2048 |
mSemanticAction = semanticAction; |
| 2049 |
return this; |
| 2050 |
} |
| 2051 |
|
| 2052 |
|
| 2053 |
|
| 2054 |
|
| 2055 |
|
| 2056 |
|
| 2057 |
@NonNull |
| 2058 |
public Builder setContextual(boolean isContextual) { |
| 2059 |
mIsContextual = isContextual; |
| 2060 |
return this; |
| 2061 |
} |
| 2062 |
|
| 2063 |
|
| 2064 |
|
| 2065 |
|
| 2066 |
|
| 2067 |
@NonNull |
| 2068 |
public Builder extend(Extender extender) { |
| 2069 |
extender.extend(this); |
| 2070 |
return this; |
| 2071 |
} |
| 2072 |
|
| 2073 |
|
| 2074 |
|
| 2075 |
|
| 2076 |
|
| 2077 |
|
| 2078 |
|
| 2079 |
|
| 2080 |
|
| 2081 |
|
| 2082 |
@NonNull |
| 2083 |
public Builder setAuthenticationRequired(boolean authenticationRequired) { |
| 2084 |
mAuthenticationRequired = authenticationRequired; |
| 2085 |
return this; |
| 2086 |
} |
| 2087 |
|
| 2088 |
|
| 2089 |
|
| 2090 |
|
| 2091 |
|
| 2092 |
private void checkContextualActionNullFields() { |
| 2093 |
if (!mIsContextual) return; |
| 2094 |
|
| 2095 |
if (mIcon == null) { |
| 2096 |
throw new NullPointerException("Contextual Actions must contain a valid icon"); |
| 2097 |
} |
| 2098 |
|
| 2099 |
if (mIntent == null) { |
| 2100 |
throw new NullPointerException( |
| 2101 |
"Contextual Actions must contain a valid PendingIntent"); |
| 2102 |
} |
| 2103 |
} |
| 2104 |
|
| 2105 |
|
| 2106 |
|
| 2107 |
|
| 2108 |
|
| 2109 |
|
| 2110 |
@NonNull |
| 2111 |
public Action build() { |
| 2112 |
checkContextualActionNullFields(); |
| 2113 |
|
| 2114 |
ArrayList<RemoteInput> dataOnlyInputs = new ArrayList<>(); |
| 2115 |
RemoteInput[] previousDataInputs = getParcelableArrayFromBundle( |
| 2116 |
mExtras, EXTRA_DATA_ONLY_INPUTS, RemoteInput.class); |
| 2117 |
if (previousDataInputs != null) { |
| 2118 |
for (RemoteInput input : previousDataInputs) { |
| 2119 |
dataOnlyInputs.add(input); |
| 2120 |
} |
| 2121 |
} |
| 2122 |
List<RemoteInput> textInputs = new ArrayList<>(); |
| 2123 |
if (mRemoteInputs != null) { |
| 2124 |
for (RemoteInput input : mRemoteInputs) { |
| 2125 |
if (input.isDataOnly()) { |
| 2126 |
dataOnlyInputs.add(input); |
| 2127 |
} else { |
| 2128 |
textInputs.add(input); |
| 2129 |
} |
| 2130 |
} |
| 2131 |
} |
| 2132 |
if (!dataOnlyInputs.isEmpty()) { |
| 2133 |
RemoteInput[] dataInputsArr = |
| 2134 |
dataOnlyInputs.toArray(new RemoteInput[dataOnlyInputs.size()]); |
| 2135 |
mExtras.putParcelableArray(EXTRA_DATA_ONLY_INPUTS, dataInputsArr); |
| 2136 |
} |
| 2137 |
RemoteInput[] textInputsArr = textInputs.isEmpty() |
| 2138 |
? null : textInputs.toArray(new RemoteInput[textInputs.size()]); |
| 2139 |
return new Action(mIcon, mTitle, mIntent, mExtras, textInputsArr, |
| 2140 |
mAllowGeneratedReplies, mSemanticAction, mIsContextual, |
| 2141 |
mAuthenticationRequired); |
| 2142 |
} |
| 2143 |
} |
| 2144 |
|
| 2145 |
@Override |
| 2146 |
public Action clone() { |
| 2147 |
return new Action( |
| 2148 |
getIcon(), |
| 2149 |
title, |
| 2150 |
actionIntent, |
| 2151 |
mExtras == null ? new Bundle() : new Bundle(mExtras), |
| 2152 |
getRemoteInputs(), |
| 2153 |
getAllowGeneratedReplies(), |
| 2154 |
getSemanticAction(), |
| 2155 |
isContextual(), |
| 2156 |
isAuthenticationRequired()); |
| 2157 |
} |
| 2158 |
|
| 2159 |
@Override |
| 2160 |
public int describeContents() { |
| 2161 |
return 0; |
| 2162 |
} |
| 2163 |
|
| 2164 |
@Override |
| 2165 |
public void writeToParcel(Parcel out, int flags) { |
| 2166 |
final Icon ic = getIcon(); |
| 2167 |
if (ic != null) { |
| 2168 |
out.writeInt(1); |
| 2169 |
ic.writeToParcel(out, 0); |
| 2170 |
} else { |
| 2171 |
out.writeInt(0); |
| 2172 |
} |
| 2173 |
TextUtils.writeToParcel(title, out, flags); |
| 2174 |
if (actionIntent != null) { |
| 2175 |
out.writeInt(1); |
| 2176 |
actionIntent.writeToParcel(out, flags); |
| 2177 |
} else { |
| 2178 |
out.writeInt(0); |
| 2179 |
} |
| 2180 |
out.writeBundle(mExtras); |
| 2181 |
out.writeTypedArray(mRemoteInputs, flags); |
| 2182 |
out.writeInt(mAllowGeneratedReplies ? 1 : 0); |
| 2183 |
out.writeInt(mSemanticAction); |
| 2184 |
out.writeInt(mIsContextual ? 1 : 0); |
| 2185 |
out.writeInt(mAuthenticationRequired ? 1 : 0); |
| 2186 |
} |
| 2187 |
|
| 2188 |
public static final @android.annotation.NonNull Parcelable.Creator<Action> CREATOR = |
| 2189 |
new Parcelable.Creator<Action>() { |
| 2190 |
public Action createFromParcel(Parcel in) { |
| 2191 |
return new Action(in); |
| 2192 |
} |
| 2193 |
public Action[] newArray(int size) { |
| 2194 |
return new Action[size]; |
| 2195 |
} |
| 2196 |
}; |
| 2197 |
|
| 2198 |
|
| 2199 |
|
| 2200 |
|
| 2201 |
|
| 2202 |
public interface Extender { |
| 2203 |
|
| 2204 |
|
| 2205 |
|
| 2206 |
|
| 2207 |
|
| 2208 |
public Builder extend(Builder builder); |
| 2209 |
} |
| 2210 |
|
| 2211 |
|
| 2212 |
|
| 2213 |
|
| 2214 |
|
| 2215 |
|
| 2216 |
|
| 2217 |
|
| 2218 |
|
| 2219 |
|
| 2220 |
|
| 2221 |
|
| 2222 |
|
| 2223 |
|
| 2224 |
|
| 2225 |
public static final class WearableExtender implements Extender { |
| 2226 |
|
| 2227 |
private static final String EXTRA_WEARABLE_EXTENSIONS = "android.wearable.EXTENSIONS"; |
| 2228 |
|
| 2229 |
|
| 2230 |
private static final String KEY_FLAGS = "flags"; |
| 2231 |
private static final String KEY_IN_PROGRESS_LABEL = "inProgressLabel"; |
| 2232 |
private static final String KEY_CONFIRM_LABEL = "confirmLabel"; |
| 2233 |
private static final String KEY_CANCEL_LABEL = "cancelLabel"; |
| 2234 |
|
| 2235 |
|
| 2236 |
private static final int FLAG_AVAILABLE_OFFLINE = 0x1; |
| 2237 |
private static final int FLAG_HINT_LAUNCHES_ACTIVITY = 1 << 1; |
| 2238 |
private static final int FLAG_HINT_DISPLAY_INLINE = 1 << 2; |
| 2239 |
|
| 2240 |
|
| 2241 |
private static final int DEFAULT_FLAGS = FLAG_AVAILABLE_OFFLINE; |
| 2242 |
|
| 2243 |
private int mFlags = DEFAULT_FLAGS; |
| 2244 |
|
| 2245 |
private CharSequence mInProgressLabel; |
| 2246 |
private CharSequence mConfirmLabel; |
| 2247 |
private CharSequence mCancelLabel; |
| 2248 |
|
| 2249 |
|
| 2250 |
|
| 2251 |
|
| 2252 |
|
| 2253 |
public WearableExtender() { |
| 2254 |
} |
| 2255 |
|
| 2256 |
|
| 2257 |
|
| 2258 |
|
| 2259 |
|
| 2260 |
|
| 2261 |
public WearableExtender(Action action) { |
| 2262 |
Bundle wearableBundle = action.getExtras().getBundle(EXTRA_WEARABLE_EXTENSIONS); |
| 2263 |
if (wearableBundle != null) { |
| 2264 |
mFlags = wearableBundle.getInt(KEY_FLAGS, DEFAULT_FLAGS); |
| 2265 |
mInProgressLabel = wearableBundle.getCharSequence(KEY_IN_PROGRESS_LABEL); |
| 2266 |
mConfirmLabel = wearableBundle.getCharSequence(KEY_CONFIRM_LABEL); |
| 2267 |
mCancelLabel = wearableBundle.getCharSequence(KEY_CANCEL_LABEL); |
| 2268 |
} |
| 2269 |
} |
| 2270 |
|
| 2271 |
|
| 2272 |
|
| 2273 |
|
| 2274 |
|
| 2275 |
|
| 2276 |
@Override |
| 2277 |
public Action.Builder extend(Action.Builder builder) { |
| 2278 |
Bundle wearableBundle = new Bundle(); |
| 2279 |
|
| 2280 |
if (mFlags != DEFAULT_FLAGS) { |
| 2281 |
wearableBundle.putInt(KEY_FLAGS, mFlags); |
| 2282 |
} |
| 2283 |
if (mInProgressLabel != null) { |
| 2284 |
wearableBundle.putCharSequence(KEY_IN_PROGRESS_LABEL, mInProgressLabel); |
| 2285 |
} |
| 2286 |
if (mConfirmLabel != null) { |
| 2287 |
wearableBundle.putCharSequence(KEY_CONFIRM_LABEL, mConfirmLabel); |
| 2288 |
} |
| 2289 |
if (mCancelLabel != null) { |
| 2290 |
wearableBundle.putCharSequence(KEY_CANCEL_LABEL, mCancelLabel); |
| 2291 |
} |
| 2292 |
|
| 2293 |
builder.getExtras().putBundle(EXTRA_WEARABLE_EXTENSIONS, wearableBundle); |
| 2294 |
return builder; |
| 2295 |
} |
| 2296 |
|
| 2297 |
@Override |
| 2298 |
public WearableExtender clone() { |
| 2299 |
WearableExtender that = new WearableExtender(); |
| 2300 |
that.mFlags = this.mFlags; |
| 2301 |
that.mInProgressLabel = this.mInProgressLabel; |
| 2302 |
that.mConfirmLabel = this.mConfirmLabel; |
| 2303 |
that.mCancelLabel = this.mCancelLabel; |
| 2304 |
return that; |
| 2305 |
} |
| 2306 |
|
| 2307 |
|
| 2308 |
|
| 2309 |
|
| 2310 |
|
| 2311 |
|
| 2312 |
|
| 2313 |
public WearableExtender setAvailableOffline(boolean availableOffline) { |
| 2314 |
setFlag(FLAG_AVAILABLE_OFFLINE, availableOffline); |
| 2315 |
return this; |
| 2316 |
} |
| 2317 |
|
| 2318 |
|
| 2319 |
|
| 2320 |
|
| 2321 |
|
| 2322 |
|
| 2323 |
|
| 2324 |
public boolean isAvailableOffline() { |
| 2325 |
return (mFlags & FLAG_AVAILABLE_OFFLINE) != 0; |
| 2326 |
} |
| 2327 |
|
| 2328 |
private void setFlag(int mask, boolean value) { |
| 2329 |
if (value) { |
| 2330 |
mFlags |= mask; |
| 2331 |
} else { |
| 2332 |
mFlags &= ~mask; |
| 2333 |
} |
| 2334 |
} |
| 2335 |
|
| 2336 |
|
| 2337 |
|
| 2338 |
|
| 2339 |
|
| 2340 |
|
| 2341 |
|
| 2342 |
|
| 2343 |
@Deprecated |
| 2344 |
public WearableExtender setInProgressLabel(CharSequence label) { |
| 2345 |
mInProgressLabel = label; |
| 2346 |
return this; |
| 2347 |
} |
| 2348 |
|
| 2349 |
|
| 2350 |
|
| 2351 |
|
| 2352 |
|
| 2353 |
|
| 2354 |
|
| 2355 |
@Deprecated |
| 2356 |
public CharSequence getInProgressLabel() { |
| 2357 |
return mInProgressLabel; |
| 2358 |
} |
| 2359 |
|
| 2360 |
|
| 2361 |
|
| 2362 |
|
| 2363 |
|
| 2364 |
|
| 2365 |
|
| 2366 |
|
| 2367 |
@Deprecated |
| 2368 |
public WearableExtender setConfirmLabel(CharSequence label) { |
| 2369 |
mConfirmLabel = label; |
| 2370 |
return this; |
| 2371 |
} |
| 2372 |
|
| 2373 |
|
| 2374 |
|
| 2375 |
|
| 2376 |
|
| 2377 |
|
| 2378 |
|
| 2379 |
@Deprecated |
| 2380 |
public CharSequence getConfirmLabel() { |
| 2381 |
return mConfirmLabel; |
| 2382 |
} |
| 2383 |
|
| 2384 |
|
| 2385 |
|
| 2386 |
|
| 2387 |
|
| 2388 |
|
| 2389 |
|
| 2390 |
|
| 2391 |
@Deprecated |
| 2392 |
public WearableExtender setCancelLabel(CharSequence label) { |
| 2393 |
mCancelLabel = label; |
| 2394 |
return this; |
| 2395 |
} |
| 2396 |
|
| 2397 |
|
| 2398 |
|
| 2399 |
|
| 2400 |
|
| 2401 |
|
| 2402 |
|
| 2403 |
@Deprecated |
| 2404 |
public CharSequence getCancelLabel() { |
| 2405 |
return mCancelLabel; |
| 2406 |
} |
| 2407 |
|
| 2408 |
|
| 2409 |
|
| 2410 |
|
| 2411 |
|
| 2412 |
|
| 2413 |
|
| 2414 |
|
| 2415 |
public WearableExtender setHintLaunchesActivity( |
| 2416 |
boolean hintLaunchesActivity) { |
| 2417 |
setFlag(FLAG_HINT_LAUNCHES_ACTIVITY, hintLaunchesActivity); |
| 2418 |
return this; |
| 2419 |
} |
| 2420 |
|
| 2421 |
|
| 2422 |
|
| 2423 |
|
| 2424 |
|
| 2425 |
|
| 2426 |
|
| 2427 |
|
| 2428 |
public boolean getHintLaunchesActivity() { |
| 2429 |
return (mFlags & FLAG_HINT_LAUNCHES_ACTIVITY) != 0; |
| 2430 |
} |
| 2431 |
|
| 2432 |
|
| 2433 |
|
| 2434 |
|
| 2435 |
|
| 2436 |
|
| 2437 |
|
| 2438 |
|
| 2439 |
public WearableExtender setHintDisplayActionInline( |
| 2440 |
boolean hintDisplayInline) { |
| 2441 |
setFlag(FLAG_HINT_DISPLAY_INLINE, hintDisplayInline); |
| 2442 |
return this; |
| 2443 |
} |
| 2444 |
|
| 2445 |
|
| 2446 |
|
| 2447 |
|
| 2448 |
|
| 2449 |
|
| 2450 |
|
| 2451 |
public boolean getHintDisplayActionInline() { |
| 2452 |
return (mFlags & FLAG_HINT_DISPLAY_INLINE) != 0; |
| 2453 |
} |
| 2454 |
} |
| 2455 |
|
| 2456 |
|
| 2457 |
|
| 2458 |
|
| 2459 |
|
| 2460 |
|
| 2461 |
|
| 2462 |
|
| 2463 |
|
| 2464 |
@IntDef(prefix = { "SEMANTIC_ACTION_" }, value = { |
| 2465 |
SEMANTIC_ACTION_NONE, |
| 2466 |
SEMANTIC_ACTION_REPLY, |
| 2467 |
SEMANTIC_ACTION_MARK_AS_READ, |
| 2468 |
SEMANTIC_ACTION_MARK_AS_UNREAD, |
| 2469 |
SEMANTIC_ACTION_DELETE, |
| 2470 |
SEMANTIC_ACTION_ARCHIVE, |
| 2471 |
SEMANTIC_ACTION_MUTE, |
| 2472 |
SEMANTIC_ACTION_UNMUTE, |
| 2473 |
SEMANTIC_ACTION_THUMBS_UP, |
| 2474 |
SEMANTIC_ACTION_THUMBS_DOWN, |
| 2475 |
SEMANTIC_ACTION_CALL, |
| 2476 |
SEMANTIC_ACTION_MARK_CONVERSATION_AS_PRIORITY, |
| 2477 |
SEMANTIC_ACTION_CONVERSATION_IS_PHISHING |
| 2478 |
}) |
| 2479 |
@Retention(RetentionPolicy.SOURCE) |
| 2480 |
public @interface SemanticAction {} |
| 2481 |
} |
| 2482 |
|
| 2483 |
|
| 2484 |
|
| 2485 |
|
| 2486 |
|
| 2487 |
|
| 2488 |
|
| 2489 |
public Action[] actions; |
| 2490 |
|
| 2491 |
|
| 2492 |
|
| 2493 |
|
| 2494 |
|
| 2495 |
|
| 2496 |
public Notification publicVersion; |
| 2497 |
|
| 2498 |
|
| 2499 |
|
| 2500 |
|
| 2501 |
|
| 2502 |
public Notification() |
| 2503 |
{ |
| 2504 |
this.when = System.currentTimeMillis(); |
| 2505 |
this.creationTime = System.currentTimeMillis(); |
| 2506 |
this.priority = PRIORITY_DEFAULT; |
| 2507 |
} |
| 2508 |
|
| 2509 |
|
| 2510 |
|
| 2511 |
|
| 2512 |
@UnsupportedAppUsage |
| 2513 |
public Notification(Context context, int icon, CharSequence tickerText, long when, |
| 2514 |
CharSequence contentTitle, CharSequence contentText, Intent contentIntent) |
| 2515 |
{ |
| 2516 |
new Builder(context) |
| 2517 |
.setWhen(when) |
| 2518 |
.setSmallIcon(icon) |
| 2519 |
.setTicker(tickerText) |
| 2520 |
.setContentTitle(contentTitle) |
| 2521 |
.setContentText(contentText) |
| 2522 |
.setContentIntent(PendingIntent.getActivity( |
| 2523 |
context, 0, contentIntent, PendingIntent.FLAG_MUTABLE)) |
| 2524 |
.buildInto(this); |
| 2525 |
} |
| 2526 |
|
| 2527 |
|
| 2528 |
|
| 2529 |
|
| 2530 |
|
| 2531 |
|
| 2532 |
|
| 2533 |
|
| 2534 |
|
| 2535 |
|
| 2536 |
|
| 2537 |
|
| 2538 |
|
| 2539 |
@Deprecated |
| 2540 |
public Notification(int icon, CharSequence tickerText, long when) |
| 2541 |
{ |
| 2542 |
this.icon = icon; |
| 2543 |
this.tickerText = tickerText; |
| 2544 |
this.when = when; |
| 2545 |
this.creationTime = System.currentTimeMillis(); |
| 2546 |
} |
| 2547 |
|
| 2548 |
|
| 2549 |
|
| 2550 |
|
| 2551 |
@SuppressWarnings("unchecked") |
| 2552 |
public Notification(Parcel parcel) { |
| 2553 |
|
| 2554 |
|
| 2555 |
readFromParcelImpl(parcel); |
| 2556 |
|
| 2557 |
allPendingIntents = (ArraySet<PendingIntent>) parcel.readArraySet(null); |
| 2558 |
} |
| 2559 |
|
| 2560 |
private void readFromParcelImpl(Parcel parcel) |
| 2561 |
{ |
| 2562 |
int version = parcel.readInt(); |
| 2563 |
|
| 2564 |
mAllowlistToken = parcel.readStrongBinder(); |
| 2565 |
if (mAllowlistToken == null) { |
| 2566 |
mAllowlistToken = processAllowlistToken; |
| 2567 |
} |
| 2568 |
|
| 2569 |
parcel.setClassCookie(PendingIntent.class, mAllowlistToken); |
| 2570 |
|
| 2571 |
when = parcel.readLong(); |
| 2572 |
creationTime = parcel.readLong(); |
| 2573 |
if (parcel.readInt() != 0) { |
| 2574 |
mSmallIcon = Icon.CREATOR.createFromParcel(parcel); |
| 2575 |
if (mSmallIcon.getType() == Icon.TYPE_RESOURCE) { |
| 2576 |
icon = mSmallIcon.getResId(); |
| 2577 |
} |
| 2578 |
} |
| 2579 |
number = parcel.readInt(); |
| 2580 |
if (parcel.readInt() != 0) { |
| 2581 |
contentIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 2582 |
} |
| 2583 |
if (parcel.readInt() != 0) { |
| 2584 |
deleteIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 2585 |
} |
| 2586 |
if (parcel.readInt() != 0) { |
| 2587 |
tickerText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel); |
| 2588 |
} |
| 2589 |
if (parcel.readInt() != 0) { |
| 2590 |
tickerView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 2591 |
} |
| 2592 |
if (parcel.readInt() != 0) { |
| 2593 |
contentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 2594 |
} |
| 2595 |
if (parcel.readInt() != 0) { |
| 2596 |
mLargeIcon = Icon.CREATOR.createFromParcel(parcel); |
| 2597 |
} |
| 2598 |
defaults = parcel.readInt(); |
| 2599 |
flags = parcel.readInt(); |
| 2600 |
if (parcel.readInt() != 0) { |
| 2601 |
sound = Uri.CREATOR.createFromParcel(parcel); |
| 2602 |
} |
| 2603 |
|
| 2604 |
audioStreamType = parcel.readInt(); |
| 2605 |
if (parcel.readInt() != 0) { |
| 2606 |
audioAttributes = AudioAttributes.CREATOR.createFromParcel(parcel); |
| 2607 |
} |
| 2608 |
vibrate = parcel.createLongArray(); |
| 2609 |
ledARGB = parcel.readInt(); |
| 2610 |
ledOnMS = parcel.readInt(); |
| 2611 |
ledOffMS = parcel.readInt(); |
| 2612 |
iconLevel = parcel.readInt(); |
| 2613 |
|
| 2614 |
if (parcel.readInt() != 0) { |
| 2615 |
fullScreenIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 2616 |
} |
| 2617 |
|
| 2618 |
priority = parcel.readInt(); |
| 2619 |
|
| 2620 |
category = parcel.readString8(); |
| 2621 |
|
| 2622 |
mGroupKey = parcel.readString8(); |
| 2623 |
|
| 2624 |
mSortKey = parcel.readString8(); |
| 2625 |
|
| 2626 |
extras = Bundle.setDefusable(parcel.readBundle(), true); |
| 2627 |
fixDuplicateExtras(); |
| 2628 |
|
| 2629 |
actions = parcel.createTypedArray(Action.CREATOR); |
| 2630 |
|
| 2631 |
if (parcel.readInt() != 0) { |
| 2632 |
bigContentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 2633 |
} |
| 2634 |
|
| 2635 |
if (parcel.readInt() != 0) { |
| 2636 |
headsUpContentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 2637 |
} |
| 2638 |
|
| 2639 |
visibility = parcel.readInt(); |
| 2640 |
|
| 2641 |
if (parcel.readInt() != 0) { |
| 2642 |
publicVersion = Notification.CREATOR.createFromParcel(parcel); |
| 2643 |
} |
| 2644 |
|
| 2645 |
color = parcel.readInt(); |
| 2646 |
|
| 2647 |
if (parcel.readInt() != 0) { |
| 2648 |
mChannelId = parcel.readString8(); |
| 2649 |
} |
| 2650 |
mTimeout = parcel.readLong(); |
| 2651 |
|
| 2652 |
if (parcel.readInt() != 0) { |
| 2653 |
mShortcutId = parcel.readString8(); |
| 2654 |
} |
| 2655 |
|
| 2656 |
if (parcel.readInt() != 0) { |
| 2657 |
mLocusId = LocusId.CREATOR.createFromParcel(parcel); |
| 2658 |
} |
| 2659 |
|
| 2660 |
mBadgeIcon = parcel.readInt(); |
| 2661 |
|
| 2662 |
if (parcel.readInt() != 0) { |
| 2663 |
mSettingsText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel); |
| 2664 |
} |
| 2665 |
|
| 2666 |
mGroupAlertBehavior = parcel.readInt(); |
| 2667 |
if (parcel.readInt() != 0) { |
| 2668 |
mBubbleMetadata = BubbleMetadata.CREATOR.createFromParcel(parcel); |
| 2669 |
} |
| 2670 |
|
| 2671 |
mAllowSystemGeneratedContextualActions = parcel.readBoolean(); |
| 2672 |
|
| 2673 |
mFgsDeferBehavior = parcel.readInt(); |
| 2674 |
} |
| 2675 |
|
| 2676 |
@Override |
| 2677 |
public Notification clone() { |
| 2678 |
Notification that = new Notification(); |
| 2679 |
cloneInto(that, true); |
| 2680 |
return that; |
| 2681 |
} |
| 2682 |
|
| 2683 |
|
| 2684 |
|
| 2685 |
|
| 2686 |
|
| 2687 |
|
| 2688 |
public void cloneInto(Notification that, boolean heavy) { |
| 2689 |
that.mAllowlistToken = this.mAllowlistToken; |
| 2690 |
that.when = this.when; |
| 2691 |
that.creationTime = this.creationTime; |
| 2692 |
that.mSmallIcon = this.mSmallIcon; |
| 2693 |
that.number = this.number; |
| 2694 |
|
| 2695 |
|
| 2696 |
that.contentIntent = this.contentIntent; |
| 2697 |
that.deleteIntent = this.deleteIntent; |
| 2698 |
that.fullScreenIntent = this.fullScreenIntent; |
| 2699 |
|
| 2700 |
if (this.tickerText != null) { |
| 2701 |
that.tickerText = this.tickerText.toString(); |
| 2702 |
} |
| 2703 |
if (heavy && this.tickerView != null) { |
| 2704 |
that.tickerView = this.tickerView.clone(); |
| 2705 |
} |
| 2706 |
if (heavy && this.contentView != null) { |
| 2707 |
that.contentView = this.contentView.clone(); |
| 2708 |
} |
| 2709 |
if (heavy && this.mLargeIcon != null) { |
| 2710 |
that.mLargeIcon = this.mLargeIcon; |
| 2711 |
} |
| 2712 |
that.iconLevel = this.iconLevel; |
| 2713 |
that.sound = this.sound; |
| 2714 |
that.audioStreamType = this.audioStreamType; |
| 2715 |
if (this.audioAttributes != null) { |
| 2716 |
that.audioAttributes = new AudioAttributes.Builder(this.audioAttributes).build(); |
| 2717 |
} |
| 2718 |
|
| 2719 |
final long[] vibrate = this.vibrate; |
| 2720 |
if (vibrate != null) { |
| 2721 |
final int N = vibrate.length; |
| 2722 |
final long[] vib = that.vibrate = new long[N]; |
| 2723 |
System.arraycopy(vibrate, 0, vib, 0, N); |
| 2724 |
} |
| 2725 |
|
| 2726 |
that.ledARGB = this.ledARGB; |
| 2727 |
that.ledOnMS = this.ledOnMS; |
| 2728 |
that.ledOffMS = this.ledOffMS; |
| 2729 |
that.defaults = this.defaults; |
| 2730 |
|
| 2731 |
that.flags = this.flags; |
| 2732 |
|
| 2733 |
that.priority = this.priority; |
| 2734 |
|
| 2735 |
that.category = this.category; |
| 2736 |
|
| 2737 |
that.mGroupKey = this.mGroupKey; |
| 2738 |
|
| 2739 |
that.mSortKey = this.mSortKey; |
| 2740 |
|
| 2741 |
if (this.extras != null) { |
| 2742 |
try { |
| 2743 |
that.extras = new Bundle(this.extras); |
| 2744 |
|
| 2745 |
that.extras.size(); |
| 2746 |
} catch (BadParcelableException e) { |
| 2747 |
Log.e(TAG, "could not unparcel extras from notification: " + this, e); |
| 2748 |
that.extras = null; |
| 2749 |
} |
| 2750 |
} |
| 2751 |
|
| 2752 |
if (!ArrayUtils.isEmpty(allPendingIntents)) { |
| 2753 |
that.allPendingIntents = new ArraySet<>(allPendingIntents); |
| 2754 |
} |
| 2755 |
|
| 2756 |
if (this.actions != null) { |
| 2757 |
that.actions = new Action[this.actions.length]; |
| 2758 |
for(int i=0; i<this.actions.length; i++) { |
| 2759 |
if ( this.actions[i] != null) { |
| 2760 |
that.actions[i] = this.actions[i].clone(); |
| 2761 |
} |
| 2762 |
} |
| 2763 |
} |
| 2764 |
|
| 2765 |
if (heavy && this.bigContentView != null) { |
| 2766 |
that.bigContentView = this.bigContentView.clone(); |
| 2767 |
} |
| 2768 |
|
| 2769 |
if (heavy && this.headsUpContentView != null) { |
| 2770 |
that.headsUpContentView = this.headsUpContentView.clone(); |
| 2771 |
} |
| 2772 |
|
| 2773 |
that.visibility = this.visibility; |
| 2774 |
|
| 2775 |
if (this.publicVersion != null) { |
| 2776 |
that.publicVersion = new Notification(); |
| 2777 |
this.publicVersion.cloneInto(that.publicVersion, heavy); |
| 2778 |
} |
| 2779 |
|
| 2780 |
that.color = this.color; |
| 2781 |
|
| 2782 |
that.mChannelId = this.mChannelId; |
| 2783 |
that.mTimeout = this.mTimeout; |
| 2784 |
that.mShortcutId = this.mShortcutId; |
| 2785 |
that.mLocusId = this.mLocusId; |
| 2786 |
that.mBadgeIcon = this.mBadgeIcon; |
| 2787 |
that.mSettingsText = this.mSettingsText; |
| 2788 |
that.mGroupAlertBehavior = this.mGroupAlertBehavior; |
| 2789 |
that.mFgsDeferBehavior = this.mFgsDeferBehavior; |
| 2790 |
that.mBubbleMetadata = this.mBubbleMetadata; |
| 2791 |
that.mAllowSystemGeneratedContextualActions = this.mAllowSystemGeneratedContextualActions; |
| 2792 |
|
| 2793 |
if (!heavy) { |
| 2794 |
that.lightenPayload(); |
| 2795 |
} |
| 2796 |
} |
| 2797 |
|
| 2798 |
private static void visitIconUri(@NonNull Consumer<Uri> visitor, @Nullable Icon icon) { |
| 2799 |
if (icon == null) return; |
| 2800 |
final int iconType = icon.getType(); |
| 2801 |
if (iconType == TYPE_URI || iconType == TYPE_URI_ADAPTIVE_BITMAP) { |
| 2802 |
visitor.accept(icon.getUri()); |
| 2803 |
} |
| 2804 |
} |
| 2805 |
|
| 2806 |
|
| 2807 |
|
| 2808 |
|
| 2809 |
|
| 2810 |
|
| 2811 |
|
| 2812 |
|
| 2813 |
public void visitUris(@NonNull Consumer<Uri> visitor) { |
| 2814 |
visitor.accept(sound); |
| 2815 |
|
| 2816 |
if (tickerView != null) tickerView.visitUris(visitor); |
| 2817 |
if (contentView != null) contentView.visitUris(visitor); |
| 2818 |
if (bigContentView != null) bigContentView.visitUris(visitor); |
| 2819 |
if (headsUpContentView != null) headsUpContentView.visitUris(visitor); |
| 2820 |
|
| 2821 |
visitIconUri(visitor, mSmallIcon); |
| 2822 |
visitIconUri(visitor, mLargeIcon); |
| 2823 |
|
| 2824 |
if (actions != null) { |
| 2825 |
for (Action action : actions) { |
| 2826 |
visitIconUri(visitor, action.getIcon()); |
| 2827 |
} |
| 2828 |
} |
| 2829 |
|
| 2830 |
if (extras != null) { |
| 2831 |
visitIconUri(visitor, extras.getParcelable(EXTRA_LARGE_ICON_BIG, Icon.class)); |
| 2832 |
visitIconUri(visitor, extras.getParcelable(EXTRA_PICTURE_ICON, Icon.class)); |
| 2833 |
|
| 2834 |
|
| 2835 |
|
| 2836 |
|
| 2837 |
|
| 2838 |
Object audioContentsUri = extras.get(EXTRA_AUDIO_CONTENTS_URI); |
| 2839 |
if (audioContentsUri instanceof Uri) { |
| 2840 |
visitor.accept((Uri) audioContentsUri); |
| 2841 |
} else if (audioContentsUri instanceof String) { |
| 2842 |
visitor.accept(Uri.parse((String) audioContentsUri)); |
| 2843 |
} |
| 2844 |
|
| 2845 |
if (extras.containsKey(EXTRA_BACKGROUND_IMAGE_URI)) { |
| 2846 |
visitor.accept(Uri.parse(extras.getString(EXTRA_BACKGROUND_IMAGE_URI))); |
| 2847 |
} |
| 2848 |
|
| 2849 |
ArrayList<Person> people = extras.getParcelableArrayList(EXTRA_PEOPLE_LIST); |
| 2850 |
if (people != null && !people.isEmpty()) { |
| 2851 |
for (Person p : people) { |
| 2852 |
visitor.accept(p.getIconUri()); |
| 2853 |
} |
| 2854 |
} |
| 2855 |
|
| 2856 |
final Person person = extras.getParcelable(EXTRA_MESSAGING_PERSON, Person.class); |
| 2857 |
if (person != null) { |
| 2858 |
visitor.accept(person.getIconUri()); |
| 2859 |
} |
| 2860 |
} |
| 2861 |
|
| 2862 |
if (isStyle(MessagingStyle.class) && extras != null) { |
| 2863 |
final Parcelable[] messages = extras.getParcelableArray(EXTRA_MESSAGES); |
| 2864 |
if (!ArrayUtils.isEmpty(messages)) { |
| 2865 |
for (MessagingStyle.Message message : MessagingStyle.Message |
| 2866 |
.getMessagesFromBundleArray(messages)) { |
| 2867 |
visitor.accept(message.getDataUri()); |
| 2868 |
|
| 2869 |
Person senderPerson = message.getSenderPerson(); |
| 2870 |
if (senderPerson != null) { |
| 2871 |
visitor.accept(senderPerson.getIconUri()); |
| 2872 |
} |
| 2873 |
} |
| 2874 |
} |
| 2875 |
|
| 2876 |
final Parcelable[] historic = extras.getParcelableArray(EXTRA_HISTORIC_MESSAGES); |
| 2877 |
if (!ArrayUtils.isEmpty(historic)) { |
| 2878 |
for (MessagingStyle.Message message : MessagingStyle.Message |
| 2879 |
.getMessagesFromBundleArray(historic)) { |
| 2880 |
visitor.accept(message.getDataUri()); |
| 2881 |
|
| 2882 |
Person senderPerson = message.getSenderPerson(); |
| 2883 |
if (senderPerson != null) { |
| 2884 |
visitor.accept(senderPerson.getIconUri()); |
| 2885 |
} |
| 2886 |
} |
| 2887 |
} |
| 2888 |
} |
| 2889 |
|
| 2890 |
if (mBubbleMetadata != null) { |
| 2891 |
visitIconUri(visitor, mBubbleMetadata.getIcon()); |
| 2892 |
} |
| 2893 |
} |
| 2894 |
|
| 2895 |
|
| 2896 |
|
| 2897 |
|
| 2898 |
|
| 2899 |
|
| 2900 |
public final void lightenPayload() { |
| 2901 |
tickerView = null; |
| 2902 |
contentView = null; |
| 2903 |
bigContentView = null; |
| 2904 |
headsUpContentView = null; |
| 2905 |
mLargeIcon = null; |
| 2906 |
if (extras != null && !extras.isEmpty()) { |
| 2907 |
final Set<String> keyset = extras.keySet(); |
| 2908 |
final int N = keyset.size(); |
| 2909 |
final String[] keys = keyset.toArray(new String[N]); |
| 2910 |
for (int i=0; i<N; i++) { |
| 2911 |
final String key = keys[i]; |
| 2912 |
if (TvExtender.EXTRA_TV_EXTENDER.equals(key)) { |
| 2913 |
continue; |
| 2914 |
} |
| 2915 |
final Object obj = extras.get(key); |
| 2916 |
if (obj != null && |
| 2917 |
( obj instanceof Parcelable |
| 2918 |
|| obj instanceof Parcelable[] |
| 2919 |
|| obj instanceof SparseArray |
| 2920 |
|| obj instanceof ArrayList)) { |
| 2921 |
extras.remove(key); |
| 2922 |
} |
| 2923 |
} |
| 2924 |
} |
| 2925 |
} |
| 2926 |
|
| 2927 |
|
| 2928 |
|
| 2929 |
|
| 2930 |
|
| 2931 |
|
| 2932 |
public static CharSequence safeCharSequence(CharSequence cs) { |
| 2933 |
if (cs == null) return cs; |
| 2934 |
if (cs.length() > MAX_CHARSEQUENCE_LENGTH) { |
| 2935 |
cs = cs.subSequence(0, MAX_CHARSEQUENCE_LENGTH); |
| 2936 |
} |
| 2937 |
if (cs instanceof Parcelable) { |
| 2938 |
Log.e(TAG, "warning: " + cs.getClass().getCanonicalName() |
| 2939 |
+ " instance is a custom Parcelable and not allowed in Notification"); |
| 2940 |
return cs.toString(); |
| 2941 |
} |
| 2942 |
return removeTextSizeSpans(cs); |
| 2943 |
} |
| 2944 |
|
| 2945 |
private static CharSequence removeTextSizeSpans(CharSequence charSequence) { |
| 2946 |
if (charSequence instanceof Spanned) { |
| 2947 |
Spanned ss = (Spanned) charSequence; |
| 2948 |
Object[] spans = ss.getSpans(0, ss.length(), Object.class); |
| 2949 |
SpannableStringBuilder builder = new SpannableStringBuilder(ss.toString()); |
| 2950 |
for (Object span : spans) { |
| 2951 |
Object resultSpan = span; |
| 2952 |
if (resultSpan instanceof CharacterStyle) { |
| 2953 |
resultSpan = ((CharacterStyle) span).getUnderlying(); |
| 2954 |
} |
| 2955 |
if (resultSpan instanceof TextAppearanceSpan) { |
| 2956 |
TextAppearanceSpan originalSpan = (TextAppearanceSpan) resultSpan; |
| 2957 |
resultSpan = new TextAppearanceSpan( |
| 2958 |
originalSpan.getFamily(), |
| 2959 |
originalSpan.getTextStyle(), |
| 2960 |
-1, |
| 2961 |
originalSpan.getTextColor(), |
| 2962 |
originalSpan.getLinkTextColor()); |
| 2963 |
} else if (resultSpan instanceof RelativeSizeSpan |
| 2964 |
|| resultSpan instanceof AbsoluteSizeSpan) { |
| 2965 |
continue; |
| 2966 |
} else { |
| 2967 |
resultSpan = span; |
| 2968 |
} |
| 2969 |
builder.setSpan(resultSpan, ss.getSpanStart(span), ss.getSpanEnd(span), |
| 2970 |
ss.getSpanFlags(span)); |
| 2971 |
} |
| 2972 |
return builder; |
| 2973 |
} |
| 2974 |
return charSequence; |
| 2975 |
} |
| 2976 |
|
| 2977 |
public int describeContents() { |
| 2978 |
return 0; |
| 2979 |
} |
| 2980 |
|
| 2981 |
|
| 2982 |
|
| 2983 |
|
| 2984 |
public void writeToParcel(Parcel parcel, int flags) { |
| 2985 |
|
| 2986 |
|
| 2987 |
|
| 2988 |
|
| 2989 |
|
| 2990 |
|
| 2991 |
|
| 2992 |
final boolean collectPendingIntents = (allPendingIntents == null); |
| 2993 |
if (collectPendingIntents) { |
| 2994 |
PendingIntent.setOnMarshaledListener( |
| 2995 |
(PendingIntent intent, Parcel out, int outFlags) -> { |
| 2996 |
if (parcel == out) { |
| 2997 |
synchronized (this) { |
| 2998 |
if (allPendingIntents == null) { |
| 2999 |
allPendingIntents = new ArraySet<>(); |
| 3000 |
} |
| 3001 |
allPendingIntents.add(intent); |
| 3002 |
} |
| 3003 |
} |
| 3004 |
}); |
| 3005 |
} |
| 3006 |
try { |
| 3007 |
|
| 3008 |
|
| 3009 |
writeToParcelImpl(parcel, flags); |
| 3010 |
synchronized (this) { |
| 3011 |
|
| 3012 |
parcel.writeArraySet(allPendingIntents); |
| 3013 |
} |
| 3014 |
} finally { |
| 3015 |
if (collectPendingIntents) { |
| 3016 |
PendingIntent.setOnMarshaledListener(null); |
| 3017 |
} |
| 3018 |
} |
| 3019 |
} |
| 3020 |
|
| 3021 |
private void writeToParcelImpl(Parcel parcel, int flags) { |
| 3022 |
parcel.writeInt(1); |
| 3023 |
|
| 3024 |
parcel.writeStrongBinder(mAllowlistToken); |
| 3025 |
parcel.writeLong(when); |
| 3026 |
parcel.writeLong(creationTime); |
| 3027 |
if (mSmallIcon == null && icon != 0) { |
| 3028 |
|
| 3029 |
mSmallIcon = Icon.createWithResource("", icon); |
| 3030 |
} |
| 3031 |
if (mSmallIcon != null) { |
| 3032 |
parcel.writeInt(1); |
| 3033 |
mSmallIcon.writeToParcel(parcel, 0); |
| 3034 |
} else { |
| 3035 |
parcel.writeInt(0); |
| 3036 |
} |
| 3037 |
parcel.writeInt(number); |
| 3038 |
if (contentIntent != null) { |
| 3039 |
parcel.writeInt(1); |
| 3040 |
contentIntent.writeToParcel(parcel, 0); |
| 3041 |
} else { |
| 3042 |
parcel.writeInt(0); |
| 3043 |
} |
| 3044 |
if (deleteIntent != null) { |
| 3045 |
parcel.writeInt(1); |
| 3046 |
deleteIntent.writeToParcel(parcel, 0); |
| 3047 |
} else { |
| 3048 |
parcel.writeInt(0); |
| 3049 |
} |
| 3050 |
if (tickerText != null) { |
| 3051 |
parcel.writeInt(1); |
| 3052 |
TextUtils.writeToParcel(tickerText, parcel, flags); |
| 3053 |
} else { |
| 3054 |
parcel.writeInt(0); |
| 3055 |
} |
| 3056 |
if (tickerView != null) { |
| 3057 |
parcel.writeInt(1); |
| 3058 |
tickerView.writeToParcel(parcel, 0); |
| 3059 |
} else { |
| 3060 |
parcel.writeInt(0); |
| 3061 |
} |
| 3062 |
if (contentView != null) { |
| 3063 |
parcel.writeInt(1); |
| 3064 |
contentView.writeToParcel(parcel, 0); |
| 3065 |
} else { |
| 3066 |
parcel.writeInt(0); |
| 3067 |
} |
| 3068 |
if (mLargeIcon == null && largeIcon != null) { |
| 3069 |
|
| 3070 |
mLargeIcon = Icon.createWithBitmap(largeIcon); |
| 3071 |
} |
| 3072 |
if (mLargeIcon != null) { |
| 3073 |
parcel.writeInt(1); |
| 3074 |
mLargeIcon.writeToParcel(parcel, 0); |
| 3075 |
} else { |
| 3076 |
parcel.writeInt(0); |
| 3077 |
} |
| 3078 |
|
| 3079 |
parcel.writeInt(defaults); |
| 3080 |
parcel.writeInt(this.flags); |
| 3081 |
|
| 3082 |
if (sound != null) { |
| 3083 |
parcel.writeInt(1); |
| 3084 |
sound.writeToParcel(parcel, 0); |
| 3085 |
} else { |
| 3086 |
parcel.writeInt(0); |
| 3087 |
} |
| 3088 |
parcel.writeInt(audioStreamType); |
| 3089 |
|
| 3090 |
if (audioAttributes != null) { |
| 3091 |
parcel.writeInt(1); |
| 3092 |
audioAttributes.writeToParcel(parcel, 0); |
| 3093 |
} else { |
| 3094 |
parcel.writeInt(0); |
| 3095 |
} |
| 3096 |
|
| 3097 |
parcel.writeLongArray(vibrate); |
| 3098 |
parcel.writeInt(ledARGB); |
| 3099 |
parcel.writeInt(ledOnMS); |
| 3100 |
parcel.writeInt(ledOffMS); |
| 3101 |
parcel.writeInt(iconLevel); |
| 3102 |
|
| 3103 |
if (fullScreenIntent != null) { |
| 3104 |
parcel.writeInt(1); |
| 3105 |
fullScreenIntent.writeToParcel(parcel, 0); |
| 3106 |
} else { |
| 3107 |
parcel.writeInt(0); |
| 3108 |
} |
| 3109 |
|
| 3110 |
parcel.writeInt(priority); |
| 3111 |
|
| 3112 |
parcel.writeString8(category); |
| 3113 |
|
| 3114 |
parcel.writeString8(mGroupKey); |
| 3115 |
|
| 3116 |
parcel.writeString8(mSortKey); |
| 3117 |
|
| 3118 |
parcel.writeBundle(extras); |
| 3119 |
|
| 3120 |
parcel.writeTypedArray(actions, 0); |
| 3121 |
|
| 3122 |
if (bigContentView != null) { |
| 3123 |
parcel.writeInt(1); |
| 3124 |
bigContentView.writeToParcel(parcel, 0); |
| 3125 |
} else { |
| 3126 |
parcel.writeInt(0); |
| 3127 |
} |
| 3128 |
|
| 3129 |
if (headsUpContentView != null) { |
| 3130 |
parcel.writeInt(1); |
| 3131 |
headsUpContentView.writeToParcel(parcel, 0); |
| 3132 |
} else { |
| 3133 |
parcel.writeInt(0); |
| 3134 |
} |
| 3135 |
|
| 3136 |
parcel.writeInt(visibility); |
| 3137 |
|
| 3138 |
if (publicVersion != null) { |
| 3139 |
parcel.writeInt(1); |
| 3140 |
publicVersion.writeToParcel(parcel, 0); |
| 3141 |
} else { |
| 3142 |
parcel.writeInt(0); |
| 3143 |
} |
| 3144 |
|
| 3145 |
parcel.writeInt(color); |
| 3146 |
|
| 3147 |
if (mChannelId != null) { |
| 3148 |
parcel.writeInt(1); |
| 3149 |
parcel.writeString8(mChannelId); |
| 3150 |
} else { |
| 3151 |
parcel.writeInt(0); |
| 3152 |
} |
| 3153 |
parcel.writeLong(mTimeout); |
| 3154 |
|
| 3155 |
if (mShortcutId != null) { |
| 3156 |
parcel.writeInt(1); |
| 3157 |
parcel.writeString8(mShortcutId); |
| 3158 |
} else { |
| 3159 |
parcel.writeInt(0); |
| 3160 |
} |
| 3161 |
|
| 3162 |
if (mLocusId != null) { |
| 3163 |
parcel.writeInt(1); |
| 3164 |
mLocusId.writeToParcel(parcel, 0); |
| 3165 |
} else { |
| 3166 |
parcel.writeInt(0); |
| 3167 |
} |
| 3168 |
|
| 3169 |
parcel.writeInt(mBadgeIcon); |
| 3170 |
|
| 3171 |
if (mSettingsText != null) { |
| 3172 |
parcel.writeInt(1); |
| 3173 |
TextUtils.writeToParcel(mSettingsText, parcel, flags); |
| 3174 |
} else { |
| 3175 |
parcel.writeInt(0); |
| 3176 |
} |
| 3177 |
|
| 3178 |
parcel.writeInt(mGroupAlertBehavior); |
| 3179 |
|
| 3180 |
if (mBubbleMetadata != null) { |
| 3181 |
parcel.writeInt(1); |
| 3182 |
mBubbleMetadata.writeToParcel(parcel, 0); |
| 3183 |
} else { |
| 3184 |
parcel.writeInt(0); |
| 3185 |
} |
| 3186 |
|
| 3187 |
parcel.writeBoolean(mAllowSystemGeneratedContextualActions); |
| 3188 |
|
| 3189 |
parcel.writeInt(mFgsDeferBehavior); |
| 3190 |
|
| 3191 |
|
| 3192 |
} |
| 3193 |
|
| 3194 |
|
| 3195 |
|
| 3196 |
|
| 3197 |
public static final @android.annotation.NonNull Parcelable.Creator<Notification> CREATOR |
| 3198 |
= new Parcelable.Creator<Notification>() |
| 3199 |
{ |
| 3200 |
public Notification createFromParcel(Parcel parcel) |
| 3201 |
{ |
| 3202 |
return new Notification(parcel); |
| 3203 |
} |
| 3204 |
|
| 3205 |
public Notification[] newArray(int size) |
| 3206 |
{ |
| 3207 |
return new Notification[size]; |
| 3208 |
} |
| 3209 |
}; |
| 3210 |
|
| 3211 |
|
| 3212 |
|
| 3213 |
|
| 3214 |
public static boolean areActionsVisiblyDifferent(Notification first, Notification second) { |
| 3215 |
Notification.Action[] firstAs = first.actions; |
| 3216 |
Notification.Action[] secondAs = second.actions; |
| 3217 |
if (firstAs == null && secondAs != null || firstAs != null && secondAs == null) { |
| 3218 |
return true; |
| 3219 |
} |
| 3220 |
if (firstAs != null && secondAs != null) { |
| 3221 |
if (firstAs.length != secondAs.length) { |
| 3222 |
return true; |
| 3223 |
} |
| 3224 |
for (int i = 0; i < firstAs.length; i++) { |
| 3225 |
if (!Objects.equals(String.valueOf(firstAs[i].title), |
| 3226 |
String.valueOf(secondAs[i].title))) { |
| 3227 |
return true; |
| 3228 |
} |
| 3229 |
RemoteInput[] firstRs = firstAs[i].getRemoteInputs(); |
| 3230 |
RemoteInput[] secondRs = secondAs[i].getRemoteInputs(); |
| 3231 |
if (firstRs == null) { |
| 3232 |
firstRs = new RemoteInput[0]; |
| 3233 |
} |
| 3234 |
if (secondRs == null) { |
| 3235 |
secondRs = new RemoteInput[0]; |
| 3236 |
} |
| 3237 |
if (firstRs.length != secondRs.length) { |
| 3238 |
return true; |
| 3239 |
} |
| 3240 |
for (int j = 0; j < firstRs.length; j++) { |
| 3241 |
if (!Objects.equals(String.valueOf(firstRs[j].getLabel()), |
| 3242 |
String.valueOf(secondRs[j].getLabel()))) { |
| 3243 |
return true; |
| 3244 |
} |
| 3245 |
} |
| 3246 |
} |
| 3247 |
} |
| 3248 |
return false; |
| 3249 |
} |
| 3250 |
|
| 3251 |
|
| 3252 |
|
| 3253 |
|
| 3254 |
public static boolean areStyledNotificationsVisiblyDifferent(Builder first, Builder second) { |
| 3255 |
if (first.getStyle() == null) { |
| 3256 |
return second.getStyle() != null; |
| 3257 |
} |
| 3258 |
if (second.getStyle() == null) { |
| 3259 |
return true; |
| 3260 |
} |
| 3261 |
return first.getStyle().areNotificationsVisiblyDifferent(second.getStyle()); |
| 3262 |
} |
| 3263 |
|
| 3264 |
|
| 3265 |
|
| 3266 |
|
| 3267 |
public static boolean areRemoteViewsChanged(Builder first, Builder second) { |
| 3268 |
if (!Objects.equals(first.usesStandardHeader(), second.usesStandardHeader())) { |
| 3269 |
return true; |
| 3270 |
} |
| 3271 |
|
| 3272 |
if (areRemoteViewsChanged(first.mN.contentView, second.mN.contentView)) { |
| 3273 |
return true; |
| 3274 |
} |
| 3275 |
if (areRemoteViewsChanged(first.mN.bigContentView, second.mN.bigContentView)) { |
| 3276 |
return true; |
| 3277 |
} |
| 3278 |
if (areRemoteViewsChanged(first.mN.headsUpContentView, second.mN.headsUpContentView)) { |
| 3279 |
return true; |
| 3280 |
} |
| 3281 |
|
| 3282 |
return false; |
| 3283 |
} |
| 3284 |
|
| 3285 |
private static boolean areRemoteViewsChanged(RemoteViews first, RemoteViews second) { |
| 3286 |
if (first == null && second == null) { |
| 3287 |
return false; |
| 3288 |
} |
| 3289 |
if (first == null && second != null || first != null && second == null) { |
| 3290 |
return true; |
| 3291 |
} |
| 3292 |
|
| 3293 |
if (!Objects.equals(first.getLayoutId(), second.getLayoutId())) { |
| 3294 |
return true; |
| 3295 |
} |
| 3296 |
|
| 3297 |
if (!Objects.equals(first.getSequenceNumber(), second.getSequenceNumber())) { |
| 3298 |
return true; |
| 3299 |
} |
| 3300 |
|
| 3301 |
return false; |
| 3302 |
} |
| 3303 |
|
| 3304 |
|
| 3305 |
|
| 3306 |
|
| 3307 |
|
| 3308 |
|
| 3309 |
|
| 3310 |
|
| 3311 |
|
| 3312 |
|
| 3313 |
|
| 3314 |
private void fixDuplicateExtras() { |
| 3315 |
if (extras != null) { |
| 3316 |
fixDuplicateExtra(mLargeIcon, EXTRA_LARGE_ICON); |
| 3317 |
} |
| 3318 |
} |
| 3319 |
|
| 3320 |
|
| 3321 |
|
| 3322 |
|
| 3323 |
|
| 3324 |
private void fixDuplicateExtra(@Nullable Parcelable original, @NonNull String extraName) { |
| 3325 |
if (original != null && extras.getParcelable(extraName) != null) { |
| 3326 |
extras.putParcelable(extraName, original); |
| 3327 |
} |
| 3328 |
} |
| 3329 |
|
| 3330 |
|
| 3331 |
|
| 3332 |
|
| 3333 |
|
| 3334 |
|
| 3335 |
|
| 3336 |
|
| 3337 |
|
| 3338 |
|
| 3339 |
|
| 3340 |
|
| 3341 |
|
| 3342 |
|
| 3343 |
|
| 3344 |
|
| 3345 |
|
| 3346 |
|
| 3347 |
|
| 3348 |
|
| 3349 |
@Deprecated |
| 3350 |
public void setLatestEventInfo(Context context, |
| 3351 |
CharSequence contentTitle, CharSequence contentText, PendingIntent contentIntent) { |
| 3352 |
if (context.getApplicationInfo().targetSdkVersion > Build.VERSION_CODES.LOLLIPOP_MR1){ |
| 3353 |
Log.e(TAG, "setLatestEventInfo() is deprecated and you should feel deprecated.", |
| 3354 |
new Throwable()); |
| 3355 |
} |
| 3356 |
|
| 3357 |
if (context.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N) { |
| 3358 |
extras.putBoolean(EXTRA_SHOW_WHEN, true); |
| 3359 |
} |
| 3360 |
|
| 3361 |
|
| 3362 |
final Notification.Builder builder = new Notification.Builder(context, this); |
| 3363 |
|
| 3364 |
|
| 3365 |
if (contentTitle != null) { |
| 3366 |
builder.setContentTitle(contentTitle); |
| 3367 |
} |
| 3368 |
if (contentText != null) { |
| 3369 |
builder.setContentText(contentText); |
| 3370 |
} |
| 3371 |
builder.setContentIntent(contentIntent); |
| 3372 |
|
| 3373 |
builder.build(); |
| 3374 |
} |
| 3375 |
|
| 3376 |
|
| 3377 |
|
| 3378 |
|
| 3379 |
|
| 3380 |
|
| 3381 |
|
| 3382 |
|
| 3383 |
|
| 3384 |
|
| 3385 |
public void setAllowlistToken(@Nullable IBinder token) { |
| 3386 |
mAllowlistToken = token; |
| 3387 |
} |
| 3388 |
|
| 3389 |
|
| 3390 |
|
| 3391 |
|
| 3392 |
public static void addFieldsFromContext(Context context, Notification notification) { |
| 3393 |
addFieldsFromContext(context.getApplicationInfo(), notification); |
| 3394 |
} |
| 3395 |
|
| 3396 |
|
| 3397 |
|
| 3398 |
|
| 3399 |
public static void addFieldsFromContext(ApplicationInfo ai, Notification notification) { |
| 3400 |
notification.extras.putParcelable(EXTRA_BUILDER_APPLICATION_INFO, ai); |
| 3401 |
} |
| 3402 |
|
| 3403 |
|
| 3404 |
|
| 3405 |
|
| 3406 |
public void dumpDebug(ProtoOutputStream proto, long fieldId) { |
| 3407 |
long token = proto.start(fieldId); |
| 3408 |
proto.write(NotificationProto.CHANNEL_ID, getChannelId()); |
| 3409 |
proto.write(NotificationProto.HAS_TICKER_TEXT, this.tickerText != null); |
| 3410 |
proto.write(NotificationProto.FLAGS, this.flags); |
| 3411 |
proto.write(NotificationProto.COLOR, this.color); |
| 3412 |
proto.write(NotificationProto.CATEGORY, this.category); |
| 3413 |
proto.write(NotificationProto.GROUP_KEY, this.mGroupKey); |
| 3414 |
proto.write(NotificationProto.SORT_KEY, this.mSortKey); |
| 3415 |
if (this.actions != null) { |
| 3416 |
proto.write(NotificationProto.ACTION_LENGTH, this.actions.length); |
| 3417 |
} |
| 3418 |
if (this.visibility >= VISIBILITY_SECRET && this.visibility <= VISIBILITY_PUBLIC) { |
| 3419 |
proto.write(NotificationProto.VISIBILITY, this.visibility); |
| 3420 |
} |
| 3421 |
if (publicVersion != null) { |
| 3422 |
publicVersion.dumpDebug(proto, NotificationProto.PUBLIC_VERSION); |
| 3423 |
} |
| 3424 |
proto.end(token); |
| 3425 |
} |
| 3426 |
|
| 3427 |
@Override |
| 3428 |
public String toString() { |
| 3429 |
StringBuilder sb = new StringBuilder(); |
| 3430 |
sb.append("Notification(channel="); |
| 3431 |
sb.append(getChannelId()); |
| 3432 |
sb.append(" shortcut="); |
| 3433 |
sb.append(getShortcutId()); |
| 3434 |
sb.append(" contentView="); |
| 3435 |
if (contentView != null) { |
| 3436 |
sb.append(contentView.getPackage()); |
| 3437 |
sb.append("/0x"); |
| 3438 |
sb.append(Integer.toHexString(contentView.getLayoutId())); |
| 3439 |
} else { |
| 3440 |
sb.append("null"); |
| 3441 |
} |
| 3442 |
sb.append(" vibrate="); |
| 3443 |
if ((this.defaults & DEFAULT_VIBRATE) != 0) { |
| 3444 |
sb.append("default"); |
| 3445 |
} else if (this.vibrate != null) { |
| 3446 |
int N = this.vibrate.length-1; |
| 3447 |
sb.append("["); |
| 3448 |
for (int i=0; i<N; i++) { |
| 3449 |
sb.append(this.vibrate[i]); |
| 3450 |
sb.append(','); |
| 3451 |
} |
| 3452 |
if (N != -1) { |
| 3453 |
sb.append(this.vibrate[N]); |
| 3454 |
} |
| 3455 |
sb.append("]"); |
| 3456 |
} else { |
| 3457 |
sb.append("null"); |
| 3458 |
} |
| 3459 |
sb.append(" sound="); |
| 3460 |
if ((this.defaults & DEFAULT_SOUND) != 0) { |
| 3461 |
sb.append("default"); |
| 3462 |
} else if (this.sound != null) { |
| 3463 |
sb.append(this.sound.toString()); |
| 3464 |
} else { |
| 3465 |
sb.append("null"); |
| 3466 |
} |
| 3467 |
if (this.tickerText != null) { |
| 3468 |
sb.append(" tick"); |
| 3469 |
} |
| 3470 |
sb.append(" defaults=0x"); |
| 3471 |
sb.append(Integer.toHexString(this.defaults)); |
| 3472 |
sb.append(" flags=0x"); |
| 3473 |
sb.append(Integer.toHexString(this.flags)); |
| 3474 |
sb.append(String.format(" color=0x%08x", this.color)); |
| 3475 |
if (this.category != null) { |
| 3476 |
sb.append(" category="); |
| 3477 |
sb.append(this.category); |
| 3478 |
} |
| 3479 |
if (this.mGroupKey != null) { |
| 3480 |
sb.append(" groupKey="); |
| 3481 |
sb.append(this.mGroupKey); |
| 3482 |
} |
| 3483 |
if (this.mSortKey != null) { |
| 3484 |
sb.append(" sortKey="); |
| 3485 |
sb.append(this.mSortKey); |
| 3486 |
} |
| 3487 |
if (actions != null) { |
| 3488 |
sb.append(" actions="); |
| 3489 |
sb.append(actions.length); |
| 3490 |
} |
| 3491 |
sb.append(" vis="); |
| 3492 |
sb.append(visibilityToString(this.visibility)); |
| 3493 |
if (this.publicVersion != null) { |
| 3494 |
sb.append(" publicVersion="); |
| 3495 |
sb.append(publicVersion.toString()); |
| 3496 |
} |
| 3497 |
if (this.mLocusId != null) { |
| 3498 |
sb.append(" locusId="); |
| 3499 |
sb.append(this.mLocusId); |
| 3500 |
} |
| 3501 |
sb.append(")"); |
| 3502 |
return sb.toString(); |
| 3503 |
} |
| 3504 |
|
| 3505 |
|
| 3506 |
|
| 3507 |
|
| 3508 |
public static String visibilityToString(int vis) { |
| 3509 |
switch (vis) { |
| 3510 |
case VISIBILITY_PRIVATE: |
| 3511 |
return "PRIVATE"; |
| 3512 |
case VISIBILITY_PUBLIC: |
| 3513 |
return "PUBLIC"; |
| 3514 |
case VISIBILITY_SECRET: |
| 3515 |
return "SECRET"; |
| 3516 |
default: |
| 3517 |
return "UNKNOWN(" + String.valueOf(vis) + ")"; |
| 3518 |
} |
| 3519 |
} |
| 3520 |
|
| 3521 |
|
| 3522 |
|
| 3523 |
|
| 3524 |
public static String priorityToString(@Priority int pri) { |
| 3525 |
switch (pri) { |
| 3526 |
case PRIORITY_MIN: |
| 3527 |
return "MIN"; |
| 3528 |
case PRIORITY_LOW: |
| 3529 |
return "LOW"; |
| 3530 |
case PRIORITY_DEFAULT: |
| 3531 |
return "DEFAULT"; |
| 3532 |
case PRIORITY_HIGH: |
| 3533 |
return "HIGH"; |
| 3534 |
case PRIORITY_MAX: |
| 3535 |
return "MAX"; |
| 3536 |
default: |
| 3537 |
return "UNKNOWN(" + String.valueOf(pri) + ")"; |
| 3538 |
} |
| 3539 |
} |
| 3540 |
|
| 3541 |
|
| 3542 |
|
| 3543 |
|
| 3544 |
public boolean hasCompletedProgress() { |
| 3545 |
|
| 3546 |
if (!extras.containsKey(EXTRA_PROGRESS) |
| 3547 |
|| !extras.containsKey(EXTRA_PROGRESS_MAX)) { |
| 3548 |
return false; |
| 3549 |
} |
| 3550 |
|
| 3551 |
if (extras.getInt(EXTRA_PROGRESS_MAX) == 0) { |
| 3552 |
return false; |
| 3553 |
} |
| 3554 |
return extras.getInt(EXTRA_PROGRESS) == extras.getInt(EXTRA_PROGRESS_MAX); |
| 3555 |
} |
| 3556 |
|
| 3557 |
|
| 3558 |
@Deprecated |
| 3559 |
public String getChannel() { |
| 3560 |
return mChannelId; |
| 3561 |
} |
| 3562 |
|
| 3563 |
|
| 3564 |
|
| 3565 |
|
| 3566 |
public String getChannelId() { |
| 3567 |
return mChannelId; |
| 3568 |
} |
| 3569 |
|
| 3570 |
|
| 3571 |
@Deprecated |
| 3572 |
public long getTimeout() { |
| 3573 |
return mTimeout; |
| 3574 |
} |
| 3575 |
|
| 3576 |
|
| 3577 |
|
| 3578 |
|
| 3579 |
|
| 3580 |
public long getTimeoutAfter() { |
| 3581 |
return mTimeout; |
| 3582 |
} |
| 3583 |
|
| 3584 |
|
| 3585 |
|
| 3586 |
|
| 3587 |
|
| 3588 |
|
| 3589 |
public int getBadgeIconType() { |
| 3590 |
return mBadgeIcon; |
| 3591 |
} |
| 3592 |
|
| 3593 |
|
| 3594 |
|
| 3595 |
|
| 3596 |
|
| 3597 |
|
| 3598 |
|
| 3599 |
public String getShortcutId() { |
| 3600 |
return mShortcutId; |
| 3601 |
} |
| 3602 |
|
| 3603 |
|
| 3604 |
|
| 3605 |
|
| 3606 |
|
| 3607 |
|
| 3608 |
|
| 3609 |
@Nullable |
| 3610 |
public LocusId getLocusId() { |
| 3611 |
return mLocusId; |
| 3612 |
} |
| 3613 |
|
| 3614 |
|
| 3615 |
|
| 3616 |
|
| 3617 |
public CharSequence getSettingsText() { |
| 3618 |
return mSettingsText; |
| 3619 |
} |
| 3620 |
|
| 3621 |
|
| 3622 |
|
| 3623 |
|
| 3624 |
|
| 3625 |
|
| 3626 |
public @GroupAlertBehavior int getGroupAlertBehavior() { |
| 3627 |
return mGroupAlertBehavior; |
| 3628 |
} |
| 3629 |
|
| 3630 |
|
| 3631 |
|
| 3632 |
|
| 3633 |
|
| 3634 |
@Nullable |
| 3635 |
public BubbleMetadata getBubbleMetadata() { |
| 3636 |
return mBubbleMetadata; |
| 3637 |
} |
| 3638 |
|
| 3639 |
|
| 3640 |
|
| 3641 |
|
| 3642 |
|
| 3643 |
public void setBubbleMetadata(BubbleMetadata data) { |
| 3644 |
mBubbleMetadata = data; |
| 3645 |
} |
| 3646 |
|
| 3647 |
|
| 3648 |
|
| 3649 |
|
| 3650 |
|
| 3651 |
public boolean getAllowSystemGeneratedContextualActions() { |
| 3652 |
return mAllowSystemGeneratedContextualActions; |
| 3653 |
} |
| 3654 |
|
| 3655 |
|
| 3656 |
|
| 3657 |
|
| 3658 |
|
| 3659 |
|
| 3660 |
|
| 3661 |
|
| 3662 |
|
| 3663 |
public Icon getSmallIcon() { |
| 3664 |
return mSmallIcon; |
| 3665 |
} |
| 3666 |
|
| 3667 |
|
| 3668 |
|
| 3669 |
|
| 3670 |
|
| 3671 |
@UnsupportedAppUsage |
| 3672 |
public void setSmallIcon(Icon icon) { |
| 3673 |
mSmallIcon = icon; |
| 3674 |
} |
| 3675 |
|
| 3676 |
|
| 3677 |
|
| 3678 |
|
| 3679 |
|
| 3680 |
|
| 3681 |
public Icon getLargeIcon() { |
| 3682 |
return mLargeIcon; |
| 3683 |
} |
| 3684 |
|
| 3685 |
|
| 3686 |
|
| 3687 |
|
| 3688 |
@UnsupportedAppUsage |
| 3689 |
public boolean isGroupSummary() { |
| 3690 |
return mGroupKey != null && (flags & FLAG_GROUP_SUMMARY) != 0; |
| 3691 |
} |
| 3692 |
|
| 3693 |
|
| 3694 |
|
| 3695 |
|
| 3696 |
@UnsupportedAppUsage |
| 3697 |
public boolean isGroupChild() { |
| 3698 |
return mGroupKey != null && (flags & FLAG_GROUP_SUMMARY) == 0; |
| 3699 |
} |
| 3700 |
|
| 3701 |
|
| 3702 |
|
| 3703 |
|
| 3704 |
public boolean suppressAlertingDueToGrouping() { |
| 3705 |
if (isGroupSummary() |
| 3706 |
&& getGroupAlertBehavior() == Notification.GROUP_ALERT_CHILDREN) { |
| 3707 |
return true; |
| 3708 |
} else if (isGroupChild() |
| 3709 |
&& getGroupAlertBehavior() == Notification.GROUP_ALERT_SUMMARY) { |
| 3710 |
return true; |
| 3711 |
} |
| 3712 |
return false; |
| 3713 |
} |
| 3714 |
|
| 3715 |
|
| 3716 |
|
| 3717 |
|
| 3718 |
|
| 3719 |
|
| 3720 |
|
| 3721 |
|
| 3722 |
@Nullable |
| 3723 |
public Pair<RemoteInput, Action> findRemoteInputActionPair(boolean requiresFreeform) { |
| 3724 |
if (actions == null) { |
| 3725 |
return null; |
| 3726 |
} |
| 3727 |
for (Notification.Action action : actions) { |
| 3728 |
if (action.getRemoteInputs() == null) { |
| 3729 |
continue; |
| 3730 |
} |
| 3731 |
RemoteInput resultRemoteInput = null; |
| 3732 |
for (RemoteInput remoteInput : action.getRemoteInputs()) { |
| 3733 |
if (remoteInput.getAllowFreeFormInput() || !requiresFreeform) { |
| 3734 |
resultRemoteInput = remoteInput; |
| 3735 |
} |
| 3736 |
} |
| 3737 |
if (resultRemoteInput != null) { |
| 3738 |
return Pair.create(resultRemoteInput, action); |
| 3739 |
} |
| 3740 |
} |
| 3741 |
return null; |
| 3742 |
} |
| 3743 |
|
| 3744 |
|
| 3745 |
|
| 3746 |
|
| 3747 |
|
| 3748 |
public @NonNull List<Notification.Action> getContextualActions() { |
| 3749 |
if (actions == null) return Collections.emptyList(); |
| 3750 |
|
| 3751 |
List<Notification.Action> contextualActions = new ArrayList<>(); |
| 3752 |
for (Notification.Action action : actions) { |
| 3753 |
if (action.isContextual()) { |
| 3754 |
contextualActions.add(action); |
| 3755 |
} |
| 3756 |
} |
| 3757 |
return contextualActions; |
| 3758 |
} |
| 3759 |
|
| 3760 |
|
| 3761 |
|
| 3762 |
|
| 3763 |
|
| 3764 |
|
| 3765 |
|
| 3766 |
|
| 3767 |
|
| 3768 |
|
| 3769 |
|
| 3770 |
|
| 3771 |
|
| 3772 |
|
| 3773 |
|
| 3774 |
|
| 3775 |
|
| 3776 |
|
| 3777 |
|
| 3778 |
|
| 3779 |
|
| 3780 |
|
| 3781 |
public static class Builder { |
| 3782 |
|
| 3783 |
|
| 3784 |
|
| 3785 |
public static final String EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT = |
| 3786 |
"android.rebuild.contentViewActionCount"; |
| 3787 |
|
| 3788 |
|
| 3789 |
|
| 3790 |
public static final String EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT |
| 3791 |
= "android.rebuild.bigViewActionCount"; |
| 3792 |
|
| 3793 |
|
| 3794 |
|
| 3795 |
public static final String EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT |
| 3796 |
= "android.rebuild.hudViewActionCount"; |
| 3797 |
|
| 3798 |
private static final boolean USE_ONLY_TITLE_IN_LOW_PRIORITY_SUMMARY = |
| 3799 |
SystemProperties.getBoolean("notifications.only_title", true); |
| 3800 |
|
| 3801 |
|
| 3802 |
|
| 3803 |
|
| 3804 |
|
| 3805 |
private static final int LIGHTNESS_TEXT_DIFFERENCE_LIGHT = 20; |
| 3806 |
|
| 3807 |
|
| 3808 |
|
| 3809 |
|
| 3810 |
|
| 3811 |
|
| 3812 |
private static final int LIGHTNESS_TEXT_DIFFERENCE_DARK = -10; |
| 3813 |
|
| 3814 |
private Context mContext; |
| 3815 |
private Notification mN; |
| 3816 |
private Bundle mUserExtras = new Bundle(); |
| 3817 |
private Style mStyle; |
| 3818 |
@UnsupportedAppUsage |
| 3819 |
private ArrayList<Action> mActions = new ArrayList<>(MAX_ACTION_BUTTONS); |
| 3820 |
private ArrayList<Person> mPersonList = new ArrayList<>(); |
| 3821 |
private ContrastColorUtil mColorUtil; |
| 3822 |
private boolean mIsLegacy; |
| 3823 |
private boolean mIsLegacyInitialized; |
| 3824 |
|
| 3825 |
|
| 3826 |
|
| 3827 |
|
| 3828 |
|
| 3829 |
StandardTemplateParams mParams = new StandardTemplateParams(); |
| 3830 |
Colors mColors = new Colors(); |
| 3831 |
|
| 3832 |
private boolean mTintActionButtons; |
| 3833 |
private boolean mInNightMode; |
| 3834 |
|
| 3835 |
|
| 3836 |
|
| 3837 |
|
| 3838 |
|
| 3839 |
|
| 3840 |
|
| 3841 |
|
| 3842 |
|
| 3843 |
|
| 3844 |
|
| 3845 |
|
| 3846 |
|
| 3847 |
public Builder(Context context, String channelId) { |
| 3848 |
this(context, (Notification) null); |
| 3849 |
mN.mChannelId = channelId; |
| 3850 |
} |
| 3851 |
|
| 3852 |
|
| 3853 |
|
| 3854 |
|
| 3855 |
|
| 3856 |
@Deprecated |
| 3857 |
public Builder(Context context) { |
| 3858 |
this(context, (Notification) null); |
| 3859 |
} |
| 3860 |
|
| 3861 |
|
| 3862 |
|
| 3863 |
|
| 3864 |
public Builder(Context context, Notification toAdopt) { |
| 3865 |
mContext = context; |
| 3866 |
Resources res = mContext.getResources(); |
| 3867 |
mTintActionButtons = res.getBoolean(R.bool.config_tintNotificationActionButtons); |
| 3868 |
|
| 3869 |
if (res.getBoolean(R.bool.config_enableNightMode)) { |
| 3870 |
Configuration currentConfig = res.getConfiguration(); |
| 3871 |
mInNightMode = (currentConfig.uiMode & Configuration.UI_MODE_NIGHT_MASK) |
| 3872 |
== Configuration.UI_MODE_NIGHT_YES; |
| 3873 |
} |
| 3874 |
|
| 3875 |
if (toAdopt == null) { |
| 3876 |
mN = new Notification(); |
| 3877 |
if (context.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N) { |
| 3878 |
mN.extras.putBoolean(EXTRA_SHOW_WHEN, true); |
| 3879 |
} |
| 3880 |
mN.priority = PRIORITY_DEFAULT; |
| 3881 |
mN.visibility = VISIBILITY_PRIVATE; |
| 3882 |
} else { |
| 3883 |
mN = toAdopt; |
| 3884 |
if (mN.actions != null) { |
| 3885 |
Collections.addAll(mActions, mN.actions); |
| 3886 |
} |
| 3887 |
|
| 3888 |
if (mN.extras.containsKey(EXTRA_PEOPLE_LIST)) { |
| 3889 |
ArrayList<Person> people = mN.extras.getParcelableArrayList(EXTRA_PEOPLE_LIST); |
| 3890 |
mPersonList.addAll(people); |
| 3891 |
} |
| 3892 |
|
| 3893 |
if (mN.getSmallIcon() == null && mN.icon != 0) { |
| 3894 |
setSmallIcon(mN.icon); |
| 3895 |
} |
| 3896 |
|
| 3897 |
if (mN.getLargeIcon() == null && mN.largeIcon != null) { |
| 3898 |
setLargeIcon(mN.largeIcon); |
| 3899 |
} |
| 3900 |
|
| 3901 |
String templateClass = mN.extras.getString(EXTRA_TEMPLATE); |
| 3902 |
if (!TextUtils.isEmpty(templateClass)) { |
| 3903 |
final Class<? extends Style> styleClass |
| 3904 |
= getNotificationStyleClass(templateClass); |
| 3905 |
if (styleClass == null) { |
| 3906 |
Log.d(TAG, "Unknown style class: " + templateClass); |
| 3907 |
} else { |
| 3908 |
try { |
| 3909 |
final Constructor<? extends Style> ctor = |
| 3910 |
styleClass.getDeclaredConstructor(); |
| 3911 |
ctor.setAccessible(true); |
| 3912 |
final Style style = ctor.newInstance(); |
| 3913 |
style.restoreFromExtras(mN.extras); |
| 3914 |
|
| 3915 |
if (style != null) { |
| 3916 |
setStyle(style); |
| 3917 |
} |
| 3918 |
} catch (Throwable t) { |
| 3919 |
Log.e(TAG, "Could not create Style", t); |
| 3920 |
} |
| 3921 |
} |
| 3922 |
} |
| 3923 |
} |
| 3924 |
} |
| 3925 |
|
| 3926 |
private ContrastColorUtil getColorUtil() { |
| 3927 |
if (mColorUtil == null) { |
| 3928 |
mColorUtil = ContrastColorUtil.getInstance(mContext); |
| 3929 |
} |
| 3930 |
return mColorUtil; |
| 3931 |
} |
| 3932 |
|
| 3933 |
|
| 3934 |
|
| 3935 |
|
| 3936 |
|
| 3937 |
|
| 3938 |
|
| 3939 |
|
| 3940 |
|
| 3941 |
|
| 3942 |
|
| 3943 |
|
| 3944 |
|
| 3945 |
|
| 3946 |
|
| 3947 |
|
| 3948 |
|
| 3949 |
|
| 3950 |
|
| 3951 |
|
| 3952 |
|
| 3953 |
|
| 3954 |
|
| 3955 |
|
| 3956 |
|
| 3957 |
|
| 3958 |
|
| 3959 |
|
| 3960 |
|
| 3961 |
|
| 3962 |
|
| 3963 |
|
| 3964 |
|
| 3965 |
|
| 3966 |
|
| 3967 |
|
| 3968 |
|
| 3969 |
|
| 3970 |
|
| 3971 |
|
| 3972 |
|
| 3973 |
|
| 3974 |
@NonNull |
| 3975 |
public Builder setShortcutId(String shortcutId) { |
| 3976 |
mN.mShortcutId = shortcutId; |
| 3977 |
return this; |
| 3978 |
} |
| 3979 |
|
| 3980 |
|
| 3981 |
|
| 3982 |
|
| 3983 |
|
| 3984 |
|
| 3985 |
|
| 3986 |
|
| 3987 |
@NonNull |
| 3988 |
public Builder setLocusId(@Nullable LocusId locusId) { |
| 3989 |
mN.mLocusId = locusId; |
| 3990 |
return this; |
| 3991 |
} |
| 3992 |
|
| 3993 |
|
| 3994 |
|
| 3995 |
|
| 3996 |
|
| 3997 |
|
| 3998 |
|
| 3999 |
|
| 4000 |
|
| 4001 |
@NonNull |
| 4002 |
public Builder setBadgeIconType(int icon) { |
| 4003 |
mN.mBadgeIcon = icon; |
| 4004 |
return this; |
| 4005 |
} |
| 4006 |
|
| 4007 |
|
| 4008 |
|
| 4009 |
|
| 4010 |
|
| 4011 |
|
| 4012 |
|
| 4013 |
|
| 4014 |
|
| 4015 |
|
| 4016 |
|
| 4017 |
@NonNull |
| 4018 |
public Builder setGroupAlertBehavior(@GroupAlertBehavior int groupAlertBehavior) { |
| 4019 |
mN.mGroupAlertBehavior = groupAlertBehavior; |
| 4020 |
return this; |
| 4021 |
} |
| 4022 |
|
| 4023 |
|
| 4024 |
|
| 4025 |
|
| 4026 |
|
| 4027 |
|
| 4028 |
|
| 4029 |
|
| 4030 |
|
| 4031 |
|
| 4032 |
|
| 4033 |
|
| 4034 |
@NonNull |
| 4035 |
public Builder setBubbleMetadata(@Nullable BubbleMetadata data) { |
| 4036 |
mN.mBubbleMetadata = data; |
| 4037 |
return this; |
| 4038 |
} |
| 4039 |
|
| 4040 |
|
| 4041 |
@Deprecated |
| 4042 |
public Builder setChannel(String channelId) { |
| 4043 |
mN.mChannelId = channelId; |
| 4044 |
return this; |
| 4045 |
} |
| 4046 |
|
| 4047 |
|
| 4048 |
|
| 4049 |
|
| 4050 |
@NonNull |
| 4051 |
public Builder setChannelId(String channelId) { |
| 4052 |
mN.mChannelId = channelId; |
| 4053 |
return this; |
| 4054 |
} |
| 4055 |
|
| 4056 |
|
| 4057 |
@Deprecated |
| 4058 |
public Builder setTimeout(long durationMs) { |
| 4059 |
mN.mTimeout = durationMs; |
| 4060 |
return this; |
| 4061 |
} |
| 4062 |
|
| 4063 |
|
| 4064 |
|
| 4065 |
|
| 4066 |
|
| 4067 |
@NonNull |
| 4068 |
public Builder setTimeoutAfter(long durationMs) { |
| 4069 |
mN.mTimeout = durationMs; |
| 4070 |
return this; |
| 4071 |
} |
| 4072 |
|
| 4073 |
|
| 4074 |
|
| 4075 |
|
| 4076 |
|
| 4077 |
|
| 4078 |
|
| 4079 |
|
| 4080 |
|
| 4081 |
|
| 4082 |
@NonNull |
| 4083 |
public Builder setWhen(long when) { |
| 4084 |
mN.when = when; |
| 4085 |
return this; |
| 4086 |
} |
| 4087 |
|
| 4088 |
|
| 4089 |
|
| 4090 |
|
| 4091 |
|
| 4092 |
|
| 4093 |
|
| 4094 |
@NonNull |
| 4095 |
public Builder setShowWhen(boolean show) { |
| 4096 |
mN.extras.putBoolean(EXTRA_SHOW_WHEN, show); |
| 4097 |
return this; |
| 4098 |
} |
| 4099 |
|
| 4100 |
|
| 4101 |
|
| 4102 |
|
| 4103 |
|
| 4104 |
|
| 4105 |
|
| 4106 |
|
| 4107 |
|
| 4108 |
|
| 4109 |
|
| 4110 |
|
| 4111 |
|
| 4112 |
|
| 4113 |
|
| 4114 |
|
| 4115 |
@NonNull |
| 4116 |
public Builder setUsesChronometer(boolean b) { |
| 4117 |
mN.extras.putBoolean(EXTRA_SHOW_CHRONOMETER, b); |
| 4118 |
return this; |
| 4119 |
} |
| 4120 |
|
| 4121 |
|
| 4122 |
|
| 4123 |
|
| 4124 |
|
| 4125 |
|
| 4126 |
|
| 4127 |
|
| 4128 |
|
| 4129 |
@NonNull |
| 4130 |
public Builder setChronometerCountDown(boolean countDown) { |
| 4131 |
mN.extras.putBoolean(EXTRA_CHRONOMETER_COUNT_DOWN, countDown); |
| 4132 |
return this; |
| 4133 |
} |
| 4134 |
|
| 4135 |
|
| 4136 |
|
| 4137 |
|
| 4138 |
|
| 4139 |
|
| 4140 |
|
| 4141 |
|
| 4142 |
|
| 4143 |
|
| 4144 |
|
| 4145 |
|
| 4146 |
|
| 4147 |
|
| 4148 |
|
| 4149 |
@NonNull |
| 4150 |
public Builder setSmallIcon(@DrawableRes int icon) { |
| 4151 |
return setSmallIcon(icon != 0 |
| 4152 |
? Icon.createWithResource(mContext, icon) |
| 4153 |
: null); |
| 4154 |
} |
| 4155 |
|
| 4156 |
|
| 4157 |
|
| 4158 |
|
| 4159 |
|
| 4160 |
|
| 4161 |
|
| 4162 |
|
| 4163 |
|
| 4164 |
|
| 4165 |
|
| 4166 |
|
| 4167 |
@NonNull |
| 4168 |
public Builder setSmallIcon(@DrawableRes int icon, int level) { |
| 4169 |
mN.iconLevel = level; |
| 4170 |
return setSmallIcon(icon); |
| 4171 |
} |
| 4172 |
|
| 4173 |
|
| 4174 |
|
| 4175 |
|
| 4176 |
|
| 4177 |
|
| 4178 |
|
| 4179 |
|
| 4180 |
|
| 4181 |
@NonNull |
| 4182 |
public Builder setSmallIcon(Icon icon) { |
| 4183 |
mN.setSmallIcon(icon); |
| 4184 |
if (icon != null && icon.getType() == Icon.TYPE_RESOURCE) { |
| 4185 |
mN.icon = icon.getResId(); |
| 4186 |
} |
| 4187 |
return this; |
| 4188 |
} |
| 4189 |
|
| 4190 |
|
| 4191 |
|
| 4192 |
|
| 4193 |
@NonNull |
| 4194 |
public Builder setContentTitle(CharSequence title) { |
| 4195 |
mN.extras.putCharSequence(EXTRA_TITLE, safeCharSequence(title)); |
| 4196 |
return this; |
| 4197 |
} |
| 4198 |
|
| 4199 |
|
| 4200 |
|
| 4201 |
|
| 4202 |
@NonNull |
| 4203 |
public Builder setContentText(CharSequence text) { |
| 4204 |
mN.extras.putCharSequence(EXTRA_TEXT, safeCharSequence(text)); |
| 4205 |
return this; |
| 4206 |
} |
| 4207 |
|
| 4208 |
|
| 4209 |
|
| 4210 |
|
| 4211 |
|
| 4212 |
|
| 4213 |
|
| 4214 |
|
| 4215 |
|
| 4216 |
|
| 4217 |
|
| 4218 |
|
| 4219 |
|
| 4220 |
|
| 4221 |
|
| 4222 |
|
| 4223 |
|
| 4224 |
|
| 4225 |
|
| 4226 |
@NonNull |
| 4227 |
public Builder setSubText(CharSequence text) { |
| 4228 |
mN.extras.putCharSequence(EXTRA_SUB_TEXT, safeCharSequence(text)); |
| 4229 |
return this; |
| 4230 |
} |
| 4231 |
|
| 4232 |
|
| 4233 |
|
| 4234 |
|
| 4235 |
|
| 4236 |
|
| 4237 |
|
| 4238 |
|
| 4239 |
|
| 4240 |
|
| 4241 |
|
| 4242 |
|
| 4243 |
|
| 4244 |
|
| 4245 |
@NonNull |
| 4246 |
public Builder setSettingsText(CharSequence text) { |
| 4247 |
mN.mSettingsText = safeCharSequence(text); |
| 4248 |
return this; |
| 4249 |
} |
| 4250 |
|
| 4251 |
|
| 4252 |
|
| 4253 |
|
| 4254 |
|
| 4255 |
|
| 4256 |
|
| 4257 |
|
| 4258 |
|
| 4259 |
|
| 4260 |
|
| 4261 |
|
| 4262 |
|
| 4263 |
|
| 4264 |
|
| 4265 |
@NonNull |
| 4266 |
public Builder setRemoteInputHistory(CharSequence[] text) { |
| 4267 |
if (text == null) { |
| 4268 |
mN.extras.putCharSequenceArray(EXTRA_REMOTE_INPUT_HISTORY, null); |
| 4269 |
} else { |
| 4270 |
final int itemCount = Math.min(MAX_REPLY_HISTORY, text.length); |
| 4271 |
CharSequence[] safe = new CharSequence[itemCount]; |
| 4272 |
RemoteInputHistoryItem[] items = new RemoteInputHistoryItem[itemCount]; |
| 4273 |
for (int i = 0; i < itemCount; i++) { |
| 4274 |
safe[i] = safeCharSequence(text[i]); |
| 4275 |
items[i] = new RemoteInputHistoryItem(text[i]); |
| 4276 |
} |
| 4277 |
mN.extras.putCharSequenceArray(EXTRA_REMOTE_INPUT_HISTORY, safe); |
| 4278 |
|
| 4279 |
|
| 4280 |
mN.extras.putParcelableArray(EXTRA_REMOTE_INPUT_HISTORY_ITEMS, items); |
| 4281 |
} |
| 4282 |
return this; |
| 4283 |
} |
| 4284 |
|
| 4285 |
|
| 4286 |
|
| 4287 |
|
| 4288 |
|
| 4289 |
|
| 4290 |
@NonNull |
| 4291 |
public Builder setRemoteInputHistory(RemoteInputHistoryItem[] items) { |
| 4292 |
if (items == null) { |
| 4293 |
mN.extras.putParcelableArray(EXTRA_REMOTE_INPUT_HISTORY_ITEMS, null); |
| 4294 |
} else { |
| 4295 |
final int itemCount = Math.min(MAX_REPLY_HISTORY, items.length); |
| 4296 |
RemoteInputHistoryItem[] history = new RemoteInputHistoryItem[itemCount]; |
| 4297 |
for (int i = 0; i < itemCount; i++) { |
| 4298 |
history[i] = items[i]; |
| 4299 |
} |
| 4300 |
mN.extras.putParcelableArray(EXTRA_REMOTE_INPUT_HISTORY_ITEMS, history); |
| 4301 |
} |
| 4302 |
return this; |
| 4303 |
} |
| 4304 |
|
| 4305 |
|
| 4306 |
|
| 4307 |
|
| 4308 |
|
| 4309 |
@NonNull |
| 4310 |
public Builder setShowRemoteInputSpinner(boolean showSpinner) { |
| 4311 |
mN.extras.putBoolean(EXTRA_SHOW_REMOTE_INPUT_SPINNER, showSpinner); |
| 4312 |
return this; |
| 4313 |
} |
| 4314 |
|
| 4315 |
|
| 4316 |
|
| 4317 |
|
| 4318 |
|
| 4319 |
@NonNull |
| 4320 |
public Builder setHideSmartReplies(boolean hideSmartReplies) { |
| 4321 |
mN.extras.putBoolean(EXTRA_HIDE_SMART_REPLIES, hideSmartReplies); |
| 4322 |
return this; |
| 4323 |
} |
| 4324 |
|
| 4325 |
|
| 4326 |
|
| 4327 |
|
| 4328 |
|
| 4329 |
@NonNull |
| 4330 |
public Builder setNumber(int number) { |
| 4331 |
mN.number = number; |
| 4332 |
return this; |
| 4333 |
} |
| 4334 |
|
| 4335 |
|
| 4336 |
|
| 4337 |
|
| 4338 |
|
| 4339 |
|
| 4340 |
|
| 4341 |
|
| 4342 |
|
| 4343 |
|
| 4344 |
|
| 4345 |
@Deprecated |
| 4346 |
public Builder setContentInfo(CharSequence info) { |
| 4347 |
mN.extras.putCharSequence(EXTRA_INFO_TEXT, safeCharSequence(info)); |
| 4348 |
return this; |
| 4349 |
} |
| 4350 |
|
| 4351 |
|
| 4352 |
|
| 4353 |
|
| 4354 |
|
| 4355 |
|
| 4356 |
@NonNull |
| 4357 |
public Builder setProgress(int max, int progress, boolean indeterminate) { |
| 4358 |
mN.extras.putInt(EXTRA_PROGRESS, progress); |
| 4359 |
mN.extras.putInt(EXTRA_PROGRESS_MAX, max); |
| 4360 |
mN.extras.putBoolean(EXTRA_PROGRESS_INDETERMINATE, indeterminate); |
| 4361 |
return this; |
| 4362 |
} |
| 4363 |
|
| 4364 |
|
| 4365 |
|
| 4366 |
|
| 4367 |
|
| 4368 |
|
| 4369 |
@Deprecated |
| 4370 |
public Builder setContent(RemoteViews views) { |
| 4371 |
return setCustomContentView(views); |
| 4372 |
} |
| 4373 |
|
| 4374 |
|
| 4375 |
|
| 4376 |
|
| 4377 |
|
| 4378 |
|
| 4379 |
|
| 4380 |
@NonNull |
| 4381 |
public Builder setCustomContentView(RemoteViews contentView) { |
| 4382 |
mN.contentView = contentView; |
| 4383 |
return this; |
| 4384 |
} |
| 4385 |
|
| 4386 |
|
| 4387 |
|
| 4388 |
|
| 4389 |
|
| 4390 |
|
| 4391 |
|
| 4392 |
@NonNull |
| 4393 |
public Builder setCustomBigContentView(RemoteViews contentView) { |
| 4394 |
mN.bigContentView = contentView; |
| 4395 |
return this; |
| 4396 |
} |
| 4397 |
|
| 4398 |
|
| 4399 |
|
| 4400 |
|
| 4401 |
|
| 4402 |
|
| 4403 |
|
| 4404 |
@NonNull |
| 4405 |
public Builder setCustomHeadsUpContentView(RemoteViews contentView) { |
| 4406 |
mN.headsUpContentView = contentView; |
| 4407 |
return this; |
| 4408 |
} |
| 4409 |
|
| 4410 |
|
| 4411 |
|
| 4412 |
|
| 4413 |
|
| 4414 |
|
| 4415 |
|
| 4416 |
|
| 4417 |
|
| 4418 |
|
| 4419 |
|
| 4420 |
|
| 4421 |
|
| 4422 |
|
| 4423 |
|
| 4424 |
|
| 4425 |
|
| 4426 |
|
| 4427 |
@NonNull |
| 4428 |
public Builder setContentIntent(PendingIntent intent) { |
| 4429 |
mN.contentIntent = intent; |
| 4430 |
return this; |
| 4431 |
} |
| 4432 |
|
| 4433 |
|
| 4434 |
|
| 4435 |
|
| 4436 |
|
| 4437 |
|
| 4438 |
@NonNull |
| 4439 |
public Builder setDeleteIntent(PendingIntent intent) { |
| 4440 |
mN.deleteIntent = intent; |
| 4441 |
return this; |
| 4442 |
} |
| 4443 |
|
| 4444 |
|
| 4445 |
|
| 4446 |
|
| 4447 |
|
| 4448 |
|
| 4449 |
|
| 4450 |
|
| 4451 |
|
| 4452 |
|
| 4453 |
|
| 4454 |
|
| 4455 |
|
| 4456 |
|
| 4457 |
|
| 4458 |
|
| 4459 |
|
| 4460 |
|
| 4461 |
|
| 4462 |
|
| 4463 |
|
| 4464 |
|
| 4465 |
|
| 4466 |
|
| 4467 |
|
| 4468 |
|
| 4469 |
|
| 4470 |
|
| 4471 |
@NonNull |
| 4472 |
public Builder setFullScreenIntent(PendingIntent intent, boolean highPriority) { |
| 4473 |
mN.fullScreenIntent = intent; |
| 4474 |
setFlag(FLAG_HIGH_PRIORITY, highPriority); |
| 4475 |
return this; |
| 4476 |
} |
| 4477 |
|
| 4478 |
|
| 4479 |
|
| 4480 |
|
| 4481 |
|
| 4482 |
|
| 4483 |
@NonNull |
| 4484 |
public Builder setTicker(CharSequence tickerText) { |
| 4485 |
mN.tickerText = safeCharSequence(tickerText); |
| 4486 |
return this; |
| 4487 |
} |
| 4488 |
|
| 4489 |
|
| 4490 |
|
| 4491 |
|
| 4492 |
|
| 4493 |
@Deprecated |
| 4494 |
public Builder setTicker(CharSequence tickerText, RemoteViews views) { |
| 4495 |
setTicker(tickerText); |
| 4496 |
|
| 4497 |
return this; |
| 4498 |
} |
| 4499 |
|
| 4500 |
|
| 4501 |
|
| 4502 |
|
| 4503 |
|
| 4504 |
|
| 4505 |
|
| 4506 |
|
| 4507 |
@NonNull |
| 4508 |
public Builder setLargeIcon(Bitmap b) { |
| 4509 |
return setLargeIcon(b != null ? Icon.createWithBitmap(b) : null); |
| 4510 |
} |
| 4511 |
|
| 4512 |
|
| 4513 |
|
| 4514 |
|
| 4515 |
|
| 4516 |
|
| 4517 |
|
| 4518 |
|
| 4519 |
@NonNull |
| 4520 |
public Builder setLargeIcon(Icon icon) { |
| 4521 |
mN.mLargeIcon = icon; |
| 4522 |
mN.extras.putParcelable(EXTRA_LARGE_ICON, icon); |
| 4523 |
return this; |
| 4524 |
} |
| 4525 |
|
| 4526 |
|
| 4527 |
|
| 4528 |
|
| 4529 |
|
| 4530 |
|
| 4531 |
|
| 4532 |
|
| 4533 |
|
| 4534 |
@Deprecated |
| 4535 |
public Builder setSound(Uri sound) { |
| 4536 |
mN.sound = sound; |
| 4537 |
mN.audioAttributes = AUDIO_ATTRIBUTES_DEFAULT; |
| 4538 |
return this; |
| 4539 |
} |
| 4540 |
|
| 4541 |
|
| 4542 |
|
| 4543 |
|
| 4544 |
|
| 4545 |
|
| 4546 |
|
| 4547 |
|
| 4548 |
@Deprecated |
| 4549 |
public Builder setSound(Uri sound, int streamType) { |
| 4550 |
PlayerBase.deprecateStreamTypeForPlayback(streamType, "Notification", "setSound()"); |
| 4551 |
mN.sound = sound; |
| 4552 |
mN.audioStreamType = streamType; |
| 4553 |
return this; |
| 4554 |
} |
| 4555 |
|
| 4556 |
|
| 4557 |
|
| 4558 |
|
| 4559 |
|
| 4560 |
|
| 4561 |
|
| 4562 |
|
| 4563 |
@Deprecated |
| 4564 |
public Builder setSound(Uri sound, AudioAttributes audioAttributes) { |
| 4565 |
mN.sound = sound; |
| 4566 |
mN.audioAttributes = audioAttributes; |
| 4567 |
return this; |
| 4568 |
} |
| 4569 |
|
| 4570 |
|
| 4571 |
|
| 4572 |
|
| 4573 |
|
| 4574 |
|
| 4575 |
|
| 4576 |
|
| 4577 |
|
| 4578 |
|
| 4579 |
|
| 4580 |
|
| 4581 |
|
| 4582 |
|
| 4583 |
@Deprecated |
| 4584 |
public Builder setVibrate(long[] pattern) { |
| 4585 |
mN.vibrate = pattern; |
| 4586 |
return this; |
| 4587 |
} |
| 4588 |
|
| 4589 |
|
| 4590 |
|
| 4591 |
|
| 4592 |
|
| 4593 |
|
| 4594 |
|
| 4595 |
|
| 4596 |
|
| 4597 |
|
| 4598 |
|
| 4599 |
|
| 4600 |
|
| 4601 |
@Deprecated |
| 4602 |
public Builder setLights(@ColorInt int argb, int onMs, int offMs) { |
| 4603 |
mN.ledARGB = argb; |
| 4604 |
mN.ledOnMS = onMs; |
| 4605 |
mN.ledOffMS = offMs; |
| 4606 |
if (onMs != 0 || offMs != 0) { |
| 4607 |
mN.flags |= FLAG_SHOW_LIGHTS; |
| 4608 |
} |
| 4609 |
return this; |
| 4610 |
} |
| 4611 |
|
| 4612 |
|
| 4613 |
|
| 4614 |
|
| 4615 |
|
| 4616 |
|
| 4617 |
|
| 4618 |
|
| 4619 |
|
| 4620 |
|
| 4621 |
|
| 4622 |
|
| 4623 |
|
| 4624 |
|
| 4625 |
|
| 4626 |
|
| 4627 |
@NonNull |
| 4628 |
public Builder setOngoing(boolean ongoing) { |
| 4629 |
setFlag(FLAG_ONGOING_EVENT, ongoing); |
| 4630 |
return this; |
| 4631 |
} |
| 4632 |
|
| 4633 |
|
| 4634 |
|
| 4635 |
|
| 4636 |
|
| 4637 |
|
| 4638 |
|
| 4639 |
|
| 4640 |
|
| 4641 |
|
| 4642 |
|
| 4643 |
|
| 4644 |
|
| 4645 |
|
| 4646 |
|
| 4647 |
|
| 4648 |
@NonNull |
| 4649 |
public Builder setColorized(boolean colorize) { |
| 4650 |
mN.extras.putBoolean(EXTRA_COLORIZED, colorize); |
| 4651 |
return this; |
| 4652 |
} |
| 4653 |
|
| 4654 |
|
| 4655 |
|
| 4656 |
|
| 4657 |
|
| 4658 |
|
| 4659 |
|
| 4660 |
|
| 4661 |
|
| 4662 |
|
| 4663 |
@NonNull |
| 4664 |
public Builder setOnlyAlertOnce(boolean onlyAlertOnce) { |
| 4665 |
setFlag(FLAG_ONLY_ALERT_ONCE, onlyAlertOnce); |
| 4666 |
return this; |
| 4667 |
} |
| 4668 |
|
| 4669 |
|
| 4670 |
|
| 4671 |
|
| 4672 |
|
| 4673 |
|
| 4674 |
|
| 4675 |
|
| 4676 |
|
| 4677 |
|
| 4678 |
|
| 4679 |
|
| 4680 |
|
| 4681 |
|
| 4682 |
|
| 4683 |
|
| 4684 |
|
| 4685 |
|
| 4686 |
|
| 4687 |
|
| 4688 |
|
| 4689 |
@NonNull |
| 4690 |
public Builder setForegroundServiceBehavior(@ServiceNotificationPolicy int behavior) { |
| 4691 |
mN.mFgsDeferBehavior = behavior; |
| 4692 |
return this; |
| 4693 |
} |
| 4694 |
|
| 4695 |
|
| 4696 |
|
| 4697 |
|
| 4698 |
|
| 4699 |
|
| 4700 |
@NonNull |
| 4701 |
public Builder setAutoCancel(boolean autoCancel) { |
| 4702 |
setFlag(FLAG_AUTO_CANCEL, autoCancel); |
| 4703 |
return this; |
| 4704 |
} |
| 4705 |
|
| 4706 |
|
| 4707 |
|
| 4708 |
|
| 4709 |
|
| 4710 |
|
| 4711 |
|
| 4712 |
@NonNull |
| 4713 |
public Builder setLocalOnly(boolean localOnly) { |
| 4714 |
setFlag(FLAG_LOCAL_ONLY, localOnly); |
| 4715 |
return this; |
| 4716 |
} |
| 4717 |
|
| 4718 |
|
| 4719 |
|
| 4720 |
|
| 4721 |
|
| 4722 |
|
| 4723 |
|
| 4724 |
|
| 4725 |
|
| 4726 |
|
| 4727 |
|
| 4728 |
|
| 4729 |
|
| 4730 |
|
| 4731 |
@Deprecated |
| 4732 |
public Builder setDefaults(int defaults) { |
| 4733 |
mN.defaults = defaults; |
| 4734 |
return this; |
| 4735 |
} |
| 4736 |
|
| 4737 |
|
| 4738 |
|
| 4739 |
|
| 4740 |
|
| 4741 |
|
| 4742 |
|
| 4743 |
@Deprecated |
| 4744 |
public Builder setPriority(@Priority int pri) { |
| 4745 |
mN.priority = pri; |
| 4746 |
return this; |
| 4747 |
} |
| 4748 |
|
| 4749 |
|
| 4750 |
|
| 4751 |
|
| 4752 |
|
| 4753 |
|
| 4754 |
@NonNull |
| 4755 |
public Builder setCategory(String category) { |
| 4756 |
mN.category = category; |
| 4757 |
return this; |
| 4758 |
} |
| 4759 |
|
| 4760 |
|
| 4761 |
|
| 4762 |
|
| 4763 |
|
| 4764 |
|
| 4765 |
|
| 4766 |
|
| 4767 |
|
| 4768 |
|
| 4769 |
|
| 4770 |
|
| 4771 |
|
| 4772 |
|
| 4773 |
|
| 4774 |
|
| 4775 |
|
| 4776 |
|
| 4777 |
|
| 4778 |
|
| 4779 |
|
| 4780 |
|
| 4781 |
|
| 4782 |
|
| 4783 |
|
| 4784 |
|
| 4785 |
|
| 4786 |
|
| 4787 |
public Builder addPerson(String uri) { |
| 4788 |
addPerson(new Person.Builder().setUri(uri).build()); |
| 4789 |
return this; |
| 4790 |
} |
| 4791 |
|
| 4792 |
|
| 4793 |
|
| 4794 |
|
| 4795 |
|
| 4796 |
|
| 4797 |
|
| 4798 |
|
| 4799 |
|
| 4800 |
|
| 4801 |
|
| 4802 |
|
| 4803 |
|
| 4804 |
|
| 4805 |
|
| 4806 |
|
| 4807 |
|
| 4808 |
|
| 4809 |
|
| 4810 |
|
| 4811 |
|
| 4812 |
@NonNull |
| 4813 |
public Builder addPerson(Person person) { |
| 4814 |
mPersonList.add(person); |
| 4815 |
return this; |
| 4816 |
} |
| 4817 |
|
| 4818 |
|
| 4819 |
|
| 4820 |
|
| 4821 |
|
| 4822 |
|
| 4823 |
|
| 4824 |
|
| 4825 |
|
| 4826 |
|
| 4827 |
|
| 4828 |
|
| 4829 |
@NonNull |
| 4830 |
public Builder setGroup(String groupKey) { |
| 4831 |
mN.mGroupKey = groupKey; |
| 4832 |
return this; |
| 4833 |
} |
| 4834 |
|
| 4835 |
|
| 4836 |
|
| 4837 |
|
| 4838 |
|
| 4839 |
|
| 4840 |
|
| 4841 |
|
| 4842 |
|
| 4843 |
@NonNull |
| 4844 |
public Builder setGroupSummary(boolean isGroupSummary) { |
| 4845 |
setFlag(FLAG_GROUP_SUMMARY, isGroupSummary); |
| 4846 |
return this; |
| 4847 |
} |
| 4848 |
|
| 4849 |
|
| 4850 |
|
| 4851 |
|
| 4852 |
|
| 4853 |
|
| 4854 |
|
| 4855 |
|
| 4856 |
|
| 4857 |
|
| 4858 |
|
| 4859 |
|
| 4860 |
|
| 4861 |
@NonNull |
| 4862 |
public Builder setSortKey(String sortKey) { |
| 4863 |
mN.mSortKey = sortKey; |
| 4864 |
return this; |
| 4865 |
} |
| 4866 |
|
| 4867 |
|
| 4868 |
|
| 4869 |
|
| 4870 |
|
| 4871 |
|
| 4872 |
|
| 4873 |
|
| 4874 |
@NonNull |
| 4875 |
public Builder addExtras(Bundle extras) { |
| 4876 |
if (extras != null) { |
| 4877 |
mUserExtras.putAll(extras); |
| 4878 |
} |
| 4879 |
return this; |
| 4880 |
} |
| 4881 |
|
| 4882 |
|
| 4883 |
|
| 4884 |
|
| 4885 |
|
| 4886 |
|
| 4887 |
|
| 4888 |
|
| 4889 |
|
| 4890 |
|
| 4891 |
|
| 4892 |
|
| 4893 |
|
| 4894 |
@NonNull |
| 4895 |
public Builder setExtras(Bundle extras) { |
| 4896 |
if (extras != null) { |
| 4897 |
mUserExtras = extras; |
| 4898 |
} |
| 4899 |
return this; |
| 4900 |
} |
| 4901 |
|
| 4902 |
|
| 4903 |
|
| 4904 |
|
| 4905 |
|
| 4906 |
|
| 4907 |
|
| 4908 |
|
| 4909 |
|
| 4910 |
|
| 4911 |
|
| 4912 |
public Bundle getExtras() { |
| 4913 |
return mUserExtras; |
| 4914 |
} |
| 4915 |
|
| 4916 |
private Bundle getAllExtras() { |
| 4917 |
final Bundle saveExtras = (Bundle) mUserExtras.clone(); |
| 4918 |
saveExtras.putAll(mN.extras); |
| 4919 |
return saveExtras; |
| 4920 |
} |
| 4921 |
|
| 4922 |
|
| 4923 |
|
| 4924 |
|
| 4925 |
|
| 4926 |
|
| 4927 |
|
| 4928 |
|
| 4929 |
|
| 4930 |
|
| 4931 |
|
| 4932 |
|
| 4933 |
|
| 4934 |
|
| 4935 |
|
| 4936 |
|
| 4937 |
|
| 4938 |
|
| 4939 |
|
| 4940 |
|
| 4941 |
|
| 4942 |
|
| 4943 |
|
| 4944 |
|
| 4945 |
|
| 4946 |
|
| 4947 |
|
| 4948 |
|
| 4949 |
|
| 4950 |
|
| 4951 |
|
| 4952 |
|
| 4953 |
@Deprecated |
| 4954 |
public Builder addAction(int icon, CharSequence title, PendingIntent intent) { |
| 4955 |
mActions.add(new Action(icon, safeCharSequence(title), intent)); |
| 4956 |
return this; |
| 4957 |
} |
| 4958 |
|
| 4959 |
|
| 4960 |
|
| 4961 |
|
| 4962 |
|
| 4963 |
|
| 4964 |
|
| 4965 |
|
| 4966 |
|
| 4967 |
|
| 4968 |
|
| 4969 |
|
| 4970 |
|
| 4971 |
|
| 4972 |
|
| 4973 |
|
| 4974 |
@NonNull |
| 4975 |
public Builder addAction(Action action) { |
| 4976 |
if (action != null) { |
| 4977 |
mActions.add(action); |
| 4978 |
} |
| 4979 |
return this; |
| 4980 |
} |
| 4981 |
|
| 4982 |
|
| 4983 |
|
| 4984 |
|
| 4985 |
|
| 4986 |
|
| 4987 |
|
| 4988 |
|
| 4989 |
@NonNull |
| 4990 |
public Builder setActions(Action... actions) { |
| 4991 |
mActions.clear(); |
| 4992 |
for (int i = 0; i < actions.length; i++) { |
| 4993 |
if (actions[i] != null) { |
| 4994 |
mActions.add(actions[i]); |
| 4995 |
} |
| 4996 |
} |
| 4997 |
return this; |
| 4998 |
} |
| 4999 |
|
| 5000 |
|
| 5001 |
|
| 5002 |
|
| 5003 |
|
| 5004 |
|
| 5005 |
@NonNull |
| 5006 |
public Builder setStyle(Style style) { |
| 5007 |
if (mStyle != style) { |
| 5008 |
mStyle = style; |
| 5009 |
if (mStyle != null) { |
| 5010 |
mStyle.setBuilder(this); |
| 5011 |
mN.extras.putString(EXTRA_TEMPLATE, style.getClass().getName()); |
| 5012 |
} else { |
| 5013 |
mN.extras.remove(EXTRA_TEMPLATE); |
| 5014 |
} |
| 5015 |
} |
| 5016 |
return this; |
| 5017 |
} |
| 5018 |
|
| 5019 |
|
| 5020 |
|
| 5021 |
|
| 5022 |
public Style getStyle() { |
| 5023 |
return mStyle; |
| 5024 |
} |
| 5025 |
|
| 5026 |
|
| 5027 |
|
| 5028 |
|
| 5029 |
|
| 5030 |
|
| 5031 |
@NonNull |
| 5032 |
public Builder setVisibility(@Visibility int visibility) { |
| 5033 |
mN.visibility = visibility; |
| 5034 |
return this; |
| 5035 |
} |
| 5036 |
|
| 5037 |
|
| 5038 |
|
| 5039 |
|
| 5040 |
|
| 5041 |
|
| 5042 |
|
| 5043 |
@NonNull |
| 5044 |
public Builder setPublicVersion(Notification n) { |
| 5045 |
if (n != null) { |
| 5046 |
mN.publicVersion = new Notification(); |
| 5047 |
n.cloneInto(mN.publicVersion, true); |
| 5048 |
} else { |
| 5049 |
mN.publicVersion = null; |
| 5050 |
} |
| 5051 |
return this; |
| 5052 |
} |
| 5053 |
|
| 5054 |
|
| 5055 |
|
| 5056 |
|
| 5057 |
|
| 5058 |
@NonNull |
| 5059 |
public Builder extend(Extender extender) { |
| 5060 |
extender.extend(this); |
| 5061 |
return this; |
| 5062 |
} |
| 5063 |
|
| 5064 |
|
| 5065 |
|
| 5066 |
|
| 5067 |
|
| 5068 |
|
| 5069 |
|
| 5070 |
|
| 5071 |
|
| 5072 |
@NonNull |
| 5073 |
public Builder setFlag(@NotificationFlags int mask, boolean value) { |
| 5074 |
if (value) { |
| 5075 |
mN.flags |= mask; |
| 5076 |
} else { |
| 5077 |
mN.flags &= ~mask; |
| 5078 |
} |
| 5079 |
return this; |
| 5080 |
} |
| 5081 |
|
| 5082 |
|
| 5083 |
|
| 5084 |
|
| 5085 |
|
| 5086 |
|
| 5087 |
|
| 5088 |
|
| 5089 |
@NonNull |
| 5090 |
public Builder setColor(@ColorInt int argb) { |
| 5091 |
mN.color = argb; |
| 5092 |
sanitizeColor(); |
| 5093 |
return this; |
| 5094 |
} |
| 5095 |
|
| 5096 |
private void bindPhishingAlertIcon(RemoteViews contentView, StandardTemplateParams p) { |
| 5097 |
contentView.setDrawableTint( |
| 5098 |
R.id.phishing_alert, |
| 5099 |
false , |
| 5100 |
getColors(p).getErrorColor(), |
| 5101 |
PorterDuff.Mode.SRC_ATOP); |
| 5102 |
} |
| 5103 |
|
| 5104 |
private Drawable getProfileBadgeDrawable() { |
| 5105 |
if (mContext.getUserId() == UserHandle.USER_SYSTEM) { |
| 5106 |
|
| 5107 |
|
| 5108 |
return null; |
| 5109 |
} |
| 5110 |
|
| 5111 |
|
| 5112 |
DevicePolicyManager dpm = mContext.getSystemService(DevicePolicyManager.class); |
| 5113 |
return dpm.getResources().getDrawable( |
| 5114 |
getUpdatableProfileBadgeId(), SOLID_COLORED, NOTIFICATION, |
| 5115 |
this::getDefaultProfileBadgeDrawable); |
| 5116 |
} |
| 5117 |
|
| 5118 |
private String getUpdatableProfileBadgeId() { |
| 5119 |
return mContext.getSystemService(UserManager.class).isManagedProfile() |
| 5120 |
? WORK_PROFILE_ICON : UNDEFINED; |
| 5121 |
} |
| 5122 |
|
| 5123 |
private Drawable getDefaultProfileBadgeDrawable() { |
| 5124 |
return mContext.getPackageManager().getUserBadgeForDensityNoBackground( |
| 5125 |
new UserHandle(mContext.getUserId()), 0); |
| 5126 |
} |
| 5127 |
|
| 5128 |
private Bitmap getProfileBadge() { |
| 5129 |
Drawable badge = getProfileBadgeDrawable(); |
| 5130 |
if (badge == null) { |
| 5131 |
return null; |
| 5132 |
} |
| 5133 |
final int size = mContext.getResources().getDimensionPixelSize( |
| 5134 |
R.dimen.notification_badge_size); |
| 5135 |
Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); |
| 5136 |
Canvas canvas = new Canvas(bitmap); |
| 5137 |
badge.setBounds(0, 0, size, size); |
| 5138 |
badge.draw(canvas); |
| 5139 |
return bitmap; |
| 5140 |
} |
| 5141 |
|
| 5142 |
private void bindProfileBadge(RemoteViews contentView, StandardTemplateParams p) { |
| 5143 |
Bitmap profileBadge = getProfileBadge(); |
| 5144 |
|
| 5145 |
if (profileBadge != null) { |
| 5146 |
contentView.setImageViewBitmap(R.id.profile_badge, profileBadge); |
| 5147 |
contentView.setViewVisibility(R.id.profile_badge, View.VISIBLE); |
| 5148 |
if (isBackgroundColorized(p)) { |
| 5149 |
contentView.setDrawableTint(R.id.profile_badge, false, |
| 5150 |
getPrimaryTextColor(p), PorterDuff.Mode.SRC_ATOP); |
| 5151 |
} |
| 5152 |
} |
| 5153 |
} |
| 5154 |
|
| 5155 |
private void bindAlertedIcon(RemoteViews contentView, StandardTemplateParams p) { |
| 5156 |
contentView.setDrawableTint( |
| 5157 |
R.id.alerted_icon, |
| 5158 |
false , |
| 5159 |
getColors(p).getSecondaryTextColor(), |
| 5160 |
PorterDuff.Mode.SRC_IN); |
| 5161 |
} |
| 5162 |
|
| 5163 |
|
| 5164 |
|
| 5165 |
|
| 5166 |
public boolean usesStandardHeader() { |
| 5167 |
if (mN.mUsesStandardHeader) { |
| 5168 |
return true; |
| 5169 |
} |
| 5170 |
if (mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.N) { |
| 5171 |
if (mN.contentView == null && mN.bigContentView == null) { |
| 5172 |
return true; |
| 5173 |
} |
| 5174 |
} |
| 5175 |
boolean contentViewUsesHeader = mN.contentView == null |
| 5176 |
|| STANDARD_LAYOUTS.contains(mN.contentView.getLayoutId()); |
| 5177 |
boolean bigContentViewUsesHeader = mN.bigContentView == null |
| 5178 |
|| STANDARD_LAYOUTS.contains(mN.bigContentView.getLayoutId()); |
| 5179 |
return contentViewUsesHeader && bigContentViewUsesHeader; |
| 5180 |
} |
| 5181 |
|
| 5182 |
private void resetStandardTemplate(RemoteViews contentView) { |
| 5183 |
resetNotificationHeader(contentView); |
| 5184 |
contentView.setViewVisibility(R.id.right_icon, View.GONE); |
| 5185 |
contentView.setViewVisibility(R.id.title, View.GONE); |
| 5186 |
contentView.setTextViewText(R.id.title, null); |
| 5187 |
contentView.setViewVisibility(R.id.text, View.GONE); |
| 5188 |
contentView.setTextViewText(R.id.text, null); |
| 5189 |
} |
| 5190 |
|
| 5191 |
|
| 5192 |
|
| 5193 |
|
| 5194 |
private void resetNotificationHeader(RemoteViews contentView) { |
| 5195 |
|
| 5196 |
|
| 5197 |
contentView.setBoolean(R.id.expand_button, "setExpanded", false); |
| 5198 |
contentView.setViewVisibility(R.id.app_name_text, View.GONE); |
| 5199 |
contentView.setTextViewText(R.id.app_name_text, null); |
| 5200 |
contentView.setViewVisibility(R.id.chronometer, View.GONE); |
| 5201 |
contentView.setViewVisibility(R.id.header_text, View.GONE); |
| 5202 |
contentView.setTextViewText(R.id.header_text, null); |
| 5203 |
contentView.setViewVisibility(R.id.header_text_secondary, View.GONE); |
| 5204 |
contentView.setTextViewText(R.id.header_text_secondary, null); |
| 5205 |
contentView.setViewVisibility(R.id.header_text_divider, View.GONE); |
| 5206 |
contentView.setViewVisibility(R.id.header_text_secondary_divider, View.GONE); |
| 5207 |
contentView.setViewVisibility(R.id.time_divider, View.GONE); |
| 5208 |
contentView.setViewVisibility(R.id.time, View.GONE); |
| 5209 |
contentView.setImageViewIcon(R.id.profile_badge, null); |
| 5210 |
contentView.setViewVisibility(R.id.profile_badge, View.GONE); |
| 5211 |
mN.mUsesStandardHeader = false; |
| 5212 |
} |
| 5213 |
|
| 5214 |
private RemoteViews applyStandardTemplate(int resId, StandardTemplateParams p, |
| 5215 |
TemplateBindResult result) { |
| 5216 |
p.headerless(resId == getBaseLayoutResource() |
| 5217 |
|| resId == getHeadsUpBaseLayoutResource() |
| 5218 |
|| resId == getMessagingLayoutResource() |
| 5219 |
|| resId == R.layout.notification_template_material_media); |
| 5220 |
RemoteViews contentView = new BuilderRemoteViews(mContext.getApplicationInfo(), resId); |
| 5221 |
|
| 5222 |
resetStandardTemplate(contentView); |
| 5223 |
|
| 5224 |
final Bundle ex = mN.extras; |
| 5225 |
updateBackgroundColor(contentView, p); |
| 5226 |
bindNotificationHeader(contentView, p); |
| 5227 |
bindLargeIconAndApplyMargin(contentView, p, result); |
| 5228 |
boolean showProgress = handleProgressBar(contentView, ex, p); |
| 5229 |
boolean hasSecondLine = showProgress; |
| 5230 |
if (p.hasTitle()) { |
| 5231 |
contentView.setViewVisibility(p.mTitleViewId, View.VISIBLE); |
| 5232 |
contentView.setTextViewText(p.mTitleViewId, processTextSpans(p.title)); |
| 5233 |
setTextViewColorPrimary(contentView, p.mTitleViewId, p); |
| 5234 |
} else if (p.mTitleViewId != R.id.title) { |
| 5235 |
|
| 5236 |
contentView.setViewVisibility(p.mTitleViewId, View.GONE); |
| 5237 |
contentView.setTextViewText(p.mTitleViewId, null); |
| 5238 |
} |
| 5239 |
if (p.text != null && p.text.length() != 0 |
| 5240 |
&& (!showProgress || p.mAllowTextWithProgress)) { |
| 5241 |
contentView.setViewVisibility(p.mTextViewId, View.VISIBLE); |
| 5242 |
contentView.setTextViewText(p.mTextViewId, processTextSpans(p.text)); |
| 5243 |
setTextViewColorSecondary(contentView, p.mTextViewId, p); |
| 5244 |
hasSecondLine = true; |
| 5245 |
} else if (p.mTextViewId != R.id.text) { |
| 5246 |
|
| 5247 |
contentView.setViewVisibility(p.mTextViewId, View.GONE); |
| 5248 |
contentView.setTextViewText(p.mTextViewId, null); |
| 5249 |
} |
| 5250 |
setHeaderlessVerticalMargins(contentView, p, hasSecondLine); |
| 5251 |
|
| 5252 |
return contentView; |
| 5253 |
} |
| 5254 |
|
| 5255 |
private static void setHeaderlessVerticalMargins(RemoteViews contentView, |
| 5256 |
StandardTemplateParams p, boolean hasSecondLine) { |
| 5257 |
if (!p.mHeaderless) { |
| 5258 |
return; |
| 5259 |
} |
| 5260 |
int marginDimen = hasSecondLine |
| 5261 |
? R.dimen.notification_headerless_margin_twoline |
| 5262 |
: R.dimen.notification_headerless_margin_oneline; |
| 5263 |
contentView.setViewLayoutMarginDimen(R.id.notification_headerless_view_column, |
| 5264 |
RemoteViews.MARGIN_TOP, marginDimen); |
| 5265 |
contentView.setViewLayoutMarginDimen(R.id.notification_headerless_view_column, |
| 5266 |
RemoteViews.MARGIN_BOTTOM, marginDimen); |
| 5267 |
} |
| 5268 |
|
| 5269 |
private CharSequence processTextSpans(CharSequence text) { |
| 5270 |
if (mInNightMode) { |
| 5271 |
return ContrastColorUtil.clearColorSpans(text); |
| 5272 |
} |
| 5273 |
return text; |
| 5274 |
} |
| 5275 |
|
| 5276 |
private void setTextViewColorPrimary(RemoteViews contentView, @IdRes int id, |
| 5277 |
StandardTemplateParams p) { |
| 5278 |
contentView.setTextColor(id, getPrimaryTextColor(p)); |
| 5279 |
} |
| 5280 |
|
| 5281 |
|
| 5282 |
|
| 5283 |
|
| 5284 |
|
| 5285 |
|
| 5286 |
@VisibleForTesting |
| 5287 |
public @ColorInt int getPrimaryTextColor(StandardTemplateParams p) { |
| 5288 |
return getColors(p).getPrimaryTextColor(); |
| 5289 |
} |
| 5290 |
|
| 5291 |
|
| 5292 |
|
| 5293 |
|
| 5294 |
|
| 5295 |
|
| 5296 |
@VisibleForTesting |
| 5297 |
public @ColorInt int getSecondaryTextColor(StandardTemplateParams p) { |
| 5298 |
return getColors(p).getSecondaryTextColor(); |
| 5299 |
} |
| 5300 |
|
| 5301 |
private void setTextViewColorSecondary(RemoteViews contentView, @IdRes int id, |
| 5302 |
StandardTemplateParams p) { |
| 5303 |
contentView.setTextColor(id, getSecondaryTextColor(p)); |
| 5304 |
} |
| 5305 |
|
| 5306 |
private Colors getColors(StandardTemplateParams p) { |
| 5307 |
mColors.resolvePalette(mContext, mN.color, isBackgroundColorized(p), mInNightMode); |
| 5308 |
return mColors; |
| 5309 |
} |
| 5310 |
|
| 5311 |
private void updateBackgroundColor(RemoteViews contentView, |
| 5312 |
StandardTemplateParams p) { |
| 5313 |
if (isBackgroundColorized(p)) { |
| 5314 |
contentView.setInt(R.id.status_bar_latest_event_content, "setBackgroundColor", |
| 5315 |
getBackgroundColor(p)); |
| 5316 |
} else { |
| 5317 |
|
| 5318 |
contentView.setInt(R.id.status_bar_latest_event_content, "setBackgroundResource", |
| 5319 |
0); |
| 5320 |
} |
| 5321 |
} |
| 5322 |
|
| 5323 |
private boolean handleProgressBar(RemoteViews contentView, Bundle ex, |
| 5324 |
StandardTemplateParams p) { |
| 5325 |
final int max = ex.getInt(EXTRA_PROGRESS_MAX, 0); |
| 5326 |
final int progress = ex.getInt(EXTRA_PROGRESS, 0); |
| 5327 |
final boolean ind = ex.getBoolean(EXTRA_PROGRESS_INDETERMINATE); |
| 5328 |
if (!p.mHideProgress && (max != 0 || ind)) { |
| 5329 |
contentView.setViewVisibility(com.android.internal.R.id.progress, View.VISIBLE); |
| 5330 |
contentView.setProgressBar(R.id.progress, max, progress, ind); |
| 5331 |
contentView.setProgressBackgroundTintList(R.id.progress, |
| 5332 |
mContext.getColorStateList(R.color.notification_progress_background_color)); |
| 5333 |
ColorStateList progressTint = ColorStateList.valueOf(getPrimaryAccentColor(p)); |
| 5334 |
contentView.setProgressTintList(R.id.progress, progressTint); |
| 5335 |
contentView.setProgressIndeterminateTintList(R.id.progress, progressTint); |
| 5336 |
return true; |
| 5337 |
} else { |
| 5338 |
contentView.setViewVisibility(R.id.progress, View.GONE); |
| 5339 |
return false; |
| 5340 |
} |
| 5341 |
} |
| 5342 |
|
| 5343 |
private void bindLargeIconAndApplyMargin(RemoteViews contentView, |
| 5344 |
@NonNull StandardTemplateParams p, |
| 5345 |
@Nullable TemplateBindResult result) { |
| 5346 |
if (result == null) { |
| 5347 |
result = new TemplateBindResult(); |
| 5348 |
} |
| 5349 |
bindLargeIcon(contentView, p, result); |
| 5350 |
if (!p.mHeaderless) { |
| 5351 |
|
| 5352 |
result.mHeadingExtraMarginSet.applyToView(contentView, R.id.notification_header); |
| 5353 |
result.mTitleMarginSet.applyToView(contentView, R.id.title); |
| 5354 |
|
| 5355 |
result.mTitleMarginSet.applyToView(contentView, p.mTextViewId); |
| 5356 |
contentView.setInt(p.mTextViewId, "setNumIndentLines", p.hasTitle() ? 0 : 1); |
| 5357 |
} |
| 5358 |
} |
| 5359 |
|
| 5360 |
|
| 5361 |
|
| 5362 |
|
| 5363 |
|
| 5364 |
@SuppressWarnings("AndroidFrameworkCompatChange") |
| 5365 |
private void calculateRightIconDimens(Icon rightIcon, boolean isPromotedPicture, |
| 5366 |
@NonNull TemplateBindResult result) { |
| 5367 |
final Resources resources = mContext.getResources(); |
| 5368 |
final float density = resources.getDisplayMetrics().density; |
| 5369 |
final float iconMarginDp = resources.getDimension( |
| 5370 |
R.dimen.notification_right_icon_content_margin) / density; |
| 5371 |
final float contentMarginDp = resources.getDimension( |
| 5372 |
R.dimen.notification_content_margin_end) / density; |
| 5373 |
final float expanderSizeDp = resources.getDimension( |
| 5374 |
R.dimen.notification_header_expand_icon_size) / density - contentMarginDp; |
| 5375 |
final float viewHeightDp = resources.getDimension( |
| 5376 |
R.dimen.notification_right_icon_size) / density; |
| 5377 |
float viewWidthDp = viewHeightDp; |
| 5378 |
if (rightIcon != null && (isPromotedPicture |
| 5379 |
|| mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.S)) { |
| 5380 |
Drawable drawable = rightIcon.loadDrawable(mContext); |
| 5381 |
if (drawable != null) { |
| 5382 |
int iconWidth = drawable.getIntrinsicWidth(); |
| 5383 |
int iconHeight = drawable.getIntrinsicHeight(); |
| 5384 |
if (iconWidth > iconHeight && iconHeight > 0) { |
| 5385 |
final float maxViewWidthDp = viewHeightDp * MAX_LARGE_ICON_ASPECT_RATIO; |
| 5386 |
viewWidthDp = Math.min(viewHeightDp * iconWidth / iconHeight, |
| 5387 |
maxViewWidthDp); |
| 5388 |
} |
| 5389 |
} |
| 5390 |
} |
| 5391 |
final float extraMarginEndDpIfVisible = viewWidthDp + iconMarginDp; |
| 5392 |
result.setRightIconState(rightIcon != null , viewWidthDp, |
| 5393 |
viewHeightDp, extraMarginEndDpIfVisible, expanderSizeDp); |
| 5394 |
} |
| 5395 |
|
| 5396 |
|
| 5397 |
|
| 5398 |
|
| 5399 |
private void bindLargeIcon(RemoteViews contentView, @NonNull StandardTemplateParams p, |
| 5400 |
@NonNull TemplateBindResult result) { |
| 5401 |
if (mN.mLargeIcon == null && mN.largeIcon != null) { |
| 5402 |
mN.mLargeIcon = Icon.createWithBitmap(mN.largeIcon); |
| 5403 |
} |
| 5404 |
|
| 5405 |
|
| 5406 |
Icon leftIcon = p.mHideLeftIcon ? null : mN.mLargeIcon; |
| 5407 |
Icon rightIcon = p.mHideRightIcon ? null |
| 5408 |
: (p.mPromotedPicture != null ? p.mPromotedPicture : mN.mLargeIcon); |
| 5409 |
|
| 5410 |
|
| 5411 |
if (leftIcon != rightIcon || leftIcon == null) { |
| 5412 |
|
| 5413 |
|
| 5414 |
contentView.setImageViewIcon(R.id.left_icon, leftIcon); |
| 5415 |
contentView.setIntTag(R.id.left_icon, R.id.tag_uses_right_icon_drawable, 0); |
| 5416 |
} else { |
| 5417 |
|
| 5418 |
|
| 5419 |
contentView.setIntTag(R.id.left_icon, R.id.tag_uses_right_icon_drawable, 1); |
| 5420 |
} |
| 5421 |
|
| 5422 |
|
| 5423 |
boolean isPromotedPicture = p.mPromotedPicture != null; |
| 5424 |
calculateRightIconDimens(rightIcon, isPromotedPicture, result); |
| 5425 |
|
| 5426 |
|
| 5427 |
if (rightIcon != null) { |
| 5428 |
contentView.setViewLayoutWidth(R.id.right_icon, |
| 5429 |
result.mRightIconWidthDp, TypedValue.COMPLEX_UNIT_DIP); |
| 5430 |
contentView.setViewLayoutHeight(R.id.right_icon, |
| 5431 |
result.mRightIconHeightDp, TypedValue.COMPLEX_UNIT_DIP); |
| 5432 |
contentView.setViewVisibility(R.id.right_icon, View.VISIBLE); |
| 5433 |
contentView.setImageViewIcon(R.id.right_icon, rightIcon); |
| 5434 |
contentView.setIntTag(R.id.right_icon, R.id.tag_keep_when_showing_left_icon, |
| 5435 |
isPromotedPicture ? 1 : 0); |
| 5436 |
processLargeLegacyIcon(rightIcon, contentView, p); |
| 5437 |
} else { |
| 5438 |
|
| 5439 |
|
| 5440 |
|
| 5441 |
contentView.setImageViewIcon(R.id.right_icon, null); |
| 5442 |
contentView.setIntTag(R.id.right_icon, R.id.tag_keep_when_showing_left_icon, 0); |
| 5443 |
} |
| 5444 |
} |
| 5445 |
|
| 5446 |
private void bindNotificationHeader(RemoteViews contentView, StandardTemplateParams p) { |
| 5447 |
bindSmallIcon(contentView, p); |
| 5448 |
|
| 5449 |
boolean hasTextToLeft = bindHeaderAppName(contentView, p, false ); |
| 5450 |
hasTextToLeft |= bindHeaderTextSecondary(contentView, p, hasTextToLeft); |
| 5451 |
hasTextToLeft |= bindHeaderText(contentView, p, hasTextToLeft); |
| 5452 |
if (!hasTextToLeft) { |
| 5453 |
|
| 5454 |
hasTextToLeft |= bindHeaderAppName(contentView, p, true ); |
| 5455 |
} |
| 5456 |
bindHeaderChronometerAndTime(contentView, p, hasTextToLeft); |
| 5457 |
bindPhishingAlertIcon(contentView, p); |
| 5458 |
bindProfileBadge(contentView, p); |
| 5459 |
bindAlertedIcon(contentView, p); |
| 5460 |
bindExpandButton(contentView, p); |
| 5461 |
mN.mUsesStandardHeader = true; |
| 5462 |
} |
| 5463 |
|
| 5464 |
private void bindExpandButton(RemoteViews contentView, StandardTemplateParams p) { |
| 5465 |
|
| 5466 |
int bgColor = getBackgroundColor(p); |
| 5467 |
int pillColor = Colors.flattenAlpha(getColors(p).getProtectionColor(), bgColor); |
| 5468 |
int textColor = Colors.flattenAlpha(getPrimaryTextColor(p), pillColor); |
| 5469 |
contentView.setInt(R.id.expand_button, "setDefaultTextColor", textColor); |
| 5470 |
contentView.setInt(R.id.expand_button, "setDefaultPillColor", pillColor); |
| 5471 |
|
| 5472 |
if (p.mHighlightExpander) { |
| 5473 |
pillColor = Colors.flattenAlpha(getColors(p).getTertiaryAccentColor(), bgColor); |
| 5474 |
textColor = Colors.flattenAlpha(getColors(p).getOnAccentTextColor(), pillColor); |
| 5475 |
} |
| 5476 |
contentView.setInt(R.id.expand_button, "setHighlightTextColor", textColor); |
| 5477 |
contentView.setInt(R.id.expand_button, "setHighlightPillColor", pillColor); |
| 5478 |
} |
| 5479 |
|
| 5480 |
private void bindHeaderChronometerAndTime(RemoteViews contentView, |
| 5481 |
StandardTemplateParams p, boolean hasTextToLeft) { |
| 5482 |
if (!p.mHideTime && showsTimeOrChronometer()) { |
| 5483 |
if (hasTextToLeft) { |
| 5484 |
contentView.setViewVisibility(R.id.time_divider, View.VISIBLE); |
| 5485 |
setTextViewColorSecondary(contentView, R.id.time_divider, p); |
| 5486 |
} |
| 5487 |
if (mN.extras.getBoolean(EXTRA_SHOW_CHRONOMETER)) { |
| 5488 |
contentView.setViewVisibility(R.id.chronometer, View.VISIBLE); |
| 5489 |
contentView.setLong(R.id.chronometer, "setBase", |
| 5490 |
mN.when + (SystemClock.elapsedRealtime() - System.currentTimeMillis())); |
| 5491 |
contentView.setBoolean(R.id.chronometer, "setStarted", true); |
| 5492 |
boolean countsDown = mN.extras.getBoolean(EXTRA_CHRONOMETER_COUNT_DOWN); |
| 5493 |
contentView.setChronometerCountDown(R.id.chronometer, countsDown); |
| 5494 |
setTextViewColorSecondary(contentView, R.id.chronometer, p); |
| 5495 |
} else { |
| 5496 |
contentView.setViewVisibility(R.id.time, View.VISIBLE); |
| 5497 |
contentView.setLong(R.id.time, "setTime", mN.when); |
| 5498 |
setTextViewColorSecondary(contentView, R.id.time, p); |
| 5499 |
} |
| 5500 |
} else { |
| 5501 |
|
| 5502 |
|
| 5503 |
contentView.setLong(R.id.time, "setTime", mN.when != 0 ? mN.when : mN.creationTime); |
| 5504 |
setTextViewColorSecondary(contentView, R.id.time, p); |
| 5505 |
} |
| 5506 |
} |
| 5507 |
|
| 5508 |
|
| 5509 |
|
| 5510 |
|
| 5511 |
private boolean bindHeaderText(RemoteViews contentView, StandardTemplateParams p, |
| 5512 |
boolean hasTextToLeft) { |
| 5513 |
if (p.mHideSubText) { |
| 5514 |
return false; |
| 5515 |
} |
| 5516 |
CharSequence summaryText = p.summaryText; |
| 5517 |
if (summaryText == null && mStyle != null && mStyle.mSummaryTextSet |
| 5518 |
&& mStyle.hasSummaryInHeader()) { |
| 5519 |
summaryText = mStyle.mSummaryText; |
| 5520 |
} |
| 5521 |
if (summaryText == null |
| 5522 |
&& mContext.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N |
| 5523 |
&& mN.extras.getCharSequence(EXTRA_INFO_TEXT) != null) { |
| 5524 |
summaryText = mN.extras.getCharSequence(EXTRA_INFO_TEXT); |
| 5525 |
} |
| 5526 |
if (!TextUtils.isEmpty(summaryText)) { |
| 5527 |
|
| 5528 |
contentView.setTextViewText(R.id.header_text, processTextSpans( |
| 5529 |
processLegacyText(summaryText))); |
| 5530 |
setTextViewColorSecondary(contentView, R.id.header_text, p); |
| 5531 |
contentView.setViewVisibility(R.id.header_text, View.VISIBLE); |
| 5532 |
if (hasTextToLeft) { |
| 5533 |
contentView.setViewVisibility(R.id.header_text_divider, View.VISIBLE); |
| 5534 |
setTextViewColorSecondary(contentView, R.id.header_text_divider, p); |
| 5535 |
} |
| 5536 |
return true; |
| 5537 |
} |
| 5538 |
return false; |
| 5539 |
} |
| 5540 |
|
| 5541 |
|
| 5542 |
|
| 5543 |
|
| 5544 |
private boolean bindHeaderTextSecondary(RemoteViews contentView, StandardTemplateParams p, |
| 5545 |
boolean hasTextToLeft) { |
| 5546 |
if (p.mHideSubText) { |
| 5547 |
return false; |
| 5548 |
} |
| 5549 |
if (!TextUtils.isEmpty(p.headerTextSecondary)) { |
| 5550 |
contentView.setTextViewText(R.id.header_text_secondary, processTextSpans( |
| 5551 |
processLegacyText(p.headerTextSecondary))); |
| 5552 |
setTextViewColorSecondary(contentView, R.id.header_text_secondary, p); |
| 5553 |
contentView.setViewVisibility(R.id.header_text_secondary, View.VISIBLE); |
| 5554 |
if (hasTextToLeft) { |
| 5555 |
contentView.setViewVisibility(R.id.header_text_secondary_divider, View.VISIBLE); |
| 5556 |
setTextViewColorSecondary(contentView, R.id.header_text_secondary_divider, p); |
| 5557 |
} |
| 5558 |
return true; |
| 5559 |
} |
| 5560 |
return false; |
| 5561 |
} |
| 5562 |
|
| 5563 |
|
| 5564 |
|
| 5565 |
|
| 5566 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 5567 |
public String loadHeaderAppName() { |
| 5568 |
CharSequence name = null; |
| 5569 |
final PackageManager pm = mContext.getPackageManager(); |
| 5570 |
if (mN.extras.containsKey(EXTRA_SUBSTITUTE_APP_NAME)) { |
| 5571 |
|
| 5572 |
|
| 5573 |
|
| 5574 |
|
| 5575 |
final String pkg = mContext.getPackageName(); |
| 5576 |
final String subName = mN.extras.getString(EXTRA_SUBSTITUTE_APP_NAME); |
| 5577 |
if (PackageManager.PERMISSION_GRANTED == pm.checkPermission( |
| 5578 |
android.Manifest.permission.SUBSTITUTE_NOTIFICATION_APP_NAME, pkg)) { |
| 5579 |
name = subName; |
| 5580 |
} else { |
| 5581 |
Log.w(TAG, "warning: pkg " |
| 5582 |
+ pkg + " attempting to substitute app name '" + subName |
| 5583 |
+ "' without holding perm " |
| 5584 |
+ android.Manifest.permission.SUBSTITUTE_NOTIFICATION_APP_NAME); |
| 5585 |
} |
| 5586 |
} |
| 5587 |
if (TextUtils.isEmpty(name)) { |
| 5588 |
name = pm.getApplicationLabel(mContext.getApplicationInfo()); |
| 5589 |
} |
| 5590 |
if (TextUtils.isEmpty(name)) { |
| 5591 |
|
| 5592 |
return null; |
| 5593 |
} |
| 5594 |
|
| 5595 |
return String.valueOf(name); |
| 5596 |
} |
| 5597 |
|
| 5598 |
|
| 5599 |
|
| 5600 |
|
| 5601 |
private boolean bindHeaderAppName(RemoteViews contentView, StandardTemplateParams p, |
| 5602 |
boolean force) { |
| 5603 |
if (p.mViewType == StandardTemplateParams.VIEW_TYPE_MINIMIZED && !force) { |
| 5604 |
|
| 5605 |
return false; |
| 5606 |
} |
| 5607 |
if (p.mHeaderless && p.hasTitle()) { |
| 5608 |
|
| 5609 |
|
| 5610 |
return true; |
| 5611 |
} |
| 5612 |
if (p.mHideAppName) { |
| 5613 |
|
| 5614 |
|
| 5615 |
return p.hasTitle(); |
| 5616 |
} |
| 5617 |
contentView.setViewVisibility(R.id.app_name_text, View.VISIBLE); |
| 5618 |
contentView.setTextViewText(R.id.app_name_text, loadHeaderAppName()); |
| 5619 |
contentView.setTextColor(R.id.app_name_text, getSecondaryTextColor(p)); |
| 5620 |
return true; |
| 5621 |
} |
| 5622 |
|
| 5623 |
|
| 5624 |
|
| 5625 |
|
| 5626 |
|
| 5627 |
|
| 5628 |
private boolean isBackgroundColorized(StandardTemplateParams p) { |
| 5629 |
return p.allowColorization && mN.isColorized(); |
| 5630 |
} |
| 5631 |
|
| 5632 |
private boolean isCallActionColorCustomizable() { |
| 5633 |
|
| 5634 |
|
| 5635 |
|
| 5636 |
|
| 5637 |
return mN.isColorized() && mContext.getResources().getBoolean( |
| 5638 |
R.bool.config_callNotificationActionColorsRequireColorized); |
| 5639 |
} |
| 5640 |
|
| 5641 |
private void bindSmallIcon(RemoteViews contentView, StandardTemplateParams p) { |
| 5642 |
if (mN.mSmallIcon == null && mN.icon != 0) { |
| 5643 |
mN.mSmallIcon = Icon.createWithResource(mContext, mN.icon); |
| 5644 |
} |
| 5645 |
contentView.setImageViewIcon(R.id.icon, mN.mSmallIcon); |
| 5646 |
contentView.setInt(R.id.icon, "setImageLevel", mN.iconLevel); |
| 5647 |
processSmallIconColor(mN.mSmallIcon, contentView, p); |
| 5648 |
} |
| 5649 |
|
| 5650 |
|
| 5651 |
|
| 5652 |
|
| 5653 |
|
| 5654 |
private boolean showsTimeOrChronometer() { |
| 5655 |
return mN.showsTime() || mN.showsChronometer(); |
| 5656 |
} |
| 5657 |
|
| 5658 |
private void resetStandardTemplateWithActions(RemoteViews big) { |
| 5659 |
|
| 5660 |
|
| 5661 |
big.setViewVisibility(R.id.actions, View.GONE); |
| 5662 |
big.removeAllViews(R.id.actions); |
| 5663 |
|
| 5664 |
big.setViewVisibility(R.id.notification_material_reply_container, View.GONE); |
| 5665 |
big.setTextViewText(R.id.notification_material_reply_text_1, null); |
| 5666 |
big.setViewVisibility(R.id.notification_material_reply_text_1_container, View.GONE); |
| 5667 |
big.setViewVisibility(R.id.notification_material_reply_progress, View.GONE); |
| 5668 |
|
| 5669 |
big.setViewVisibility(R.id.notification_material_reply_text_2, View.GONE); |
| 5670 |
big.setTextViewText(R.id.notification_material_reply_text_2, null); |
| 5671 |
big.setViewVisibility(R.id.notification_material_reply_text_3, View.GONE); |
| 5672 |
big.setTextViewText(R.id.notification_material_reply_text_3, null); |
| 5673 |
|
| 5674 |
|
| 5675 |
big.setViewLayoutMarginDimen(R.id.notification_action_list_margin_target, |
| 5676 |
RemoteViews.MARGIN_BOTTOM, R.dimen.notification_content_margin); |
| 5677 |
} |
| 5678 |
|
| 5679 |
private void bindSnoozeAction(RemoteViews big, StandardTemplateParams p) { |
| 5680 |
boolean hideSnoozeButton = mN.isForegroundService() || mN.fullScreenIntent != null |
| 5681 |
|| isBackgroundColorized(p) |
| 5682 |
|| p.mViewType != StandardTemplateParams.VIEW_TYPE_BIG; |
| 5683 |
big.setBoolean(R.id.snooze_button, "setEnabled", !hideSnoozeButton); |
| 5684 |
if (hideSnoozeButton) { |
| 5685 |
|
| 5686 |
big.setViewVisibility(R.id.snooze_button, View.GONE); |
| 5687 |
} |
| 5688 |
|
| 5689 |
final boolean snoozeEnabled = !hideSnoozeButton |
| 5690 |
&& mContext.getContentResolver() != null |
| 5691 |
&& isSnoozeSettingEnabled(); |
| 5692 |
if (snoozeEnabled) { |
| 5693 |
big.setViewLayoutMarginDimen(R.id.notification_action_list_margin_target, |
| 5694 |
RemoteViews.MARGIN_BOTTOM, 0); |
| 5695 |
} |
| 5696 |
} |
| 5697 |
|
| 5698 |
private boolean isSnoozeSettingEnabled() { |
| 5699 |
try { |
| 5700 |
return Settings.Secure.getInt(mContext.getContentResolver(), |
| 5701 |
Settings.Secure.SHOW_NOTIFICATION_SNOOZE, 0) == 1; |
| 5702 |
} catch (SecurityException ex) { |
| 5703 |
|
| 5704 |
|
| 5705 |
return false; |
| 5706 |
} |
| 5707 |
} |
| 5708 |
|
| 5709 |
|
| 5710 |
|
| 5711 |
|
| 5712 |
private @NonNull List<Notification.Action> getNonContextualActions() { |
| 5713 |
if (mActions == null) return Collections.emptyList(); |
| 5714 |
List<Notification.Action> standardActions = new ArrayList<>(); |
| 5715 |
for (Notification.Action action : mActions) { |
| 5716 |
if (!action.isContextual()) { |
| 5717 |
standardActions.add(action); |
| 5718 |
} |
| 5719 |
} |
| 5720 |
return standardActions; |
| 5721 |
} |
| 5722 |
|
| 5723 |
private RemoteViews applyStandardTemplateWithActions(int layoutId, |
| 5724 |
StandardTemplateParams p, TemplateBindResult result) { |
| 5725 |
RemoteViews big = applyStandardTemplate(layoutId, p, result); |
| 5726 |
|
| 5727 |
resetStandardTemplateWithActions(big); |
| 5728 |
bindSnoozeAction(big, p); |
| 5729 |
|
| 5730 |
ColorStateList actionColor = ColorStateList.valueOf(getStandardActionColor(p)); |
| 5731 |
big.setColorStateList(R.id.snooze_button, "setImageTintList", actionColor); |
| 5732 |
big.setColorStateList(R.id.bubble_button, "setImageTintList", actionColor); |
| 5733 |
|
| 5734 |
boolean validRemoteInput = false; |
| 5735 |
|
| 5736 |
|
| 5737 |
|
| 5738 |
List<Notification.Action> nonContextualActions = getNonContextualActions(); |
| 5739 |
|
| 5740 |
int numActions = Math.min(nonContextualActions.size(), MAX_ACTION_BUTTONS); |
| 5741 |
boolean emphazisedMode = mN.fullScreenIntent != null || p.mCallStyleActions; |
| 5742 |
if (p.mCallStyleActions) { |
| 5743 |
|
| 5744 |
|
| 5745 |
big.setViewPadding(R.id.actions, 0, 0, 0, 0); |
| 5746 |
|
| 5747 |
|
| 5748 |
big.setInt(R.id.actions, "setCollapsibleIndentDimen", |
| 5749 |
R.dimen.call_notification_collapsible_indent); |
| 5750 |
} |
| 5751 |
big.setBoolean(R.id.actions, "setEmphasizedMode", emphazisedMode); |
| 5752 |
if (numActions > 0 && !p.mHideActions) { |
| 5753 |
big.setViewVisibility(R.id.actions_container, View.VISIBLE); |
| 5754 |
big.setViewVisibility(R.id.actions, View.VISIBLE); |
| 5755 |
big.setViewLayoutMarginDimen(R.id.notification_action_list_margin_target, |
| 5756 |
RemoteViews.MARGIN_BOTTOM, 0); |
| 5757 |
for (int i = 0; i < numActions; i++) { |
| 5758 |
Action action = nonContextualActions.get(i); |
| 5759 |
|
| 5760 |
boolean actionHasValidInput = hasValidRemoteInput(action); |
| 5761 |
validRemoteInput |= actionHasValidInput; |
| 5762 |
|
| 5763 |
final RemoteViews button = generateActionButton(action, emphazisedMode, p); |
| 5764 |
if (actionHasValidInput && !emphazisedMode) { |
| 5765 |
|
| 5766 |
button.setInt(R.id.action0, "setBackgroundResource", 0); |
| 5767 |
} |
| 5768 |
if (emphazisedMode && i > 0) { |
| 5769 |
|
| 5770 |
|
| 5771 |
button.setViewLayoutMarginDimen(R.id.action0, RemoteViews.MARGIN_START, 0); |
| 5772 |
} |
| 5773 |
big.addView(R.id.actions, button); |
| 5774 |
} |
| 5775 |
} else { |
| 5776 |
big.setViewVisibility(R.id.actions_container, View.GONE); |
| 5777 |
} |
| 5778 |
|
| 5779 |
RemoteInputHistoryItem[] replyText = getParcelableArrayFromBundle( |
| 5780 |
mN.extras, EXTRA_REMOTE_INPUT_HISTORY_ITEMS, RemoteInputHistoryItem.class); |
| 5781 |
if (validRemoteInput && replyText != null && replyText.length > 0 |
| 5782 |
&& !TextUtils.isEmpty(replyText[0].getText()) |
| 5783 |
&& p.maxRemoteInputHistory > 0) { |
| 5784 |
boolean showSpinner = mN.extras.getBoolean(EXTRA_SHOW_REMOTE_INPUT_SPINNER); |
| 5785 |
big.setViewVisibility(R.id.notification_material_reply_container, View.VISIBLE); |
| 5786 |
big.setViewVisibility(R.id.notification_material_reply_text_1_container, |
| 5787 |
View.VISIBLE); |
| 5788 |
big.setTextViewText(R.id.notification_material_reply_text_1, |
| 5789 |
processTextSpans(replyText[0].getText())); |
| 5790 |
setTextViewColorSecondary(big, R.id.notification_material_reply_text_1, p); |
| 5791 |
big.setViewVisibility(R.id.notification_material_reply_progress, |
| 5792 |
showSpinner ? View.VISIBLE : View.GONE); |
| 5793 |
big.setProgressIndeterminateTintList( |
| 5794 |
R.id.notification_material_reply_progress, |
| 5795 |
ColorStateList.valueOf(getPrimaryAccentColor(p))); |
| 5796 |
|
| 5797 |
if (replyText.length > 1 && !TextUtils.isEmpty(replyText[1].getText()) |
| 5798 |
&& p.maxRemoteInputHistory > 1) { |
| 5799 |
big.setViewVisibility(R.id.notification_material_reply_text_2, View.VISIBLE); |
| 5800 |
big.setTextViewText(R.id.notification_material_reply_text_2, |
| 5801 |
processTextSpans(replyText[1].getText())); |
| 5802 |
setTextViewColorSecondary(big, R.id.notification_material_reply_text_2, p); |
| 5803 |
|
| 5804 |
if (replyText.length > 2 && !TextUtils.isEmpty(replyText[2].getText()) |
| 5805 |
&& p.maxRemoteInputHistory > 2) { |
| 5806 |
big.setViewVisibility( |
| 5807 |
R.id.notification_material_reply_text_3, View.VISIBLE); |
| 5808 |
big.setTextViewText(R.id.notification_material_reply_text_3, |
| 5809 |
processTextSpans(replyText[2].getText())); |
| 5810 |
setTextViewColorSecondary(big, R.id.notification_material_reply_text_3, p); |
| 5811 |
} |
| 5812 |
} |
| 5813 |
} |
| 5814 |
|
| 5815 |
return big; |
| 5816 |
} |
| 5817 |
|
| 5818 |
private boolean hasValidRemoteInput(Action action) { |
| 5819 |
if (TextUtils.isEmpty(action.title) || action.actionIntent == null) { |
| 5820 |
|
| 5821 |
return false; |
| 5822 |
} |
| 5823 |
|
| 5824 |
RemoteInput[] remoteInputs = action.getRemoteInputs(); |
| 5825 |
if (remoteInputs == null) { |
| 5826 |
return false; |
| 5827 |
} |
| 5828 |
|
| 5829 |
for (RemoteInput r : remoteInputs) { |
| 5830 |
CharSequence[] choices = r.getChoices(); |
| 5831 |
if (r.getAllowFreeFormInput() || (choices != null && choices.length != 0)) { |
| 5832 |
return true; |
| 5833 |
} |
| 5834 |
} |
| 5835 |
return false; |
| 5836 |
} |
| 5837 |
|
| 5838 |
|
| 5839 |
|
| 5840 |
|
| 5841 |
|
| 5842 |
|
| 5843 |
|
| 5844 |
public RemoteViews createContentView() { |
| 5845 |
return createContentView(false ); |
| 5846 |
} |
| 5847 |
|
| 5848 |
|
| 5849 |
|
| 5850 |
|
| 5851 |
|
| 5852 |
|
| 5853 |
@SuppressWarnings("AndroidFrameworkCompatChange") |
| 5854 |
private boolean fullyCustomViewRequiresDecoration(boolean fromStyle) { |
| 5855 |
|
| 5856 |
|
| 5857 |
|
| 5858 |
if (fromStyle && PLATFORM_STYLE_CLASSES.contains(mStyle.getClass())) { |
| 5859 |
return false; |
| 5860 |
} |
| 5861 |
return mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.S; |
| 5862 |
} |
| 5863 |
|
| 5864 |
private RemoteViews minimallyDecoratedContentView(@NonNull RemoteViews customContent) { |
| 5865 |
StandardTemplateParams p = mParams.reset() |
| 5866 |
.viewType(StandardTemplateParams.VIEW_TYPE_NORMAL) |
| 5867 |
.decorationType(StandardTemplateParams.DECORATION_MINIMAL) |
| 5868 |
.fillTextsFrom(this); |
| 5869 |
TemplateBindResult result = new TemplateBindResult(); |
| 5870 |
RemoteViews standard = applyStandardTemplate(getBaseLayoutResource(), p, result); |
| 5871 |
buildCustomContentIntoTemplate(mContext, standard, customContent, |
| 5872 |
p, result); |
| 5873 |
return standard; |
| 5874 |
} |
| 5875 |
|
| 5876 |
private RemoteViews minimallyDecoratedBigContentView(@NonNull RemoteViews customContent) { |
| 5877 |
StandardTemplateParams p = mParams.reset() |
| 5878 |
.viewType(StandardTemplateParams.VIEW_TYPE_BIG) |
| 5879 |
.decorationType(StandardTemplateParams.DECORATION_MINIMAL) |
| 5880 |
.fillTextsFrom(this); |
| 5881 |
TemplateBindResult result = new TemplateBindResult(); |
| 5882 |
RemoteViews standard = applyStandardTemplateWithActions(getBigBaseLayoutResource(), |
| 5883 |
p, result); |
| 5884 |
buildCustomContentIntoTemplate(mContext, standard, customContent, |
| 5885 |
p, result); |
| 5886 |
makeHeaderExpanded(standard); |
| 5887 |
return standard; |
| 5888 |
} |
| 5889 |
|
| 5890 |
private RemoteViews minimallyDecoratedHeadsUpContentView( |
| 5891 |
@NonNull RemoteViews customContent) { |
| 5892 |
StandardTemplateParams p = mParams.reset() |
| 5893 |
.viewType(StandardTemplateParams.VIEW_TYPE_HEADS_UP) |
| 5894 |
.decorationType(StandardTemplateParams.DECORATION_MINIMAL) |
| 5895 |
.fillTextsFrom(this); |
| 5896 |
TemplateBindResult result = new TemplateBindResult(); |
| 5897 |
RemoteViews standard = applyStandardTemplateWithActions(getHeadsUpBaseLayoutResource(), |
| 5898 |
p, result); |
| 5899 |
buildCustomContentIntoTemplate(mContext, standard, customContent, |
| 5900 |
p, result); |
| 5901 |
return standard; |
| 5902 |
} |
| 5903 |
|
| 5904 |
|
| 5905 |
|
| 5906 |
|
| 5907 |
|
| 5908 |
|
| 5909 |
|
| 5910 |
|
| 5911 |
|
| 5912 |
|
| 5913 |
|
| 5914 |
public RemoteViews createContentView(boolean increasedHeight) { |
| 5915 |
if (useExistingRemoteView(mN.contentView)) { |
| 5916 |
return fullyCustomViewRequiresDecoration(false ) |
| 5917 |
? minimallyDecoratedContentView(mN.contentView) : mN.contentView; |
| 5918 |
} else if (mStyle != null) { |
| 5919 |
final RemoteViews styleView = mStyle.makeContentView(increasedHeight); |
| 5920 |
if (styleView != null) { |
| 5921 |
return fullyCustomViewRequiresDecoration(true ) |
| 5922 |
? minimallyDecoratedContentView(styleView) : styleView; |
| 5923 |
} |
| 5924 |
} |
| 5925 |
StandardTemplateParams p = mParams.reset() |
| 5926 |
.viewType(StandardTemplateParams.VIEW_TYPE_NORMAL) |
| 5927 |
.fillTextsFrom(this); |
| 5928 |
return applyStandardTemplate(getBaseLayoutResource(), p, null ); |
| 5929 |
} |
| 5930 |
|
| 5931 |
private boolean useExistingRemoteView(RemoteViews customContent) { |
| 5932 |
if (customContent == null) { |
| 5933 |
return false; |
| 5934 |
} |
| 5935 |
if (styleDisplaysCustomViewInline()) { |
| 5936 |
|
| 5937 |
return false; |
| 5938 |
} |
| 5939 |
if (fullyCustomViewRequiresDecoration(false) |
| 5940 |
&& STANDARD_LAYOUTS.contains(customContent.getLayoutId())) { |
| 5941 |
|
| 5942 |
|
| 5943 |
|
| 5944 |
Log.w(TAG, "For apps targeting S, a custom content view that is a modified " |
| 5945 |
+ "version of any standard layout is disallowed."); |
| 5946 |
return false; |
| 5947 |
} |
| 5948 |
return true; |
| 5949 |
} |
| 5950 |
|
| 5951 |
|
| 5952 |
|
| 5953 |
|
| 5954 |
public RemoteViews createBigContentView() { |
| 5955 |
RemoteViews result = null; |
| 5956 |
if (useExistingRemoteView(mN.bigContentView)) { |
| 5957 |
return fullyCustomViewRequiresDecoration(false ) |
| 5958 |
? minimallyDecoratedBigContentView(mN.bigContentView) : mN.bigContentView; |
| 5959 |
} |
| 5960 |
if (mStyle != null) { |
| 5961 |
result = mStyle.makeBigContentView(); |
| 5962 |
if (fullyCustomViewRequiresDecoration(true )) { |
| 5963 |
result = minimallyDecoratedBigContentView(result); |
| 5964 |
} |
| 5965 |
} |
| 5966 |
if (result == null) { |
| 5967 |
if (bigContentViewRequired()) { |
| 5968 |
StandardTemplateParams p = mParams.reset() |
| 5969 |
.viewType(StandardTemplateParams.VIEW_TYPE_BIG) |
| 5970 |
.allowTextWithProgress(true) |
| 5971 |
.fillTextsFrom(this); |
| 5972 |
result = applyStandardTemplateWithActions(getBigBaseLayoutResource(), p, |
| 5973 |
null ); |
| 5974 |
} |
| 5975 |
} |
| 5976 |
makeHeaderExpanded(result); |
| 5977 |
return result; |
| 5978 |
} |
| 5979 |
|
| 5980 |
|
| 5981 |
|
| 5982 |
|
| 5983 |
|
| 5984 |
|
| 5985 |
@SuppressWarnings("AndroidFrameworkCompatChange") |
| 5986 |
private boolean bigContentViewRequired() { |
| 5987 |
if (mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.S) { |
| 5988 |
return true; |
| 5989 |
} |
| 5990 |
|
| 5991 |
|
| 5992 |
|
| 5993 |
boolean exempt = mN.contentView != null && mN.bigContentView == null |
| 5994 |
&& mStyle == null && mActions.size() == 0; |
| 5995 |
return !exempt; |
| 5996 |
} |
| 5997 |
|
| 5998 |
|
| 5999 |
|
| 6000 |
|
| 6001 |
|
| 6002 |
|
| 6003 |
|
| 6004 |
public RemoteViews makeNotificationGroupHeader() { |
| 6005 |
return makeNotificationHeader(mParams.reset() |
| 6006 |
.viewType(StandardTemplateParams.VIEW_TYPE_GROUP_HEADER) |
| 6007 |
.fillTextsFrom(this)); |
| 6008 |
} |
| 6009 |
|
| 6010 |
|
| 6011 |
|
| 6012 |
|
| 6013 |
|
| 6014 |
|
| 6015 |
|
| 6016 |
private RemoteViews makeNotificationHeader(StandardTemplateParams p) { |
| 6017 |
|
| 6018 |
p.disallowColorization(); |
| 6019 |
RemoteViews header = new BuilderRemoteViews(mContext.getApplicationInfo(), |
| 6020 |
R.layout.notification_template_header); |
| 6021 |
resetNotificationHeader(header); |
| 6022 |
bindNotificationHeader(header, p); |
| 6023 |
return header; |
| 6024 |
} |
| 6025 |
|
| 6026 |
|
| 6027 |
|
| 6028 |
|
| 6029 |
|
| 6030 |
|
| 6031 |
public RemoteViews makeAmbientNotification() { |
| 6032 |
RemoteViews headsUpContentView = createHeadsUpContentView(false ); |
| 6033 |
if (headsUpContentView != null) { |
| 6034 |
return headsUpContentView; |
| 6035 |
} |
| 6036 |
return createContentView(); |
| 6037 |
} |
| 6038 |
|
| 6039 |
|
| 6040 |
|
| 6041 |
|
| 6042 |
|
| 6043 |
|
| 6044 |
public static void makeHeaderExpanded(RemoteViews result) { |
| 6045 |
if (result != null) { |
| 6046 |
result.setBoolean(R.id.expand_button, "setExpanded", true); |
| 6047 |
} |
| 6048 |
} |
| 6049 |
|
| 6050 |
|
| 6051 |
|
| 6052 |
|
| 6053 |
|
| 6054 |
|
| 6055 |
|
| 6056 |
|
| 6057 |
|
| 6058 |
|
| 6059 |
|
| 6060 |
public RemoteViews createHeadsUpContentView(boolean increasedHeight) { |
| 6061 |
if (useExistingRemoteView(mN.headsUpContentView)) { |
| 6062 |
return fullyCustomViewRequiresDecoration(false ) |
| 6063 |
? minimallyDecoratedHeadsUpContentView(mN.headsUpContentView) |
| 6064 |
: mN.headsUpContentView; |
| 6065 |
} else if (mStyle != null) { |
| 6066 |
final RemoteViews styleView = mStyle.makeHeadsUpContentView(increasedHeight); |
| 6067 |
if (styleView != null) { |
| 6068 |
return fullyCustomViewRequiresDecoration(true ) |
| 6069 |
? minimallyDecoratedHeadsUpContentView(styleView) : styleView; |
| 6070 |
} |
| 6071 |
} else if (mActions.size() == 0) { |
| 6072 |
return null; |
| 6073 |
} |
| 6074 |
|
| 6075 |
|
| 6076 |
|
| 6077 |
StandardTemplateParams p = mParams.reset() |
| 6078 |
.viewType(StandardTemplateParams.VIEW_TYPE_HEADS_UP) |
| 6079 |
.fillTextsFrom(this) |
| 6080 |
.setMaxRemoteInputHistory(1); |
| 6081 |
return applyStandardTemplateWithActions(getHeadsUpBaseLayoutResource(), p, |
| 6082 |
null ); |
| 6083 |
} |
| 6084 |
|
| 6085 |
|
| 6086 |
|
| 6087 |
|
| 6088 |
public RemoteViews createHeadsUpContentView() { |
| 6089 |
return createHeadsUpContentView(false ); |
| 6090 |
} |
| 6091 |
|
| 6092 |
|
| 6093 |
|
| 6094 |
|
| 6095 |
|
| 6096 |
|
| 6097 |
|
| 6098 |
@UnsupportedAppUsage |
| 6099 |
public RemoteViews makePublicContentView(boolean isLowPriority) { |
| 6100 |
if (mN.publicVersion != null) { |
| 6101 |
final Builder builder = recoverBuilder(mContext, mN.publicVersion); |
| 6102 |
return builder.createContentView(); |
| 6103 |
} |
| 6104 |
Bundle savedBundle = mN.extras; |
| 6105 |
Style style = mStyle; |
| 6106 |
mStyle = null; |
| 6107 |
Icon largeIcon = mN.mLargeIcon; |
| 6108 |
mN.mLargeIcon = null; |
| 6109 |
Bitmap largeIconLegacy = mN.largeIcon; |
| 6110 |
mN.largeIcon = null; |
| 6111 |
ArrayList<Action> actions = mActions; |
| 6112 |
mActions = new ArrayList<>(); |
| 6113 |
Bundle publicExtras = new Bundle(); |
| 6114 |
publicExtras.putBoolean(EXTRA_SHOW_WHEN, |
| 6115 |
savedBundle.getBoolean(EXTRA_SHOW_WHEN)); |
| 6116 |
publicExtras.putBoolean(EXTRA_SHOW_CHRONOMETER, |
| 6117 |
savedBundle.getBoolean(EXTRA_SHOW_CHRONOMETER)); |
| 6118 |
publicExtras.putBoolean(EXTRA_CHRONOMETER_COUNT_DOWN, |
| 6119 |
savedBundle.getBoolean(EXTRA_CHRONOMETER_COUNT_DOWN)); |
| 6120 |
String appName = savedBundle.getString(EXTRA_SUBSTITUTE_APP_NAME); |
| 6121 |
if (appName != null) { |
| 6122 |
publicExtras.putString(EXTRA_SUBSTITUTE_APP_NAME, appName); |
| 6123 |
} |
| 6124 |
mN.extras = publicExtras; |
| 6125 |
RemoteViews view; |
| 6126 |
StandardTemplateParams params = mParams.reset() |
| 6127 |
.viewType(StandardTemplateParams.VIEW_TYPE_PUBLIC) |
| 6128 |
.fillTextsFrom(this); |
| 6129 |
if (isLowPriority) { |
| 6130 |
params.highlightExpander(false); |
| 6131 |
} |
| 6132 |
view = makeNotificationHeader(params); |
| 6133 |
view.setBoolean(R.id.notification_header, "setExpandOnlyOnButton", true); |
| 6134 |
mN.extras = savedBundle; |
| 6135 |
mN.mLargeIcon = largeIcon; |
| 6136 |
mN.largeIcon = largeIconLegacy; |
| 6137 |
mActions = actions; |
| 6138 |
mStyle = style; |
| 6139 |
return view; |
| 6140 |
} |
| 6141 |
|
| 6142 |
|
| 6143 |
|
| 6144 |
|
| 6145 |
|
| 6146 |
|
| 6147 |
|
| 6148 |
|
| 6149 |
|
| 6150 |
public RemoteViews makeLowPriorityContentView(boolean useRegularSubtext) { |
| 6151 |
StandardTemplateParams p = mParams.reset() |
| 6152 |
.viewType(StandardTemplateParams.VIEW_TYPE_MINIMIZED) |
| 6153 |
.highlightExpander(false) |
| 6154 |
.fillTextsFrom(this); |
| 6155 |
if (!useRegularSubtext || TextUtils.isEmpty(p.summaryText)) { |
| 6156 |
p.summaryText(createSummaryText()); |
| 6157 |
} |
| 6158 |
RemoteViews header = makeNotificationHeader(p); |
| 6159 |
header.setBoolean(R.id.notification_header, "setAcceptAllTouches", true); |
| 6160 |
|
| 6161 |
header.setBoolean(R.id.notification_header, "styleTextAsTitle", true); |
| 6162 |
return header; |
| 6163 |
} |
| 6164 |
|
| 6165 |
private CharSequence createSummaryText() { |
| 6166 |
CharSequence titleText = mN.extras.getCharSequence(Notification.EXTRA_TITLE); |
| 6167 |
if (USE_ONLY_TITLE_IN_LOW_PRIORITY_SUMMARY) { |
| 6168 |
return titleText; |
| 6169 |
} |
| 6170 |
SpannableStringBuilder summary = new SpannableStringBuilder(); |
| 6171 |
if (titleText == null) { |
| 6172 |
titleText = mN.extras.getCharSequence(Notification.EXTRA_TITLE_BIG); |
| 6173 |
} |
| 6174 |
BidiFormatter bidi = BidiFormatter.getInstance(); |
| 6175 |
if (titleText != null) { |
| 6176 |
summary.append(bidi.unicodeWrap(titleText)); |
| 6177 |
} |
| 6178 |
CharSequence contentText = mN.extras.getCharSequence(Notification.EXTRA_TEXT); |
| 6179 |
if (titleText != null && contentText != null) { |
| 6180 |
summary.append(bidi.unicodeWrap(mContext.getText( |
| 6181 |
R.string.notification_header_divider_symbol_with_spaces))); |
| 6182 |
} |
| 6183 |
if (contentText != null) { |
| 6184 |
summary.append(bidi.unicodeWrap(contentText)); |
| 6185 |
} |
| 6186 |
return summary; |
| 6187 |
} |
| 6188 |
|
| 6189 |
private RemoteViews generateActionButton(Action action, boolean emphasizedMode, |
| 6190 |
StandardTemplateParams p) { |
| 6191 |
final boolean tombstone = (action.actionIntent == null); |
| 6192 |
RemoteViews button = new BuilderRemoteViews(mContext.getApplicationInfo(), |
| 6193 |
emphasizedMode ? getEmphasizedActionLayoutResource() |
| 6194 |
: tombstone ? getActionTombstoneLayoutResource() |
| 6195 |
: getActionLayoutResource()); |
| 6196 |
if (!tombstone) { |
| 6197 |
button.setOnClickPendingIntent(R.id.action0, action.actionIntent); |
| 6198 |
} |
| 6199 |
button.setContentDescription(R.id.action0, action.title); |
| 6200 |
if (action.mRemoteInputs != null) { |
| 6201 |
button.setRemoteInputs(R.id.action0, action.mRemoteInputs); |
| 6202 |
} |
| 6203 |
if (emphasizedMode) { |
| 6204 |
|
| 6205 |
CharSequence title = action.title; |
| 6206 |
int buttonFillColor = getColors(p).getSecondaryAccentColor(); |
| 6207 |
if (isLegacy()) { |
| 6208 |
title = ContrastColorUtil.clearColorSpans(title); |
| 6209 |
} else { |
| 6210 |
|
| 6211 |
Integer fullLengthColor = getFullLengthSpanColor(title); |
| 6212 |
if (fullLengthColor != null) { |
| 6213 |
|
| 6214 |
int notifBackgroundColor = getColors(p).getBackgroundColor(); |
| 6215 |
buttonFillColor = ensureButtonFillContrast( |
| 6216 |
fullLengthColor, notifBackgroundColor); |
| 6217 |
} |
| 6218 |
|
| 6219 |
title = ensureColorSpanContrast(title, buttonFillColor); |
| 6220 |
} |
| 6221 |
button.setTextViewText(R.id.action0, processTextSpans(title)); |
| 6222 |
final int textColor = ContrastColorUtil.resolvePrimaryColor(mContext, |
| 6223 |
buttonFillColor, mInNightMode); |
| 6224 |
button.setTextColor(R.id.action0, textColor); |
| 6225 |
|
| 6226 |
final int rippleColor = (textColor & 0x00ffffff) | 0x33000000; |
| 6227 |
button.setColorStateList(R.id.action0, "setRippleColor", |
| 6228 |
ColorStateList.valueOf(rippleColor)); |
| 6229 |
button.setColorStateList(R.id.action0, "setButtonBackground", |
| 6230 |
ColorStateList.valueOf(buttonFillColor)); |
| 6231 |
if (p.mCallStyleActions) { |
| 6232 |
button.setImageViewIcon(R.id.action0, action.getIcon()); |
| 6233 |
boolean priority = action.getExtras().getBoolean(CallStyle.KEY_ACTION_PRIORITY); |
| 6234 |
button.setBoolean(R.id.action0, "setIsPriority", priority); |
| 6235 |
int minWidthDimen = |
| 6236 |
priority ? R.dimen.call_notification_system_action_min_width : 0; |
| 6237 |
button.setIntDimen(R.id.action0, "setMinimumWidth", minWidthDimen); |
| 6238 |
} |
| 6239 |
} else { |
| 6240 |
button.setTextViewText(R.id.action0, processTextSpans( |
| 6241 |
processLegacyText(action.title))); |
| 6242 |
button.setTextColor(R.id.action0, getStandardActionColor(p)); |
| 6243 |
} |
| 6244 |
|
| 6245 |
|
| 6246 |
int actionIndex = mActions.indexOf(action); |
| 6247 |
if (actionIndex != -1) { |
| 6248 |
button.setIntTag(R.id.action0, R.id.notification_action_index_tag, actionIndex); |
| 6249 |
} |
| 6250 |
return button; |
| 6251 |
} |
| 6252 |
|
| 6253 |
|
| 6254 |
|
| 6255 |
|
| 6256 |
|
| 6257 |
|
| 6258 |
|
| 6259 |
|
| 6260 |
|
| 6261 |
@VisibleForTesting |
| 6262 |
@Nullable |
| 6263 |
public static Integer getFullLengthSpanColor(CharSequence charSequence) { |
| 6264 |
|
| 6265 |
|
| 6266 |
Integer result = null; |
| 6267 |
if (charSequence instanceof Spanned) { |
| 6268 |
Spanned ss = (Spanned) charSequence; |
| 6269 |
Object[] spans = ss.getSpans(0, ss.length(), Object.class); |
| 6270 |
|
| 6271 |
|
| 6272 |
for (Object span : spans) { |
| 6273 |
int spanStart = ss.getSpanStart(span); |
| 6274 |
int spanEnd = ss.getSpanEnd(span); |
| 6275 |
boolean fullLength = (spanEnd - spanStart) == charSequence.length(); |
| 6276 |
if (!fullLength) { |
| 6277 |
continue; |
| 6278 |
} |
| 6279 |
if (span instanceof TextAppearanceSpan) { |
| 6280 |
TextAppearanceSpan originalSpan = (TextAppearanceSpan) span; |
| 6281 |
ColorStateList textColor = originalSpan.getTextColor(); |
| 6282 |
if (textColor != null) { |
| 6283 |
result = textColor.getDefaultColor(); |
| 6284 |
} |
| 6285 |
} else if (span instanceof ForegroundColorSpan) { |
| 6286 |
ForegroundColorSpan originalSpan = (ForegroundColorSpan) span; |
| 6287 |
result = originalSpan.getForegroundColor(); |
| 6288 |
} |
| 6289 |
} |
| 6290 |
} |
| 6291 |
return result; |
| 6292 |
} |
| 6293 |
|
| 6294 |
|
| 6295 |
|
| 6296 |
|
| 6297 |
|
| 6298 |
|
| 6299 |
|
| 6300 |
|
| 6301 |
|
| 6302 |
|
| 6303 |
@VisibleForTesting |
| 6304 |
public static CharSequence ensureColorSpanContrast(CharSequence charSequence, |
| 6305 |
int background) { |
| 6306 |
if (charSequence instanceof Spanned) { |
| 6307 |
Spanned ss = (Spanned) charSequence; |
| 6308 |
Object[] spans = ss.getSpans(0, ss.length(), Object.class); |
| 6309 |
SpannableStringBuilder builder = new SpannableStringBuilder(ss.toString()); |
| 6310 |
for (Object span : spans) { |
| 6311 |
Object resultSpan = span; |
| 6312 |
int spanStart = ss.getSpanStart(span); |
| 6313 |
int spanEnd = ss.getSpanEnd(span); |
| 6314 |
boolean fullLength = (spanEnd - spanStart) == charSequence.length(); |
| 6315 |
if (resultSpan instanceof CharacterStyle) { |
| 6316 |
resultSpan = ((CharacterStyle) span).getUnderlying(); |
| 6317 |
} |
| 6318 |
if (resultSpan instanceof TextAppearanceSpan) { |
| 6319 |
TextAppearanceSpan originalSpan = (TextAppearanceSpan) resultSpan; |
| 6320 |
ColorStateList textColor = originalSpan.getTextColor(); |
| 6321 |
if (textColor != null) { |
| 6322 |
if (fullLength) { |
| 6323 |
|
| 6324 |
textColor = null; |
| 6325 |
} else { |
| 6326 |
int[] colors = textColor.getColors(); |
| 6327 |
int[] newColors = new int[colors.length]; |
| 6328 |
for (int i = 0; i < newColors.length; i++) { |
| 6329 |
boolean isBgDark = isColorDark(background); |
| 6330 |
newColors[i] = ContrastColorUtil.ensureLargeTextContrast( |
| 6331 |
colors[i], background, isBgDark); |
| 6332 |
} |
| 6333 |
textColor = new ColorStateList(textColor.getStates().clone(), |
| 6334 |
newColors); |
| 6335 |
} |
| 6336 |
resultSpan = new TextAppearanceSpan( |
| 6337 |
originalSpan.getFamily(), |
| 6338 |
originalSpan.getTextStyle(), |
| 6339 |
originalSpan.getTextSize(), |
| 6340 |
textColor, |
| 6341 |
originalSpan.getLinkTextColor()); |
| 6342 |
} |
| 6343 |
} else if (resultSpan instanceof ForegroundColorSpan) { |
| 6344 |
if (fullLength) { |
| 6345 |
resultSpan = null; |
| 6346 |
} else { |
| 6347 |
ForegroundColorSpan originalSpan = (ForegroundColorSpan) resultSpan; |
| 6348 |
int foregroundColor = originalSpan.getForegroundColor(); |
| 6349 |
boolean isBgDark = isColorDark(background); |
| 6350 |
foregroundColor = ContrastColorUtil.ensureLargeTextContrast( |
| 6351 |
foregroundColor, background, isBgDark); |
| 6352 |
resultSpan = new ForegroundColorSpan(foregroundColor); |
| 6353 |
} |
| 6354 |
} else { |
| 6355 |
resultSpan = span; |
| 6356 |
} |
| 6357 |
if (resultSpan != null) { |
| 6358 |
builder.setSpan(resultSpan, spanStart, spanEnd, ss.getSpanFlags(span)); |
| 6359 |
} |
| 6360 |
} |
| 6361 |
return builder; |
| 6362 |
} |
| 6363 |
return charSequence; |
| 6364 |
} |
| 6365 |
|
| 6366 |
|
| 6367 |
|
| 6368 |
|
| 6369 |
|
| 6370 |
|
| 6371 |
|
| 6372 |
|
| 6373 |
|
| 6374 |
|
| 6375 |
public static boolean isColorDark(int color) { |
| 6376 |
|
| 6377 |
return ContrastColorUtil.calculateLuminance(color) <= 0.17912878474; |
| 6378 |
} |
| 6379 |
|
| 6380 |
|
| 6381 |
|
| 6382 |
|
| 6383 |
|
| 6384 |
|
| 6385 |
|
| 6386 |
|
| 6387 |
@VisibleForTesting |
| 6388 |
public static int ensureButtonFillContrast(int color, int bg) { |
| 6389 |
return isColorDark(bg) |
| 6390 |
? ContrastColorUtil.findContrastColorAgainstDark(color, bg, true, 1.3) |
| 6391 |
: ContrastColorUtil.findContrastColor(color, bg, true, 1.3); |
| 6392 |
} |
| 6393 |
|
| 6394 |
|
| 6395 |
|
| 6396 |
|
| 6397 |
|
| 6398 |
|
| 6399 |
private boolean isLegacy() { |
| 6400 |
if (!mIsLegacyInitialized) { |
| 6401 |
mIsLegacy = mContext.getApplicationInfo().targetSdkVersion |
| 6402 |
< Build.VERSION_CODES.LOLLIPOP; |
| 6403 |
mIsLegacyInitialized = true; |
| 6404 |
} |
| 6405 |
return mIsLegacy; |
| 6406 |
} |
| 6407 |
|
| 6408 |
private CharSequence processLegacyText(CharSequence charSequence) { |
| 6409 |
boolean isAlreadyLightText = isLegacy() || textColorsNeedInversion(); |
| 6410 |
if (isAlreadyLightText) { |
| 6411 |
return getColorUtil().invertCharSequenceColors(charSequence); |
| 6412 |
} else { |
| 6413 |
return charSequence; |
| 6414 |
} |
| 6415 |
} |
| 6416 |
|
| 6417 |
|
| 6418 |
|
| 6419 |
|
| 6420 |
private void processSmallIconColor(Icon smallIcon, RemoteViews contentView, |
| 6421 |
StandardTemplateParams p) { |
| 6422 |
boolean colorable = !isLegacy() || getColorUtil().isGrayscaleIcon(mContext, smallIcon); |
| 6423 |
int color = getSmallIconColor(p); |
| 6424 |
contentView.setInt(R.id.icon, "setBackgroundColor", |
| 6425 |
getBackgroundColor(p)); |
| 6426 |
contentView.setInt(R.id.icon, "setOriginalIconColor", |
| 6427 |
colorable ? color : COLOR_INVALID); |
| 6428 |
} |
| 6429 |
|
| 6430 |
|
| 6431 |
|
| 6432 |
|
| 6433 |
|
| 6434 |
|
| 6435 |
private void processLargeLegacyIcon(Icon largeIcon, RemoteViews contentView, |
| 6436 |
StandardTemplateParams p) { |
| 6437 |
if (largeIcon != null && isLegacy() |
| 6438 |
&& getColorUtil().isGrayscaleIcon(mContext, largeIcon)) { |
| 6439 |
|
| 6440 |
int color = getSmallIconColor(p); |
| 6441 |
contentView.setInt(R.id.icon, "setOriginalIconColor", color); |
| 6442 |
} |
| 6443 |
} |
| 6444 |
|
| 6445 |
private void sanitizeColor() { |
| 6446 |
if (mN.color != COLOR_DEFAULT) { |
| 6447 |
mN.color |= 0xFF000000; |
| 6448 |
} |
| 6449 |
} |
| 6450 |
|
| 6451 |
|
| 6452 |
|
| 6453 |
|
| 6454 |
private @ColorInt int getStandardActionColor(Notification.StandardTemplateParams p) { |
| 6455 |
return mTintActionButtons || isBackgroundColorized(p) |
| 6456 |
? getPrimaryAccentColor(p) : getSecondaryTextColor(p); |
| 6457 |
} |
| 6458 |
|
| 6459 |
|
| 6460 |
|
| 6461 |
|
| 6462 |
|
| 6463 |
private @ColorInt int getSmallIconColor(StandardTemplateParams p) { |
| 6464 |
return getColors(p).getContrastColor(); |
| 6465 |
} |
| 6466 |
|
| 6467 |
|
| 6468 |
private @ColorInt int getPrimaryAccentColor(StandardTemplateParams p) { |
| 6469 |
return getColors(p).getPrimaryAccentColor(); |
| 6470 |
} |
| 6471 |
|
| 6472 |
|
| 6473 |
|
| 6474 |
|
| 6475 |
|
| 6476 |
@NonNull |
| 6477 |
public Notification buildUnstyled() { |
| 6478 |
if (mActions.size() > 0) { |
| 6479 |
mN.actions = new Action[mActions.size()]; |
| 6480 |
mActions.toArray(mN.actions); |
| 6481 |
} |
| 6482 |
if (!mPersonList.isEmpty()) { |
| 6483 |
mN.extras.putParcelableArrayList(EXTRA_PEOPLE_LIST, mPersonList); |
| 6484 |
} |
| 6485 |
if (mN.bigContentView != null || mN.contentView != null |
| 6486 |
|| mN.headsUpContentView != null) { |
| 6487 |
mN.extras.putBoolean(EXTRA_CONTAINS_CUSTOM_VIEW, true); |
| 6488 |
} |
| 6489 |
return mN; |
| 6490 |
} |
| 6491 |
|
| 6492 |
|
| 6493 |
|
| 6494 |
|
| 6495 |
|
| 6496 |
|
| 6497 |
@NonNull |
| 6498 |
public static Notification.Builder recoverBuilder(Context context, Notification n) { |
| 6499 |
|
| 6500 |
ApplicationInfo applicationInfo = n.extras.getParcelable( |
| 6501 |
EXTRA_BUILDER_APPLICATION_INFO, ApplicationInfo.class); |
| 6502 |
Context builderContext; |
| 6503 |
if (applicationInfo != null) { |
| 6504 |
try { |
| 6505 |
builderContext = context.createApplicationContext(applicationInfo, |
| 6506 |
Context.CONTEXT_RESTRICTED); |
| 6507 |
} catch (NameNotFoundException e) { |
| 6508 |
Log.e(TAG, "ApplicationInfo " + applicationInfo + " not found"); |
| 6509 |
builderContext = context; |
| 6510 |
} |
| 6511 |
} else { |
| 6512 |
builderContext = context; |
| 6513 |
} |
| 6514 |
|
| 6515 |
return new Builder(builderContext, n); |
| 6516 |
} |
| 6517 |
|
| 6518 |
|
| 6519 |
|
| 6520 |
|
| 6521 |
|
| 6522 |
@NonNull |
| 6523 |
public Builder setAllowSystemGeneratedContextualActions(boolean allowed) { |
| 6524 |
mN.mAllowSystemGeneratedContextualActions = allowed; |
| 6525 |
return this; |
| 6526 |
} |
| 6527 |
|
| 6528 |
|
| 6529 |
|
| 6530 |
|
| 6531 |
@Deprecated |
| 6532 |
public Notification getNotification() { |
| 6533 |
return build(); |
| 6534 |
} |
| 6535 |
|
| 6536 |
|
| 6537 |
|
| 6538 |
|
| 6539 |
|
| 6540 |
|
| 6541 |
|
| 6542 |
|
| 6543 |
|
| 6544 |
|
| 6545 |
|
| 6546 |
|
| 6547 |
|
| 6548 |
@NonNull |
| 6549 |
public Notification build() { |
| 6550 |
|
| 6551 |
if (mN.mShortcutId != null |
| 6552 |
&& mN.mBubbleMetadata != null |
| 6553 |
&& mN.mBubbleMetadata.getShortcutId() != null |
| 6554 |
&& !mN.mShortcutId.equals(mN.mBubbleMetadata.getShortcutId())) { |
| 6555 |
throw new IllegalArgumentException( |
| 6556 |
"Notification and BubbleMetadata shortcut id's don't match," |
| 6557 |
+ " notification: " + mN.mShortcutId |
| 6558 |
+ " vs bubble: " + mN.mBubbleMetadata.getShortcutId()); |
| 6559 |
} |
| 6560 |
|
| 6561 |
|
| 6562 |
if (mUserExtras != null) { |
| 6563 |
mN.extras = getAllExtras(); |
| 6564 |
} |
| 6565 |
|
| 6566 |
mN.creationTime = System.currentTimeMillis(); |
| 6567 |
|
| 6568 |
|
| 6569 |
Notification.addFieldsFromContext(mContext, mN); |
| 6570 |
|
| 6571 |
buildUnstyled(); |
| 6572 |
|
| 6573 |
if (mStyle != null) { |
| 6574 |
mStyle.reduceImageSizes(mContext); |
| 6575 |
mStyle.purgeResources(); |
| 6576 |
mStyle.validate(mContext); |
| 6577 |
mStyle.buildStyled(mN); |
| 6578 |
} |
| 6579 |
mN.reduceImageSizes(mContext); |
| 6580 |
|
| 6581 |
if (mContext.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N |
| 6582 |
&& !styleDisplaysCustomViewInline()) { |
| 6583 |
RemoteViews newContentView = mN.contentView; |
| 6584 |
RemoteViews newBigContentView = mN.bigContentView; |
| 6585 |
RemoteViews newHeadsUpContentView = mN.headsUpContentView; |
| 6586 |
if (newContentView == null) { |
| 6587 |
newContentView = createContentView(); |
| 6588 |
mN.extras.putInt(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT, |
| 6589 |
newContentView.getSequenceNumber()); |
| 6590 |
} |
| 6591 |
if (newBigContentView == null) { |
| 6592 |
newBigContentView = createBigContentView(); |
| 6593 |
if (newBigContentView != null) { |
| 6594 |
mN.extras.putInt(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT, |
| 6595 |
newBigContentView.getSequenceNumber()); |
| 6596 |
} |
| 6597 |
} |
| 6598 |
if (newHeadsUpContentView == null) { |
| 6599 |
newHeadsUpContentView = createHeadsUpContentView(); |
| 6600 |
if (newHeadsUpContentView != null) { |
| 6601 |
mN.extras.putInt(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT, |
| 6602 |
newHeadsUpContentView.getSequenceNumber()); |
| 6603 |
} |
| 6604 |
} |
| 6605 |
|
| 6606 |
|
| 6607 |
|
| 6608 |
mN.contentView = newContentView; |
| 6609 |
mN.bigContentView = newBigContentView; |
| 6610 |
mN.headsUpContentView = newHeadsUpContentView; |
| 6611 |
} |
| 6612 |
|
| 6613 |
if ((mN.defaults & DEFAULT_LIGHTS) != 0) { |
| 6614 |
mN.flags |= FLAG_SHOW_LIGHTS; |
| 6615 |
} |
| 6616 |
|
| 6617 |
mN.allPendingIntents = null; |
| 6618 |
|
| 6619 |
return mN; |
| 6620 |
} |
| 6621 |
|
| 6622 |
private boolean styleDisplaysCustomViewInline() { |
| 6623 |
return mStyle != null && mStyle.displayCustomViewInline(); |
| 6624 |
} |
| 6625 |
|
| 6626 |
|
| 6627 |
|
| 6628 |
|
| 6629 |
|
| 6630 |
|
| 6631 |
@NonNull |
| 6632 |
public Notification buildInto(@NonNull Notification n) { |
| 6633 |
build().cloneInto(n, true); |
| 6634 |
return n; |
| 6635 |
} |
| 6636 |
|
| 6637 |
|
| 6638 |
|
| 6639 |
|
| 6640 |
|
| 6641 |
|
| 6642 |
|
| 6643 |
|
| 6644 |
|
| 6645 |
public static Notification maybeCloneStrippedForDelivery(Notification n) { |
| 6646 |
String templateClass = n.extras.getString(EXTRA_TEMPLATE); |
| 6647 |
|
| 6648 |
|
| 6649 |
|
| 6650 |
if (!TextUtils.isEmpty(templateClass) |
| 6651 |
&& getNotificationStyleClass(templateClass) == null) { |
| 6652 |
return n; |
| 6653 |
} |
| 6654 |
|
| 6655 |
|
| 6656 |
boolean stripContentView = n.contentView instanceof BuilderRemoteViews && |
| 6657 |
n.extras.getInt(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT, -1) == |
| 6658 |
n.contentView.getSequenceNumber(); |
| 6659 |
boolean stripBigContentView = n.bigContentView instanceof BuilderRemoteViews && |
| 6660 |
n.extras.getInt(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT, -1) == |
| 6661 |
n.bigContentView.getSequenceNumber(); |
| 6662 |
boolean stripHeadsUpContentView = n.headsUpContentView instanceof BuilderRemoteViews && |
| 6663 |
n.extras.getInt(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT, -1) == |
| 6664 |
n.headsUpContentView.getSequenceNumber(); |
| 6665 |
|
| 6666 |
|
| 6667 |
if (!stripContentView && !stripBigContentView && !stripHeadsUpContentView) { |
| 6668 |
return n; |
| 6669 |
} |
| 6670 |
|
| 6671 |
Notification clone = n.clone(); |
| 6672 |
if (stripContentView) { |
| 6673 |
clone.contentView = null; |
| 6674 |
clone.extras.remove(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT); |
| 6675 |
} |
| 6676 |
if (stripBigContentView) { |
| 6677 |
clone.bigContentView = null; |
| 6678 |
clone.extras.remove(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT); |
| 6679 |
} |
| 6680 |
if (stripHeadsUpContentView) { |
| 6681 |
clone.headsUpContentView = null; |
| 6682 |
clone.extras.remove(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT); |
| 6683 |
} |
| 6684 |
return clone; |
| 6685 |
} |
| 6686 |
|
| 6687 |
@UnsupportedAppUsage |
| 6688 |
private int getBaseLayoutResource() { |
| 6689 |
return R.layout.notification_template_material_base; |
| 6690 |
} |
| 6691 |
|
| 6692 |
private int getHeadsUpBaseLayoutResource() { |
| 6693 |
return R.layout.notification_template_material_heads_up_base; |
| 6694 |
} |
| 6695 |
|
| 6696 |
private int getBigBaseLayoutResource() { |
| 6697 |
return R.layout.notification_template_material_big_base; |
| 6698 |
} |
| 6699 |
|
| 6700 |
private int getBigPictureLayoutResource() { |
| 6701 |
return R.layout.notification_template_material_big_picture; |
| 6702 |
} |
| 6703 |
|
| 6704 |
private int getBigTextLayoutResource() { |
| 6705 |
return R.layout.notification_template_material_big_text; |
| 6706 |
} |
| 6707 |
|
| 6708 |
private int getInboxLayoutResource() { |
| 6709 |
return R.layout.notification_template_material_inbox; |
| 6710 |
} |
| 6711 |
|
| 6712 |
private int getMessagingLayoutResource() { |
| 6713 |
return R.layout.notification_template_material_messaging; |
| 6714 |
} |
| 6715 |
|
| 6716 |
private int getBigMessagingLayoutResource() { |
| 6717 |
return R.layout.notification_template_material_big_messaging; |
| 6718 |
} |
| 6719 |
|
| 6720 |
private int getConversationLayoutResource() { |
| 6721 |
return R.layout.notification_template_material_conversation; |
| 6722 |
} |
| 6723 |
|
| 6724 |
private int getActionLayoutResource() { |
| 6725 |
return R.layout.notification_material_action; |
| 6726 |
} |
| 6727 |
|
| 6728 |
private int getEmphasizedActionLayoutResource() { |
| 6729 |
return R.layout.notification_material_action_emphasized; |
| 6730 |
} |
| 6731 |
|
| 6732 |
private int getActionTombstoneLayoutResource() { |
| 6733 |
return R.layout.notification_material_action_tombstone; |
| 6734 |
} |
| 6735 |
|
| 6736 |
private @ColorInt int getBackgroundColor(StandardTemplateParams p) { |
| 6737 |
return getColors(p).getBackgroundColor(); |
| 6738 |
} |
| 6739 |
|
| 6740 |
private boolean textColorsNeedInversion() { |
| 6741 |
if (mStyle == null || !MediaStyle.class.equals(mStyle.getClass())) { |
| 6742 |
return false; |
| 6743 |
} |
| 6744 |
int targetSdkVersion = mContext.getApplicationInfo().targetSdkVersion; |
| 6745 |
return targetSdkVersion > Build.VERSION_CODES.M |
| 6746 |
&& targetSdkVersion < Build.VERSION_CODES.O; |
| 6747 |
} |
| 6748 |
|
| 6749 |
|
| 6750 |
|
| 6751 |
|
| 6752 |
|
| 6753 |
|
| 6754 |
|
| 6755 |
|
| 6756 |
|
| 6757 |
public CharSequence getHeadsUpStatusBarText(boolean publicMode) { |
| 6758 |
if (mStyle != null && !publicMode) { |
| 6759 |
CharSequence text = mStyle.getHeadsUpStatusBarText(); |
| 6760 |
if (!TextUtils.isEmpty(text)) { |
| 6761 |
return text; |
| 6762 |
} |
| 6763 |
} |
| 6764 |
return loadHeaderAppName(); |
| 6765 |
} |
| 6766 |
|
| 6767 |
|
| 6768 |
|
| 6769 |
|
| 6770 |
|
| 6771 |
|
| 6772 |
public boolean usesTemplate() { |
| 6773 |
return (mN.contentView == null && mN.headsUpContentView == null |
| 6774 |
&& mN.bigContentView == null) |
| 6775 |
|| styleDisplaysCustomViewInline(); |
| 6776 |
} |
| 6777 |
} |
| 6778 |
|
| 6779 |
|
| 6780 |
|
| 6781 |
|
| 6782 |
|
| 6783 |
|
| 6784 |
|
| 6785 |
void reduceImageSizes(Context context) { |
| 6786 |
if (extras.getBoolean(EXTRA_REDUCED_IMAGES)) { |
| 6787 |
return; |
| 6788 |
} |
| 6789 |
boolean isLowRam = ActivityManager.isLowRamDeviceStatic(); |
| 6790 |
|
| 6791 |
if (mSmallIcon != null |
| 6792 |
|
| 6793 |
&& (mSmallIcon.getType() == Icon.TYPE_BITMAP |
| 6794 |
|| mSmallIcon.getType() == Icon.TYPE_ADAPTIVE_BITMAP)) { |
| 6795 |
Resources resources = context.getResources(); |
| 6796 |
int maxSize = resources.getDimensionPixelSize( |
| 6797 |
isLowRam ? R.dimen.notification_small_icon_size_low_ram |
| 6798 |
: R.dimen.notification_small_icon_size); |
| 6799 |
mSmallIcon.scaleDownIfNecessary(maxSize, maxSize); |
| 6800 |
} |
| 6801 |
|
| 6802 |
if (mLargeIcon != null || largeIcon != null) { |
| 6803 |
Resources resources = context.getResources(); |
| 6804 |
Class<? extends Style> style = getNotificationStyle(); |
| 6805 |
int maxSize = resources.getDimensionPixelSize(isLowRam |
| 6806 |
? R.dimen.notification_right_icon_size_low_ram |
| 6807 |
: R.dimen.notification_right_icon_size); |
| 6808 |
if (mLargeIcon != null) { |
| 6809 |
mLargeIcon.scaleDownIfNecessary(maxSize, maxSize); |
| 6810 |
} |
| 6811 |
if (largeIcon != null) { |
| 6812 |
largeIcon = Icon.scaleDownIfNecessary(largeIcon, maxSize, maxSize); |
| 6813 |
} |
| 6814 |
} |
| 6815 |
reduceImageSizesForRemoteView(contentView, context, isLowRam); |
| 6816 |
reduceImageSizesForRemoteView(headsUpContentView, context, isLowRam); |
| 6817 |
reduceImageSizesForRemoteView(bigContentView, context, isLowRam); |
| 6818 |
extras.putBoolean(EXTRA_REDUCED_IMAGES, true); |
| 6819 |
} |
| 6820 |
|
| 6821 |
private void reduceImageSizesForRemoteView(RemoteViews remoteView, Context context, |
| 6822 |
boolean isLowRam) { |
| 6823 |
if (remoteView != null) { |
| 6824 |
Resources resources = context.getResources(); |
| 6825 |
int maxWidth = resources.getDimensionPixelSize(isLowRam |
| 6826 |
? R.dimen.notification_custom_view_max_image_width_low_ram |
| 6827 |
: R.dimen.notification_custom_view_max_image_width); |
| 6828 |
int maxHeight = resources.getDimensionPixelSize(isLowRam |
| 6829 |
? R.dimen.notification_custom_view_max_image_height_low_ram |
| 6830 |
: R.dimen.notification_custom_view_max_image_height); |
| 6831 |
remoteView.reduceImageSizes(maxWidth, maxHeight); |
| 6832 |
} |
| 6833 |
} |
| 6834 |
|
| 6835 |
|
| 6836 |
|
| 6837 |
|
| 6838 |
|
| 6839 |
public boolean isForegroundService() { |
| 6840 |
return (flags & Notification.FLAG_FOREGROUND_SERVICE) != 0; |
| 6841 |
} |
| 6842 |
|
| 6843 |
|
| 6844 |
|
| 6845 |
|
| 6846 |
|
| 6847 |
|
| 6848 |
|
| 6849 |
|
| 6850 |
|
| 6851 |
|
| 6852 |
|
| 6853 |
|
| 6854 |
|
| 6855 |
|
| 6856 |
|
| 6857 |
|
| 6858 |
|
| 6859 |
|
| 6860 |
|
| 6861 |
|
| 6862 |
|
| 6863 |
|
| 6864 |
|
| 6865 |
|
| 6866 |
|
| 6867 |
|
| 6868 |
@TestApi |
| 6869 |
public boolean shouldShowForegroundImmediately() { |
| 6870 |
|
| 6871 |
if (mFgsDeferBehavior == FOREGROUND_SERVICE_IMMEDIATE) { |
| 6872 |
return true; |
| 6873 |
} |
| 6874 |
|
| 6875 |
|
| 6876 |
if (mFgsDeferBehavior == FOREGROUND_SERVICE_DEFERRED) { |
| 6877 |
return false; |
| 6878 |
} |
| 6879 |
|
| 6880 |
|
| 6881 |
|
| 6882 |
if (isMediaNotification() |
| 6883 |
|| CATEGORY_CALL.equals(category) |
| 6884 |
|| CATEGORY_NAVIGATION.equals(category) |
| 6885 |
|| (actions != null && actions.length > 0)) { |
| 6886 |
return true; |
| 6887 |
} |
| 6888 |
|
| 6889 |
|
| 6890 |
return false; |
| 6891 |
} |
| 6892 |
|
| 6893 |
|
| 6894 |
|
| 6895 |
|
| 6896 |
|
| 6897 |
public boolean isForegroundDisplayForceDeferred() { |
| 6898 |
return FOREGROUND_SERVICE_DEFERRED == mFgsDeferBehavior; |
| 6899 |
} |
| 6900 |
|
| 6901 |
|
| 6902 |
|
| 6903 |
|
| 6904 |
|
| 6905 |
public Class<? extends Notification.Style> getNotificationStyle() { |
| 6906 |
String templateClass = extras.getString(Notification.EXTRA_TEMPLATE); |
| 6907 |
|
| 6908 |
if (!TextUtils.isEmpty(templateClass)) { |
| 6909 |
return Notification.getNotificationStyleClass(templateClass); |
| 6910 |
} |
| 6911 |
return null; |
| 6912 |
} |
| 6913 |
|
| 6914 |
|
| 6915 |
|
| 6916 |
|
| 6917 |
|
| 6918 |
public boolean isStyle(@NonNull Class<? extends Style> styleClass) { |
| 6919 |
String templateClass = extras.getString(Notification.EXTRA_TEMPLATE); |
| 6920 |
return Objects.equals(templateClass, styleClass.getName()); |
| 6921 |
} |
| 6922 |
|
| 6923 |
|
| 6924 |
|
| 6925 |
|
| 6926 |
|
| 6927 |
|
| 6928 |
|
| 6929 |
|
| 6930 |
public boolean isColorized() { |
| 6931 |
return extras.getBoolean(EXTRA_COLORIZED) |
| 6932 |
&& (hasColorizedPermission() || isForegroundService()); |
| 6933 |
} |
| 6934 |
|
| 6935 |
|
| 6936 |
|
| 6937 |
|
| 6938 |
|
| 6939 |
private boolean hasColorizedPermission() { |
| 6940 |
return (flags & Notification.FLAG_CAN_COLORIZE) != 0; |
| 6941 |
} |
| 6942 |
|
| 6943 |
|
| 6944 |
|
| 6945 |
|
| 6946 |
|
| 6947 |
|
| 6948 |
public boolean isMediaNotification() { |
| 6949 |
Class<? extends Style> style = getNotificationStyle(); |
| 6950 |
boolean isMediaStyle = (MediaStyle.class.equals(style) |
| 6951 |
|| DecoratedMediaCustomViewStyle.class.equals(style)); |
| 6952 |
|
| 6953 |
boolean hasMediaSession = extras.getParcelable(Notification.EXTRA_MEDIA_SESSION, |
| 6954 |
MediaSession.Token.class) != null; |
| 6955 |
|
| 6956 |
return isMediaStyle && hasMediaSession; |
| 6957 |
} |
| 6958 |
|
| 6959 |
|
| 6960 |
|
| 6961 |
|
| 6962 |
|
| 6963 |
|
| 6964 |
public boolean isBubbleNotification() { |
| 6965 |
return (flags & Notification.FLAG_BUBBLE) != 0; |
| 6966 |
} |
| 6967 |
|
| 6968 |
private boolean hasLargeIcon() { |
| 6969 |
return mLargeIcon != null || largeIcon != null; |
| 6970 |
} |
| 6971 |
|
| 6972 |
|
| 6973 |
|
| 6974 |
|
| 6975 |
|
| 6976 |
public boolean showsTime() { |
| 6977 |
return when != 0 && extras.getBoolean(EXTRA_SHOW_WHEN); |
| 6978 |
} |
| 6979 |
|
| 6980 |
|
| 6981 |
|
| 6982 |
|
| 6983 |
|
| 6984 |
public boolean showsChronometer() { |
| 6985 |
return when != 0 && extras.getBoolean(EXTRA_SHOW_CHRONOMETER); |
| 6986 |
} |
| 6987 |
|
| 6988 |
|
| 6989 |
|
| 6990 |
|
| 6991 |
public boolean hasImage() { |
| 6992 |
if (isStyle(MessagingStyle.class) && extras != null) { |
| 6993 |
final Parcelable[] messages = extras.getParcelableArray(EXTRA_MESSAGES); |
| 6994 |
if (!ArrayUtils.isEmpty(messages)) { |
| 6995 |
for (MessagingStyle.Message m : MessagingStyle.Message |
| 6996 |
.getMessagesFromBundleArray(messages)) { |
| 6997 |
if (m.getDataUri() != null |
| 6998 |
&& m.getDataMimeType() != null |
| 6999 |
&& m.getDataMimeType().startsWith("image/")) { |
| 7000 |
return true; |
| 7001 |
} |
| 7002 |
} |
| 7003 |
} |
| 7004 |
} else if (hasLargeIcon()) { |
| 7005 |
return true; |
| 7006 |
} else if (extras.containsKey(EXTRA_BACKGROUND_IMAGE_URI)) { |
| 7007 |
return true; |
| 7008 |
} |
| 7009 |
return false; |
| 7010 |
} |
| 7011 |
|
| 7012 |
|
| 7013 |
|
| 7014 |
|
| 7015 |
|
| 7016 |
@SystemApi |
| 7017 |
public static Class<? extends Style> getNotificationStyleClass(String templateClass) { |
| 7018 |
for (Class<? extends Style> innerClass : PLATFORM_STYLE_CLASSES) { |
| 7019 |
if (templateClass.equals(innerClass.getName())) { |
| 7020 |
return innerClass; |
| 7021 |
} |
| 7022 |
} |
| 7023 |
return null; |
| 7024 |
} |
| 7025 |
|
| 7026 |
private static void buildCustomContentIntoTemplate(@NonNull Context context, |
| 7027 |
@NonNull RemoteViews template, @Nullable RemoteViews customContent, |
| 7028 |
@NonNull StandardTemplateParams p, @NonNull TemplateBindResult result) { |
| 7029 |
int childIndex = -1; |
| 7030 |
if (customContent != null) { |
| 7031 |
|
| 7032 |
|
| 7033 |
customContent = customContent.clone(); |
| 7034 |
if (p.mHeaderless) { |
| 7035 |
template.removeFromParent(R.id.notification_top_line); |
| 7036 |
|
| 7037 |
|
| 7038 |
|
| 7039 |
Builder.setHeaderlessVerticalMargins(template, p, true ); |
| 7040 |
} else { |
| 7041 |
|
| 7042 |
Resources resources = context.getResources(); |
| 7043 |
result.mTitleMarginSet.applyToView(template, R.id.notification_main_column, |
| 7044 |
resources.getDimension(R.dimen.notification_content_margin_end) |
| 7045 |
/ resources.getDisplayMetrics().density); |
| 7046 |
} |
| 7047 |
template.removeAllViewsExceptId(R.id.notification_main_column, R.id.progress); |
| 7048 |
template.addView(R.id.notification_main_column, customContent, 0 ); |
| 7049 |
template.addFlags(RemoteViews.FLAG_REAPPLY_DISALLOWED); |
| 7050 |
childIndex = 0; |
| 7051 |
} |
| 7052 |
template.setIntTag(R.id.notification_main_column, |
| 7053 |
com.android.internal.R.id.notification_custom_view_index_tag, |
| 7054 |
childIndex); |
| 7055 |
} |
| 7056 |
|
| 7057 |
|
| 7058 |
|
| 7059 |
|
| 7060 |
|
| 7061 |
public static abstract class Style { |
| 7062 |
|
| 7063 |
|
| 7064 |
|
| 7065 |
|
| 7066 |
|
| 7067 |
static final int MAX_REMOTE_INPUT_HISTORY_LINES = 3; |
| 7068 |
private CharSequence mBigContentTitle; |
| 7069 |
|
| 7070 |
|
| 7071 |
|
| 7072 |
|
| 7073 |
protected CharSequence mSummaryText = null; |
| 7074 |
|
| 7075 |
|
| 7076 |
|
| 7077 |
|
| 7078 |
protected boolean mSummaryTextSet = false; |
| 7079 |
|
| 7080 |
protected Builder mBuilder; |
| 7081 |
|
| 7082 |
|
| 7083 |
|
| 7084 |
|
| 7085 |
|
| 7086 |
protected void internalSetBigContentTitle(CharSequence title) { |
| 7087 |
mBigContentTitle = title; |
| 7088 |
} |
| 7089 |
|
| 7090 |
|
| 7091 |
|
| 7092 |
|
| 7093 |
protected void internalSetSummaryText(CharSequence cs) { |
| 7094 |
mSummaryText = cs; |
| 7095 |
mSummaryTextSet = true; |
| 7096 |
} |
| 7097 |
|
| 7098 |
public void setBuilder(Builder builder) { |
| 7099 |
if (mBuilder != builder) { |
| 7100 |
mBuilder = builder; |
| 7101 |
if (mBuilder != null) { |
| 7102 |
mBuilder.setStyle(this); |
| 7103 |
} |
| 7104 |
} |
| 7105 |
} |
| 7106 |
|
| 7107 |
protected void checkBuilder() { |
| 7108 |
if (mBuilder == null) { |
| 7109 |
throw new IllegalArgumentException("Style requires a valid Builder object"); |
| 7110 |
} |
| 7111 |
} |
| 7112 |
|
| 7113 |
protected RemoteViews getStandardView(int layoutId) { |
| 7114 |
|
| 7115 |
StandardTemplateParams p = mBuilder.mParams.reset() |
| 7116 |
.viewType(StandardTemplateParams.VIEW_TYPE_UNSPECIFIED) |
| 7117 |
.fillTextsFrom(mBuilder); |
| 7118 |
return getStandardView(layoutId, p, null); |
| 7119 |
} |
| 7120 |
|
| 7121 |
|
| 7122 |
|
| 7123 |
|
| 7124 |
|
| 7125 |
|
| 7126 |
|
| 7127 |
|
| 7128 |
|
| 7129 |
|
| 7130 |
|
| 7131 |
protected RemoteViews getStandardView(int layoutId, StandardTemplateParams p, |
| 7132 |
TemplateBindResult result) { |
| 7133 |
checkBuilder(); |
| 7134 |
|
| 7135 |
if (mBigContentTitle != null) { |
| 7136 |
p.title = mBigContentTitle; |
| 7137 |
} |
| 7138 |
|
| 7139 |
return mBuilder.applyStandardTemplateWithActions(layoutId, p, result); |
| 7140 |
} |
| 7141 |
|
| 7142 |
|
| 7143 |
|
| 7144 |
|
| 7145 |
|
| 7146 |
|
| 7147 |
|
| 7148 |
|
| 7149 |
public RemoteViews makeContentView(boolean increasedHeight) { |
| 7150 |
return null; |
| 7151 |
} |
| 7152 |
|
| 7153 |
|
| 7154 |
|
| 7155 |
|
| 7156 |
|
| 7157 |
public RemoteViews makeBigContentView() { |
| 7158 |
return null; |
| 7159 |
} |
| 7160 |
|
| 7161 |
|
| 7162 |
|
| 7163 |
|
| 7164 |
|
| 7165 |
|
| 7166 |
|
| 7167 |
public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
| 7168 |
return null; |
| 7169 |
} |
| 7170 |
|
| 7171 |
|
| 7172 |
|
| 7173 |
|
| 7174 |
|
| 7175 |
public void addExtras(Bundle extras) { |
| 7176 |
if (mSummaryTextSet) { |
| 7177 |
extras.putCharSequence(EXTRA_SUMMARY_TEXT, mSummaryText); |
| 7178 |
} |
| 7179 |
if (mBigContentTitle != null) { |
| 7180 |
extras.putCharSequence(EXTRA_TITLE_BIG, mBigContentTitle); |
| 7181 |
} |
| 7182 |
extras.putString(EXTRA_TEMPLATE, this.getClass().getName()); |
| 7183 |
} |
| 7184 |
|
| 7185 |
|
| 7186 |
|
| 7187 |
|
| 7188 |
|
| 7189 |
protected void restoreFromExtras(Bundle extras) { |
| 7190 |
if (extras.containsKey(EXTRA_SUMMARY_TEXT)) { |
| 7191 |
mSummaryText = extras.getCharSequence(EXTRA_SUMMARY_TEXT); |
| 7192 |
mSummaryTextSet = true; |
| 7193 |
} |
| 7194 |
if (extras.containsKey(EXTRA_TITLE_BIG)) { |
| 7195 |
mBigContentTitle = extras.getCharSequence(EXTRA_TITLE_BIG); |
| 7196 |
} |
| 7197 |
} |
| 7198 |
|
| 7199 |
|
| 7200 |
|
| 7201 |
|
| 7202 |
|
| 7203 |
public Notification buildStyled(Notification wip) { |
| 7204 |
addExtras(wip.extras); |
| 7205 |
return wip; |
| 7206 |
} |
| 7207 |
|
| 7208 |
|
| 7209 |
|
| 7210 |
|
| 7211 |
public void purgeResources() {} |
| 7212 |
|
| 7213 |
|
| 7214 |
|
| 7215 |
|
| 7216 |
|
| 7217 |
|
| 7218 |
|
| 7219 |
public Notification build() { |
| 7220 |
checkBuilder(); |
| 7221 |
return mBuilder.build(); |
| 7222 |
} |
| 7223 |
|
| 7224 |
|
| 7225 |
|
| 7226 |
|
| 7227 |
|
| 7228 |
public boolean hasSummaryInHeader() { |
| 7229 |
return true; |
| 7230 |
} |
| 7231 |
|
| 7232 |
|
| 7233 |
|
| 7234 |
|
| 7235 |
|
| 7236 |
public boolean displayCustomViewInline() { |
| 7237 |
return false; |
| 7238 |
} |
| 7239 |
|
| 7240 |
|
| 7241 |
|
| 7242 |
|
| 7243 |
|
| 7244 |
|
| 7245 |
public void reduceImageSizes(Context context) { |
| 7246 |
} |
| 7247 |
|
| 7248 |
|
| 7249 |
|
| 7250 |
|
| 7251 |
|
| 7252 |
public void validate(Context context) { |
| 7253 |
} |
| 7254 |
|
| 7255 |
|
| 7256 |
|
| 7257 |
|
| 7258 |
public abstract boolean areNotificationsVisiblyDifferent(Style other); |
| 7259 |
|
| 7260 |
|
| 7261 |
|
| 7262 |
|
| 7263 |
|
| 7264 |
|
| 7265 |
|
| 7266 |
public CharSequence getHeadsUpStatusBarText() { |
| 7267 |
return null; |
| 7268 |
} |
| 7269 |
} |
| 7270 |
|
| 7271 |
|
| 7272 |
|
| 7273 |
|
| 7274 |
|
| 7275 |
|
| 7276 |
|
| 7277 |
|
| 7278 |
|
| 7279 |
|
| 7280 |
|
| 7281 |
|
| 7282 |
|
| 7283 |
|
| 7284 |
|
| 7285 |
|
| 7286 |
|
| 7287 |
|
| 7288 |
public static class BigPictureStyle extends Style { |
| 7289 |
private Icon mPictureIcon; |
| 7290 |
private Icon mBigLargeIcon; |
| 7291 |
private boolean mBigLargeIconSet = false; |
| 7292 |
private CharSequence mPictureContentDescription; |
| 7293 |
private boolean mShowBigPictureWhenCollapsed; |
| 7294 |
|
| 7295 |
public BigPictureStyle() { |
| 7296 |
} |
| 7297 |
|
| 7298 |
|
| 7299 |
|
| 7300 |
|
| 7301 |
@Deprecated |
| 7302 |
public BigPictureStyle(Builder builder) { |
| 7303 |
setBuilder(builder); |
| 7304 |
} |
| 7305 |
|
| 7306 |
|
| 7307 |
|
| 7308 |
|
| 7309 |
|
| 7310 |
@NonNull |
| 7311 |
public BigPictureStyle setBigContentTitle(@Nullable CharSequence title) { |
| 7312 |
internalSetBigContentTitle(safeCharSequence(title)); |
| 7313 |
return this; |
| 7314 |
} |
| 7315 |
|
| 7316 |
|
| 7317 |
|
| 7318 |
|
| 7319 |
@NonNull |
| 7320 |
public BigPictureStyle setSummaryText(@Nullable CharSequence cs) { |
| 7321 |
internalSetSummaryText(safeCharSequence(cs)); |
| 7322 |
return this; |
| 7323 |
} |
| 7324 |
|
| 7325 |
|
| 7326 |
|
| 7327 |
|
| 7328 |
@NonNull |
| 7329 |
public BigPictureStyle setContentDescription( |
| 7330 |
@Nullable CharSequence contentDescription) { |
| 7331 |
mPictureContentDescription = contentDescription; |
| 7332 |
return this; |
| 7333 |
} |
| 7334 |
|
| 7335 |
|
| 7336 |
|
| 7337 |
|
| 7338 |
@Nullable |
| 7339 |
public Icon getBigPicture() { |
| 7340 |
if (mPictureIcon != null) { |
| 7341 |
return mPictureIcon; |
| 7342 |
} |
| 7343 |
return null; |
| 7344 |
} |
| 7345 |
|
| 7346 |
|
| 7347 |
|
| 7348 |
|
| 7349 |
@NonNull |
| 7350 |
public BigPictureStyle bigPicture(@Nullable Bitmap b) { |
| 7351 |
mPictureIcon = b == null ? null : Icon.createWithBitmap(b); |
| 7352 |
return this; |
| 7353 |
} |
| 7354 |
|
| 7355 |
|
| 7356 |
|
| 7357 |
|
| 7358 |
@NonNull |
| 7359 |
public BigPictureStyle bigPicture(@Nullable Icon icon) { |
| 7360 |
mPictureIcon = icon; |
| 7361 |
return this; |
| 7362 |
} |
| 7363 |
|
| 7364 |
|
| 7365 |
|
| 7366 |
|
| 7367 |
|
| 7368 |
|
| 7369 |
@NonNull |
| 7370 |
public BigPictureStyle showBigPictureWhenCollapsed(boolean show) { |
| 7371 |
mShowBigPictureWhenCollapsed = show; |
| 7372 |
return this; |
| 7373 |
} |
| 7374 |
|
| 7375 |
|
| 7376 |
|
| 7377 |
|
| 7378 |
@NonNull |
| 7379 |
public BigPictureStyle bigLargeIcon(@Nullable Bitmap b) { |
| 7380 |
return bigLargeIcon(b != null ? Icon.createWithBitmap(b) : null); |
| 7381 |
} |
| 7382 |
|
| 7383 |
|
| 7384 |
|
| 7385 |
|
| 7386 |
@NonNull |
| 7387 |
public BigPictureStyle bigLargeIcon(@Nullable Icon icon) { |
| 7388 |
mBigLargeIconSet = true; |
| 7389 |
mBigLargeIcon = icon; |
| 7390 |
return this; |
| 7391 |
} |
| 7392 |
|
| 7393 |
|
| 7394 |
public static final int MIN_ASHMEM_BITMAP_SIZE = 128 * (1 << 10); |
| 7395 |
|
| 7396 |
|
| 7397 |
|
| 7398 |
|
| 7399 |
@Override |
| 7400 |
public void purgeResources() { |
| 7401 |
super.purgeResources(); |
| 7402 |
if (mPictureIcon != null) { |
| 7403 |
mPictureIcon.convertToAshmem(); |
| 7404 |
} |
| 7405 |
if (mBigLargeIcon != null) { |
| 7406 |
mBigLargeIcon.convertToAshmem(); |
| 7407 |
} |
| 7408 |
} |
| 7409 |
|
| 7410 |
|
| 7411 |
|
| 7412 |
|
| 7413 |
@Override |
| 7414 |
public void reduceImageSizes(Context context) { |
| 7415 |
super.reduceImageSizes(context); |
| 7416 |
Resources resources = context.getResources(); |
| 7417 |
boolean isLowRam = ActivityManager.isLowRamDeviceStatic(); |
| 7418 |
if (mPictureIcon != null) { |
| 7419 |
int maxPictureWidth = resources.getDimensionPixelSize(isLowRam |
| 7420 |
? R.dimen.notification_big_picture_max_height_low_ram |
| 7421 |
: R.dimen.notification_big_picture_max_height); |
| 7422 |
int maxPictureHeight = resources.getDimensionPixelSize(isLowRam |
| 7423 |
? R.dimen.notification_big_picture_max_width_low_ram |
| 7424 |
: R.dimen.notification_big_picture_max_width); |
| 7425 |
mPictureIcon.scaleDownIfNecessary(maxPictureWidth, maxPictureHeight); |
| 7426 |
} |
| 7427 |
if (mBigLargeIcon != null) { |
| 7428 |
int rightIconSize = resources.getDimensionPixelSize(isLowRam |
| 7429 |
? R.dimen.notification_right_icon_size_low_ram |
| 7430 |
: R.dimen.notification_right_icon_size); |
| 7431 |
mBigLargeIcon.scaleDownIfNecessary(rightIconSize, rightIconSize); |
| 7432 |
} |
| 7433 |
} |
| 7434 |
|
| 7435 |
|
| 7436 |
|
| 7437 |
|
| 7438 |
@Override |
| 7439 |
public RemoteViews makeContentView(boolean increasedHeight) { |
| 7440 |
if (mPictureIcon == null || !mShowBigPictureWhenCollapsed) { |
| 7441 |
return super.makeContentView(increasedHeight); |
| 7442 |
} |
| 7443 |
|
| 7444 |
StandardTemplateParams p = mBuilder.mParams.reset() |
| 7445 |
.viewType(StandardTemplateParams.VIEW_TYPE_NORMAL) |
| 7446 |
.fillTextsFrom(mBuilder) |
| 7447 |
.promotedPicture(mPictureIcon); |
| 7448 |
return getStandardView(mBuilder.getBaseLayoutResource(), p, null ); |
| 7449 |
} |
| 7450 |
|
| 7451 |
|
| 7452 |
|
| 7453 |
|
| 7454 |
@Override |
| 7455 |
public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
| 7456 |
if (mPictureIcon == null || !mShowBigPictureWhenCollapsed) { |
| 7457 |
return super.makeHeadsUpContentView(increasedHeight); |
| 7458 |
} |
| 7459 |
|
| 7460 |
StandardTemplateParams p = mBuilder.mParams.reset() |
| 7461 |
.viewType(StandardTemplateParams.VIEW_TYPE_HEADS_UP) |
| 7462 |
.fillTextsFrom(mBuilder) |
| 7463 |
.promotedPicture(mPictureIcon); |
| 7464 |
return getStandardView(mBuilder.getHeadsUpBaseLayoutResource(), p, null ); |
| 7465 |
} |
| 7466 |
|
| 7467 |
|
| 7468 |
|
| 7469 |
|
| 7470 |
public RemoteViews makeBigContentView() { |
| 7471 |
|
| 7472 |
|
| 7473 |
|
| 7474 |
|
| 7475 |
|
| 7476 |
Icon oldLargeIcon = null; |
| 7477 |
Bitmap largeIconLegacy = null; |
| 7478 |
if (mBigLargeIconSet) { |
| 7479 |
oldLargeIcon = mBuilder.mN.mLargeIcon; |
| 7480 |
mBuilder.mN.mLargeIcon = mBigLargeIcon; |
| 7481 |
|
| 7482 |
|
| 7483 |
|
| 7484 |
largeIconLegacy = mBuilder.mN.largeIcon; |
| 7485 |
mBuilder.mN.largeIcon = null; |
| 7486 |
} |
| 7487 |
|
| 7488 |
StandardTemplateParams p = mBuilder.mParams.reset() |
| 7489 |
.viewType(StandardTemplateParams.VIEW_TYPE_BIG).fillTextsFrom(mBuilder); |
| 7490 |
RemoteViews contentView = getStandardView(mBuilder.getBigPictureLayoutResource(), |
| 7491 |
p, null ); |
| 7492 |
if (mSummaryTextSet) { |
| 7493 |
contentView.setTextViewText(R.id.text, mBuilder.processTextSpans( |
| 7494 |
mBuilder.processLegacyText(mSummaryText))); |
| 7495 |
mBuilder.setTextViewColorSecondary(contentView, R.id.text, p); |
| 7496 |
contentView.setViewVisibility(R.id.text, View.VISIBLE); |
| 7497 |
} |
| 7498 |
|
| 7499 |
if (mBigLargeIconSet) { |
| 7500 |
mBuilder.mN.mLargeIcon = oldLargeIcon; |
| 7501 |
mBuilder.mN.largeIcon = largeIconLegacy; |
| 7502 |
} |
| 7503 |
|
| 7504 |
contentView.setImageViewIcon(R.id.big_picture, mPictureIcon); |
| 7505 |
|
| 7506 |
if (mPictureContentDescription != null) { |
| 7507 |
contentView.setContentDescription(R.id.big_picture, mPictureContentDescription); |
| 7508 |
} |
| 7509 |
|
| 7510 |
return contentView; |
| 7511 |
} |
| 7512 |
|
| 7513 |
|
| 7514 |
|
| 7515 |
|
| 7516 |
public void addExtras(Bundle extras) { |
| 7517 |
super.addExtras(extras); |
| 7518 |
|
| 7519 |
if (mBigLargeIconSet) { |
| 7520 |
extras.putParcelable(EXTRA_LARGE_ICON_BIG, mBigLargeIcon); |
| 7521 |
} |
| 7522 |
if (mPictureContentDescription != null) { |
| 7523 |
extras.putCharSequence(EXTRA_PICTURE_CONTENT_DESCRIPTION, |
| 7524 |
mPictureContentDescription); |
| 7525 |
} |
| 7526 |
extras.putBoolean(EXTRA_SHOW_BIG_PICTURE_WHEN_COLLAPSED, mShowBigPictureWhenCollapsed); |
| 7527 |
|
| 7528 |
|
| 7529 |
|
| 7530 |
|
| 7531 |
if (mPictureIcon != null && mPictureIcon.getType() == Icon.TYPE_BITMAP) { |
| 7532 |
extras.putParcelable(EXTRA_PICTURE, mPictureIcon.getBitmap()); |
| 7533 |
extras.putParcelable(EXTRA_PICTURE_ICON, null); |
| 7534 |
} else { |
| 7535 |
extras.putParcelable(EXTRA_PICTURE, null); |
| 7536 |
extras.putParcelable(EXTRA_PICTURE_ICON, mPictureIcon); |
| 7537 |
} |
| 7538 |
} |
| 7539 |
|
| 7540 |
|
| 7541 |
|
| 7542 |
|
| 7543 |
@Override |
| 7544 |
protected void restoreFromExtras(Bundle extras) { |
| 7545 |
super.restoreFromExtras(extras); |
| 7546 |
|
| 7547 |
if (extras.containsKey(EXTRA_LARGE_ICON_BIG)) { |
| 7548 |
mBigLargeIconSet = true; |
| 7549 |
mBigLargeIcon = extras.getParcelable(EXTRA_LARGE_ICON_BIG, Icon.class); |
| 7550 |
} |
| 7551 |
|
| 7552 |
if (extras.containsKey(EXTRA_PICTURE_CONTENT_DESCRIPTION)) { |
| 7553 |
mPictureContentDescription = |
| 7554 |
extras.getCharSequence(EXTRA_PICTURE_CONTENT_DESCRIPTION); |
| 7555 |
} |
| 7556 |
|
| 7557 |
mShowBigPictureWhenCollapsed = extras.getBoolean(EXTRA_SHOW_BIG_PICTURE_WHEN_COLLAPSED); |
| 7558 |
|
| 7559 |
mPictureIcon = getPictureIcon(extras); |
| 7560 |
} |
| 7561 |
|
| 7562 |
|
| 7563 |
@Nullable |
| 7564 |
public static Icon getPictureIcon(@Nullable Bundle extras) { |
| 7565 |
if (extras == null) return null; |
| 7566 |
|
| 7567 |
|
| 7568 |
|
| 7569 |
Bitmap bitmapPicture = extras.getParcelable(EXTRA_PICTURE, Bitmap.class); |
| 7570 |
if (bitmapPicture != null) { |
| 7571 |
return Icon.createWithBitmap(bitmapPicture); |
| 7572 |
} else { |
| 7573 |
return extras.getParcelable(EXTRA_PICTURE_ICON, Icon.class); |
| 7574 |
} |
| 7575 |
} |
| 7576 |
|
| 7577 |
|
| 7578 |
|
| 7579 |
|
| 7580 |
@Override |
| 7581 |
public boolean hasSummaryInHeader() { |
| 7582 |
return false; |
| 7583 |
} |
| 7584 |
|
| 7585 |
|
| 7586 |
|
| 7587 |
|
| 7588 |
|
| 7589 |
|
| 7590 |
@Override |
| 7591 |
public boolean areNotificationsVisiblyDifferent(Style other) { |
| 7592 |
if (other == null || getClass() != other.getClass()) { |
| 7593 |
return true; |
| 7594 |
} |
| 7595 |
BigPictureStyle otherS = (BigPictureStyle) other; |
| 7596 |
return areIconsObviouslyDifferent(getBigPicture(), otherS.getBigPicture()); |
| 7597 |
} |
| 7598 |
|
| 7599 |
private static boolean areIconsObviouslyDifferent(Icon a, Icon b) { |
| 7600 |
if (a == b) { |
| 7601 |
return false; |
| 7602 |
} |
| 7603 |
if (a == null || b == null) { |
| 7604 |
return true; |
| 7605 |
} |
| 7606 |
if (a.sameAs(b)) { |
| 7607 |
return false; |
| 7608 |
} |
| 7609 |
final int aType = a.getType(); |
| 7610 |
if (aType != b.getType()) { |
| 7611 |
return true; |
| 7612 |
} |
| 7613 |
if (aType == Icon.TYPE_BITMAP || aType == Icon.TYPE_ADAPTIVE_BITMAP) { |
| 7614 |
final Bitmap aBitmap = a.getBitmap(); |
| 7615 |
final Bitmap bBitmap = b.getBitmap(); |
| 7616 |
return aBitmap.getWidth() != bBitmap.getWidth() |
| 7617 |
|| aBitmap.getHeight() != bBitmap.getHeight() |
| 7618 |
|| aBitmap.getConfig() != bBitmap.getConfig() |
| 7619 |
|| aBitmap.getGenerationId() != bBitmap.getGenerationId(); |
| 7620 |
} |
| 7621 |
return true; |
| 7622 |
} |
| 7623 |
} |
| 7624 |
|
| 7625 |
|
| 7626 |
|
| 7627 |
|
| 7628 |
|
| 7629 |
|
| 7630 |
|
| 7631 |
|
| 7632 |
|
| 7633 |
|
| 7634 |
|
| 7635 |
|
| 7636 |
|
| 7637 |
|
| 7638 |
|
| 7639 |
|
| 7640 |
|
| 7641 |
|
| 7642 |
public static class BigTextStyle extends Style { |
| 7643 |
|
| 7644 |
private CharSequence mBigText; |
| 7645 |
|
| 7646 |
public BigTextStyle() { |
| 7647 |
} |
| 7648 |
|
| 7649 |
|
| 7650 |
|
| 7651 |
|
| 7652 |
@Deprecated |
| 7653 |
public BigTextStyle(Builder builder) { |
| 7654 |
setBuilder(builder); |
| 7655 |
} |
| 7656 |
|
| 7657 |
|
| 7658 |
|
| 7659 |
|
| 7660 |
|
| 7661 |
public BigTextStyle setBigContentTitle(CharSequence title) { |
| 7662 |
internalSetBigContentTitle(safeCharSequence(title)); |
| 7663 |
return this; |
| 7664 |
} |
| 7665 |
|
| 7666 |
|
| 7667 |
|
| 7668 |
|
| 7669 |
public BigTextStyle setSummaryText(CharSequence cs) { |
| 7670 |
internalSetSummaryText(safeCharSequence(cs)); |
| 7671 |
return this; |
| 7672 |
} |
| 7673 |
|
| 7674 |
|
| 7675 |
|
| 7676 |
|
| 7677 |
|
| 7678 |
public BigTextStyle bigText(CharSequence cs) { |
| 7679 |
mBigText = safeCharSequence(cs); |
| 7680 |
return this; |
| 7681 |
} |
| 7682 |
|
| 7683 |
|
| 7684 |
|
| 7685 |
|
| 7686 |
public CharSequence getBigText() { |
| 7687 |
return mBigText; |
| 7688 |
} |
| 7689 |
|
| 7690 |
|
| 7691 |
|
| 7692 |
|
| 7693 |
public void addExtras(Bundle extras) { |
| 7694 |
super.addExtras(extras); |
| 7695 |
|
| 7696 |
extras.putCharSequence(EXTRA_BIG_TEXT, mBigText); |
| 7697 |
} |
| 7698 |
|
| 7699 |
|
| 7700 |
|
| 7701 |
|
| 7702 |
@Override |
| 7703 |
protected void restoreFromExtras(Bundle extras) { |
| 7704 |
super.restoreFromExtras(extras); |
| 7705 |
|
| 7706 |
mBigText = extras.getCharSequence(EXTRA_BIG_TEXT); |
| 7707 |
} |
| 7708 |
|
| 7709 |
|
| 7710 |
|
| 7711 |
|
| 7712 |
|
| 7713 |
|
| 7714 |
@Override |
| 7715 |
public RemoteViews makeContentView(boolean increasedHeight) { |
| 7716 |
if (increasedHeight) { |
| 7717 |
ArrayList<Action> originalActions = mBuilder.mActions; |
| 7718 |
mBuilder.mActions = new ArrayList<>(); |
| 7719 |
RemoteViews remoteViews = makeBigContentView(); |
| 7720 |
mBuilder.mActions = originalActions; |
| 7721 |
return remoteViews; |
| 7722 |
} |
| 7723 |
return super.makeContentView(increasedHeight); |
| 7724 |
} |
| 7725 |
|
| 7726 |
|
| 7727 |
|
| 7728 |
|
| 7729 |
@Override |
| 7730 |
public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
| 7731 |
if (increasedHeight && mBuilder.mActions.size() > 0) { |
| 7732 |
|
| 7733 |
return makeBigContentView(); |
| 7734 |
} |
| 7735 |
return super.makeHeadsUpContentView(increasedHeight); |
| 7736 |
} |
| 7737 |
|
| 7738 |
|
| 7739 |
|
| 7740 |
|
| 7741 |
public RemoteViews makeBigContentView() { |
| 7742 |
StandardTemplateParams p = mBuilder.mParams.reset() |
| 7743 |
.viewType(StandardTemplateParams.VIEW_TYPE_BIG) |
| 7744 |
.allowTextWithProgress(true) |
| 7745 |
.textViewId(R.id.big_text) |
| 7746 |
.fillTextsFrom(mBuilder); |
| 7747 |
|
| 7748 |
|
| 7749 |
CharSequence bigTextText = mBuilder.processLegacyText(mBigText); |
| 7750 |
if (!TextUtils.isEmpty(bigTextText)) { |
| 7751 |
p.text(bigTextText); |
| 7752 |
} |
| 7753 |
|
| 7754 |
return getStandardView(mBuilder.getBigTextLayoutResource(), p, null ); |
| 7755 |
} |
| 7756 |
|
| 7757 |
|
| 7758 |
|
| 7759 |
|
| 7760 |
|
| 7761 |
@Override |
| 7762 |
public boolean areNotificationsVisiblyDifferent(Style other) { |
| 7763 |
if (other == null || getClass() != other.getClass()) { |
| 7764 |
return true; |
| 7765 |
} |
| 7766 |
BigTextStyle newS = (BigTextStyle) other; |
| 7767 |
return !Objects.equals(String.valueOf(getBigText()), String.valueOf(newS.getBigText())); |
| 7768 |
} |
| 7769 |
|
| 7770 |
} |
| 7771 |
|
| 7772 |
|
| 7773 |
|
| 7774 |
|
| 7775 |
|
| 7776 |
|
| 7777 |
|
| 7778 |
|
| 7779 |
|
| 7780 |
|
| 7781 |
|
| 7782 |
|
| 7783 |
|
| 7784 |
|
| 7785 |
|
| 7786 |
|
| 7787 |
|
| 7788 |
|
| 7789 |
|
| 7790 |
|
| 7791 |
|
| 7792 |
|
| 7793 |
|
| 7794 |
|
| 7795 |
|
| 7796 |
|
| 7797 |
|
| 7798 |
|
| 7799 |
|
| 7800 |
|
| 7801 |
|
| 7802 |
|
| 7803 |
|
| 7804 |
|
| 7805 |
|
| 7806 |
|
| 7807 |
public static class MessagingStyle extends Style { |
| 7808 |
|
| 7809 |
|
| 7810 |
|
| 7811 |
|
| 7812 |
|
| 7813 |
public static final int MAXIMUM_RETAINED_MESSAGES = 25; |
| 7814 |
|
| 7815 |
|
| 7816 |
|
| 7817 |
public static final int CONVERSATION_TYPE_LEGACY = 0; |
| 7818 |
|
| 7819 |
public static final int CONVERSATION_TYPE_NORMAL = 1; |
| 7820 |
|
| 7821 |
public static final int CONVERSATION_TYPE_IMPORTANT = 2; |
| 7822 |
|
| 7823 |
|
| 7824 |
@IntDef(prefix = {"CONVERSATION_TYPE_"}, value = { |
| 7825 |
CONVERSATION_TYPE_LEGACY, CONVERSATION_TYPE_NORMAL, CONVERSATION_TYPE_IMPORTANT |
| 7826 |
}) |
| 7827 |
@Retention(RetentionPolicy.SOURCE) |
| 7828 |
public @interface ConversationType {} |
| 7829 |
|
| 7830 |
@NonNull Person mUser; |
| 7831 |
@Nullable CharSequence mConversationTitle; |
| 7832 |
@Nullable Icon mShortcutIcon; |
| 7833 |
List<Message> mMessages = new ArrayList<>(); |
| 7834 |
List<Message> mHistoricMessages = new ArrayList<>(); |
| 7835 |
boolean mIsGroupConversation; |
| 7836 |
@ConversationType int mConversationType = CONVERSATION_TYPE_LEGACY; |
| 7837 |
int mUnreadMessageCount; |
| 7838 |
|
| 7839 |
MessagingStyle() { |
| 7840 |
} |
| 7841 |
|
| 7842 |
|
| 7843 |
|
| 7844 |
|
| 7845 |
|
| 7846 |
|
| 7847 |
|
| 7848 |
|
| 7849 |
|
| 7850 |
public MessagingStyle(@NonNull CharSequence userDisplayName) { |
| 7851 |
this(new Person.Builder().setName(userDisplayName).build()); |
| 7852 |
} |
| 7853 |
|
| 7854 |
|
| 7855 |
|
| 7856 |
|
| 7857 |
|
| 7858 |
|
| 7859 |
|
| 7860 |
|
| 7861 |
public MessagingStyle(@NonNull Person user) { |
| 7862 |
mUser = user; |
| 7863 |
} |
| 7864 |
|
| 7865 |
|
| 7866 |
|
| 7867 |
|
| 7868 |
|
| 7869 |
@Override |
| 7870 |
public void validate(Context context) { |
| 7871 |
super.validate(context); |
| 7872 |
if (context.getApplicationInfo().targetSdkVersion |
| 7873 |
>= Build.VERSION_CODES.P && (mUser == null || mUser.getName() == null)) { |
| 7874 |
throw new RuntimeException("User must be valid and have a name."); |
| 7875 |
} |
| 7876 |
} |
| 7877 |
|
| 7878 |
|
| 7879 |
|
| 7880 |
|
| 7881 |
|
| 7882 |
|
| 7883 |
|
| 7884 |
@Override |
| 7885 |
public CharSequence getHeadsUpStatusBarText() { |
| 7886 |
CharSequence conversationTitle = !TextUtils.isEmpty(super.mBigContentTitle) |
| 7887 |
? super.mBigContentTitle |
| 7888 |
: mConversationTitle; |
| 7889 |
if (mConversationType == CONVERSATION_TYPE_LEGACY |
| 7890 |
&& !TextUtils.isEmpty(conversationTitle) && !hasOnlyWhiteSpaceSenders()) { |
| 7891 |
return conversationTitle; |
| 7892 |
} |
| 7893 |
return null; |
| 7894 |
} |
| 7895 |
|
| 7896 |
|
| 7897 |
|
| 7898 |
|
| 7899 |
@NonNull |
| 7900 |
public Person getUser() { |
| 7901 |
return mUser; |
| 7902 |
} |
| 7903 |
|
| 7904 |
|
| 7905 |
|
| 7906 |
|
| 7907 |
|
| 7908 |
|
| 7909 |
public CharSequence getUserDisplayName() { |
| 7910 |
return mUser.getName(); |
| 7911 |
} |
| 7912 |
|
| 7913 |
|
| 7914 |
|
| 7915 |
|
| 7916 |
|
| 7917 |
|
| 7918 |
|
| 7919 |
|
| 7920 |
|
| 7921 |
|
| 7922 |
|
| 7923 |
|
| 7924 |
|
| 7925 |
|
| 7926 |
|
| 7927 |
|
| 7928 |
|
| 7929 |
|
| 7930 |
|
| 7931 |
|
| 7932 |
public MessagingStyle setConversationTitle(@Nullable CharSequence conversationTitle) { |
| 7933 |
mConversationTitle = conversationTitle; |
| 7934 |
return this; |
| 7935 |
} |
| 7936 |
|
| 7937 |
|
| 7938 |
|
| 7939 |
|
| 7940 |
@Nullable |
| 7941 |
public CharSequence getConversationTitle() { |
| 7942 |
return mConversationTitle; |
| 7943 |
} |
| 7944 |
|
| 7945 |
|
| 7946 |
|
| 7947 |
|
| 7948 |
|
| 7949 |
|
| 7950 |
public MessagingStyle setShortcutIcon(@Nullable Icon conversationIcon) { |
| 7951 |
|
| 7952 |
|
| 7953 |
mShortcutIcon = conversationIcon; |
| 7954 |
return this; |
| 7955 |
} |
| 7956 |
|
| 7957 |
|
| 7958 |
|
| 7959 |
|
| 7960 |
|
| 7961 |
|
| 7962 |
|
| 7963 |
@Nullable |
| 7964 |
public Icon getShortcutIcon() { |
| 7965 |
return mShortcutIcon; |
| 7966 |
} |
| 7967 |
|
| 7968 |
|
| 7969 |
|
| 7970 |
|
| 7971 |
|
| 7972 |
|
| 7973 |
|
| 7974 |
|
| 7975 |
|
| 7976 |
public MessagingStyle setConversationType(@ConversationType int conversationType) { |
| 7977 |
mConversationType = conversationType; |
| 7978 |
return this; |
| 7979 |
} |
| 7980 |
|
| 7981 |
|
| 7982 |
@ConversationType |
| 7983 |
public int getConversationType() { |
| 7984 |
return mConversationType; |
| 7985 |
} |
| 7986 |
|
| 7987 |
|
| 7988 |
public int getUnreadMessageCount() { |
| 7989 |
return mUnreadMessageCount; |
| 7990 |
} |
| 7991 |
|
| 7992 |
|
| 7993 |
public MessagingStyle setUnreadMessageCount(int unreadMessageCount) { |
| 7994 |
mUnreadMessageCount = unreadMessageCount; |
| 7995 |
return this; |
| 7996 |
} |
| 7997 |
|
| 7998 |
|
| 7999 |
|
| 8000 |
|
| 8001 |
|
| 8002 |
|
| 8003 |
|
| 8004 |
|
| 8005 |
|
| 8006 |
|
| 8007 |
|
| 8008 |
|
| 8009 |
|
| 8010 |
|
| 8011 |
|
| 8012 |
|
| 8013 |
|
| 8014 |
|
| 8015 |
public MessagingStyle addMessage(CharSequence text, long timestamp, CharSequence sender) { |
| 8016 |
return addMessage(text, timestamp, |
| 8017 |
sender == null ? null : new Person.Builder().setName(sender).build()); |
| 8018 |
} |
| 8019 |
|
| 8020 |
|
| 8021 |
|
| 8022 |
|
| 8023 |
|
| 8024 |
|
| 8025 |
|
| 8026 |
|
| 8027 |
|
| 8028 |
|
| 8029 |
|
| 8030 |
|
| 8031 |
|
| 8032 |
|
| 8033 |
public MessagingStyle addMessage(@NonNull CharSequence text, long timestamp, |
| 8034 |
@Nullable Person sender) { |
| 8035 |
return addMessage(new Message(text, timestamp, sender)); |
| 8036 |
} |
| 8037 |
|
| 8038 |
|
| 8039 |
|
| 8040 |
|
| 8041 |
|
| 8042 |
|
| 8043 |
|
| 8044 |
|
| 8045 |
|
| 8046 |
|
| 8047 |
public MessagingStyle addMessage(Message message) { |
| 8048 |
mMessages.add(message); |
| 8049 |
if (mMessages.size() > MAXIMUM_RETAINED_MESSAGES) { |
| 8050 |
mMessages.remove(0); |
| 8051 |
} |
| 8052 |
return this; |
| 8053 |
} |
| 8054 |
|
| 8055 |
|
| 8056 |
|
| 8057 |
|
| 8058 |
|
| 8059 |
|
| 8060 |
|
| 8061 |
|
| 8062 |
|
| 8063 |
|
| 8064 |
|
| 8065 |
|
| 8066 |
|
| 8067 |
|
| 8068 |
public MessagingStyle addHistoricMessage(Message message) { |
| 8069 |
mHistoricMessages.add(message); |
| 8070 |
if (mHistoricMessages.size() > MAXIMUM_RETAINED_MESSAGES) { |
| 8071 |
mHistoricMessages.remove(0); |
| 8072 |
} |
| 8073 |
return this; |
| 8074 |
} |
| 8075 |
|
| 8076 |
|
| 8077 |
|
| 8078 |
|
| 8079 |
public List<Message> getMessages() { |
| 8080 |
return mMessages; |
| 8081 |
} |
| 8082 |
|
| 8083 |
|
| 8084 |
|
| 8085 |
|
| 8086 |
public List<Message> getHistoricMessages() { |
| 8087 |
return mHistoricMessages; |
| 8088 |
} |
| 8089 |
|
| 8090 |
|
| 8091 |
|
| 8092 |
|
| 8093 |
|
| 8094 |
|
| 8095 |
|
| 8096 |
|
| 8097 |
|
| 8098 |
|
| 8099 |
public MessagingStyle setGroupConversation(boolean isGroupConversation) { |
| 8100 |
mIsGroupConversation = isGroupConversation; |
| 8101 |
return this; |
| 8102 |
} |
| 8103 |
|
| 8104 |
|
| 8105 |
|
| 8106 |
|
| 8107 |
|
| 8108 |
|
| 8109 |
|
| 8110 |
|
| 8111 |
|
| 8112 |
|
| 8113 |
|
| 8114 |
|
| 8115 |
|
| 8116 |
|
| 8117 |
public boolean isGroupConversation() { |
| 8118 |
|
| 8119 |
|
| 8120 |
if (mBuilder != null |
| 8121 |
&& mBuilder.mContext.getApplicationInfo().targetSdkVersion |
| 8122 |
< Build.VERSION_CODES.P) { |
| 8123 |
return mConversationTitle != null; |
| 8124 |
} |
| 8125 |
|
| 8126 |
return mIsGroupConversation; |
| 8127 |
} |
| 8128 |
|
| 8129 |
|
| 8130 |
|
| 8131 |
|
| 8132 |
@Override |
| 8133 |
public void addExtras(Bundle extras) { |
| 8134 |
super.addExtras(extras); |
| 8135 |
if (mUser != null) { |
| 8136 |
|
| 8137 |
extras.putCharSequence(EXTRA_SELF_DISPLAY_NAME, mUser.getName()); |
| 8138 |
extras.putParcelable(EXTRA_MESSAGING_PERSON, mUser); |
| 8139 |
} |
| 8140 |
if (mConversationTitle != null) { |
| 8141 |
extras.putCharSequence(EXTRA_CONVERSATION_TITLE, mConversationTitle); |
| 8142 |
} |
| 8143 |
if (!mMessages.isEmpty()) { extras.putParcelableArray(EXTRA_MESSAGES, |
| 8144 |
Message.getBundleArrayForMessages(mMessages)); |
| 8145 |
} |
| 8146 |
if (!mHistoricMessages.isEmpty()) { extras.putParcelableArray(EXTRA_HISTORIC_MESSAGES, |
| 8147 |
Message.getBundleArrayForMessages(mHistoricMessages)); |
| 8148 |
} |
| 8149 |
if (mShortcutIcon != null) { |
| 8150 |
extras.putParcelable(EXTRA_CONVERSATION_ICON, mShortcutIcon); |
| 8151 |
} |
| 8152 |
extras.putInt(EXTRA_CONVERSATION_UNREAD_MESSAGE_COUNT, mUnreadMessageCount); |
| 8153 |
|
| 8154 |
fixTitleAndTextExtras(extras); |
| 8155 |
extras.putBoolean(EXTRA_IS_GROUP_CONVERSATION, mIsGroupConversation); |
| 8156 |
} |
| 8157 |
|
| 8158 |
private void fixTitleAndTextExtras(Bundle extras) { |
| 8159 |
Message m = findLatestIncomingMessage(); |
| 8160 |
CharSequence text = (m == null) ? null : m.mText; |
| 8161 |
CharSequence sender = m == null ? null |
| 8162 |
: m.mSender == null || TextUtils.isEmpty(m.mSender.getName()) |
| 8163 |
? mUser.getName() : m.mSender.getName(); |
| 8164 |
CharSequence title; |
| 8165 |
if (!TextUtils.isEmpty(mConversationTitle)) { |
| 8166 |
if (!TextUtils.isEmpty(sender)) { |
| 8167 |
BidiFormatter bidi = BidiFormatter.getInstance(); |
| 8168 |
title = mBuilder.mContext.getString( |
| 8169 |
com.android.internal.R.string.notification_messaging_title_template, |
| 8170 |
bidi.unicodeWrap(mConversationTitle), bidi.unicodeWrap(sender)); |
| 8171 |
} else { |
| 8172 |
title = mConversationTitle; |
| 8173 |
} |
| 8174 |
} else { |
| 8175 |
title = sender; |
| 8176 |
} |
| 8177 |
|
| 8178 |
if (title != null) { |
| 8179 |
extras.putCharSequence(EXTRA_TITLE, title); |
| 8180 |
} |
| 8181 |
if (text != null) { |
| 8182 |
extras.putCharSequence(EXTRA_TEXT, text); |
| 8183 |
} |
| 8184 |
} |
| 8185 |
|
| 8186 |
|
| 8187 |
|
| 8188 |
|
| 8189 |
@Override |
| 8190 |
protected void restoreFromExtras(Bundle extras) { |
| 8191 |
super.restoreFromExtras(extras); |
| 8192 |
|
| 8193 |
mUser = extras.getParcelable(EXTRA_MESSAGING_PERSON, Person.class); |
| 8194 |
if (mUser == null) { |
| 8195 |
CharSequence displayName = extras.getCharSequence(EXTRA_SELF_DISPLAY_NAME); |
| 8196 |
mUser = new Person.Builder().setName(displayName).build(); |
| 8197 |
} |
| 8198 |
mConversationTitle = extras.getCharSequence(EXTRA_CONVERSATION_TITLE); |
| 8199 |
Parcelable[] messages = extras.getParcelableArray(EXTRA_MESSAGES); |
| 8200 |
mMessages = Message.getMessagesFromBundleArray(messages); |
| 8201 |
Parcelable[] histMessages = extras.getParcelableArray(EXTRA_HISTORIC_MESSAGES); |
| 8202 |
mHistoricMessages = Message.getMessagesFromBundleArray(histMessages); |
| 8203 |
mIsGroupConversation = extras.getBoolean(EXTRA_IS_GROUP_CONVERSATION); |
| 8204 |
mUnreadMessageCount = extras.getInt(EXTRA_CONVERSATION_UNREAD_MESSAGE_COUNT); |
| 8205 |
mShortcutIcon = extras.getParcelable(EXTRA_CONVERSATION_ICON, Icon.class); |
| 8206 |
} |
| 8207 |
|
| 8208 |
|
| 8209 |
|
| 8210 |
|
| 8211 |
@Override |
| 8212 |
public RemoteViews makeContentView(boolean increasedHeight) { |
| 8213 |
|
| 8214 |
ArrayList<Action> originalActions = mBuilder.mActions; |
| 8215 |
try { |
| 8216 |
mBuilder.mActions = new ArrayList<>(); |
| 8217 |
return makeMessagingView(StandardTemplateParams.VIEW_TYPE_NORMAL); |
| 8218 |
} finally { |
| 8219 |
mBuilder.mActions = originalActions; |
| 8220 |
} |
| 8221 |
} |
| 8222 |
|
| 8223 |
|
| 8224 |
|
| 8225 |
|
| 8226 |
|
| 8227 |
@Override |
| 8228 |
public boolean areNotificationsVisiblyDifferent(Style other) { |
| 8229 |
if (other == null || getClass() != other.getClass()) { |
| 8230 |
return true; |
| 8231 |
} |
| 8232 |
MessagingStyle newS = (MessagingStyle) other; |
| 8233 |
List<MessagingStyle.Message> oldMs = getMessages(); |
| 8234 |
List<MessagingStyle.Message> newMs = newS.getMessages(); |
| 8235 |
|
| 8236 |
if (oldMs == null || newMs == null) { |
| 8237 |
newMs = new ArrayList<>(); |
| 8238 |
} |
| 8239 |
|
| 8240 |
int n = oldMs.size(); |
| 8241 |
if (n != newMs.size()) { |
| 8242 |
return true; |
| 8243 |
} |
| 8244 |
for (int i = 0; i < n; i++) { |
| 8245 |
MessagingStyle.Message oldM = oldMs.get(i); |
| 8246 |
MessagingStyle.Message newM = newMs.get(i); |
| 8247 |
if (!Objects.equals( |
| 8248 |
String.valueOf(oldM.getText()), |
| 8249 |
String.valueOf(newM.getText()))) { |
| 8250 |
return true; |
| 8251 |
} |
| 8252 |
if (!Objects.equals(oldM.getDataUri(), newM.getDataUri())) { |
| 8253 |
return true; |
| 8254 |
} |
| 8255 |
String oldSender = String.valueOf(oldM.getSenderPerson() == null |
| 8256 |
? oldM.getSender() |
| 8257 |
: oldM.getSenderPerson().getName()); |
| 8258 |
String newSender = String.valueOf(newM.getSenderPerson() == null |
| 8259 |
? newM.getSender() |
| 8260 |
: newM.getSenderPerson().getName()); |
| 8261 |
if (!Objects.equals(oldSender, newSender)) { |
| 8262 |
return true; |
| 8263 |
} |
| 8264 |
|
| 8265 |
String oldKey = oldM.getSenderPerson() == null |
| 8266 |
? null : oldM.getSenderPerson().getKey(); |
| 8267 |
String newKey = newM.getSenderPerson() == null |
| 8268 |
? null : newM.getSenderPerson().getKey(); |
| 8269 |
if (!Objects.equals(oldKey, newKey)) { |
| 8270 |
return true; |
| 8271 |
} |
| 8272 |
|
| 8273 |
} |
| 8274 |
return false; |
| 8275 |
} |
| 8276 |
|
| 8277 |
private Message findLatestIncomingMessage() { |
| 8278 |
return findLatestIncomingMessage(mMessages); |
| 8279 |
} |
| 8280 |
|
| 8281 |
|
| 8282 |
|
| 8283 |
|
| 8284 |
@Nullable |
| 8285 |
public static Message findLatestIncomingMessage( |
| 8286 |
List<Message> messages) { |
| 8287 |
for (int i = messages.size() - 1; i >= 0; i--) { |
| 8288 |
Message m = messages.get(i); |
| 8289 |
|
| 8290 |
if (m.mSender != null && !TextUtils.isEmpty(m.mSender.getName())) { |
| 8291 |
return m; |
| 8292 |
} |
| 8293 |
} |
| 8294 |
if (!messages.isEmpty()) { |
| 8295 |
|
| 8296 |
return messages.get(messages.size() - 1); |
| 8297 |
} |
| 8298 |
return null; |
| 8299 |
} |
| 8300 |
|
| 8301 |
|
| 8302 |
|
| 8303 |
|
| 8304 |
@Override |
| 8305 |
public RemoteViews makeBigContentView() { |
| 8306 |
return makeMessagingView(StandardTemplateParams.VIEW_TYPE_BIG); |
| 8307 |
} |
| 8308 |
|
| 8309 |
|
| 8310 |
|
| 8311 |
|
| 8312 |
|
| 8313 |
|
| 8314 |
|
| 8315 |
|
| 8316 |
@NonNull |
| 8317 |
private RemoteViews makeMessagingView(int viewType) { |
| 8318 |
boolean isCollapsed = viewType != StandardTemplateParams.VIEW_TYPE_BIG; |
| 8319 |
boolean hideRightIcons = viewType != StandardTemplateParams.VIEW_TYPE_NORMAL; |
| 8320 |
boolean isConversationLayout = mConversationType != CONVERSATION_TYPE_LEGACY; |
| 8321 |
boolean isImportantConversation = mConversationType == CONVERSATION_TYPE_IMPORTANT; |
| 8322 |
boolean isHeaderless = !isConversationLayout && isCollapsed; |
| 8323 |
|
| 8324 |
CharSequence conversationTitle = !TextUtils.isEmpty(super.mBigContentTitle) |
| 8325 |
? super.mBigContentTitle |
| 8326 |
: mConversationTitle; |
| 8327 |
boolean atLeastP = mBuilder.mContext.getApplicationInfo().targetSdkVersion |
| 8328 |
>= Build.VERSION_CODES.P; |
| 8329 |
boolean isOneToOne; |
| 8330 |
CharSequence nameReplacement = null; |
| 8331 |
if (!atLeastP) { |
| 8332 |
isOneToOne = TextUtils.isEmpty(conversationTitle); |
| 8333 |
if (hasOnlyWhiteSpaceSenders()) { |
| 8334 |
isOneToOne = true; |
| 8335 |
nameReplacement = conversationTitle; |
| 8336 |
conversationTitle = null; |
| 8337 |
} |
| 8338 |
} else { |
| 8339 |
isOneToOne = !isGroupConversation(); |
| 8340 |
} |
| 8341 |
if (isHeaderless && isOneToOne && TextUtils.isEmpty(conversationTitle)) { |
| 8342 |
conversationTitle = getOtherPersonName(); |
| 8343 |
} |
| 8344 |
|
| 8345 |
Icon largeIcon = mBuilder.mN.mLargeIcon; |
| 8346 |
TemplateBindResult bindResult = new TemplateBindResult(); |
| 8347 |
StandardTemplateParams p = mBuilder.mParams.reset() |
| 8348 |
.viewType(viewType) |
| 8349 |
.highlightExpander(isConversationLayout) |
| 8350 |
.hideProgress(true) |
| 8351 |
.title(isHeaderless ? conversationTitle : null) |
| 8352 |
.text(null) |
| 8353 |
.hideLeftIcon(isOneToOne) |
| 8354 |
.hideRightIcon(hideRightIcons || isOneToOne) |
| 8355 |
.headerTextSecondary(isHeaderless ? null : conversationTitle); |
| 8356 |
RemoteViews contentView = mBuilder.applyStandardTemplateWithActions( |
| 8357 |
isConversationLayout |
| 8358 |
? mBuilder.getConversationLayoutResource() |
| 8359 |
: isCollapsed |
| 8360 |
? mBuilder.getMessagingLayoutResource() |
| 8361 |
: mBuilder.getBigMessagingLayoutResource(), |
| 8362 |
p, |
| 8363 |
bindResult); |
| 8364 |
if (isConversationLayout) { |
| 8365 |
mBuilder.setTextViewColorPrimary(contentView, R.id.conversation_text, p); |
| 8366 |
mBuilder.setTextViewColorSecondary(contentView, R.id.app_name_divider, p); |
| 8367 |
} |
| 8368 |
|
| 8369 |
addExtras(mBuilder.mN.extras); |
| 8370 |
contentView.setInt(R.id.status_bar_latest_event_content, "setLayoutColor", |
| 8371 |
mBuilder.getSmallIconColor(p)); |
| 8372 |
contentView.setInt(R.id.status_bar_latest_event_content, "setSenderTextColor", |
| 8373 |
mBuilder.getPrimaryTextColor(p)); |
| 8374 |
contentView.setInt(R.id.status_bar_latest_event_content, "setMessageTextColor", |
| 8375 |
mBuilder.getSecondaryTextColor(p)); |
| 8376 |
contentView.setInt(R.id.status_bar_latest_event_content, |
| 8377 |
"setNotificationBackgroundColor", |
| 8378 |
mBuilder.getBackgroundColor(p)); |
| 8379 |
contentView.setBoolean(R.id.status_bar_latest_event_content, "setIsCollapsed", |
| 8380 |
isCollapsed); |
| 8381 |
contentView.setIcon(R.id.status_bar_latest_event_content, "setAvatarReplacement", |
| 8382 |
mBuilder.mN.mLargeIcon); |
| 8383 |
contentView.setCharSequence(R.id.status_bar_latest_event_content, "setNameReplacement", |
| 8384 |
nameReplacement); |
| 8385 |
contentView.setBoolean(R.id.status_bar_latest_event_content, "setIsOneToOne", |
| 8386 |
isOneToOne); |
| 8387 |
contentView.setCharSequence(R.id.status_bar_latest_event_content, |
| 8388 |
"setConversationTitle", conversationTitle); |
| 8389 |
if (isConversationLayout) { |
| 8390 |
contentView.setIcon(R.id.status_bar_latest_event_content, |
| 8391 |
"setShortcutIcon", mShortcutIcon); |
| 8392 |
contentView.setBoolean(R.id.status_bar_latest_event_content, |
| 8393 |
"setIsImportantConversation", isImportantConversation); |
| 8394 |
} |
| 8395 |
if (isHeaderless) { |
| 8396 |
|
| 8397 |
contentView.setInt(R.id.notification_messaging, "setMaxDisplayedLines", 1); |
| 8398 |
} |
| 8399 |
contentView.setIcon(R.id.status_bar_latest_event_content, "setLargeIcon", |
| 8400 |
largeIcon); |
| 8401 |
contentView.setBundle(R.id.status_bar_latest_event_content, "setData", |
| 8402 |
mBuilder.mN.extras); |
| 8403 |
return contentView; |
| 8404 |
} |
| 8405 |
|
| 8406 |
private CharSequence getKey(Person person) { |
| 8407 |
return person == null ? null |
| 8408 |
: person.getKey() == null ? person.getName() : person.getKey(); |
| 8409 |
} |
| 8410 |
|
| 8411 |
private CharSequence getOtherPersonName() { |
| 8412 |
CharSequence userKey = getKey(mUser); |
| 8413 |
for (int i = mMessages.size() - 1; i >= 0; i--) { |
| 8414 |
Person sender = mMessages.get(i).getSenderPerson(); |
| 8415 |
if (sender != null && !TextUtils.equals(userKey, getKey(sender))) { |
| 8416 |
return sender.getName(); |
| 8417 |
} |
| 8418 |
} |
| 8419 |
return null; |
| 8420 |
} |
| 8421 |
|
| 8422 |
private boolean hasOnlyWhiteSpaceSenders() { |
| 8423 |
for (int i = 0; i < mMessages.size(); i++) { |
| 8424 |
Message m = mMessages.get(i); |
| 8425 |
Person sender = m.getSenderPerson(); |
| 8426 |
if (sender != null && !isWhiteSpace(sender.getName())) { |
| 8427 |
return false; |
| 8428 |
} |
| 8429 |
} |
| 8430 |
return true; |
| 8431 |
} |
| 8432 |
|
| 8433 |
private boolean isWhiteSpace(CharSequence sender) { |
| 8434 |
if (TextUtils.isEmpty(sender)) { |
| 8435 |
return true; |
| 8436 |
} |
| 8437 |
if (sender.toString().matches("^\\s*$")) { |
| 8438 |
return true; |
| 8439 |
} |
| 8440 |
|
| 8441 |
|
| 8442 |
for (int i = 0; i < sender.length(); i++) { |
| 8443 |
char c = sender.charAt(i); |
| 8444 |
if (c != '\u200B') { |
| 8445 |
return false; |
| 8446 |
} |
| 8447 |
} |
| 8448 |
return true; |
| 8449 |
} |
| 8450 |
|
| 8451 |
|
| 8452 |
|
| 8453 |
|
| 8454 |
@Override |
| 8455 |
public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
| 8456 |
return makeMessagingView(StandardTemplateParams.VIEW_TYPE_HEADS_UP); |
| 8457 |
} |
| 8458 |
|
| 8459 |
|
| 8460 |
|
| 8461 |
|
| 8462 |
@Override |
| 8463 |
public void reduceImageSizes(Context context) { |
| 8464 |
super.reduceImageSizes(context); |
| 8465 |
Resources resources = context.getResources(); |
| 8466 |
boolean isLowRam = ActivityManager.isLowRamDeviceStatic(); |
| 8467 |
if (mShortcutIcon != null) { |
| 8468 |
int maxSize = resources.getDimensionPixelSize( |
| 8469 |
isLowRam ? R.dimen.notification_small_icon_size_low_ram |
| 8470 |
: R.dimen.notification_small_icon_size); |
| 8471 |
mShortcutIcon.scaleDownIfNecessary(maxSize, maxSize); |
| 8472 |
} |
| 8473 |
|
| 8474 |
int maxAvatarSize = resources.getDimensionPixelSize( |
| 8475 |
isLowRam ? R.dimen.notification_person_icon_max_size_low_ram |
| 8476 |
: R.dimen.notification_person_icon_max_size); |
| 8477 |
if (mUser != null && mUser.getIcon() != null) { |
| 8478 |
mUser.getIcon().scaleDownIfNecessary(maxAvatarSize, maxAvatarSize); |
| 8479 |
} |
| 8480 |
|
| 8481 |
reduceMessagesIconSizes(mMessages, maxAvatarSize); |
| 8482 |
reduceMessagesIconSizes(mHistoricMessages, maxAvatarSize); |
| 8483 |
} |
| 8484 |
|
| 8485 |
|
| 8486 |
|
| 8487 |
|
| 8488 |
private static void reduceMessagesIconSizes(@Nullable List<Message> messages, int maxSize) { |
| 8489 |
if (messages == null) { |
| 8490 |
return; |
| 8491 |
} |
| 8492 |
|
| 8493 |
for (Message message : messages) { |
| 8494 |
Person sender = message.mSender; |
| 8495 |
if (sender != null) { |
| 8496 |
Icon icon = sender.getIcon(); |
| 8497 |
if (icon != null) { |
| 8498 |
icon.scaleDownIfNecessary(maxSize, maxSize); |
| 8499 |
} |
| 8500 |
} |
| 8501 |
} |
| 8502 |
} |
| 8503 |
|
| 8504 |
public static final class Message { |
| 8505 |
|
| 8506 |
public static final String KEY_TEXT = "text"; |
| 8507 |
static final String KEY_TIMESTAMP = "time"; |
| 8508 |
static final String KEY_SENDER = "sender"; |
| 8509 |
static final String KEY_SENDER_PERSON = "sender_person"; |
| 8510 |
static final String KEY_DATA_MIME_TYPE = "type"; |
| 8511 |
static final String KEY_DATA_URI= "uri"; |
| 8512 |
static final String KEY_EXTRAS_BUNDLE = "extras"; |
| 8513 |
static final String KEY_REMOTE_INPUT_HISTORY = "remote_input_history"; |
| 8514 |
|
| 8515 |
private final CharSequence mText; |
| 8516 |
private final long mTimestamp; |
| 8517 |
@Nullable |
| 8518 |
private final Person mSender; |
| 8519 |
|
| 8520 |
|
| 8521 |
|
| 8522 |
private final boolean mRemoteInputHistory; |
| 8523 |
|
| 8524 |
private Bundle mExtras = new Bundle(); |
| 8525 |
private String mDataMimeType; |
| 8526 |
private Uri mDataUri; |
| 8527 |
|
| 8528 |
|
| 8529 |
|
| 8530 |
|
| 8531 |
|
| 8532 |
|
| 8533 |
|
| 8534 |
|
| 8535 |
|
| 8536 |
|
| 8537 |
|
| 8538 |
|
| 8539 |
|
| 8540 |
public Message(CharSequence text, long timestamp, CharSequence sender){ |
| 8541 |
this(text, timestamp, sender == null ? null |
| 8542 |
: new Person.Builder().setName(sender).build()); |
| 8543 |
} |
| 8544 |
|
| 8545 |
|
| 8546 |
|
| 8547 |
|
| 8548 |
|
| 8549 |
|
| 8550 |
|
| 8551 |
|
| 8552 |
|
| 8553 |
|
| 8554 |
|
| 8555 |
|
| 8556 |
|
| 8557 |
|
| 8558 |
|
| 8559 |
|
| 8560 |
public Message(@NonNull CharSequence text, long timestamp, @Nullable Person sender) { |
| 8561 |
this(text, timestamp, sender, false ); |
| 8562 |
} |
| 8563 |
|
| 8564 |
|
| 8565 |
|
| 8566 |
|
| 8567 |
|
| 8568 |
|
| 8569 |
|
| 8570 |
|
| 8571 |
|
| 8572 |
|
| 8573 |
|
| 8574 |
|
| 8575 |
|
| 8576 |
|
| 8577 |
|
| 8578 |
|
| 8579 |
|
| 8580 |
|
| 8581 |
|
| 8582 |
public Message(@NonNull CharSequence text, long timestamp, @Nullable Person sender, |
| 8583 |
boolean remoteInputHistory) { |
| 8584 |
mText = safeCharSequence(text); |
| 8585 |
mTimestamp = timestamp; |
| 8586 |
mSender = sender; |
| 8587 |
mRemoteInputHistory = remoteInputHistory; |
| 8588 |
} |
| 8589 |
|
| 8590 |
|
| 8591 |
|
| 8592 |
|
| 8593 |
|
| 8594 |
|
| 8595 |
|
| 8596 |
|
| 8597 |
|
| 8598 |
|
| 8599 |
|
| 8600 |
|
| 8601 |
|
| 8602 |
|
| 8603 |
|
| 8604 |
|
| 8605 |
|
| 8606 |
|
| 8607 |
|
| 8608 |
|
| 8609 |
|
| 8610 |
|
| 8611 |
|
| 8612 |
|
| 8613 |
|
| 8614 |
|
| 8615 |
|
| 8616 |
|
| 8617 |
public Message setData(String dataMimeType, Uri dataUri) { |
| 8618 |
mDataMimeType = dataMimeType; |
| 8619 |
mDataUri = dataUri; |
| 8620 |
return this; |
| 8621 |
} |
| 8622 |
|
| 8623 |
|
| 8624 |
|
| 8625 |
|
| 8626 |
|
| 8627 |
public CharSequence getText() { |
| 8628 |
return mText; |
| 8629 |
} |
| 8630 |
|
| 8631 |
|
| 8632 |
|
| 8633 |
|
| 8634 |
public long getTimestamp() { |
| 8635 |
return mTimestamp; |
| 8636 |
} |
| 8637 |
|
| 8638 |
|
| 8639 |
|
| 8640 |
|
| 8641 |
public Bundle getExtras() { |
| 8642 |
return mExtras; |
| 8643 |
} |
| 8644 |
|
| 8645 |
|
| 8646 |
|
| 8647 |
|
| 8648 |
|
| 8649 |
|
| 8650 |
public CharSequence getSender() { |
| 8651 |
return mSender == null ? null : mSender.getName(); |
| 8652 |
} |
| 8653 |
|
| 8654 |
|
| 8655 |
|
| 8656 |
|
| 8657 |
@Nullable |
| 8658 |
public Person getSenderPerson() { |
| 8659 |
return mSender; |
| 8660 |
} |
| 8661 |
|
| 8662 |
|
| 8663 |
|
| 8664 |
|
| 8665 |
public String getDataMimeType() { |
| 8666 |
return mDataMimeType; |
| 8667 |
} |
| 8668 |
|
| 8669 |
|
| 8670 |
|
| 8671 |
|
| 8672 |
|
| 8673 |
public Uri getDataUri() { |
| 8674 |
return mDataUri; |
| 8675 |
} |
| 8676 |
|
| 8677 |
|
| 8678 |
|
| 8679 |
|
| 8680 |
|
| 8681 |
|
| 8682 |
public boolean isRemoteInputHistory() { |
| 8683 |
return mRemoteInputHistory; |
| 8684 |
} |
| 8685 |
|
| 8686 |
|
| 8687 |
|
| 8688 |
|
| 8689 |
@VisibleForTesting |
| 8690 |
public Bundle toBundle() { |
| 8691 |
Bundle bundle = new Bundle(); |
| 8692 |
if (mText != null) { |
| 8693 |
bundle.putCharSequence(KEY_TEXT, mText); |
| 8694 |
} |
| 8695 |
bundle.putLong(KEY_TIMESTAMP, mTimestamp); |
| 8696 |
if (mSender != null) { |
| 8697 |
|
| 8698 |
bundle.putCharSequence(KEY_SENDER, safeCharSequence(mSender.getName())); |
| 8699 |
bundle.putParcelable(KEY_SENDER_PERSON, mSender); |
| 8700 |
} |
| 8701 |
if (mDataMimeType != null) { |
| 8702 |
bundle.putString(KEY_DATA_MIME_TYPE, mDataMimeType); |
| 8703 |
} |
| 8704 |
if (mDataUri != null) { |
| 8705 |
bundle.putParcelable(KEY_DATA_URI, mDataUri); |
| 8706 |
} |
| 8707 |
if (mExtras != null) { |
| 8708 |
bundle.putBundle(KEY_EXTRAS_BUNDLE, mExtras); |
| 8709 |
} |
| 8710 |
if (mRemoteInputHistory) { |
| 8711 |
bundle.putBoolean(KEY_REMOTE_INPUT_HISTORY, mRemoteInputHistory); |
| 8712 |
} |
| 8713 |
return bundle; |
| 8714 |
} |
| 8715 |
|
| 8716 |
static Bundle[] getBundleArrayForMessages(List<Message> messages) { |
| 8717 |
Bundle[] bundles = new Bundle[messages.size()]; |
| 8718 |
final int N = messages.size(); |
| 8719 |
for (int i = 0; i < N; i++) { |
| 8720 |
bundles[i] = messages.get(i).toBundle(); |
| 8721 |
} |
| 8722 |
return bundles; |
| 8723 |
} |
| 8724 |
|
| 8725 |
|
| 8726 |
|
| 8727 |
|
| 8728 |
|
| 8729 |
@NonNull |
| 8730 |
public static List<Message> getMessagesFromBundleArray(@Nullable Parcelable[] bundles) { |
| 8731 |
if (bundles == null) { |
| 8732 |
return new ArrayList<>(); |
| 8733 |
} |
| 8734 |
List<Message> messages = new ArrayList<>(bundles.length); |
| 8735 |
for (int i = 0; i < bundles.length; i++) { |
| 8736 |
if (bundles[i] instanceof Bundle) { |
| 8737 |
Message message = getMessageFromBundle((Bundle)bundles[i]); |
| 8738 |
if (message != null) { |
| 8739 |
messages.add(message); |
| 8740 |
} |
| 8741 |
} |
| 8742 |
} |
| 8743 |
return messages; |
| 8744 |
} |
| 8745 |
|
| 8746 |
|
| 8747 |
|
| 8748 |
|
| 8749 |
|
| 8750 |
|
| 8751 |
|
| 8752 |
@Nullable |
| 8753 |
public static Message getMessageFromBundle(@NonNull Bundle bundle) { |
| 8754 |
try { |
| 8755 |
if (!bundle.containsKey(KEY_TEXT) || !bundle.containsKey(KEY_TIMESTAMP)) { |
| 8756 |
return null; |
| 8757 |
} else { |
| 8758 |
|
| 8759 |
Person senderPerson = bundle.getParcelable(KEY_SENDER_PERSON, Person.class); |
| 8760 |
if (senderPerson == null) { |
| 8761 |
|
| 8762 |
|
| 8763 |
|
| 8764 |
CharSequence senderName = bundle.getCharSequence(KEY_SENDER); |
| 8765 |
if (senderName != null) { |
| 8766 |
senderPerson = new Person.Builder().setName(senderName).build(); |
| 8767 |
} |
| 8768 |
} |
| 8769 |
Message message = new Message(bundle.getCharSequence(KEY_TEXT), |
| 8770 |
bundle.getLong(KEY_TIMESTAMP), |
| 8771 |
senderPerson, |
| 8772 |
bundle.getBoolean(KEY_REMOTE_INPUT_HISTORY, false)); |
| 8773 |
if (bundle.containsKey(KEY_DATA_MIME_TYPE) && |
| 8774 |
bundle.containsKey(KEY_DATA_URI)) { |
| 8775 |
message.setData(bundle.getString(KEY_DATA_MIME_TYPE), |
| 8776 |
bundle.getParcelable(KEY_DATA_URI, Uri.class)); |
| 8777 |
} |
| 8778 |
if (bundle.containsKey(KEY_EXTRAS_BUNDLE)) { |
| 8779 |
message.getExtras().putAll(bundle.getBundle(KEY_EXTRAS_BUNDLE)); |
| 8780 |
} |
| 8781 |
return message; |
| 8782 |
} |
| 8783 |
} catch (ClassCastException e) { |
| 8784 |
return null; |
| 8785 |
} |
| 8786 |
} |
| 8787 |
} |
| 8788 |
} |
| 8789 |
|
| 8790 |
|
| 8791 |
|
| 8792 |
|
| 8793 |
|
| 8794 |
|
| 8795 |
|
| 8796 |
|
| 8797 |
|
| 8798 |
|
| 8799 |
|
| 8800 |
|
| 8801 |
|
| 8802 |
|
| 8803 |
|
| 8804 |
|
| 8805 |
|
| 8806 |
|
| 8807 |
|
| 8808 |
|
| 8809 |
|
| 8810 |
public static class InboxStyle extends Style { |
| 8811 |
|
| 8812 |
|
| 8813 |
|
| 8814 |
|
| 8815 |
private static final int NUMBER_OF_HISTORY_ALLOWED_UNTIL_REDUCTION = 1; |
| 8816 |
private ArrayList<CharSequence> mTexts = new ArrayList<CharSequence>(5); |
| 8817 |
|
| 8818 |
public InboxStyle() { |
| 8819 |
} |
| 8820 |
|
| 8821 |
|
| 8822 |
|
| 8823 |
|
| 8824 |
@Deprecated |
| 8825 |
public InboxStyle(Builder builder) { |
| 8826 |
setBuilder(builder); |
| 8827 |
} |
| 8828 |
|
| 8829 |
|
| 8830 |
|
| 8831 |
|
| 8832 |
|
| 8833 |
public InboxStyle setBigContentTitle(CharSequence title) { |
| 8834 |
internalSetBigContentTitle(safeCharSequence(title)); |
| 8835 |
return this; |
| 8836 |
} |
| 8837 |
|
| 8838 |
|
| 8839 |
|
| 8840 |
|
| 8841 |
public InboxStyle setSummaryText(CharSequence cs) { |
| 8842 |
internalSetSummaryText(safeCharSequence(cs)); |
| 8843 |
return this; |
| 8844 |
} |
| 8845 |
|
| 8846 |
|
| 8847 |
|
| 8848 |
|
| 8849 |
public InboxStyle addLine(CharSequence cs) { |
| 8850 |
mTexts.add(safeCharSequence(cs)); |
| 8851 |
return this; |
| 8852 |
} |
| 8853 |
|
| 8854 |
|
| 8855 |
|
| 8856 |
|
| 8857 |
public ArrayList<CharSequence> getLines() { |
| 8858 |
return mTexts; |
| 8859 |
} |
| 8860 |
|
| 8861 |
|
| 8862 |
|
| 8863 |
|
| 8864 |
public void addExtras(Bundle extras) { |
| 8865 |
super.addExtras(extras); |
| 8866 |
|
| 8867 |
CharSequence[] a = new CharSequence[mTexts.size()]; |
| 8868 |
extras.putCharSequenceArray(EXTRA_TEXT_LINES, mTexts.toArray(a)); |
| 8869 |
} |
| 8870 |
|
| 8871 |
|
| 8872 |
|
| 8873 |
|
| 8874 |
@Override |
| 8875 |
protected void restoreFromExtras(Bundle extras) { |
| 8876 |
super.restoreFromExtras(extras); |
| 8877 |
|
| 8878 |
mTexts.clear(); |
| 8879 |
if (extras.containsKey(EXTRA_TEXT_LINES)) { |
| 8880 |
Collections.addAll(mTexts, extras.getCharSequenceArray(EXTRA_TEXT_LINES)); |
| 8881 |
} |
| 8882 |
} |
| 8883 |
|
| 8884 |
|
| 8885 |
|
| 8886 |
|
| 8887 |
public RemoteViews makeBigContentView() { |
| 8888 |
StandardTemplateParams p = mBuilder.mParams.reset() |
| 8889 |
.viewType(StandardTemplateParams.VIEW_TYPE_BIG) |
| 8890 |
.fillTextsFrom(mBuilder).text(null); |
| 8891 |
TemplateBindResult result = new TemplateBindResult(); |
| 8892 |
RemoteViews contentView = getStandardView(mBuilder.getInboxLayoutResource(), p, result); |
| 8893 |
|
| 8894 |
int[] rowIds = {R.id.inbox_text0, R.id.inbox_text1, R.id.inbox_text2, R.id.inbox_text3, |
| 8895 |
R.id.inbox_text4, R.id.inbox_text5, R.id.inbox_text6}; |
| 8896 |
|
| 8897 |
|
| 8898 |
for (int rowId : rowIds) { |
| 8899 |
contentView.setViewVisibility(rowId, View.GONE); |
| 8900 |
} |
| 8901 |
|
| 8902 |
int i=0; |
| 8903 |
int topPadding = mBuilder.mContext.getResources().getDimensionPixelSize( |
| 8904 |
R.dimen.notification_inbox_item_top_padding); |
| 8905 |
boolean first = true; |
| 8906 |
int onlyViewId = 0; |
| 8907 |
int maxRows = rowIds.length; |
| 8908 |
if (mBuilder.mActions.size() > 0) { |
| 8909 |
maxRows--; |
| 8910 |
} |
| 8911 |
RemoteInputHistoryItem[] remoteInputHistory = getParcelableArrayFromBundle( |
| 8912 |
mBuilder.mN.extras, EXTRA_REMOTE_INPUT_HISTORY_ITEMS, |
| 8913 |
RemoteInputHistoryItem.class); |
| 8914 |
if (remoteInputHistory != null |
| 8915 |
&& remoteInputHistory.length > NUMBER_OF_HISTORY_ALLOWED_UNTIL_REDUCTION) { |
| 8916 |
|
| 8917 |
|
| 8918 |
int numRemoteInputs = Math.min(remoteInputHistory.length, |
| 8919 |
MAX_REMOTE_INPUT_HISTORY_LINES); |
| 8920 |
int totalNumRows = mTexts.size() + numRemoteInputs |
| 8921 |
- NUMBER_OF_HISTORY_ALLOWED_UNTIL_REDUCTION; |
| 8922 |
if (totalNumRows > maxRows) { |
| 8923 |
int overflow = totalNumRows - maxRows; |
| 8924 |
if (mTexts.size() > maxRows) { |
| 8925 |
|
| 8926 |
|
| 8927 |
maxRows -= overflow; |
| 8928 |
} else { |
| 8929 |
|
| 8930 |
i = overflow; |
| 8931 |
} |
| 8932 |
} |
| 8933 |
} |
| 8934 |
while (i < mTexts.size() && i < maxRows) { |
| 8935 |
CharSequence str = mTexts.get(i); |
| 8936 |
if (!TextUtils.isEmpty(str)) { |
| 8937 |
contentView.setViewVisibility(rowIds[i], View.VISIBLE); |
| 8938 |
contentView.setTextViewText(rowIds[i], |
| 8939 |
mBuilder.processTextSpans(mBuilder.processLegacyText(str))); |
| 8940 |
mBuilder.setTextViewColorSecondary(contentView, rowIds[i], p); |
| 8941 |
contentView.setViewPadding(rowIds[i], 0, topPadding, 0, 0); |
| 8942 |
if (first) { |
| 8943 |
onlyViewId = rowIds[i]; |
| 8944 |
} else { |
| 8945 |
onlyViewId = 0; |
| 8946 |
} |
| 8947 |
first = false; |
| 8948 |
} |
| 8949 |
i++; |
| 8950 |
} |
| 8951 |
if (onlyViewId != 0) { |
| 8952 |
|
| 8953 |
topPadding = mBuilder.mContext.getResources().getDimensionPixelSize( |
| 8954 |
R.dimen.notification_text_margin_top); |
| 8955 |
contentView.setViewPadding(onlyViewId, 0, topPadding, 0, 0); |
| 8956 |
} |
| 8957 |
|
| 8958 |
return contentView; |
| 8959 |
} |
| 8960 |
|
| 8961 |
|
| 8962 |
|
| 8963 |
|
| 8964 |
@Override |
| 8965 |
public boolean areNotificationsVisiblyDifferent(Style other) { |
| 8966 |
if (other == null || getClass() != other.getClass()) { |
| 8967 |
return true; |
| 8968 |
} |
| 8969 |
InboxStyle newS = (InboxStyle) other; |
| 8970 |
|
| 8971 |
final ArrayList<CharSequence> myLines = getLines(); |
| 8972 |
final ArrayList<CharSequence> newLines = newS.getLines(); |
| 8973 |
final int n = myLines.size(); |
| 8974 |
if (n != newLines.size()) { |
| 8975 |
return true; |
| 8976 |
} |
| 8977 |
|
| 8978 |
for (int i = 0; i < n; i++) { |
| 8979 |
if (!Objects.equals( |
| 8980 |
String.valueOf(myLines.get(i)), |
| 8981 |
String.valueOf(newLines.get(i)))) { |
| 8982 |
return true; |
| 8983 |
} |
| 8984 |
} |
| 8985 |
return false; |
| 8986 |
} |
| 8987 |
} |
| 8988 |
|
| 8989 |
|
| 8990 |
|
| 8991 |
|
| 8992 |
|
| 8993 |
|
| 8994 |
|
| 8995 |
|
| 8996 |
|
| 8997 |
|
| 8998 |
|
| 8999 |
|
| 9000 |
|
| 9001 |
|
| 9002 |
|
| 9003 |
|
| 9004 |
|
| 9005 |
|
| 9006 |
|
| 9007 |
|
| 9008 |
|
| 9009 |
|
| 9010 |
|
| 9011 |
|
| 9012 |
|
| 9013 |
|
| 9014 |
|
| 9015 |
|
| 9016 |
|
| 9017 |
|
| 9018 |
|
| 9019 |
|
| 9020 |
|
| 9021 |
|
| 9022 |
|
| 9023 |
|
| 9024 |
|
| 9025 |
|
| 9026 |
|
| 9027 |
|
| 9028 |
|
| 9029 |
|
| 9030 |
|
| 9031 |
|
| 9032 |
|
| 9033 |
|
| 9034 |
|
| 9035 |
public static class MediaStyle extends Style { |
| 9036 |
|
| 9037 |
|
| 9038 |
static final int MAX_MEDIA_BUTTONS_IN_COMPACT = 3; |
| 9039 |
static final int MAX_MEDIA_BUTTONS = 5; |
| 9040 |
@IdRes private static final int[] MEDIA_BUTTON_IDS = { |
| 9041 |
R.id.action0, |
| 9042 |
R.id.action1, |
| 9043 |
R.id.action2, |
| 9044 |
R.id.action3, |
| 9045 |
R.id.action4, |
| 9046 |
}; |
| 9047 |
|
| 9048 |
private int[] mActionsToShowInCompact = null; |
| 9049 |
private MediaSession.Token mToken; |
| 9050 |
private CharSequence mDeviceName; |
| 9051 |
private int mDeviceIcon; |
| 9052 |
private PendingIntent mDeviceIntent; |
| 9053 |
|
| 9054 |
public MediaStyle() { |
| 9055 |
} |
| 9056 |
|
| 9057 |
|
| 9058 |
|
| 9059 |
|
| 9060 |
@Deprecated |
| 9061 |
public MediaStyle(Builder builder) { |
| 9062 |
setBuilder(builder); |
| 9063 |
} |
| 9064 |
|
| 9065 |
|
| 9066 |
|
| 9067 |
|
| 9068 |
|
| 9069 |
|
| 9070 |
|
| 9071 |
public MediaStyle setShowActionsInCompactView(int...actions) { |
| 9072 |
mActionsToShowInCompact = actions; |
| 9073 |
return this; |
| 9074 |
} |
| 9075 |
|
| 9076 |
|
| 9077 |
|
| 9078 |
|
| 9079 |
|
| 9080 |
public MediaStyle setMediaSession(MediaSession.Token token) { |
| 9081 |
mToken = token; |
| 9082 |
return this; |
| 9083 |
} |
| 9084 |
|
| 9085 |
|
| 9086 |
|
| 9087 |
|
| 9088 |
|
| 9089 |
|
| 9090 |
|
| 9091 |
|
| 9092 |
|
| 9093 |
|
| 9094 |
|
| 9095 |
|
| 9096 |
|
| 9097 |
|
| 9098 |
|
| 9099 |
|
| 9100 |
|
| 9101 |
|
| 9102 |
|
| 9103 |
|
| 9104 |
@SystemApi |
| 9105 |
@RequiresPermission(android.Manifest.permission.MEDIA_CONTENT_CONTROL) |
| 9106 |
@NonNull |
| 9107 |
public MediaStyle setRemotePlaybackInfo(@NonNull CharSequence deviceName, |
| 9108 |
@DrawableRes int iconResource, @Nullable PendingIntent chipIntent) { |
| 9109 |
mDeviceName = deviceName; |
| 9110 |
mDeviceIcon = iconResource; |
| 9111 |
mDeviceIntent = chipIntent; |
| 9112 |
return this; |
| 9113 |
} |
| 9114 |
|
| 9115 |
|
| 9116 |
|
| 9117 |
|
| 9118 |
@Override |
| 9119 |
@UnsupportedAppUsage |
| 9120 |
public Notification buildStyled(Notification wip) { |
| 9121 |
super.buildStyled(wip); |
| 9122 |
if (wip.category == null) { |
| 9123 |
wip.category = Notification.CATEGORY_TRANSPORT; |
| 9124 |
} |
| 9125 |
return wip; |
| 9126 |
} |
| 9127 |
|
| 9128 |
|
| 9129 |
|
| 9130 |
|
| 9131 |
@Override |
| 9132 |
public RemoteViews makeContentView(boolean increasedHeight) { |
| 9133 |
return makeMediaContentView(null ); |
| 9134 |
} |
| 9135 |
|
| 9136 |
|
| 9137 |
|
| 9138 |
|
| 9139 |
@Override |
| 9140 |
public RemoteViews makeBigContentView() { |
| 9141 |
return makeMediaBigContentView(null ); |
| 9142 |
} |
| 9143 |
|
| 9144 |
|
| 9145 |
|
| 9146 |
|
| 9147 |
@Override |
| 9148 |
public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
| 9149 |
return makeMediaContentView(null ); |
| 9150 |
} |
| 9151 |
|
| 9152 |
|
| 9153 |
@Override |
| 9154 |
public void addExtras(Bundle extras) { |
| 9155 |
super.addExtras(extras); |
| 9156 |
|
| 9157 |
if (mToken != null) { |
| 9158 |
extras.putParcelable(EXTRA_MEDIA_SESSION, mToken); |
| 9159 |
} |
| 9160 |
if (mActionsToShowInCompact != null) { |
| 9161 |
extras.putIntArray(EXTRA_COMPACT_ACTIONS, mActionsToShowInCompact); |
| 9162 |
} |
| 9163 |
if (mDeviceName != null) { |
| 9164 |
extras.putCharSequence(EXTRA_MEDIA_REMOTE_DEVICE, mDeviceName); |
| 9165 |
} |
| 9166 |
if (mDeviceIcon > 0) { |
| 9167 |
extras.putInt(EXTRA_MEDIA_REMOTE_ICON, mDeviceIcon); |
| 9168 |
} |
| 9169 |
if (mDeviceIntent != null) { |
| 9170 |
extras.putParcelable(EXTRA_MEDIA_REMOTE_INTENT, mDeviceIntent); |
| 9171 |
} |
| 9172 |
} |
| 9173 |
|
| 9174 |
|
| 9175 |
|
| 9176 |
|
| 9177 |
@Override |
| 9178 |
protected void restoreFromExtras(Bundle extras) { |
| 9179 |
super.restoreFromExtras(extras); |
| 9180 |
|
| 9181 |
if (extras.containsKey(EXTRA_MEDIA_SESSION)) { |
| 9182 |
mToken = extras.getParcelable(EXTRA_MEDIA_SESSION, MediaSession.Token.class); |
| 9183 |
} |
| 9184 |
if (extras.containsKey(EXTRA_COMPACT_ACTIONS)) { |
| 9185 |
mActionsToShowInCompact = extras.getIntArray(EXTRA_COMPACT_ACTIONS); |
| 9186 |
} |
| 9187 |
if (extras.containsKey(EXTRA_MEDIA_REMOTE_DEVICE)) { |
| 9188 |
mDeviceName = extras.getCharSequence(EXTRA_MEDIA_REMOTE_DEVICE); |
| 9189 |
} |
| 9190 |
if (extras.containsKey(EXTRA_MEDIA_REMOTE_ICON)) { |
| 9191 |
mDeviceIcon = extras.getInt(EXTRA_MEDIA_REMOTE_ICON); |
| 9192 |
} |
| 9193 |
if (extras.containsKey(EXTRA_MEDIA_REMOTE_INTENT)) { |
| 9194 |
mDeviceIntent = extras.getParcelable( |
| 9195 |
EXTRA_MEDIA_REMOTE_INTENT, PendingIntent.class); |
| 9196 |
} |
| 9197 |
} |
| 9198 |
|
| 9199 |
|
| 9200 |
|
| 9201 |
|
| 9202 |
@Override |
| 9203 |
public boolean areNotificationsVisiblyDifferent(Style other) { |
| 9204 |
if (other == null || getClass() != other.getClass()) { |
| 9205 |
return true; |
| 9206 |
} |
| 9207 |
|
| 9208 |
return false; |
| 9209 |
} |
| 9210 |
|
| 9211 |
private void bindMediaActionButton(RemoteViews container, @IdRes int buttonId, |
| 9212 |
Action action, StandardTemplateParams p) { |
| 9213 |
final boolean tombstone = (action.actionIntent == null); |
| 9214 |
container.setViewVisibility(buttonId, View.VISIBLE); |
| 9215 |
container.setImageViewIcon(buttonId, action.getIcon()); |
| 9216 |
|
| 9217 |
|
| 9218 |
|
| 9219 |
int tintColor = mBuilder.getStandardActionColor(p); |
| 9220 |
|
| 9221 |
container.setDrawableTint(buttonId, false, tintColor, |
| 9222 |
PorterDuff.Mode.SRC_ATOP); |
| 9223 |
|
| 9224 |
int rippleAlpha = mBuilder.getColors(p).getRippleAlpha(); |
| 9225 |
int rippleColor = Color.argb(rippleAlpha, Color.red(tintColor), Color.green(tintColor), |
| 9226 |
Color.blue(tintColor)); |
| 9227 |
container.setRippleDrawableColor(buttonId, ColorStateList.valueOf(rippleColor)); |
| 9228 |
|
| 9229 |
if (!tombstone) { |
| 9230 |
container.setOnClickPendingIntent(buttonId, action.actionIntent); |
| 9231 |
} |
| 9232 |
container.setContentDescription(buttonId, action.title); |
| 9233 |
} |
| 9234 |
|
| 9235 |
|
| 9236 |
protected RemoteViews makeMediaContentView(@Nullable RemoteViews customContent) { |
| 9237 |
final int numActions = mBuilder.mActions.size(); |
| 9238 |
final int numActionsToShow = Math.min(mActionsToShowInCompact == null |
| 9239 |
? 0 : mActionsToShowInCompact.length, MAX_MEDIA_BUTTONS_IN_COMPACT); |
| 9240 |
if (numActionsToShow > numActions) { |
| 9241 |
throw new IllegalArgumentException(String.format( |
| 9242 |
"setShowActionsInCompactView: action %d out of bounds (max %d)", |
| 9243 |
numActions, numActions - 1)); |
| 9244 |
} |
| 9245 |
|
| 9246 |
StandardTemplateParams p = mBuilder.mParams.reset() |
| 9247 |
.viewType(StandardTemplateParams.VIEW_TYPE_NORMAL) |
| 9248 |
.hideTime(numActionsToShow > 1) |
| 9249 |
.hideSubText(numActionsToShow > 1) |
| 9250 |
.hideLeftIcon(false) |
| 9251 |
.hideRightIcon(numActionsToShow > 0) |
| 9252 |
.hideProgress(true) |
| 9253 |
.fillTextsFrom(mBuilder); |
| 9254 |
TemplateBindResult result = new TemplateBindResult(); |
| 9255 |
RemoteViews template = mBuilder.applyStandardTemplate( |
| 9256 |
R.layout.notification_template_material_media, p, |
| 9257 |
null ); |
| 9258 |
|
| 9259 |
for (int i = 0; i < MAX_MEDIA_BUTTONS_IN_COMPACT; i++) { |
| 9260 |
if (i < numActionsToShow) { |
| 9261 |
final Action action = mBuilder.mActions.get(mActionsToShowInCompact[i]); |
| 9262 |
bindMediaActionButton(template, MEDIA_BUTTON_IDS[i], action, p); |
| 9263 |
} else { |
| 9264 |
template.setViewVisibility(MEDIA_BUTTON_IDS[i], View.GONE); |
| 9265 |
} |
| 9266 |
} |
| 9267 |
|
| 9268 |
boolean hasActions = numActionsToShow != 0; |
| 9269 |
template.setViewVisibility(R.id.media_actions, hasActions ? View.VISIBLE : View.GONE); |
| 9270 |
|
| 9271 |
|
| 9272 |
buildCustomContentIntoTemplate(mBuilder.mContext, template, customContent, p, result); |
| 9273 |
return template; |
| 9274 |
} |
| 9275 |
|
| 9276 |
|
| 9277 |
protected RemoteViews makeMediaBigContentView(@Nullable RemoteViews customContent) { |
| 9278 |
final int actionCount = Math.min(mBuilder.mActions.size(), MAX_MEDIA_BUTTONS); |
| 9279 |
StandardTemplateParams p = mBuilder.mParams.reset() |
| 9280 |
.viewType(StandardTemplateParams.VIEW_TYPE_BIG) |
| 9281 |
.hideProgress(true) |
| 9282 |
.fillTextsFrom(mBuilder); |
| 9283 |
TemplateBindResult result = new TemplateBindResult(); |
| 9284 |
RemoteViews template = mBuilder.applyStandardTemplate( |
| 9285 |
R.layout.notification_template_material_big_media, p , result); |
| 9286 |
|
| 9287 |
for (int i = 0; i < MAX_MEDIA_BUTTONS; i++) { |
| 9288 |
if (i < actionCount) { |
| 9289 |
bindMediaActionButton(template, |
| 9290 |
MEDIA_BUTTON_IDS[i], mBuilder.mActions.get(i), p); |
| 9291 |
} else { |
| 9292 |
template.setViewVisibility(MEDIA_BUTTON_IDS[i], View.GONE); |
| 9293 |
} |
| 9294 |
} |
| 9295 |
buildCustomContentIntoTemplate(mBuilder.mContext, template, customContent, p, result); |
| 9296 |
return template; |
| 9297 |
} |
| 9298 |
} |
| 9299 |
|
| 9300 |
|
| 9301 |
|
| 9302 |
|
| 9303 |
|
| 9304 |
|
| 9305 |
|
| 9306 |
|
| 9307 |
|
| 9308 |
|
| 9309 |
|
| 9310 |
|
| 9311 |
public static class CallStyle extends Style { |
| 9312 |
|
| 9313 |
public static final int CALL_TYPE_INCOMING = 1; |
| 9314 |
|
| 9315 |
public static final int CALL_TYPE_ONGOING = 2; |
| 9316 |
|
| 9317 |
public static final int CALL_TYPE_SCREENING = 3; |
| 9318 |
|
| 9319 |
|
| 9320 |
|
| 9321 |
|
| 9322 |
|
| 9323 |
private static final String KEY_ACTION_PRIORITY = "key_action_priority"; |
| 9324 |
|
| 9325 |
private int mCallType; |
| 9326 |
private Person mPerson; |
| 9327 |
private PendingIntent mAnswerIntent; |
| 9328 |
private PendingIntent mDeclineIntent; |
| 9329 |
private PendingIntent mHangUpIntent; |
| 9330 |
private boolean mIsVideo; |
| 9331 |
private Integer mAnswerButtonColor; |
| 9332 |
private Integer mDeclineButtonColor; |
| 9333 |
private Icon mVerificationIcon; |
| 9334 |
private CharSequence mVerificationText; |
| 9335 |
|
| 9336 |
CallStyle() { |
| 9337 |
} |
| 9338 |
|
| 9339 |
|
| 9340 |
|
| 9341 |
|
| 9342 |
|
| 9343 |
|
| 9344 |
|
| 9345 |
|
| 9346 |
|
| 9347 |
|
| 9348 |
|
| 9349 |
|
| 9350 |
@NonNull |
| 9351 |
public static CallStyle forIncomingCall(@NonNull Person person, |
| 9352 |
@NonNull PendingIntent declineIntent, @NonNull PendingIntent answerIntent) { |
| 9353 |
return new CallStyle(CALL_TYPE_INCOMING, person, |
| 9354 |
null , |
| 9355 |
requireNonNull(declineIntent, "declineIntent is required"), |
| 9356 |
requireNonNull(answerIntent, "answerIntent is required") |
| 9357 |
); |
| 9358 |
} |
| 9359 |
|
| 9360 |
|
| 9361 |
|
| 9362 |
|
| 9363 |
|
| 9364 |
|
| 9365 |
|
| 9366 |
|
| 9367 |
|
| 9368 |
|
| 9369 |
|
| 9370 |
@NonNull |
| 9371 |
public static CallStyle forOngoingCall(@NonNull Person person, |
| 9372 |
@NonNull PendingIntent hangUpIntent) { |
| 9373 |
return new CallStyle(CALL_TYPE_ONGOING, person, |
| 9374 |
requireNonNull(hangUpIntent, "hangUpIntent is required"), |
| 9375 |
null , |
| 9376 |
null |
| 9377 |
); |
| 9378 |
} |
| 9379 |
|
| 9380 |
|
| 9381 |
|
| 9382 |
|
| 9383 |
|
| 9384 |
|
| 9385 |
|
| 9386 |
|
| 9387 |
|
| 9388 |
|
| 9389 |
|
| 9390 |
|
| 9391 |
|
| 9392 |
@NonNull |
| 9393 |
public static CallStyle forScreeningCall(@NonNull Person person, |
| 9394 |
@NonNull PendingIntent hangUpIntent, @NonNull PendingIntent answerIntent) { |
| 9395 |
return new CallStyle(CALL_TYPE_SCREENING, person, |
| 9396 |
requireNonNull(hangUpIntent, "hangUpIntent is required"), |
| 9397 |
null , |
| 9398 |
requireNonNull(answerIntent, "answerIntent is required") |
| 9399 |
); |
| 9400 |
} |
| 9401 |
|
| 9402 |
|
| 9403 |
|
| 9404 |
|
| 9405 |
|
| 9406 |
|
| 9407 |
|
| 9408 |
|
| 9409 |
private CallStyle(int callType, @NonNull Person person, |
| 9410 |
@Nullable PendingIntent hangUpIntent, @Nullable PendingIntent declineIntent, |
| 9411 |
@Nullable PendingIntent answerIntent) { |
| 9412 |
if (person == null || TextUtils.isEmpty(person.getName())) { |
| 9413 |
throw new IllegalArgumentException("person must have a non-empty a name"); |
| 9414 |
} |
| 9415 |
mCallType = callType; |
| 9416 |
mPerson = person; |
| 9417 |
mAnswerIntent = answerIntent; |
| 9418 |
mDeclineIntent = declineIntent; |
| 9419 |
mHangUpIntent = hangUpIntent; |
| 9420 |
} |
| 9421 |
|
| 9422 |
|
| 9423 |
|
| 9424 |
|
| 9425 |
|
| 9426 |
@NonNull |
| 9427 |
public CallStyle setIsVideo(boolean isVideo) { |
| 9428 |
mIsVideo = isVideo; |
| 9429 |
return this; |
| 9430 |
} |
| 9431 |
|
| 9432 |
|
| 9433 |
|
| 9434 |
|
| 9435 |
|
| 9436 |
@NonNull |
| 9437 |
public CallStyle setVerificationIcon(@Nullable Icon verificationIcon) { |
| 9438 |
mVerificationIcon = verificationIcon; |
| 9439 |
return this; |
| 9440 |
} |
| 9441 |
|
| 9442 |
|
| 9443 |
|
| 9444 |
|
| 9445 |
|
| 9446 |
@NonNull |
| 9447 |
public CallStyle setVerificationText(@Nullable CharSequence verificationText) { |
| 9448 |
mVerificationText = safeCharSequence(verificationText); |
| 9449 |
return this; |
| 9450 |
} |
| 9451 |
|
| 9452 |
|
| 9453 |
|
| 9454 |
|
| 9455 |
|
| 9456 |
|
| 9457 |
@NonNull |
| 9458 |
public CallStyle setAnswerButtonColorHint(@ColorInt int color) { |
| 9459 |
mAnswerButtonColor = color; |
| 9460 |
return this; |
| 9461 |
} |
| 9462 |
|
| 9463 |
|
| 9464 |
|
| 9465 |
|
| 9466 |
|
| 9467 |
|
| 9468 |
@NonNull |
| 9469 |
public CallStyle setDeclineButtonColorHint(@ColorInt int color) { |
| 9470 |
mDeclineButtonColor = color; |
| 9471 |
return this; |
| 9472 |
} |
| 9473 |
|
| 9474 |
|
| 9475 |
@Override |
| 9476 |
public Notification buildStyled(Notification wip) { |
| 9477 |
wip = super.buildStyled(wip); |
| 9478 |
|
| 9479 |
mBuilder.mActions = getActionsListWithSystemActions(); |
| 9480 |
wip.actions = new Action[mBuilder.mActions.size()]; |
| 9481 |
mBuilder.mActions.toArray(wip.actions); |
| 9482 |
return wip; |
| 9483 |
} |
| 9484 |
|
| 9485 |
|
| 9486 |
|
| 9487 |
|
| 9488 |
public boolean displayCustomViewInline() { |
| 9489 |
|
| 9490 |
|
| 9491 |
return true; |
| 9492 |
} |
| 9493 |
|
| 9494 |
|
| 9495 |
|
| 9496 |
|
| 9497 |
@Override |
| 9498 |
public void purgeResources() { |
| 9499 |
super.purgeResources(); |
| 9500 |
if (mVerificationIcon != null) { |
| 9501 |
mVerificationIcon.convertToAshmem(); |
| 9502 |
} |
| 9503 |
} |
| 9504 |
|
| 9505 |
|
| 9506 |
|
| 9507 |
|
| 9508 |
@Override |
| 9509 |
public void reduceImageSizes(Context context) { |
| 9510 |
super.reduceImageSizes(context); |
| 9511 |
if (mVerificationIcon != null) { |
| 9512 |
int rightIconSize = context.getResources().getDimensionPixelSize( |
| 9513 |
ActivityManager.isLowRamDeviceStatic() |
| 9514 |
? R.dimen.notification_right_icon_size_low_ram |
| 9515 |
: R.dimen.notification_right_icon_size); |
| 9516 |
mVerificationIcon.scaleDownIfNecessary(rightIconSize, rightIconSize); |
| 9517 |
} |
| 9518 |
} |
| 9519 |
|
| 9520 |
|
| 9521 |
|
| 9522 |
|
| 9523 |
@Override |
| 9524 |
public RemoteViews makeContentView(boolean increasedHeight) { |
| 9525 |
return makeCallLayout(StandardTemplateParams.VIEW_TYPE_NORMAL); |
| 9526 |
} |
| 9527 |
|
| 9528 |
|
| 9529 |
|
| 9530 |
|
| 9531 |
@Override |
| 9532 |
public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
| 9533 |
return makeCallLayout(StandardTemplateParams.VIEW_TYPE_HEADS_UP); |
| 9534 |
} |
| 9535 |
|
| 9536 |
|
| 9537 |
|
| 9538 |
|
| 9539 |
public RemoteViews makeBigContentView() { |
| 9540 |
return makeCallLayout(StandardTemplateParams.VIEW_TYPE_BIG); |
| 9541 |
} |
| 9542 |
|
| 9543 |
@NonNull |
| 9544 |
private Action makeNegativeAction() { |
| 9545 |
if (mDeclineIntent == null) { |
| 9546 |
return makeAction(R.drawable.ic_call_decline, |
| 9547 |
R.string.call_notification_hang_up_action, |
| 9548 |
mDeclineButtonColor, R.color.call_notification_decline_color, |
| 9549 |
mHangUpIntent); |
| 9550 |
} else { |
| 9551 |
return makeAction(R.drawable.ic_call_decline, |
| 9552 |
R.string.call_notification_decline_action, |
| 9553 |
mDeclineButtonColor, R.color.call_notification_decline_color, |
| 9554 |
mDeclineIntent); |
| 9555 |
} |
| 9556 |
} |
| 9557 |
|
| 9558 |
@Nullable |
| 9559 |
private Action makeAnswerAction() { |
| 9560 |
return mAnswerIntent == null ? null : makeAction( |
| 9561 |
mIsVideo ? R.drawable.ic_call_answer_video : R.drawable.ic_call_answer, |
| 9562 |
mIsVideo ? R.string.call_notification_answer_video_action |
| 9563 |
: R.string.call_notification_answer_action, |
| 9564 |
mAnswerButtonColor, R.color.call_notification_answer_color, |
| 9565 |
mAnswerIntent); |
| 9566 |
} |
| 9567 |
|
| 9568 |
@NonNull |
| 9569 |
private Action makeAction(@DrawableRes int icon, @StringRes int title, |
| 9570 |
@ColorInt Integer colorInt, @ColorRes int defaultColorRes, PendingIntent intent) { |
| 9571 |
if (colorInt == null || !mBuilder.isCallActionColorCustomizable()) { |
| 9572 |
colorInt = mBuilder.mContext.getColor(defaultColorRes); |
| 9573 |
} |
| 9574 |
Action action = new Action.Builder(Icon.createWithResource("", icon), |
| 9575 |
new SpannableStringBuilder().append(mBuilder.mContext.getString(title), |
| 9576 |
new ForegroundColorSpan(colorInt), |
| 9577 |
SpannableStringBuilder.SPAN_INCLUSIVE_INCLUSIVE), |
| 9578 |
intent).build(); |
| 9579 |
action.getExtras().putBoolean(KEY_ACTION_PRIORITY, true); |
| 9580 |
return action; |
| 9581 |
} |
| 9582 |
|
| 9583 |
private boolean isActionAddedByCallStyle(Action action) { |
| 9584 |
|
| 9585 |
|
| 9586 |
return action != null && action.getExtras().getBoolean(KEY_ACTION_PRIORITY); |
| 9587 |
} |
| 9588 |
|
| 9589 |
|
| 9590 |
|
| 9591 |
|
| 9592 |
|
| 9593 |
|
| 9594 |
|
| 9595 |
@NonNull |
| 9596 |
public ArrayList<Action> getActionsListWithSystemActions() { |
| 9597 |
|
| 9598 |
final Action firstAction = makeNegativeAction(); |
| 9599 |
final Action lastAction = makeAnswerAction(); |
| 9600 |
|
| 9601 |
|
| 9602 |
int nonContextualActionSlotsRemaining = MAX_ACTION_BUTTONS; |
| 9603 |
ArrayList<Action> resultActions = new ArrayList<>(MAX_ACTION_BUTTONS); |
| 9604 |
|
| 9605 |
|
| 9606 |
resultActions.add(firstAction); |
| 9607 |
--nonContextualActionSlotsRemaining; |
| 9608 |
|
| 9609 |
|
| 9610 |
if (mBuilder.mActions != null) { |
| 9611 |
for (Notification.Action action : mBuilder.mActions) { |
| 9612 |
if (action.isContextual()) { |
| 9613 |
|
| 9614 |
resultActions.add(action); |
| 9615 |
} else if (isActionAddedByCallStyle(action)) { |
| 9616 |
|
| 9617 |
} else { |
| 9618 |
|
| 9619 |
resultActions.add(action); |
| 9620 |
--nonContextualActionSlotsRemaining; |
| 9621 |
} |
| 9622 |
|
| 9623 |
if (lastAction != null && nonContextualActionSlotsRemaining == 1) { |
| 9624 |
resultActions.add(lastAction); |
| 9625 |
--nonContextualActionSlotsRemaining; |
| 9626 |
} |
| 9627 |
} |
| 9628 |
} |
| 9629 |
|
| 9630 |
if (lastAction != null && nonContextualActionSlotsRemaining >= 1) { |
| 9631 |
resultActions.add(lastAction); |
| 9632 |
} |
| 9633 |
return resultActions; |
| 9634 |
} |
| 9635 |
|
| 9636 |
private RemoteViews makeCallLayout(int viewType) { |
| 9637 |
final boolean isCollapsed = viewType == StandardTemplateParams.VIEW_TYPE_NORMAL; |
| 9638 |
Bundle extras = mBuilder.mN.extras; |
| 9639 |
CharSequence title = mPerson != null ? mPerson.getName() : null; |
| 9640 |
CharSequence text = mBuilder.processLegacyText(extras.getCharSequence(EXTRA_TEXT)); |
| 9641 |
if (text == null) { |
| 9642 |
text = getDefaultText(); |
| 9643 |
} |
| 9644 |
|
| 9645 |
|
| 9646 |
StandardTemplateParams p = mBuilder.mParams.reset() |
| 9647 |
.viewType(viewType) |
| 9648 |
.callStyleActions(true) |
| 9649 |
.allowTextWithProgress(true) |
| 9650 |
.hideLeftIcon(true) |
| 9651 |
.hideRightIcon(true) |
| 9652 |
.hideAppName(isCollapsed) |
| 9653 |
.titleViewId(R.id.conversation_text) |
| 9654 |
.title(title) |
| 9655 |
.text(text) |
| 9656 |
.summaryText(mBuilder.processLegacyText(mVerificationText)); |
| 9657 |
mBuilder.mActions = getActionsListWithSystemActions(); |
| 9658 |
final RemoteViews contentView; |
| 9659 |
if (isCollapsed) { |
| 9660 |
contentView = mBuilder.applyStandardTemplate( |
| 9661 |
R.layout.notification_template_material_call, p, null ); |
| 9662 |
} else { |
| 9663 |
contentView = mBuilder.applyStandardTemplateWithActions( |
| 9664 |
R.layout.notification_template_material_big_call, p, null ); |
| 9665 |
} |
| 9666 |
|
| 9667 |
|
| 9668 |
if (!p.mHideAppName) { |
| 9669 |
mBuilder.setTextViewColorSecondary(contentView, R.id.app_name_divider, p); |
| 9670 |
contentView.setViewVisibility(R.id.app_name_divider, View.VISIBLE); |
| 9671 |
} |
| 9672 |
bindCallerVerification(contentView, p); |
| 9673 |
|
| 9674 |
|
| 9675 |
contentView.setInt(R.id.status_bar_latest_event_content, "setLayoutColor", |
| 9676 |
mBuilder.getSmallIconColor(p)); |
| 9677 |
contentView.setInt(R.id.status_bar_latest_event_content, |
| 9678 |
"setNotificationBackgroundColor", mBuilder.getBackgroundColor(p)); |
| 9679 |
contentView.setIcon(R.id.status_bar_latest_event_content, "setLargeIcon", |
| 9680 |
mBuilder.mN.mLargeIcon); |
| 9681 |
contentView.setBundle(R.id.status_bar_latest_event_content, "setData", |
| 9682 |
mBuilder.mN.extras); |
| 9683 |
|
| 9684 |
return contentView; |
| 9685 |
} |
| 9686 |
|
| 9687 |
private void bindCallerVerification(RemoteViews contentView, StandardTemplateParams p) { |
| 9688 |
String iconContentDescription = null; |
| 9689 |
boolean showDivider = true; |
| 9690 |
if (mVerificationIcon != null) { |
| 9691 |
contentView.setImageViewIcon(R.id.verification_icon, mVerificationIcon); |
| 9692 |
contentView.setDrawableTint(R.id.verification_icon, false , |
| 9693 |
mBuilder.getSecondaryTextColor(p), PorterDuff.Mode.SRC_ATOP); |
| 9694 |
contentView.setViewVisibility(R.id.verification_icon, View.VISIBLE); |
| 9695 |
iconContentDescription = mBuilder.mContext.getString( |
| 9696 |
R.string.notification_verified_content_description); |
| 9697 |
showDivider = false; |
| 9698 |
} else { |
| 9699 |
contentView.setViewVisibility(R.id.verification_icon, View.GONE); |
| 9700 |
} |
| 9701 |
if (!TextUtils.isEmpty(mVerificationText)) { |
| 9702 |
contentView.setTextViewText(R.id.verification_text, mVerificationText); |
| 9703 |
mBuilder.setTextViewColorSecondary(contentView, R.id.verification_text, p); |
| 9704 |
contentView.setViewVisibility(R.id.verification_text, View.VISIBLE); |
| 9705 |
iconContentDescription = null; |
| 9706 |
} else { |
| 9707 |
contentView.setViewVisibility(R.id.verification_text, View.GONE); |
| 9708 |
showDivider = false; |
| 9709 |
} |
| 9710 |
contentView.setContentDescription(R.id.verification_icon, iconContentDescription); |
| 9711 |
if (showDivider) { |
| 9712 |
contentView.setViewVisibility(R.id.verification_divider, View.VISIBLE); |
| 9713 |
mBuilder.setTextViewColorSecondary(contentView, R.id.verification_divider, p); |
| 9714 |
} else { |
| 9715 |
contentView.setViewVisibility(R.id.verification_divider, View.GONE); |
| 9716 |
} |
| 9717 |
} |
| 9718 |
|
| 9719 |
@Nullable |
| 9720 |
private String getDefaultText() { |
| 9721 |
switch (mCallType) { |
| 9722 |
case CALL_TYPE_INCOMING: |
| 9723 |
return mBuilder.mContext.getString(R.string.call_notification_incoming_text); |
| 9724 |
case CALL_TYPE_ONGOING: |
| 9725 |
return mBuilder.mContext.getString(R.string.call_notification_ongoing_text); |
| 9726 |
case CALL_TYPE_SCREENING: |
| 9727 |
return mBuilder.mContext.getString(R.string.call_notification_screening_text); |
| 9728 |
} |
| 9729 |
return null; |
| 9730 |
} |
| 9731 |
|
| 9732 |
|
| 9733 |
|
| 9734 |
|
| 9735 |
public void addExtras(Bundle extras) { |
| 9736 |
super.addExtras(extras); |
| 9737 |
extras.putInt(EXTRA_CALL_TYPE, mCallType); |
| 9738 |
extras.putBoolean(EXTRA_CALL_IS_VIDEO, mIsVideo); |
| 9739 |
extras.putParcelable(EXTRA_CALL_PERSON, mPerson); |
| 9740 |
if (mVerificationIcon != null) { |
| 9741 |
extras.putParcelable(EXTRA_VERIFICATION_ICON, mVerificationIcon); |
| 9742 |
} |
| 9743 |
if (mVerificationText != null) { |
| 9744 |
extras.putCharSequence(EXTRA_VERIFICATION_TEXT, mVerificationText); |
| 9745 |
} |
| 9746 |
if (mAnswerIntent != null) { |
| 9747 |
extras.putParcelable(EXTRA_ANSWER_INTENT, mAnswerIntent); |
| 9748 |
} |
| 9749 |
if (mDeclineIntent != null) { |
| 9750 |
extras.putParcelable(EXTRA_DECLINE_INTENT, mDeclineIntent); |
| 9751 |
} |
| 9752 |
if (mHangUpIntent != null) { |
| 9753 |
extras.putParcelable(EXTRA_HANG_UP_INTENT, mHangUpIntent); |
| 9754 |
} |
| 9755 |
if (mAnswerButtonColor != null) { |
| 9756 |
extras.putInt(EXTRA_ANSWER_COLOR, mAnswerButtonColor); |
| 9757 |
} |
| 9758 |
if (mDeclineButtonColor != null) { |
| 9759 |
extras.putInt(EXTRA_DECLINE_COLOR, mDeclineButtonColor); |
| 9760 |
} |
| 9761 |
fixTitleAndTextExtras(extras); |
| 9762 |
} |
| 9763 |
|
| 9764 |
private void fixTitleAndTextExtras(Bundle extras) { |
| 9765 |
CharSequence sender = mPerson != null ? mPerson.getName() : null; |
| 9766 |
if (sender != null) { |
| 9767 |
extras.putCharSequence(EXTRA_TITLE, sender); |
| 9768 |
} |
| 9769 |
if (extras.getCharSequence(EXTRA_TEXT) == null) { |
| 9770 |
extras.putCharSequence(EXTRA_TEXT, getDefaultText()); |
| 9771 |
} |
| 9772 |
} |
| 9773 |
|
| 9774 |
|
| 9775 |
|
| 9776 |
|
| 9777 |
@Override |
| 9778 |
protected void restoreFromExtras(Bundle extras) { |
| 9779 |
super.restoreFromExtras(extras); |
| 9780 |
mCallType = extras.getInt(EXTRA_CALL_TYPE); |
| 9781 |
mIsVideo = extras.getBoolean(EXTRA_CALL_IS_VIDEO); |
| 9782 |
mPerson = extras.getParcelable(EXTRA_CALL_PERSON, Person.class); |
| 9783 |
mVerificationIcon = extras.getParcelable(EXTRA_VERIFICATION_ICON); |
| 9784 |
mVerificationText = extras.getCharSequence(EXTRA_VERIFICATION_TEXT); |
| 9785 |
mAnswerIntent = extras.getParcelable(EXTRA_ANSWER_INTENT, PendingIntent.class); |
| 9786 |
mDeclineIntent = extras.getParcelable(EXTRA_DECLINE_INTENT, PendingIntent.class); |
| 9787 |
mHangUpIntent = extras.getParcelable(EXTRA_HANG_UP_INTENT, PendingIntent.class); |
| 9788 |
mAnswerButtonColor = extras.containsKey(EXTRA_ANSWER_COLOR) |
| 9789 |
? extras.getInt(EXTRA_ANSWER_COLOR) : null; |
| 9790 |
mDeclineButtonColor = extras.containsKey(EXTRA_DECLINE_COLOR) |
| 9791 |
? extras.getInt(EXTRA_DECLINE_COLOR) : null; |
| 9792 |
} |
| 9793 |
|
| 9794 |
|
| 9795 |
|
| 9796 |
|
| 9797 |
@Override |
| 9798 |
public boolean hasSummaryInHeader() { |
| 9799 |
return false; |
| 9800 |
} |
| 9801 |
|
| 9802 |
|
| 9803 |
|
| 9804 |
|
| 9805 |
@Override |
| 9806 |
public boolean areNotificationsVisiblyDifferent(Style other) { |
| 9807 |
if (other == null || getClass() != other.getClass()) { |
| 9808 |
return true; |
| 9809 |
} |
| 9810 |
CallStyle otherS = (CallStyle) other; |
| 9811 |
return !Objects.equals(mCallType, otherS.mCallType) |
| 9812 |
|| !Objects.equals(mPerson, otherS.mPerson) |
| 9813 |
|| !Objects.equals(mVerificationText, otherS.mVerificationText); |
| 9814 |
} |
| 9815 |
} |
| 9816 |
|
| 9817 |
|
| 9818 |
|
| 9819 |
|
| 9820 |
|
| 9821 |
|
| 9822 |
|
| 9823 |
|
| 9824 |
|
| 9825 |
|
| 9826 |
|
| 9827 |
|
| 9828 |
|
| 9829 |
|
| 9830 |
|
| 9831 |
|
| 9832 |
|
| 9833 |
|
| 9834 |
|
| 9835 |
|
| 9836 |
|
| 9837 |
|
| 9838 |
|
| 9839 |
|
| 9840 |
public static class DecoratedCustomViewStyle extends Style { |
| 9841 |
|
| 9842 |
public DecoratedCustomViewStyle() { |
| 9843 |
} |
| 9844 |
|
| 9845 |
|
| 9846 |
|
| 9847 |
|
| 9848 |
public boolean displayCustomViewInline() { |
| 9849 |
return true; |
| 9850 |
} |
| 9851 |
|
| 9852 |
|
| 9853 |
|
| 9854 |
|
| 9855 |
@Override |
| 9856 |
public RemoteViews makeContentView(boolean increasedHeight) { |
| 9857 |
return makeStandardTemplateWithCustomContent(mBuilder.mN.contentView); |
| 9858 |
} |
| 9859 |
|
| 9860 |
|
| 9861 |
|
| 9862 |
|
| 9863 |
@Override |
| 9864 |
public RemoteViews makeBigContentView() { |
| 9865 |
return makeDecoratedBigContentView(); |
| 9866 |
} |
| 9867 |
|
| 9868 |
|
| 9869 |
|
| 9870 |
|
| 9871 |
@Override |
| 9872 |
public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
| 9873 |
return makeDecoratedHeadsUpContentView(); |
| 9874 |
} |
| 9875 |
|
| 9876 |
private RemoteViews makeDecoratedHeadsUpContentView() { |
| 9877 |
RemoteViews headsUpContentView = mBuilder.mN.headsUpContentView == null |
| 9878 |
? mBuilder.mN.contentView |
| 9879 |
: mBuilder.mN.headsUpContentView; |
| 9880 |
if (headsUpContentView == null) { |
| 9881 |
return null; |
| 9882 |
} |
| 9883 |
if (mBuilder.mActions.size() == 0) { |
| 9884 |
return makeStandardTemplateWithCustomContent(headsUpContentView); |
| 9885 |
} |
| 9886 |
TemplateBindResult result = new TemplateBindResult(); |
| 9887 |
StandardTemplateParams p = mBuilder.mParams.reset() |
| 9888 |
.viewType(StandardTemplateParams.VIEW_TYPE_HEADS_UP) |
| 9889 |
.decorationType(StandardTemplateParams.DECORATION_PARTIAL) |
| 9890 |
.fillTextsFrom(mBuilder); |
| 9891 |
RemoteViews remoteViews = mBuilder.applyStandardTemplateWithActions( |
| 9892 |
mBuilder.getHeadsUpBaseLayoutResource(), p, result); |
| 9893 |
buildCustomContentIntoTemplate(mBuilder.mContext, remoteViews, headsUpContentView, |
| 9894 |
p, result); |
| 9895 |
return remoteViews; |
| 9896 |
} |
| 9897 |
|
| 9898 |
private RemoteViews makeStandardTemplateWithCustomContent(RemoteViews customContent) { |
| 9899 |
if (customContent == null) { |
| 9900 |
return null; |
| 9901 |
} |
| 9902 |
TemplateBindResult result = new TemplateBindResult(); |
| 9903 |
StandardTemplateParams p = mBuilder.mParams.reset() |
| 9904 |
.viewType(StandardTemplateParams.VIEW_TYPE_NORMAL) |
| 9905 |
.decorationType(StandardTemplateParams.DECORATION_PARTIAL) |
| 9906 |
.fillTextsFrom(mBuilder); |
| 9907 |
RemoteViews remoteViews = mBuilder.applyStandardTemplate( |
| 9908 |
mBuilder.getBaseLayoutResource(), p, result); |
| 9909 |
buildCustomContentIntoTemplate(mBuilder.mContext, remoteViews, customContent, |
| 9910 |
p, result); |
| 9911 |
return remoteViews; |
| 9912 |
} |
| 9913 |
|
| 9914 |
private RemoteViews makeDecoratedBigContentView() { |
| 9915 |
RemoteViews bigContentView = mBuilder.mN.bigContentView == null |
| 9916 |
? mBuilder.mN.contentView |
| 9917 |
: mBuilder.mN.bigContentView; |
| 9918 |
if (bigContentView == null) { |
| 9919 |
return null; |
| 9920 |
} |
| 9921 |
TemplateBindResult result = new TemplateBindResult(); |
| 9922 |
StandardTemplateParams p = mBuilder.mParams.reset() |
| 9923 |
.viewType(StandardTemplateParams.VIEW_TYPE_BIG) |
| 9924 |
.decorationType(StandardTemplateParams.DECORATION_PARTIAL) |
| 9925 |
.fillTextsFrom(mBuilder); |
| 9926 |
RemoteViews remoteViews = mBuilder.applyStandardTemplateWithActions( |
| 9927 |
mBuilder.getBigBaseLayoutResource(), p, result); |
| 9928 |
buildCustomContentIntoTemplate(mBuilder.mContext, remoteViews, bigContentView, |
| 9929 |
p, result); |
| 9930 |
return remoteViews; |
| 9931 |
} |
| 9932 |
|
| 9933 |
|
| 9934 |
|
| 9935 |
|
| 9936 |
@Override |
| 9937 |
public boolean areNotificationsVisiblyDifferent(Style other) { |
| 9938 |
if (other == null || getClass() != other.getClass()) { |
| 9939 |
return true; |
| 9940 |
} |
| 9941 |
|
| 9942 |
return false; |
| 9943 |
} |
| 9944 |
} |
| 9945 |
|
| 9946 |
|
| 9947 |
|
| 9948 |
|
| 9949 |
|
| 9950 |
|
| 9951 |
|
| 9952 |
|
| 9953 |
|
| 9954 |
|
| 9955 |
|
| 9956 |
|
| 9957 |
|
| 9958 |
|
| 9959 |
|
| 9960 |
|
| 9961 |
|
| 9962 |
|
| 9963 |
|
| 9964 |
|
| 9965 |
|
| 9966 |
|
| 9967 |
|
| 9968 |
|
| 9969 |
|
| 9970 |
|
| 9971 |
|
| 9972 |
|
| 9973 |
|
| 9974 |
|
| 9975 |
|
| 9976 |
public static class DecoratedMediaCustomViewStyle extends MediaStyle { |
| 9977 |
|
| 9978 |
public DecoratedMediaCustomViewStyle() { |
| 9979 |
} |
| 9980 |
|
| 9981 |
|
| 9982 |
|
| 9983 |
|
| 9984 |
public boolean displayCustomViewInline() { |
| 9985 |
return true; |
| 9986 |
} |
| 9987 |
|
| 9988 |
|
| 9989 |
|
| 9990 |
|
| 9991 |
@Override |
| 9992 |
public RemoteViews makeContentView(boolean increasedHeight) { |
| 9993 |
return makeMediaContentView(mBuilder.mN.contentView); |
| 9994 |
} |
| 9995 |
|
| 9996 |
|
| 9997 |
|
| 9998 |
|
| 9999 |
@Override |
| 10000 |
public RemoteViews makeBigContentView() { |
| 10001 |
RemoteViews customContent = mBuilder.mN.bigContentView != null |
| 10002 |
? mBuilder.mN.bigContentView |
| 10003 |
: mBuilder.mN.contentView; |
| 10004 |
return makeMediaBigContentView(customContent); |
| 10005 |
} |
| 10006 |
|
| 10007 |
|
| 10008 |
|
| 10009 |
|
| 10010 |
@Override |
| 10011 |
public RemoteViews makeHeadsUpContentView(boolean increasedHeight) { |
| 10012 |
RemoteViews customContent = mBuilder.mN.headsUpContentView != null |
| 10013 |
? mBuilder.mN.headsUpContentView |
| 10014 |
: mBuilder.mN.contentView; |
| 10015 |
return makeMediaBigContentView(customContent); |
| 10016 |
} |
| 10017 |
|
| 10018 |
|
| 10019 |
|
| 10020 |
|
| 10021 |
@Override |
| 10022 |
public boolean areNotificationsVisiblyDifferent(Style other) { |
| 10023 |
if (other == null || getClass() != other.getClass()) { |
| 10024 |
return true; |
| 10025 |
} |
| 10026 |
|
| 10027 |
return false; |
| 10028 |
} |
| 10029 |
} |
| 10030 |
|
| 10031 |
|
| 10032 |
|
| 10033 |
|
| 10034 |
|
| 10035 |
|
| 10036 |
|
| 10037 |
|
| 10038 |
|
| 10039 |
|
| 10040 |
|
| 10041 |
|
| 10042 |
|
| 10043 |
|
| 10044 |
|
| 10045 |
|
| 10046 |
|
| 10047 |
public static final class BubbleMetadata implements Parcelable { |
| 10048 |
|
| 10049 |
private PendingIntent mPendingIntent; |
| 10050 |
private PendingIntent mDeleteIntent; |
| 10051 |
private Icon mIcon; |
| 10052 |
private int mDesiredHeight; |
| 10053 |
@DimenRes private int mDesiredHeightResId; |
| 10054 |
private int mFlags; |
| 10055 |
private String mShortcutId; |
| 10056 |
|
| 10057 |
|
| 10058 |
|
| 10059 |
|
| 10060 |
|
| 10061 |
|
| 10062 |
|
| 10063 |
|
| 10064 |
|
| 10065 |
|
| 10066 |
|
| 10067 |
|
| 10068 |
|
| 10069 |
|
| 10070 |
|
| 10071 |
public static final int FLAG_AUTO_EXPAND_BUBBLE = 0x00000001; |
| 10072 |
|
| 10073 |
|
| 10074 |
|
| 10075 |
|
| 10076 |
|
| 10077 |
|
| 10078 |
|
| 10079 |
|
| 10080 |
|
| 10081 |
|
| 10082 |
|
| 10083 |
|
| 10084 |
|
| 10085 |
|
| 10086 |
|
| 10087 |
|
| 10088 |
|
| 10089 |
|
| 10090 |
public static final int FLAG_SUPPRESS_NOTIFICATION = 0x00000002; |
| 10091 |
|
| 10092 |
|
| 10093 |
|
| 10094 |
|
| 10095 |
|
| 10096 |
|
| 10097 |
|
| 10098 |
|
| 10099 |
public static final int FLAG_SUPPRESSABLE_BUBBLE = 0x00000004; |
| 10100 |
|
| 10101 |
|
| 10102 |
|
| 10103 |
|
| 10104 |
|
| 10105 |
|
| 10106 |
public static final int FLAG_SUPPRESS_BUBBLE = 0x00000008; |
| 10107 |
|
| 10108 |
private BubbleMetadata(PendingIntent expandIntent, PendingIntent deleteIntent, |
| 10109 |
Icon icon, int height, @DimenRes int heightResId, String shortcutId) { |
| 10110 |
mPendingIntent = expandIntent; |
| 10111 |
mIcon = icon; |
| 10112 |
mDesiredHeight = height; |
| 10113 |
mDesiredHeightResId = heightResId; |
| 10114 |
mDeleteIntent = deleteIntent; |
| 10115 |
mShortcutId = shortcutId; |
| 10116 |
} |
| 10117 |
|
| 10118 |
private BubbleMetadata(Parcel in) { |
| 10119 |
if (in.readInt() != 0) { |
| 10120 |
mPendingIntent = PendingIntent.CREATOR.createFromParcel(in); |
| 10121 |
} |
| 10122 |
if (in.readInt() != 0) { |
| 10123 |
mIcon = Icon.CREATOR.createFromParcel(in); |
| 10124 |
} |
| 10125 |
mDesiredHeight = in.readInt(); |
| 10126 |
mFlags = in.readInt(); |
| 10127 |
if (in.readInt() != 0) { |
| 10128 |
mDeleteIntent = PendingIntent.CREATOR.createFromParcel(in); |
| 10129 |
} |
| 10130 |
mDesiredHeightResId = in.readInt(); |
| 10131 |
if (in.readInt() != 0) { |
| 10132 |
mShortcutId = in.readString8(); |
| 10133 |
} |
| 10134 |
} |
| 10135 |
|
| 10136 |
|
| 10137 |
|
| 10138 |
|
| 10139 |
|
| 10140 |
|
| 10141 |
@Nullable |
| 10142 |
public String getShortcutId() { |
| 10143 |
return mShortcutId; |
| 10144 |
} |
| 10145 |
|
| 10146 |
|
| 10147 |
|
| 10148 |
|
| 10149 |
|
| 10150 |
@SuppressLint("InvalidNullConversion") |
| 10151 |
@Nullable |
| 10152 |
public PendingIntent getIntent() { |
| 10153 |
return mPendingIntent; |
| 10154 |
} |
| 10155 |
|
| 10156 |
|
| 10157 |
|
| 10158 |
|
| 10159 |
|
| 10160 |
@Nullable |
| 10161 |
@Deprecated |
| 10162 |
public PendingIntent getBubbleIntent() { |
| 10163 |
return mPendingIntent; |
| 10164 |
} |
| 10165 |
|
| 10166 |
|
| 10167 |
|
| 10168 |
|
| 10169 |
@Nullable |
| 10170 |
public PendingIntent getDeleteIntent() { |
| 10171 |
return mDeleteIntent; |
| 10172 |
} |
| 10173 |
|
| 10174 |
|
| 10175 |
|
| 10176 |
|
| 10177 |
|
| 10178 |
@SuppressLint("InvalidNullConversion") |
| 10179 |
@Nullable |
| 10180 |
public Icon getIcon() { |
| 10181 |
return mIcon; |
| 10182 |
} |
| 10183 |
|
| 10184 |
|
| 10185 |
|
| 10186 |
|
| 10187 |
|
| 10188 |
@Nullable |
| 10189 |
@Deprecated |
| 10190 |
public Icon getBubbleIcon() { |
| 10191 |
return mIcon; |
| 10192 |
} |
| 10193 |
|
| 10194 |
|
| 10195 |
|
| 10196 |
|
| 10197 |
|
| 10198 |
|
| 10199 |
@Dimension(unit = DP) |
| 10200 |
public int getDesiredHeight() { |
| 10201 |
return mDesiredHeight; |
| 10202 |
} |
| 10203 |
|
| 10204 |
|
| 10205 |
|
| 10206 |
|
| 10207 |
|
| 10208 |
|
| 10209 |
@DimenRes |
| 10210 |
public int getDesiredHeightResId() { |
| 10211 |
return mDesiredHeightResId; |
| 10212 |
} |
| 10213 |
|
| 10214 |
|
| 10215 |
|
| 10216 |
|
| 10217 |
|
| 10218 |
|
| 10219 |
public boolean getAutoExpandBubble() { |
| 10220 |
return (mFlags & FLAG_AUTO_EXPAND_BUBBLE) != 0; |
| 10221 |
} |
| 10222 |
|
| 10223 |
|
| 10224 |
|
| 10225 |
|
| 10226 |
|
| 10227 |
|
| 10228 |
|
| 10229 |
|
| 10230 |
|
| 10231 |
|
| 10232 |
|
| 10233 |
|
| 10234 |
|
| 10235 |
|
| 10236 |
|
| 10237 |
|
| 10238 |
|
| 10239 |
|
| 10240 |
|
| 10241 |
|
| 10242 |
public boolean isNotificationSuppressed() { |
| 10243 |
return (mFlags & FLAG_SUPPRESS_NOTIFICATION) != 0; |
| 10244 |
} |
| 10245 |
|
| 10246 |
|
| 10247 |
|
| 10248 |
|
| 10249 |
|
| 10250 |
|
| 10251 |
|
| 10252 |
|
| 10253 |
|
| 10254 |
|
| 10255 |
|
| 10256 |
|
| 10257 |
|
| 10258 |
|
| 10259 |
public boolean isBubbleSuppressable() { |
| 10260 |
return (mFlags & FLAG_SUPPRESSABLE_BUBBLE) != 0; |
| 10261 |
} |
| 10262 |
|
| 10263 |
|
| 10264 |
|
| 10265 |
|
| 10266 |
|
| 10267 |
|
| 10268 |
public boolean isBubbleSuppressed() { |
| 10269 |
return (mFlags & FLAG_SUPPRESS_BUBBLE) != 0; |
| 10270 |
} |
| 10271 |
|
| 10272 |
|
| 10273 |
|
| 10274 |
|
| 10275 |
|
| 10276 |
|
| 10277 |
|
| 10278 |
|
| 10279 |
public void setSuppressNotification(boolean suppressed) { |
| 10280 |
if (suppressed) { |
| 10281 |
mFlags |= Notification.BubbleMetadata.FLAG_SUPPRESS_NOTIFICATION; |
| 10282 |
} else { |
| 10283 |
mFlags &= ~Notification.BubbleMetadata.FLAG_SUPPRESS_NOTIFICATION; |
| 10284 |
} |
| 10285 |
} |
| 10286 |
|
| 10287 |
|
| 10288 |
|
| 10289 |
|
| 10290 |
|
| 10291 |
|
| 10292 |
|
| 10293 |
|
| 10294 |
public void setSuppressBubble(boolean suppressed) { |
| 10295 |
if (suppressed) { |
| 10296 |
mFlags |= Notification.BubbleMetadata.FLAG_SUPPRESS_BUBBLE; |
| 10297 |
} else { |
| 10298 |
mFlags &= ~Notification.BubbleMetadata.FLAG_SUPPRESS_BUBBLE; |
| 10299 |
} |
| 10300 |
} |
| 10301 |
|
| 10302 |
|
| 10303 |
|
| 10304 |
|
| 10305 |
public void setFlags(int flags) { |
| 10306 |
mFlags = flags; |
| 10307 |
} |
| 10308 |
|
| 10309 |
|
| 10310 |
|
| 10311 |
|
| 10312 |
public int getFlags() { |
| 10313 |
return mFlags; |
| 10314 |
} |
| 10315 |
|
| 10316 |
public static final @android.annotation.NonNull Parcelable.Creator<BubbleMetadata> CREATOR = |
| 10317 |
new Parcelable.Creator<BubbleMetadata>() { |
| 10318 |
|
| 10319 |
@Override |
| 10320 |
public BubbleMetadata createFromParcel(Parcel source) { |
| 10321 |
return new BubbleMetadata(source); |
| 10322 |
} |
| 10323 |
|
| 10324 |
@Override |
| 10325 |
public BubbleMetadata[] newArray(int size) { |
| 10326 |
return new BubbleMetadata[size]; |
| 10327 |
} |
| 10328 |
}; |
| 10329 |
|
| 10330 |
@Override |
| 10331 |
public int describeContents() { |
| 10332 |
return 0; |
| 10333 |
} |
| 10334 |
|
| 10335 |
@Override |
| 10336 |
public void writeToParcel(Parcel out, int flags) { |
| 10337 |
out.writeInt(mPendingIntent != null ? 1 : 0); |
| 10338 |
if (mPendingIntent != null) { |
| 10339 |
mPendingIntent.writeToParcel(out, 0); |
| 10340 |
} |
| 10341 |
out.writeInt(mIcon != null ? 1 : 0); |
| 10342 |
if (mIcon != null) { |
| 10343 |
mIcon.writeToParcel(out, 0); |
| 10344 |
} |
| 10345 |
out.writeInt(mDesiredHeight); |
| 10346 |
out.writeInt(mFlags); |
| 10347 |
out.writeInt(mDeleteIntent != null ? 1 : 0); |
| 10348 |
if (mDeleteIntent != null) { |
| 10349 |
mDeleteIntent.writeToParcel(out, 0); |
| 10350 |
} |
| 10351 |
out.writeInt(mDesiredHeightResId); |
| 10352 |
out.writeInt(TextUtils.isEmpty(mShortcutId) ? 0 : 1); |
| 10353 |
if (!TextUtils.isEmpty(mShortcutId)) { |
| 10354 |
out.writeString8(mShortcutId); |
| 10355 |
} |
| 10356 |
} |
| 10357 |
|
| 10358 |
|
| 10359 |
|
| 10360 |
|
| 10361 |
public static final class Builder { |
| 10362 |
|
| 10363 |
private PendingIntent mPendingIntent; |
| 10364 |
private Icon mIcon; |
| 10365 |
private int mDesiredHeight; |
| 10366 |
@DimenRes private int mDesiredHeightResId; |
| 10367 |
private int mFlags; |
| 10368 |
private PendingIntent mDeleteIntent; |
| 10369 |
private String mShortcutId; |
| 10370 |
|
| 10371 |
|
| 10372 |
|
| 10373 |
|
| 10374 |
|
| 10375 |
|
| 10376 |
@Deprecated |
| 10377 |
public Builder() { |
| 10378 |
} |
| 10379 |
|
| 10380 |
|
| 10381 |
|
| 10382 |
|
| 10383 |
|
| 10384 |
|
| 10385 |
|
| 10386 |
|
| 10387 |
|
| 10388 |
|
| 10389 |
|
| 10390 |
|
| 10391 |
|
| 10392 |
|
| 10393 |
|
| 10394 |
|
| 10395 |
|
| 10396 |
|
| 10397 |
|
| 10398 |
|
| 10399 |
|
| 10400 |
|
| 10401 |
|
| 10402 |
|
| 10403 |
|
| 10404 |
|
| 10405 |
|
| 10406 |
public Builder(@NonNull String shortcutId) { |
| 10407 |
if (TextUtils.isEmpty(shortcutId)) { |
| 10408 |
throw new NullPointerException("Bubble requires a non-null shortcut id"); |
| 10409 |
} |
| 10410 |
mShortcutId = shortcutId; |
| 10411 |
} |
| 10412 |
|
| 10413 |
|
| 10414 |
|
| 10415 |
|
| 10416 |
|
| 10417 |
|
| 10418 |
|
| 10419 |
|
| 10420 |
|
| 10421 |
|
| 10422 |
|
| 10423 |
|
| 10424 |
|
| 10425 |
|
| 10426 |
|
| 10427 |
|
| 10428 |
|
| 10429 |
|
| 10430 |
|
| 10431 |
|
| 10432 |
|
| 10433 |
public Builder(@NonNull PendingIntent intent, @NonNull Icon icon) { |
| 10434 |
if (intent == null) { |
| 10435 |
throw new NullPointerException("Bubble requires non-null pending intent"); |
| 10436 |
} |
| 10437 |
if (icon == null) { |
| 10438 |
throw new NullPointerException("Bubbles require non-null icon"); |
| 10439 |
} |
| 10440 |
if (icon.getType() != TYPE_URI_ADAPTIVE_BITMAP |
| 10441 |
&& icon.getType() != TYPE_URI) { |
| 10442 |
Log.w(TAG, "Bubbles work best with icons of TYPE_URI or " |
| 10443 |
+ "TYPE_URI_ADAPTIVE_BITMAP. " |
| 10444 |
+ "In the future, using an icon of this type will be required."); |
| 10445 |
} |
| 10446 |
mPendingIntent = intent; |
| 10447 |
mIcon = icon; |
| 10448 |
} |
| 10449 |
|
| 10450 |
|
| 10451 |
|
| 10452 |
|
| 10453 |
|
| 10454 |
@NonNull |
| 10455 |
@Deprecated |
| 10456 |
public BubbleMetadata.Builder createShortcutBubble(@NonNull String shortcutId) { |
| 10457 |
if (!TextUtils.isEmpty(shortcutId)) { |
| 10458 |
|
| 10459 |
mPendingIntent = null; |
| 10460 |
mIcon = null; |
| 10461 |
} |
| 10462 |
mShortcutId = shortcutId; |
| 10463 |
return this; |
| 10464 |
} |
| 10465 |
|
| 10466 |
|
| 10467 |
|
| 10468 |
|
| 10469 |
|
| 10470 |
@NonNull |
| 10471 |
@Deprecated |
| 10472 |
public BubbleMetadata.Builder createIntentBubble(@NonNull PendingIntent intent, |
| 10473 |
@NonNull Icon icon) { |
| 10474 |
if (intent == null) { |
| 10475 |
throw new IllegalArgumentException("Bubble requires non-null pending intent"); |
| 10476 |
} |
| 10477 |
if (icon == null) { |
| 10478 |
throw new IllegalArgumentException("Bubbles require non-null icon"); |
| 10479 |
} |
| 10480 |
if (icon.getType() != TYPE_URI_ADAPTIVE_BITMAP |
| 10481 |
&& icon.getType() != TYPE_URI) { |
| 10482 |
Log.w(TAG, "Bubbles work best with icons of TYPE_URI or " |
| 10483 |
+ "TYPE_URI_ADAPTIVE_BITMAP. " |
| 10484 |
+ "In the future, using an icon of this type will be required."); |
| 10485 |
} |
| 10486 |
mShortcutId = null; |
| 10487 |
mPendingIntent = intent; |
| 10488 |
mIcon = icon; |
| 10489 |
return this; |
| 10490 |
} |
| 10491 |
|
| 10492 |
|
| 10493 |
|
| 10494 |
|
| 10495 |
|
| 10496 |
|
| 10497 |
|
| 10498 |
|
| 10499 |
|
| 10500 |
|
| 10501 |
|
| 10502 |
|
| 10503 |
@NonNull |
| 10504 |
public BubbleMetadata.Builder setIntent(@NonNull PendingIntent intent) { |
| 10505 |
if (mShortcutId != null) { |
| 10506 |
throw new IllegalStateException("Created as a shortcut bubble, cannot set a " |
| 10507 |
+ "PendingIntent. Consider using " |
| 10508 |
+ "BubbleMetadata.Builder(PendingIntent,Icon) instead."); |
| 10509 |
} |
| 10510 |
if (intent == null) { |
| 10511 |
throw new NullPointerException("Bubble requires non-null pending intent"); |
| 10512 |
} |
| 10513 |
mPendingIntent = intent; |
| 10514 |
return this; |
| 10515 |
} |
| 10516 |
|
| 10517 |
|
| 10518 |
|
| 10519 |
|
| 10520 |
|
| 10521 |
|
| 10522 |
|
| 10523 |
|
| 10524 |
|
| 10525 |
|
| 10526 |
|
| 10527 |
|
| 10528 |
|
| 10529 |
|
| 10530 |
|
| 10531 |
|
| 10532 |
@NonNull |
| 10533 |
public BubbleMetadata.Builder setIcon(@NonNull Icon icon) { |
| 10534 |
if (mShortcutId != null) { |
| 10535 |
throw new IllegalStateException("Created as a shortcut bubble, cannot set an " |
| 10536 |
+ "Icon. Consider using " |
| 10537 |
+ "BubbleMetadata.Builder(PendingIntent,Icon) instead."); |
| 10538 |
} |
| 10539 |
if (icon == null) { |
| 10540 |
throw new NullPointerException("Bubbles require non-null icon"); |
| 10541 |
} |
| 10542 |
if (icon.getType() != TYPE_URI_ADAPTIVE_BITMAP |
| 10543 |
&& icon.getType() != TYPE_URI) { |
| 10544 |
Log.w(TAG, "Bubbles work best with icons of TYPE_URI or " |
| 10545 |
+ "TYPE_URI_ADAPTIVE_BITMAP. " |
| 10546 |
+ "In the future, using an icon of this type will be required."); |
| 10547 |
} |
| 10548 |
mIcon = icon; |
| 10549 |
return this; |
| 10550 |
} |
| 10551 |
|
| 10552 |
|
| 10553 |
|
| 10554 |
|
| 10555 |
|
| 10556 |
|
| 10557 |
|
| 10558 |
|
| 10559 |
|
| 10560 |
|
| 10561 |
|
| 10562 |
|
| 10563 |
|
| 10564 |
|
| 10565 |
|
| 10566 |
@NonNull |
| 10567 |
public BubbleMetadata.Builder setDesiredHeight(@Dimension(unit = DP) int height) { |
| 10568 |
mDesiredHeight = Math.max(height, 0); |
| 10569 |
mDesiredHeightResId = 0; |
| 10570 |
return this; |
| 10571 |
} |
| 10572 |
|
| 10573 |
|
| 10574 |
|
| 10575 |
|
| 10576 |
|
| 10577 |
|
| 10578 |
|
| 10579 |
|
| 10580 |
|
| 10581 |
|
| 10582 |
|
| 10583 |
|
| 10584 |
|
| 10585 |
|
| 10586 |
|
| 10587 |
|
| 10588 |
@NonNull |
| 10589 |
public BubbleMetadata.Builder setDesiredHeightResId(@DimenRes int heightResId) { |
| 10590 |
mDesiredHeightResId = heightResId; |
| 10591 |
mDesiredHeight = 0; |
| 10592 |
return this; |
| 10593 |
} |
| 10594 |
|
| 10595 |
|
| 10596 |
|
| 10597 |
|
| 10598 |
|
| 10599 |
|
| 10600 |
|
| 10601 |
|
| 10602 |
|
| 10603 |
|
| 10604 |
|
| 10605 |
|
| 10606 |
|
| 10607 |
|
| 10608 |
@NonNull |
| 10609 |
public BubbleMetadata.Builder setAutoExpandBubble(boolean shouldExpand) { |
| 10610 |
setFlag(FLAG_AUTO_EXPAND_BUBBLE, shouldExpand); |
| 10611 |
return this; |
| 10612 |
} |
| 10613 |
|
| 10614 |
|
| 10615 |
|
| 10616 |
|
| 10617 |
|
| 10618 |
|
| 10619 |
|
| 10620 |
|
| 10621 |
|
| 10622 |
|
| 10623 |
|
| 10624 |
@NonNull |
| 10625 |
public BubbleMetadata.Builder setSuppressNotification(boolean shouldSuppressNotif) { |
| 10626 |
setFlag(FLAG_SUPPRESS_NOTIFICATION, shouldSuppressNotif); |
| 10627 |
return this; |
| 10628 |
} |
| 10629 |
|
| 10630 |
|
| 10631 |
|
| 10632 |
|
| 10633 |
|
| 10634 |
|
| 10635 |
|
| 10636 |
|
| 10637 |
|
| 10638 |
|
| 10639 |
|
| 10640 |
|
| 10641 |
@NonNull |
| 10642 |
public BubbleMetadata.Builder setSuppressableBubble(boolean suppressBubble) { |
| 10643 |
setFlag(FLAG_SUPPRESSABLE_BUBBLE, suppressBubble); |
| 10644 |
return this; |
| 10645 |
} |
| 10646 |
|
| 10647 |
|
| 10648 |
|
| 10649 |
|
| 10650 |
|
| 10651 |
|
| 10652 |
@NonNull |
| 10653 |
public BubbleMetadata.Builder setDeleteIntent(@Nullable PendingIntent deleteIntent) { |
| 10654 |
mDeleteIntent = deleteIntent; |
| 10655 |
return this; |
| 10656 |
} |
| 10657 |
|
| 10658 |
|
| 10659 |
|
| 10660 |
|
| 10661 |
|
| 10662 |
|
| 10663 |
@NonNull |
| 10664 |
public BubbleMetadata build() { |
| 10665 |
if (mShortcutId == null && mPendingIntent == null) { |
| 10666 |
throw new NullPointerException( |
| 10667 |
"Must supply pending intent or shortcut to bubble"); |
| 10668 |
} |
| 10669 |
if (mShortcutId == null && mIcon == null) { |
| 10670 |
throw new NullPointerException( |
| 10671 |
"Must supply an icon or shortcut for the bubble"); |
| 10672 |
} |
| 10673 |
BubbleMetadata data = new BubbleMetadata(mPendingIntent, mDeleteIntent, |
| 10674 |
mIcon, mDesiredHeight, mDesiredHeightResId, mShortcutId); |
| 10675 |
data.setFlags(mFlags); |
| 10676 |
return data; |
| 10677 |
} |
| 10678 |
|
| 10679 |
|
| 10680 |
|
| 10681 |
|
| 10682 |
public BubbleMetadata.Builder setFlag(int mask, boolean value) { |
| 10683 |
if (value) { |
| 10684 |
mFlags |= mask; |
| 10685 |
} else { |
| 10686 |
mFlags &= ~mask; |
| 10687 |
} |
| 10688 |
return this; |
| 10689 |
} |
| 10690 |
} |
| 10691 |
} |
| 10692 |
|
| 10693 |
|
| 10694 |
|
| 10695 |
|
| 10696 |
|
| 10697 |
|
| 10698 |
|
| 10699 |
|
| 10700 |
|
| 10701 |
public interface Extender { |
| 10702 |
|
| 10703 |
|
| 10704 |
|
| 10705 |
|
| 10706 |
|
| 10707 |
public Builder extend(Builder builder); |
| 10708 |
} |
| 10709 |
|
| 10710 |
|
| 10711 |
|
| 10712 |
|
| 10713 |
|
| 10714 |
|
| 10715 |
|
| 10716 |
|
| 10717 |
|
| 10718 |
|
| 10719 |
|
| 10720 |
|
| 10721 |
|
| 10722 |
|
| 10723 |
|
| 10724 |
|
| 10725 |
|
| 10726 |
|
| 10727 |
|
| 10728 |
|
| 10729 |
|
| 10730 |
|
| 10731 |
|
| 10732 |
|
| 10733 |
|
| 10734 |
|
| 10735 |
|
| 10736 |
|
| 10737 |
|
| 10738 |
|
| 10739 |
|
| 10740 |
|
| 10741 |
|
| 10742 |
|
| 10743 |
|
| 10744 |
|
| 10745 |
|
| 10746 |
|
| 10747 |
|
| 10748 |
|
| 10749 |
|
| 10750 |
public static final class WearableExtender implements Extender { |
| 10751 |
|
| 10752 |
|
| 10753 |
|
| 10754 |
public static final int UNSET_ACTION_INDEX = -1; |
| 10755 |
|
| 10756 |
|
| 10757 |
|
| 10758 |
|
| 10759 |
|
| 10760 |
|
| 10761 |
|
| 10762 |
|
| 10763 |
|
| 10764 |
|
| 10765 |
@Deprecated |
| 10766 |
public static final int SIZE_DEFAULT = 0; |
| 10767 |
|
| 10768 |
|
| 10769 |
|
| 10770 |
|
| 10771 |
|
| 10772 |
|
| 10773 |
|
| 10774 |
|
| 10775 |
|
| 10776 |
@Deprecated |
| 10777 |
public static final int SIZE_XSMALL = 1; |
| 10778 |
|
| 10779 |
|
| 10780 |
|
| 10781 |
|
| 10782 |
|
| 10783 |
|
| 10784 |
|
| 10785 |
|
| 10786 |
|
| 10787 |
@Deprecated |
| 10788 |
public static final int SIZE_SMALL = 2; |
| 10789 |
|
| 10790 |
|
| 10791 |
|
| 10792 |
|
| 10793 |
|
| 10794 |
|
| 10795 |
|
| 10796 |
|
| 10797 |
|
| 10798 |
@Deprecated |
| 10799 |
public static final int SIZE_MEDIUM = 3; |
| 10800 |
|
| 10801 |
|
| 10802 |
|
| 10803 |
|
| 10804 |
|
| 10805 |
|
| 10806 |
|
| 10807 |
|
| 10808 |
|
| 10809 |
@Deprecated |
| 10810 |
public static final int SIZE_LARGE = 4; |
| 10811 |
|
| 10812 |
|
| 10813 |
|
| 10814 |
|
| 10815 |
|
| 10816 |
|
| 10817 |
|
| 10818 |
|
| 10819 |
|
| 10820 |
@Deprecated |
| 10821 |
public static final int SIZE_FULL_SCREEN = 5; |
| 10822 |
|
| 10823 |
|
| 10824 |
|
| 10825 |
|
| 10826 |
|
| 10827 |
|
| 10828 |
|
| 10829 |
|
| 10830 |
@Deprecated |
| 10831 |
public static final int SCREEN_TIMEOUT_SHORT = 0; |
| 10832 |
|
| 10833 |
|
| 10834 |
|
| 10835 |
|
| 10836 |
|
| 10837 |
|
| 10838 |
|
| 10839 |
@Deprecated |
| 10840 |
public static final int SCREEN_TIMEOUT_LONG = -1; |
| 10841 |
|
| 10842 |
|
| 10843 |
private static final String EXTRA_WEARABLE_EXTENSIONS = "android.wearable.EXTENSIONS"; |
| 10844 |
|
| 10845 |
|
| 10846 |
private static final String KEY_ACTIONS = "actions"; |
| 10847 |
private static final String KEY_FLAGS = "flags"; |
| 10848 |
static final String KEY_DISPLAY_INTENT = "displayIntent"; |
| 10849 |
private static final String KEY_PAGES = "pages"; |
| 10850 |
static final String KEY_BACKGROUND = "background"; |
| 10851 |
private static final String KEY_CONTENT_ICON = "contentIcon"; |
| 10852 |
private static final String KEY_CONTENT_ICON_GRAVITY = "contentIconGravity"; |
| 10853 |
private static final String KEY_CONTENT_ACTION_INDEX = "contentActionIndex"; |
| 10854 |
private static final String KEY_CUSTOM_SIZE_PRESET = "customSizePreset"; |
| 10855 |
private static final String KEY_CUSTOM_CONTENT_HEIGHT = "customContentHeight"; |
| 10856 |
private static final String KEY_GRAVITY = "gravity"; |
| 10857 |
private static final String KEY_HINT_SCREEN_TIMEOUT = "hintScreenTimeout"; |
| 10858 |
private static final String KEY_DISMISSAL_ID = "dismissalId"; |
| 10859 |
private static final String KEY_BRIDGE_TAG = "bridgeTag"; |
| 10860 |
|
| 10861 |
|
| 10862 |
private static final int FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE = 0x1; |
| 10863 |
private static final int FLAG_HINT_HIDE_ICON = 1 << 1; |
| 10864 |
private static final int FLAG_HINT_SHOW_BACKGROUND_ONLY = 1 << 2; |
| 10865 |
private static final int FLAG_START_SCROLL_BOTTOM = 1 << 3; |
| 10866 |
private static final int FLAG_HINT_AVOID_BACKGROUND_CLIPPING = 1 << 4; |
| 10867 |
private static final int FLAG_BIG_PICTURE_AMBIENT = 1 << 5; |
| 10868 |
private static final int FLAG_HINT_CONTENT_INTENT_LAUNCHES_ACTIVITY = 1 << 6; |
| 10869 |
|
| 10870 |
|
| 10871 |
private static final int DEFAULT_FLAGS = FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE; |
| 10872 |
|
| 10873 |
private static final int DEFAULT_CONTENT_ICON_GRAVITY = Gravity.END; |
| 10874 |
private static final int DEFAULT_GRAVITY = Gravity.BOTTOM; |
| 10875 |
|
| 10876 |
private ArrayList<Action> mActions = new ArrayList<Action>(); |
| 10877 |
private int mFlags = DEFAULT_FLAGS; |
| 10878 |
private PendingIntent mDisplayIntent; |
| 10879 |
private ArrayList<Notification> mPages = new ArrayList<Notification>(); |
| 10880 |
private Bitmap mBackground; |
| 10881 |
private int mContentIcon; |
| 10882 |
private int mContentIconGravity = DEFAULT_CONTENT_ICON_GRAVITY; |
| 10883 |
private int mContentActionIndex = UNSET_ACTION_INDEX; |
| 10884 |
private int mCustomSizePreset = SIZE_DEFAULT; |
| 10885 |
private int mCustomContentHeight; |
| 10886 |
private int mGravity = DEFAULT_GRAVITY; |
| 10887 |
private int mHintScreenTimeout; |
| 10888 |
private String mDismissalId; |
| 10889 |
private String mBridgeTag; |
| 10890 |
|
| 10891 |
|
| 10892 |
|
| 10893 |
|
| 10894 |
|
| 10895 |
public WearableExtender() { |
| 10896 |
} |
| 10897 |
|
| 10898 |
public WearableExtender(Notification notif) { |
| 10899 |
Bundle wearableBundle = notif.extras.getBundle(EXTRA_WEARABLE_EXTENSIONS); |
| 10900 |
if (wearableBundle != null) { |
| 10901 |
List<Action> actions = wearableBundle.getParcelableArrayList(KEY_ACTIONS); |
| 10902 |
if (actions != null) { |
| 10903 |
mActions.addAll(actions); |
| 10904 |
} |
| 10905 |
|
| 10906 |
mFlags = wearableBundle.getInt(KEY_FLAGS, DEFAULT_FLAGS); |
| 10907 |
mDisplayIntent = wearableBundle.getParcelable( |
| 10908 |
KEY_DISPLAY_INTENT, PendingIntent.class); |
| 10909 |
|
| 10910 |
Notification[] pages = getParcelableArrayFromBundle( |
| 10911 |
wearableBundle, KEY_PAGES, Notification.class); |
| 10912 |
if (pages != null) { |
| 10913 |
Collections.addAll(mPages, pages); |
| 10914 |
} |
| 10915 |
|
| 10916 |
mBackground = wearableBundle.getParcelable(KEY_BACKGROUND, Bitmap.class); |
| 10917 |
mContentIcon = wearableBundle.getInt(KEY_CONTENT_ICON); |
| 10918 |
mContentIconGravity = wearableBundle.getInt(KEY_CONTENT_ICON_GRAVITY, |
| 10919 |
DEFAULT_CONTENT_ICON_GRAVITY); |
| 10920 |
mContentActionIndex = wearableBundle.getInt(KEY_CONTENT_ACTION_INDEX, |
| 10921 |
UNSET_ACTION_INDEX); |
| 10922 |
mCustomSizePreset = wearableBundle.getInt(KEY_CUSTOM_SIZE_PRESET, |
| 10923 |
SIZE_DEFAULT); |
| 10924 |
mCustomContentHeight = wearableBundle.getInt(KEY_CUSTOM_CONTENT_HEIGHT); |
| 10925 |
mGravity = wearableBundle.getInt(KEY_GRAVITY, DEFAULT_GRAVITY); |
| 10926 |
mHintScreenTimeout = wearableBundle.getInt(KEY_HINT_SCREEN_TIMEOUT); |
| 10927 |
mDismissalId = wearableBundle.getString(KEY_DISMISSAL_ID); |
| 10928 |
mBridgeTag = wearableBundle.getString(KEY_BRIDGE_TAG); |
| 10929 |
} |
| 10930 |
} |
| 10931 |
|
| 10932 |
|
| 10933 |
|
| 10934 |
|
| 10935 |
|
| 10936 |
|
| 10937 |
@Override |
| 10938 |
public Notification.Builder extend(Notification.Builder builder) { |
| 10939 |
Bundle wearableBundle = new Bundle(); |
| 10940 |
|
| 10941 |
if (!mActions.isEmpty()) { |
| 10942 |
wearableBundle.putParcelableArrayList(KEY_ACTIONS, mActions); |
| 10943 |
} |
| 10944 |
if (mFlags != DEFAULT_FLAGS) { |
| 10945 |
wearableBundle.putInt(KEY_FLAGS, mFlags); |
| 10946 |
} |
| 10947 |
if (mDisplayIntent != null) { |
| 10948 |
wearableBundle.putParcelable(KEY_DISPLAY_INTENT, mDisplayIntent); |
| 10949 |
} |
| 10950 |
if (!mPages.isEmpty()) { |
| 10951 |
wearableBundle.putParcelableArray(KEY_PAGES, mPages.toArray( |
| 10952 |
new Notification[mPages.size()])); |
| 10953 |
} |
| 10954 |
if (mBackground != null) { |
| 10955 |
wearableBundle.putParcelable(KEY_BACKGROUND, mBackground); |
| 10956 |
} |
| 10957 |
if (mContentIcon != 0) { |
| 10958 |
wearableBundle.putInt(KEY_CONTENT_ICON, mContentIcon); |
| 10959 |
} |
| 10960 |
if (mContentIconGravity != DEFAULT_CONTENT_ICON_GRAVITY) { |
| 10961 |
wearableBundle.putInt(KEY_CONTENT_ICON_GRAVITY, mContentIconGravity); |
| 10962 |
} |
| 10963 |
if (mContentActionIndex != UNSET_ACTION_INDEX) { |
| 10964 |
wearableBundle.putInt(KEY_CONTENT_ACTION_INDEX, |
| 10965 |
mContentActionIndex); |
| 10966 |
} |
| 10967 |
if (mCustomSizePreset != SIZE_DEFAULT) { |
| 10968 |
wearableBundle.putInt(KEY_CUSTOM_SIZE_PRESET, mCustomSizePreset); |
| 10969 |
} |
| 10970 |
if (mCustomContentHeight != 0) { |
| 10971 |
wearableBundle.putInt(KEY_CUSTOM_CONTENT_HEIGHT, mCustomContentHeight); |
| 10972 |
} |
| 10973 |
if (mGravity != DEFAULT_GRAVITY) { |
| 10974 |
wearableBundle.putInt(KEY_GRAVITY, mGravity); |
| 10975 |
} |
| 10976 |
if (mHintScreenTimeout != 0) { |
| 10977 |
wearableBundle.putInt(KEY_HINT_SCREEN_TIMEOUT, mHintScreenTimeout); |
| 10978 |
} |
| 10979 |
if (mDismissalId != null) { |
| 10980 |
wearableBundle.putString(KEY_DISMISSAL_ID, mDismissalId); |
| 10981 |
} |
| 10982 |
if (mBridgeTag != null) { |
| 10983 |
wearableBundle.putString(KEY_BRIDGE_TAG, mBridgeTag); |
| 10984 |
} |
| 10985 |
|
| 10986 |
builder.getExtras().putBundle(EXTRA_WEARABLE_EXTENSIONS, wearableBundle); |
| 10987 |
return builder; |
| 10988 |
} |
| 10989 |
|
| 10990 |
@Override |
| 10991 |
public WearableExtender clone() { |
| 10992 |
WearableExtender that = new WearableExtender(); |
| 10993 |
that.mActions = new ArrayList<Action>(this.mActions); |
| 10994 |
that.mFlags = this.mFlags; |
| 10995 |
that.mDisplayIntent = this.mDisplayIntent; |
| 10996 |
that.mPages = new ArrayList<Notification>(this.mPages); |
| 10997 |
that.mBackground = this.mBackground; |
| 10998 |
that.mContentIcon = this.mContentIcon; |
| 10999 |
that.mContentIconGravity = this.mContentIconGravity; |
| 11000 |
that.mContentActionIndex = this.mContentActionIndex; |
| 11001 |
that.mCustomSizePreset = this.mCustomSizePreset; |
| 11002 |
that.mCustomContentHeight = this.mCustomContentHeight; |
| 11003 |
that.mGravity = this.mGravity; |
| 11004 |
that.mHintScreenTimeout = this.mHintScreenTimeout; |
| 11005 |
that.mDismissalId = this.mDismissalId; |
| 11006 |
that.mBridgeTag = this.mBridgeTag; |
| 11007 |
return that; |
| 11008 |
} |
| 11009 |
|
| 11010 |
|
| 11011 |
|
| 11012 |
|
| 11013 |
|
| 11014 |
|
| 11015 |
|
| 11016 |
|
| 11017 |
|
| 11018 |
|
| 11019 |
|
| 11020 |
|
| 11021 |
|
| 11022 |
public WearableExtender addAction(Action action) { |
| 11023 |
mActions.add(action); |
| 11024 |
return this; |
| 11025 |
} |
| 11026 |
|
| 11027 |
|
| 11028 |
|
| 11029 |
|
| 11030 |
|
| 11031 |
|
| 11032 |
|
| 11033 |
|
| 11034 |
|
| 11035 |
|
| 11036 |
|
| 11037 |
|
| 11038 |
|
| 11039 |
public WearableExtender addActions(List<Action> actions) { |
| 11040 |
mActions.addAll(actions); |
| 11041 |
return this; |
| 11042 |
} |
| 11043 |
|
| 11044 |
|
| 11045 |
|
| 11046 |
|
| 11047 |
|
| 11048 |
|
| 11049 |
public WearableExtender clearActions() { |
| 11050 |
mActions.clear(); |
| 11051 |
return this; |
| 11052 |
} |
| 11053 |
|
| 11054 |
|
| 11055 |
|
| 11056 |
|
| 11057 |
public List<Action> getActions() { |
| 11058 |
return mActions; |
| 11059 |
} |
| 11060 |
|
| 11061 |
|
| 11062 |
|
| 11063 |
|
| 11064 |
|
| 11065 |
|
| 11066 |
|
| 11067 |
|
| 11068 |
|
| 11069 |
|
| 11070 |
|
| 11071 |
|
| 11072 |
|
| 11073 |
|
| 11074 |
|
| 11075 |
|
| 11076 |
|
| 11077 |
|
| 11078 |
|
| 11079 |
|
| 11080 |
|
| 11081 |
|
| 11082 |
|
| 11083 |
|
| 11084 |
|
| 11085 |
|
| 11086 |
|
| 11087 |
|
| 11088 |
|
| 11089 |
|
| 11090 |
|
| 11091 |
|
| 11092 |
@Deprecated |
| 11093 |
public WearableExtender setDisplayIntent(PendingIntent intent) { |
| 11094 |
mDisplayIntent = intent; |
| 11095 |
return this; |
| 11096 |
} |
| 11097 |
|
| 11098 |
|
| 11099 |
|
| 11100 |
|
| 11101 |
|
| 11102 |
|
| 11103 |
|
| 11104 |
@Deprecated |
| 11105 |
public PendingIntent getDisplayIntent() { |
| 11106 |
return mDisplayIntent; |
| 11107 |
} |
| 11108 |
|
| 11109 |
|
| 11110 |
|
| 11111 |
|
| 11112 |
|
| 11113 |
|
| 11114 |
|
| 11115 |
|
| 11116 |
|
| 11117 |
|
| 11118 |
|
| 11119 |
|
| 11120 |
@Deprecated |
| 11121 |
public WearableExtender addPage(Notification page) { |
| 11122 |
mPages.add(page); |
| 11123 |
return this; |
| 11124 |
} |
| 11125 |
|
| 11126 |
|
| 11127 |
|
| 11128 |
|
| 11129 |
|
| 11130 |
|
| 11131 |
|
| 11132 |
|
| 11133 |
|
| 11134 |
|
| 11135 |
|
| 11136 |
|
| 11137 |
@Deprecated |
| 11138 |
public WearableExtender addPages(List<Notification> pages) { |
| 11139 |
mPages.addAll(pages); |
| 11140 |
return this; |
| 11141 |
} |
| 11142 |
|
| 11143 |
|
| 11144 |
|
| 11145 |
|
| 11146 |
|
| 11147 |
|
| 11148 |
|
| 11149 |
@Deprecated |
| 11150 |
public WearableExtender clearPages() { |
| 11151 |
mPages.clear(); |
| 11152 |
return this; |
| 11153 |
} |
| 11154 |
|
| 11155 |
|
| 11156 |
|
| 11157 |
|
| 11158 |
|
| 11159 |
|
| 11160 |
|
| 11161 |
|
| 11162 |
|
| 11163 |
@Deprecated |
| 11164 |
public List<Notification> getPages() { |
| 11165 |
return mPages; |
| 11166 |
} |
| 11167 |
|
| 11168 |
|
| 11169 |
|
| 11170 |
|
| 11171 |
|
| 11172 |
|
| 11173 |
|
| 11174 |
|
| 11175 |
|
| 11176 |
|
| 11177 |
|
| 11178 |
@Deprecated |
| 11179 |
public WearableExtender setBackground(Bitmap background) { |
| 11180 |
mBackground = background; |
| 11181 |
return this; |
| 11182 |
} |
| 11183 |
|
| 11184 |
|
| 11185 |
|
| 11186 |
|
| 11187 |
|
| 11188 |
|
| 11189 |
|
| 11190 |
|
| 11191 |
|
| 11192 |
|
| 11193 |
@Deprecated |
| 11194 |
public Bitmap getBackground() { |
| 11195 |
return mBackground; |
| 11196 |
} |
| 11197 |
|
| 11198 |
|
| 11199 |
|
| 11200 |
|
| 11201 |
@Deprecated |
| 11202 |
public WearableExtender setContentIcon(int icon) { |
| 11203 |
mContentIcon = icon; |
| 11204 |
return this; |
| 11205 |
} |
| 11206 |
|
| 11207 |
|
| 11208 |
|
| 11209 |
|
| 11210 |
@Deprecated |
| 11211 |
public int getContentIcon() { |
| 11212 |
return mContentIcon; |
| 11213 |
} |
| 11214 |
|
| 11215 |
|
| 11216 |
|
| 11217 |
|
| 11218 |
|
| 11219 |
|
| 11220 |
|
| 11221 |
@Deprecated |
| 11222 |
public WearableExtender setContentIconGravity(int contentIconGravity) { |
| 11223 |
mContentIconGravity = contentIconGravity; |
| 11224 |
return this; |
| 11225 |
} |
| 11226 |
|
| 11227 |
|
| 11228 |
|
| 11229 |
|
| 11230 |
|
| 11231 |
|
| 11232 |
|
| 11233 |
@Deprecated |
| 11234 |
public int getContentIconGravity() { |
| 11235 |
return mContentIconGravity; |
| 11236 |
} |
| 11237 |
|
| 11238 |
|
| 11239 |
|
| 11240 |
|
| 11241 |
|
| 11242 |
|
| 11243 |
|
| 11244 |
|
| 11245 |
|
| 11246 |
|
| 11247 |
|
| 11248 |
public WearableExtender setContentAction(int actionIndex) { |
| 11249 |
mContentActionIndex = actionIndex; |
| 11250 |
return this; |
| 11251 |
} |
| 11252 |
|
| 11253 |
|
| 11254 |
|
| 11255 |
|
| 11256 |
|
| 11257 |
|
| 11258 |
|
| 11259 |
|
| 11260 |
|
| 11261 |
|
| 11262 |
public int getContentAction() { |
| 11263 |
return mContentActionIndex; |
| 11264 |
} |
| 11265 |
|
| 11266 |
|
| 11267 |
|
| 11268 |
|
| 11269 |
|
| 11270 |
|
| 11271 |
|
| 11272 |
@Deprecated |
| 11273 |
public WearableExtender setGravity(int gravity) { |
| 11274 |
mGravity = gravity; |
| 11275 |
return this; |
| 11276 |
} |
| 11277 |
|
| 11278 |
|
| 11279 |
|
| 11280 |
|
| 11281 |
|
| 11282 |
|
| 11283 |
|
| 11284 |
@Deprecated |
| 11285 |
public int getGravity() { |
| 11286 |
return mGravity; |
| 11287 |
} |
| 11288 |
|
| 11289 |
|
| 11290 |
|
| 11291 |
|
| 11292 |
|
| 11293 |
|
| 11294 |
|
| 11295 |
|
| 11296 |
|
| 11297 |
|
| 11298 |
@Deprecated |
| 11299 |
public WearableExtender setCustomSizePreset(int sizePreset) { |
| 11300 |
mCustomSizePreset = sizePreset; |
| 11301 |
return this; |
| 11302 |
} |
| 11303 |
|
| 11304 |
|
| 11305 |
|
| 11306 |
|
| 11307 |
|
| 11308 |
|
| 11309 |
|
| 11310 |
|
| 11311 |
|
| 11312 |
@Deprecated |
| 11313 |
public int getCustomSizePreset() { |
| 11314 |
return mCustomSizePreset; |
| 11315 |
} |
| 11316 |
|
| 11317 |
|
| 11318 |
|
| 11319 |
|
| 11320 |
|
| 11321 |
|
| 11322 |
|
| 11323 |
|
| 11324 |
@Deprecated |
| 11325 |
public WearableExtender setCustomContentHeight(int height) { |
| 11326 |
mCustomContentHeight = height; |
| 11327 |
return this; |
| 11328 |
} |
| 11329 |
|
| 11330 |
|
| 11331 |
|
| 11332 |
|
| 11333 |
|
| 11334 |
|
| 11335 |
|
| 11336 |
@Deprecated |
| 11337 |
public int getCustomContentHeight() { |
| 11338 |
return mCustomContentHeight; |
| 11339 |
} |
| 11340 |
|
| 11341 |
|
| 11342 |
|
| 11343 |
|
| 11344 |
|
| 11345 |
|
| 11346 |
public WearableExtender setStartScrollBottom(boolean startScrollBottom) { |
| 11347 |
setFlag(FLAG_START_SCROLL_BOTTOM, startScrollBottom); |
| 11348 |
return this; |
| 11349 |
} |
| 11350 |
|
| 11351 |
|
| 11352 |
|
| 11353 |
|
| 11354 |
|
| 11355 |
|
| 11356 |
public boolean getStartScrollBottom() { |
| 11357 |
return (mFlags & FLAG_START_SCROLL_BOTTOM) != 0; |
| 11358 |
} |
| 11359 |
|
| 11360 |
|
| 11361 |
|
| 11362 |
|
| 11363 |
|
| 11364 |
|
| 11365 |
|
| 11366 |
public WearableExtender setContentIntentAvailableOffline( |
| 11367 |
boolean contentIntentAvailableOffline) { |
| 11368 |
setFlag(FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE, contentIntentAvailableOffline); |
| 11369 |
return this; |
| 11370 |
} |
| 11371 |
|
| 11372 |
|
| 11373 |
|
| 11374 |
|
| 11375 |
|
| 11376 |
|
| 11377 |
|
| 11378 |
public boolean getContentIntentAvailableOffline() { |
| 11379 |
return (mFlags & FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE) != 0; |
| 11380 |
} |
| 11381 |
|
| 11382 |
|
| 11383 |
|
| 11384 |
|
| 11385 |
|
| 11386 |
|
| 11387 |
@Deprecated |
| 11388 |
public WearableExtender setHintHideIcon(boolean hintHideIcon) { |
| 11389 |
setFlag(FLAG_HINT_HIDE_ICON, hintHideIcon); |
| 11390 |
return this; |
| 11391 |
} |
| 11392 |
|
| 11393 |
|
| 11394 |
|
| 11395 |
|
| 11396 |
|
| 11397 |
|
| 11398 |
@Deprecated |
| 11399 |
public boolean getHintHideIcon() { |
| 11400 |
return (mFlags & FLAG_HINT_HIDE_ICON) != 0; |
| 11401 |
} |
| 11402 |
|
| 11403 |
|
| 11404 |
|
| 11405 |
|
| 11406 |
|
| 11407 |
|
| 11408 |
@Deprecated |
| 11409 |
public WearableExtender setHintShowBackgroundOnly(boolean hintShowBackgroundOnly) { |
| 11410 |
setFlag(FLAG_HINT_SHOW_BACKGROUND_ONLY, hintShowBackgroundOnly); |
| 11411 |
return this; |
| 11412 |
} |
| 11413 |
|
| 11414 |
|
| 11415 |
|
| 11416 |
|
| 11417 |
|
| 11418 |
|
| 11419 |
@Deprecated |
| 11420 |
public boolean getHintShowBackgroundOnly() { |
| 11421 |
return (mFlags & FLAG_HINT_SHOW_BACKGROUND_ONLY) != 0; |
| 11422 |
} |
| 11423 |
|
| 11424 |
|
| 11425 |
|
| 11426 |
|
| 11427 |
|
| 11428 |
|
| 11429 |
|
| 11430 |
|
| 11431 |
@Deprecated |
| 11432 |
public WearableExtender setHintAvoidBackgroundClipping( |
| 11433 |
boolean hintAvoidBackgroundClipping) { |
| 11434 |
setFlag(FLAG_HINT_AVOID_BACKGROUND_CLIPPING, hintAvoidBackgroundClipping); |
| 11435 |
return this; |
| 11436 |
} |
| 11437 |
|
| 11438 |
|
| 11439 |
|
| 11440 |
|
| 11441 |
|
| 11442 |
|
| 11443 |
|
| 11444 |
|
| 11445 |
@Deprecated |
| 11446 |
public boolean getHintAvoidBackgroundClipping() { |
| 11447 |
return (mFlags & FLAG_HINT_AVOID_BACKGROUND_CLIPPING) != 0; |
| 11448 |
} |
| 11449 |
|
| 11450 |
|
| 11451 |
|
| 11452 |
|
| 11453 |
|
| 11454 |
|
| 11455 |
|
| 11456 |
|
| 11457 |
@Deprecated |
| 11458 |
public WearableExtender setHintScreenTimeout(int timeout) { |
| 11459 |
mHintScreenTimeout = timeout; |
| 11460 |
return this; |
| 11461 |
} |
| 11462 |
|
| 11463 |
|
| 11464 |
|
| 11465 |
|
| 11466 |
|
| 11467 |
|
| 11468 |
|
| 11469 |
@Deprecated |
| 11470 |
public int getHintScreenTimeout() { |
| 11471 |
return mHintScreenTimeout; |
| 11472 |
} |
| 11473 |
|
| 11474 |
|
| 11475 |
|
| 11476 |
|
| 11477 |
|
| 11478 |
|
| 11479 |
|
| 11480 |
|
| 11481 |
|
| 11482 |
@Deprecated |
| 11483 |
public WearableExtender setHintAmbientBigPicture(boolean hintAmbientBigPicture) { |
| 11484 |
setFlag(FLAG_BIG_PICTURE_AMBIENT, hintAmbientBigPicture); |
| 11485 |
return this; |
| 11486 |
} |
| 11487 |
|
| 11488 |
|
| 11489 |
|
| 11490 |
|
| 11491 |
|
| 11492 |
|
| 11493 |
|
| 11494 |
|
| 11495 |
|
| 11496 |
@Deprecated |
| 11497 |
public boolean getHintAmbientBigPicture() { |
| 11498 |
return (mFlags & FLAG_BIG_PICTURE_AMBIENT) != 0; |
| 11499 |
} |
| 11500 |
|
| 11501 |
|
| 11502 |
|
| 11503 |
|
| 11504 |
|
| 11505 |
|
| 11506 |
|
| 11507 |
|
| 11508 |
public WearableExtender setHintContentIntentLaunchesActivity( |
| 11509 |
boolean hintContentIntentLaunchesActivity) { |
| 11510 |
setFlag(FLAG_HINT_CONTENT_INTENT_LAUNCHES_ACTIVITY, hintContentIntentLaunchesActivity); |
| 11511 |
return this; |
| 11512 |
} |
| 11513 |
|
| 11514 |
|
| 11515 |
|
| 11516 |
|
| 11517 |
|
| 11518 |
|
| 11519 |
|
| 11520 |
public boolean getHintContentIntentLaunchesActivity() { |
| 11521 |
return (mFlags & FLAG_HINT_CONTENT_INTENT_LAUNCHES_ACTIVITY) != 0; |
| 11522 |
} |
| 11523 |
|
| 11524 |
|
| 11525 |
|
| 11526 |
|
| 11527 |
|
| 11528 |
|
| 11529 |
|
| 11530 |
|
| 11531 |
|
| 11532 |
|
| 11533 |
public WearableExtender setDismissalId(String dismissalId) { |
| 11534 |
mDismissalId = dismissalId; |
| 11535 |
return this; |
| 11536 |
} |
| 11537 |
|
| 11538 |
|
| 11539 |
|
| 11540 |
|
| 11541 |
|
| 11542 |
public String getDismissalId() { |
| 11543 |
return mDismissalId; |
| 11544 |
} |
| 11545 |
|
| 11546 |
|
| 11547 |
|
| 11548 |
|
| 11549 |
|
| 11550 |
|
| 11551 |
|
| 11552 |
|
| 11553 |
|
| 11554 |
public WearableExtender setBridgeTag(String bridgeTag) { |
| 11555 |
mBridgeTag = bridgeTag; |
| 11556 |
return this; |
| 11557 |
} |
| 11558 |
|
| 11559 |
|
| 11560 |
|
| 11561 |
|
| 11562 |
|
| 11563 |
public String getBridgeTag() { |
| 11564 |
return mBridgeTag; |
| 11565 |
} |
| 11566 |
|
| 11567 |
private void setFlag(int mask, boolean value) { |
| 11568 |
if (value) { |
| 11569 |
mFlags |= mask; |
| 11570 |
} else { |
| 11571 |
mFlags &= ~mask; |
| 11572 |
} |
| 11573 |
} |
| 11574 |
} |
| 11575 |
|
| 11576 |
|
| 11577 |
|
| 11578 |
|
| 11579 |
|
| 11580 |
|
| 11581 |
|
| 11582 |
|
| 11583 |
|
| 11584 |
|
| 11585 |
|
| 11586 |
|
| 11587 |
|
| 11588 |
|
| 11589 |
|
| 11590 |
|
| 11591 |
|
| 11592 |
|
| 11593 |
|
| 11594 |
|
| 11595 |
|
| 11596 |
|
| 11597 |
|
| 11598 |
|
| 11599 |
|
| 11600 |
|
| 11601 |
|
| 11602 |
public static final class CarExtender implements Extender { |
| 11603 |
private static final String TAG = "CarExtender"; |
| 11604 |
|
| 11605 |
private static final String EXTRA_CAR_EXTENDER = "android.car.EXTENSIONS"; |
| 11606 |
private static final String EXTRA_LARGE_ICON = "large_icon"; |
| 11607 |
private static final String EXTRA_CONVERSATION = "car_conversation"; |
| 11608 |
private static final String EXTRA_COLOR = "app_color"; |
| 11609 |
|
| 11610 |
private Bitmap mLargeIcon; |
| 11611 |
private UnreadConversation mUnreadConversation; |
| 11612 |
private int mColor = Notification.COLOR_DEFAULT; |
| 11613 |
|
| 11614 |
|
| 11615 |
|
| 11616 |
|
| 11617 |
public CarExtender() { |
| 11618 |
} |
| 11619 |
|
| 11620 |
|
| 11621 |
|
| 11622 |
|
| 11623 |
|
| 11624 |
|
| 11625 |
public CarExtender(Notification notif) { |
| 11626 |
Bundle carBundle = notif.extras == null ? |
| 11627 |
null : notif.extras.getBundle(EXTRA_CAR_EXTENDER); |
| 11628 |
if (carBundle != null) { |
| 11629 |
mLargeIcon = carBundle.getParcelable(EXTRA_LARGE_ICON, Bitmap.class); |
| 11630 |
mColor = carBundle.getInt(EXTRA_COLOR, Notification.COLOR_DEFAULT); |
| 11631 |
|
| 11632 |
Bundle b = carBundle.getBundle(EXTRA_CONVERSATION); |
| 11633 |
mUnreadConversation = UnreadConversation.getUnreadConversationFromBundle(b); |
| 11634 |
} |
| 11635 |
} |
| 11636 |
|
| 11637 |
|
| 11638 |
|
| 11639 |
|
| 11640 |
|
| 11641 |
|
| 11642 |
@Override |
| 11643 |
public Notification.Builder extend(Notification.Builder builder) { |
| 11644 |
Bundle carExtensions = new Bundle(); |
| 11645 |
|
| 11646 |
if (mLargeIcon != null) { |
| 11647 |
carExtensions.putParcelable(EXTRA_LARGE_ICON, mLargeIcon); |
| 11648 |
} |
| 11649 |
if (mColor != Notification.COLOR_DEFAULT) { |
| 11650 |
carExtensions.putInt(EXTRA_COLOR, mColor); |
| 11651 |
} |
| 11652 |
|
| 11653 |
if (mUnreadConversation != null) { |
| 11654 |
Bundle b = mUnreadConversation.getBundleForUnreadConversation(); |
| 11655 |
carExtensions.putBundle(EXTRA_CONVERSATION, b); |
| 11656 |
} |
| 11657 |
|
| 11658 |
builder.getExtras().putBundle(EXTRA_CAR_EXTENDER, carExtensions); |
| 11659 |
return builder; |
| 11660 |
} |
| 11661 |
|
| 11662 |
|
| 11663 |
|
| 11664 |
|
| 11665 |
|
| 11666 |
|
| 11667 |
|
| 11668 |
|
| 11669 |
|
| 11670 |
public CarExtender setColor(@ColorInt int color) { |
| 11671 |
mColor = color; |
| 11672 |
return this; |
| 11673 |
} |
| 11674 |
|
| 11675 |
|
| 11676 |
|
| 11677 |
|
| 11678 |
|
| 11679 |
|
| 11680 |
@ColorInt |
| 11681 |
public int getColor() { |
| 11682 |
return mColor; |
| 11683 |
} |
| 11684 |
|
| 11685 |
|
| 11686 |
|
| 11687 |
|
| 11688 |
|
| 11689 |
|
| 11690 |
|
| 11691 |
|
| 11692 |
|
| 11693 |
|
| 11694 |
public CarExtender setLargeIcon(Bitmap largeIcon) { |
| 11695 |
mLargeIcon = largeIcon; |
| 11696 |
return this; |
| 11697 |
} |
| 11698 |
|
| 11699 |
|
| 11700 |
|
| 11701 |
|
| 11702 |
|
| 11703 |
|
| 11704 |
|
| 11705 |
public Bitmap getLargeIcon() { |
| 11706 |
return mLargeIcon; |
| 11707 |
} |
| 11708 |
|
| 11709 |
|
| 11710 |
|
| 11711 |
|
| 11712 |
|
| 11713 |
|
| 11714 |
|
| 11715 |
public CarExtender setUnreadConversation(UnreadConversation unreadConversation) { |
| 11716 |
mUnreadConversation = unreadConversation; |
| 11717 |
return this; |
| 11718 |
} |
| 11719 |
|
| 11720 |
|
| 11721 |
|
| 11722 |
|
| 11723 |
|
| 11724 |
public UnreadConversation getUnreadConversation() { |
| 11725 |
return mUnreadConversation; |
| 11726 |
} |
| 11727 |
|
| 11728 |
|
| 11729 |
|
| 11730 |
|
| 11731 |
public static class UnreadConversation { |
| 11732 |
private static final String KEY_AUTHOR = "author"; |
| 11733 |
private static final String KEY_TEXT = "text"; |
| 11734 |
private static final String KEY_MESSAGES = "messages"; |
| 11735 |
static final String KEY_REMOTE_INPUT = "remote_input"; |
| 11736 |
static final String KEY_ON_REPLY = "on_reply"; |
| 11737 |
static final String KEY_ON_READ = "on_read"; |
| 11738 |
private static final String KEY_PARTICIPANTS = "participants"; |
| 11739 |
private static final String KEY_TIMESTAMP = "timestamp"; |
| 11740 |
|
| 11741 |
private final String[] mMessages; |
| 11742 |
private final RemoteInput mRemoteInput; |
| 11743 |
private final PendingIntent mReplyPendingIntent; |
| 11744 |
private final PendingIntent mReadPendingIntent; |
| 11745 |
private final String[] mParticipants; |
| 11746 |
private final long mLatestTimestamp; |
| 11747 |
|
| 11748 |
UnreadConversation(String[] messages, RemoteInput remoteInput, |
| 11749 |
PendingIntent replyPendingIntent, PendingIntent readPendingIntent, |
| 11750 |
String[] participants, long latestTimestamp) { |
| 11751 |
mMessages = messages; |
| 11752 |
mRemoteInput = remoteInput; |
| 11753 |
mReadPendingIntent = readPendingIntent; |
| 11754 |
mReplyPendingIntent = replyPendingIntent; |
| 11755 |
mParticipants = participants; |
| 11756 |
mLatestTimestamp = latestTimestamp; |
| 11757 |
} |
| 11758 |
|
| 11759 |
|
| 11760 |
|
| 11761 |
|
| 11762 |
public String[] getMessages() { |
| 11763 |
return mMessages; |
| 11764 |
} |
| 11765 |
|
| 11766 |
|
| 11767 |
|
| 11768 |
|
| 11769 |
|
| 11770 |
public RemoteInput getRemoteInput() { |
| 11771 |
return mRemoteInput; |
| 11772 |
} |
| 11773 |
|
| 11774 |
|
| 11775 |
|
| 11776 |
|
| 11777 |
|
| 11778 |
public PendingIntent getReplyPendingIntent() { |
| 11779 |
return mReplyPendingIntent; |
| 11780 |
} |
| 11781 |
|
| 11782 |
|
| 11783 |
|
| 11784 |
|
| 11785 |
|
| 11786 |
public PendingIntent getReadPendingIntent() { |
| 11787 |
return mReadPendingIntent; |
| 11788 |
} |
| 11789 |
|
| 11790 |
|
| 11791 |
|
| 11792 |
|
| 11793 |
public String[] getParticipants() { |
| 11794 |
return mParticipants; |
| 11795 |
} |
| 11796 |
|
| 11797 |
|
| 11798 |
|
| 11799 |
|
| 11800 |
public String getParticipant() { |
| 11801 |
return mParticipants.length > 0 ? mParticipants[0] : null; |
| 11802 |
} |
| 11803 |
|
| 11804 |
|
| 11805 |
|
| 11806 |
|
| 11807 |
public long getLatestTimestamp() { |
| 11808 |
return mLatestTimestamp; |
| 11809 |
} |
| 11810 |
|
| 11811 |
Bundle getBundleForUnreadConversation() { |
| 11812 |
Bundle b = new Bundle(); |
| 11813 |
String author = null; |
| 11814 |
if (mParticipants != null && mParticipants.length > 1) { |
| 11815 |
author = mParticipants[0]; |
| 11816 |
} |
| 11817 |
Parcelable[] messages = new Parcelable[mMessages.length]; |
| 11818 |
for (int i = 0; i < messages.length; i++) { |
| 11819 |
Bundle m = new Bundle(); |
| 11820 |
m.putString(KEY_TEXT, mMessages[i]); |
| 11821 |
m.putString(KEY_AUTHOR, author); |
| 11822 |
messages[i] = m; |
| 11823 |
} |
| 11824 |
b.putParcelableArray(KEY_MESSAGES, messages); |
| 11825 |
if (mRemoteInput != null) { |
| 11826 |
b.putParcelable(KEY_REMOTE_INPUT, mRemoteInput); |
| 11827 |
} |
| 11828 |
b.putParcelable(KEY_ON_REPLY, mReplyPendingIntent); |
| 11829 |
b.putParcelable(KEY_ON_READ, mReadPendingIntent); |
| 11830 |
b.putStringArray(KEY_PARTICIPANTS, mParticipants); |
| 11831 |
b.putLong(KEY_TIMESTAMP, mLatestTimestamp); |
| 11832 |
return b; |
| 11833 |
} |
| 11834 |
|
| 11835 |
static UnreadConversation getUnreadConversationFromBundle(Bundle b) { |
| 11836 |
if (b == null) { |
| 11837 |
return null; |
| 11838 |
} |
| 11839 |
Parcelable[] parcelableMessages = b.getParcelableArray(KEY_MESSAGES); |
| 11840 |
String[] messages = null; |
| 11841 |
if (parcelableMessages != null) { |
| 11842 |
String[] tmp = new String[parcelableMessages.length]; |
| 11843 |
boolean success = true; |
| 11844 |
for (int i = 0; i < tmp.length; i++) { |
| 11845 |
if (!(parcelableMessages[i] instanceof Bundle)) { |
| 11846 |
success = false; |
| 11847 |
break; |
| 11848 |
} |
| 11849 |
tmp[i] = ((Bundle) parcelableMessages[i]).getString(KEY_TEXT); |
| 11850 |
if (tmp[i] == null) { |
| 11851 |
success = false; |
| 11852 |
break; |
| 11853 |
} |
| 11854 |
} |
| 11855 |
if (success) { |
| 11856 |
messages = tmp; |
| 11857 |
} else { |
| 11858 |
return null; |
| 11859 |
} |
| 11860 |
} |
| 11861 |
|
| 11862 |
PendingIntent onRead = b.getParcelable(KEY_ON_READ, PendingIntent.class); |
| 11863 |
PendingIntent onReply = b.getParcelable(KEY_ON_REPLY, PendingIntent.class); |
| 11864 |
|
| 11865 |
RemoteInput remoteInput = b.getParcelable(KEY_REMOTE_INPUT, RemoteInput.class); |
| 11866 |
|
| 11867 |
String[] participants = b.getStringArray(KEY_PARTICIPANTS); |
| 11868 |
if (participants == null || participants.length != 1) { |
| 11869 |
return null; |
| 11870 |
} |
| 11871 |
|
| 11872 |
return new UnreadConversation(messages, |
| 11873 |
remoteInput, |
| 11874 |
onReply, |
| 11875 |
onRead, |
| 11876 |
participants, b.getLong(KEY_TIMESTAMP)); |
| 11877 |
} |
| 11878 |
}; |
| 11879 |
|
| 11880 |
|
| 11881 |
|
| 11882 |
|
| 11883 |
public static class Builder { |
| 11884 |
private final List<String> mMessages = new ArrayList<String>(); |
| 11885 |
private final String mParticipant; |
| 11886 |
private RemoteInput mRemoteInput; |
| 11887 |
private PendingIntent mReadPendingIntent; |
| 11888 |
private PendingIntent mReplyPendingIntent; |
| 11889 |
private long mLatestTimestamp; |
| 11890 |
|
| 11891 |
|
| 11892 |
|
| 11893 |
|
| 11894 |
|
| 11895 |
|
| 11896 |
public Builder(String name) { |
| 11897 |
mParticipant = name; |
| 11898 |
} |
| 11899 |
|
| 11900 |
|
| 11901 |
|
| 11902 |
|
| 11903 |
|
| 11904 |
|
| 11905 |
|
| 11906 |
|
| 11907 |
|
| 11908 |
public Builder addMessage(String message) { |
| 11909 |
mMessages.add(message); |
| 11910 |
return this; |
| 11911 |
} |
| 11912 |
|
| 11913 |
|
| 11914 |
|
| 11915 |
|
| 11916 |
|
| 11917 |
|
| 11918 |
|
| 11919 |
|
| 11920 |
|
| 11921 |
|
| 11922 |
|
| 11923 |
|
| 11924 |
public Builder setReplyAction( |
| 11925 |
PendingIntent pendingIntent, RemoteInput remoteInput) { |
| 11926 |
mRemoteInput = remoteInput; |
| 11927 |
mReplyPendingIntent = pendingIntent; |
| 11928 |
|
| 11929 |
return this; |
| 11930 |
} |
| 11931 |
|
| 11932 |
|
| 11933 |
|
| 11934 |
|
| 11935 |
|
| 11936 |
|
| 11937 |
|
| 11938 |
|
| 11939 |
public Builder setReadPendingIntent(PendingIntent pendingIntent) { |
| 11940 |
mReadPendingIntent = pendingIntent; |
| 11941 |
return this; |
| 11942 |
} |
| 11943 |
|
| 11944 |
|
| 11945 |
|
| 11946 |
|
| 11947 |
|
| 11948 |
|
| 11949 |
|
| 11950 |
|
| 11951 |
|
| 11952 |
|
| 11953 |
|
| 11954 |
|
| 11955 |
public Builder setLatestTimestamp(long timestamp) { |
| 11956 |
mLatestTimestamp = timestamp; |
| 11957 |
return this; |
| 11958 |
} |
| 11959 |
|
| 11960 |
|
| 11961 |
|
| 11962 |
|
| 11963 |
|
| 11964 |
|
| 11965 |
public UnreadConversation build() { |
| 11966 |
String[] messages = mMessages.toArray(new String[mMessages.size()]); |
| 11967 |
String[] participants = { mParticipant }; |
| 11968 |
return new UnreadConversation(messages, mRemoteInput, mReplyPendingIntent, |
| 11969 |
mReadPendingIntent, participants, mLatestTimestamp); |
| 11970 |
} |
| 11971 |
} |
| 11972 |
} |
| 11973 |
|
| 11974 |
|
| 11975 |
|
| 11976 |
|
| 11977 |
|
| 11978 |
|
| 11979 |
|
| 11980 |
|
| 11981 |
|
| 11982 |
|
| 11983 |
|
| 11984 |
|
| 11985 |
|
| 11986 |
|
| 11987 |
|
| 11988 |
|
| 11989 |
|
| 11990 |
|
| 11991 |
|
| 11992 |
|
| 11993 |
|
| 11994 |
|
| 11995 |
|
| 11996 |
|
| 11997 |
|
| 11998 |
|
| 11999 |
|
| 12000 |
|
| 12001 |
@SystemApi |
| 12002 |
public static final class TvExtender implements Extender { |
| 12003 |
private static final String TAG = "TvExtender"; |
| 12004 |
|
| 12005 |
private static final String EXTRA_TV_EXTENDER = "android.tv.EXTENSIONS"; |
| 12006 |
private static final String EXTRA_FLAGS = "flags"; |
| 12007 |
static final String EXTRA_CONTENT_INTENT = "content_intent"; |
| 12008 |
static final String EXTRA_DELETE_INTENT = "delete_intent"; |
| 12009 |
private static final String EXTRA_CHANNEL_ID = "channel_id"; |
| 12010 |
private static final String EXTRA_SUPPRESS_SHOW_OVER_APPS = "suppressShowOverApps"; |
| 12011 |
|
| 12012 |
|
| 12013 |
private static final int FLAG_AVAILABLE_ON_TV = 0x1; |
| 12014 |
|
| 12015 |
private int mFlags; |
| 12016 |
private String mChannelId; |
| 12017 |
private PendingIntent mContentIntent; |
| 12018 |
private PendingIntent mDeleteIntent; |
| 12019 |
private boolean mSuppressShowOverApps; |
| 12020 |
|
| 12021 |
|
| 12022 |
|
| 12023 |
|
| 12024 |
public TvExtender() { |
| 12025 |
mFlags = FLAG_AVAILABLE_ON_TV; |
| 12026 |
} |
| 12027 |
|
| 12028 |
|
| 12029 |
|
| 12030 |
|
| 12031 |
|
| 12032 |
|
| 12033 |
public TvExtender(Notification notif) { |
| 12034 |
Bundle bundle = notif.extras == null ? |
| 12035 |
null : notif.extras.getBundle(EXTRA_TV_EXTENDER); |
| 12036 |
if (bundle != null) { |
| 12037 |
mFlags = bundle.getInt(EXTRA_FLAGS); |
| 12038 |
mChannelId = bundle.getString(EXTRA_CHANNEL_ID); |
| 12039 |
mSuppressShowOverApps = bundle.getBoolean(EXTRA_SUPPRESS_SHOW_OVER_APPS); |
| 12040 |
mContentIntent = bundle.getParcelable(EXTRA_CONTENT_INTENT, PendingIntent.class); |
| 12041 |
mDeleteIntent = bundle.getParcelable(EXTRA_DELETE_INTENT, PendingIntent.class); |
| 12042 |
} |
| 12043 |
} |
| 12044 |
|
| 12045 |
|
| 12046 |
|
| 12047 |
|
| 12048 |
|
| 12049 |
|
| 12050 |
@Override |
| 12051 |
public Notification.Builder extend(Notification.Builder builder) { |
| 12052 |
Bundle bundle = new Bundle(); |
| 12053 |
|
| 12054 |
bundle.putInt(EXTRA_FLAGS, mFlags); |
| 12055 |
bundle.putString(EXTRA_CHANNEL_ID, mChannelId); |
| 12056 |
bundle.putBoolean(EXTRA_SUPPRESS_SHOW_OVER_APPS, mSuppressShowOverApps); |
| 12057 |
if (mContentIntent != null) { |
| 12058 |
bundle.putParcelable(EXTRA_CONTENT_INTENT, mContentIntent); |
| 12059 |
} |
| 12060 |
|
| 12061 |
if (mDeleteIntent != null) { |
| 12062 |
bundle.putParcelable(EXTRA_DELETE_INTENT, mDeleteIntent); |
| 12063 |
} |
| 12064 |
|
| 12065 |
builder.getExtras().putBundle(EXTRA_TV_EXTENDER, bundle); |
| 12066 |
return builder; |
| 12067 |
} |
| 12068 |
|
| 12069 |
|
| 12070 |
|
| 12071 |
|
| 12072 |
|
| 12073 |
public boolean isAvailableOnTv() { |
| 12074 |
return (mFlags & FLAG_AVAILABLE_ON_TV) != 0; |
| 12075 |
} |
| 12076 |
|
| 12077 |
|
| 12078 |
|
| 12079 |
|
| 12080 |
|
| 12081 |
|
| 12082 |
public TvExtender setChannel(String channelId) { |
| 12083 |
mChannelId = channelId; |
| 12084 |
return this; |
| 12085 |
} |
| 12086 |
|
| 12087 |
|
| 12088 |
|
| 12089 |
|
| 12090 |
|
| 12091 |
|
| 12092 |
public TvExtender setChannelId(String channelId) { |
| 12093 |
mChannelId = channelId; |
| 12094 |
return this; |
| 12095 |
} |
| 12096 |
|
| 12097 |
|
| 12098 |
@Deprecated |
| 12099 |
public String getChannel() { |
| 12100 |
return mChannelId; |
| 12101 |
} |
| 12102 |
|
| 12103 |
|
| 12104 |
|
| 12105 |
|
| 12106 |
public String getChannelId() { |
| 12107 |
return mChannelId; |
| 12108 |
} |
| 12109 |
|
| 12110 |
|
| 12111 |
|
| 12112 |
|
| 12113 |
|
| 12114 |
|
| 12115 |
public TvExtender setContentIntent(PendingIntent intent) { |
| 12116 |
mContentIntent = intent; |
| 12117 |
return this; |
| 12118 |
} |
| 12119 |
|
| 12120 |
|
| 12121 |
|
| 12122 |
|
| 12123 |
|
| 12124 |
|
| 12125 |
|
| 12126 |
public PendingIntent getContentIntent() { |
| 12127 |
return mContentIntent; |
| 12128 |
} |
| 12129 |
|
| 12130 |
|
| 12131 |
|
| 12132 |
|
| 12133 |
|
| 12134 |
|
| 12135 |
public TvExtender setDeleteIntent(PendingIntent intent) { |
| 12136 |
mDeleteIntent = intent; |
| 12137 |
return this; |
| 12138 |
} |
| 12139 |
|
| 12140 |
|
| 12141 |
|
| 12142 |
|
| 12143 |
|
| 12144 |
|
| 12145 |
|
| 12146 |
public PendingIntent getDeleteIntent() { |
| 12147 |
return mDeleteIntent; |
| 12148 |
} |
| 12149 |
|
| 12150 |
|
| 12151 |
|
| 12152 |
|
| 12153 |
|
| 12154 |
public TvExtender setSuppressShowOverApps(boolean suppress) { |
| 12155 |
mSuppressShowOverApps = suppress; |
| 12156 |
return this; |
| 12157 |
} |
| 12158 |
|
| 12159 |
|
| 12160 |
|
| 12161 |
|
| 12162 |
|
| 12163 |
public boolean getSuppressShowOverApps() { |
| 12164 |
return mSuppressShowOverApps; |
| 12165 |
} |
| 12166 |
} |
| 12167 |
|
| 12168 |
|
| 12169 |
|
| 12170 |
|
| 12171 |
|
| 12172 |
|
| 12173 |
@Nullable |
| 12174 |
private static <T extends Parcelable> T[] getParcelableArrayFromBundle( |
| 12175 |
Bundle bundle, String key, Class<T> itemClass) { |
| 12176 |
final Parcelable[] array = bundle.getParcelableArray(key); |
| 12177 |
final Class<?> arrayClass = Array.newInstance(itemClass, 0).getClass(); |
| 12178 |
if (arrayClass.isInstance(array) || array == null) { |
| 12179 |
return (T[]) array; |
| 12180 |
} |
| 12181 |
final T[] typedArray = (T[]) Array.newInstance(itemClass, array.length); |
| 12182 |
for (int i = 0; i < array.length; i++) { |
| 12183 |
typedArray[i] = (T) array[i]; |
| 12184 |
} |
| 12185 |
bundle.putParcelableArray(key, typedArray); |
| 12186 |
return typedArray; |
| 12187 |
} |
| 12188 |
|
| 12189 |
private static class BuilderRemoteViews extends RemoteViews { |
| 12190 |
public BuilderRemoteViews(Parcel parcel) { |
| 12191 |
super(parcel); |
| 12192 |
} |
| 12193 |
|
| 12194 |
public BuilderRemoteViews(ApplicationInfo appInfo, int layoutId) { |
| 12195 |
super(appInfo, layoutId); |
| 12196 |
} |
| 12197 |
|
| 12198 |
@Override |
| 12199 |
public BuilderRemoteViews clone() { |
| 12200 |
Parcel p = Parcel.obtain(); |
| 12201 |
writeToParcel(p, 0); |
| 12202 |
p.setDataPosition(0); |
| 12203 |
BuilderRemoteViews brv = new BuilderRemoteViews(p); |
| 12204 |
p.recycle(); |
| 12205 |
return brv; |
| 12206 |
} |
| 12207 |
|
| 12208 |
|
| 12209 |
|
| 12210 |
|
| 12211 |
|
| 12212 |
|
| 12213 |
@Override |
| 12214 |
protected boolean shouldUseStaticFilter() { |
| 12215 |
return true; |
| 12216 |
} |
| 12217 |
} |
| 12218 |
|
| 12219 |
|
| 12220 |
|
| 12221 |
|
| 12222 |
private static class TemplateBindResult { |
| 12223 |
boolean mRightIconVisible; |
| 12224 |
float mRightIconWidthDp; |
| 12225 |
float mRightIconHeightDp; |
| 12226 |
|
| 12227 |
|
| 12228 |
|
| 12229 |
|
| 12230 |
|
| 12231 |
|
| 12232 |
|
| 12233 |
public final MarginSet mHeadingExtraMarginSet = new MarginSet(); |
| 12234 |
|
| 12235 |
|
| 12236 |
|
| 12237 |
|
| 12238 |
|
| 12239 |
|
| 12240 |
|
| 12241 |
public final MarginSet mHeadingFullMarginSet = new MarginSet(); |
| 12242 |
|
| 12243 |
|
| 12244 |
|
| 12245 |
|
| 12246 |
|
| 12247 |
|
| 12248 |
public final MarginSet mTitleMarginSet = new MarginSet(); |
| 12249 |
|
| 12250 |
public void setRightIconState(boolean visible, float widthDp, float heightDp, |
| 12251 |
float marginEndDpIfVisible, float expanderSizeDp) { |
| 12252 |
mRightIconVisible = visible; |
| 12253 |
mRightIconWidthDp = widthDp; |
| 12254 |
mRightIconHeightDp = heightDp; |
| 12255 |
mHeadingExtraMarginSet.setValues(0, marginEndDpIfVisible); |
| 12256 |
mHeadingFullMarginSet.setValues(expanderSizeDp, marginEndDpIfVisible + expanderSizeDp); |
| 12257 |
mTitleMarginSet.setValues(0, marginEndDpIfVisible + expanderSizeDp); |
| 12258 |
} |
| 12259 |
|
| 12260 |
|
| 12261 |
|
| 12262 |
|
| 12263 |
|
| 12264 |
|
| 12265 |
private class MarginSet { |
| 12266 |
private float mValueIfGone; |
| 12267 |
private float mValueIfVisible; |
| 12268 |
|
| 12269 |
public void setValues(float valueIfGone, float valueIfVisible) { |
| 12270 |
mValueIfGone = valueIfGone; |
| 12271 |
mValueIfVisible = valueIfVisible; |
| 12272 |
} |
| 12273 |
|
| 12274 |
public void applyToView(@NonNull RemoteViews views, @IdRes int viewId) { |
| 12275 |
applyToView(views, viewId, 0); |
| 12276 |
} |
| 12277 |
|
| 12278 |
public void applyToView(@NonNull RemoteViews views, @IdRes int viewId, |
| 12279 |
float extraMarginDp) { |
| 12280 |
final float marginEndDp = getDpValue() + extraMarginDp; |
| 12281 |
if (viewId == R.id.notification_header) { |
| 12282 |
views.setFloat(R.id.notification_header, |
| 12283 |
"setTopLineExtraMarginEndDp", marginEndDp); |
| 12284 |
} else if (viewId == R.id.text || viewId == R.id.big_text) { |
| 12285 |
if (mValueIfGone != 0) { |
| 12286 |
throw new RuntimeException("Programming error: `text` and `big_text` use " |
| 12287 |
+ "ImageFloatingTextView which can either show a margin or not; " |
| 12288 |
+ "thus mValueIfGone must be 0, but it was " + mValueIfGone); |
| 12289 |
} |
| 12290 |
|
| 12291 |
|
| 12292 |
views.setFloat(viewId, "setImageEndMarginDp", mValueIfVisible); |
| 12293 |
views.setBoolean(viewId, "setHasImage", mRightIconVisible); |
| 12294 |
|
| 12295 |
|
| 12296 |
|
| 12297 |
views.setViewLayoutMargin(viewId, RemoteViews.MARGIN_END, |
| 12298 |
extraMarginDp, TypedValue.COMPLEX_UNIT_DIP); |
| 12299 |
} else { |
| 12300 |
views.setViewLayoutMargin(viewId, RemoteViews.MARGIN_END, |
| 12301 |
marginEndDp, TypedValue.COMPLEX_UNIT_DIP); |
| 12302 |
} |
| 12303 |
if (mRightIconVisible) { |
| 12304 |
views.setIntTag(viewId, R.id.tag_margin_end_when_icon_visible, |
| 12305 |
TypedValue.createComplexDimension( |
| 12306 |
mValueIfVisible + extraMarginDp, TypedValue.COMPLEX_UNIT_DIP)); |
| 12307 |
views.setIntTag(viewId, R.id.tag_margin_end_when_icon_gone, |
| 12308 |
TypedValue.createComplexDimension( |
| 12309 |
mValueIfGone + extraMarginDp, TypedValue.COMPLEX_UNIT_DIP)); |
| 12310 |
} |
| 12311 |
} |
| 12312 |
|
| 12313 |
public float getDpValue() { |
| 12314 |
return mRightIconVisible ? mValueIfVisible : mValueIfGone; |
| 12315 |
} |
| 12316 |
} |
| 12317 |
} |
| 12318 |
|
| 12319 |
private static class StandardTemplateParams { |
| 12320 |
|
| 12321 |
|
| 12322 |
|
| 12323 |
|
| 12324 |
|
| 12325 |
|
| 12326 |
public static final int DECORATION_MINIMAL = 1; |
| 12327 |
|
| 12328 |
|
| 12329 |
|
| 12330 |
|
| 12331 |
|
| 12332 |
|
| 12333 |
|
| 12334 |
public static final int DECORATION_PARTIAL = 2; |
| 12335 |
|
| 12336 |
public static int VIEW_TYPE_UNSPECIFIED = 0; |
| 12337 |
public static int VIEW_TYPE_NORMAL = 1; |
| 12338 |
public static int VIEW_TYPE_BIG = 2; |
| 12339 |
public static int VIEW_TYPE_HEADS_UP = 3; |
| 12340 |
public static int VIEW_TYPE_MINIMIZED = 4; |
| 12341 |
public static int VIEW_TYPE_PUBLIC = 5; |
| 12342 |
public static int VIEW_TYPE_GROUP_HEADER = 6; |
| 12343 |
|
| 12344 |
int mViewType = VIEW_TYPE_UNSPECIFIED; |
| 12345 |
boolean mHeaderless; |
| 12346 |
boolean mHideAppName; |
| 12347 |
boolean mHideTitle; |
| 12348 |
boolean mHideSubText; |
| 12349 |
boolean mHideTime; |
| 12350 |
boolean mHideActions; |
| 12351 |
boolean mHideProgress; |
| 12352 |
boolean mHideSnoozeButton; |
| 12353 |
boolean mHideLeftIcon; |
| 12354 |
boolean mHideRightIcon; |
| 12355 |
Icon mPromotedPicture; |
| 12356 |
boolean mCallStyleActions; |
| 12357 |
boolean mAllowTextWithProgress; |
| 12358 |
int mTitleViewId; |
| 12359 |
int mTextViewId; |
| 12360 |
CharSequence title; |
| 12361 |
CharSequence text; |
| 12362 |
CharSequence headerTextSecondary; |
| 12363 |
CharSequence summaryText; |
| 12364 |
int maxRemoteInputHistory = Style.MAX_REMOTE_INPUT_HISTORY_LINES; |
| 12365 |
boolean allowColorization = true; |
| 12366 |
boolean mHighlightExpander = false; |
| 12367 |
|
| 12368 |
final StandardTemplateParams reset() { |
| 12369 |
mViewType = VIEW_TYPE_UNSPECIFIED; |
| 12370 |
mHeaderless = false; |
| 12371 |
mHideAppName = false; |
| 12372 |
mHideTitle = false; |
| 12373 |
mHideSubText = false; |
| 12374 |
mHideTime = false; |
| 12375 |
mHideActions = false; |
| 12376 |
mHideProgress = false; |
| 12377 |
mHideSnoozeButton = false; |
| 12378 |
mHideLeftIcon = false; |
| 12379 |
mHideRightIcon = false; |
| 12380 |
mPromotedPicture = null; |
| 12381 |
mCallStyleActions = false; |
| 12382 |
mAllowTextWithProgress = false; |
| 12383 |
mTitleViewId = R.id.title; |
| 12384 |
mTextViewId = R.id.text; |
| 12385 |
title = null; |
| 12386 |
text = null; |
| 12387 |
summaryText = null; |
| 12388 |
headerTextSecondary = null; |
| 12389 |
maxRemoteInputHistory = Style.MAX_REMOTE_INPUT_HISTORY_LINES; |
| 12390 |
allowColorization = true; |
| 12391 |
mHighlightExpander = false; |
| 12392 |
return this; |
| 12393 |
} |
| 12394 |
|
| 12395 |
final boolean hasTitle() { |
| 12396 |
return !TextUtils.isEmpty(title) && !mHideTitle; |
| 12397 |
} |
| 12398 |
|
| 12399 |
final StandardTemplateParams viewType(int viewType) { |
| 12400 |
mViewType = viewType; |
| 12401 |
return this; |
| 12402 |
} |
| 12403 |
|
| 12404 |
public StandardTemplateParams headerless(boolean headerless) { |
| 12405 |
mHeaderless = headerless; |
| 12406 |
return this; |
| 12407 |
} |
| 12408 |
|
| 12409 |
public StandardTemplateParams hideAppName(boolean hideAppName) { |
| 12410 |
mHideAppName = hideAppName; |
| 12411 |
return this; |
| 12412 |
} |
| 12413 |
|
| 12414 |
public StandardTemplateParams hideSubText(boolean hideSubText) { |
| 12415 |
mHideSubText = hideSubText; |
| 12416 |
return this; |
| 12417 |
} |
| 12418 |
|
| 12419 |
public StandardTemplateParams hideTime(boolean hideTime) { |
| 12420 |
mHideTime = hideTime; |
| 12421 |
return this; |
| 12422 |
} |
| 12423 |
|
| 12424 |
final StandardTemplateParams hideActions(boolean hideActions) { |
| 12425 |
this.mHideActions = hideActions; |
| 12426 |
return this; |
| 12427 |
} |
| 12428 |
|
| 12429 |
final StandardTemplateParams hideProgress(boolean hideProgress) { |
| 12430 |
this.mHideProgress = hideProgress; |
| 12431 |
return this; |
| 12432 |
} |
| 12433 |
|
| 12434 |
final StandardTemplateParams hideTitle(boolean hideTitle) { |
| 12435 |
this.mHideTitle = hideTitle; |
| 12436 |
return this; |
| 12437 |
} |
| 12438 |
|
| 12439 |
final StandardTemplateParams callStyleActions(boolean callStyleActions) { |
| 12440 |
this.mCallStyleActions = callStyleActions; |
| 12441 |
return this; |
| 12442 |
} |
| 12443 |
|
| 12444 |
final StandardTemplateParams allowTextWithProgress(boolean allowTextWithProgress) { |
| 12445 |
this.mAllowTextWithProgress = allowTextWithProgress; |
| 12446 |
return this; |
| 12447 |
} |
| 12448 |
|
| 12449 |
final StandardTemplateParams hideSnoozeButton(boolean hideSnoozeButton) { |
| 12450 |
this.mHideSnoozeButton = hideSnoozeButton; |
| 12451 |
return this; |
| 12452 |
} |
| 12453 |
|
| 12454 |
final StandardTemplateParams promotedPicture(Icon promotedPicture) { |
| 12455 |
this.mPromotedPicture = promotedPicture; |
| 12456 |
return this; |
| 12457 |
} |
| 12458 |
|
| 12459 |
public StandardTemplateParams titleViewId(int titleViewId) { |
| 12460 |
mTitleViewId = titleViewId; |
| 12461 |
return this; |
| 12462 |
} |
| 12463 |
|
| 12464 |
public StandardTemplateParams textViewId(int textViewId) { |
| 12465 |
mTextViewId = textViewId; |
| 12466 |
return this; |
| 12467 |
} |
| 12468 |
|
| 12469 |
final StandardTemplateParams title(CharSequence title) { |
| 12470 |
this.title = title; |
| 12471 |
return this; |
| 12472 |
} |
| 12473 |
|
| 12474 |
final StandardTemplateParams text(CharSequence text) { |
| 12475 |
this.text = text; |
| 12476 |
return this; |
| 12477 |
} |
| 12478 |
|
| 12479 |
final StandardTemplateParams summaryText(CharSequence text) { |
| 12480 |
this.summaryText = text; |
| 12481 |
return this; |
| 12482 |
} |
| 12483 |
|
| 12484 |
final StandardTemplateParams headerTextSecondary(CharSequence text) { |
| 12485 |
this.headerTextSecondary = text; |
| 12486 |
return this; |
| 12487 |
} |
| 12488 |
|
| 12489 |
|
| 12490 |
final StandardTemplateParams hideLeftIcon(boolean hideLeftIcon) { |
| 12491 |
this.mHideLeftIcon = hideLeftIcon; |
| 12492 |
return this; |
| 12493 |
} |
| 12494 |
|
| 12495 |
final StandardTemplateParams hideRightIcon(boolean hideRightIcon) { |
| 12496 |
this.mHideRightIcon = hideRightIcon; |
| 12497 |
return this; |
| 12498 |
} |
| 12499 |
|
| 12500 |
final StandardTemplateParams disallowColorization() { |
| 12501 |
this.allowColorization = false; |
| 12502 |
return this; |
| 12503 |
} |
| 12504 |
|
| 12505 |
final StandardTemplateParams highlightExpander(boolean highlight) { |
| 12506 |
this.mHighlightExpander = highlight; |
| 12507 |
return this; |
| 12508 |
} |
| 12509 |
|
| 12510 |
final StandardTemplateParams fillTextsFrom(Builder b) { |
| 12511 |
Bundle extras = b.mN.extras; |
| 12512 |
this.title = b.processLegacyText(extras.getCharSequence(EXTRA_TITLE)); |
| 12513 |
this.text = b.processLegacyText(extras.getCharSequence(EXTRA_TEXT)); |
| 12514 |
this.summaryText = extras.getCharSequence(EXTRA_SUB_TEXT); |
| 12515 |
return this; |
| 12516 |
} |
| 12517 |
|
| 12518 |
|
| 12519 |
|
| 12520 |
|
| 12521 |
|
| 12522 |
|
| 12523 |
public StandardTemplateParams setMaxRemoteInputHistory(int maxRemoteInputHistory) { |
| 12524 |
this.maxRemoteInputHistory = maxRemoteInputHistory; |
| 12525 |
return this; |
| 12526 |
} |
| 12527 |
|
| 12528 |
public StandardTemplateParams decorationType(int decorationType) { |
| 12529 |
hideTitle(true); |
| 12530 |
|
| 12531 |
|
| 12532 |
boolean hideOtherFields = decorationType <= DECORATION_MINIMAL; |
| 12533 |
hideLeftIcon(false); |
| 12534 |
hideRightIcon(hideOtherFields); |
| 12535 |
hideProgress(hideOtherFields); |
| 12536 |
hideActions(hideOtherFields); |
| 12537 |
return this; |
| 12538 |
} |
| 12539 |
} |
| 12540 |
|
| 12541 |
|
| 12542 |
|
| 12543 |
|
| 12544 |
|
| 12545 |
@VisibleForTesting |
| 12546 |
public static class Colors { |
| 12547 |
private int mPaletteIsForRawColor = COLOR_INVALID; |
| 12548 |
private boolean mPaletteIsForColorized = false; |
| 12549 |
private boolean mPaletteIsForNightMode = false; |
| 12550 |
|
| 12551 |
private int mBackgroundColor = COLOR_INVALID; |
| 12552 |
private int mProtectionColor = COLOR_INVALID; |
| 12553 |
private int mPrimaryTextColor = COLOR_INVALID; |
| 12554 |
private int mSecondaryTextColor = COLOR_INVALID; |
| 12555 |
private int mPrimaryAccentColor = COLOR_INVALID; |
| 12556 |
private int mSecondaryAccentColor = COLOR_INVALID; |
| 12557 |
private int mTertiaryAccentColor = COLOR_INVALID; |
| 12558 |
private int mOnAccentTextColor = COLOR_INVALID; |
| 12559 |
private int mErrorColor = COLOR_INVALID; |
| 12560 |
private int mContrastColor = COLOR_INVALID; |
| 12561 |
private int mRippleAlpha = 0x33; |
| 12562 |
|
| 12563 |
|
| 12564 |
|
| 12565 |
|
| 12566 |
|
| 12567 |
|
| 12568 |
|
| 12569 |
|
| 12570 |
|
| 12571 |
|
| 12572 |
|
| 12573 |
@Nullable |
| 12574 |
private static TypedArray obtainDayNightAttributes(@NonNull Context ctx, |
| 12575 |
@NonNull @StyleableRes int[] attrs) { |
| 12576 |
|
| 12577 |
if (ctx.getTheme() == null) { |
| 12578 |
return null; |
| 12579 |
} |
| 12580 |
Resources.Theme theme = new ContextThemeWrapper(ctx, |
| 12581 |
R.style.Theme_DeviceDefault_DayNight).getTheme(); |
| 12582 |
return theme.obtainStyledAttributes(attrs); |
| 12583 |
} |
| 12584 |
|
| 12585 |
|
| 12586 |
private static @ColorInt int getColor(@Nullable TypedArray ta, int index, |
| 12587 |
@ColorInt int defValue) { |
| 12588 |
return ta == null ? defValue : ta.getColor(index, defValue); |
| 12589 |
} |
| 12590 |
|
| 12591 |
|
| 12592 |
|
| 12593 |
|
| 12594 |
|
| 12595 |
|
| 12596 |
|
| 12597 |
|
| 12598 |
|
| 12599 |
|
| 12600 |
|
| 12601 |
|
| 12602 |
|
| 12603 |
public void resolvePalette(Context ctx, int rawColor, |
| 12604 |
boolean isColorized, boolean nightMode) { |
| 12605 |
if (mPaletteIsForRawColor == rawColor |
| 12606 |
&& mPaletteIsForColorized == isColorized |
| 12607 |
&& mPaletteIsForNightMode == nightMode) { |
| 12608 |
return; |
| 12609 |
} |
| 12610 |
mPaletteIsForRawColor = rawColor; |
| 12611 |
mPaletteIsForColorized = isColorized; |
| 12612 |
mPaletteIsForNightMode = nightMode; |
| 12613 |
|
| 12614 |
if (isColorized) { |
| 12615 |
if (rawColor == COLOR_DEFAULT) { |
| 12616 |
int[] attrs = {R.attr.colorAccentSecondary}; |
| 12617 |
try (TypedArray ta = obtainDayNightAttributes(ctx, attrs)) { |
| 12618 |
mBackgroundColor = getColor(ta, 0, Color.WHITE); |
| 12619 |
} |
| 12620 |
} else { |
| 12621 |
mBackgroundColor = rawColor; |
| 12622 |
} |
| 12623 |
mProtectionColor = COLOR_INVALID; |
| 12624 |
mPrimaryTextColor = ContrastColorUtil.findAlphaToMeetContrast( |
| 12625 |
ContrastColorUtil.resolvePrimaryColor(ctx, mBackgroundColor, nightMode), |
| 12626 |
mBackgroundColor, 4.5); |
| 12627 |
mSecondaryTextColor = ContrastColorUtil.findAlphaToMeetContrast( |
| 12628 |
ContrastColorUtil.resolveSecondaryColor(ctx, mBackgroundColor, nightMode), |
| 12629 |
mBackgroundColor, 4.5); |
| 12630 |
mContrastColor = mPrimaryTextColor; |
| 12631 |
mPrimaryAccentColor = mPrimaryTextColor; |
| 12632 |
mSecondaryAccentColor = mSecondaryTextColor; |
| 12633 |
mTertiaryAccentColor = flattenAlpha(mPrimaryTextColor, mBackgroundColor); |
| 12634 |
mOnAccentTextColor = mBackgroundColor; |
| 12635 |
mErrorColor = mPrimaryTextColor; |
| 12636 |
mRippleAlpha = 0x33; |
| 12637 |
} else { |
| 12638 |
int[] attrs = { |
| 12639 |
R.attr.colorSurface, |
| 12640 |
R.attr.colorBackgroundFloating, |
| 12641 |
R.attr.textColorPrimary, |
| 12642 |
R.attr.textColorSecondary, |
| 12643 |
R.attr.colorAccent, |
| 12644 |
R.attr.colorAccentSecondary, |
| 12645 |
R.attr.colorAccentTertiary, |
| 12646 |
R.attr.textColorOnAccent, |
| 12647 |
R.attr.colorError, |
| 12648 |
R.attr.colorControlHighlight |
| 12649 |
}; |
| 12650 |
try (TypedArray ta = obtainDayNightAttributes(ctx, attrs)) { |
| 12651 |
mBackgroundColor = getColor(ta, 0, nightMode ? Color.BLACK : Color.WHITE); |
| 12652 |
mProtectionColor = getColor(ta, 1, COLOR_INVALID); |
| 12653 |
mPrimaryTextColor = getColor(ta, 2, COLOR_INVALID); |
| 12654 |
mSecondaryTextColor = getColor(ta, 3, COLOR_INVALID); |
| 12655 |
mPrimaryAccentColor = getColor(ta, 4, COLOR_INVALID); |
| 12656 |
mSecondaryAccentColor = getColor(ta, 5, COLOR_INVALID); |
| 12657 |
mTertiaryAccentColor = getColor(ta, 6, COLOR_INVALID); |
| 12658 |
mOnAccentTextColor = getColor(ta, 7, COLOR_INVALID); |
| 12659 |
mErrorColor = getColor(ta, 8, COLOR_INVALID); |
| 12660 |
mRippleAlpha = Color.alpha(getColor(ta, 9, 0x33ffffff)); |
| 12661 |
} |
| 12662 |
mContrastColor = calculateContrastColor(ctx, rawColor, mPrimaryAccentColor, |
| 12663 |
mBackgroundColor, nightMode); |
| 12664 |
|
| 12665 |
|
| 12666 |
if (mPrimaryTextColor == COLOR_INVALID) { |
| 12667 |
mPrimaryTextColor = ContrastColorUtil.resolvePrimaryColor( |
| 12668 |
ctx, mBackgroundColor, nightMode); |
| 12669 |
} |
| 12670 |
if (mSecondaryTextColor == COLOR_INVALID) { |
| 12671 |
mSecondaryTextColor = ContrastColorUtil.resolveSecondaryColor( |
| 12672 |
ctx, mBackgroundColor, nightMode); |
| 12673 |
} |
| 12674 |
if (mPrimaryAccentColor == COLOR_INVALID) { |
| 12675 |
mPrimaryAccentColor = mContrastColor; |
| 12676 |
} |
| 12677 |
if (mSecondaryAccentColor == COLOR_INVALID) { |
| 12678 |
mSecondaryAccentColor = mContrastColor; |
| 12679 |
} |
| 12680 |
if (mTertiaryAccentColor == COLOR_INVALID) { |
| 12681 |
mTertiaryAccentColor = mContrastColor; |
| 12682 |
} |
| 12683 |
if (mOnAccentTextColor == COLOR_INVALID) { |
| 12684 |
mOnAccentTextColor = ColorUtils.setAlphaComponent( |
| 12685 |
ContrastColorUtil.resolvePrimaryColor( |
| 12686 |
ctx, mTertiaryAccentColor, nightMode), 0xFF); |
| 12687 |
} |
| 12688 |
if (mErrorColor == COLOR_INVALID) { |
| 12689 |
mErrorColor = mPrimaryTextColor; |
| 12690 |
} |
| 12691 |
} |
| 12692 |
|
| 12693 |
if (mProtectionColor == COLOR_INVALID) { |
| 12694 |
mProtectionColor = ColorUtils.blendARGB(mPrimaryTextColor, mBackgroundColor, 0.8f); |
| 12695 |
} |
| 12696 |
} |
| 12697 |
|
| 12698 |
|
| 12699 |
private static @ColorInt int calculateContrastColor(Context ctx, @ColorInt int rawColor, |
| 12700 |
@ColorInt int accentColor, @ColorInt int backgroundColor, boolean nightMode) { |
| 12701 |
int color; |
| 12702 |
if (rawColor == COLOR_DEFAULT) { |
| 12703 |
color = accentColor; |
| 12704 |
if (color == COLOR_INVALID) { |
| 12705 |
color = ContrastColorUtil.resolveDefaultColor(ctx, backgroundColor, nightMode); |
| 12706 |
} |
| 12707 |
} else { |
| 12708 |
color = ContrastColorUtil.resolveContrastColor(ctx, rawColor, backgroundColor, |
| 12709 |
nightMode); |
| 12710 |
} |
| 12711 |
return flattenAlpha(color, backgroundColor); |
| 12712 |
} |
| 12713 |
|
| 12714 |
|
| 12715 |
private static @ColorInt int flattenAlpha(@ColorInt int color, @ColorInt int background) { |
| 12716 |
return Color.alpha(color) == 0xff ? color |
| 12717 |
: ContrastColorUtil.compositeColors(color, background); |
| 12718 |
} |
| 12719 |
|
| 12720 |
|
| 12721 |
public @ColorInt int getBackgroundColor() { |
| 12722 |
return mBackgroundColor; |
| 12723 |
} |
| 12724 |
|
| 12725 |
|
| 12726 |
|
| 12727 |
|
| 12728 |
|
| 12729 |
public @ColorInt int getProtectionColor() { |
| 12730 |
return mProtectionColor; |
| 12731 |
} |
| 12732 |
|
| 12733 |
|
| 12734 |
public @ColorInt int getPrimaryTextColor() { |
| 12735 |
return mPrimaryTextColor; |
| 12736 |
} |
| 12737 |
|
| 12738 |
|
| 12739 |
public @ColorInt int getSecondaryTextColor() { |
| 12740 |
return mSecondaryTextColor; |
| 12741 |
} |
| 12742 |
|
| 12743 |
|
| 12744 |
public @ColorInt int getPrimaryAccentColor() { |
| 12745 |
return mPrimaryAccentColor; |
| 12746 |
} |
| 12747 |
|
| 12748 |
|
| 12749 |
public @ColorInt int getSecondaryAccentColor() { |
| 12750 |
return mSecondaryAccentColor; |
| 12751 |
} |
| 12752 |
|
| 12753 |
|
| 12754 |
public @ColorInt int getTertiaryAccentColor() { |
| 12755 |
return mTertiaryAccentColor; |
| 12756 |
} |
| 12757 |
|
| 12758 |
|
| 12759 |
public @ColorInt int getOnAccentTextColor() { |
| 12760 |
return mOnAccentTextColor; |
| 12761 |
} |
| 12762 |
|
| 12763 |
|
| 12764 |
|
| 12765 |
|
| 12766 |
|
| 12767 |
public @ColorInt int getContrastColor() { |
| 12768 |
return mContrastColor; |
| 12769 |
} |
| 12770 |
|
| 12771 |
|
| 12772 |
public @ColorInt int getErrorColor() { |
| 12773 |
return mErrorColor; |
| 12774 |
} |
| 12775 |
|
| 12776 |
|
| 12777 |
public int getRippleAlpha() { |
| 12778 |
return mRippleAlpha; |
| 12779 |
} |
| 12780 |
} |
| 12781 |
} |