Merge "Revamp battery Ui in low battery mode" into oc-dev
This commit is contained in:
@@ -511,7 +511,7 @@ public class BatteryHistoryChart extends View {
|
||||
elapsedRealtimeUs);
|
||||
mDrainString = "";
|
||||
mChargeDurationString = "";
|
||||
setContentDescription(mInfo.mChargeLabelString);
|
||||
setContentDescription(mInfo.chargeLabelString);
|
||||
|
||||
int pos = 0;
|
||||
int lastInteresting = 0;
|
||||
@@ -589,7 +589,7 @@ public class BatteryHistoryChart extends View {
|
||||
mMaxPercentLabelStringWidth = (int)mTextPaint.measureText(mMaxPercentLabelString);
|
||||
mMinPercentLabelStringWidth = (int)mTextPaint.measureText(mMinPercentLabelString);
|
||||
mDrainStringWidth = (int)mHeaderTextPaint.measureText(mDrainString);
|
||||
mChargeLabelStringWidth = (int)mHeaderTextPaint.measureText(mInfo.mChargeLabelString);
|
||||
mChargeLabelStringWidth = (int)mHeaderTextPaint.measureText(mInfo.chargeLabelString);
|
||||
mChargeDurationStringWidth = (int)mHeaderTextPaint.measureText(mChargeDurationString);
|
||||
mTextAscent = (int)mTextPaint.ascent();
|
||||
mTextDescent = (int)mTextPaint.descent();
|
||||
@@ -974,7 +974,7 @@ public class BatteryHistoryChart extends View {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
i++;
|
||||
}
|
||||
mStats.finishIteratingHistoryLocked();
|
||||
@@ -983,9 +983,9 @@ public class BatteryHistoryChart extends View {
|
||||
if (lastY < 0 || lastX < 0) {
|
||||
// Didn't get any data...
|
||||
x = lastX = mLevelLeft;
|
||||
y = lastY = mLevelTop + levelh - ((mInfo.mBatteryLevel-batLow)*(levelh-1))/batChange;
|
||||
y = lastY = mLevelTop + levelh - ((mInfo.batteryLevel -batLow)*(levelh-1))/batChange;
|
||||
Path path;
|
||||
byte value = (byte)mInfo.mBatteryLevel;
|
||||
byte value = (byte)mInfo.batteryLevel;
|
||||
if (value <= mBatteryCriticalLevel) path = mBatCriticalPath;
|
||||
else if (value <= mBatteryWarnLevel) path = mBatWarnPath;
|
||||
else path = null; //mBatGoodPath;
|
||||
@@ -1014,7 +1014,7 @@ public class BatteryHistoryChart extends View {
|
||||
mTimeRemainPath.moveTo(x, lastY);
|
||||
int fullY = mLevelTop + levelh - ((100-batLow)*(levelh-1))/batChange;
|
||||
int emptyY = mLevelTop + levelh - ((0-batLow)*(levelh-1))/batChange;
|
||||
if (mInfo.mDischarging) {
|
||||
if (mInfo.discharging) {
|
||||
mTimeRemainPath.lineTo(mLevelRight, emptyY);
|
||||
} else {
|
||||
mTimeRemainPath.lineTo(mLevelRight, fullY);
|
||||
@@ -1211,8 +1211,8 @@ public class BatteryHistoryChart extends View {
|
||||
|
||||
int headerTop = -mHeaderTextAscent + (mHeaderTextDescent-mHeaderTextAscent)/3;
|
||||
mHeaderTextPaint.setTextAlign(textAlignLeft);
|
||||
if (DEBUG) Log.d(TAG, "Drawing charge label string: " + mInfo.mChargeLabelString);
|
||||
canvas.drawText(mInfo.mChargeLabelString, textStartX, headerTop, mHeaderTextPaint);
|
||||
if (DEBUG) Log.d(TAG, "Drawing charge label string: " + mInfo.chargeLabelString);
|
||||
canvas.drawText(mInfo.chargeLabelString, textStartX, headerTop, mHeaderTextPaint);
|
||||
int stringHalfWidth = mChargeDurationStringWidth / 2;
|
||||
if (layoutRtl) stringHalfWidth = -stringHalfWidth;
|
||||
int headerCenter = ((width-mChargeDurationStringWidth-mDrainStringWidth)/2)
|
||||
|
@@ -18,17 +18,25 @@ package com.android.settings.fuelgauge;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.ColorFilter;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffColorFilter;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settingslib.graph.BatteryMeterDrawableBase;
|
||||
|
||||
public class BatteryMeterView extends ImageView {
|
||||
private BatteryMeterDrawable mDrawable;
|
||||
@VisibleForTesting
|
||||
BatteryMeterDrawable mDrawable;
|
||||
@VisibleForTesting
|
||||
ColorFilter mErrorColorFilter;
|
||||
@VisibleForTesting
|
||||
ColorFilter mAccentColorFilter;
|
||||
|
||||
public BatteryMeterView(Context context) {
|
||||
this(context, null, 0);
|
||||
@@ -42,21 +50,30 @@ public class BatteryMeterView extends ImageView {
|
||||
super(context, attrs, defStyleAttr);
|
||||
|
||||
final int frameColor = context.getColor(R.color.batterymeter_frame_color);
|
||||
final int tintColor = Utils.getColorAttr(context, android.R.attr.colorAccent);
|
||||
mAccentColorFilter = new PorterDuffColorFilter(
|
||||
Utils.getColorAttr(context, android.R.attr.colorAccent), PorterDuff.Mode.SRC_IN);
|
||||
mErrorColorFilter = new PorterDuffColorFilter(
|
||||
context.getColor(R.color.battery_icon_color_error), PorterDuff.Mode.SRC_IN);
|
||||
|
||||
mDrawable = new BatteryMeterDrawable(context, frameColor);
|
||||
mDrawable.setColorFilter(new PorterDuffColorFilter(tintColor, PorterDuff.Mode.SRC_IN));
|
||||
mDrawable.setShowPercent(false);
|
||||
mDrawable.setBatteryColorFilter(mAccentColorFilter);
|
||||
mDrawable.setWarningColorFilter(
|
||||
new PorterDuffColorFilter(Color.WHITE, PorterDuff.Mode.SRC_IN));
|
||||
setImageDrawable(mDrawable);
|
||||
}
|
||||
|
||||
public void setBatteryInfo(int level) {
|
||||
public void setBatteryLevel(int level) {
|
||||
mDrawable.setBatteryLevel(level);
|
||||
if (level < mDrawable.getCriticalLevel()) {
|
||||
mDrawable.setBatteryColorFilter(mErrorColorFilter);
|
||||
} else {
|
||||
mDrawable.setBatteryColorFilter(mAccentColorFilter);
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void setBatteryDrawable(BatteryMeterDrawable drawable) {
|
||||
mDrawable = drawable;
|
||||
public void setCharging(boolean charging) {
|
||||
mDrawable.setCharging(charging);
|
||||
}
|
||||
|
||||
public static class BatteryMeterDrawable extends BatteryMeterDrawableBase {
|
||||
@@ -81,6 +98,16 @@ public class BatteryMeterView extends ImageView {
|
||||
public int getIntrinsicHeight() {
|
||||
return mIntrinsicHeight;
|
||||
}
|
||||
|
||||
public void setWarningColorFilter(@Nullable ColorFilter colorFilter) {
|
||||
mWarningTextPaint.setColorFilter(colorFilter);
|
||||
}
|
||||
|
||||
public void setBatteryColorFilter(@Nullable ColorFilter colorFilter) {
|
||||
mFramePaint.setColorFilter(colorFilter);
|
||||
mBatteryPaint.setColorFilter(colorFilter);
|
||||
mBoltPaint.setColorFilter(colorFilter);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -561,14 +561,15 @@ public class PowerUsageSummary extends PowerUsageBase {
|
||||
.findViewById(R.id.battery_header_icon);
|
||||
final TextView timeText = (TextView) mBatteryLayoutPref.findViewById(R.id.battery_percent);
|
||||
final TextView summary1 = (TextView) mBatteryLayoutPref.findViewById(R.id.summary1);
|
||||
timeText.setText(Utils.formatPercentage(info.mBatteryLevel));
|
||||
timeText.setText(Utils.formatPercentage(info.batteryLevel));
|
||||
if (info.remainingLabel == null ) {
|
||||
summary1.setText(info.statusLabel);
|
||||
} else {
|
||||
summary1.setText(info.remainingLabel);
|
||||
}
|
||||
|
||||
batteryView.setBatteryInfo(info.mBatteryLevel);
|
||||
batteryView.setBatteryLevel(info.batteryLevel);
|
||||
batteryView.setCharging(!info.discharging);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
@@ -695,7 +696,7 @@ public class PowerUsageSummary extends PowerUsageBase {
|
||||
BatteryInfo.getBatteryInfo(mContext, new BatteryInfo.Callback() {
|
||||
@Override
|
||||
public void onBatteryInfoLoaded(BatteryInfo info) {
|
||||
mLoader.setSummary(SummaryProvider.this, info.mChargeLabelString);
|
||||
mLoader.setSummary(SummaryProvider.this, info.chargeLabelString);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user