Add minTickWidth for the bar chart

At jsharkey's request.

Change-Id: Ic489e534fe793fc7ec3fd2bedc5bb256be99daec
This commit is contained in:
Kenny Root
2010-12-17 11:57:14 -08:00
parent e4330890d6
commit 42a92e83a1
3 changed files with 12 additions and 18 deletions

View File

@@ -16,6 +16,7 @@
<com.android.settings.deviceinfo.PercentageBarChart
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
@@ -24,5 +25,6 @@
android:paddingRight="?android:attr/scrollbarSize"
android:paddingTop="6dip"
android:paddingBottom="6dip"
emptyColor="@color/memory_avail">
</com.android.settings.deviceinfo.PercentageBarChart>
settings:minTickWidth="6dip"
settings:emptyColor="@color/memory_avail">
</com.android.settings.deviceinfo.PercentageBarChart>

View File

@@ -46,5 +46,7 @@
<declare-styleable name="PercentageBarChart">
<!-- Background color -->
<attr name="emptyColor" format="color" />
<!-- Minimum tick width for each slice in the bar chart. -->
<attr name="minTickWidth" format="dimension" />
</declare-styleable>
</resources>

View File

@@ -36,6 +36,8 @@ public class PercentageBarChart extends View {
private Collection<Entry> mEntries;
private int mMinTickWidth = 1;
public static class Entry {
public final float percentage;
public final Paint paint;
@@ -49,21 +51,9 @@ public class PercentageBarChart extends View {
public PercentageBarChart(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PercentageBarChart, 0, 0);
int emptyColor = Color.BLACK;
int n = a.getIndexCount();
for (int i = 0; i < n; i++) {
int attr = a.getIndex(i);
switch (attr) {
case R.styleable.PercentageBarChart_emptyColor:
emptyColor = a.getColor(attr, 0);
break;
}
}
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PercentageBarChart);
mMinTickWidth = a.getDimensionPixelSize(R.styleable.PercentageBarChart_minTickWidth, 1);
int emptyColor = a.getColor(R.styleable.PercentageBarChart_emptyColor, Color.BLACK);
a.recycle();
mEmptyPaint.setColor(emptyColor);
@@ -89,7 +79,7 @@ public class PercentageBarChart extends View {
if (e.percentage == 0f) {
entryWidth = 0;
} else {
entryWidth = Math.max(1, (int) (width * e.percentage));
entryWidth = Math.max(mMinTickWidth, (int) (width * e.percentage));
}
final int nextX = lastX + entryWidth;