Cherish: Add battery styles and customizations for Android 10 [2/2]
Allows the user to tune: - battery styles - battery percentage rcstar6696: - Adapted to our battery stylesAdd battery styles and customizations for Android 10 [2/2] Change-Id: I6075e1a70a7a3c111daa24d913953111776bceb0 Signed-off-by: SagarMakhar <sagarmakhar@gmail.com> Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
This commit is contained in:
@@ -265,4 +265,35 @@
|
||||
<item>3</item>
|
||||
</string-array>
|
||||
|
||||
<!-- Battery percent -->
|
||||
<string-array name="battery_percent_entries">
|
||||
<item>@string/status_bar_battery_percentage_default</item>
|
||||
<item>@string/status_bar_battery_percentage_text_inside</item>
|
||||
<item>@string/status_bar_battery_percentage_text_next</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="battery_percent_values" translatable="false">
|
||||
<item>0</item>
|
||||
<item>1</item>
|
||||
<item>2</item>
|
||||
</string-array>
|
||||
|
||||
<!-- Battery -->
|
||||
<string-array name="status_bar_battery_style_entries" translatable="false">
|
||||
<item>@string/status_bar_battery_style_icon_portrait</item>
|
||||
<item>@string/status_bar_battery_style_circle</item>
|
||||
<item>@string/status_bar_battery_style_dotted_circle</item>
|
||||
<item>@string/status_bar_battery_style_filled_circle</item>
|
||||
<item>@string/status_bar_battery_style_text</item>
|
||||
<item>@string/status_bar_battery_style_hidden</item>
|
||||
</string-array>
|
||||
<string-array name="status_bar_battery_style_values" translatable="false">
|
||||
<item>0</item>
|
||||
<item>1</item>
|
||||
<item>2</item>
|
||||
<item>3</item>
|
||||
<item>4</item>
|
||||
<item>5</item>
|
||||
</string-array>
|
||||
|
||||
</resources>
|
||||
|
||||
@@ -457,4 +457,26 @@
|
||||
<string name="charging_animation_title">Charging animation</string>
|
||||
<string name="charging_animation_summary">Display an animation when the device is plugged in</string>
|
||||
|
||||
<!-- Battery Settings -->
|
||||
<string name="battery_settings_title">Battery Settings</string>
|
||||
|
||||
<!-- Battery Styles -->
|
||||
<string name="battery_style_category_title">Battery styles</string>
|
||||
<string name="battery_percent_title">Battery percent</string>
|
||||
|
||||
<!-- Status bar - Battery -->
|
||||
<string name="status_bar_battery_style_title">Battery style</string>
|
||||
<string name="status_bar_battery_style_icon_portrait">Icon portrait (default)</string>
|
||||
<string name="status_bar_battery_style_circle">Circle</string>
|
||||
<string name="status_bar_battery_style_dotted_circle">Circle (Dotted)</string>
|
||||
<string name="status_bar_battery_style_filled_circle">Circle (Filled)</string>
|
||||
<string name="status_bar_battery_style_text">Text</string>
|
||||
<string name="status_bar_battery_style_hidden">Hidden</string>
|
||||
|
||||
<!-- Status bar - Battery percentage -->
|
||||
<string name="status_bar_battery_percentage_title">Battery percentage</string>
|
||||
<string name="status_bar_battery_percentage_default">Hidden (default)</string>
|
||||
<string name="status_bar_battery_percentage_text_inside">Inside the icon</string>
|
||||
<string name="status_bar_battery_percentage_text_next">Next to the icon</string>
|
||||
|
||||
</resources>
|
||||
@@ -11,10 +11,37 @@
|
||||
limitations under the License.
|
||||
-->
|
||||
<PreferenceScreen
|
||||
android:title="@string/battery_bar_title"
|
||||
android:title="@string/battery_settings_title"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings">
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="battery_style_category"
|
||||
android:title="@string/battery_style_category_title" >
|
||||
|
||||
<com.cherish.settings.preferences.SystemSettingListPreference
|
||||
android:key="status_bar_battery_style"
|
||||
android:title="@string/status_bar_battery_style_title"
|
||||
android:summary="%s"
|
||||
android:dialogTitle="@string/status_bar_battery_style_title"
|
||||
android:entries="@array/status_bar_battery_style_entries"
|
||||
android:entryValues="@array/status_bar_battery_style_values"
|
||||
android:defaultValue="0" />
|
||||
|
||||
<com.cherish.settings.preferences.SystemSettingListPreference
|
||||
android:key="status_bar_show_battery_percent"
|
||||
android:title="@string/battery_percent_title"
|
||||
android:dialogTitle="@string/battery_percent_title"
|
||||
android:entries="@array/battery_percent_entries"
|
||||
android:entryValues="@array/battery_percent_values"
|
||||
android:defaultValue="0" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="battery_bar_category"
|
||||
android:title="@string/battery_bar_title">
|
||||
|
||||
<ListPreference
|
||||
android:key="statusbar_battery_bar_list"
|
||||
android:title="@string/battery_bar"
|
||||
@@ -37,7 +64,7 @@
|
||||
android:title="@string/battery_bar_battery_low_color"
|
||||
android:defaultValue="0xffffff" />
|
||||
|
||||
<net.margaritov.preference.colorpicker.ColorPickerPreference
|
||||
<com.cherish.settings.preferences.SystemSettingSwitchPreference
|
||||
android:key="statusbar_battery_bar_enable_charging_color"
|
||||
android:title="@string/battery_bar_use_charging_color"
|
||||
android:defaultValue="true" />
|
||||
@@ -54,7 +81,7 @@
|
||||
android:summary="@string/battery_bar_blend_color_summary"
|
||||
android:defaultValue="false" />
|
||||
|
||||
<con.cherish.settings.preferences.SystemSettingSwitchPreference
|
||||
<com.cherish.settings.preferences.SystemSettingSwitchPreference
|
||||
android:key="statusbar_battery_bar_blend_color_reverse"
|
||||
android:title="@string/battery_bar_blend_color_reverse_title"
|
||||
android:summaryOn="@string/battery_bar_blend_color_reverse_summary_on"
|
||||
@@ -68,7 +95,7 @@
|
||||
android:entries="@array/battery_bar_style_entries"
|
||||
android:entryValues="@array/battery_bar_style_values" />
|
||||
|
||||
<con.cherish.settings.preferences.CustomSeekBarPreference
|
||||
<com.cherish.settings.preferences.CustomSeekBarPreference
|
||||
android:key="statusbar_battery_bar_thickness"
|
||||
android:title="@string/battery_bar_thickness_title"
|
||||
android:max="4"
|
||||
@@ -80,4 +107,5 @@
|
||||
android:key="statusbar_battery_bar_animate"
|
||||
android:title="@string/battery_bar_animate_title" />
|
||||
|
||||
</PreferenceCategory>
|
||||
</PreferenceScreen>
|
||||
@@ -94,8 +94,8 @@
|
||||
|
||||
<Preference
|
||||
android:key="battery_bar_category"
|
||||
android:fragment="com.cherish.settings.fragments.BatteryBar"
|
||||
android:title="@string/battery_bar_title" />
|
||||
android:fragment="com.cherish.settings.fragments.BatterySettings"
|
||||
android:title="@string/battery_settings_title" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.Preference.OnPreferenceChangeListener;
|
||||
@@ -33,10 +34,10 @@ import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
|
||||
import net.margaritov.preference.colorpicker.ColorPickerPreference;
|
||||
import con.cherish.settings.preferences.CustomSeekBarPreference;
|
||||
import com.cherish.settings.preferences.CustomSeekBarPreference;
|
||||
import com.android.settings.R;
|
||||
|
||||
public class BatteryBar extends SettingsPreferenceFragment
|
||||
public class BatterySettings extends SettingsPreferenceFragment
|
||||
implements Preference.OnPreferenceChangeListener {
|
||||
|
||||
private static final String PREF_BATT_BAR = "statusbar_battery_bar_list";
|
||||
@@ -50,6 +51,14 @@ public class BatteryBar extends SettingsPreferenceFragment
|
||||
private static final String PREF_BATT_USE_CHARGING_COLOR = "statusbar_battery_bar_enable_charging_color";
|
||||
private static final String PREF_BATT_BLEND_COLOR = "statusbar_battery_bar_blend_color";
|
||||
private static final String PREF_BATT_BLEND_COLOR_REVERSE = "statusbar_battery_bar_blend_color_reverse";
|
||||
private static final String PREF_STATUS_BAR_SHOW_BATTERY_PERCENT = "status_bar_show_battery_percent";
|
||||
private static final String PREF_STATUS_BAR_BATTERY_STYLE = "status_bar_battery_style";
|
||||
|
||||
private static final int BATTERY_STYLE_PORTRAIT = 0;
|
||||
private static final int BATTERY_STYLE_TEXT = 4;
|
||||
private static final int BATTERY_STYLE_HIDDEN = 5;
|
||||
private static final int BATTERY_PERCENT_HIDDEN = 0;
|
||||
private static final int BATTERY_PERCENT_SHOW = 2;
|
||||
|
||||
private ListPreference mBatteryBar;
|
||||
private ListPreference mBatteryBarNoNavbar;
|
||||
@@ -62,12 +71,16 @@ public class BatteryBar extends SettingsPreferenceFragment
|
||||
private ColorPickerPreference mBatteryBarColor;
|
||||
private ColorPickerPreference mBatteryBarChargingColor;
|
||||
private ColorPickerPreference mBatteryBarBatteryLowColor;
|
||||
private ListPreference mBatteryPercent;
|
||||
private ListPreference mBatteryStyle;
|
||||
private int mBatteryPercentValue;
|
||||
private int mBatteryPercentValuePrev;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
addPreferencesFromResource(R.xml.battery_bar);
|
||||
addPreferencesFromResource(R.xml.battery_settings);
|
||||
|
||||
PreferenceScreen prefSet = getPreferenceScreen();
|
||||
ContentResolver resolver = getActivity().getContentResolver();
|
||||
@@ -126,6 +139,24 @@ public class BatteryBar extends SettingsPreferenceFragment
|
||||
mBatteryBarBlendColor = (SwitchPreference) findPreference(PREF_BATT_BLEND_COLOR);
|
||||
mBatteryBarBlendColorReverse = (SwitchPreference) findPreference(PREF_BATT_BLEND_COLOR_REVERSE);
|
||||
|
||||
int batterystyle = Settings.System.getIntForUser(getContentResolver(),
|
||||
Settings.System.STATUS_BAR_BATTERY_STYLE, BATTERY_STYLE_PORTRAIT, UserHandle.USER_CURRENT);
|
||||
|
||||
mBatteryStyle = (ListPreference) findPreference(PREF_STATUS_BAR_BATTERY_STYLE);
|
||||
mBatteryStyle.setValue(String.valueOf(batterystyle));
|
||||
mBatteryStyle.setSummary(mBatteryStyle.getEntry());
|
||||
mBatteryStyle.setOnPreferenceChangeListener(this);
|
||||
|
||||
mBatteryPercentValue = Settings.System.getIntForUser(getContentResolver(),
|
||||
Settings.System.STATUS_BAR_SHOW_BATTERY_PERCENT, 0, UserHandle.USER_CURRENT);
|
||||
mBatteryPercentValuePrev = Settings.System.getIntForUser(getContentResolver(),
|
||||
Settings.System.STATUS_BAR_SHOW_BATTERY_PERCENT + "_prev", -1, UserHandle.USER_CURRENT);
|
||||
|
||||
mBatteryPercent = (ListPreference) findPreference(PREF_STATUS_BAR_SHOW_BATTERY_PERCENT);
|
||||
mBatteryPercent.setValue(String.valueOf(mBatteryPercentValue));
|
||||
mBatteryPercent.setSummary(mBatteryPercent.getEntry());
|
||||
mBatteryPercent.setOnPreferenceChangeListener(this);
|
||||
|
||||
/*
|
||||
boolean hasNavBarByDefault = getResources().getBoolean(
|
||||
com.android.internal.R.bool.config_showNavigationBar);
|
||||
@@ -136,13 +167,12 @@ public class BatteryBar extends SettingsPreferenceFragment
|
||||
if (!enableNavigationBar || !batteryBarSupported) {
|
||||
*/
|
||||
prefSet.removePreference(mBatteryBar);
|
||||
/*
|
||||
} else {
|
||||
/* } else {
|
||||
prefSet.removePreference(mBatteryBarNoNavbar);
|
||||
}
|
||||
*/
|
||||
}*/
|
||||
|
||||
updateBatteryBarOptions();
|
||||
updateBatteryOptions(batterystyle, mBatteryPercentValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -203,6 +233,20 @@ public class BatteryBar extends SettingsPreferenceFragment
|
||||
int val = ((Boolean) newValue) ? 1 : 0;
|
||||
Settings.System.putInt(resolver, Settings.System.STATUSBAR_BATTERY_BAR_ANIMATE, val);
|
||||
return true;
|
||||
} else if (preference == mBatteryStyle) {
|
||||
int batterystyle = Integer.parseInt((String) newValue);
|
||||
updateBatteryOptions(batterystyle, mBatteryPercentValue);
|
||||
int index = mBatteryStyle.findIndexOfValue((String) newValue);
|
||||
mBatteryStyle.setSummary(mBatteryStyle.getEntries()[index]);
|
||||
return true;
|
||||
} else if (preference == mBatteryPercent) {
|
||||
mBatteryPercentValue = Integer.parseInt((String) newValue);
|
||||
Settings.System.putIntForUser(resolver,
|
||||
Settings.System.STATUS_BAR_SHOW_BATTERY_PERCENT, mBatteryPercentValue,
|
||||
UserHandle.USER_CURRENT);
|
||||
int index = mBatteryPercent.findIndexOfValue((String) newValue);
|
||||
mBatteryPercent.setSummary(mBatteryPercent.getEntries()[index]);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -232,6 +276,56 @@ public class BatteryBar extends SettingsPreferenceFragment
|
||||
}
|
||||
}
|
||||
|
||||
private void updateBatteryOptions(int batterystyle, int batterypercent) {
|
||||
ContentResolver resolver = getActivity().getContentResolver();
|
||||
switch (batterystyle) {
|
||||
case BATTERY_STYLE_TEXT:
|
||||
handleTextPercentage(BATTERY_PERCENT_SHOW);
|
||||
break;
|
||||
case BATTERY_STYLE_HIDDEN:
|
||||
handleTextPercentage(BATTERY_PERCENT_HIDDEN);
|
||||
break;
|
||||
default:
|
||||
mBatteryPercent.setEnabled(true);
|
||||
if (mBatteryPercentValuePrev != -1) {
|
||||
Settings.System.putIntForUser(resolver,
|
||||
Settings.System.STATUS_BAR_SHOW_BATTERY_PERCENT,
|
||||
mBatteryPercentValuePrev, UserHandle.USER_CURRENT);
|
||||
Settings.System.putIntForUser(resolver,
|
||||
Settings.System.STATUS_BAR_SHOW_BATTERY_PERCENT + "_prev",
|
||||
-1, UserHandle.USER_CURRENT);
|
||||
mBatteryPercentValue = mBatteryPercentValuePrev;
|
||||
mBatteryPercentValuePrev = -1;
|
||||
int index = mBatteryPercent.findIndexOfValue(String.valueOf(mBatteryPercentValue));
|
||||
mBatteryPercent.setSummary(mBatteryPercent.getEntries()[index]);
|
||||
}
|
||||
|
||||
Settings.System.putIntForUser(resolver,
|
||||
Settings.System.STATUS_BAR_BATTERY_STYLE, batterystyle,
|
||||
UserHandle.USER_CURRENT);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void handleTextPercentage(int batterypercent) {
|
||||
ContentResolver resolver = getActivity().getContentResolver();
|
||||
if (mBatteryPercentValuePrev == -1) {
|
||||
mBatteryPercentValuePrev = mBatteryPercentValue;
|
||||
Settings.System.putIntForUser(resolver,
|
||||
Settings.System.STATUS_BAR_SHOW_BATTERY_PERCENT + "_prev",
|
||||
mBatteryPercentValue, UserHandle.USER_CURRENT);
|
||||
}
|
||||
|
||||
Settings.System.putIntForUser(resolver,
|
||||
Settings.System.STATUS_BAR_SHOW_BATTERY_PERCENT,
|
||||
batterypercent, UserHandle.USER_CURRENT);
|
||||
Settings.System.putIntForUser(resolver,
|
||||
Settings.System.STATUS_BAR_BATTERY_STYLE, BATTERY_STYLE_TEXT,
|
||||
UserHandle.USER_CURRENT);
|
||||
int index = mBatteryPercent.findIndexOfValue(String.valueOf(batterypercent));
|
||||
mBatteryPercent.setSummary(mBatteryPercent.getEntries()[index]);
|
||||
mBatteryPercent.setEnabled(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
Reference in New Issue
Block a user