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

Commit e4e6a9dc authored by LuK1337's avatar LuK1337 Committed by Łukasz Patron
Browse files

LineageParts: Support breath LED mode

Change-Id: Ic49a4ae260294aeb10235ca6089c9169d4b2fd41
parent b5241880
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -26,6 +26,16 @@
    </string-array>

    <!-- Values for the notification light pulse spinners -->
    <string-array name="notification_breath_length_entries" translatable="false">
        <item>@string/pulse_length_always_on</item>
        <item>@string/pulse_length_blink</item>
    </string-array>

    <string-array name="notification_breath_length_values" translatable="false">
        <item>1</item>
        <item>1000</item>
    </string-array>

    <string-array name="notification_pulse_length_entries" translatable="false">
        <item>@string/pulse_length_always_on</item>
        <item>@string/pulse_length_very_short</item>
+1 −0
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@

    <!-- Values for the notification light pulse spinners -->
    <string name="pulse_length_always_on">Always on</string>
    <string name="pulse_length_blink">Blink</string>
    <string name="pulse_length_very_short">Very short</string>
    <string name="pulse_length_short">Short</string>
    <string name="pulse_length_normal">Normal</string>
+26 −12
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import androidx.appcompat.app.AlertDialog;
import androidx.preference.PreferenceViewHolder;

import org.lineageos.internal.notification.LightsCapabilities;
import org.lineageos.lineageparts.notificationlight.LightSettingsDialog.OnOffType;
import org.lineageos.lineageparts.widget.CustomDialogPreference;
import org.lineageos.lineageparts.R;

@@ -39,7 +40,7 @@ public class ApplicationLightPreference extends CustomDialogPreference<LightSett
    private int mColorValue;
    private int mOnValue;
    private int mOffValue;
    private boolean mOnOffChangeable;
    private OnOffType mOnOffType;

    private boolean mHasDefaults;
    private int mDefaultColorValue;
