am eef03831: Merge "Draw status bar battery icon bolt in code." into klp-dev
* commit 'eef03831fdde5a89b88451bcf12274697fe1db99': Draw status bar battery icon bolt in code.
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 2.8 KiB |
@@ -51,5 +51,14 @@
|
|||||||
<item>#FFFF3300</item>
|
<item>#FFFF3300</item>
|
||||||
<item>#FFFFFFFF</item>
|
<item>#FFFFFFFF</item>
|
||||||
</array>
|
</array>
|
||||||
|
<array name="batterymeter_bolt_points">
|
||||||
|
<item>88</item> <item>0</item>
|
||||||
|
<item>459</item><item>1</item>
|
||||||
|
<item>238</item><item>333</item>
|
||||||
|
<item>525</item><item>310</item>
|
||||||
|
<item>120</item><item>840</item>
|
||||||
|
<item>82</item> <item>818</item>
|
||||||
|
<item>246</item><item>373</item>
|
||||||
|
<item>0</item> <item>408</item>
|
||||||
|
</array>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -23,12 +23,13 @@ import android.content.IntentFilter;
|
|||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.LightingColorFilter;
|
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
|
import android.graphics.Path;
|
||||||
|
import android.graphics.PorterDuff;
|
||||||
|
import android.graphics.PorterDuffXfermode;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.graphics.RectF;
|
import android.graphics.RectF;
|
||||||
import android.graphics.Typeface;
|
import android.graphics.Typeface;
|
||||||
import android.graphics.drawable.Drawable;
|
|
||||||
import android.os.BatteryManager;
|
import android.os.BatteryManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
@@ -43,26 +44,27 @@ public class BatteryMeterView extends View implements DemoMode {
|
|||||||
public static final boolean SINGLE_DIGIT_PERCENT = false;
|
public static final boolean SINGLE_DIGIT_PERCENT = false;
|
||||||
public static final boolean SHOW_100_PERCENT = false;
|
public static final boolean SHOW_100_PERCENT = false;
|
||||||
|
|
||||||
private static final LightingColorFilter LIGHTNING_FILTER_OPAQUE =
|
|
||||||
new LightingColorFilter(0x00000000, 0x00000000);
|
|
||||||
private static final LightingColorFilter LIGHTNING_FILTER_TRANS =
|
|
||||||
new LightingColorFilter(0x00999999, 0x00000000);
|
|
||||||
|
|
||||||
public static final int FULL = 96;
|
public static final int FULL = 96;
|
||||||
public static final int EMPTY = 4;
|
public static final int EMPTY = 4;
|
||||||
|
|
||||||
int[] mColors;
|
int[] mColors;
|
||||||
|
|
||||||
boolean mShowPercent = true;
|
boolean mShowPercent = true;
|
||||||
Paint mFramePaint, mBatteryPaint, mWarningTextPaint, mTextPaint;
|
Paint mFramePaint, mBatteryPaint, mWarningTextPaint, mTextPaint, mBoltPaint;
|
||||||
int mButtonHeight;
|
int mButtonHeight;
|
||||||
private float mTextHeight, mWarningTextHeight;
|
private float mTextHeight, mWarningTextHeight;
|
||||||
Drawable mLightning;
|
|
||||||
|
|
||||||
private int mHeight;
|
private int mHeight;
|
||||||
private int mWidth;
|
private int mWidth;
|
||||||
private String mWarningString;
|
private String mWarningString;
|
||||||
private final int mChargeColor;
|
private final int mChargeColor;
|
||||||
|
private final float[] mBoltPoints;
|
||||||
|
private final Path mBoltPath = new Path();
|
||||||
|
|
||||||
|
private final RectF mFrame = new RectF();
|
||||||
|
private final RectF mButtonFrame = new RectF();
|
||||||
|
private final RectF mClipFrame = new RectF();
|
||||||
|
private final Rect mBoltFrame = new Rect();
|
||||||
|
|
||||||
private class BatteryTracker extends BroadcastReceiver {
|
private class BatteryTracker extends BroadcastReceiver {
|
||||||
// current battery status
|
// current battery status
|
||||||
@@ -175,7 +177,8 @@ public class BatteryMeterView extends View implements DemoMode {
|
|||||||
mColors[2*i] = levels.getInt(i, 0);
|
mColors[2*i] = levels.getInt(i, 0);
|
||||||
mColors[2*i+1] = colors.getColor(i, 0);
|
mColors[2*i+1] = colors.getColor(i, 0);
|
||||||
}
|
}
|
||||||
|
levels.recycle();
|
||||||
|
colors.recycle();
|
||||||
mShowPercent = ENABLE_PERCENT && 0 != Settings.System.getInt(
|
mShowPercent = ENABLE_PERCENT && 0 != Settings.System.getInt(
|
||||||
context.getContentResolver(), "status_bar_show_battery_percent", 0);
|
context.getContentResolver(), "status_bar_show_battery_percent", 0);
|
||||||
|
|
||||||
@@ -198,8 +201,28 @@ public class BatteryMeterView extends View implements DemoMode {
|
|||||||
mWarningTextPaint.setTypeface(font);
|
mWarningTextPaint.setTypeface(font);
|
||||||
mWarningTextPaint.setTextAlign(Paint.Align.CENTER);
|
mWarningTextPaint.setTextAlign(Paint.Align.CENTER);
|
||||||
|
|
||||||
mLightning = getResources().getDrawable(R.drawable.lightning);
|
|
||||||
mChargeColor = getResources().getColor(R.color.batterymeter_charge_color);
|
mChargeColor = getResources().getColor(R.color.batterymeter_charge_color);
|
||||||
|
|
||||||
|
mBoltPaint = new Paint();
|
||||||
|
mBoltPaint.setAntiAlias(true);
|
||||||
|
mBoltPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); // punch hole
|
||||||
|
setLayerType(LAYER_TYPE_HARDWARE, null);
|
||||||
|
mBoltPoints = loadBoltPoints(res);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static float[] loadBoltPoints(Resources res) {
|
||||||
|
final int[] pts = res.getIntArray(R.array.batterymeter_bolt_points);
|
||||||
|
int maxX = 0, maxY = 0;
|
||||||
|
for (int i = 0; i < pts.length; i += 2) {
|
||||||
|
maxX = Math.max(maxX, pts[i]);
|
||||||
|
maxY = Math.max(maxY, pts[i + 1]);
|
||||||
|
}
|
||||||
|
final float[] ptsF = new float[pts.length];
|
||||||
|
for (int i = 0; i < pts.length; i += 2) {
|
||||||
|
ptsF[i] = (float)pts[i] / maxX;
|
||||||
|
ptsF[i + 1] = (float)pts[i + 1] / maxY;
|
||||||
|
}
|
||||||
|
return ptsF;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -220,15 +243,6 @@ public class BatteryMeterView extends View implements DemoMode {
|
|||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO jspurlock - remove once we draw hollow bolt in code
|
|
||||||
public void setBarTransparent(boolean isTransparent) {
|
|
||||||
mLightning.setColorFilter(isTransparent ? LIGHTNING_FILTER_TRANS : LIGHTNING_FILTER_OPAQUE);
|
|
||||||
BatteryTracker tracker = mDemoMode ? mDemoTracker : mTracker;
|
|
||||||
if (tracker.plugged) {
|
|
||||||
postInvalidate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Canvas c) {
|
public void draw(Canvas c) {
|
||||||
BatteryTracker tracker = mDemoMode ? mDemoTracker : mTracker;
|
BatteryTracker tracker = mDemoMode ? mDemoTracker : mTracker;
|
||||||
@@ -243,22 +257,19 @@ public class BatteryMeterView extends View implements DemoMode {
|
|||||||
|
|
||||||
mButtonHeight = (int) (height * 0.12f);
|
mButtonHeight = (int) (height * 0.12f);
|
||||||
|
|
||||||
final RectF frame = new RectF(0, 0, width, height);
|
mFrame.set(0, 0, width, height);
|
||||||
frame.offset(pl, pt);
|
mFrame.offset(pl, pt);
|
||||||
|
|
||||||
// Log.v("BatteryGauge", String.format("canvas: %dx%d frame: %s",
|
mButtonFrame.set(
|
||||||
// c.getWidth(), c.getHeight(), frame.toString()));
|
mFrame.left + width * 0.25f,
|
||||||
|
mFrame.top,
|
||||||
|
mFrame.right - width * 0.25f,
|
||||||
|
mFrame.top + mButtonHeight);
|
||||||
|
|
||||||
final RectF buttonframe = new RectF(
|
mFrame.top += mButtonHeight;
|
||||||
frame.left + width * 0.25f,
|
|
||||||
frame.top,
|
|
||||||
frame.right - width * 0.25f,
|
|
||||||
frame.top + mButtonHeight);
|
|
||||||
|
|
||||||
frame.top += mButtonHeight;
|
|
||||||
|
|
||||||
// first, draw the battery shape
|
// first, draw the battery shape
|
||||||
c.drawRect(frame, mFramePaint);
|
c.drawRect(mFrame, mFramePaint);
|
||||||
|
|
||||||
// fill 'er up
|
// fill 'er up
|
||||||
final int pct = tracker.level;
|
final int pct = tracker.level;
|
||||||
@@ -271,15 +282,14 @@ public class BatteryMeterView extends View implements DemoMode {
|
|||||||
drawFrac = 0f;
|
drawFrac = 0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
c.drawRect(buttonframe,
|
c.drawRect(mButtonFrame, drawFrac == 1f ? mBatteryPaint : mFramePaint);
|
||||||
drawFrac == 1f ? mBatteryPaint : mFramePaint);
|
|
||||||
|
|
||||||
RectF clip = new RectF(frame);
|
mClipFrame.set(mFrame);
|
||||||
clip.top += (frame.height() * (1f - drawFrac));
|
mClipFrame.top += (mFrame.height() * (1f - drawFrac));
|
||||||
|
|
||||||
c.save(Canvas.CLIP_SAVE_FLAG);
|
c.save(Canvas.CLIP_SAVE_FLAG);
|
||||||
c.clipRect(clip);
|
c.clipRect(mClipFrame);
|
||||||
c.drawRect(frame, mBatteryPaint);
|
c.drawRect(mFrame, mBatteryPaint);
|
||||||
c.restore();
|
c.restore();
|
||||||
|
|
||||||
if (level <= EMPTY) {
|
if (level <= EMPTY) {
|
||||||
@@ -287,11 +297,28 @@ public class BatteryMeterView extends View implements DemoMode {
|
|||||||
final float y = (mHeight + mWarningTextHeight) * 0.48f;
|
final float y = (mHeight + mWarningTextHeight) * 0.48f;
|
||||||
c.drawText(mWarningString, x, y, mWarningTextPaint);
|
c.drawText(mWarningString, x, y, mWarningTextPaint);
|
||||||
} else if (tracker.plugged) {
|
} else if (tracker.plugged) {
|
||||||
final Rect r = new Rect(
|
// draw the bolt
|
||||||
(int)frame.left + width / 4, (int)frame.top + height / 5,
|
final int bl = (int)(mFrame.left + width / 4f);
|
||||||
(int)frame.right - width / 4, (int)frame.bottom - height / 6);
|
final int bt = (int)(mFrame.top + height / 6f);
|
||||||
mLightning.setBounds(r);
|
final int br = (int)(mFrame.right - width / 5f);
|
||||||
mLightning.draw(c);
|
final int bb = (int)(mFrame.bottom - height / 6f);
|
||||||
|
if (mBoltFrame.left != bl || mBoltFrame.top != bt
|
||||||
|
|| mBoltFrame.right != br || mBoltFrame.bottom != bb) {
|
||||||
|
mBoltFrame.set(bl, bt, br, bb);
|
||||||
|
mBoltPath.reset();
|
||||||
|
mBoltPath.moveTo(
|
||||||
|
mBoltFrame.left + mBoltPoints[0] * mBoltFrame.width(),
|
||||||
|
mBoltFrame.top + mBoltPoints[1] * mBoltFrame.height());
|
||||||
|
for (int i = 2; i < mBoltPoints.length; i += 2) {
|
||||||
|
mBoltPath.lineTo(
|
||||||
|
mBoltFrame.left + mBoltPoints[i] * mBoltFrame.width(),
|
||||||
|
mBoltFrame.top + mBoltPoints[i + 1] * mBoltFrame.height());
|
||||||
|
}
|
||||||
|
mBoltPath.lineTo(
|
||||||
|
mBoltFrame.left + mBoltPoints[0] * mBoltFrame.width(),
|
||||||
|
mBoltFrame.top + mBoltPoints[1] * mBoltFrame.height());
|
||||||
|
}
|
||||||
|
c.drawPath(mBoltPath, mBoltPaint);
|
||||||
} else if (mShowPercent && !(tracker.level == 100 && !SHOW_100_PERCENT)) {
|
} else if (mShowPercent && !(tracker.level == 100 && !SHOW_100_PERCENT)) {
|
||||||
mTextPaint.setTextSize(height *
|
mTextPaint.setTextSize(height *
|
||||||
(SINGLE_DIGIT_PERCENT ? 0.75f
|
(SINGLE_DIGIT_PERCENT ? 0.75f
|
||||||
|
|||||||
@@ -97,7 +97,6 @@ public class PhoneStatusBarView extends PanelBar {
|
|||||||
|
|
||||||
private void applyMode(int mode, boolean animate) {
|
private void applyMode(int mode, boolean animate) {
|
||||||
if (mLeftSide == null || mRightSide == null) return;
|
if (mLeftSide == null || mRightSide == null) return;
|
||||||
mBattery.setBarTransparent(isTransparent(mode));
|
|
||||||
float newAlpha = getAlphaFor(mode);
|
float newAlpha = getAlphaFor(mode);
|
||||||
if (animate) {
|
if (animate) {
|
||||||
ObjectAnimator lhs = animateTransitionTo(mLeftSide, newAlpha);
|
ObjectAnimator lhs = animateTransitionTo(mLeftSide, newAlpha);
|
||||||
|
|||||||
Reference in New Issue
Block a user