Skip to content

Commit

Permalink
CarbonFibers: Port BatteryBar [2/2]
Browse files Browse the repository at this point in the history
{x} Adds Battery bar with following features:
{x} location set
{x} color
{x} aligment
{x} thickness
{x} charging animation

Change-Id: I4b1a3dfbcb172ed85e7a211aa2f0a9e03bd99a11
Signed-off-by: STELIX <ssspinni@gmail.com>
  • Loading branch information
STELIX authored and Robert Rascon committed Mar 20, 2014
1 parent 1d1d18a commit c292ceb
Show file tree
Hide file tree
Showing 4 changed files with 198 additions and 11 deletions.
39 changes: 39 additions & 0 deletions res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,45 @@
<item>4</item>
</string-array>

<!-- Battery bar -->
<string-array name="battery_bar_entries">
<item>Hide</item>
<item>Statusbar</item>
<item>Top of navbar</item>
<item>Bottom of navbar</item>
</string-array>

<string-array name="battery_bar_values" translatable="false">
<item>0</item>
<item>1</item>
<item>2</item>
<item>3</item>
</string-array>

<string-array name="battery_bar_style_entries">
<item>Regular</item>
<item>Center-mirrored</item>
</string-array>

<string-array name="battery_bar_style_values" translatable="false">
<item>0</item>
<item>1</item>
</string-array>

<string-array name="battery_bar_thickness_entries" translatable="false">
<item>1 dp</item>
<item>2 dp</item>
<item>3 dp</item>
<item>4 dp</item>
</string-array>

<string-array name="battery_bar_thickness_values" translatable="false">
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
</string-array>

<!-- Lockscreen lock icon values -->
<string-array name="lock_icon_entries">
<item>@string/lockscreen_lock_icon_custom</item>
Expand Down
11 changes: 11 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,17 @@
<string name="status_bar_notif_count_title">Show notification count</string>
<string name="status_bar_notif_count_summary">Display the number of pending notifications</string>

<!-- Battery Bar -->
<string name="status_bar_battery_cat_title">Battery</string>
<string name="battery_bar_title">Battery Bar</string>
<string name="battery_bar">Battery bar location</string>
<string name="battery_bar_color">Battery bar color</string>
<string name="battery_bar_cat">Battery bar style</string>
<string name="battery_bar_style_title">Battery bar alignment</string>
<string name="battery_bar_thickness_title">Battery bar thickness</string>
<string name="battery_bar_animate_title">Charging animation</string>
<string name="battery_bar_animate_summary">The charging animation may result in a poor user experience. Enable at your own discretion.</string>

<!-- QuickSettings fliptiles -->
<string name="flip_qs_tiles_title">Flip tiles on touch</string>

Expand Down
34 changes: 34 additions & 0 deletions res/xml/sb_battery_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,38 @@
android:title="@string/battery_text_charging_color"
android:defaultValue="0xffffffff" />

<PreferenceCategory
android:key="category_status_bar_battery_bar"
android:title="@string/battery_bar_title">

<ListPreference
android:key="battery_bar_list"
android:title="@string/battery_bar"
android:entries="@array/battery_bar_entries"
android:entryValues="@array/battery_bar_values" />

<net.margaritov.preference.colorpicker.ColorPickerPreference
android:key="battery_bar_color"
android:title="@string/battery_bar_color"
android:defaultValue="0xffffffff" />

<ListPreference
android:key="battery_bar_style"
android:title="@string/battery_bar_style_title"
android:entries="@array/battery_bar_style_entries"
android:entryValues="@array/battery_bar_style_values" />

<ListPreference
android:key="battery_bar_thickness"
android:title="@string/battery_bar_thickness_title"
android:entries="@array/battery_bar_thickness_entries"
android:entryValues="@array/battery_bar_thickness_values" />

<CheckBoxPreference
android:key="battery_bar_animate"
android:title="@string/battery_bar_animate_title"
android:summary="@string/battery_bar_animate_summary" />

</PreferenceCategory>

</PreferenceScreen>
125 changes: 114 additions & 11 deletions src/com/carbon/fibers/fragments/sb/BatterySettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.carbon.fibers.fragments.sb;

