summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Martinz <amartinz@shiftphones.com>2019-03-06 19:37:48 +0100
committermosimchah <mosimchah@gmail.com>2019-05-18 13:07:41 -0400
commitdc957afb85ff4751f366742cf49a66a96e1f981d (patch)
tree11d49c21809ac0f50abefc6b926b3f6edc767a0c
parentf6993762bf12cb084e03a4abe990fcf136b824f5 (diff)
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>
-rw-r--r--res/values/strings.xml4
-rw-r--r--src/org/lineageos/lineageparts/notificationlight/LightSettingsDialog.java26
2 files changed, 27 insertions, 3 deletions
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 5ee76a7..65a1249 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 @@ package org.lineageos.lineageparts.notificationlight;
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 @@ public class LightSettingsDialog extends AlertDialog implements
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 class LightSettingsDialog extends AlertDialog implements
}
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;