Merge "Tweak battery usage to match red lines." into lmp-preview-dev

This commit is contained in:
Dianne Hackborn
2014-06-03 00:21:29 +00:00
committed by Android (Google) Code Review
12 changed files with 237 additions and 130 deletions

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2011 The Android Open Source Project
<!-- Copyright (C) 2014 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -16,22 +16,19 @@
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape>
<solid android:color="#ff28262c" />
</shape>
<nine-patch android:src="@*android:drawable/progress_qntm_alpha"
android:tint="@color/quantum_empty_color_light" />
</item>
<item android:id="@android:id/secondaryProgress">
<clip>
<shape>
<solid android:color="#c050ade5" />
</shape>
</clip>
<scale android:scaleWidth="100%">
<nine-patch android:src="@*android:drawable/progress_qntm_alpha"
android:tint="?android:attr/colorControlActivated" />
</scale>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<solid android:color="#c050ade5" />
</shape>
</clip>
<scale android:scaleWidth="100%">
<nine-patch android:src="@*android:drawable/progress_primary_qntm_alpha"
android:tint="?android:attr/colorControlActivated" />
</scale>
</item>
</layer-list>

View File

@@ -45,16 +45,16 @@
<TextView
android:id="@android:id/text1"
android:layout_marginStart="8dip"
android:layout_marginStart="6dip"
android:layout_marginTop="2dip"
android:textAppearance="?android:attr/textAppearanceSmall" />
<ProgressBar
android:id="@android:id/progress"
android:layout_height="12dip"
android:layout_height="8dip"
android:layout_columnSpan="2"
android:layout_gravity="fill_horizontal|top"
android:layout_marginTop="4dip"
android:layout_marginTop="8dip"
android:max="100"
android:progressDrawable="@drawable/data_usage_bar"
style="?android:attr/progressBarStyleHorizontal" />
@@ -64,7 +64,7 @@
android:layout_width="0dip"
android:layout_gravity="fill_horizontal|top"
android:layout_columnSpan="2"
android:layout_marginTop="4dip"
android:layout_marginTop="6dip"
android:visibility="gone"
android:maxLines="2"
android:textAppearance="?android:attr/textAppearanceSmall" />

View File

@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2014 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<com.android.settings.fuelgauge.BatteryHistoryChart
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.android.settings"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:id="@+android:id/battery_history_chart"
android:paddingEnd="?android:attr/scrollbarSize"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#ff000000"
app:headerAppearance="?android:attr/textAppearanceMedium"
android:shadowRadius="4"
android:shadowColor="?android:attr/colorBackground"
android:shadowDx="2"
android:shadowDy="2"
app:barPrimaryColor="?android:attr/colorControlActivated"
app:barPredictionColor="@color/quantum_empty_color_light"
app:chartMinHeight="@dimen/battery_history_chart_height">
</com.android.settings.fuelgauge.BatteryHistoryChart>

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2010 The Android Open Source Project
<!-- Copyright (C) 2014 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -14,19 +14,18 @@
limitations under the License.
-->
<com.android.settings.fuelgauge.BatteryHistoryChart
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.android.settings"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="@dimen/battery_history_chart_height"
android:gravity="center_vertical"
android:id="@+android:id/battery_history_chart"
android:paddingEnd="?android:attr/scrollbarSize"
android:textAppearance="?android:attr/textAppearanceSmall"
app:headerAppearance="?android:attr/textAppearanceMedium"
android:shadowRadius="4"
android:shadowColor="?android:attr/colorBackground"
android:shadowDx="2"
android:shadowDy="2">
</com.android.settings.fuelgauge.BatteryHistoryChart>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:minHeight="@dimen/battery_history_chart_height"
android:paddingEnd="?android:attr/scrollbarSize">
<include layout="@layout/battery_history_chart" />
<TextView android:id="@+id/labelsHeader"
android:layout_width="match_parent" android:layout_height="48dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="14sp"
android:textColor="?android:attr/colorControlActivated"
android:gravity="left|center_vertical"
android:text="@string/power_usage_list_summary" />
</LinearLayout>

