Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9e4d4a88 authored by Alexander Martinz's avatar Alexander Martinz
Browse files

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's avatarAlexander Martinz <amartinz@shiftphones.com>
parent 7f0727af
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -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>
+23 −3
Original line number Diff line number Diff line
@@ -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;