Issue #15986092: Add power tracking of flashlight.
Also improve drawing of date markers to allow a middle marker for really looong durations. Change-Id: I0c12ec9b6de102360d9171627787462dfa58b7ef
This commit is contained in:
@@ -3625,6 +3625,8 @@
|
||||
|
||||
<!-- Label for power consumed by the screen -->
|
||||
<string name="power_screen">Screen</string>
|
||||
<!-- Label for power consumed by the flashlight -->
|
||||
<string name="power_flashlight">Flashlight</string>
|
||||
<!-- Label for power consumed by Wi-Fi -->
|
||||
<string name="power_wifi">Wi\u2011Fi</string>
|
||||
<!-- Label for power consumed by Bluetooth -->
|
||||
|
@@ -150,6 +150,10 @@ public class BatteryEntry {
|
||||
name = context.getResources().getString(R.string.power_screen);
|
||||
iconId = R.drawable.ic_settings_display;
|
||||
break;
|
||||
case FLASHLIGHT:
|
||||
name = context.getResources().getString(R.string.power_flashlight);
|
||||
iconId = R.drawable.ic_settings_display;
|
||||
break;
|
||||
case APP:
|
||||
name = sipper.packageWithHighestDrain;
|
||||
break;
|
||||
|
@@ -17,6 +17,7 @@
|
||||
package com.android.settings.fuelgauge;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.DashPathEffect;
|
||||
import android.os.BatteryManager;
|
||||
import android.provider.Settings;
|
||||
@@ -219,6 +220,9 @@ public class BatteryHistoryChart extends View {
|
||||
final ArrayList<TimeLabel> mTimeLabels = new ArrayList<TimeLabel>();
|
||||
final ArrayList<DateLabel> mDateLabels = new ArrayList<DateLabel>();
|
||||
|
||||
Bitmap mBitmap;
|
||||
Canvas mCanvas;
|
||||
|
||||
static class TextAttrs {
|
||||
ColorStateList textColor = null;
|
||||
int textSize = 15;
|
||||
@@ -339,6 +343,8 @@ public class BatteryHistoryChart extends View {
|
||||
public BatteryHistoryChart(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
if (DEBUG) Log.d(TAG, "New BatteryHistoryChart!");
|
||||
|
||||
mBatteryWarnLevel = mContext.getResources().getInteger(
|
||||
com.android.internal.R.integer.config_lowBatteryWarningLevel);
|
||||
mBatteryCriticalLevel = mContext.getResources().getInteger(
|
||||
@@ -468,6 +474,8 @@ public class BatteryHistoryChart extends View {
|
||||
mStats = stats;
|
||||
mBatteryBroadcast = broadcast;
|
||||
|
||||
if (DEBUG) Log.d(TAG, "Setting stats...");
|
||||
|
||||
final long elapsedRealtimeUs = SystemClock.elapsedRealtime() * 1000;
|
||||
|
||||
long uSecTime = mStats.computeBatteryRealtime(elapsedRealtimeUs,
|
||||
@@ -687,8 +695,12 @@ public class BatteryHistoryChart extends View {
|
||||
return;
|
||||
}
|
||||
|
||||
if (DEBUG) Log.d(TAG, "Rebuilding chart for: " + w + "x" + h);
|
||||
|
||||
mLastWidth = w;
|
||||
mLastHeight = h;
|
||||
mBitmap = null;
|
||||
mCanvas = null;
|
||||
|
||||
int textHeight = mTextDescent - mTextAscent;
|
||||
if (h > ((textHeight*10)+mChartMinHeight)) {
|
||||
@@ -1025,6 +1037,13 @@ public class BatteryHistoryChart extends View {
|
||||
endRoundTime = calEnd.getTimeInMillis();
|
||||
if (startRoundTime < endRoundTime) {
|
||||
addDateLabel(calStart, mLevelLeft, mLevelRight, isDayFirst);
|
||||
Calendar calMid = Calendar.getInstance();
|
||||
calMid.setTimeInMillis(startRoundTime + ((endRoundTime - startRoundTime) / 2));
|
||||
calMid.set(Calendar.HOUR_OF_DAY, 0);
|
||||
long calMidMillis = calMid.getTimeInMillis();
|
||||
if (calMidMillis > startRoundTime && calMidMillis < endRoundTime) {
|
||||
addDateLabel(calMid, mLevelLeft, mLevelRight, isDayFirst);
|
||||
}
|
||||
}
|
||||
addDateLabel(calEnd, mLevelLeft, mLevelRight, isDayFirst);
|
||||
}
|
||||
@@ -1067,8 +1086,27 @@ public class BatteryHistoryChart extends View {
|
||||
final int width = getWidth();
|
||||
final int height = getHeight();
|
||||
|
||||
if (DEBUG) Log.d(TAG, "onDraw: " + width + "x" + height);
|
||||
//buildBitmap(width, height);
|
||||
|
||||
if (DEBUG) Log.d(TAG, "onDraw: " + width + "x" + height);
|
||||
//canvas.drawBitmap(mBitmap, 0, 0, null);
|
||||
drawChart(canvas, width, height);
|
||||
}
|
||||
|
||||
void buildBitmap(int width, int height) {
|
||||
if (mBitmap != null && width == mBitmap.getWidth() && height == mBitmap.getHeight()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (DEBUG) Log.d(TAG, "buildBitmap: " + width + "x" + height);
|
||||
|
||||
mBitmap = Bitmap.createBitmap(getResources().getDisplayMetrics(), width, height,
|
||||
Bitmap.Config.ARGB_8888);
|
||||
mCanvas = new Canvas(mBitmap);
|
||||
drawChart(mCanvas, width, height);
|
||||
}
|
||||
|
||||
void drawChart(Canvas canvas, int width, int height) {
|
||||
final boolean layoutRtl = isLayoutRtl();
|
||||
final int textStartX = layoutRtl ? width : 0;
|
||||
final int textEndX = layoutRtl ? 0 : width;
|
||||
|
Reference in New Issue
Block a user