summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/widget/ChartView.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/settings/widget/ChartView.java')
-rw-r--r--src/com/android/settings/widget/ChartView.java32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/com/android/settings/widget/ChartView.java b/src/com/android/settings/widget/ChartView.java
index a5b8b09..e3a658a 100644
--- a/src/com/android/settings/widget/ChartView.java
+++ b/src/com/android/settings/widget/ChartView.java
@@ -19,12 +19,16 @@ package com.android.settings.widget;
import static com.google.common.base.Preconditions.checkNotNull;
import android.content.Context;
+import android.content.res.TypedArray;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
+import android.view.ViewDebug;
import android.widget.FrameLayout;
+import com.android.settings.R;
+
/**
* Container for two-dimensional chart, drawn with a combination of
* {@link ChartGridView}, {@link ChartNetworkSeriesView} and {@link ChartSweepView}
@@ -41,6 +45,10 @@ public class ChartView extends FrameLayout {
ChartAxis mHoriz;
ChartAxis mVert;
+ @ViewDebug.ExportedProperty
+ private int mOptimalWidth = -1;
+ private float mOptimalWidthWeight = 0;
+
private Rect mContent = new Rect();
public ChartView(Context context) {
@@ -54,6 +62,12 @@ public class ChartView extends FrameLayout {
public ChartView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
+ final TypedArray a = context.obtainStyledAttributes(
+ attrs, R.styleable.ChartView, defStyle, 0);
+ setOptimalWidth(a.getDimensionPixelSize(R.styleable.ChartView_optimalWidth, -1),
+ a.getFloat(R.styleable.ChartView_optimalWidthWeight, 0));
+ a.recycle();
+
setClipToPadding(false);
setClipChildren(false);
}
@@ -63,6 +77,24 @@ public class ChartView extends FrameLayout {
mVert = checkNotNull(vert, "missing vert");
}
+ public void setOptimalWidth(int optimalWidth, float optimalWidthWeight) {
+ mOptimalWidth = optimalWidth;
+ mOptimalWidthWeight = optimalWidthWeight;
+ requestLayout();
+ }
+
+ @Override
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+ super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+
+ final int slack = getMeasuredWidth() - mOptimalWidth;
+ if (mOptimalWidth > 0 && slack > 0) {
+ final int targetWidth = (int) (mOptimalWidth + (slack * mOptimalWidthWeight));
+ widthMeasureSpec = MeasureSpec.makeMeasureSpec(targetWidth, MeasureSpec.EXACTLY);
+ super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+ }
+ }
+
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
mContent.set(getPaddingLeft(), getPaddingTop(), r - l - getPaddingRight(),