LightSettingsDialog: create and use notification channel

Android O introduced notification channels and deprecated
every non-notification-channel-usage.

Change-Id: I5ae46add9cdeaf8096079fedbd63b142abf14c9d
Signed-off-by: Alexander Martinz <amartinz@shiftphones.com>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 684cbee..12591b5 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -63,6 +63,10 @@
     <string name="privacy_guard_advanced_settings_title">Advanced</string>
     <string name="privacy_guard_notification_title">Show notification</string>
 
+    <!-- Notification channels -->
+    <string name="channel_light_settings_id" translatable="false">light_settings</string>
+    <string name="channel_light_settings_name">Light settings preview</string>
+
     <!-- Notification light dialogs -->
     <string name="edit_light_settings">Edit light settings</string>
     <string name="pulse_speed_title">Pulse length and speed</string>
diff --git a/src/org/lineageos/lineageparts/notificationlight/LightSettingsDialog.java b/src/org/lineageos/lineageparts/notificationlight/LightSettingsDialog.java
index 70dc639..ba6c6b8 100644
--- a/src/org/lineageos/lineageparts/notificationlight/LightSettingsDialog.java
+++ b/src/org/lineageos/lineageparts/notificationlight/LightSettingsDialog.java
@@ -21,6 +21,7 @@
 import android.app.Activity;
 import android.app.AlertDialog;
 import android.app.Notification;
+import android.app.NotificationChannel;
 import android.app.NotificationManager;
 import android.content.Context;
 import android.graphics.Color;
@@ -317,14 +318,20 @@
         if  (mLedBrightness > 0 && mLedBrightness < LedValues.LIGHT_BRIGHTNESS_MAXIMUM) {
             b.putInt(LineageNotification.EXTRA_FORCE_LIGHT_BRIGHTNESS, mLedBrightness);
         }
-        final Notification.Builder builder = new Notification.Builder(mContext);
+
+        createNotificationChannel();
+
+        final String channelId = mContext.getString(R.string.channel_light_settings_id);
+        final Notification.Builder builder = new Notification.Builder(mContext, channelId);
         builder.setLights(color, speedOn, speedOff);
         builder.setExtras(b);
         builder.setSmallIcon(R.drawable.ic_settings_24dp);
         builder.setContentTitle(mContext.getString(R.string.led_notification_title));
         builder.setContentText(mContext.getString(R.string.led_notification_text));
         builder.setOngoing(true);
-        mNotificationManager.notify(1, builder.build());
+
+        final Notification notification = builder.build();
+        mNotificationManager.notify(channelId, 1, notification);
 
         mLedLastColor = color;
         mLedLastSpeedOn = speedOn;
@@ -333,12 +340,25 @@
     }
 
     public void dismissLed() {
-        mNotificationManager.cancel(1);
+        final String channelId = mContext.getString(R.string.channel_light_settings_id);
+        mNotificationManager.cancel(channelId, 1);
         // ensure we later reset LED if dialog is
         // hidden and then made visible
         mLedLastColor = 0;
     }
 
+    private void createNotificationChannel() {
+        final String channelId = mContext.getString(R.string.channel_light_settings_id);
+        final String channelName = mContext.getString(R.string.channel_light_settings_name);
+        final NotificationChannel notificationChannel = new NotificationChannel(
+                channelId, channelName, NotificationManager.IMPORTANCE_LOW);
+        notificationChannel.enableLights(true);
+        notificationChannel.enableVibration(false);
+        notificationChannel.setShowBadge(false);
+
+        mNotificationManager.createNotificationChannel(notificationChannel);
+    }
+
     class PulseSpeedAdapter extends BaseAdapter implements SpinnerAdapter {
         private ArrayList<Pair<String, Integer>> times;