Skip to content

Commit

Permalink
Add CmCircleBattery to StatusBar options (1/2)
Browse files Browse the repository at this point in the history
Cyanogenmod Circle Battery implementation
- Done 100% in pure code, wont blow up the framework with countless png resources
- View can be shown with or without percentage as text inside
- Indicator turns holo-red below 15%.
- All sizes are calculated on the fly and should work on all current and
  future screen resolutions. (needs testing)
- All colors are read from the holo-theme, so changes by themers will be obeyed.
- The lower part of the pictures tries to illustrate the charge animation.

Screenshot: http://dl.dropbox.com/u/16186798/cm10/cm-circle-bat-mockup.png

Patchset 2:
- Level >= 95% is treated as 100% (see inline comment)
- paint.setDither(true) should reduce artifacts on 16bit color depth devices
- modified tablet-specific xml. alignment should fit now (not tested yet)
- cleaned up some xml formating derps
- fixed possible crash bug

PS3: 97% seems better than 95% for full circle

Patchset 4+5: lost track of patchsets.

Patchset 6:
The battery fill-up above 97% was a quick shot. In the end,
we show the right percentage in text, but circle fills up, once 97% is
reached. This also solves the issue, that circle with very tiny gap
looks slightly unbalanced.

Also gave in about code formating. Its for the greater good. (I still am
convinced, the whole world is wrong about this :)

Patchset 7:
- Fix derp

Change-Id: I3dfe0b4e69c545cb9bbad2d1461d154618c60e00
  • Loading branch information
Sven-Dawitz authored and DvTonder committed Oct 14, 2012
1 parent 2c79d53 commit bc5b61d
Show file tree
Hide file tree
Showing 7 changed files with 420 additions and 12 deletions.
6 changes: 4 additions & 2 deletions core/java/android/provider/Settings.java
Expand Up @@ -2449,7 +2449,9 @@ public static void setShowGTalkServiceStatus(ContentResolver cr, boolean flag) {
* Display style of the status bar battery information
* 0: Display the stock battery information
* 1: Display cm battery percentage implementation / dont show stock icon
* 2: Hide the battery information
* 2: Display cm circle battery implementation without percentage
* 3: Display cm circle battery implementation with percentage
* 4: Hide the battery information
* default: 0
* @hide
*/
Expand Down Expand Up @@ -2517,7 +2519,7 @@ public static void setShowGTalkServiceStatus(ContentResolver cr, boolean flag) {

/**
* Boolean value whether to link ringtone and notification volumes
*
*
* @hide
*/
public static final String VOLUME_LINK_NOTIFICATION = "volume_link_notification";
Expand Down
10 changes: 10 additions & 0 deletions packages/SystemUI/res/layout/status_bar.xml
Expand Up @@ -110,6 +110,16 @@
android:id="@+id/battery"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:gravity="center_vertical|bottom"
android:paddingLeft="4dip"
/>
<com.android.systemui.statusbar.policy.CircleBattery
android:id="@+id/circle_battery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.StatusBar.Battery"
android:singleLine="true"
android:gravity="bottom"
android:paddingLeft="4dip"
/>
</LinearLayout>
Expand Down
9 changes: 9 additions & 0 deletions packages/SystemUI/res/layout/system_bar_notification_area.xml
Expand Up @@ -144,6 +144,15 @@
android:layout_marginRight="-3dip"
android:gravity="center_vertical|left"
/>
<com.android.systemui.statusbar.policy.CircleBattery
android:id="@+id/dock_circle_battery"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:singleLine="true"
android:paddingLeft="4dip"
android:layout_marginRight="-3dip"
android:gravity="center_vertical|left"
/>
<ImageView
android:id="@+id/dock_battery"
android:layout_height="wrap_content"
Expand Down
Expand Up @@ -153,6 +153,15 @@
android:text="@string/status_bar_settings_settings_button"
/>

<com.android.systemui.statusbar.policy.CircleBattery
android:id="@+id/panel_circle_battery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:paddingLeft="6dp"
android:layout_gravity="center_vertical"
/>

<ImageView
android:id="@+id/battery"
android:layout_height="wrap_content"
Expand Down
Expand Up @@ -41,9 +41,18 @@ public class BatteryController extends BroadcastReceiver {
private ArrayList<ImageView> mIconViews = new ArrayList<ImageView>();
private ArrayList<TextView> mLabelViews = new ArrayList<TextView>();

private static final int BATTERY_STYLE_NORMAL = 0;
private static final int BATTERY_STYLE_TEXT = 1;
private static final int BATTERY_STYLE_GONE = 2;
private static final int BATTERY_STYLE_NORMAL = 0;
private static final int BATTERY_STYLE_PERCENT = 1;
/***
* BATTERY_STYLE_CIRCLE* cannot be handled in this controller, since we cannot get views from
* statusbar here. Yet it is listed for completion and not to confuse at future updates
* See CircleBattery.java for more info
*
* set to public to be reused by CircleBattery
*/
public static final int BATTERY_STYLE_CIRCLE = 2;
public static final int BATTERY_STYLE_CIRCLE_PERCENT = 3;
private static final int BATTERY_STYLE_GONE = 4;

private static final int BATTERY_ICON_STYLE_NORMAL = R.drawable.stat_sys_battery;
private static final int BATTERY_ICON_STYLE_CHARGE = R.drawable.stat_sys_battery_charge;
Expand Down Expand Up @@ -124,11 +133,11 @@ private void updateBattery() {
int mText = View.GONE;
int mIconStyle = BATTERY_ICON_STYLE_NORMAL;

if (mBatteryStyle == 0) {
if (mBatteryStyle == BATTERY_STYLE_NORMAL) {
mIcon = (View.VISIBLE);
mIconStyle = mBatteryPlugged ? BATTERY_ICON_STYLE_CHARGE
: BATTERY_ICON_STYLE_NORMAL;
} else if (mBatteryStyle == 1) {
} else if (mBatteryStyle == BATTERY_STYLE_PERCENT) {
mIcon = (View.VISIBLE);
mText = (View.VISIBLE);
mIconStyle = mBatteryPlugged ? BATTERY_ICON_STYLE_CHARGE_MIN
Expand Down

0 comments on commit bc5b61d

Please sign in to comment.