From 36829428f6a8bdaf9973187b82880e79915efa8c Mon Sep 17 00:00:00 2001 From: MARTINI1 Date: Sat, 14 Oct 2017 19:36:09 +0200 Subject: [PATCH 1/9] added notification with nougat style and optimized layouts with relativelayout --- .../GoIVNotificationManager.java | 102 ++++++++++++----- .../layout/notification_pokefly_paused.xml | 76 +++++++------ .../notification_pokefly_paused_expanded.xml | 102 ++++++++--------- .../layout/notification_pokefly_started.xml | 77 +++++++------ .../notification_pokefly_started_expanded.xml | 103 ++++++++---------- app/src/main/res/values-v24/dimens.xml | 3 +- app/src/main/res/values/dimens.xml | 1 + 7 files changed, 251 insertions(+), 213 deletions(-) diff --git a/app/src/main/java/com/kamron/pogoiv/pokeflycomponents/GoIVNotificationManager.java b/app/src/main/java/com/kamron/pogoiv/pokeflycomponents/GoIVNotificationManager.java index 0c32be786..ec242baa8 100644 --- a/app/src/main/java/com/kamron/pogoiv/pokeflycomponents/GoIVNotificationManager.java +++ b/app/src/main/java/com/kamron/pogoiv/pokeflycomponents/GoIVNotificationManager.java @@ -6,6 +6,7 @@ import android.app.PendingIntent; import android.content.Context; import android.content.Intent; +import android.os.Build; import android.os.Handler; import android.os.Looper; import android.support.v7.app.NotificationCompat; @@ -73,22 +74,44 @@ public void showPausedNotification() { contentBigView.setOnClickPendingIntent(R.id.start, startServicePendingIntent); // Build notification - Notification notification = new NotificationCompat.Builder(pokefly) - .setSmallIcon(R.drawable.notification_icon) - .setContentTitle(pokefly.getString(R.string.notification_title_goiv_stopped)) - .setContentText(pokefly.getString(R.string.notification_title_tap_to_open)) - .setColor(pokefly.getColorC(R.color.colorAccent)) - .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) - .setPriority(NotificationCompat.PRIORITY_MAX) - .setCategory(NotificationCompat.CATEGORY_PROGRESS) - .setContent(contentView) - .setCustomBigContentView(contentBigView) - .setOngoing(false) - .build(); - - NotificationManager notificationManager = - (NotificationManager) pokefly.getSystemService(Context.NOTIFICATION_SERVICE); - notificationManager.notify(NOTIFICATION_REQ_CODE, notification); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + // N style notification + Notification.Builder builder = new Notification.Builder(pokefly) + .setCustomContentView(contentView) + .setStyle(new Notification.DecoratedCustomViewStyle()) + .setCustomBigContentView(contentBigView) + .setGroupSummary(false) + .setSmallIcon(R.drawable.notification_icon) + .setContentTitle(pokefly.getString(R.string.notification_title_goiv_stopped)) + .setContentText(pokefly.getString(R.string.notification_title_tap_to_open)) + .setColor(pokefly.getColorC(R.color.colorAccent)) + .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) + .setPriority(Notification.PRIORITY_MAX) + .setCategory(NotificationCompat.CATEGORY_PROGRESS) + .setOngoing(false); + + NotificationManager notificationManager = + (NotificationManager) pokefly.getSystemService(Context.NOTIFICATION_SERVICE); + notificationManager.notify(NOTIFICATION_REQ_CODE, builder.build()); + } else { + // classic style notification + Notification notification = new NotificationCompat.Builder(pokefly) + .setSmallIcon(R.drawable.notification_icon) + .setContentTitle(pokefly.getString(R.string.notification_title_goiv_stopped)) + .setContentText(pokefly.getString(R.string.notification_title_tap_to_open)) + .setColor(pokefly.getColorC(R.color.colorAccent)) + .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) + .setPriority(NotificationCompat.PRIORITY_MAX) + .setCategory(NotificationCompat.CATEGORY_PROGRESS) + .setContent(contentView) + .setCustomBigContentView(contentBigView) + .setOngoing(false) + .build(); + + NotificationManager notificationManager = + (NotificationManager) pokefly.getSystemService(Context.NOTIFICATION_SERVICE); + notificationManager.notify(NOTIFICATION_REQ_CODE, notification); + } } /** @@ -129,20 +152,39 @@ public void showRunningNotification() { contentBigView.setOnClickPendingIntent(R.id.pause, stopServicePendingIntent); // Build notification - Notification notification = new NotificationCompat.Builder(pokefly) - .setSmallIcon(R.drawable.notification_icon_play) - .setContentTitle(pokefly.getString(R.string.notification_title, pokefly.getTrainerLevel())) - .setContentText(pokefly.getString(R.string.notification_title_tap_to_open)) - .setColor(pokefly.getColorC(R.color.colorPrimary)) - .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) - .setPriority(NotificationCompat.PRIORITY_MAX) - .setCategory(NotificationCompat.CATEGORY_PROGRESS) - .setContent(contentView) - .setCustomBigContentView(contentBigView) - .setOngoing(true) - .build(); - - pokefly.startForeground(NOTIFICATION_REQ_CODE, notification); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + // N style notification + Notification.Builder builder = new Notification.Builder(pokefly) + .setCustomContentView(contentView) + .setStyle(new Notification.DecoratedCustomViewStyle()) + .setCustomBigContentView(contentBigView) + .setSmallIcon(R.drawable.notification_icon_play) + .setContentTitle(pokefly.getString(R.string.notification_title, pokefly.getTrainerLevel())) + .setContentText(pokefly.getString(R.string.notification_title_tap_to_open)) + .setColor(pokefly.getColorC(R.color.colorPrimary)) + .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) + .setPriority(Notification.PRIORITY_MAX) + .setCategory(NotificationCompat.CATEGORY_PROGRESS) + .setOngoing(false); + + pokefly.startForeground(NOTIFICATION_REQ_CODE, builder.build()); + } else { + // classic style notification + Notification notification = new NotificationCompat.Builder(pokefly) + .setSmallIcon(R.drawable.notification_icon_play) + .setContentTitle(pokefly.getString(R.string.notification_title, pokefly.getTrainerLevel())) + .setContentText(pokefly.getString(R.string.notification_title_tap_to_open)) + .setColor(pokefly.getColorC(R.color.colorPrimary)) + .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) + .setPriority(NotificationCompat.PRIORITY_MAX) + .setCategory(NotificationCompat.CATEGORY_PROGRESS) + .setContent(contentView) + .setCustomBigContentView(contentBigView) + .setOngoing(false) + .build(); + + pokefly.startForeground(NOTIFICATION_REQ_CODE, notification); + } } /** diff --git a/app/src/main/res/layout/notification_pokefly_paused.xml b/app/src/main/res/layout/notification_pokefly_paused.xml index 4d5d93244..637e95fad 100644 --- a/app/src/main/res/layout/notification_pokefly_paused.xml +++ b/app/src/main/res/layout/notification_pokefly_paused.xml @@ -1,60 +1,66 @@ - + android:paddingTop="@dimen/notification_vertical_padding" + android:paddingBottom="@dimen/notification_vertical_padding"> - + android:layout_toEndOf="@id/icon" + android:layout_toStartOf="@+id/settings" + android:text="@string/notification_title_goiv_stopped" /> - - - - - + + android:layout_marginEnd="8dp" + android:layout_alignParentTop="true" + android:layout_toStartOf="@+id/start" + android:contentDescription="@string/settings_page_title" + android:adjustViewBounds="true" + android:scaleType="centerInside" + android:layout_centerInParent="true" + android:src="@drawable/ic_settings_24px"/> + android:layout_alignParentEnd="true" + android:layout_alignParentTop="true" + android:contentDescription="@string/main_start" + android:adjustViewBounds="true" + android:scaleType="centerInside" + android:layout_centerInParent="true" + android:src="@drawable/ic_play_circle_outline_24px"/> - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/notification_pokefly_paused_expanded.xml b/app/src/main/res/layout/notification_pokefly_paused_expanded.xml index 6d40cc782..4380d13c6 100644 --- a/app/src/main/res/layout/notification_pokefly_paused_expanded.xml +++ b/app/src/main/res/layout/notification_pokefly_paused_expanded.xml @@ -1,73 +1,65 @@ - + android:paddingTop="@dimen/notification_vertical_padding" + android:paddingBottom="@dimen/notification_vertical_padding"> - - - - - - - - -