Implement battery percent styles (2/2)
Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
This commit is contained in:
@@ -383,4 +383,15 @@
|
|||||||
<item>7</item>
|
<item>7</item>
|
||||||
<item>5</item>
|
<item>5</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="status_bar_battery_percentage_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_percentage_text_next</item>
|
||||||
|
</string-array>
|
||||||
|
<string-array name="status_bar_battery_percentage_values" translatable="false">
|
||||||
|
<item>0</item>
|
||||||
|
<item>1</item>
|
||||||
|
<item>2</item>
|
||||||
|
</string-array>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -485,4 +485,11 @@
|
|||||||
<string name="gaming_mode_title">Game space</string>
|
<string name="gaming_mode_title">Game space</string>
|
||||||
<string name="gaming_mode_summary">Extra features for immersive gaming experience</string>
|
<string name="gaming_mode_summary">Extra features for immersive gaming experience</string>
|
||||||
|
|
||||||
|
<!-- Battery percentage -->
|
||||||
|
<string name="battery_style_category_title">Battery icon</string>
|
||||||
|
<string name="status_bar_battery_percentage_title">Battery percentage</string>
|
||||||
|
<string name="status_bar_battery_percentage_default">Hidden</string>
|
||||||
|
<string name="status_bar_battery_percentage_text_next">Next to the icon</string>
|
||||||
|
<string name="status_bar_battery_percentage_text_inside">Inside the icon</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
27
res/xml/statusbar_battery.xml
Normal file
27
res/xml/statusbar_battery.xml
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Copyright (C) 2016 Nitrogen 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">
|
||||||
|
|
||||||
|
<ListPreference
|
||||||
|
android:key="status_bar_show_battery_percent"
|
||||||
|
android:title="@string/status_bar_battery_percentage_title"
|
||||||
|
android:dialogTitle="@string/status_bar_battery_percentage_title"
|
||||||
|
android:entries="@array/status_bar_battery_percentage_entries"
|
||||||
|
android:entryValues="@array/status_bar_battery_percentage_values" />
|
||||||
|
</PreferenceScreen>
|
||||||
75
src/com/cherish/settings/fragments/StatusBarBattery.java
Normal file
75
src/com/cherish/settings/fragments/StatusBarBattery.java
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2012 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.cherish.settings.fragments;
|
||||||
|
|
||||||
|
import android.content.ContentResolver;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.v7.preference.ListPreference;
|
||||||
|
import android.support.v7.preference.Preference;
|
||||||
|
import android.support.v7.preference.Preference.OnPreferenceChangeListener;
|
||||||
|
import android.provider.Settings;
|
||||||
|
|
||||||
|
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.SettingsPreferenceFragment;
|
||||||
|
|
||||||
|
public class StatusBarBattery extends SettingsPreferenceFragment implements
|
||||||
|
Preference.OnPreferenceChangeListener {
|
||||||
|
|
||||||
|
private static final String SHOW_BATTERY_PERCENT = "status_bar_show_battery_percent";
|
||||||
|
|
||||||
|
private ListPreference mStatusBarBatteryShowPercent;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
addPreferencesFromResource(R.xml.statusbar_battery);
|
||||||
|
|
||||||
|
ContentResolver resolver = getActivity().getContentResolver();
|
||||||
|
|
||||||
|
mStatusBarBatteryShowPercent =
|
||||||
|
(ListPreference) findPreference(SHOW_BATTERY_PERCENT);
|
||||||
|
|
||||||
|
int batteryShowPercent = Settings.System.getInt(resolver,
|
||||||
|
Settings.System.SHOW_BATTERY_PERCENT, 0);
|
||||||
|
mStatusBarBatteryShowPercent.setValue(String.valueOf(batteryShowPercent));
|
||||||
|
mStatusBarBatteryShowPercent.setSummary(mStatusBarBatteryShowPercent.getEntry());
|
||||||
|
mStatusBarBatteryShowPercent.setOnPreferenceChangeListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMetricsCategory() {
|
||||||
|
return MetricsEvent.CHERISH_SETTINGS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
|
ContentResolver resolver = getActivity().getContentResolver();
|
||||||
|
if (preference == mStatusBarBatteryShowPercent) {
|
||||||
|
int batteryShowPercent = Integer.valueOf((String) newValue);
|
||||||
|
int index = mStatusBarBatteryShowPercent.findIndexOfValue((String) newValue);
|
||||||
|
Settings.System.putInt(
|
||||||
|
resolver, Settings.System.SHOW_BATTERY_PERCENT, batteryShowPercent);
|
||||||
|
mStatusBarBatteryShowPercent.setSummary(
|
||||||
|
mStatusBarBatteryShowPercent.getEntries()[index]);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user