Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gingerbread #1

Open
wants to merge 3 commits into
base: gingerbread
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions core/java/android/provider/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -2326,13 +2326,18 @@ 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
* 2: Display status bar battery
* 3: Hide the battery information
* 2: Hide the battery information
* 3: Display status bar battery
* default: 0
* @hide
*/
public static final String STATUS_BAR_BATTERY = "status_bar_battery";


/**
* Color for the status bar battery style
*/
public static final String STATUS_BAR_BATTERY_COLOR = "status_bar_battery_color";

/**
* Whether to show the clock in status bar
* of the stock battery icon
Expand Down
13 changes: 6 additions & 7 deletions packages/SystemUI/res/drawable/battery_bar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<solid android:color="#ff0000" />
</shape>
</item>
<item android:maxLevel="3000">
<item android:maxLevel="2000">
<shape>
<corners android:radius="5dip" />
<solid android:color="#ffff00" />
Expand All @@ -26,15 +26,14 @@
<shape>
<corners android:radius="5dip" />
<gradient
android:startColor="#ffffd300"
android:centerColor="#ffffb600"
android:centerY="0.75"
android:endColor="#ffffcb00"
android:angle="270" />
android:startColor="#ff7aa600"
android:endColor="#ff94d400"
android:centerColor="#ff89bf00"
android:angle="0" />
</shape>
</item>
</level-list>
</clip>
</item>

</layer-list>
</layer-list>
141 changes: 80 additions & 61 deletions packages/SystemUI/src/com/android/systemui/statusbar/CmBatteryBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,27 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.database.ContentObserver;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.drawable.Animatable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.os.BatteryManager;
import android.os.Handler;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.widget.ProgressBar;

public class CmBatteryBar extends ProgressBar {
public class CmBatteryBar extends ProgressBar implements Animatable, Runnable {

private static final String TAG = "CmBatteryBar";
private static final String TAG = CmBatteryBar.class.getSimpleName();

// Total animation duration
private static final int ANIM_DURATION = 5000; // 5 seconds

// Duration between frames of charging animation
private static final int FRAME_DURATION = ANIM_DURATION / 100;

// Are we listening for actions?
private boolean mAttached = false;
Expand All @@ -29,9 +41,6 @@ public class CmBatteryBar extends ProgressBar {
// Current "step" of charging animation
private int mChargingLevel = -1;

// Duration between frames of charging animation
private int mAnimDuration = 500;

// Are we charging?
private boolean mBatteryCharging = false;

Expand All @@ -47,6 +56,9 @@ void observer() {
ContentResolver resolver = mContext.getContentResolver();
resolver.registerContentObserver(
Settings.System.getUriFor(Settings.System.STATUS_BAR_BATTERY), false, this);
resolver.registerContentObserver(
Settings.System.getUriFor(Settings.System.STATUS_BAR_BATTERY_COLOR), false,
this);
}

@Override
Expand All @@ -55,31 +67,6 @@ public void onChange(boolean selfChange) {
}
}

private final Runnable onFakeTimer = new Runnable() {
@Override
public void run() {
if (mChargingLevel > -1) {
if (mChargingLevel < 20) {
mChargingLevel += mChargingLevel % 5;
} else if (mChargingLevel < 90) {
mChargingLevel += mChargingLevel % 10;
}
setProgress(mChargingLevel);
if (mChargingLevel >= 100) {
mChargingLevel = mBatteryLevel;
} else {
if (mChargingLevel < 20) {
mChargingLevel += 5;
} else {
mChargingLevel += 10;
}
}
invalidate();
mHandler.postDelayed(onFakeTimer, mAnimDuration);
}
}
};

public CmBatteryBar(Context context) {
this(context, null);
}
Expand Down Expand Up @@ -128,59 +115,91 @@ public void onReceive(Context context, Intent intent) {
mBatteryLevel = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0);
mBatteryCharging = intent.getIntExtra(BatteryManager.EXTRA_STATUS, 0) == BatteryManager.BATTERY_STATUS_CHARGING;
if (mBatteryCharging && mBatteryLevel < 100) {
startTimer();
if (mBatteryLevel % 10 == 0) {
updateAnimDuration();
}
start();
} else {
stopTimer();
stop();
}
} else if (Intent.ACTION_SCREEN_OFF.equals(action)) {
stopTimer();
stop();
} else if (Intent.ACTION_SCREEN_ON.equals(action)) {
if (mBatteryCharging && mBatteryLevel < 100) {
startTimer();
start();
}
}
}
};

private void updateAnimDuration() {
mAnimDuration = 200 + (mBatteryLevel / 10) * 50;
}

private void startTimer() {
if (mChargingLevel == -1) {
mHandler.removeCallbacks(onFakeTimer);
updateAnimDuration();
mChargingLevel = mBatteryLevel;
invalidate();
mHandler.postDelayed(onFakeTimer, mAnimDuration);
}
}

private void stopTimer() {
mHandler.removeCallbacks(onFakeTimer);
setProgress(mBatteryLevel);
mChargingLevel = -1;
invalidate();
}

private void updateSettings() {
ContentResolver resolver = mContext.getContentResolver();
mShowCmBatteryBar = (Settings.System.getInt(resolver,
Settings.System.STATUS_BAR_BATTERY, 0) == 2);
Settings.System.STATUS_BAR_BATTERY, 0) == 3);
if (mShowCmBatteryBar) {
setVisibility(VISIBLE);
} else {
setVisibility(GONE);
}

Drawable d = getProgressDrawable();
if (d instanceof LayerDrawable) {
Drawable bar = ((LayerDrawable) d)
.findDrawableByLayerId(com.android.internal.R.id.progress);
if (bar != null) {
String color = Settings.System
.getString(resolver, Settings.System.STATUS_BAR_BATTERY_COLOR);
Integer barColor = null;
if (!TextUtils.isEmpty(color)) {
try {
barColor = Color.parseColor(color);
} catch (IllegalArgumentException e) {
}
}
if (barColor != null) {
bar.setColorFilter(barColor, PorterDuff.Mode.SRC);
} else {
bar.clearColorFilter();
}
invalidate();
}
}

if (mBatteryCharging && mBatteryLevel < 100) {
startTimer();
start();
} else {
stopTimer();
stop();
}
}

@Override
public void run() {
mChargingLevel++;
if (mChargingLevel > 100) {
mChargingLevel = mBatteryLevel;
}
setProgress(mChargingLevel);
mHandler.postDelayed(this, FRAME_DURATION);
}

@Override
public void start() {
if (!isRunning()) {
mHandler.removeCallbacks(this);
mChargingLevel = mBatteryLevel;
mHandler.postDelayed(this, FRAME_DURATION);
}
}

@Override
public void stop() {
if (isRunning()) {
mHandler.removeCallbacks(this);
mChargingLevel = -1;
}
setProgress(mBatteryLevel);
}

@Override
public boolean isRunning() {
return mChargingLevel != -1;
}

}