From 4e275d03d261cfe31caaf13b2e063e676f76abf6 Mon Sep 17 00:00:00 2001 From: jacques Date: Fri, 14 Aug 2020 15:13:27 +0200 Subject: [PATCH] restore file. may be a git error from me --- .../foucry/pilldroid/NotificationHelper.java | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 app/src/main/java/net/foucry/pilldroid/NotificationHelper.java diff --git a/app/src/main/java/net/foucry/pilldroid/NotificationHelper.java b/app/src/main/java/net/foucry/pilldroid/NotificationHelper.java new file mode 100644 index 0000000..41ea026 --- /dev/null +++ b/app/src/main/java/net/foucry/pilldroid/NotificationHelper.java @@ -0,0 +1,60 @@ +package net.foucry.pilldroid; + +import android.app.Notification; +import android.app.NotificationChannel; +import android.app.NotificationManager; +import android.content.Context; +import android.content.ContextWrapper; +import android.graphics.Color; +import android.os.Build; + +/** + * Created by jfoucry on 6/23/16. + * Publish notification + */ + + +class NotificationHelper extends ContextWrapper { + + private static final String TAG = NotificationHelper.class.getName(); + private NotificationManager notificationManager; + public final String CHANNEL_ID ="net.foucry.pilldroid"; + public final String CHANNEL_ID_NAME = getString(R.string.app_name); + + public NotificationHelper(Context base) { + super(base); + createChannels(); + } + + private void createChannels() { + + String description = getString(R.string.channel_description); + NotificationChannel channel = new NotificationChannel(CHANNEL_ID, CHANNEL_ID_NAME, + NotificationManager.IMPORTANCE_DEFAULT); + channel.setDescription(description); + channel.setLightColor(Color.RED); + channel.enableLights(true); + channel.setShowBadge(true); + channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC); + + getManager().createNotificationChannel(channel); + } + public Notification.Builder getNotification(String title, String body) { + return new Notification.Builder(getApplicationContext(), CHANNEL_ID) + .setContentTitle(title) + .setContentText(body) + .setSmallIcon(R.drawable.ic_pill) + .setAutoCancel(true); + } + + public void notify(int id, Notification.Builder notification) { + getManager().notify(id, notification.build()); + } + + private NotificationManager getManager() { + if(notificationManager == null) { + notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); + } + return notificationManager; + } +} \ No newline at end of file