View File

@@ -43,6 +43,12 @@
<attr name="android:shadowRadius" />
<!-- Text color, typeface, size, and style of header. -->
<attr name="headerAppearance" format="reference" />
<!-- Primary color of chart. -->
<attr name="barPrimaryColor" format="color|reference" />
<!-- Color of predicted future use part of chart. -->
<attr name="barPredictionColor" format="color|reference" />
<!-- Minimum height of the chart itself. -->
<attr name="chartMinHeight" format="dimension|reference" />
</declare-styleable>
<declare-styleable name="PercentageBarChart">

View File

@@ -57,6 +57,10 @@
<color name="quantum_orange_A200">#ffffab40</color>
<color name="quantum_orange_A400">#ffff9100</color>
<color name="quantum_accent_color_light">#FF009688</color>
<color name="quantum_accent_color_dark">#FF80CBC4</color>
<color name="quantum_empty_color_light">#FFCED7DB</color>
<color name="actionbar_background_color">#ff263238</color>
<color name="dashboard_background_color">#ffe1e1e0</color>
<color name="switchbar_background_color">#ff384248</color>

View File

@@ -3529,8 +3529,18 @@
<xliff:g id="state">%2$s</xliff:g></string>
<!-- [CHAR_LIMIT=40] Label for battery level chart when charging with duration -->
<string name="power_charging_duration"><xliff:g id="level">%1$d</xliff:g>%% -
<xliff:g id="state">%2$s</xliff:g>
(<xliff:g id="time">%3$s</xliff:g> until full)</string>
<xliff:g id="time">%2$s</xliff:g> until full</string>
<!-- [CHAR_LIMIT=40] Label for battery level chart when charging with duration -->
<string name="power_charging_duration_ac"><xliff:g id="level">%1$d</xliff:g>%% -
<xliff:g id="time">%2$s</xliff:g> until full on AC</string>
<!-- [CHAR_LIMIT=40] Label for battery level chart when charging with duration -->
<string name="power_charging_duration_usb"><xliff:g id="level">%1$d</xliff:g>%% -
<xliff:g id="time">%2$s</xliff:g> until full over USB</string>
<!-- [CHAR_LIMIT=40] Label for battery level chart when charging with duration -->
<string name="power_charging_duration_wireless"><xliff:g id="level">%1$d</xliff:g>%% -
<xliff:g id="time">%2$s</xliff:g> until full from wireless</string>
<!-- [CHAR_LIMIT=40] Label for list of apps using battery in power use UI -->
<string name="power_usage_list_summary">Use since last full charge</string>
<!-- Battery usage since unplugged -->
<string name="battery_since_unplugged">Battery use since unplugged</string>
<!-- Battery usage since user reset the stats -->

View File

@@ -91,6 +91,8 @@
<item name="android:colorAccent">@color/quantum_orange_A200</item>
<!-- Redefine the ActionBar style for contentInsetStart -->
<item name="android:actionBarStyle">@style/Theme.ActionBar</item>
<!-- Redefine control activited color for progress bars and the like -->
<item name="android:colorControlActivated">@color/quantum_accent_color_light</item>
</style>
<style name="Theme.ActionBar" parent="@android:style/Widget.Quantum.Light.ActionBar.Solid">

View File

