Clean up notification builders. Part 3
Make NotificationCompatApi21.Builder extend NotificationCompatApi21.Builder.
Bug: 37214421
Test: ./gradlew assembleDebug
Change-Id: Ia01a760cc85c057f470de630ca94d2a1fbe109f6
diff --git a/compat/api20/android/support/v4/app/NotificationCompatApi20.java b/compat/api20/android/support/v4/app/NotificationCompatApi20.java
index f646b8f..3eaef48 100644
--- a/compat/api20/android/support/v4/app/NotificationCompatApi20.java
+++ b/compat/api20/android/support/v4/app/NotificationCompatApi20.java
@@ -39,11 +39,12 @@
class NotificationCompatApi20 {
public static class Builder implements NotificationBuilderWithBuilderAccessor,
NotificationBuilderWithActions {
- private Notification.Builder b;
+ protected Notification.Builder mBuilder;
+ protected int mGroupAlertBehavior;
+ protected RemoteViews mContentView;
+ protected RemoteViews mBigContentView;
+
private Bundle mExtras;
- private RemoteViews mContentView;
- private RemoteViews mBigContentView;
- private int mGroupAlertBehavior;
public Builder(Context context, Notification n,
CharSequence contentTitle, CharSequence contentText, CharSequence contentInfo,
@@ -53,8 +54,8 @@
boolean useChronometer, int priority, CharSequence subText, boolean localOnly,
ArrayList<String> people, Bundle extras, String groupKey, boolean groupSummary,
String sortKey, RemoteViews contentView, RemoteViews bigContentView,
- int groupAlertBehavior) {
- b = new Notification.Builder(context)
+ int groupAlertBehavior, String channelId) {
+ mBuilder = newBuilder(context, channelId)
.setWhen(n.when)
.setShowWhen(showWhen)
.setSmallIcon(n.icon, n.iconLevel)
@@ -99,18 +100,18 @@
@Override
public void addAction(NotificationCompatBase.Action action) {
- NotificationCompatApi20.addAction(b, action);
+ NotificationCompatApi20.addAction(mBuilder, action);
}
@Override
public Notification.Builder getBuilder() {
- return b;
+ return mBuilder;
}
@Override
public Notification build() {
- b.setExtras(mExtras);
- Notification notification = b.build();
+ mBuilder.setExtras(mExtras);
+ Notification notification = mBuilder.build();
if (mContentView != null) {
notification.contentView = mContentView;
}
@@ -136,7 +137,11 @@
return notification;
}
- private void removeSoundAndVibration(Notification notification) {
+ protected Notification.Builder newBuilder(Context context, String channelId) {
+ return new Notification.Builder(context);
+ }
+
+ protected void removeSoundAndVibration(Notification notification) {
notification.sound = null;
notification.vibrate = null;
notification.defaults &= ~DEFAULT_SOUND;
diff --git a/compat/api21/android/support/v4/app/NotificationCompatApi21.java b/compat/api21/android/support/v4/app/NotificationCompatApi21.java
index 023a219..d7cfdc4 100644
--- a/compat/api21/android/support/v4/app/NotificationCompatApi21.java
+++ b/compat/api21/android/support/v4/app/NotificationCompatApi21.java
@@ -16,8 +16,6 @@
package android.support.v4.app;
-import static android.support.v4.app.NotificationCompat.DEFAULT_SOUND;
-import static android.support.v4.app.NotificationCompat.DEFAULT_VIBRATE;
import static android.support.v4.app.NotificationCompat.FLAG_GROUP_SUMMARY;
import static android.support.v4.app.NotificationCompat.GROUP_ALERT_ALL;
import static android.support.v4.app.NotificationCompat.GROUP_ALERT_CHILDREN;
@@ -45,14 +43,8 @@
private static final String KEY_PARTICIPANTS = "participants";
private static final String KEY_TIMESTAMP = "timestamp";
- public static class Builder implements NotificationBuilderWithBuilderAccessor,
- NotificationBuilderWithActions {
- protected Notification.Builder mBuilder;
- protected int mGroupAlertBehavior;
-
+ public static class Builder extends NotificationCompatApi20.Builder {
private Bundle mExtras;
- private RemoteViews mContentView;
- private RemoteViews mBigContentView;
private RemoteViews mHeadsUpContentView;
public Builder(Context context, Notification n,
@@ -65,37 +57,12 @@
int visibility, Notification publicVersion, String groupKey, boolean groupSummary,
String sortKey, RemoteViews contentView, RemoteViews bigContentView,
RemoteViews headsUpContentView, int groupAlertBehavior, String channelId) {
- mBuilder = newBuilder(context, channelId)
- .setWhen(n.when)
- .setShowWhen(showWhen)
- .setSmallIcon(n.icon, n.iconLevel)
- .setContent(n.contentView)
- .setTicker(n.tickerText, tickerView)
- .setSound(n.sound, n.audioStreamType)
- .setVibrate(n.vibrate)
- .setLights(n.ledARGB, n.ledOnMS, n.ledOffMS)
- .setOngoing((n.flags & Notification.FLAG_ONGOING_EVENT) != 0)
- .setOnlyAlertOnce((n.flags & Notification.FLAG_ONLY_ALERT_ONCE) != 0)
- .setAutoCancel((n.flags & Notification.FLAG_AUTO_CANCEL) != 0)
- .setDefaults(n.defaults)
- .setContentTitle(contentTitle)
- .setContentText(contentText)
- .setSubText(subText)
- .setContentInfo(contentInfo)
- .setContentIntent(contentIntent)
- .setDeleteIntent(n.deleteIntent)
- .setFullScreenIntent(fullScreenIntent,
- (n.flags & Notification.FLAG_HIGH_PRIORITY) != 0)
- .setLargeIcon(largeIcon)
- .setNumber(number)
- .setUsesChronometer(useChronometer)
- .setPriority(priority)
- .setProgress(progressMax, progress, progressIndeterminate)
- .setLocalOnly(localOnly)
- .setGroup(groupKey)
- .setGroupSummary(groupSummary)
- .setSortKey(sortKey)
- .setCategory(category)
+ super(context, n, contentTitle, contentText, contentInfo, tickerView, number,
+ contentIntent, fullScreenIntent, largeIcon, progressMax, progress,
+ progressIndeterminate, showWhen, useChronometer, priority, subText, localOnly,
+ people, extras, groupKey, groupSummary, sortKey, contentView, bigContentView,
+ groupAlertBehavior, channelId);
+ mBuilder.setCategory(category)
.setColor(color)
.setVisibility(visibility)
.setPublicVersion(publicVersion);
@@ -106,20 +73,7 @@
for (String person: people) {
mBuilder.addPerson(person);
}
- mContentView = contentView;
- mBigContentView = bigContentView;
mHeadsUpContentView = headsUpContentView;
- mGroupAlertBehavior = groupAlertBehavior;
- }
-
- @Override
- public void addAction(NotificationCompatBase.Action action) {
- NotificationCompatApi20.addAction(mBuilder, action);
- }
-
- @Override
- public Notification.Builder getBuilder() {
- return mBuilder;
}
@Override
@@ -152,17 +106,6 @@
}
return notification;
}
-
- protected Notification.Builder newBuilder(Context context, String channelId) {
- return new Notification.Builder(context);
- }
-
- protected void removeSoundAndVibration(Notification notification) {
- notification.sound = null;
- notification.vibrate = null;
- notification.defaults &= ~DEFAULT_SOUND;
- notification.defaults &= ~DEFAULT_VIBRATE;
- }
}
static Bundle getBundleForUnreadConversation(NotificationCompatBase.UnreadConversation uc) {
diff --git a/compat/java/android/support/v4/app/NotificationCompat.java b/compat/java/android/support/v4/app/NotificationCompat.java
index 9564676..a23813b 100644
--- a/compat/java/android/support/v4/app/NotificationCompat.java
+++ b/compat/java/android/support/v4/app/NotificationCompat.java
@@ -802,7 +802,7 @@
b.mProgressMax, b.mProgress, b.mProgressIndeterminate, b.mShowWhen,
b.mUseChronometer, b.mPriority, b.mSubText, b.mLocalOnly, b.mPeople, b.mExtras,
b.mGroupKey, b.mGroupSummary, b.mSortKey, b.mContentView, b.mBigContentView,
- b.mGroupAlertBehavior);
+ b.mGroupAlertBehavior, null);
addActionsToBuilder(builder, b.mActions);
if (b.mStyle != null) {
b.mStyle.apply(builder);