diff options
author | Simon Davie <nexx@nexxdesign.co.uk> | 2011-10-24 02:12:18 +0100 |
---|---|---|
committer | Simon Davie <nexx@nexxdesign.co.uk> | 2011-10-24 02:12:18 +0100 |
commit | 154ad6904f0630c99c6238f329074ce71ccb8fa1 (patch) | |
tree | 832f3a912c1b7d1e5730052c0269d2b2343a8ca5 /packages | |
parent | cba1d1e6430f72c4e2ab824db68006b3177693de (diff) | |
download | frameworks_base-154ad6904f0630c99c6238f329074ce71ccb8fa1.zip frameworks_base-154ad6904f0630c99c6238f329074ce71ccb8fa1.tar.gz frameworks_base-154ad6904f0630c99c6238f329074ce71ccb8fa1.tar.bz2 |
(1/2) Add status bar battery icon configuration.
Many people resort to editing the compiled frameworks to remove the
battery icon on the status bar. This patch set adds an new option in
CMParts to select between the stock icon, the CyanogenMod percentage
meter, or no battery status at all.
By default the stock battery icon is shown.
Part 2/2: I2cb73df37a4857288dae6ffabb8652c37d76a8ca
Change-Id: Ie73690cfa465f0299f8904cb4f3690898614eb71
Diffstat (limited to 'packages')
3 files changed, 43 insertions, 26 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/CmBatteryMiniIcon.java b/packages/SystemUI/src/com/android/systemui/statusbar/CmBatteryMiniIcon.java index 54f5b6b67..50a0dbe 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/CmBatteryMiniIcon.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/CmBatteryMiniIcon.java @@ -64,8 +64,9 @@ public class CmBatteryMiniIcon extends ImageView { // recalculation of BATTERY_MINI_ICON_MARGIN_RIGHT_DIP to pixels private int mMarginRightPx; - // weather to show this battery widget or not - private boolean mShowCmBattery = false; + // battery style preferences + private static final int BATTERY_STYLE_PERCENT = 1; + private int mStatusBarBattery; // used for animation and still values when not charging/fully charged private int mCurrentFrame = 0; @@ -92,7 +93,7 @@ public class CmBatteryMiniIcon extends ImageView { void observe() { ContentResolver resolver = mContext.getContentResolver(); resolver.registerContentObserver( - Settings.System.getUriFor(Settings.System.STATUS_BAR_CM_BATTERY), false, this); + Settings.System.getUriFor(Settings.System.STATUS_BAR_BATTERY), false, this); } @Override @@ -218,7 +219,7 @@ public class CmBatteryMiniIcon extends ImageView { protected void onDraw(Canvas canvas) { super.onDraw(canvas); - if (!mAttached || !mShowCmBattery) + if (!mAttached || mStatusBarBattery != BATTERY_STYLE_PERCENT) return; canvas.drawBitmap(mMiniIconCache[mCurrentFrame], mMatrix, mPaint); @@ -270,13 +271,15 @@ public class CmBatteryMiniIcon extends ImageView { private void updateSettings() { ContentResolver resolver = mContext.getContentResolver(); - mShowCmBattery = (Settings.System - .getInt(resolver, Settings.System.STATUS_BAR_CM_BATTERY, 0) == 1); + int statusBarBattery = (Settings.System.getInt(resolver, + Settings.System.STATUS_BAR_BATTERY, 2)); + mStatusBarBattery = Integer.valueOf(statusBarBattery); - if (mShowCmBattery) + if (mStatusBarBattery == BATTERY_STYLE_PERCENT) { setVisibility(View.VISIBLE); - else + } else { setVisibility(View.GONE); + } } // should be toggled to private (or inlined at constructor), once StatusBarService.updateResources properly handles theme change diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/CmBatteryText.java b/packages/SystemUI/src/com/android/systemui/statusbar/CmBatteryText.java index da35d33..0dd1616 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/CmBatteryText.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/CmBatteryText.java @@ -34,8 +34,9 @@ import android.widget.TextView; public class CmBatteryText extends TextView { private boolean mAttached; - // weather to show this battery widget or not - private boolean mShowCmBattery; + // battery style preferences + private static final int BATTERY_STYLE_PERCENT = 1; + private int mStatusBarBattery; Handler mHandler; @@ -49,7 +50,7 @@ public class CmBatteryText extends TextView { void observe() { ContentResolver resolver = mContext.getContentResolver(); resolver.registerContentObserver( - Settings.System.getUriFor(Settings.System.STATUS_BAR_CM_BATTERY), false, this); + Settings.System.getUriFor(Settings.System.STATUS_BAR_BATTERY), false, this); } @Override @@ -129,12 +130,14 @@ public class CmBatteryText extends TextView { private void updateSettings() { ContentResolver resolver = mContext.getContentResolver(); - mShowCmBattery = (Settings.System - .getInt(resolver, Settings.System.STATUS_BAR_CM_BATTERY, 0) == 1); + int statusBarBattery = (Settings.System.getInt(resolver, + Settings.System.STATUS_BAR_BATTERY, 2)); + mStatusBarBattery = Integer.valueOf(statusBarBattery); - if (mShowCmBattery) + if (mStatusBarBattery == BATTERY_STYLE_PERCENT) { setVisibility(View.VISIBLE); - else + } else { setVisibility(View.GONE); + } } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarPolicy.java b/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarPolicy.java index a0ec792..c4dcfff 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarPolicy.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarPolicy.java @@ -85,6 +85,10 @@ public class StatusBarPolicy { private static int AM_PM_STYLE = AM_PM_STYLE_GONE; + private static final int BATTERY_STYLE_NORMAL = 0; + private static final int BATTERY_STYLE_PERCENT = 1; + private static final int BATTERY_STYLE_GONE = 2; + private static final int INET_CONDITION_THRESHOLD = 50; private final Context mContext; @@ -602,8 +606,7 @@ public class StatusBarPolicy { } }; - private boolean mShowCmBattery; - private boolean mCmBatteryStatus; + private int mStatusBarBattery; // need another var that superceding mPhoneSignalHidden private boolean mShowCmSignal; @@ -617,7 +620,7 @@ public class StatusBarPolicy { void observe() { ContentResolver resolver = mContext.getContentResolver(); resolver.registerContentObserver(Settings.System.getUriFor( - Settings.System.STATUS_BAR_CM_BATTERY), false, this); + Settings.System.STATUS_BAR_BATTERY), false, this); resolver.registerContentObserver(Settings.System .getUriFor(Settings.System.STATUS_BAR_CM_SIGNAL_TEXT), false, this); @@ -805,10 +808,13 @@ public class StatusBarPolicy { private final void updateBattery(Intent intent) { final int id = intent.getIntExtra("icon-small", 0); int level = intent.getIntExtra("level", 0); - if(!mShowCmBattery || mCmBatteryStatus != mShowCmBattery) { - mService.setIcon("battery", id, level); - mService.setIconVisibility("battery", !mShowCmBattery); - mCmBatteryStatus = mShowCmBattery; + mService.setIcon("battery", id, level); + if(mStatusBarBattery == BATTERY_STYLE_NORMAL) { + mService.setIconVisibility("battery", true); + } else if (mStatusBarBattery == BATTERY_STYLE_PERCENT) { + mService.setIconVisibility("battery", false); + } else if (mStatusBarBattery == BATTERY_STYLE_GONE) { + mService.setIconVisibility("battery", false); } boolean plugged = intent.getIntExtra("plugged", 0) != 0; @@ -1645,10 +1651,15 @@ public class StatusBarPolicy { private void updateSettings(){ ContentResolver resolver = mContext.getContentResolver(); - mShowCmBattery = (Settings.System.getInt(resolver, - Settings.System.STATUS_BAR_CM_BATTERY, 0) == 1); - mCmBatteryStatus = !mShowCmBattery; - mService.setIconVisibility("battery", !mShowCmBattery); + int statusBarBattery = Settings.System.getInt(resolver, + Settings.System.STATUS_BAR_BATTERY, 0); + mStatusBarBattery = Integer.valueOf(statusBarBattery); + + if (mStatusBarBattery == BATTERY_STYLE_NORMAL) { + mService.setIconVisibility("battery", true); + } else if (mStatusBarBattery == BATTERY_STYLE_PERCENT || mStatusBarBattery == BATTERY_STYLE_GONE) { + mService.setIconVisibility("battery", false); + } //0 will hide the cmsignaltext and show the signal bars mShowCmSignal = Settings.System.getInt(mContext.getContentResolver(), |