Cherish:Battery styles: Add battery styles and customizations [2/2]
ezio84: Battery styles: cleanup [2/2] neobuddy89: Simplify code and add battery percentage when charging neobuddy89: Battery Styles: Add customization for QS [2/2] neobuddy89: Allow setting battery percent view on left [2/2] DennySPb: Add back big dotted and big circle battery indicator palaych: Add a summary to battery styles and customizations Co-authored-by: ezio84 <brabus84@gmail.com> Co-authored-by: Pranav Vashi <neobuddy89@gmail.com> Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
This commit is contained in:
@@ -101,5 +101,67 @@
|
||||
<item>23</item>
|
||||
<item>24</item>
|
||||
</string-array>
|
||||
|
||||
<!-- Battery -->
|
||||
<string-array name="status_bar_battery_percent_entries" translatable="false">
|
||||
<item>@string/status_bar_battery_percentage_default</item>
|
||||
<item>@string/status_bar_battery_percentage_text_inside</item>
|
||||
<item>@string/status_bar_battery_percent_text_next_right</item>
|
||||
<item>@string/status_bar_battery_percent_text_next_left</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="status_bar_battery_percent_values" translatable="false">
|
||||
<item>0</item>
|
||||
<item>1</item>
|
||||
<item>2</item>
|
||||
<item>3</item>
|
||||
</string-array>
|
||||
|
||||
<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_big_circle</item>
|
||||
<item>@string/status_bar_battery_style_big_dotted_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>6</item>
|
||||
<item>7</item>
|
||||
<item>4</item>
|
||||
<item>5</item>
|
||||
</string-array>
|
||||
|
||||
<!-- QS battery style -->
|
||||
<string-array name="qs_battery_style_entries" translatable="false">
|
||||
<item>@string/qs_use_status_bar_battery_style</item>
|
||||
<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_big_circle</item>
|
||||
<item>@string/status_bar_battery_style_big_dotted_circle</item>
|
||||
<item>@string/status_bar_battery_style_text</item>
|
||||
<item>@string/status_bar_battery_style_hidden</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="qs_battery_style_values" translatable="false">
|
||||
<item>-1</item>
|
||||
<item>0</item>
|
||||
<item>1</item>
|
||||
<item>2</item>
|
||||
<item>3</item>
|
||||
<item>6</item>
|
||||
<item>7</item>
|
||||
<item>4</item>
|
||||
<item>5</item>
|
||||
</string-array>
|
||||
|
||||
</resources>
|
||||
|
||||
@@ -267,5 +267,32 @@
|
||||
<string name="volte_icon_vimeo">Vimeo Icon</string>
|
||||
<string name="volte_icon_volit">Volit Icon</string>
|
||||
<string name="volte_icon_zirco">Ziroc Icon</string>
|
||||
|
||||
<!-- Statusbar Battery -->
|
||||
<string name="battery_style_title">Battery icon style</string>
|
||||
<string name="battery_style_summary">Customize battery icons, hide or show percentage</string>
|
||||
<string name="battery_style_category_title">Battery icon</string>
|
||||
<string name="status_bar_battery_category_title">In Status Bar</string>
|
||||
<string name="status_bar_battery_percent_title">Battery percentage</string>
|
||||
<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_big_circle">Big circle</string>
|
||||
<string name="status_bar_battery_style_big_dotted_circle">Big dotted circle</string>
|
||||
<string name="status_bar_battery_style_text">Text</string>
|
||||
<string name="status_bar_battery_style_hidden">Hidden</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_percent_text_next_right">Next to the icon (right)</string>
|
||||
<string name="status_bar_battery_percent_text_next_left">Next to the icon (left)</string>
|
||||
<string name="status_bar_battery_text_charging_title">Battery percentage when charging</string>
|
||||
<string name="status_bar_battery_text_charging_summary">Always display battery percentage when charging</string>
|
||||
|
||||
<!-- QS battery -->
|
||||
<string name="qs_battery_category_title">In QS Panel</string>
|
||||
<string name="qs_battery_percent_title" translatable="false">@string/status_bar_battery_percent_title</string>
|
||||
<string name="qs_use_status_bar_battery_style">Follow status bar style</string>
|
||||
|
||||
</resources>
|
||||
|
||||
@@ -21,6 +21,12 @@
|
||||
android:summary="@string/network_traffic_summary"
|
||||
android:fragment="com.cherish.settings.fragments.NetworkTrafficSettings" />
|
||||
|
||||
<Preference
|
||||
android:key="battery_settings"
|
||||
android:fragment="com.cherish.settings.fragments.StatusBarBattery"
|
||||
android:title="@string/battery_style_title"
|
||||
android:summary="@string/battery_style_summary" />
|
||||
|
||||
<PreferenceCategory
|
||||
android:title="@string/status_bar_icons_category_title">
|
||||
|
||||
|
||||
68
res/xml/statusbar_battery.xml
Normal file
68
res/xml/statusbar_battery.xml
Normal file
@@ -0,0 +1,68 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2017-2019 The Dirty Unicorns 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
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:title="@string/battery_style_category_title"
|
||||
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings">
|
||||
|
||||
<!-- Status bar battery customizations -->
|
||||
<PreferenceCategory
|
||||
android:title="@string/status_bar_battery_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/status_bar_battery_percent_title"
|
||||
android:dialogTitle="@string/status_bar_battery_percent_title"
|
||||
android:entries="@array/status_bar_battery_percent_entries"
|
||||
android:entryValues="@array/status_bar_battery_percent_values"
|
||||
android:defaultValue="0" />
|
||||
|
||||
<com.cherish.settings.preferences.SystemSettingSwitchPreference
|
||||
android:key="status_bar_battery_text_charging"
|
||||
android:title="@string/status_bar_battery_text_charging_title"
|
||||
android:summary="@string/status_bar_battery_text_charging_summary"
|
||||
android:defaultValue="true" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<!-- QS panel battery customizations -->
|
||||
<PreferenceCategory
|
||||
android:title="@string/qs_battery_category_title">
|
||||
|
||||
<com.cherish.settings.preferences.SystemSettingListPreference
|
||||
android:key="qs_battery_style"
|
||||
android:title="@string/status_bar_battery_style_title"
|
||||
android:entries="@array/qs_battery_style_entries"
|
||||
android:entryValues="@array/qs_battery_style_values"
|
||||
android:defaultValue="-1" />
|
||||
|
||||
<com.cherish.settings.preferences.SystemSettingListPreference
|
||||
android:key="qs_show_battery_percent"
|
||||
android:title="@string/qs_battery_percent_title"
|
||||
android:entries="@array/status_bar_battery_percent_entries"
|
||||
android:entryValues="@array/status_bar_battery_percent_values"
|
||||
android:defaultValue="2" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
||||
122
src/com/cherish/settings/fragments/StatusBarBattery.java
Normal file
122
src/com/cherish/settings/fragments/StatusBarBattery.java
Normal file
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* Copyright (C) 2017-2019 The Dirty Unicorns 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.
|
||||
*/
|
||||
package com.cherish.settings.fragments;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.preference.PreferenceCategory;
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.preference.Preference.OnPreferenceChangeListener;
|
||||
import androidx.preference.SwitchPreference;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.Utils;
|
||||
|
||||
import com.cherish.settings.preferences.SystemSettingListPreference;
|
||||
import com.cherish.settings.preferences.SystemSettingSwitchPreference;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class StatusBarBattery extends SettingsPreferenceFragment
|
||||
implements Preference.OnPreferenceChangeListener {
|
||||
private static final String STATUS_BAR_SHOW_BATTERY_PERCENT = "status_bar_show_battery_percent";
|
||||
private static final String STATUS_BAR_BATTERY_STYLE = "status_bar_battery_style";
|
||||
private static final String STATUS_BAR_BATTERY_TEXT_CHARGING = "status_bar_battery_text_charging";
|
||||
|
||||
private SwitchPreference mBatteryTextCharging;
|
||||
|
||||
private SystemSettingListPreference mBatteryPercent;
|
||||
private SystemSettingListPreference mBatteryStyle;
|
||||
|
||||
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;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
addPreferencesFromResource(R.xml.statusbar_battery);
|
||||
|
||||
int batterystyle = Settings.System.getIntForUser(getContentResolver(),
|
||||
Settings.System.STATUS_BAR_BATTERY_STYLE, BATTERY_STYLE_PORTRAIT, UserHandle.USER_CURRENT);
|
||||
int batterypercent = Settings.System.getIntForUser(getContentResolver(),
|
||||
Settings.System.STATUS_BAR_SHOW_BATTERY_PERCENT, 0, UserHandle.USER_CURRENT);
|
||||
|
||||
mBatteryStyle = (SystemSettingListPreference) findPreference(STATUS_BAR_BATTERY_STYLE);
|
||||
mBatteryStyle.setOnPreferenceChangeListener(this);
|
||||
|
||||
mBatteryPercent = (SystemSettingListPreference) findPreference(STATUS_BAR_SHOW_BATTERY_PERCENT);
|
||||
mBatteryPercent.setEnabled(
|
||||
batterystyle != BATTERY_STYLE_TEXT && batterystyle != BATTERY_STYLE_HIDDEN);
|
||||
mBatteryPercent.setOnPreferenceChangeListener(this);
|
||||
|
||||
mBatteryTextCharging = (SwitchPreference) findPreference(STATUS_BAR_BATTERY_TEXT_CHARGING);
|
||||
mBatteryTextCharging.setEnabled(batterystyle == BATTERY_STYLE_HIDDEN ||
|
||||
(batterystyle != BATTERY_STYLE_TEXT && batterypercent != 2));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
ContentResolver resolver = getActivity().getContentResolver();
|
||||
if (preference == mBatteryStyle) {
|
||||
int value = Integer.parseInt((String) newValue);
|
||||
int batterypercent = Settings.System.getIntForUser(getContentResolver(),
|
||||
Settings.System.STATUS_BAR_SHOW_BATTERY_PERCENT, 0, UserHandle.USER_CURRENT);
|
||||
mBatteryPercent.setEnabled(
|
||||
value != BATTERY_STYLE_TEXT && value != BATTERY_STYLE_HIDDEN);
|
||||
mBatteryTextCharging.setEnabled(value == BATTERY_STYLE_HIDDEN ||
|
||||
(value != BATTERY_STYLE_TEXT && batterypercent != 2));
|
||||
return true;
|
||||
} else if (preference == mBatteryPercent) {
|
||||
int value = Integer.parseInt((String) newValue);
|
||||
int batterystyle = Settings.System.getIntForUser(getContentResolver(),
|
||||
Settings.System.STATUS_BAR_BATTERY_STYLE, BATTERY_STYLE_PORTRAIT, UserHandle.USER_CURRENT);
|
||||
mBatteryTextCharging.setEnabled(batterystyle == BATTERY_STYLE_HIDDEN ||
|
||||
(batterystyle != BATTERY_STYLE_TEXT && value != 2));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void reset(Context mContext) {
|
||||
ContentResolver resolver = mContext.getContentResolver();
|
||||
Settings.System.putIntForUser(resolver,
|
||||
Settings.System.STATUS_BAR_BATTERY_STYLE, BATTERY_STYLE_PORTRAIT, UserHandle.USER_CURRENT);
|
||||
Settings.System.putIntForUser(resolver,
|
||||
Settings.System.STATUS_BAR_SHOW_BATTERY_PERCENT, 0, UserHandle.USER_CURRENT);
|
||||
Settings.System.putIntForUser(resolver,
|
||||
Settings.System.STATUS_BAR_BATTERY_TEXT_CHARGING, 1, UserHandle.USER_CURRENT);
|
||||
Settings.System.putIntForUser(resolver,
|
||||
Settings.System.QS_BATTERY_STYLE, -1, UserHandle.USER_CURRENT);
|
||||
Settings.System.putIntForUser(resolver,
|
||||
Settings.System.QS_SHOW_BATTERY_PERCENT, 2, UserHandle.USER_CURRENT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user