[SQUASH]DerpQuest: Add Battery Bar [2/2]
AquariOS:
Fixed color preferences to stick - @calebcabob
I'd like to thank and show respect to the following contributors for this
fantastic feature
Lokesh Chamane <lokesh.chamane@pac-rom.com>
SpiritCroc <spiritcroc@gmail.com>
westcripp <korukaltan@gmail.com>
commit fe5fa0cb0b74348d5e0e8172b17ab0f2d272dbf3
Author: Lokesh Chamane <lokesh.chamane@pac-rom.com>
Date: Thu Aug 4 23:37:17 2016 -0600
BatteryBar: Gradient Color [2/2]
Change-Id: If85baf2e724f9c6cdef868af323be039b47e49ad
Signed-off-by: mydongistiny <jaysonedson@gmail.com>
commit 0f046e9887f547ff130a925d02d75d0a74b369f4
Author: SpiritCroc <spiritcroc@gmail.com>
Date: Mon May 2 02:52:00 2016 -0700
Battery bar enhancements [2/2]
Add color settings for charging & low battery
Add reversed alignment setting
Change-Id: I51f7e0499971ed344d8faa6e63d4f89558946cb7
Signed-off-by: mydongistiny <jaysonedson@gmail.com>
commit be722a66ed4243831c48f45997a4cf1c442bc335
Author: westcripp <korukaltan@gmail.com>
Date: Sat Jan 10 04:14:45 2015 +0200
Settings: Add back batterybar [2/2]
Change-Id: I67b0a971fe9f0b6f5443d8ca7336d5e28e86bccd
Signed-off-by: mydongistiny <jaysonedson@gmail.com>
Change-Id: I4ad46c0e294b8fcf443926b5bb6d11930d981f91
@idoybh (DerpFest) edits:
* Improved and simplified the code
* Converted to a MasterSwitchPreference
* Added to settings search index
Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
This commit is contained in:
7
res/drawable/ic_battery_bar.xml
Normal file
7
res/drawable/ic_battery_bar.xml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:height="24dp"
|
||||||
|
android:width="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path android:fillColor="?android:attr/colorControlNormal" android:pathData="M3,7H9V13H3V7M3,3H21V5H3V3M21,7V9H11V7H21M21,11V13H11V11H21M3,15H17V17H3V15M3,19H21V21H3V19Z" />
|
||||||
|
</vector>
|
||||||
@@ -669,4 +669,29 @@
|
|||||||
<item>3</item>
|
<item>3</item>
|
||||||
<item>4</item>
|
<item>4</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
<!-- Battery bar -->
|
||||||
|
<string-array name="battery_bar_entries" translatable="false">
|
||||||
|
<item>@string/sb_battery_bar_statusbar</item>
|
||||||
|
<item>@string/sb_battery_bar_topnav</item>
|
||||||
|
<item>@string/sb_battery_bar_bottomnav</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="battery_bar_values" translatable="false">
|
||||||
|
<item>1</item>
|
||||||
|
<item>2</item>
|
||||||
|
<item>3</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="battery_bar_style_entries" translatable="false">
|
||||||
|
<item>@string/sb_battery_bar_reg</item>
|
||||||
|
<item>@string/sb_battery_bar_center</item>
|
||||||
|
<item>@string/sb_battery_bar_reversed</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="battery_bar_style_values" translatable="false">
|
||||||
|
<item>0</item>
|
||||||
|
<item>1</item>
|
||||||
|
<item>2</item>
|
||||||
|
</string-array>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -749,4 +749,29 @@
|
|||||||
<string name="flashlight_on_call_ignore_dnd_summary">Whether to flash when in Do Not Disturb mode</string>
|
<string name="flashlight_on_call_ignore_dnd_summary">Whether to flash when in Do Not Disturb mode</string>
|
||||||
<string name="flashlight_on_call_rate_title">Rate</string>
|
<string name="flashlight_on_call_rate_title">Rate</string>
|
||||||
<string name="flashlight_on_call_rate_summary">Flashlight on call blink rate</string>
|
<string name="flashlight_on_call_rate_summary">Flashlight on call blink rate</string>
|
||||||
|
|
||||||
|
<!-- Battery bar -->
|
||||||
|
<string name="enable_first">Please enable first</string>
|
||||||
|
<string name="battery_bar_title">Battery bar</string>
|
||||||
|
<string name="sb_battery_bar_title">Battery bar</string>
|
||||||
|
<string name="sb_battery_bar_summary">Display and customize battery bar near status bar or navigation bar</string>
|
||||||
|
<string name="sb_battery_bar_location">Battery bar location</string>
|
||||||
|
<string name="sb_battery_bar_color">Battery bar color</string>
|
||||||
|
<string name="sb_battery_bar_style_title">Battery bar style</string>
|
||||||
|
<string name="sb_battery_bar_thickness_title">Battery bar thickness</string>
|
||||||
|
<string name="sb_battery_bar_animate_title">Charging animation</string>
|
||||||
|
<string name="sb_battery_bar_animate_summary">The charging animation may result in a poor user experience. Enable at your own discretion.</string>
|
||||||
|
<string name="sb_battery_bar_hide">Hide</string>
|
||||||
|
<string name="sb_battery_bar_statusbar">Statusbar</string>
|
||||||
|
<string name="sb_battery_bar_topnav">Top of navbar</string>
|
||||||
|
<string name="sb_battery_bar_bottomnav">Bottom of navbar</string>
|
||||||
|
<string name="sb_battery_bar_reg">Regular</string>
|
||||||
|
<string name="sb_battery_bar_center">Center-mirrored</string>
|
||||||
|
<string name="sb_battery_bar_charging_color">Battery bar charging color</string>
|
||||||
|
<string name="sb_battery_bar_battery_low_color">Battery bar low battery color</string>
|
||||||
|
<string name="sb_battery_bar_reversed">Reversed</string>
|
||||||
|
<string name="sb_battery_bar_use_gradient_color">Use gradient color</string>
|
||||||
|
<string name="sb_battery_bar_gradient_color_summary">Use gradient color as a scale for the battery level</string>
|
||||||
|
<string name="sb_battery_bar_high_color">High level color"</string>
|
||||||
|
<string name="sb_battery_bar_low_color">Low level color"</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
75
res/xml/battery_bar.xml
Normal file
75
res/xml/battery_bar.xml
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!-- Copyright (C) 2018 AospExtended ROM 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.
|
||||||
|
-->
|
||||||
|
<PreferenceScreen
|
||||||
|
android:title="@string/battery_bar_title"
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings">
|
||||||
|
|
||||||
|
<ListPreference
|
||||||
|
android:key="battery_bar_list"
|
||||||
|
android:title="@string/sb_battery_bar_location"
|
||||||
|
android:entries="@array/battery_bar_entries"
|
||||||
|
android:entryValues="@array/battery_bar_values" />
|
||||||
|
|
||||||
|
<ListPreference
|
||||||
|
android:key="battery_bar_style"
|
||||||
|
android:title="@string/sb_battery_bar_style_title"
|
||||||
|
android:entries="@array/battery_bar_style_entries"
|
||||||
|
android:entryValues="@array/battery_bar_style_values" />
|
||||||
|
|
||||||
|
<com.cherish.settings.preferences.CustomSeekBarPreference
|
||||||
|
android:key="battery_bar_thickness"
|
||||||
|
android:title="@string/sb_battery_bar_thickness_title"
|
||||||
|
android:max="4"
|
||||||
|
settings:min="1"
|
||||||
|
settings:units="dp"
|
||||||
|
android:persistent="false" />
|
||||||
|
|
||||||
|
<SwitchPreference
|
||||||
|
android:key="battery_bar_animate"
|
||||||
|
android:title="@string/sb_battery_bar_animate_title"
|
||||||
|
android:summary="@string/sb_battery_bar_animate_summary" />
|
||||||
|
|
||||||
|
<net.margaritov.preference.colorpicker.ColorPickerPreference
|
||||||
|
android:key="battery_bar_color"
|
||||||
|
android:title="@string/sb_battery_bar_color"
|
||||||
|
android:defaultValue="0xffffff" />
|
||||||
|
|
||||||
|
<net.margaritov.preference.colorpicker.ColorPickerPreference
|
||||||
|
android:key="battery_bar_charging_color"
|
||||||
|
android:title="@string/sb_battery_bar_charging_color"
|
||||||
|
android:defaultValue="0xff00ff00" />
|
||||||
|
|
||||||
|
<net.margaritov.preference.colorpicker.ColorPickerPreference
|
||||||
|
android:key="battery_bar_battery_low_color_warning"
|
||||||
|
android:title="@string/sb_battery_bar_battery_low_color"
|
||||||
|
android:defaultValue="0xffff6600" />
|
||||||
|
|
||||||
|
<SwitchPreference
|
||||||
|
android:key="battery_bar_use_gradient_color"
|
||||||
|
android:title="@string/sb_battery_bar_use_gradient_color"
|
||||||
|
android:summary="@string/sb_battery_bar_gradient_color_summary" />
|
||||||
|
|
||||||
|
<net.margaritov.preference.colorpicker.ColorPickerPreference
|
||||||
|
android:key="battery_bar_low_color"
|
||||||
|
android:title="@string/sb_battery_bar_low_color"
|
||||||
|
android:dependency="battery_bar_use_gradient_color"
|
||||||
|
android:defaultValue="0xffff4400" />
|
||||||
|
|
||||||
|
<net.margaritov.preference.colorpicker.ColorPickerPreference
|
||||||
|
android:key="battery_bar_high_color"
|
||||||
|
android:title="@string/sb_battery_bar_high_color"
|
||||||
|
android:dependency="battery_bar_use_gradient_color"
|
||||||
|
android:defaultValue="0xff99cc00" />
|
||||||
|
|
||||||
|
</PreferenceScreen>
|
||||||
@@ -126,6 +126,12 @@
|
|||||||
android:key="battery_style_category"
|
android:key="battery_style_category"
|
||||||
android:title="@string/battery_style_category_title" >
|
android:title="@string/battery_style_category_title" >
|
||||||
|
|
||||||
|
<com.cherish.settings.preferences.SystemSettingMasterSwitchPreference
|
||||||
|
android:key="battery_bar_settings"
|
||||||
|
android:icon="@drawable/ic_battery_bar"
|
||||||
|
android:title="@string/sb_battery_bar_title"
|
||||||
|
android:fragment="com.cherish.settings.fragments.BatteryBar" />
|
||||||
|
|
||||||
<com.cherish.settings.preferences.SystemSettingListPreference
|
<com.cherish.settings.preferences.SystemSettingListPreference
|
||||||
android:key="status_bar_battery_style"
|
android:key="status_bar_battery_style"
|
||||||
android:icon="@drawable/ic_battery_styles"
|
android:icon="@drawable/ic_battery_styles"
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ public class NotificationSettings extends SettingsPreferenceFragment implements
|
|||||||
|
|
||||||
addPreferencesFromResource(R.xml.cherish_settings_notifications);
|
addPreferencesFromResource(R.xml.cherish_settings_notifications);
|
||||||
PreferenceScreen prefScreen = getPreferenceScreen();
|
PreferenceScreen prefScreen = getPreferenceScreen();
|
||||||
|
ContentResolver resolver = getActivity().getContentResolver();
|
||||||
|
|
||||||
mChargingLeds = (Preference) findPreference("charging_light");
|
mChargingLeds = (Preference) findPreference("charging_light");
|
||||||
if (mChargingLeds != null
|
if (mChargingLeds != null
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ public class StatusBarSettings extends SettingsPreferenceFragment implements
|
|||||||
private static final String STATUS_BAR_BATTERY_CHARGING_BOLT = "status_bar_battery_charging_bolt";
|
private static final String STATUS_BAR_BATTERY_CHARGING_BOLT = "status_bar_battery_charging_bolt";
|
||||||
private static final String BATTERY_PERCENTAGE_HIDDEN = "0";
|
private static final String BATTERY_PERCENTAGE_HIDDEN = "0";
|
||||||
private static final String STATUS_BAR_BATTERY_STYLE = "status_bar_battery_style";
|
private static final String STATUS_BAR_BATTERY_STYLE = "status_bar_battery_style";
|
||||||
|
private static final String BATTERY_BAR = "battery_bar_settings";
|
||||||
|
|
||||||
private static final int BATTERY_STYLE_Q = 0;
|
private static final int BATTERY_STYLE_Q = 0;
|
||||||
private static final int BATTERY_STYLE_DOTTED_CIRCLE = 1;
|
private static final int BATTERY_STYLE_DOTTED_CIRCLE = 1;
|
||||||
@@ -59,6 +60,7 @@ public class StatusBarSettings extends SettingsPreferenceFragment implements
|
|||||||
private CustomSeekBarPreference mThreshold;
|
private CustomSeekBarPreference mThreshold;
|
||||||
private SystemSettingSwitchPreference mNetMonitor;
|
private SystemSettingSwitchPreference mNetMonitor;
|
||||||
private SwitchPreference mBatteryBolt;
|
private SwitchPreference mBatteryBolt;
|
||||||
|
private SystemSettingMasterSwitchPreference mBatteryBar;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle icicle) {
|
public void onCreate(Bundle icicle) {
|
||||||
@@ -101,6 +103,13 @@ public class StatusBarSettings extends SettingsPreferenceFragment implements
|
|||||||
mThreshold.setValue(value);
|
mThreshold.setValue(value);
|
||||||
mThreshold.setOnPreferenceChangeListener(this);
|
mThreshold.setOnPreferenceChangeListener(this);
|
||||||
mThreshold.setEnabled(isNetMonitorEnabled);
|
mThreshold.setEnabled(isNetMonitorEnabled);
|
||||||
|
|
||||||
|
mBatteryBar = (SystemSettingMasterSwitchPreference)
|
||||||
|
findPreference(BATTERY_BAR);
|
||||||
|
mBatteryBar.setOnPreferenceChangeListener(this);
|
||||||
|
boolean enabled = Settings.System.getInt(resolver,
|
||||||
|
Settings.System.BATTERY_BAR_LOCATION, 0) != 0;
|
||||||
|
mBatteryBar.setChecked(enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -141,6 +150,11 @@ public class StatusBarSettings extends SettingsPreferenceFragment implements
|
|||||||
Settings.System.STATUS_BAR_BATTERY_CHARGING_BOLT,
|
Settings.System.STATUS_BAR_BATTERY_CHARGING_BOLT,
|
||||||
enabled ? 1 : 0);
|
enabled ? 1 : 0);
|
||||||
return true;
|
return true;
|
||||||
|
} else if (preference == mBatteryBar) {
|
||||||
|
boolean enabled = (boolean) objValue;
|
||||||
|
Settings.System.putInt(getActivity().getContentResolver(),
|
||||||
|
Settings.System.BATTERY_BAR_LOCATION, enabled ? 1 : 0);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
259
src/com/cherish/settings/preferences/fragments/BatteryBar.java
Normal file
259
src/com/cherish/settings/preferences/fragments/BatteryBar.java
Normal file
@@ -0,0 +1,259 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2013 Android Open Kang Project
|
||||||
|
* Copyright (C) 2017 faust93 at monumentum@gmail.com
|
||||||
|
*
|
||||||
|
* 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.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.ContentResolver;
|
||||||
|
import android.content.res.Resources;
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.net.ConnectivityManager;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.UserManager;
|
||||||
|
import android.provider.SearchIndexableResource;
|
||||||
|
import android.provider.Settings;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
import androidx.preference.ListPreference;
|
||||||
|
import androidx.preference.Preference;
|
||||||
|
import androidx.preference.PreferenceCategory;
|
||||||
|
import androidx.preference.PreferenceScreen;
|
||||||
|
import androidx.preference.Preference.OnPreferenceChangeListener;
|
||||||
|
import androidx.preference.SwitchPreference;
|
||||||
|
|
||||||
|
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
|
import com.android.settings.search.Indexable;
|
||||||
|
import com.android.settings.SettingsPreferenceFragment;
|
||||||
|
import com.android.settings.Utils;
|
||||||
|
import com.android.settingslib.search.SearchIndexable;
|
||||||
|
|
||||||
|
import com.cherish.settings.preferences.CustomSeekBarPreference;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import net.margaritov.preference.colorpicker.ColorPickerPreference;
|
||||||
|
|
||||||
|
@SearchIndexable
|
||||||
|
public class BatteryBar extends SettingsPreferenceFragment
|
||||||
|
implements Preference.OnPreferenceChangeListener, Indexable {
|
||||||
|
|
||||||
|
private static final String PREF_BATT_BAR = "battery_bar_list";
|
||||||
|
private static final String PREF_BATT_BAR_STYLE = "battery_bar_style";
|
||||||
|
private static final String PREF_BATT_BAR_COLOR = "battery_bar_color";
|
||||||
|
private static final String PREF_BATT_BAR_CHARGING_COLOR = "battery_bar_charging_color";
|
||||||
|
private static final String PREF_BATT_BAR_LOW_COLOR_WARNING = "battery_bar_battery_low_color_warning";
|
||||||
|
private static final String PREF_BATT_BAR_USE_GRADIENT_COLOR = "battery_bar_use_gradient_color";
|
||||||
|
private static final String PREF_BATT_BAR_LOW_COLOR = "battery_bar_low_color";
|
||||||
|
private static final String PREF_BATT_BAR_HIGH_COLOR = "battery_bar_high_color";
|
||||||
|
private static final String PREF_BATT_BAR_WIDTH = "battery_bar_thickness";
|
||||||
|
private static final String PREF_BATT_ANIMATE = "battery_bar_animate";
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
|
|
||||||
|
private ListPreference mBatteryBar;
|
||||||
|
private ListPreference mBatteryBarStyle;
|
||||||
|
private CustomSeekBarPreference mBatteryBarThickness;
|
||||||
|
private SwitchPreference mBatteryBarChargingAnimation;
|
||||||
|
private SwitchPreference mBatteryBarUseGradient;
|
||||||
|
private ColorPickerPreference mBatteryBarColor;
|
||||||
|
private ColorPickerPreference mBatteryBarChargingColor;
|
||||||
|
private ColorPickerPreference mBatteryBarBatteryLowColor;
|
||||||
|
private ColorPickerPreference mBatteryBarBatteryLowColorWarn;
|
||||||
|
private ColorPickerPreference mBatteryBarBatteryHighColor;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
addPreferencesFromResource(R.xml.battery_bar);
|
||||||
|
|
||||||
|
mContext = (Context) getActivity();
|
||||||
|
final ContentResolver resolver = getActivity().getContentResolver();
|
||||||
|
PreferenceScreen prefSet = getPreferenceScreen();
|
||||||
|
|
||||||
|
mBatteryBar = (ListPreference) findPreference(PREF_BATT_BAR);
|
||||||
|
mBatteryBar.setOnPreferenceChangeListener(this);
|
||||||
|
boolean enabled = Settings.System.getInt(resolver,
|
||||||
|
Settings.System.BATTERY_BAR_LOCATION, 0) != 0;
|
||||||
|
if (enabled) {
|
||||||
|
mBatteryBar.setValue((Settings.System.getInt(resolver, Settings.System.BATTERY_BAR_LOCATION, 0)) + "");
|
||||||
|
mBatteryBar.setSummary(mBatteryBar.getEntry());
|
||||||
|
} else {
|
||||||
|
mBatteryBar.setEnabled(false);
|
||||||
|
mBatteryBar.setSummary(R.string.enable_first);
|
||||||
|
}
|
||||||
|
|
||||||
|
mBatteryBarStyle = (ListPreference) findPreference(PREF_BATT_BAR_STYLE);
|
||||||
|
mBatteryBarStyle.setOnPreferenceChangeListener(this);
|
||||||
|
mBatteryBarStyle.setValue((Settings.System.getInt(resolver,
|
||||||
|
Settings.System.BATTERY_BAR_STYLE, 0)) + "");
|
||||||
|
mBatteryBarStyle.setSummary(mBatteryBarStyle.getEntry());
|
||||||
|
|
||||||
|
mBatteryBarColor = (ColorPickerPreference) prefSet.findPreference(PREF_BATT_BAR_COLOR);
|
||||||
|
mBatteryBarColor.setNewPreviewColor(Settings.System.getInt(resolver,
|
||||||
|
Settings.System.BATTERY_BAR_COLOR, Color.WHITE));
|
||||||
|
mBatteryBarColor.setOnPreferenceChangeListener(this);
|
||||||
|
|
||||||
|
mBatteryBarChargingColor = (ColorPickerPreference) prefSet.findPreference(PREF_BATT_BAR_CHARGING_COLOR);
|
||||||
|
mBatteryBarChargingColor.setNewPreviewColor(Settings.System.getInt(resolver,
|
||||||
|
Settings.System.BATTERY_BAR_CHARGING_COLOR, Color.WHITE));
|
||||||
|
mBatteryBarChargingColor.setOnPreferenceChangeListener(this);
|
||||||
|
|
||||||
|
mBatteryBarBatteryLowColorWarn = (ColorPickerPreference) prefSet.findPreference(PREF_BATT_BAR_LOW_COLOR_WARNING);
|
||||||
|
mBatteryBarBatteryLowColorWarn.setNewPreviewColor(Settings.System.getInt(resolver,
|
||||||
|
Settings.System.BATTERY_BAR_BATTERY_LOW_COLOR_WARNING,Color.WHITE));
|
||||||
|
mBatteryBarBatteryLowColorWarn.setOnPreferenceChangeListener(this);
|
||||||
|
|
||||||
|
mBatteryBarBatteryLowColor = (ColorPickerPreference) prefSet.findPreference(PREF_BATT_BAR_LOW_COLOR);
|
||||||
|
mBatteryBarBatteryLowColor.setNewPreviewColor(Settings.System.getInt(resolver,
|
||||||
|
Settings.System.BATTERY_BAR_LOW_COLOR, Color.WHITE));
|
||||||
|
mBatteryBarBatteryLowColor.setOnPreferenceChangeListener(this);
|
||||||
|
|
||||||
|
mBatteryBarBatteryHighColor = (ColorPickerPreference) prefSet.findPreference(PREF_BATT_BAR_HIGH_COLOR);
|
||||||
|
mBatteryBarBatteryHighColor.setNewPreviewColor(Settings.System.getInt(resolver,
|
||||||
|
Settings.System.BATTERY_BAR_HIGH_COLOR, Color.WHITE));
|
||||||
|
mBatteryBarBatteryHighColor.setOnPreferenceChangeListener(this);
|
||||||
|
|
||||||
|
mBatteryBarUseGradient = (SwitchPreference) findPreference(PREF_BATT_BAR_USE_GRADIENT_COLOR);
|
||||||
|
mBatteryBarUseGradient.setChecked(Settings.System.getInt(resolver,
|
||||||
|
Settings.System.BATTERY_BAR_USE_GRADIENT_COLOR, 0) == 1);
|
||||||
|
|
||||||
|
mBatteryBarChargingAnimation = (SwitchPreference) findPreference(PREF_BATT_ANIMATE);
|
||||||
|
mBatteryBarChargingAnimation.setChecked(Settings.System.getInt(resolver,
|
||||||
|
Settings.System.BATTERY_BAR_ANIMATE, 0) == 1);
|
||||||
|
|
||||||
|
mBatteryBarThickness = (CustomSeekBarPreference) prefSet.findPreference(PREF_BATT_BAR_WIDTH);
|
||||||
|
mBatteryBarThickness.setValue(Settings.System.getInt(resolver,
|
||||||
|
Settings.System.BATTERY_BAR_THICKNESS, 1));
|
||||||
|
mBatteryBarThickness.setOnPreferenceChangeListener(this);
|
||||||
|
|
||||||
|
updateBatteryBarOptions();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
|
ContentResolver resolver = getActivity().getContentResolver();
|
||||||
|
if (preference == mBatteryBarColor) {
|
||||||
|
int intHex = (Integer) newValue;
|
||||||
|
Settings.System.putInt(resolver,
|
||||||
|
Settings.System.BATTERY_BAR_COLOR, intHex);
|
||||||
|
return true;
|
||||||
|
} else if (preference == mBatteryBarChargingColor) {
|
||||||
|
int intHex = (Integer) newValue;
|
||||||
|
Settings.System.putInt(resolver,
|
||||||
|
Settings.System.BATTERY_BAR_CHARGING_COLOR, intHex);
|
||||||
|
return true;
|
||||||
|
} else if (preference == mBatteryBarBatteryLowColor) {
|
||||||
|
int intHex = (Integer) newValue;
|
||||||
|
Settings.System.putInt(resolver,
|
||||||
|
Settings.System.BATTERY_BAR_LOW_COLOR, intHex);
|
||||||
|
return true;
|
||||||
|
} else if (preference == mBatteryBarBatteryLowColorWarn) {
|
||||||
|
int intHex = (Integer) newValue;
|
||||||
|
Settings.System.putInt(resolver,
|
||||||
|
Settings.System.BATTERY_BAR_BATTERY_LOW_COLOR_WARNING, intHex);
|
||||||
|
return true;
|
||||||
|
} else if (preference == mBatteryBarBatteryHighColor) {
|
||||||
|
int intHex = (Integer) newValue;
|
||||||
|
Settings.System.putInt(resolver,
|
||||||
|
Settings.System.BATTERY_BAR_HIGH_COLOR, intHex);
|
||||||
|
return true;
|
||||||
|
} else if (preference == mBatteryBar) {
|
||||||
|
int val = Integer.parseInt((String) newValue);
|
||||||
|
int index = mBatteryBar.findIndexOfValue((String) newValue);
|
||||||
|
Settings.System.putInt(resolver,
|
||||||
|
Settings.System.BATTERY_BAR_LOCATION, val);
|
||||||
|
mBatteryBar.setSummary(mBatteryBar.getEntries()[index]);
|
||||||
|
updateBatteryBarOptions();
|
||||||
|
return true;
|
||||||
|
} else if (preference == mBatteryBarStyle) {
|
||||||
|
int val = Integer.parseInt((String) newValue);
|
||||||
|
int index = mBatteryBarStyle.findIndexOfValue((String) newValue);
|
||||||
|
Settings.System.putInt(resolver,
|
||||||
|
Settings.System.BATTERY_BAR_STYLE, val);
|
||||||
|
mBatteryBarStyle.setSummary(mBatteryBarStyle.getEntries()[index]);
|
||||||
|
return true;
|
||||||
|
} else if (preference == mBatteryBarThickness) {
|
||||||
|
int val = (Integer) newValue;
|
||||||
|
Settings.System.putInt(resolver,
|
||||||
|
Settings.System.BATTERY_BAR_THICKNESS, val);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean onPreferenceTreeClick(Preference preference) {
|
||||||
|
ContentResolver resolver = getActivity().getContentResolver();
|
||||||
|
if (preference == mBatteryBarChargingAnimation) {
|
||||||
|
boolean value = mBatteryBarChargingAnimation.isChecked();
|
||||||
|
Settings.System.putInt(resolver,
|
||||||
|
Settings.System.BATTERY_BAR_ANIMATE, value ? 1 : 0);
|
||||||
|
return true;
|
||||||
|
} else if (preference == mBatteryBarUseGradient) {
|
||||||
|
boolean value = mBatteryBarUseGradient.isChecked();
|
||||||
|
Settings.System.putInt(getContentResolver(),
|
||||||
|
Settings.System.BATTERY_BAR_USE_GRADIENT_COLOR, value ? 1 : 0);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateBatteryBarOptions() {
|
||||||
|
boolean enabled = Settings.System.getInt(getActivity().getContentResolver(),
|
||||||
|
Settings.System.BATTERY_BAR_LOCATION, 0) != 0;
|
||||||
|
mBatteryBarStyle.setEnabled(enabled);
|
||||||
|
mBatteryBarThickness.setEnabled(enabled);
|
||||||
|
mBatteryBarChargingAnimation.setEnabled(enabled);
|
||||||
|
mBatteryBarColor.setEnabled(enabled);
|
||||||
|
mBatteryBarChargingColor.setEnabled(enabled);
|
||||||
|
mBatteryBarUseGradient.setEnabled(enabled);
|
||||||
|
mBatteryBarBatteryLowColor.setEnabled(enabled);
|
||||||
|
mBatteryBarBatteryHighColor.setEnabled(enabled);
|
||||||
|
mBatteryBarBatteryLowColorWarn.setEnabled(enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMetricsCategory() {
|
||||||
|
return MetricsEvent.CHERISH_SETTINGS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||||
|
new BaseSearchIndexProvider() {
|
||||||
|
@Override
|
||||||
|
public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
|
||||||
|
boolean enabled) {
|
||||||
|
ArrayList<SearchIndexableResource> result =
|
||||||
|
new ArrayList<SearchIndexableResource>();
|
||||||
|
|
||||||
|
SearchIndexableResource sir = new SearchIndexableResource(context);
|
||||||
|
sir.xmlResId = R.xml.battery_bar;
|
||||||
|
result.add(sir);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getNonIndexableKeys(Context context) {
|
||||||
|
List<String> keys = super.getNonIndexableKeys(context);
|
||||||
|
return keys;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user