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

Commit 0a52b0c3 authored by Romain Hunault's avatar Romain Hunault 🚴🏻
Browse files

Merge remote-tracking branch 'origin/lineage-15.1' into v1-oreo

parents 57093b30 7648f48b
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>
+26 −13
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;
@@ -49,7 +50,6 @@ import org.lineageos.internal.notification.LedValues;
import org.lineageos.internal.notification.LightsCapabilities;
import org.lineageos.internal.notification.LineageNotification;
import org.lineageos.lineageparts.R;
import org.lineageos.lineageparts.notificationlight.ColorPickerView.OnColorChangedListener;

import java.util.ArrayList;
import java.util.Locale;
@@ -73,8 +73,6 @@ public class LightSettingsDialog extends AlertDialog implements
    private Spinner mPulseSpeedOff;
    private LayoutInflater mInflater;

    private OnColorChangedListener mListener;

    private NotificationManager mNotificationManager;

    private boolean mReadyForLed;
@@ -243,10 +241,6 @@ public class LightSettingsDialog extends AlertDialog implements
        mNewColor.setColor(color);
        mHexColorInput.setText(String.format(Locale.US, format, color & mask));

        if (mListener != null) {
            mListener.onColorChanged(color);
        }

        updateLed();
    }

@@ -324,14 +318,23 @@ 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);
        b.putInt(LineageNotification.EXTRA_FORCE_PREVIEW_COLOR, color);
        b.putInt(LineageNotification.EXTRA_FORCE_PREVIEW_LIGHT_ON_MS, speedOn);
        b.putInt(LineageNotification.EXTRA_FORCE_PREVIEW_LIGHT_OFF_MS, speedOff);

        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;
@@ -340,12 +343,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;

@@ -447,9 +463,6 @@ public class LightSettingsDialog extends AlertDialog implements
                mColorPicker.setColor(color);
                mNewColor.setColor(color);
                updateLed();
                if (mListener != null) {
                    mListener.onColorChanged(color);
                }
            } catch (IllegalArgumentException ex) {
                // Number format is incorrect, ignore
            }