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

Commit b08b1677 authored by Ricardo Cerqueira's avatar Ricardo Cerqueira
Browse files

lights: Use NotificationManager to figure out LED capabilities

As of f/b change I7d627914b058861048071fc15776031c4152157f, there's
a more generic helper method in the notification service to get a
more unified (and extensible) list of what the on-device LEDs can
do. Move away from direct usage of the boolean resources.

Change-Id: Ib9a6f28dc52af722dac168ec219b790ad94d6a19
parent d1a1c2d5
Loading
Loading
Loading
Loading
+8 −5
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.settings.notificationlight;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.NotificationManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.Resources;
@@ -55,11 +56,11 @@ public class ApplicationLightPreference extends DialogPreference {
     */
    public ApplicationLightPreference(Context context, AttributeSet attrs) {
        super(context, attrs);
        NotificationManager nm = context.getSystemService(NotificationManager.class);
        mColorValue = DEFAULT_COLOR;
        mOnValue = DEFAULT_TIME;
        mOffValue = DEFAULT_TIME;
        mOnOffChangeable = context.getResources().getBoolean(
                com.android.internal.R.bool.config_ledCanPulse);
        mOnOffChangeable = nm.deviceLightsCan(NotificationManager.LIGHTS_LED_PULSE);
        init();
    }

@@ -71,11 +72,11 @@ public class ApplicationLightPreference extends DialogPreference {
     */
    public ApplicationLightPreference(Context context, int color, int onValue, int offValue) {
        super(context, null);
        NotificationManager nm = context.getSystemService(NotificationManager.class);
        mColorValue = color;
        mOnValue = onValue;
        mOffValue = offValue;
        mOnOffChangeable = context.getResources().getBoolean(
                com.android.internal.R.bool.config_ledCanPulse);
        mOnOffChangeable = nm.deviceLightsCan(NotificationManager.LIGHTS_LED_PULSE);
        init();
    }

@@ -117,6 +118,8 @@ public class ApplicationLightPreference extends DialogPreference {
    protected void onBindView(View view) {
        super.onBindView(view);

        NotificationManager nm = getContext().getSystemService(NotificationManager.class);

        mLightColorView = (ImageView) view.findViewById(R.id.light_color);
        mOnValueView = (TextView) view.findViewById(R.id.textViewTimeOnValue);
        mOffValueView = (TextView) view.findViewById(R.id.textViewTimeOffValue);
@@ -126,7 +129,7 @@ public class ApplicationLightPreference extends DialogPreference {
        TextView tView = (TextView) view.findViewById(android.R.id.summary);
        tView.setVisibility(View.GONE);

        if (!mResources.getBoolean(com.android.internal.R.bool.config_multiColorNotificationLed)) {
        if (!nm.deviceLightsCan(NotificationManager.LIGHTS_RGB_NOTIFICATION)) {
            mLightColorView.setVisibility(View.GONE);
        }

+5 −2
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.settings.notificationlight;

import android.app.NotificationManager;
import android.content.ContentResolver;
import android.content.res.Resources;
import android.os.Bundle;
@@ -64,6 +65,8 @@ public class BatteryLightSettings extends SettingsPreferenceFragment implements
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.battery_light_settings);

        final NotificationManager nm = getContext().getSystemService(NotificationManager.class);

        PreferenceScreen prefSet = getPreferenceScreen();

        PreferenceGroup mGeneralPrefs = (PreferenceGroup) prefSet.findPreference("general_section");
@@ -71,12 +74,12 @@ public class BatteryLightSettings extends SettingsPreferenceFragment implements
        mLightEnabledPref = (CMSystemSettingSwitchPreference) prefSet.findPreference(LIGHT_ENABLED_PREF);
        mPulseEnabledPref = (CMSystemSettingSwitchPreference) prefSet.findPreference(PULSE_ENABLED_PREF);

        if (!getResources().getBoolean(com.android.internal.R.bool.config_ledCanPulse)) {
        if (!nm.deviceLightsCan(NotificationManager.LIGHTS_LED_PULSE)) {
            mGeneralPrefs.removePreference(mPulseEnabledPref);
        }

        // Does the Device support changing battery LED colors?
        if (getResources().getBoolean(com.android.internal.R.bool.config_multiColorBatteryLed)) {
        if (nm.deviceLightsCan(NotificationManager.LIGHTS_RGB_BATTERY)) {
            setHasOptionsMenu(true);

            // Low, Medium and full color preferences
+1 −2
Original line number Diff line number Diff line
@@ -170,8 +170,7 @@ public class LightSettingsDialog extends AlertDialog implements
        setView(layout);
        setTitle(R.string.edit_light_settings);

        if (!getContext().getResources().getBoolean(
                com.android.internal.R.bool.config_multiColorNotificationLed)) {
        if (!mNotificationManager.deviceLightsCan(NotificationManager.LIGHTS_RGB_NOTIFICATION)) {
            mColorPicker.setVisibility(View.GONE);
            mColorPanel.setVisibility(View.GONE);
            mLightsDialogDivider.setVisibility(View.GONE);
+5 −3
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.settings.notificationlight;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.NotificationManager;
import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
@@ -97,6 +98,8 @@ public class NotificationLightSettings extends SettingsPreferenceFragment implem
        PreferenceScreen prefSet = getPreferenceScreen();
        Resources resources = getResources();

        final NotificationManager nm = getContext().getSystemService(NotificationManager.class);

        PreferenceGroup mAdvancedPrefs = (PreferenceGroup) prefSet.findPreference("advanced_section");

        // Get the system defined default notification color
@@ -135,8 +138,7 @@ public class NotificationLightSettings extends SettingsPreferenceFragment implem
        } else {
            mNotificationLedBrightnessPref.setOnPreferenceChangeListener(this);
        }
        if (!resources.getBoolean(
                org.cyanogenmod.platform.internal.R.bool.config_multipleNotificationLeds)) {
        if (!nm.deviceLightsCan(NotificationManager.LIGHTS_MULTIPLE_LED)) {
            mAdvancedPrefs.removePreference(mMultipleLedsEnabledPref);
        } else {
            mMultipleLedsEnabledPref.setOnPreferenceChangeListener(this);
@@ -164,7 +166,7 @@ public class NotificationLightSettings extends SettingsPreferenceFragment implem
        mPackages = new HashMap<String, Package>();
        setHasOptionsMenu(true);

        mMultiColorLed = resources.getBoolean(com.android.internal.R.bool.config_multiColorNotificationLed);
        mMultiColorLed = nm.deviceLightsCan(NotificationManager.LIGHTS_RGB_NOTIFICATION);
        if (!mMultiColorLed) {
            resetColors();
            PreferenceGroup mGeneralPrefs = (PreferenceGroup) prefSet.findPreference("general_section");