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

Commit 03ab459e authored by d34d's avatar d34d Committed by Zhao Wei Liew
Browse files

BatteryLight: Reset all settings back to default

This patch resets all the settings for BatteryLightSettings
when the user presses reset, for a more consistent UX.

Change-Id: I5b705a02b9df686eea8af5afd4d552897926d0e3
parent 850ab1d4
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
     Copyright (C) 2015 The CyanogenMod Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->
<resources>

    <!-- Default value for battery_light_enabled preference -->
    <bool name="def_battery_light_enabled">true</bool>
    <!-- Default value for battery light pulse -->
    <bool name="def_battery_light_pulse">true</bool>

</resources>
+2 −2
Original line number Diff line number Diff line
@@ -24,12 +24,12 @@
        <com.android.settings.cyanogenmod.SystemSettingCheckBoxPreference
            android:key="battery_light_enabled"
            android:title="@string/battery_light_title"
            android:defaultValue="true" />
            android:defaultValue="@bool/def_battery_light_enabled" />

        <com.android.settings.cyanogenmod.SystemSettingCheckBoxPreference
            android:key="battery_light_pulse"
            android:title="@string/battery_low_pulse_title"
            android:defaultValue="true"
            android:defaultValue="@bool/def_battery_light_pulse"
            android:dependency="battery_light_enabled" />

    </PreferenceCategory>
+20 −1
Original line number Diff line number Diff line
@@ -38,12 +38,17 @@ public class BatteryLightSettings extends SettingsPreferenceFragment implements
    private static final String LOW_COLOR_PREF = "low_color";
    private static final String MEDIUM_COLOR_PREF = "medium_color";
    private static final String FULL_COLOR_PREF = "full_color";
    private static final String LIGHT_ENABLED_PREF = "battery_light_enabled";
    private static final String PULSE_ENABLED_PREF = "battery_light_pulse";

    private CheckBoxPreference mEnabledPref;
    private PreferenceGroup mColorPrefs;
    private ApplicationLightPreference mLowColorPref;
    private ApplicationLightPreference mMediumColorPref;
    private ApplicationLightPreference mFullColorPref;
    private CheckBoxPreference mLightEnabledPref;
    private CheckBoxPreference mPulseEnabledPref;

    private static final int MENU_RESET = Menu.FIRST;

    @Override
@@ -53,6 +58,9 @@ public class BatteryLightSettings extends SettingsPreferenceFragment implements

        PreferenceScreen prefSet = getPreferenceScreen();

        mLightEnabledPref = (CheckBoxPreference) prefSet.findPreference(LIGHT_ENABLED_PREF);
        mPulseEnabledPref = (CheckBoxPreference) prefSet.findPreference(PULSE_ENABLED_PREF);

        // Does the Device support changing battery LED colors?
        if (getResources().getBoolean(com.android.internal.R.bool.config_multiColorBatteryLed)) {
            setHasOptionsMenu(true);
@@ -131,7 +139,7 @@ public class BatteryLightSettings extends SettingsPreferenceFragment implements
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case MENU_RESET:
                resetColors();
                resetToDefaults();
                return true;
        }
        return false;
@@ -151,6 +159,17 @@ public class BatteryLightSettings extends SettingsPreferenceFragment implements
        refreshDefault();
    }

    protected void resetToDefaults() {
        final Resources res = getResources();
        final boolean batteryLightEnabled = res.getBoolean(R.bool.def_battery_light_enabled);
        final boolean batteryLightPulseEnabled = res.getBoolean(R.bool.def_battery_light_pulse);

        if (mLightEnabledPref != null) mLightEnabledPref.setChecked(batteryLightEnabled);
        if (mPulseEnabledPref != null) mPulseEnabledPref.setChecked(batteryLightPulseEnabled);

        resetColors();
    }

    @Override
    public boolean onPreferenceChange(Preference preference, Object objValue) {
        ApplicationLightPreference lightPref = (ApplicationLightPreference) preference;