Add minTickWidth for the bar chart
At jsharkey's request. Change-Id: Ic489e534fe793fc7ec3fd2bedc5bb256be99daec
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
<com.android.settings.deviceinfo.PercentageBarChart
|
<com.android.settings.deviceinfo.PercentageBarChart
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
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_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:minHeight="?android:attr/listPreferredItemHeight"
|
android:minHeight="?android:attr/listPreferredItemHeight"
|
||||||
@@ -24,5 +25,6 @@
|
|||||||
android:paddingRight="?android:attr/scrollbarSize"
|
android:paddingRight="?android:attr/scrollbarSize"
|
||||||
android:paddingTop="6dip"
|
android:paddingTop="6dip"
|
||||||
android:paddingBottom="6dip"
|
android:paddingBottom="6dip"
|
||||||
emptyColor="@color/memory_avail">
|
settings:minTickWidth="6dip"
|
||||||
|
settings:emptyColor="@color/memory_avail">
|
||||||
</com.android.settings.deviceinfo.PercentageBarChart>
|
</com.android.settings.deviceinfo.PercentageBarChart>
|
@@ -46,5 +46,7 @@
|
|||||||
<declare-styleable name="PercentageBarChart">
|
<declare-styleable name="PercentageBarChart">
|
||||||
<!-- Background color -->
|
<!-- Background color -->
|
||||||
<attr name="emptyColor" format="color" />
|
<attr name="emptyColor" format="color" />
|
||||||
|
<!-- Minimum tick width for each slice in the bar chart. -->
|
||||||
|
<attr name="minTickWidth" format="dimension" />
|
||||||
</declare-styleable>
|
</declare-styleable>
|
||||||
</resources>
|
</resources>
|
||||||
|
@@ -36,6 +36,8 @@ public class PercentageBarChart extends View {
|
|||||||
|
|
||||||
private Collection<Entry> mEntries;
|
private Collection<Entry> mEntries;
|
||||||
|
|
||||||
|
private int mMinTickWidth = 1;
|
||||||
|
|
||||||
public static class Entry {
|
public static class Entry {
|
||||||
public final float percentage;
|
public final float percentage;
|
||||||
public final Paint paint;
|
public final Paint paint;
|
||||||
@@ -49,21 +51,9 @@ public class PercentageBarChart extends View {
|
|||||||
public PercentageBarChart(Context context, AttributeSet attrs) {
|
public PercentageBarChart(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
|
|
||||||
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PercentageBarChart, 0, 0);
|
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PercentageBarChart);
|
||||||
|
mMinTickWidth = a.getDimensionPixelSize(R.styleable.PercentageBarChart_minTickWidth, 1);
|
||||||
int emptyColor = Color.BLACK;
|
int emptyColor = a.getColor(R.styleable.PercentageBarChart_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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
a.recycle();
|
a.recycle();
|
||||||
|
|
||||||
mEmptyPaint.setColor(emptyColor);
|
mEmptyPaint.setColor(emptyColor);
|
||||||
@@ -89,7 +79,7 @@ public class PercentageBarChart extends View {
|
|||||||
if (e.percentage == 0f) {
|
if (e.percentage == 0f) {
|
||||||
entryWidth = 0;
|
entryWidth = 0;
|
||||||
} else {
|
} else {
|
||||||
entryWidth = Math.max(1, (int) (width * e.percentage));
|
entryWidth = Math.max(mMinTickWidth, (int) (width * e.percentage));
|
||||||
}
|
}
|
||||||
|
|
||||||
final int nextX = lastX + entryWidth;
|
final int nextX = lastX + entryWidth;
|
||||||
|
Reference in New Issue
Block a user