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

Commit 7d4b258d authored by Daniel Hillenbrand's avatar Daniel Hillenbrand Committed by Gerrit Code Review
Browse files

Merge "Battery light: Add ability to reset the colors to default" into ics

parents 3ffb27d6 e8f0caa1
Loading
Loading
Loading
Loading
+57 −8
Original line number Diff line number Diff line
@@ -17,12 +17,16 @@
package com.android.settings.notificationlight;

import android.content.ContentResolver;
import android.content.res.Resources;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.PreferenceGroup;
import android.preference.PreferenceScreen;
import android.provider.Settings;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
@@ -44,11 +48,28 @@ public class BatteryLightSettings extends SettingsPreferenceFragment implements
    private ApplicationLightPreference mLowColorPref;
    private ApplicationLightPreference mMediumColorPref;
    private ApplicationLightPreference mFullColorPref;
    private static final int MENU_RESET = Menu.FIRST;
    private Menu mOptionsMenu;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.battery_light_settings);

        // Retrieve general settings
        ContentResolver resolver = getContentResolver();
        mLightEnabled = Settings.System.getInt(resolver,
                Settings.System.BATTERY_LIGHT_ENABLED, 1) == 1;
        mLightPulse = Settings.System.getInt(resolver,
                Settings.System.BATTERY_LIGHT_PULSE, 1) == 1;

        // Does the Device support changing battery LED colors?
        mMultiColorLed = getResources().getBoolean(com.android.internal.R.bool.config_multiColorBatteryLed);

        if(mMultiColorLed) {
            // Only used when the colors are changeable
            setHasOptionsMenu(true);
        }
    }

    @Override
@@ -59,10 +80,6 @@ public class BatteryLightSettings extends SettingsPreferenceFragment implements

    private void refreshDefault() {
        ContentResolver resolver = getContentResolver();
        mLightEnabled = Settings.System.getInt(resolver,
                Settings.System.BATTERY_LIGHT_ENABLED, 1) == 1;
        mLightPulse = Settings.System.getInt(resolver,
                Settings.System.BATTERY_LIGHT_PULSE, 1) == 1;
        int lowColor = Settings.System.getInt(resolver,
                Settings.System.BATTERY_LIGHT_LOW_COLOR,
                getResources().getInteger(com.android.internal.R.integer.config_notificationsBatteryLowARGB));
@@ -89,9 +106,6 @@ public class BatteryLightSettings extends SettingsPreferenceFragment implements
            mPulsePref.setOnPreferenceChangeListener(this);
        }

        // Does the Device support changing battery LED colors?
        mMultiColorLed = getResources().getBoolean(com.android.internal.R.bool.config_multiColorBatteryLed);

        PreferenceGroup colorPrefs = (PreferenceGroup) prefSet.findPreference("colors_list");
        if (colorPrefs != null) {
            if (!mMultiColorLed) {
@@ -140,6 +154,41 @@ public class BatteryLightSettings extends SettingsPreferenceFragment implements
        }
    }

    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        mOptionsMenu = menu;

        mOptionsMenu.add(0, MENU_RESET, 0, R.string.profile_reset_title)
                .setIcon(R.drawable.ic_settings_backup) // use the backup icon
                .setAlphabeticShortcut('r')
                .setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case MENU_RESET:
                resetColors();
                return true;
        }
        return false;
    }


    protected void resetColors() {
        ContentResolver resolver = getContentResolver();
        Resources res = getResources();

        // Reset to the framework default colors
        Settings.System.putInt(resolver, Settings.System.BATTERY_LIGHT_LOW_COLOR,
                res.getInteger(com.android.internal.R.integer.config_notificationsBatteryLowARGB));
        Settings.System.putInt(resolver, Settings.System.BATTERY_LIGHT_MEDIUM_COLOR,
                res.getInteger(com.android.internal.R.integer.config_notificationsBatteryMediumARGB));
        Settings.System.putInt(resolver, Settings.System.BATTERY_LIGHT_FULL_COLOR,
                res.getInteger(com.android.internal.R.integer.config_notificationsBatteryFullARGB));
        refreshDefault();
    }

    public boolean onPreferenceChange(Preference preference, Object objValue) {
        String key = preference.getKey();