@@ -62,18 +63,17 @@ public class ApplicationLightPreference extends CustomDialogPreference<LightSett

    public ApplicationLightPreference(Context context, AttributeSet attrs,
                                      int color, int onValue, int offValue) {
        this(context, attrs, color, onValue, offValue,
                LightsCapabilities.supports(context, LightsCapabilities.LIGHTS_PULSATING_LED));
        this(context, attrs, color, onValue, offValue, getOnOffType(context));
    }

    public ApplicationLightPreference(Context context, AttributeSet attrs,
                                      int color, int onValue, int offValue,
                                      boolean onOffChangeable) {
                                      OnOffType onOffType) {
        super(context, attrs);
        mColorValue = color;
        mOnValue = onValue;
        mOffValue = offValue;
        mOnOffChangeable = onOffChangeable;
        mOnOffType = onOffType;
        mHasDefaults = false;
        mLedBrightness = 0; // use system brightness

@@ -128,6 +128,18 @@ public class ApplicationLightPreference extends CustomDialogPreference<LightSett
        }
    }

    private static OnOffType getOnOffType(Context context) {
        if (LightsCapabilities.supports(context, LightsCapabilities.LIGHTS_PULSATING_LED)) {
            return OnOffType.PULSE;
        }

        if (LightsCapabilities.supports(context, LightsCapabilities.LIGHTS_BREATHING_LED)) {
            return OnOffType.BREATH;
        }

        return OnOffType.TOGGLE;
    }

    private void updatePreferenceViews() {
        final int size = (int) getContext().getResources().getDimension(
                R.dimen.oval_notification_size);
@@ -144,7 +156,7 @@ public class ApplicationLightPreference extends CustomDialogPreference<LightSett
            mOnValueView.setText(mapLengthValue(mOnValue));
        }
        if (mOffValueView != null) {
            if (mOnValue == 1 || !mOnOffChangeable) {
            if (mOnValue == 1 || mOnOffType != OnOffType.PULSE) {
                mOffValueView.setVisibility(View.GONE);
            } else {
                mOffValueView.setVisibility(View.VISIBLE);
@@ -158,7 +170,7 @@ public class ApplicationLightPreference extends CustomDialogPreference<LightSett
        if (which == DialogInterface.BUTTON_NEUTRAL) {
            // Reset to previously supplied defaults
            mDialog.setColor(mDefaultColorValue);
            if (mOnOffChangeable) {
            if (mOnOffType != OnOffType.TOGGLE) {
                mDialog.setPulseSpeedOn(mDefaultOnValue);
                mDialog.setPulseSpeedOff(mDefaultOffValue);
            }
@@ -182,7 +194,7 @@ public class ApplicationLightPreference extends CustomDialogPreference<LightSett
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        mDialog = new LightSettingsDialog(getContext(), 0xFF000000 | mColorValue,
                mOnValue, mOffValue, mOnOffChangeable, mLedBrightness);
                mOnValue, mOffValue, mOnOffType, mLedBrightness);
        mDialog.setAlphaSliderVisible(false);

        // Initialize the buttons with null handlers, as they will get remapped by
@@ -230,11 +242,11 @@ public class ApplicationLightPreference extends CustomDialogPreference<LightSett
        updatePreferenceViews();
    }

    public void setAllValues(int color, int onValue, int offValue, boolean onOffChangeable) {
    public void setAllValues(int color, int onValue, int offValue, OnOffType onOffType) {
        mColorValue = color;
        mOnValue = onValue;
        mOffValue = offValue;
        mOnOffChangeable = onOffChangeable;
        mOnOffType = onOffType;
        updatePreferenceViews();
    }

@@ -261,11 +273,13 @@ public class ApplicationLightPreference extends CustomDialogPreference<LightSett
    }

    private String mapLengthValue(Integer time) {
        if (!mOnOffChangeable) {
        if (mOnOffType == OnOffType.TOGGLE) {
            return getContext().getResources().getString(R.string.pulse_length_always_on);
        }
        if (time == DEFAULT_TIME) {
            return getContext().getResources().getString(R.string.default_time);
            return mOnOffType == OnOffType.BREATH
                    ? getContext().getResources().getString(R.string.pulse_length_blink)
                    : getContext().getResources().getString(R.string.default_time);
        }

        String[] timeNames = getContext().getResources().getStringArray(
+7 −7
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import androidx.preference.PreferenceScreen;
import org.lineageos.internal.notification.LightsCapabilities;
import org.lineageos.lineageparts.R;
import org.lineageos.lineageparts.SettingsPreferenceFragment;
import org.lineageos.lineageparts.notificationlight.LightSettingsDialog.OnOffType;
import org.lineageos.lineageparts.search.BaseSearchIndexProvider;
import org.lineageos.lineageparts.search.Searchable;

@@ -78,8 +79,7 @@ public class BatteryLightSettings extends SettingsPreferenceFragment implements
        // liblights supports brightness control
        final boolean halAdjustableBrightness = LightsCapabilities.supports(context,
                LightsCapabilities.LIGHTS_ADJUSTABLE_BATTERY_LED_BRIGHTNESS);
        final boolean pulsatingLed = LightsCapabilities.supports(context,
                LightsCapabilities.LIGHTS_PULSATING_LED);
        final boolean blinkingLed = LightsCapabilities.blinks(context);
        final boolean segmentedBatteryLed = LightsCapabilities.supports(context,
                LightsCapabilities.LIGHTS_SEGMENTED_BATTERY_LED);

@@ -105,7 +105,7 @@ public class BatteryLightSettings extends SettingsPreferenceFragment implements

        int batteryBrightness = mBatteryBrightnessPref.getBrightnessSetting();

        if (!pulsatingLed || segmentedBatteryLed) {
        if (!blinkingLed || segmentedBatteryLed) {
            generalPrefs.removePreference(mPulseEnabledPref);
        }

@@ -161,19 +161,19 @@ public class BatteryLightSettings extends SettingsPreferenceFragment implements
        if (mLowColorPref != null) {
            int lowColor = LineageSettings.System.getInt(resolver,
                    LineageSettings.System.BATTERY_LIGHT_LOW_COLOR, mDefaultLowColor);
            mLowColorPref.setAllValues(lowColor, 0, 0, false);
            mLowColorPref.setAllValues(lowColor, 0, 0, OnOffType.TOGGLE);
        }

        if (mMediumColorPref != null) {
            int mediumColor = LineageSettings.System.getInt(resolver,
                    LineageSettings.System.BATTERY_LIGHT_MEDIUM_COLOR, mDefaultMediumColor);
            mMediumColorPref.setAllValues(mediumColor, 0, 0, false);
            mMediumColorPref.setAllValues(mediumColor, 0, 0, OnOffType.TOGGLE);
        }

        if (mFullColorPref != null) {
            int fullColor = LineageSettings.System.getInt(resolver,
                    LineageSettings.System.BATTERY_LIGHT_FULL_COLOR, mDefaultFullColor);
            mFullColorPref.setAllValues(fullColor, 0, 0, false);
            mFullColorPref.setAllValues(fullColor, 0, 0, OnOffType.TOGGLE);
            updateBrightnessPrefColor(fullColor);
        }
    }
@@ -308,7 +308,7 @@ public class BatteryLightSettings extends SettingsPreferenceFragment implements
                result.add(BRIGHTNESS_PREFERENCE);
                result.add(BRIGHTNESS_ZEN_PREFERENCE);
            }
            if (!LightsCapabilities.supports(context, LightsCapabilities.LIGHTS_PULSATING_LED) ||
            if (!LightsCapabilities.blinks(context) ||
                    LightsCapabilities.supports(context,
                            LightsCapabilities.LIGHTS_SEGMENTED_BATTERY_LED)) {
                result.add(PULSE_ENABLED_PREF);
+40 −17
Original line number Diff line number Diff line
@@ -73,22 +73,28 @@ public class LightSettingsDialog extends AlertDialog implements

    private Context mContext;

    public enum OnOffType {
        TOGGLE,
        BREATH,
        PULSE;
    };

    protected LightSettingsDialog(Context context, int initialColor, int initialSpeedOn,
            int initialSpeedOff) {
        super(context);

        init(context, initialColor, initialSpeedOn, initialSpeedOff, true, 0);
        init(context, initialColor, initialSpeedOn, initialSpeedOff, OnOffType.PULSE, 0);
    }

    protected LightSettingsDialog(Context context, int initialColor, int initialSpeedOn,
            int initialSpeedOff, boolean onOffChangeable, int brightness) {
            int initialSpeedOff, OnOffType onOffType, int brightness) {
        super(context);

        init(context, initialColor, initialSpeedOn, initialSpeedOff, onOffChangeable, brightness);
        init(context, initialColor, initialSpeedOn, initialSpeedOff, onOffType, brightness);
    }

    private void init(Context context, int color, int speedOn, int speedOff,
            boolean onOffChangeable, int brightness) {
            OnOffType onOffType, int brightness) {
        mContext = context;
        mNotificationManager = mContext.getSystemService(NotificationManager.class);

@@ -97,7 +103,7 @@ public class LightSettingsDialog extends AlertDialog implements

        // To fight color banding.
        getWindow().setFormat(PixelFormat.RGBA_8888);
        setUp(color, speedOn, speedOff, onOffChangeable, brightness);
        setUp(color, speedOn, speedOff, onOffType, brightness);
    }

    /**
@@ -108,8 +114,7 @@ public class LightSettingsDialog extends AlertDialog implements
     * @param speedOn - the flash time in ms
     * @param speedOff - the flash length in ms
     */
    private void setUp(int color, int speedOn, int speedOff, boolean onOffChangeable,
               int brightness) {
    private void setUp(int color, int speedOn, int speedOff, OnOffType onOffType, int brightness) {
        mInflater = mContext.getSystemService(LayoutInflater.class);
        View layout = mInflater.inflate(R.layout.dialog_light_settings, null);

@@ -123,29 +128,47 @@ public class LightSettingsDialog extends AlertDialog implements

        mHexColorInput.setOnFocusChangeListener(this);

        if (onOffChangeable) {
        if (onOffType == OnOffType.TOGGLE) {
            View speedSettingsGroup = layout.findViewById(R.id.speed_title_view);
            speedSettingsGroup.setVisibility(View.GONE);
            mPulseSpeedOn.setEnabled(false);
            mPulseSpeedOff.setEnabled(false);
        } else if (onOffType == OnOffType.BREATH) {
            mPulseSpeedAdapterOn = new PulseSpeedAdapter(
                    R.array.notification_pulse_length_entries,
                    R.array.notification_pulse_length_values,
                    R.array.notification_breath_length_entries,
                    R.array.notification_breath_length_values,
                    speedOn);
            mPulseSpeedAdapterOff = new PulseSpeedAdapter(
                    R.array.notification_pulse_speed_entries,
                    R.array.notification_pulse_speed_values,
                    speedOff);

            mPulseSpeedOn.setAdapter(mPulseSpeedAdapterOn);
            mPulseSpeedOn.setSelection(mPulseSpeedAdapterOn.getTimePosition(speedOn));
            mPulseSpeedOn.setOnItemSelectedListener(mPulseSelectionListener);

            mPulseSpeedAdapterOff = new PulseSpeedAdapter(R.array.notification_pulse_speed_entries,
            mPulseSpeedOff.setAdapter(mPulseSpeedAdapterOff);
            mPulseSpeedOff.setVisibility(View.INVISIBLE);
        } else if (onOffType == OnOffType.PULSE) {
            mPulseSpeedAdapterOn = new PulseSpeedAdapter(
                    R.array.notification_pulse_length_entries,
                    R.array.notification_pulse_length_values,
                    speedOn);
            mPulseSpeedAdapterOff = new PulseSpeedAdapter(
                    R.array.notification_pulse_speed_entries,
                    R.array.notification_pulse_speed_values,
                    speedOff);

            mPulseSpeedOn.setAdapter(mPulseSpeedAdapterOn);
            mPulseSpeedOn.setSelection(mPulseSpeedAdapterOn.getTimePosition(speedOn));
            mPulseSpeedOn.setOnItemSelectedListener(mPulseSelectionListener);

            mPulseSpeedOff.setAdapter(mPulseSpeedAdapterOff);
            mPulseSpeedOff.setSelection(mPulseSpeedAdapterOff.getTimePosition(speedOff));
            mPulseSpeedOff.setOnItemSelectedListener(mPulseSelectionListener);
        } else {
            View speedSettingsGroup = layout.findViewById(R.id.speed_title_view);
            speedSettingsGroup.setVisibility(View.GONE);
            mPulseSpeedOff.setEnabled(speedOn != 1);
        }

        mPulseSpeedOn.setEnabled(onOffChangeable);
        mPulseSpeedOff.setEnabled((speedOn != 1) && onOffChangeable);

        setView(layout);
        setTitle(R.string.edit_light_settings);

Loading