Skip to content

Commit 8028517

Browse files
committed
add options to change color of clock and battery percentage
Change-Id: Ic31ce08852ad954476f170788ba8dcabc234223b
1 parent 5eb3b7d commit 8028517

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

apps/SpareParts/res/values/strings.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@
4242
<string name="title_launcher_orientation">Launcher Orientation</string>
4343
<string name="summary_on_launcher_orientation">Disable Launcher rotation"</string>
4444
<string name="summary_off_launcher_orientation">Enable Launcher rotation"</string>
45+
46+
<string name="title_clock_color">Clock color</string>
47+
<string name="summary_clock_color">Change clock color</string>
48+
<string name="dialog_title_clock_color">Select clock color</string>
49+
50+
<string name="title_battery_color">Battery percentage color</string>
51+
<string name="summary_battery_color">Change battery percentage color</string>
52+
<string name="dialog_title_battery_color">Select battery color</string>
4553
<!-- end extra -->
4654

4755
<string name="title_window_animations">Window animations</string>

apps/SpareParts/res/xml/spare_parts.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,18 @@
6464
android:summaryOn="@string/summary_on_launcher_orientation"
6565
android:summaryOff="@string/summary_off_launcher_orientation" />
6666

67+
<Preference
68+
android:key="clock_color"
69+
android:title="@string/title_clock_color"
70+
android:summary="@string/summary_clock_color"
71+
android:defaultValue="-16777216" />
72+
73+
<Preference
74+
android:key="battery_color"
75+
android:title="@string/title_battery_color"
76+
android:summary="@string/summary_battery_color"
77+
android:defaultValue="-1" />
78+
6779
</PreferenceCategory>
6880
<!-- end -->
6981

apps/SpareParts/src/com/android/spare_parts/SpareParts.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ public class SpareParts extends PreferenceActivity
5454
//extra
5555
private static final String MENU_UNLOCK_SCREEN_PREF = "menu_unlock_screen";
5656
private static final String LAUNCHER_ORIENTATION_PREF = "launcher_orientation";
57+
private static final String CLOCK_COLOR_PREF = "clock_color";
58+
private static final String BATTERY_COLOR_PREF = "battery_color";
5759
//end extra
5860

5961
private static final String WINDOW_ANIMATIONS_PREF = "window_animations";
@@ -69,6 +71,8 @@ public class SpareParts extends PreferenceActivity
6971
//extra
7072
private CheckBoxPreference mMenuUnlockScreenPref;
7173
private CheckBoxPreference mLauncherOrientationPref;
74+
private Preference mClockColorPref;
75+
private Preference mBatteryColorPref;
7276
//end extra
7377

7478
private ListPreference mWindowAnimationsPref;
@@ -126,6 +130,8 @@ public void onCreate(Bundle icicle) {
126130
//extra
127131
mMenuUnlockScreenPref = (CheckBoxPreference) prefSet.findPreference(MENU_UNLOCK_SCREEN_PREF);
128132
mLauncherOrientationPref = (CheckBoxPreference) prefSet.findPreference(LAUNCHER_ORIENTATION_PREF);
133+
mClockColorPref = prefSet.findPreference(CLOCK_COLOR_PREF);
134+
mBatteryColorPref = prefSet.findPreference(BATTERY_COLOR_PREF);
129135
//end extra
130136

131137
mWindowAnimationsPref = (ListPreference) prefSet.findPreference(WINDOW_ANIMATIONS_PREF);
@@ -195,6 +201,20 @@ public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preferen
195201
mCompatibilityMode.isChecked() ? 1 : 0);
196202
return true;
197203
}
204+
//extra
205+
else if (preference == mClockColorPref) {
206+
ColorPickerDialog cp = new ColorPickerDialog(this,
207+
mClockFontColorListener,
208+
readClockFontColor());
209+
cp.show();
210+
}
211+
else if (preference == mBatteryColorPref) {
212+
ColorPickerDialog cp = new ColorPickerDialog(this,
213+
mBatteryFontColorListener,
214+
readBatteryFontColor());
215+
cp.show();
216+
}
217+
//end extra
198218
return false;
199219
}
200220

@@ -264,6 +284,37 @@ public void readEndButtonPreference(ListPreference pref) {
264284
}
265285
}
266286

287+
//extra
288+
private int readClockFontColor() {
289+
try {
290+
return Settings.System.getInt(getContentResolver(), Settings.System.CLOCK_COLOR);
291+
}
292+
catch (SettingNotFoundException e) {
293+
return -16777216;
294+
}
295+
}
296+
ColorPickerDialog.OnColorChangedListener mClockFontColorListener =
297+
new ColorPickerDialog.OnColorChangedListener() {
298+
public void colorChanged(int color) {
299+
Settings.System.putInt(getContentResolver(), Settings.System.CLOCK_COLOR, color);
300+
}
301+
};
302+
private int readBatteryFontColor() {
303+
try {
304+
return Settings.System.getInt(getContentResolver(), Settings.System.BATTERY_COLOR);
305+
}
306+
catch (SettingNotFoundException e) {
307+
return -1;
308+
}
309+
}
310+
ColorPickerDialog.OnColorChangedListener mBatteryFontColorListener =
311+
new ColorPickerDialog.OnColorChangedListener() {
312+
public void colorChanged(int color) {
313+
Settings.System.putInt(getContentResolver(), Settings.System.BATTERY_COLOR, color);
314+
}
315+
};
316+
//end extra
317+
267318
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
268319
//extra
269320
if (MENU_UNLOCK_SCREEN_PREF.equals(key)) {

0 commit comments

Comments
 (0)