import android.app.AlertDialog;
import android.content.ContentResolver;
import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.content.res.Resources;
Expand Down Expand Up @@ -53,6 +54,12 @@ public class BatterySettings extends SettingsPreferenceFragment
private static final String PREF_STATUS_BAR_BATTERY_TEXT_CHARGING_COLOR = "battery_text_charging_color";
private static final String PREF_STATUS_BAR_CIRCLE_BATTERY_ANIMATIONSPEED = "circle_battery_animation_speed";

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_WIDTH = "battery_bar_thickness";
private static final String PREF_BATT_ANIMATE = "battery_bar_animate";

private static final int MENU_RESET = Menu.FIRST;

private ListPreference mStatusBarBattery;
Expand All @@ -61,6 +68,12 @@ public class BatterySettings extends SettingsPreferenceFragment
private ColorPickerPreference mBatteryTextChargingColor;
private ListPreference mCircleAnimSpeed;

private ListPreference mBatteryBar;
private ListPreference mBatteryBarStyle;
private ListPreference mBatteryBarThickness;
private CheckBoxPreference mBatteryBarChargingAnimation;
private ColorPickerPreference mBatteryBarColor;

private boolean mCheckPreferences;

@Override
Expand All @@ -79,6 +92,8 @@ private PreferenceScreen createCustomView() {
addPreferencesFromResource(R.xml.sb_battery_settings);
prefSet = getPreferenceScreen();

ContentResolver resolver = getActivity().getContentResolver();

int intColor;
String hexColor;

Expand All @@ -93,14 +108,14 @@ private PreferenceScreen createCustomView() {

mStatusBarBattery = (ListPreference) prefSet.findPreference(PREF_STATUS_BAR_BATTERY);
mStatusBarBattery.setOnPreferenceChangeListener(this);
int statusBarBattery = Settings.System.getInt(getActivity().getContentResolver(),
int statusBarBattery = Settings.System.getInt(resolver,
Settings.System.STATUS_BAR_BATTERY, 0);
mStatusBarBattery.setValue(String.valueOf(statusBarBattery));
mStatusBarBattery.setSummary(mStatusBarBattery.getEntry());

mBatteryColor = (ColorPickerPreference) findPreference(PREF_STATUS_BAR_BATTERY_COLOR);
mBatteryColor.setOnPreferenceChangeListener(this);
intColor = Settings.System.getInt(getActivity().getContentResolver(),
intColor = Settings.System.getInt(resolver,
Settings.System.STATUS_BAR_BATTERY_COLOR, -2);
if (intColor == -2) {
intColor = systemUiResources.getColor(systemUiResources.getIdentifier(
Expand All @@ -115,7 +130,7 @@ private PreferenceScreen createCustomView() {
mBatteryTextColor =
(ColorPickerPreference) findPreference(PREF_STATUS_BAR_BATTERY_TEXT_COLOR);
mBatteryTextColor.setOnPreferenceChangeListener(this);
intColor = Settings.System.getInt(getActivity().getContentResolver(),
intColor = Settings.System.getInt(resolver,
Settings.System.STATUS_BAR_BATTERY_TEXT_COLOR, -2);
mBatteryTextColor.setSummary(getResources().getString(R.string.default_string));
if (intColor == -2 && statusBarBattery == 2) {
Expand All @@ -133,7 +148,7 @@ private PreferenceScreen createCustomView() {
mBatteryTextChargingColor = (ColorPickerPreference)
findPreference(PREF_STATUS_BAR_BATTERY_TEXT_CHARGING_COLOR);
mBatteryTextChargingColor.setOnPreferenceChangeListener(this);
intColor = Settings.System.getInt(getActivity().getContentResolver(),
intColor = Settings.System.getInt(resolver,
Settings.System.STATUS_BAR_BATTERY_TEXT_CHARGING_COLOR, -2);
mBatteryTextChargingColor.setSummary(getResources().getString(R.string.default_string));
if (intColor == -2 && (statusBarBattery == 2 || statusBarBattery == 0)) {
Expand All @@ -152,11 +167,40 @@ private PreferenceScreen createCustomView() {
(ListPreference) findPreference(PREF_STATUS_BAR_CIRCLE_BATTERY_ANIMATIONSPEED);
mCircleAnimSpeed.setOnPreferenceChangeListener(this);
mCircleAnimSpeed.setValue((Settings.System
.getInt(getActivity().getContentResolver(),
Settings.System.STATUS_BAR_CIRCLE_BATTERY_ANIMATIONSPEED, 3))
.getInt(resolver, Settings.System.STATUS_BAR_CIRCLE_BATTERY_ANIMATIONSPEED, 3))
+ "");
mCircleAnimSpeed.setSummary(mCircleAnimSpeed.getEntry());

mBatteryBar = (ListPreference) findPreference(PREF_BATT_BAR);
mBatteryBar.setOnPreferenceChangeListener(this);
mBatteryBar.setValue((Settings.System.getInt(resolver, Settings.System.STATUSBAR_BATTERY_BAR, 0)) + "");
mBatteryBar.setSummary(mBatteryBar.getEntry());

mBatteryBarStyle = (ListPreference) findPreference(PREF_BATT_BAR_STYLE);
mBatteryBarStyle.setOnPreferenceChangeListener(this);
mBatteryBarStyle.setValue((Settings.System.getInt(resolver,
Settings.System.STATUSBAR_BATTERY_BAR_STYLE, 0)) + "");
mBatteryBarStyle.setSummary(mBatteryBarStyle.getEntry());

mBatteryBarColor = (ColorPickerPreference) findPreference(PREF_BATT_BAR_COLOR);
mBatteryBarColor.setOnPreferenceChangeListener(this);
int defaultColor = 0xffffffff;
intColor = Settings.System.getInt(resolver, Settings.System.STATUSBAR_BATTERY_BAR_COLOR, defaultColor);
hexColor = String.format("#%08x", (0xffffffff & intColor));
mBatteryBarColor.setSummary(hexColor);

mBatteryBarChargingAnimation = (CheckBoxPreference) findPreference(PREF_BATT_ANIMATE);
mBatteryBarChargingAnimation.setChecked(Settings.System.getInt(resolver,
Settings.System.STATUSBAR_BATTERY_BAR_ANIMATE, 0) == 1);

mBatteryBarThickness = (ListPreference) findPreference(PREF_BATT_BAR_WIDTH);
mBatteryBarThickness.setOnPreferenceChangeListener(this);
mBatteryBarThickness.setValue((Settings.System.getInt(resolver,
Settings.System.STATUSBAR_BATTERY_BAR_THICKNESS, 1)) + "");
mBatteryBarThickness.setSummary(mBatteryBarThickness.getEntry());

updateBatteryBarOptions();

updateBatteryIconOptions(statusBarBattery);

setHasOptionsMenu(true);
Expand Down Expand Up @@ -197,13 +241,16 @@ public void onClick(DialogInterface dialog, int id) {
}

public boolean onPreferenceChange(Preference preference, Object newValue) {

ContentResolver resolver = getActivity().getContentResolver();

if (!mCheckPreferences) {
return false;
}
if (preference == mStatusBarBattery) {
int statusBarBattery = Integer.valueOf((String) newValue);
int index = mStatusBarBattery.findIndexOfValue((String) newValue);
Settings.System.putInt(getActivity().getContentResolver(),
Settings.System.putInt(resolver,
Settings.System.STATUS_BAR_BATTERY, statusBarBattery);
mStatusBarBattery.setSummary(mStatusBarBattery.getEntries()[index]);
createCustomView();
Expand All @@ -213,32 +260,73 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
.valueOf(String.valueOf(newValue)));
preference.setSummary(hex);
int intHex = ColorPickerPreference.convertToColorInt(hex);
Settings.System.putInt(getActivity().getContentResolver(),
Settings.System.putInt(resolver,
Settings.System.STATUS_BAR_BATTERY_COLOR, intHex);
return true;
} else if (preference == mBatteryTextColor) {
String hex = ColorPickerPreference.convertToARGB(Integer
.valueOf(String.valueOf(newValue)));
preference.setSummary(hex);
int intHex = ColorPickerPreference.convertToColorInt(hex);
Settings.System.putInt(getActivity().getContentResolver(),
Settings.System.putInt(resolver,
Settings.System.STATUS_BAR_BATTERY_TEXT_COLOR, intHex);
return true;
} else if (preference == mBatteryTextChargingColor) {
String hex = ColorPickerPreference.convertToARGB(Integer
.valueOf(String.valueOf(newValue)));
preference.setSummary(hex);
int intHex = ColorPickerPreference.convertToColorInt(hex);
Settings.System.putInt(getActivity().getContentResolver(),
Settings.System.putInt(resolver,
Settings.System.STATUS_BAR_BATTERY_TEXT_CHARGING_COLOR, intHex);
return true;
} else if (preference == mCircleAnimSpeed) {
int val = Integer.parseInt((String) newValue);
int index = mCircleAnimSpeed.findIndexOfValue((String) newValue);
Settings.System.putInt(getActivity().getContentResolver(),
Settings.System.putInt(resolver,
Settings.System.STATUS_BAR_CIRCLE_BATTERY_ANIMATIONSPEED, val);
mCircleAnimSpeed.setSummary(mCircleAnimSpeed.getEntries()[index]);
return true;

} else if (preference == mBatteryBarColor) {
String hex = ColorPickerPreference.convertToARGB(Integer
.valueOf(String.valueOf(newValue)));
preference.setSummary(hex);
int intHex = ColorPickerPreference.convertToColorInt(hex);
Settings.System.putInt(resolver,
Settings.System.STATUSBAR_BATTERY_BAR_COLOR, intHex);
return true;
} else if (preference == mBatteryBar) {
int val = Integer.valueOf((String) newValue);
int index = mBatteryBar.findIndexOfValue((String) newValue);
Settings.System.putInt(resolver, Settings.System.STATUSBAR_BATTERY_BAR, val);
mBatteryBar.setSummary(mBatteryBar.getEntries()[index]);
updateBatteryBarOptions();
return true;
} else if (preference == mBatteryBarStyle) {
int val = Integer.valueOf((String) newValue);
int index = mBatteryBarStyle.findIndexOfValue((String) newValue);
Settings.System.putInt(resolver, Settings.System.STATUSBAR_BATTERY_BAR_STYLE, val);
mBatteryBarStyle.setSummary(mBatteryBarStyle.getEntries()[index]);
return true;
} else if (preference == mBatteryBarThickness) {
int val = Integer.valueOf((String) newValue);
int index = mBatteryBarThickness.findIndexOfValue((String) newValue);
Settings.System.putInt(resolver, Settings.System.STATUSBAR_BATTERY_BAR_THICKNESS, val);
mBatteryBarThickness.setSummary(mBatteryBarThickness.getEntries()[index]);
return true;

}
return false;
}

public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
ContentResolver resolver = getActivity().getContentResolver();
boolean value;
if (preference == mBatteryBarChargingAnimation) {
value = mBatteryBarChargingAnimation.isChecked();
Settings.System.putInt(resolver, Settings.System.STATUSBAR_BATTERY_BAR_ANIMATE, value ? 1 : 0);
return true;

}
return false;
}
Expand Down Expand Up @@ -283,4 +371,19 @@ private void updateBatteryIconOptions(int batteryIconStat) {
}
}

private void updateBatteryBarOptions() {
if (Settings.System.getInt(getActivity().getContentResolver(),
Settings.System.STATUSBAR_BATTERY_BAR, 0) == 0) {
mBatteryBarStyle.setEnabled(false);
mBatteryBarThickness.setEnabled(false);
mBatteryBarChargingAnimation.setEnabled(false);
mBatteryBarColor.setEnabled(false);
} else {
mBatteryBarStyle.setEnabled(true);
mBatteryBarThickness.setEnabled(true);
mBatteryBarChargingAnimation.setEnabled(true);
mBatteryBarColor.setEnabled(true);
}
}

}

0 comments on commit c292ceb

Please sign in to comment.