Inline v7 NotificationCompatImplApi21+24
Remove the need for separate NotificationCompatImplApi21
and NotificationCompatImplApi24 classes in v7
NotificationCompat by inlining the APIs.
Test: Manual inspection
BUG: 28983951
Change-Id: I4604e07dbda0d724b35972eb25504c14fb85cca2
diff --git a/v7/appcompat/src/android/support/v7/app/NotificationCompat.java b/v7/appcompat/src/android/support/v7/app/NotificationCompat.java
index ee403fa..0ebe1ea 100644
--- a/v7/appcompat/src/android/support/v7/app/NotificationCompat.java
+++ b/v7/appcompat/src/android/support/v7/app/NotificationCompat.java
@@ -21,10 +21,12 @@
import android.app.Notification;
import android.app.PendingIntent;
import android.content.Context;
+import android.media.session.MediaSession;
import android.os.Build;
import android.os.Bundle;
import android.os.IBinder;
import android.os.Parcel;
+import android.support.annotation.RequiresApi;
import android.support.annotation.RestrictTo;
import android.support.v4.app.BundleCompat;
import android.support.v4.app.NotificationBuilderWithBuilderAccessor;
@@ -204,14 +206,24 @@
@Override
public void apply(NotificationBuilderWithBuilderAccessor builder) {
if (Build.VERSION.SDK_INT >= 21) {
- NotificationCompatImpl21.addMediaStyle(builder,
- mActionsToShowInCompact,
- mToken != null ? mToken.getToken() : null);
+ builder.getBuilder().setStyle(
+ fillInMediaStyle(new Notification.MediaStyle()));
} else if (mShowCancelButton) {
builder.getBuilder().setOngoing(true);
}
}
+ @RequiresApi(21)
+ Notification.MediaStyle fillInMediaStyle(Notification.MediaStyle style) {
+ if (mActionsToShowInCompact != null) {
+ style.setShowActionsInCompactView(mActionsToShowInCompact);
+ }
+ if (mToken != null) {
+ style.setMediaSession((MediaSession.Token) mToken.getToken());
+ }
+ return style;
+ }
+
/**
* @hide
*/
@@ -301,7 +313,7 @@
@Override
public void apply(NotificationBuilderWithBuilderAccessor builder) {
if (Build.VERSION.SDK_INT >= 24) {
- NotificationCompatImpl24.addDecoratedCustomViewStyle(builder);
+ builder.getBuilder().setStyle(new Notification.DecoratedCustomViewStyle());
}
}
@@ -421,9 +433,8 @@
@Override
public void apply(NotificationBuilderWithBuilderAccessor builder) {
if (Build.VERSION.SDK_INT >= 24) {
- NotificationCompatImpl24.addDecoratedMediaCustomViewStyle(builder,
- mActionsToShowInCompact,
- mToken != null ? mToken.getToken() : null);
+ builder.getBuilder().setStyle(
+ fillInMediaStyle(new Notification.DecoratedMediaCustomViewStyle()));
} else {
super.apply(builder);
}
diff --git a/v7/appcompat/src/android/support/v7/app/NotificationCompatImpl21.java b/v7/appcompat/src/android/support/v7/app/NotificationCompatImpl21.java
deleted file mode 100644
index 2a4bf7b..0000000
--- a/v7/appcompat/src/android/support/v7/app/NotificationCompatImpl21.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (C) 2015 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.support.v7.app;
-
-import android.app.Notification;
-import android.media.session.MediaSession;
-import android.support.annotation.RequiresApi;
-import android.support.v4.app.NotificationBuilderWithBuilderAccessor;
-
-@RequiresApi(21)
-class NotificationCompatImpl21 {
-
- public static void addMediaStyle(NotificationBuilderWithBuilderAccessor b,
- int[] actionsToShowInCompact,
- Object token) {
- Notification.MediaStyle style = new Notification.MediaStyle(b.getBuilder());
- if (actionsToShowInCompact != null) {
- style.setShowActionsInCompactView(actionsToShowInCompact);
- }
- if (token != null) {
- style.setMediaSession((MediaSession.Token) token);
- }
- }
-}
diff --git a/v7/appcompat/src/android/support/v7/app/NotificationCompatImpl24.java b/v7/appcompat/src/android/support/v7/app/NotificationCompatImpl24.java
deleted file mode 100644
index cc09bb5..0000000
--- a/v7/appcompat/src/android/support/v7/app/NotificationCompatImpl24.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License
- */
-
-package android.support.v7.app;
-
-import android.app.Notification;
-import android.media.session.MediaSession;
-import android.support.annotation.RequiresApi;
-import android.support.v4.app.NotificationBuilderWithBuilderAccessor;
-
-@RequiresApi(24)
-class NotificationCompatImpl24 {
-
- public static void addDecoratedCustomViewStyle(NotificationBuilderWithBuilderAccessor b) {
- Notification.Builder builder = b.getBuilder();
- builder.setStyle(new Notification.DecoratedCustomViewStyle());
- }
-
- public static void addDecoratedMediaCustomViewStyle(NotificationBuilderWithBuilderAccessor b,
- int[] actionsToShowInCompact,
- Object token) {
- Notification.Builder builder = b.getBuilder();
- Notification.DecoratedMediaCustomViewStyle style =
- new Notification.DecoratedMediaCustomViewStyle();
- if (actionsToShowInCompact != null) {
- style.setShowActionsInCompactView(actionsToShowInCompact);
- }
- if (token != null) {
- style.setMediaSession((MediaSession.Token) token);
- }
- builder.setStyle(style);
- }
-}