OSDN Git Service

lights: Use NotificationManager to figure out LED capabilities
authorRicardo Cerqueira <android@cerqueira.org>
Thu, 10 Nov 2016 12:17:30 +0000 (12:17 +0000)
committerGerrit Code Review <gerrit@cyanogenmod.org>
Thu, 10 Nov 2016 12:30:18 +0000 (04:30 -0800)
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

src/com/android/settings/notificationlight/ApplicationLightPreference.java
src/com/android/settings/notificationlight/BatteryLightSettings.java
src/com/android/settings/notificationlight/LightSettingsDialog.java
src/com/android/settings/notificationlight/NotificationLightSettings.java

index a12f45b..405c826 100644 (file)
@@ -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);
         }
 
index 2ee884e..9efabc3 100644 (file)
@@ -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,13 +74,13 @@ 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) ||
-                getResources().getBoolean(org.cyanogenmod.platform.internal.R.bool.config_useSegmentedBatteryLed)) {
+        if (!nm.deviceLightsCan(NotificationManager.LIGHTS_LED_PULSE) ||
+             nm.deviceLightsCan(NotificationManager.LIGHTS_SEGMENTED_BATTERY_LIGHTS) ) {
             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
index d2d4e84..79b23e0 100644 (file)
@@ -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);
index b17918a..1c3601c 100644 (file)
@@ -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");