summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/widget
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2011-07-17 20:31:40 -0700
committerJeff Sharkey <jsharkey@android.com>2011-07-17 20:31:54 -0700
commit2412b0f2489d5fde811d802b39a0a00d861b5ddf (patch)
tree2863b38d2cc6d6e463b8c614365f0601f517cf4c /src/com/android/settings/widget
parentabc95ee82295b82ad0475a8b4c55a5196a5f014a (diff)
downloadpackages_apps_settings-2412b0f2489d5fde811d802b39a0a00d861b5ddf.zip
packages_apps_settings-2412b0f2489d5fde811d802b39a0a00d861b5ddf.tar.gz
packages_apps_settings-2412b0f2489d5fde811d802b39a0a00d861b5ddf.tar.bz2
Data usage app bars, draw estimated cycle usage.
Show application list with normalized percentage data usage as horizontal bar chart. Draw estimated usage for remainder of cycle to reinforce log scale, and break out received/sent when showing app details. Bug: 5038591, 4948713, 4818025 Change-Id: Ib71e73d4f692adc7fe8ae87edd0cec2a8f3976d3
Diffstat (limited to 'src/com/android/settings/widget')
-rw-r--r--src/com/android/settings/widget/ChartNetworkSeriesView.java50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/com/android/settings/widget/ChartNetworkSeriesView.java b/src/com/android/settings/widget/ChartNetworkSeriesView.java
index 10d8976..51c3c2c 100644
--- a/src/com/android/settings/widget/ChartNetworkSeriesView.java
+++ b/src/com/android/settings/widget/ChartNetworkSeriesView.java
@@ -16,6 +16,9 @@
package com.android.settings.widget;
+import static android.text.format.DateUtils.DAY_IN_MILLIS;
+import static android.text.format.DateUtils.WEEK_IN_MILLIS;
+
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
@@ -46,11 +49,13 @@ public class ChartNetworkSeriesView extends View {
private Paint mPaintStroke;
private Paint mPaintFill;
private Paint mPaintFillSecondary;
+ private Paint mPaintEstimate;
private NetworkStatsHistory mStats;
private Path mPathStroke;
private Path mPathFill;
+ private Path mPathEstimate;
private long mPrimaryLeft;
private long mPrimaryRight;
@@ -81,6 +86,7 @@ public class ChartNetworkSeriesView extends View {
mPathStroke = new Path();
mPathFill = new Path();
+ mPathEstimate = new Path();
}
void init(ChartAxis horiz, ChartAxis vert) {
@@ -104,6 +110,12 @@ public class ChartNetworkSeriesView extends View {
mPaintFillSecondary.setColor(fillSecondary);
mPaintFillSecondary.setStyle(Style.FILL);
mPaintFillSecondary.setAntiAlias(true);
+
+ mPaintEstimate = new Paint();
+ mPaintEstimate.setStrokeWidth(3.0f);
+ mPaintEstimate.setColor(fillSecondary);
+ mPaintEstimate.setStyle(Style.STROKE);
+ mPaintEstimate.setAntiAlias(true);
}
public void bindNetworkStats(NetworkStatsHistory stats) {
@@ -111,6 +123,7 @@ public class ChartNetworkSeriesView extends View {
mPathStroke.reset();
mPathFill.reset();
+ mPathEstimate.reset();
invalidate();
}
@@ -138,6 +151,7 @@ public class ChartNetworkSeriesView extends View {
mPathStroke.reset();
mPathFill.reset();
+ mPathEstimate.reset();
// bail when not enough stats to render
if (mStats == null || mStats.size() < 2) return;
@@ -149,6 +163,7 @@ public class ChartNetworkSeriesView extends View {
float firstX = 0;
float lastX = 0;
float lastY = 0;
+ long lastTime = Long.MIN_VALUE;
// TODO: count fractional data from first bucket crossing start;
// currently it only accepts first full bucket.
@@ -159,6 +174,7 @@ public class ChartNetworkSeriesView extends View {
for (int i = 0; i < mStats.size(); i++) {
entry = mStats.getValues(i, entry);
+ lastTime = entry.bucketStart;
final float x = mHoriz.convertToPoint(entry.bucketStart);
final float y = mVert.convertToPoint(totalData);
@@ -193,6 +209,35 @@ public class ChartNetworkSeriesView extends View {
// drop to bottom of graph from current location
mPathFill.lineTo(lastX, height);
mPathFill.lineTo(firstX, height);
+
+ // build estimated data
+ mPathEstimate.moveTo(lastX, lastY);
+
+ final long now = System.currentTimeMillis();
+ final long bucketDuration = mStats.getBucketDuration();
+
+ // long window is average over two weeks
+ entry = mStats.getValues(lastTime - WEEK_IN_MILLIS * 2, lastTime, now, entry);
+ final long longWindow = (entry.rxBytes + entry.txBytes) * bucketDuration
+ / entry.bucketDuration;
+
+ long futureTime = 0;
+ while (lastX < width) {
+ futureTime += bucketDuration;
+
+ // short window is day average last week
+ final long lastWeekTime = lastTime - WEEK_IN_MILLIS + (futureTime % WEEK_IN_MILLIS);
+ entry = mStats.getValues(lastWeekTime - DAY_IN_MILLIS, lastWeekTime, now, entry);
+ final long shortWindow = (entry.rxBytes + entry.txBytes) * bucketDuration
+ / entry.bucketDuration;
+
+ totalData += (longWindow * 7 + shortWindow * 3) / 10;
+
+ lastX = mHoriz.convertToPoint(lastTime + futureTime);
+ final float y = mVert.convertToPoint(totalData);
+
+ mPathEstimate.lineTo(lastX, y);
+ }
}
@Override
@@ -203,6 +248,11 @@ public class ChartNetworkSeriesView extends View {
final float primaryRightPoint = mHoriz.convertToPoint(mPrimaryRight);
save = canvas.save();
+ canvas.clipRect(0, 0, getWidth(), getHeight());
+ canvas.drawPath(mPathEstimate, mPaintEstimate);
+ canvas.restoreToCount(save);
+
+ save = canvas.save();
canvas.clipRect(0, 0, primaryLeftPoint, getHeight());
canvas.drawPath(mPathFill, mPaintFillSecondary);
canvas.restoreToCount(save);