@@ -117,9 +117,6 @@ public class BatteryHistoryChart extends View {
static final int SERIF = 2;
static final int MONOSPACE = 3;
static final int BATTERY_WARN = 29;
static final int BATTERY_CRITICAL = 14;
// First value if for phone off; first value is "scanning"; following values
// are battery stats signal strength buckets.
static final int NUM_PHONE_SIGNALS = 7;
@@ -167,7 +164,13 @@ public class BatteryHistoryChart extends View {
String mWifiRunningLabel;
String mCpuRunningLabel;
String mPhoneSignalLabel;
int mChartMinHeight;
int mHeaderHeight;
int mBatteryWarnLevel;
int mBatteryCriticalLevel;
int mTextAscent;
int mTextDescent;
int mHeaderTextAscent;
@@ -352,19 +355,24 @@ public class BatteryHistoryChart extends View {
public BatteryHistoryChart(Context context, AttributeSet attrs) {
super(context, attrs);
mBatteryWarnLevel = mContext.getResources().getInteger(
com.android.internal.R.integer.config_lowBatteryWarningLevel);
mBatteryCriticalLevel = mContext.getResources().getInteger(
com.android.internal.R.integer.config_criticalBatteryWarningLevel);
mThinLineWidth = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
2, getResources().getDisplayMetrics());
mBatteryBackgroundPaint.setColor(0xff263238);
mBatteryBackgroundPaint.setColor(0xFF009688);
mBatteryBackgroundPaint.setStyle(Paint.Style.FILL);
mBatteryGoodPaint.setARGB(128, 0, 255, 0);
mBatteryGoodPaint.setARGB(128, 0, 128, 0);
mBatteryGoodPaint.setStyle(Paint.Style.STROKE);
mBatteryWarnPaint.setARGB(128, 255, 255, 0);
mBatteryWarnPaint.setARGB(128, 128, 128, 0);
mBatteryWarnPaint.setStyle(Paint.Style.STROKE);
mBatteryCriticalPaint.setARGB(192, 255, 0, 0);
mBatteryCriticalPaint.setARGB(192, 128, 0, 0);
mBatteryCriticalPaint.setStyle(Paint.Style.STROKE);
mTimeRemainPaint.setColor(0xffA5B1B7);
mTimeRemainPaint.setColor(0xFFCED7BB);
mTimeRemainPaint.setStyle(Paint.Style.FILL);
mChargingPaint.setARGB(255, 0, 128, 0);
mChargingPaint.setStyle(Paint.Style.STROKE);
@@ -431,6 +439,18 @@ public class BatteryHistoryChart extends View {
mainTextAttrs.styleIndex = a.getInt(attr, mainTextAttrs.styleIndex);
headTextAttrs.styleIndex = a.getInt(attr, headTextAttrs.styleIndex);
break;
case R.styleable.BatteryHistoryChart_barPrimaryColor:
mBatteryBackgroundPaint.setColor(a.getInt(attr, 0));
break;
case R.styleable.BatteryHistoryChart_barPredictionColor:
mTimeRemainPaint.setColor(a.getInt(attr, 0));
break;
case R.styleable.BatteryHistoryChart_chartMinHeight:
mChartMinHeight = a.getDimensionPixelSize(attr, 0);
break;
}
}
@@ -502,8 +522,19 @@ public class BatteryHistoryChart extends View {
remainingTimeUs = chargeTime;
String timeString = Formatter.formatShortElapsedTime(getContext(),
chargeTime / 1000);
int plugType = mBatteryBroadcast.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0);
int resId;
if (plugType == BatteryManager.BATTERY_PLUGGED_AC) {
resId = R.string.power_charging_duration_ac;
} else if (plugType == BatteryManager.BATTERY_PLUGGED_USB) {
resId = R.string.power_charging_duration_usb;
} else if (plugType == BatteryManager.BATTERY_PLUGGED_WIRELESS) {
resId = R.string.power_charging_duration_wireless;
} else {
resId = R.string.power_charging_duration;
}
mChargeLabelString = getContext().getResources().getString(
R.string.power_charging_duration, batteryLevel, statusLabel, timeString);
resId, batteryLevel, timeString);
} else {
mChargeLabelString = getContext().getResources().getString(
R.string.power_charging, batteryLevel, statusLabel);
@@ -562,19 +593,12 @@ public class BatteryHistoryChart extends View {
mHavePhoneSignal = true;
}
if (mHistEnd <= mHistStart) mHistEnd = mHistStart+1;
//String durationString = Utils.formatElapsedTime(getContext(), mStatsPeriod / 1000, true);
//mDurationString = getContext().getString(R.string.battery_stats_on_battery,
// durationString);
mDurationString = Utils.formatElapsedTime(getContext(), mHistEnd - mHistStart, true);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
mMaxPercentLabelStringWidth = (int)mTextPaint.measureText(mMaxPercentLabelString);
mMinPercentLabelStringWidth = (int)mTextPaint.measureText(mMinPercentLabelString);
mDurationStringWidth = (int)mTextPaint.measureText(mDurationString);
mDrainStringWidth = (int)mHeaderTextPaint.measureText(mDrainString);
mChargeLabelStringWidth = (int)mHeaderTextPaint.measureText(mChargeLabelString);
mChargeDurationStringWidth = (int)mHeaderTextPaint.measureText(mChargeDurationString);
@@ -582,6 +606,10 @@ public class BatteryHistoryChart extends View {
mTextDescent = (int)mTextPaint.descent();
mHeaderTextAscent = (int)mHeaderTextPaint.ascent();
mHeaderTextDescent = (int)mHeaderTextPaint.descent();
int headerTextHeight = mHeaderTextDescent - mHeaderTextAscent;
mHeaderHeight = headerTextHeight*2 - mTextAscent;
setMeasuredDimension(getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec),
getDefaultSize(mChartMinHeight+mHeaderHeight, heightMeasureSpec));
}
void finishPaths(int w, int h, int levelh, int startX, int y, Path curLevelPath,
@@ -669,8 +697,7 @@ public class BatteryHistoryChart extends View {
mLastHeight = h;
int textHeight = mTextDescent - mTextAscent;
int headerTextHeight = mHeaderTextDescent - mHeaderTextAscent;
if (h > (textHeight*12)) {
if (h > ((textHeight*10)+mChartMinHeight)) {
mLargeMode = true;
if (h > (textHeight*15)) {
// Plenty of room for the chart.
@@ -693,7 +720,7 @@ public class BatteryHistoryChart extends View {
}
if (mLineWidth <= 0) mLineWidth = 1;
mLevelTop = headerTextHeight*2 - mTextAscent;
mLevelTop = mHeaderHeight;
mLevelLeft = mMaxPercentLabelStringWidth + mThinLineWidth*3;
mLevelRight = w;
int levelWidth = mLevelRight-mLevelLeft;
@@ -798,17 +825,19 @@ public class BatteryHistoryChart extends View {
// Don't plot changes within a pixel.
Path path;
byte value = rec.batteryLevel;
if (value <= BATTERY_CRITICAL) path = mBatCriticalPath;
else if (value <= BATTERY_WARN) path = mBatWarnPath;
else path = mBatGoodPath;
if (value <= mBatteryCriticalLevel) path = mBatCriticalPath;
else if (value <= mBatteryWarnLevel) path = mBatWarnPath;
else path = null; //mBatGoodPath;
if (path != lastLinePath) {
if (lastLinePath != null) {
lastLinePath.lineTo(x, y);
}
path.moveTo(x, y);
if (path != null) {
path.moveTo(x, y);
}
lastLinePath = path;
} else {
} else if (path != null) {
path.lineTo(x, y);
}
@@ -937,54 +966,67 @@ public class BatteryHistoryChart extends View {
mTimeRemainPath.close();
}
// Create the time labels at the bottom.
boolean is24hr = is24Hour();
Calendar calStart = Calendar.getInstance();
calStart.setTimeInMillis(mStartWallTime);
calStart.set(Calendar.MILLISECOND, 0);
calStart.set(Calendar.SECOND, 0);
calStart.set(Calendar.MINUTE, 0);
long startRoundTime = calStart.getTimeInMillis();
if (startRoundTime < mStartWallTime) {
calStart.set(Calendar.HOUR_OF_DAY, calStart.get(Calendar.HOUR_OF_DAY)+1);
startRoundTime = calStart.getTimeInMillis();
}
Calendar calEnd = Calendar.getInstance();
calEnd.setTimeInMillis(mEndWallTime);
calEnd.set(Calendar.MILLISECOND, 0);
calEnd.set(Calendar.SECOND, 0);
calEnd.set(Calendar.MINUTE, 0);
long endRoundTime = calEnd.getTimeInMillis();
if (startRoundTime < endRoundTime) {
addTimeLabel(calStart, mLevelLeft, mLevelRight, is24hr);
Calendar calMid = Calendar.getInstance();
calMid.setTimeInMillis(mStartWallTime+((mEndWallTime-mStartWallTime)/2));
calMid.set(Calendar.MILLISECOND, 0);
calMid.set(Calendar.SECOND, 0);
calMid.set(Calendar.MINUTE, 0);
long calMidMillis = calMid.getTimeInMillis();
if (calMidMillis > startRoundTime && calMidMillis < endRoundTime) {
addTimeLabel(calMid, mLevelLeft, mLevelRight, is24hr);
}
addTimeLabel(calEnd, mLevelLeft, mLevelRight, is24hr);
}
// Create the date labels if the chart includes multiple days
if (calStart.get(Calendar.DAY_OF_YEAR) != calEnd.get(Calendar.DAY_OF_YEAR) ||
calStart.get(Calendar.YEAR) != calEnd.get(Calendar.YEAR)) {
boolean isDayFirst = isDayFirst();
calStart.set(Calendar.HOUR_OF_DAY, 0);
startRoundTime = calStart.getTimeInMillis();
if (mStartWallTime > 0) {
// Create the time labels at the bottom.
boolean is24hr = is24Hour();
Calendar calStart = Calendar.getInstance();
calStart.setTimeInMillis(mStartWallTime);
calStart.set(Calendar.MILLISECOND, 0);
calStart.set(Calendar.SECOND, 0);
calStart.set(Calendar.MINUTE, 0);
long startRoundTime = calStart.getTimeInMillis();
if (startRoundTime < mStartWallTime) {
calStart.set(Calendar.DAY_OF_YEAR, calStart.get(Calendar.DAY_OF_YEAR) + 1);
calStart.set(Calendar.HOUR_OF_DAY, calStart.get(Calendar.HOUR_OF_DAY)+1);
startRoundTime = calStart.getTimeInMillis();
}
calEnd.set(Calendar.HOUR_OF_DAY, 0);
endRoundTime = calEnd.getTimeInMillis();
Calendar calEnd = Calendar.getInstance();
calEnd.setTimeInMillis(mEndWallTime);
calEnd.set(Calendar.MILLISECOND, 0);
calEnd.set(Calendar.SECOND, 0);
calEnd.set(Calendar.MINUTE, 0);
long endRoundTime = calEnd.getTimeInMillis();
if (startRoundTime < endRoundTime) {
addDateLabel(calStart, mLevelLeft, mLevelRight, isDayFirst);
addTimeLabel(calStart, mLevelLeft, mLevelRight, is24hr);
Calendar calMid = Calendar.getInstance();
calMid.setTimeInMillis(mStartWallTime+((mEndWallTime-mStartWallTime)/2));
calMid.set(Calendar.MILLISECOND, 0);
calMid.set(Calendar.SECOND, 0);
calMid.set(Calendar.MINUTE, 0);
long calMidMillis = calMid.getTimeInMillis();
if (calMidMillis > startRoundTime && calMidMillis < endRoundTime) {
addTimeLabel(calMid, mLevelLeft, mLevelRight, is24hr);
}
addTimeLabel(calEnd, mLevelLeft, mLevelRight, is24hr);
}
addDateLabel(calEnd, mLevelLeft, mLevelRight, isDayFirst);
// Create the date labels if the chart includes multiple days
if (calStart.get(Calendar.DAY_OF_YEAR) != calEnd.get(Calendar.DAY_OF_YEAR) ||
calStart.get(Calendar.YEAR) != calEnd.get(Calendar.YEAR)) {
boolean isDayFirst = isDayFirst();
calStart.set(Calendar.HOUR_OF_DAY, 0);
startRoundTime = calStart.getTimeInMillis();
if (startRoundTime < mStartWallTime) {
calStart.set(Calendar.DAY_OF_YEAR, calStart.get(Calendar.DAY_OF_YEAR) + 1);
startRoundTime = calStart.getTimeInMillis();
}
calEnd.set(Calendar.HOUR_OF_DAY, 0);
endRoundTime = calEnd.getTimeInMillis();
if (startRoundTime < endRoundTime) {
addDateLabel(calStart, mLevelLeft, mLevelRight, isDayFirst);
}
addDateLabel(calEnd, mLevelLeft, mLevelRight, isDayFirst);
}
}
if (mTimeLabels.size() < 2) {
// If there are fewer than 2 time labels, then they are useless. Just
// show an axis label giving the entire duration.
mDurationString = Formatter.formatShortElapsedTime(getContext(),
mEndWallTime - mStartWallTime);
mDurationStringWidth = (int)mTextPaint.measureText(mDurationString);
} else {
mDurationString = null;
mDurationStringWidth = 0;
}
}
@@ -1031,9 +1073,7 @@ public class BatteryHistoryChart extends View {
if (DEBUG) Log.d(TAG, "Drawing time remain path.");
canvas.drawPath(mTimeRemainPath, mTimeRemainPaint);
}
int durationHalfWidth = mDurationStringWidth / 2;
if (layoutRtl) durationHalfWidth = -durationHalfWidth;
if (mTimeLabels.size() > 0) {
if (mTimeLabels.size() > 1) {
int y = mLevelBottom - mTextAscent + (mThinLineWidth*4);
int ytick = mLevelBottom+mThinLineWidth+(mThinLineWidth/2);
mTextPaint.setTextAlign(Paint.Align.LEFT);
@@ -1072,31 +1112,24 @@ public class BatteryHistoryChart extends View {
canvas.drawLine(label.x, ytick, label.x, ytick+mThinLineWidth, mTextPaint);
}
}
}
if (false) {
// Old code for printing label.
mTextPaint.setTextAlign(textAlignLeft);
if (mLargeMode) {
canvas.drawText(mDurationString, (width / 2) - durationHalfWidth,
mLevelBottom - mTextAscent + mThinLineWidth, mTextPaint);
} else {
canvas.drawText(mDurationString, (width / 2) - durationHalfWidth,
mLevelTop + ((height-mLevelTop) / 2) - ((mTextDescent - mTextAscent) / 2)
- mTextAscent, mTextPaint);
}
} else if (mDurationString != null) {
int y = mLevelBottom - mTextAscent + (mThinLineWidth*4);
mTextPaint.setTextAlign(Paint.Align.LEFT);
canvas.drawText(mDurationString,
mLevelLeft + (mLevelRight-mLevelLeft)/2 - mDurationStringWidth/2,
y, mTextPaint);
}
int headerTop = -mHeaderTextAscent + (mHeaderTextDescent-mHeaderTextAscent)/3;
mHeaderTextPaint.setTextAlign(textAlignLeft);
if (DEBUG) Log.d(TAG, "Drawing charge label string: " + mChargeLabelString);
canvas.drawText(mChargeLabelString, textStartX, headerTop, mHeaderTextPaint);
durationHalfWidth = mChargeDurationStringWidth / 2;
if (layoutRtl) durationHalfWidth = -durationHalfWidth;
int stringHalfWidth = mChargeDurationStringWidth / 2;
if (layoutRtl) stringHalfWidth = -stringHalfWidth;
int headerCenter = ((width-mChargeDurationStringWidth-mDrainStringWidth)/2)
+ (layoutRtl ? mDrainStringWidth : mChargeLabelStringWidth);
if (DEBUG) Log.d(TAG, "Drawing charge duration string: " + mChargeDurationString);
canvas.drawText(mChargeDurationString, headerCenter - durationHalfWidth, headerTop,
canvas.drawText(mChargeDurationString, headerCenter - stringHalfWidth, headerTop,
mHeaderTextPaint);
mHeaderTextPaint.setTextAlign(textAlignRight);
if (DEBUG) Log.d(TAG, "Drawing drain string: " + mDrainString);
@@ -1181,7 +1214,7 @@ public class BatteryHistoryChart extends View {
canvas.drawText(mMinPercentLabelString,
mMaxPercentLabelStringWidth-mMinPercentLabelStringWidth,
mLevelBottom - mThinLineWidth, mTextPaint);
canvas.drawLine(0, mLevelBottom+mThinLineWidth, width,
canvas.drawLine(mLevelLeft/2, mLevelBottom+mThinLineWidth, width,
mLevelBottom+mThinLineWidth, mTextPaint);
if (mDateLabels.size() > 0) {

View File

@@ -48,7 +48,7 @@ public class BatteryHistoryDetail extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.preference_batteryhistory, null);
View view = inflater.inflate(R.layout.battery_history_chart, null);
BatteryHistoryChart chart = (BatteryHistoryChart)view.findViewById(
R.id.battery_history_chart);
chart.setStats(mStats, mBatteryBroadcast);

View File

@@ -37,6 +37,9 @@ public class BatteryHistoryPreference extends Preference {
final private BatteryStats mStats;
final private Intent mBatteryBroadcast;
private boolean mHideLabels;
private View mLabelHeader;
public BatteryHistoryPreference(Context context, BatteryStats stats, Intent batteryBroadcast) {
super(context);
setLayoutResource(R.layout.preference_batteryhistory);
@@ -48,6 +51,15 @@ public class BatteryHistoryPreference extends Preference {
return mStats;
}
public void setHideLabels(boolean hide) {
if (mHideLabels != hide) {
mHideLabels = hide;
if (mLabelHeader != null) {
mLabelHeader.setVisibility(hide ? View.GONE : View.VISIBLE);
}
}
}
@Override
protected void onBindView(View view) {
super.onBindView(view);
@@ -55,5 +67,7 @@ public class BatteryHistoryPreference extends Preference {
BatteryHistoryChart chart = (BatteryHistoryChart)view.findViewById(
R.id.battery_history_chart);
chart.setStats(mStats, mBatteryBroadcast);
mLabelHeader = view.findViewById(R.id.labelsHeader);
mLabelHeader.setVisibility(mHideLabels ? View.GONE : View.VISIBLE);
}
}

View File

@@ -64,6 +64,7 @@ public class PowerUsageSummary extends PreferenceFragment {
private UserManager mUm;
private BatteryHistoryPreference mHistPref;
private PreferenceGroup mAppListGroup;
private String mBatteryLevel;
private String mBatteryStatus;
@@ -210,6 +211,7 @@ public class PowerUsageSummary extends PreferenceFragment {
private void addNotAvailableMessage() {
Preference notAvailable = new Preference(getActivity());
notAvailable.setTitle(R.string.power_usage_not_available);
mHistPref.setHideLabels(true);
mAppListGroup.addPreference(notAvailable);
}
@@ -233,16 +235,17 @@ public class PowerUsageSummary extends PreferenceFragment {
mStatsHelper.refreshStats(BatteryStats.STATS_SINCE_CHARGED, UserHandle.myUserId());
BatteryHistoryPreference hist = new BatteryHistoryPreference(
mHistPref = new BatteryHistoryPreference(
getActivity(), mStatsHelper.getStats(), mStatsHelper.getBatteryBroadcast());
hist.setOrder(-1);
mAppListGroup.addPreference(hist);
mHistPref.setOrder(-1);
mAppListGroup.addPreference(mHistPref);
if (mStatsHelper.getPowerProfile().getAveragePower(
PowerProfile.POWER_SCREEN_FULL) < 10) {
addNotAvailableMessage();
return;
}
boolean addedSome = false;
final int dischargeAmount = mStatsHelper.getStats().getDischargeAmount(mStatsType);
List<BatterySipper> usageList = mStatsHelper.getUsageList();
for (int i=0; i<usageList.size(); i++) {
@@ -263,9 +266,13 @@ public class PowerUsageSummary extends PreferenceFragment {
if (sipper.uidObj != null) {
pref.setKey(Integer.toString(sipper.uidObj.getUid()));
}
addedSome = true;
mAppListGroup.addPreference(pref);
if (mAppListGroup.getPreferenceCount() > (MAX_ITEMS_TO_LIST+1)) break;
}
if (!addedSome) {
addNotAvailableMessage();
}
BatteryEntry.startRequestQueue();
}