summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/widget/ChartNetworkSeriesView.java
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2011-06-23 00:39:38 -0700
committerJeff Sharkey <jsharkey@android.com>2011-06-23 00:39:47 -0700
commit52c3f4461b806e4f1ce48455ee2ba0ac05dfdab4 (patch)
tree413297650a61f914f6e212b73af8fb76cacbc3d9 /src/com/android/settings/widget/ChartNetworkSeriesView.java
parentaef3981e86909a6a5b4f6ecab972e43fd77582c1 (diff)
downloadpackages_apps_Settings-52c3f4461b806e4f1ce48455ee2ba0ac05dfdab4.zip
packages_apps_Settings-52c3f4461b806e4f1ce48455ee2ba0ac05dfdab4.tar.gz
packages_apps_Settings-52c3f4461b806e4f1ce48455ee2ba0ac05dfdab4.tar.bz2
Iterate on data usage chart UI.
Switched to inflating chart views from XML, using attributes for configuration. Start using drawable assets for chart components instead of manually painting. Include hand-cut assets, and animate between states when touched to invoke. Clamp sweeps to valid chart ranges and prepare for sweep labels. Bug: 4768483, 4598460 Change-Id: Ic660c35bec826eb5e3f6a1dde3cc04d8c437ef2b
Diffstat (limited to 'src/com/android/settings/widget/ChartNetworkSeriesView.java')
-rw-r--r--src/com/android/settings/widget/ChartNetworkSeriesView.java81
1 files changed, 47 insertions, 34 deletions
diff --git a/src/com/android/settings/widget/ChartNetworkSeriesView.java b/src/com/android/settings/widget/ChartNetworkSeriesView.java
index 780ca46..0a34565 100644
--- a/src/com/android/settings/widget/ChartNetworkSeriesView.java
+++ b/src/com/android/settings/widget/ChartNetworkSeriesView.java
@@ -17,6 +17,7 @@
package com.android.settings.widget;
import android.content.Context;
+import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
@@ -24,9 +25,11 @@ import android.graphics.Paint.Style;
import android.graphics.Path;
import android.graphics.RectF;
import android.net.NetworkStatsHistory;
+import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
+import com.android.settings.R;
import com.google.common.base.Preconditions;
/**
@@ -37,35 +40,54 @@ public class ChartNetworkSeriesView extends View {
private static final String TAG = "ChartNetworkSeriesView";
private static final boolean LOGD = true;
- private final ChartAxis mHoriz;
- private final ChartAxis mVert;
+ private ChartAxis mHoriz;
+ private ChartAxis mVert;
private Paint mPaintStroke;
private Paint mPaintFill;
- private Paint mPaintFillDisabled;
+ private Paint mPaintFillSecondary;
private NetworkStatsHistory mStats;
private Path mPathStroke;
private Path mPathFill;
- private ChartSweepView mSweep1;
- private ChartSweepView mSweep2;
+ private long mPrimaryLeft;
+ private long mPrimaryRight;
- public ChartNetworkSeriesView(Context context, ChartAxis horiz, ChartAxis vert) {
- super(context);
+ public ChartNetworkSeriesView(Context context) {
+ this(context, null, 0);
+ }
- mHoriz = Preconditions.checkNotNull(horiz, "missing horiz");
- mVert = Preconditions.checkNotNull(vert, "missing vert");
+ public ChartNetworkSeriesView(Context context, AttributeSet attrs) {
+ this(context, attrs, 0);
+ }
+
+ public ChartNetworkSeriesView(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+
+ final TypedArray a = context.obtainStyledAttributes(
+ attrs, R.styleable.ChartNetworkSeriesView, defStyle, 0);
+
+ final int stroke = a.getColor(R.styleable.ChartNetworkSeriesView_strokeColor, Color.RED);
+ final int fill = a.getColor(R.styleable.ChartNetworkSeriesView_fillColor, Color.RED);
+ final int fillSecondary = a.getColor(
+ R.styleable.ChartNetworkSeriesView_fillColorSecondary, Color.RED);
+
+ setChartColor(stroke, fill, fillSecondary);
- setChartColor(Color.parseColor("#24aae1"), Color.parseColor("#c050ade5"),
- Color.parseColor("#88566abc"));
+ a.recycle();
mPathStroke = new Path();
mPathFill = new Path();
}
- public void setChartColor(int stroke, int fill, int disabled) {
+ void init(ChartAxis horiz, ChartAxis vert) {
+ mHoriz = Preconditions.checkNotNull(horiz, "missing horiz");
+ mVert = Preconditions.checkNotNull(vert, "missing vert");
+ }
+
+ public void setChartColor(int stroke, int fill, int fillSecondary) {
mPaintStroke = new Paint();
mPaintStroke.setStrokeWidth(6.0f);
mPaintStroke.setColor(stroke);
@@ -77,10 +99,10 @@ public class ChartNetworkSeriesView extends View {
mPaintFill.setStyle(Style.FILL);
mPaintFill.setAntiAlias(true);
- mPaintFillDisabled = new Paint();
- mPaintFillDisabled.setColor(disabled);
- mPaintFillDisabled.setStyle(Style.FILL);
- mPaintFillDisabled.setAntiAlias(true);
+ mPaintFillSecondary = new Paint();
+ mPaintFillSecondary.setColor(fillSecondary);
+ mPaintFillSecondary.setStyle(Style.FILL);
+ mPaintFillSecondary.setAntiAlias(true);
}
public void bindNetworkStats(NetworkStatsHistory stats) {
@@ -90,12 +112,10 @@ public class ChartNetworkSeriesView extends View {
mPathFill.reset();
}
- public void bindSweepRange(ChartSweepView sweep1, ChartSweepView sweep2) {
- // TODO: generalize to support vertical sweeps
- // TODO: enforce that both sweeps are along same dimension
-
- mSweep1 = Preconditions.checkNotNull(sweep1, "missing sweep1");
- mSweep2 = Preconditions.checkNotNull(sweep2, "missing sweep2");
+ public void setPrimaryRange(long left, long right) {
+ mPrimaryLeft = left;
+ mPrimaryRight = right;
+ invalidate();
}
@Override
@@ -168,27 +188,20 @@ public class ChartNetworkSeriesView extends View {
@Override
protected void onDraw(Canvas canvas) {
-
- // clip to sweep area
- final float sweep1 = mSweep1.getPoint();
- final float sweep2 = mSweep2.getPoint();
- final float sweepLeft = Math.min(sweep1, sweep2);
- final float sweepRight = Math.max(sweep1, sweep2);
-
int save;
save = canvas.save();
- canvas.clipRect(0, 0, sweepLeft, getHeight());
- canvas.drawPath(mPathFill, mPaintFillDisabled);
+ canvas.clipRect(0, 0, mPrimaryLeft, getHeight());
+ canvas.drawPath(mPathFill, mPaintFillSecondary);
canvas.restoreToCount(save);
save = canvas.save();
- canvas.clipRect(sweepRight, 0, getWidth(), getHeight());
- canvas.drawPath(mPathFill, mPaintFillDisabled);
+ canvas.clipRect(mPrimaryRight, 0, getWidth(), getHeight());
+ canvas.drawPath(mPathFill, mPaintFillSecondary);
canvas.restoreToCount(save);
save = canvas.save();
- canvas.clipRect(sweepLeft, 0, sweepRight, getHeight());
+ canvas.clipRect(mPrimaryLeft, 0, mPrimaryRight, getHeight());
canvas.drawPath(mPathFill, mPaintFill);
canvas.drawPath(mPathStroke, mPaintStroke);
canvas.restoreToCount(save);