From 86741432894aa81525f1098bb31e0074050b8462 Mon Sep 17 00:00:00 2001 From: ezio84 Date: Sun, 17 Sep 2017 19:28:50 +0800 Subject: [PATCH] Battery light customization [2/2] --- res/drawable/ic_battery_almostfull.xml | 8 + res/drawable/ic_battery_full.xml | 8 + res/drawable/ic_battery_low.xml | 8 + res/drawable/ic_battery_medium.xml | 8 + res/drawable/ic_blinking.xml | 8 + res/drawable/ic_dnd.xml | 8 + res/values-vi/cherish_strings.xml | 1 - res/values/cherish_strings.xml | 11 ++ res/xml/battery_light_settings.xml | 66 ++++++++ res/xml/cherish_settings_notifications.xml | 5 + .../fragments/BatteryLightSettings.java | 142 ++++++++++++++++++ .../fragments/NotificationSettings.java | 27 +++- 12 files changed, 298 insertions(+), 2 deletions(-) create mode 100644 res/drawable/ic_battery_almostfull.xml create mode 100644 res/drawable/ic_battery_full.xml create mode 100644 res/drawable/ic_battery_low.xml create mode 100644 res/drawable/ic_battery_medium.xml create mode 100644 res/drawable/ic_blinking.xml create mode 100644 res/drawable/ic_dnd.xml create mode 100644 res/xml/battery_light_settings.xml create mode 100644 src/com/cherish/settings/fragments/BatteryLightSettings.java diff --git a/res/drawable/ic_battery_almostfull.xml b/res/drawable/ic_battery_almostfull.xml new file mode 100644 index 0000000..8f1e24d --- /dev/null +++ b/res/drawable/ic_battery_almostfull.xml @@ -0,0 +1,8 @@ + + + diff --git a/res/drawable/ic_battery_full.xml b/res/drawable/ic_battery_full.xml new file mode 100644 index 0000000..5d3b0cc --- /dev/null +++ b/res/drawable/ic_battery_full.xml @@ -0,0 +1,8 @@ + + + diff --git a/res/drawable/ic_battery_low.xml b/res/drawable/ic_battery_low.xml new file mode 100644 index 0000000..d4437b3 --- /dev/null +++ b/res/drawable/ic_battery_low.xml @@ -0,0 +1,8 @@ + + + diff --git a/res/drawable/ic_battery_medium.xml b/res/drawable/ic_battery_medium.xml new file mode 100644 index 0000000..5418317 --- /dev/null +++ b/res/drawable/ic_battery_medium.xml @@ -0,0 +1,8 @@ + + + diff --git a/res/drawable/ic_blinking.xml b/res/drawable/ic_blinking.xml new file mode 100644 index 0000000..40cdf54 --- /dev/null +++ b/res/drawable/ic_blinking.xml @@ -0,0 +1,8 @@ + + + diff --git a/res/drawable/ic_dnd.xml b/res/drawable/ic_dnd.xml new file mode 100644 index 0000000..da087de --- /dev/null +++ b/res/drawable/ic_dnd.xml @@ -0,0 +1,8 @@ + + + diff --git a/res/values-vi/cherish_strings.xml b/res/values-vi/cherish_strings.xml index 1af116a..c29d3f0 100644 --- a/res/values-vi/cherish_strings.xml +++ b/res/values-vi/cherish_strings.xml @@ -52,5 +52,4 @@ Thay thế xóa tất cả văn bản bằng nút đẹp Hiển thị xóa tất cả nút thông báo trong cài đặt nhanh thay vì văn bản mặc định - diff --git a/res/values/cherish_strings.xml b/res/values/cherish_strings.xml index d65e044..9a88907 100644 --- a/res/values/cherish_strings.xml +++ b/res/values/cherish_strings.xml @@ -244,4 +244,15 @@ Advanced restart When unlocked, include options in the power menu for restarting into recovery or bootloader + + Battery charging light + Enable + Battery light in Do Not Disturb mode + Blinking light on low battery + Battery light color when charging + Low battery + Medium battery + Almost full battery + Full (100) battery + diff --git a/res/xml/battery_light_settings.xml b/res/xml/battery_light_settings.xml new file mode 100644 index 0000000..596f40b --- /dev/null +++ b/res/xml/battery_light_settings.xml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/res/xml/cherish_settings_notifications.xml b/res/xml/cherish_settings_notifications.xml index a95f054..f0389ca 100644 --- a/res/xml/cherish_settings_notifications.xml +++ b/res/xml/cherish_settings_notifications.xml @@ -18,4 +18,9 @@ android:title="@string/notifications_title" xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"> + diff --git a/src/com/cherish/settings/fragments/BatteryLightSettings.java b/src/com/cherish/settings/fragments/BatteryLightSettings.java new file mode 100644 index 0000000..8ffe678 --- /dev/null +++ b/src/com/cherish/settings/fragments/BatteryLightSettings.java @@ -0,0 +1,142 @@ +/* + * Copyright (C) 2017 The ABC rom + * + * 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. + */ +package com.cherish.settings.fragments; + +import android.content.ContentResolver; +import android.content.res.Resources; +import android.os.Bundle; +import android.os.UserHandle; +import androidx.preference.ListPreference; +import androidx.preference.Preference; +import androidx.preference.PreferenceCategory; +import androidx.preference.PreferenceScreen; +import android.provider.Settings; + +import com.android.internal.logging.nano.MetricsProto; + +import com.cherish.settings.preferences.SystemSettingSwitchPreference; +import com.android.settings.R; +import com.android.settings.SettingsPreferenceFragment; + +import net.margaritov.preference.colorpicker.ColorPickerPreference; + +public class BatteryLightSettings extends SettingsPreferenceFragment implements + Preference.OnPreferenceChangeListener { + + private ColorPickerPreference mLowColor; + private ColorPickerPreference mMediumColor; + private ColorPickerPreference mFullColor; + private ColorPickerPreference mReallyFullColor; + private SystemSettingSwitchPreference mLowBatteryBlinking; + + private PreferenceCategory mColorCategory; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + addPreferencesFromResource(R.xml.battery_light_settings); + + PreferenceScreen prefSet = getPreferenceScreen(); + mColorCategory = (PreferenceCategory) findPreference("battery_light_cat"); + + mLowBatteryBlinking = (SystemSettingSwitchPreference)prefSet.findPreference("battery_light_low_blinking"); + if (getResources().getBoolean( + com.android.internal.R.bool.config_ledCanPulse)) { + mLowBatteryBlinking.setChecked(Settings.System.getIntForUser(getContentResolver(), + Settings.System.BATTERY_LIGHT_LOW_BLINKING, 0, UserHandle.USER_CURRENT) == 1); + mLowBatteryBlinking.setOnPreferenceChangeListener(this); + } else { + prefSet.removePreference(mLowBatteryBlinking); + } + + if (getResources().getBoolean(com.android.internal.R.bool.config_multiColorBatteryLed)) { + int color = Settings.System.getIntForUser(getContentResolver(), + Settings.System.BATTERY_LIGHT_LOW_COLOR, 0xFFFF0000, + UserHandle.USER_CURRENT); + mLowColor = (ColorPickerPreference) findPreference("battery_light_low_color"); + mLowColor.setAlphaSliderEnabled(true); + mLowColor.setNewPreviewColor(color); + mLowColor.setOnPreferenceChangeListener(this); + + color = Settings.System.getIntForUser(getContentResolver(), + Settings.System.BATTERY_LIGHT_MEDIUM_COLOR, 0xFFFFFF00, + UserHandle.USER_CURRENT); + mMediumColor = (ColorPickerPreference) findPreference("battery_light_medium_color"); + mMediumColor.setAlphaSliderEnabled(true); + mMediumColor.setNewPreviewColor(color); + mMediumColor.setOnPreferenceChangeListener(this); + + color = Settings.System.getIntForUser(getContentResolver(), + Settings.System.BATTERY_LIGHT_FULL_COLOR, 0xFFFFFF00, + UserHandle.USER_CURRENT); + mFullColor = (ColorPickerPreference) findPreference("battery_light_full_color"); + mFullColor.setAlphaSliderEnabled(true); + mFullColor.setNewPreviewColor(color); + mFullColor.setOnPreferenceChangeListener(this); + + color = Settings.System.getIntForUser(getContentResolver(), + Settings.System.BATTERY_LIGHT_REALLYFULL_COLOR, 0xFF00FF00, + UserHandle.USER_CURRENT); + mReallyFullColor = (ColorPickerPreference) findPreference("battery_light_reallyfull_color"); + mReallyFullColor.setAlphaSliderEnabled(true); + mReallyFullColor.setNewPreviewColor(color); + mReallyFullColor.setOnPreferenceChangeListener(this); + } else { + prefSet.removePreference(mColorCategory); + } + } + + @Override + public int getMetricsCategory() { + return MetricsProto.MetricsEvent.CHERISH_SETTINGS; + } + + public boolean onPreferenceChange(Preference preference, Object newValue) { + if (preference.equals(mLowColor)) { + int color = ((Integer) newValue).intValue(); + Settings.System.putIntForUser(getContentResolver(), + Settings.System.BATTERY_LIGHT_LOW_COLOR, color, + UserHandle.USER_CURRENT); + return true; + } else if (preference.equals(mMediumColor)) { + int color = ((Integer) newValue).intValue(); + Settings.System.putIntForUser(getContentResolver(), + Settings.System.BATTERY_LIGHT_MEDIUM_COLOR, color, + UserHandle.USER_CURRENT); + return true; + } else if (preference.equals(mFullColor)) { + int color = ((Integer) newValue).intValue(); + Settings.System.putIntForUser(getContentResolver(), + Settings.System.BATTERY_LIGHT_FULL_COLOR, color, + UserHandle.USER_CURRENT); + return true; + } else if (preference.equals(mReallyFullColor)) { + int color = ((Integer) newValue).intValue(); + Settings.System.putIntForUser(getContentResolver(), + Settings.System.BATTERY_LIGHT_REALLYFULL_COLOR, color, + UserHandle.USER_CURRENT); + return true; + } else if (preference == mLowBatteryBlinking) { + boolean value = (Boolean) newValue; + Settings.System.putIntForUser(getActivity().getContentResolver(), + Settings.System.BATTERY_LIGHT_LOW_BLINKING, value ? 1 : 0, + UserHandle.USER_CURRENT); + mLowBatteryBlinking.setChecked(value); + return true; + } + return false; + } +} diff --git a/src/com/cherish/settings/fragments/NotificationSettings.java b/src/com/cherish/settings/fragments/NotificationSettings.java index 2a9195d..8c64cee 100644 --- a/src/com/cherish/settings/fragments/NotificationSettings.java +++ b/src/com/cherish/settings/fragments/NotificationSettings.java @@ -4,16 +4,41 @@ import com.android.internal.logging.nano.MetricsProto; import android.os.Bundle; import com.android.settings.R; +import android.content.res.Resources; +import androidx.preference.Preference; +import androidx.preference.Preference.OnPreferenceChangeListener; +import androidx.preference.PreferenceCategory; +import androidx.preference.PreferenceScreen; +import android.provider.Settings; import com.android.settings.SettingsPreferenceFragment; +import net.margaritov.preference.colorpicker.ColorPickerPreference; -public class NotificationSettings extends SettingsPreferenceFragment { +public class NotificationSettings extends SettingsPreferenceFragment implements Preference.OnPreferenceChangeListener{ + + private ColorPickerPreference mEdgeLightColorPreference; + + private Preference mChargingLeds; @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); addPreferencesFromResource(R.xml.cherish_settings_notifications); + PreferenceScreen prefScreen = getPreferenceScreen(); + + mChargingLeds = (Preference) findPreference("charging_light"); + if (mChargingLeds != null + && !getResources().getBoolean( + com.android.internal.R.bool.config_intrusiveBatteryLed)) { + prefScreen.removePreference(mChargingLeds); + } + + } + + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + return false; } @Override