Add minTickWidth for the bar chart
At jsharkey's request.
Change-Id: Ic489e534fe793fc7ec3fd2bedc5bb256be99daec
diff --git a/res/layout/preference_memoryusage.xml b/res/layout/preference_memoryusage.xml
index 25fd888..303a5b7 100644
--- a/res/layout/preference_memoryusage.xml
+++ b/res/layout/preference_memoryusage.xml
@@ -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>
\ No newline at end of file
+ settings:minTickWidth="6dip"
+ settings:emptyColor="@color/memory_avail">
+</com.android.settings.deviceinfo.PercentageBarChart>
diff --git a/res/values/attrs.xml b/res/values/attrs.xml
index 57d0f45..7cff69c 100644
--- a/res/values/attrs.xml
+++ b/res/values/attrs.xml
@@ -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>
diff --git a/src/com/android/settings/deviceinfo/PercentageBarChart.java b/src/com/android/settings/deviceinfo/PercentageBarChart.java
index 2f174fb..7d02301 100644
--- a/src/com/android/settings/deviceinfo/PercentageBarChart.java
+++ b/src/com/android/settings/deviceinfo/PercentageBarChart.java
@@ -36,6 +36,8 @@
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 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 @@
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;