Merge "Tweak battery usage to match red lines." into lmp-preview-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
a4e854fa5b
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?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");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with 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">
|
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<item android:id="@android:id/background">
|
<item android:id="@android:id/background">
|
||||||
<shape>
|
<nine-patch android:src="@*android:drawable/progress_qntm_alpha"
|
||||||
<solid android:color="#ff28262c" />
|
android:tint="@color/quantum_empty_color_light" />
|
||||||
</shape>
|
|
||||||
</item>
|
</item>
|
||||||
<item android:id="@android:id/secondaryProgress">
|
<item android:id="@android:id/secondaryProgress">
|
||||||
<clip>
|
<scale android:scaleWidth="100%">
|
||||||
<shape>
|
<nine-patch android:src="@*android:drawable/progress_qntm_alpha"
|
||||||
<solid android:color="#c050ade5" />
|
android:tint="?android:attr/colorControlActivated" />
|
||||||
</shape>
|
</scale>
|
||||||
</clip>
|
|
||||||
</item>
|
</item>
|
||||||
<item android:id="@android:id/progress">
|
<item android:id="@android:id/progress">
|
||||||
<clip>
|
<scale android:scaleWidth="100%">
|
||||||
<shape>
|
<nine-patch android:src="@*android:drawable/progress_primary_qntm_alpha"
|
||||||
<solid android:color="#c050ade5" />
|
android:tint="?android:attr/colorControlActivated" />
|
||||||
</shape>
|
</scale>
|
||||||
</clip>
|
|
||||||
</item>
|
</item>
|
||||||
</layer-list>
|
</layer-list>
|
||||||
|
@@ -45,16 +45,16 @@
|
|||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@android:id/text1"
|
android:id="@android:id/text1"
|
||||||
android:layout_marginStart="8dip"
|
android:layout_marginStart="6dip"
|
||||||
android:layout_marginTop="2dip"
|
android:layout_marginTop="2dip"
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||||
|
|
||||||
<ProgressBar
|
<ProgressBar
|
||||||
android:id="@android:id/progress"
|
android:id="@android:id/progress"
|
||||||
android:layout_height="12dip"
|
android:layout_height="8dip"
|
||||||
android:layout_columnSpan="2"
|
android:layout_columnSpan="2"
|
||||||
android:layout_gravity="fill_horizontal|top"
|
android:layout_gravity="fill_horizontal|top"
|
||||||
android:layout_marginTop="4dip"
|
android:layout_marginTop="8dip"
|
||||||
android:max="100"
|
android:max="100"
|
||||||
android:progressDrawable="@drawable/data_usage_bar"
|
android:progressDrawable="@drawable/data_usage_bar"
|
||||||
style="?android:attr/progressBarStyleHorizontal" />
|
style="?android:attr/progressBarStyleHorizontal" />
|
||||||
@@ -64,7 +64,7 @@
|
|||||||
android:layout_width="0dip"
|
android:layout_width="0dip"
|
||||||
android:layout_gravity="fill_horizontal|top"
|
android:layout_gravity="fill_horizontal|top"
|
||||||
android:layout_columnSpan="2"
|
android:layout_columnSpan="2"
|
||||||
android:layout_marginTop="4dip"
|
android:layout_marginTop="6dip"
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
android:maxLines="2"
|
android:maxLines="2"
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||||
|
35
res/layout/battery_history_chart.xml
Normal file
35
res/layout/battery_history_chart.xml
Normal 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>
|
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?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");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -14,19 +14,18 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<com.android.settings.fuelgauge.BatteryHistoryChart
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
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_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
android:minHeight="@dimen/battery_history_chart_height"
|
android:minHeight="@dimen/battery_history_chart_height"
|
||||||
android:gravity="center_vertical"
|
android:paddingEnd="?android:attr/scrollbarSize">
|
||||||
android:id="@+android:id/battery_history_chart"
|
<include layout="@layout/battery_history_chart" />
|
||||||
android:paddingEnd="?android:attr/scrollbarSize"
|
<TextView android:id="@+id/labelsHeader"
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
android:layout_width="match_parent" android:layout_height="48dp"
|
||||||
app:headerAppearance="?android:attr/textAppearanceMedium"
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
android:shadowRadius="4"
|
android:textSize="14sp"
|
||||||
android:shadowColor="?android:attr/colorBackground"
|
android:textColor="?android:attr/colorControlActivated"
|
||||||
android:shadowDx="2"
|
android:gravity="left|center_vertical"
|
||||||
android:shadowDy="2">
|
android:text="@string/power_usage_list_summary" />
|
||||||
</com.android.settings.fuelgauge.BatteryHistoryChart>
|
</LinearLayout>
|
||||||
|
@@ -43,6 +43,12 @@
|
|||||||
<attr name="android:shadowRadius" />
|
<attr name="android:shadowRadius" />
|
||||||
<!-- Text color, typeface, size, and style of header. -->
|
<!-- Text color, typeface, size, and style of header. -->
|
||||||
<attr name="headerAppearance" format="reference" />
|
<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>
|
||||||
|
|
||||||
<declare-styleable name="PercentageBarChart">
|
<declare-styleable name="PercentageBarChart">
|
||||||
|
@@ -57,6 +57,10 @@
|
|||||||
<color name="quantum_orange_A200">#ffffab40</color>
|
<color name="quantum_orange_A200">#ffffab40</color>
|
||||||
<color name="quantum_orange_A400">#ffff9100</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="actionbar_background_color">#ff263238</color>
|
||||||
<color name="dashboard_background_color">#ffe1e1e0</color>
|
<color name="dashboard_background_color">#ffe1e1e0</color>
|
||||||
<color name="switchbar_background_color">#ff384248</color>
|
<color name="switchbar_background_color">#ff384248</color>
|
||||||
|
@@ -3529,8 +3529,18 @@
|
|||||||
<xliff:g id="state">%2$s</xliff:g></string>
|
<xliff:g id="state">%2$s</xliff:g></string>
|
||||||
<!-- [CHAR_LIMIT=40] Label for battery level chart when charging with duration -->
|
<!-- [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>%% -
|
<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">%2$s</xliff:g> until full</string>
|
||||||
(<xliff:g id="time">%3$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 -->
|
<!-- Battery usage since unplugged -->
|
||||||
<string name="battery_since_unplugged">Battery use since unplugged</string>
|
<string name="battery_since_unplugged">Battery use since unplugged</string>
|
||||||
<!-- Battery usage since user reset the stats -->
|
<!-- Battery usage since user reset the stats -->
|
||||||
|
@@ -91,6 +91,8 @@
|
|||||||
<item name="android:colorAccent">@color/quantum_orange_A200</item>
|
<item name="android:colorAccent">@color/quantum_orange_A200</item>
|
||||||
<!-- Redefine the ActionBar style for contentInsetStart -->
|
<!-- Redefine the ActionBar style for contentInsetStart -->
|
||||||
<item name="android:actionBarStyle">@style/Theme.ActionBar</item>
|
<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>
|
||||||
|
|
||||||
<style name="Theme.ActionBar" parent="@android:style/Widget.Quantum.Light.ActionBar.Solid">
|
<style name="Theme.ActionBar" parent="@android:style/Widget.Quantum.Light.ActionBar.Solid">
|
||||||
|
@@ -117,9 +117,6 @@ public class BatteryHistoryChart extends View {
|
|||||||
static final int SERIF = 2;
|
static final int SERIF = 2;
|
||||||
static final int MONOSPACE = 3;
|
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
|
// First value if for phone off; first value is "scanning"; following values
|
||||||
// are battery stats signal strength buckets.
|
// are battery stats signal strength buckets.
|
||||||
static final int NUM_PHONE_SIGNALS = 7;
|
static final int NUM_PHONE_SIGNALS = 7;
|
||||||
@@ -168,6 +165,12 @@ public class BatteryHistoryChart extends View {
|
|||||||
String mCpuRunningLabel;
|
String mCpuRunningLabel;
|
||||||
String mPhoneSignalLabel;
|
String mPhoneSignalLabel;
|
||||||
|
|
||||||
|
int mChartMinHeight;
|
||||||
|
int mHeaderHeight;
|
||||||
|
|
||||||
|
int mBatteryWarnLevel;
|
||||||
|
int mBatteryCriticalLevel;
|
||||||
|
|
||||||
int mTextAscent;
|
int mTextAscent;
|
||||||
int mTextDescent;
|
int mTextDescent;
|
||||||
int mHeaderTextAscent;
|
int mHeaderTextAscent;
|
||||||
@@ -353,18 +356,23 @@ public class BatteryHistoryChart extends View {
|
|||||||
public BatteryHistoryChart(Context context, AttributeSet attrs) {
|
public BatteryHistoryChart(Context context, AttributeSet attrs) {
|
||||||
super(context, 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,
|
mThinLineWidth = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
|
||||||
2, getResources().getDisplayMetrics());
|
2, getResources().getDisplayMetrics());
|
||||||
|
|
||||||
mBatteryBackgroundPaint.setColor(0xff263238);
|
mBatteryBackgroundPaint.setColor(0xFF009688);
|
||||||
mBatteryBackgroundPaint.setStyle(Paint.Style.FILL);
|
mBatteryBackgroundPaint.setStyle(Paint.Style.FILL);
|
||||||
mBatteryGoodPaint.setARGB(128, 0, 255, 0);
|
mBatteryGoodPaint.setARGB(128, 0, 128, 0);
|
||||||
mBatteryGoodPaint.setStyle(Paint.Style.STROKE);
|
mBatteryGoodPaint.setStyle(Paint.Style.STROKE);
|
||||||
mBatteryWarnPaint.setARGB(128, 255, 255, 0);
|
mBatteryWarnPaint.setARGB(128, 128, 128, 0);
|
||||||
mBatteryWarnPaint.setStyle(Paint.Style.STROKE);
|
mBatteryWarnPaint.setStyle(Paint.Style.STROKE);
|
||||||
mBatteryCriticalPaint.setARGB(192, 255, 0, 0);
|
mBatteryCriticalPaint.setARGB(192, 128, 0, 0);
|
||||||
mBatteryCriticalPaint.setStyle(Paint.Style.STROKE);
|
mBatteryCriticalPaint.setStyle(Paint.Style.STROKE);
|
||||||
mTimeRemainPaint.setColor(0xffA5B1B7);
|
mTimeRemainPaint.setColor(0xFFCED7BB);
|
||||||
mTimeRemainPaint.setStyle(Paint.Style.FILL);
|
mTimeRemainPaint.setStyle(Paint.Style.FILL);
|
||||||
mChargingPaint.setARGB(255, 0, 128, 0);
|
mChargingPaint.setARGB(255, 0, 128, 0);
|
||||||
mChargingPaint.setStyle(Paint.Style.STROKE);
|
mChargingPaint.setStyle(Paint.Style.STROKE);
|
||||||
@@ -431,6 +439,18 @@ public class BatteryHistoryChart extends View {
|
|||||||
mainTextAttrs.styleIndex = a.getInt(attr, mainTextAttrs.styleIndex);
|
mainTextAttrs.styleIndex = a.getInt(attr, mainTextAttrs.styleIndex);
|
||||||
headTextAttrs.styleIndex = a.getInt(attr, headTextAttrs.styleIndex);
|
headTextAttrs.styleIndex = a.getInt(attr, headTextAttrs.styleIndex);
|
||||||
break;
|
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;
|
remainingTimeUs = chargeTime;
|
||||||
String timeString = Formatter.formatShortElapsedTime(getContext(),
|
String timeString = Formatter.formatShortElapsedTime(getContext(),
|
||||||
chargeTime / 1000);
|
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(
|
mChargeLabelString = getContext().getResources().getString(
|
||||||
R.string.power_charging_duration, batteryLevel, statusLabel, timeString);
|
resId, batteryLevel, timeString);
|
||||||
} else {
|
} else {
|
||||||
mChargeLabelString = getContext().getResources().getString(
|
mChargeLabelString = getContext().getResources().getString(
|
||||||
R.string.power_charging, batteryLevel, statusLabel);
|
R.string.power_charging, batteryLevel, statusLabel);
|
||||||
@@ -562,19 +593,12 @@ public class BatteryHistoryChart extends View {
|
|||||||
mHavePhoneSignal = true;
|
mHavePhoneSignal = true;
|
||||||
}
|
}
|
||||||
if (mHistEnd <= mHistStart) mHistEnd = mHistStart+1;
|
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
|
@Override
|
||||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
|
||||||
mMaxPercentLabelStringWidth = (int)mTextPaint.measureText(mMaxPercentLabelString);
|
mMaxPercentLabelStringWidth = (int)mTextPaint.measureText(mMaxPercentLabelString);
|
||||||
mMinPercentLabelStringWidth = (int)mTextPaint.measureText(mMinPercentLabelString);
|
mMinPercentLabelStringWidth = (int)mTextPaint.measureText(mMinPercentLabelString);
|
||||||
mDurationStringWidth = (int)mTextPaint.measureText(mDurationString);
|
|
||||||
mDrainStringWidth = (int)mHeaderTextPaint.measureText(mDrainString);
|
mDrainStringWidth = (int)mHeaderTextPaint.measureText(mDrainString);
|
||||||
mChargeLabelStringWidth = (int)mHeaderTextPaint.measureText(mChargeLabelString);
|
mChargeLabelStringWidth = (int)mHeaderTextPaint.measureText(mChargeLabelString);
|
||||||
mChargeDurationStringWidth = (int)mHeaderTextPaint.measureText(mChargeDurationString);
|
mChargeDurationStringWidth = (int)mHeaderTextPaint.measureText(mChargeDurationString);
|
||||||
@@ -582,6 +606,10 @@ public class BatteryHistoryChart extends View {
|
|||||||
mTextDescent = (int)mTextPaint.descent();
|
mTextDescent = (int)mTextPaint.descent();
|
||||||
mHeaderTextAscent = (int)mHeaderTextPaint.ascent();
|
mHeaderTextAscent = (int)mHeaderTextPaint.ascent();
|
||||||
mHeaderTextDescent = (int)mHeaderTextPaint.descent();
|
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,
|
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;
|
mLastHeight = h;
|
||||||
|
|
||||||
int textHeight = mTextDescent - mTextAscent;
|
int textHeight = mTextDescent - mTextAscent;
|
||||||
int headerTextHeight = mHeaderTextDescent - mHeaderTextAscent;
|
if (h > ((textHeight*10)+mChartMinHeight)) {
|
||||||
if (h > (textHeight*12)) {
|
|
||||||
mLargeMode = true;
|
mLargeMode = true;
|
||||||
if (h > (textHeight*15)) {
|
if (h > (textHeight*15)) {
|
||||||
// Plenty of room for the chart.
|
// Plenty of room for the chart.
|
||||||
@@ -693,7 +720,7 @@ public class BatteryHistoryChart extends View {
|
|||||||
}
|
}
|
||||||
if (mLineWidth <= 0) mLineWidth = 1;
|
if (mLineWidth <= 0) mLineWidth = 1;
|
||||||
|
|
||||||
mLevelTop = headerTextHeight*2 - mTextAscent;
|
mLevelTop = mHeaderHeight;
|
||||||
mLevelLeft = mMaxPercentLabelStringWidth + mThinLineWidth*3;
|
mLevelLeft = mMaxPercentLabelStringWidth + mThinLineWidth*3;
|
||||||
mLevelRight = w;
|
mLevelRight = w;
|
||||||
int levelWidth = mLevelRight-mLevelLeft;
|
int levelWidth = mLevelRight-mLevelLeft;
|
||||||
@@ -798,17 +825,19 @@ public class BatteryHistoryChart extends View {
|
|||||||
// Don't plot changes within a pixel.
|
// Don't plot changes within a pixel.
|
||||||
Path path;
|
Path path;
|
||||||
byte value = rec.batteryLevel;
|
byte value = rec.batteryLevel;
|
||||||
if (value <= BATTERY_CRITICAL) path = mBatCriticalPath;
|
if (value <= mBatteryCriticalLevel) path = mBatCriticalPath;
|
||||||
else if (value <= BATTERY_WARN) path = mBatWarnPath;
|
else if (value <= mBatteryWarnLevel) path = mBatWarnPath;
|
||||||
else path = mBatGoodPath;
|
else path = null; //mBatGoodPath;
|
||||||
|
|
||||||
if (path != lastLinePath) {
|
if (path != lastLinePath) {
|
||||||
if (lastLinePath != null) {
|
if (lastLinePath != null) {
|
||||||
lastLinePath.lineTo(x, y);
|
lastLinePath.lineTo(x, y);
|
||||||
}
|
}
|
||||||
|
if (path != null) {
|
||||||
path.moveTo(x, y);
|
path.moveTo(x, y);
|
||||||
|
}
|
||||||
lastLinePath = path;
|
lastLinePath = path;
|
||||||
} else {
|
} else if (path != null) {
|
||||||
path.lineTo(x, y);
|
path.lineTo(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -937,6 +966,7 @@ public class BatteryHistoryChart extends View {
|
|||||||
mTimeRemainPath.close();
|
mTimeRemainPath.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mStartWallTime > 0) {
|
||||||
// Create the time labels at the bottom.
|
// Create the time labels at the bottom.
|
||||||
boolean is24hr = is24Hour();
|
boolean is24hr = is24Hour();
|
||||||
Calendar calStart = Calendar.getInstance();
|
Calendar calStart = Calendar.getInstance();
|
||||||
@@ -988,6 +1018,18 @@ public class BatteryHistoryChart extends View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void addTimeLabel(Calendar cal, int levelLeft, int levelRight, boolean is24hr) {
|
void addTimeLabel(Calendar cal, int levelLeft, int levelRight, boolean is24hr) {
|
||||||
final long walltimeStart = mStartWallTime;
|
final long walltimeStart = mStartWallTime;
|
||||||
final long walltimeChange = mEndWallTime-walltimeStart;
|
final long walltimeChange = mEndWallTime-walltimeStart;
|
||||||
@@ -1031,9 +1073,7 @@ public class BatteryHistoryChart extends View {
|
|||||||
if (DEBUG) Log.d(TAG, "Drawing time remain path.");
|
if (DEBUG) Log.d(TAG, "Drawing time remain path.");
|
||||||
canvas.drawPath(mTimeRemainPath, mTimeRemainPaint);
|
canvas.drawPath(mTimeRemainPath, mTimeRemainPaint);
|
||||||
}
|
}
|
||||||
int durationHalfWidth = mDurationStringWidth / 2;
|
if (mTimeLabels.size() > 1) {
|
||||||
if (layoutRtl) durationHalfWidth = -durationHalfWidth;
|
|
||||||
if (mTimeLabels.size() > 0) {
|
|
||||||
int y = mLevelBottom - mTextAscent + (mThinLineWidth*4);
|
int y = mLevelBottom - mTextAscent + (mThinLineWidth*4);
|
||||||
int ytick = mLevelBottom+mThinLineWidth+(mThinLineWidth/2);
|
int ytick = mLevelBottom+mThinLineWidth+(mThinLineWidth/2);
|
||||||
mTextPaint.setTextAlign(Paint.Align.LEFT);
|
mTextPaint.setTextAlign(Paint.Align.LEFT);
|
||||||
@@ -1072,31 +1112,24 @@ public class BatteryHistoryChart extends View {
|
|||||||
canvas.drawLine(label.x, ytick, label.x, ytick+mThinLineWidth, mTextPaint);
|
canvas.drawLine(label.x, ytick, label.x, ytick+mThinLineWidth, mTextPaint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else if (mDurationString != null) {
|
||||||
|
int y = mLevelBottom - mTextAscent + (mThinLineWidth*4);
|
||||||
if (false) {
|
mTextPaint.setTextAlign(Paint.Align.LEFT);
|
||||||
// Old code for printing label.
|
canvas.drawText(mDurationString,
|
||||||
mTextPaint.setTextAlign(textAlignLeft);
|
mLevelLeft + (mLevelRight-mLevelLeft)/2 - mDurationStringWidth/2,
|
||||||
if (mLargeMode) {
|
y, mTextPaint);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int headerTop = -mHeaderTextAscent + (mHeaderTextDescent-mHeaderTextAscent)/3;
|
int headerTop = -mHeaderTextAscent + (mHeaderTextDescent-mHeaderTextAscent)/3;
|
||||||
mHeaderTextPaint.setTextAlign(textAlignLeft);
|
mHeaderTextPaint.setTextAlign(textAlignLeft);
|
||||||
if (DEBUG) Log.d(TAG, "Drawing charge label string: " + mChargeLabelString);
|
if (DEBUG) Log.d(TAG, "Drawing charge label string: " + mChargeLabelString);
|
||||||
canvas.drawText(mChargeLabelString, textStartX, headerTop, mHeaderTextPaint);
|
canvas.drawText(mChargeLabelString, textStartX, headerTop, mHeaderTextPaint);
|
||||||
durationHalfWidth = mChargeDurationStringWidth / 2;
|
int stringHalfWidth = mChargeDurationStringWidth / 2;
|
||||||
if (layoutRtl) durationHalfWidth = -durationHalfWidth;
|
if (layoutRtl) stringHalfWidth = -stringHalfWidth;
|
||||||
int headerCenter = ((width-mChargeDurationStringWidth-mDrainStringWidth)/2)
|
int headerCenter = ((width-mChargeDurationStringWidth-mDrainStringWidth)/2)
|
||||||
+ (layoutRtl ? mDrainStringWidth : mChargeLabelStringWidth);
|
+ (layoutRtl ? mDrainStringWidth : mChargeLabelStringWidth);
|
||||||
if (DEBUG) Log.d(TAG, "Drawing charge duration string: " + mChargeDurationString);
|
if (DEBUG) Log.d(TAG, "Drawing charge duration string: " + mChargeDurationString);
|
||||||
canvas.drawText(mChargeDurationString, headerCenter - durationHalfWidth, headerTop,
|
canvas.drawText(mChargeDurationString, headerCenter - stringHalfWidth, headerTop,
|
||||||
mHeaderTextPaint);
|
mHeaderTextPaint);
|
||||||
mHeaderTextPaint.setTextAlign(textAlignRight);
|
mHeaderTextPaint.setTextAlign(textAlignRight);
|
||||||
if (DEBUG) Log.d(TAG, "Drawing drain string: " + mDrainString);
|
if (DEBUG) Log.d(TAG, "Drawing drain string: " + mDrainString);
|
||||||
@@ -1181,7 +1214,7 @@ public class BatteryHistoryChart extends View {
|
|||||||
canvas.drawText(mMinPercentLabelString,
|
canvas.drawText(mMinPercentLabelString,
|
||||||
mMaxPercentLabelStringWidth-mMinPercentLabelStringWidth,
|
mMaxPercentLabelStringWidth-mMinPercentLabelStringWidth,
|
||||||
mLevelBottom - mThinLineWidth, mTextPaint);
|
mLevelBottom - mThinLineWidth, mTextPaint);
|
||||||
canvas.drawLine(0, mLevelBottom+mThinLineWidth, width,
|
canvas.drawLine(mLevelLeft/2, mLevelBottom+mThinLineWidth, width,
|
||||||
mLevelBottom+mThinLineWidth, mTextPaint);
|
mLevelBottom+mThinLineWidth, mTextPaint);
|
||||||
|
|
||||||
if (mDateLabels.size() > 0) {
|
if (mDateLabels.size() > 0) {
|
||||||
|
@@ -48,7 +48,7 @@ public class BatteryHistoryDetail extends Fragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
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(
|
BatteryHistoryChart chart = (BatteryHistoryChart)view.findViewById(
|
||||||
R.id.battery_history_chart);
|
R.id.battery_history_chart);
|
||||||
chart.setStats(mStats, mBatteryBroadcast);
|
chart.setStats(mStats, mBatteryBroadcast);
|
||||||
|
@@ -37,6 +37,9 @@ public class BatteryHistoryPreference extends Preference {
|
|||||||
final private BatteryStats mStats;
|
final private BatteryStats mStats;
|
||||||
final private Intent mBatteryBroadcast;
|
final private Intent mBatteryBroadcast;
|
||||||
|
|
||||||
|
private boolean mHideLabels;
|
||||||
|
private View mLabelHeader;
|
||||||
|
|
||||||
public BatteryHistoryPreference(Context context, BatteryStats stats, Intent batteryBroadcast) {
|
public BatteryHistoryPreference(Context context, BatteryStats stats, Intent batteryBroadcast) {
|
||||||
super(context);
|
super(context);
|
||||||
setLayoutResource(R.layout.preference_batteryhistory);
|
setLayoutResource(R.layout.preference_batteryhistory);
|
||||||
@@ -48,6 +51,15 @@ public class BatteryHistoryPreference extends Preference {
|
|||||||
return mStats;
|
return mStats;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setHideLabels(boolean hide) {
|
||||||
|
if (mHideLabels != hide) {
|
||||||
|
mHideLabels = hide;
|
||||||
|
if (mLabelHeader != null) {
|
||||||
|
mLabelHeader.setVisibility(hide ? View.GONE : View.VISIBLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onBindView(View view) {
|
protected void onBindView(View view) {
|
||||||
super.onBindView(view);
|
super.onBindView(view);
|
||||||
@@ -55,5 +67,7 @@ public class BatteryHistoryPreference extends Preference {
|
|||||||
BatteryHistoryChart chart = (BatteryHistoryChart)view.findViewById(
|
BatteryHistoryChart chart = (BatteryHistoryChart)view.findViewById(
|
||||||
R.id.battery_history_chart);
|
R.id.battery_history_chart);
|
||||||
chart.setStats(mStats, mBatteryBroadcast);
|
chart.setStats(mStats, mBatteryBroadcast);
|
||||||
|
mLabelHeader = view.findViewById(R.id.labelsHeader);
|
||||||
|
mLabelHeader.setVisibility(mHideLabels ? View.GONE : View.VISIBLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -64,6 +64,7 @@ public class PowerUsageSummary extends PreferenceFragment {
|
|||||||
|
|
||||||
private UserManager mUm;
|
private UserManager mUm;
|
||||||
|
|
||||||
|
private BatteryHistoryPreference mHistPref;
|
||||||
private PreferenceGroup mAppListGroup;
|
private PreferenceGroup mAppListGroup;
|
||||||
private String mBatteryLevel;
|
private String mBatteryLevel;
|
||||||
private String mBatteryStatus;
|
private String mBatteryStatus;
|
||||||
@@ -210,6 +211,7 @@ public class PowerUsageSummary extends PreferenceFragment {
|
|||||||
private void addNotAvailableMessage() {
|
private void addNotAvailableMessage() {
|
||||||
Preference notAvailable = new Preference(getActivity());
|
Preference notAvailable = new Preference(getActivity());
|
||||||
notAvailable.setTitle(R.string.power_usage_not_available);
|
notAvailable.setTitle(R.string.power_usage_not_available);
|
||||||
|
mHistPref.setHideLabels(true);
|
||||||
mAppListGroup.addPreference(notAvailable);
|
mAppListGroup.addPreference(notAvailable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -233,16 +235,17 @@ public class PowerUsageSummary extends PreferenceFragment {
|
|||||||
|
|
||||||
mStatsHelper.refreshStats(BatteryStats.STATS_SINCE_CHARGED, UserHandle.myUserId());
|
mStatsHelper.refreshStats(BatteryStats.STATS_SINCE_CHARGED, UserHandle.myUserId());
|
||||||
|
|
||||||
BatteryHistoryPreference hist = new BatteryHistoryPreference(
|
mHistPref = new BatteryHistoryPreference(
|
||||||
getActivity(), mStatsHelper.getStats(), mStatsHelper.getBatteryBroadcast());
|
getActivity(), mStatsHelper.getStats(), mStatsHelper.getBatteryBroadcast());
|
||||||
hist.setOrder(-1);
|
mHistPref.setOrder(-1);
|
||||||
mAppListGroup.addPreference(hist);
|
mAppListGroup.addPreference(mHistPref);
|
||||||
|
|
||||||
if (mStatsHelper.getPowerProfile().getAveragePower(
|
if (mStatsHelper.getPowerProfile().getAveragePower(
|
||||||
PowerProfile.POWER_SCREEN_FULL) < 10) {
|
PowerProfile.POWER_SCREEN_FULL) < 10) {
|
||||||
addNotAvailableMessage();
|
addNotAvailableMessage();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
boolean addedSome = false;
|
||||||
final int dischargeAmount = mStatsHelper.getStats().getDischargeAmount(mStatsType);
|
final int dischargeAmount = mStatsHelper.getStats().getDischargeAmount(mStatsType);
|
||||||
List<BatterySipper> usageList = mStatsHelper.getUsageList();
|
List<BatterySipper> usageList = mStatsHelper.getUsageList();
|
||||||
for (int i=0; i<usageList.size(); i++) {
|
for (int i=0; i<usageList.size(); i++) {
|
||||||
@@ -263,9 +266,13 @@ public class PowerUsageSummary extends PreferenceFragment {
|
|||||||
if (sipper.uidObj != null) {
|
if (sipper.uidObj != null) {
|
||||||
pref.setKey(Integer.toString(sipper.uidObj.getUid()));
|
pref.setKey(Integer.toString(sipper.uidObj.getUid()));
|
||||||
}
|
}
|
||||||
|
addedSome = true;
|
||||||
mAppListGroup.addPreference(pref);
|
mAppListGroup.addPreference(pref);
|
||||||
if (mAppListGroup.getPreferenceCount() > (MAX_ITEMS_TO_LIST+1)) break;
|
if (mAppListGroup.getPreferenceCount() > (MAX_ITEMS_TO_LIST+1)) break;
|
||||||
}
|
}
|
||||||
|
if (!addedSome) {
|
||||||
|
addNotAvailableMessage();
|
||||||
|
}
|
||||||
|
|
||||||
BatteryEntry.startRequestQueue();
|
BatteryEntry.startRequestQueue();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user