Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.notifications; | 5 package org.chromium.chrome.browser.notifications; |
| 6 | 6 |
| 7 import android.app.Notification; | 7 import android.app.Notification; |
| 8 import android.app.PendingIntent; | 8 import android.app.PendingIntent; |
| 9 import android.content.Context; | 9 import android.content.Context; |
| 10 import android.graphics.Bitmap; | 10 import android.graphics.Bitmap; |
| 11 import android.graphics.drawable.Icon; | |
| 11 import android.support.v4.app.NotificationCompat; | 12 import android.support.v4.app.NotificationCompat; |
| 13 import android.widget.RemoteViews; | |
| 12 | 14 |
| 13 /** | 15 /** |
| 14 * Wraps a NotificationCompat.Builder object. | 16 * Wraps a NotificationCompat.Builder object. |
| 15 * Created by awdf on 2/16/17. | 17 * Created by awdf on 2/16/17. |
| 16 */ | 18 */ |
| 17 public class NotificationCompatBuilder implements ChromeNotificationBuilder { | 19 public class NotificationCompatBuilder implements ChromeNotificationBuilder { |
| 18 private final NotificationCompat.Builder mBuilder; | 20 private final NotificationCompat.Builder mBuilder; |
| 19 | 21 |
| 20 public NotificationCompatBuilder(Context context) { | 22 public NotificationCompatBuilder(Context context) { |
| 21 mBuilder = new NotificationCompat.Builder(context); | 23 mBuilder = new NotificationCompat.Builder(context); |
| 22 } | 24 } |
| 23 | 25 |
| 24 @Override | 26 @Override |
| 25 public ChromeNotificationBuilder setAutoCancel(boolean autoCancel) { | 27 public ChromeNotificationBuilder setAutoCancel(boolean autoCancel) { |
| 26 mBuilder.setAutoCancel(autoCancel); | 28 mBuilder.setAutoCancel(autoCancel); |
| 27 return this; | 29 return this; |
| 28 } | 30 } |
| 29 | 31 |
| 30 @Override | 32 @Override |
| 31 public ChromeNotificationBuilder setContentIntent(PendingIntent contentInten t) { | 33 public ChromeNotificationBuilder setContentIntent(PendingIntent contentInten t) { |
| 32 mBuilder.setContentIntent(contentIntent); | 34 mBuilder.setContentIntent(contentIntent); |
| 33 return this; | 35 return this; |
| 34 } | 36 } |
| 35 | 37 |
| 36 @Override | 38 @Override |
| 37 public ChromeNotificationBuilder setContentTitle(String title) { | 39 public ChromeNotificationBuilder setContentTitle(CharSequence title) { |
| 38 mBuilder.setContentTitle(title); | 40 mBuilder.setContentTitle(title); |
| 39 return this; | 41 return this; |
| 40 } | 42 } |
| 41 | 43 |
| 42 @Override | 44 @Override |
| 43 public ChromeNotificationBuilder setContentText(String text) { | 45 public ChromeNotificationBuilder setContentText(CharSequence text) { |
| 44 mBuilder.setContentText(text); | 46 mBuilder.setContentText(text); |
| 45 return this; | 47 return this; |
| 46 } | 48 } |
| 47 | 49 |
| 48 @Override | 50 @Override |
| 49 public ChromeNotificationBuilder setSmallIcon(int icon) { | 51 public ChromeNotificationBuilder setSmallIcon(int icon) { |
| 50 mBuilder.setSmallIcon(icon); | 52 mBuilder.setSmallIcon(icon); |
| 51 return this; | 53 return this; |
| 52 } | 54 } |
| 53 | 55 |
| 54 @Override | 56 @Override |
| 55 public ChromeNotificationBuilder setTicker(String text) { | 57 public ChromeNotificationBuilder setSmallIcon(Icon icon) { |
| 58 return this; | |
| 59 } | |
| 60 | |
| 61 @Override | |
| 62 public ChromeNotificationBuilder setTicker(CharSequence text) { | |
| 56 mBuilder.setTicker(text); | 63 mBuilder.setTicker(text); |
| 57 return this; | 64 return this; |
| 58 } | 65 } |
| 59 | 66 |
| 60 @Override | 67 @Override |
| 61 public ChromeNotificationBuilder setLocalOnly(boolean localOnly) { | 68 public ChromeNotificationBuilder setLocalOnly(boolean localOnly) { |
| 62 mBuilder.setLocalOnly(localOnly); | 69 mBuilder.setLocalOnly(localOnly); |
| 63 return this; | 70 return this; |
| 64 } | 71 } |
| 65 | 72 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 81 return this; | 88 return this; |
| 82 } | 89 } |
| 83 | 90 |
| 84 @Override | 91 @Override |
| 85 public ChromeNotificationBuilder setShowWhen(boolean showWhen) { | 92 public ChromeNotificationBuilder setShowWhen(boolean showWhen) { |
| 86 mBuilder.setShowWhen(showWhen); | 93 mBuilder.setShowWhen(showWhen); |
| 87 return this; | 94 return this; |
| 88 } | 95 } |
| 89 | 96 |
| 90 @Override | 97 @Override |
| 91 public ChromeNotificationBuilder addAction(int icon, String title, PendingIn tent intent) { | 98 public ChromeNotificationBuilder addAction(int icon, CharSequence title, Pen dingIntent intent) { |
| 92 mBuilder.addAction(icon, title, intent); | 99 mBuilder.addAction(icon, title, intent); |
| 93 return this; | 100 return this; |
| 94 } | 101 } |
| 95 | 102 |
| 96 @Override | 103 @Override |
| 104 public ChromeNotificationBuilder addAction(Notification.Action action) { | |
| 105 return this; | |
| 106 } | |
| 107 | |
| 108 @Override | |
| 97 public ChromeNotificationBuilder setDeleteIntent(PendingIntent intent) { | 109 public ChromeNotificationBuilder setDeleteIntent(PendingIntent intent) { |
| 98 mBuilder.setDeleteIntent(intent); | 110 mBuilder.setDeleteIntent(intent); |
| 99 return this; | 111 return this; |
| 100 } | 112 } |
| 101 | 113 |
| 102 @Override | 114 @Override |
| 103 public ChromeNotificationBuilder setPriority(int pri) { | 115 public ChromeNotificationBuilder setPriority(int pri) { |
| 104 mBuilder.setPriority(pri); | 116 mBuilder.setPriority(pri); |
| 105 return this; | 117 return this; |
| 106 } | 118 } |
| 107 | 119 |
| 108 @Override | 120 @Override |
| 109 public ChromeNotificationBuilder setProgress(int max, int percentage, boolea n indeterminate) { | 121 public ChromeNotificationBuilder setProgress(int max, int percentage, boolea n indeterminate) { |
| 110 mBuilder.setProgress(max, percentage, indeterminate); | 122 mBuilder.setProgress(max, percentage, indeterminate); |
| 111 return this; | 123 return this; |
| 112 } | 124 } |
| 113 | 125 |
| 114 @Override | 126 @Override |
| 115 public ChromeNotificationBuilder setSubText(String text) { | 127 public ChromeNotificationBuilder setSubText(CharSequence text) { |
| 116 mBuilder.setSubText(text); | 128 mBuilder.setSubText(text); |
| 117 return this; | 129 return this; |
| 118 } | 130 } |
| 119 | 131 |
| 120 @Override | 132 @Override |
| 121 public ChromeNotificationBuilder setContentInfo(String info) { | 133 public ChromeNotificationBuilder setContentInfo(String info) { |
| 122 mBuilder.setContentInfo(info); | 134 mBuilder.setContentInfo(info); |
| 123 return this; | 135 return this; |
| 124 } | 136 } |
| 125 | 137 |
| 126 @Override | 138 @Override |
| 127 public ChromeNotificationBuilder setWhen(long time) { | 139 public ChromeNotificationBuilder setWhen(long time) { |
| 128 mBuilder.setWhen(time); | 140 mBuilder.setWhen(time); |
| 129 return this; | 141 return this; |
| 130 } | 142 } |
| 131 | 143 |
| 132 @Override | 144 @Override |
| 133 public ChromeNotificationBuilder setLargeIcon(Bitmap icon) { | 145 public ChromeNotificationBuilder setLargeIcon(Bitmap icon) { |
| 134 mBuilder.setLargeIcon(icon); | 146 mBuilder.setLargeIcon(icon); |
| 135 return this; | 147 return this; |
| 136 } | 148 } |
| 137 | 149 |
| 138 @Override | 150 @Override |
| 139 public ChromeNotificationBuilder setVibrate(long[] vibratePattern) { | 151 public ChromeNotificationBuilder setVibrate(long[] vibratePattern) { |
| 140 mBuilder.setVibrate(vibratePattern); | 152 mBuilder.setVibrate(vibratePattern); |
| 141 return this; | 153 return this; |
| 142 } | 154 } |
| 143 | 155 |
| 144 @Override | 156 @Override |
| 157 public ChromeNotificationBuilder setDefaults(int defaults) { | |
| 158 mBuilder.setDefaults(defaults); | |
| 159 return this; | |
| 160 } | |
| 161 | |
| 162 public ChromeNotificationBuilder setOnlyAlertOnce(boolean onlyAlertOnce) { | |
| 163 mBuilder.setOnlyAlertOnce(onlyAlertOnce); | |
| 164 return this; | |
| 165 } | |
| 166 | |
| 167 @Override | |
| 168 public ChromeNotificationBuilder setPublicVersion(Notification publicNotific ation) { | |
| 169 mBuilder.setPublicVersion(publicNotification); | |
| 170 return this; | |
| 171 } | |
| 172 | |
| 173 @Override | |
| 174 public ChromeNotificationBuilder setContent(RemoteViews views) { | |
| 175 mBuilder.setCustomContentView(views); | |
| 176 return this; | |
| 177 } | |
| 178 | |
| 179 @Override | |
| 180 public ChromeNotificationBuilder setStyle(Notification.BigPictureStyle style ) { | |
| 181 return this; | |
|
Peter Beverloo
2017/02/20 01:10:20
Maybe "assert false; // unused" or something to c
awdf
2017/02/24 17:37:30
Done, and in the other places it where it no-ops.
| |
| 182 } | |
| 183 | |
| 184 @Override | |
| 185 public ChromeNotificationBuilder setStyle(Notification.BigTextStyle bigTextS tyle) { | |
| 186 return this; | |
| 187 } | |
| 188 | |
| 189 @Override | |
| 190 public Notification buildWithBigContentView(RemoteViews view) { | |
| 191 return mBuilder.setCustomBigContentView(view).build(); | |
| 192 } | |
| 193 | |
| 194 @Override | |
| 145 public Notification buildWithBigTextStyle(String bigText) { | 195 public Notification buildWithBigTextStyle(String bigText) { |
| 146 NotificationCompat.BigTextStyle bigTextStyle = | 196 NotificationCompat.BigTextStyle bigTextStyle = |
| 147 new NotificationCompat.BigTextStyle(mBuilder); | 197 new NotificationCompat.BigTextStyle(mBuilder); |
| 148 bigTextStyle.bigText(bigText); | 198 bigTextStyle.bigText(bigText); |
| 149 return bigTextStyle.build(); | 199 return bigTextStyle.build(); |
| 150 } | 200 } |
| 151 | 201 |
| 152 @Override | 202 @Override |
| 153 public Notification build() { | 203 public Notification build() { |
| 154 return mBuilder.build(); | 204 return mBuilder.build(); |
| 155 } | 205 } |
| 156 } | 206 } |
| OLD | NEW |