summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/widget/DataUsageChartView.java
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2011-07-09 01:02:56 -0700
committerJeff Sharkey <jsharkey@android.com>2011-07-09 01:02:56 -0700
commitec3be8a4a5efa0e98aeefbf22bb876d09f08a023 (patch)
tree21e1886d25752947bf5a388c63239b879058386d /src/com/android/settings/widget/DataUsageChartView.java
parent890e352d5f897b533c216f56e7604cdd2fd67eda (diff)
downloadpackages_apps_Settings-ec3be8a4a5efa0e98aeefbf22bb876d09f08a023.zip
packages_apps_Settings-ec3be8a4a5efa0e98aeefbf22bb876d09f08a023.tar.gz
packages_apps_Settings-ec3be8a4a5efa0e98aeefbf22bb876d09f08a023.tar.bz2
Draw vertical data usage sweep labels.
Using template string, ask axis to build label for sweeps. Also clean up margins exposed to parent view, since we offset when label is larger than sweep drawable. Bug: 4598460 Change-Id: If71bc8ec8c952023325c80b9bc00b63c23609c7a
Diffstat (limited to 'src/com/android/settings/widget/DataUsageChartView.java')
-rw-r--r--src/com/android/settings/widget/DataUsageChartView.java61
1 files changed, 44 insertions, 17 deletions
diff --git a/src/com/android/settings/widget/DataUsageChartView.java b/src/com/android/settings/widget/DataUsageChartView.java
index a8bdaa6..89caef1 100644
--- a/src/com/android/settings/widget/DataUsageChartView.java
+++ b/src/com/android/settings/widget/DataUsageChartView.java
@@ -17,8 +17,12 @@
package com.android.settings.widget;
import android.content.Context;
+import android.content.res.Resources;
import android.net.NetworkPolicy;
import android.net.NetworkStatsHistory;
+import android.text.Spannable;
+import android.text.SpannableStringBuilder;
+import android.text.TextUtils;
import android.text.format.DateUtils;
import android.util.AttributeSet;
import android.view.MotionEvent;
@@ -283,15 +287,9 @@ public class DataUsageChartView extends ChartView {
}
/** {@inheritDoc} */
- public CharSequence getLabel(long value) {
- // TODO: convert to string
- return Long.toString(value);
- }
-
- /** {@inheritDoc} */
- public CharSequence getShortLabel(long value) {
- // TODO: convert to string
- return Long.toString(value);
+ public void buildLabel(Resources res, SpannableStringBuilder builder, long value) {
+ // TODO: convert to better string
+ builder.replace(0, builder.length(), Long.toString(value));
}
/** {@inheritDoc} */
@@ -345,16 +343,33 @@ public class DataUsageChartView extends ChartView {
return (long) fraction;
}
- /** {@inheritDoc} */
- public CharSequence getLabel(long value) {
- // TODO: use exploded string here
- return Long.toString(value);
- }
+ private static final Object sSpanSize = new Object();
+ private static final Object sSpanUnit = new Object();
/** {@inheritDoc} */
- public CharSequence getShortLabel(long value) {
- // TODO: convert to string
- return Long.toString(value);
+ public void buildLabel(Resources res, SpannableStringBuilder builder, long value) {
+
+ float result = value;
+ final CharSequence unit;
+ if (result <= 100 * MB_IN_BYTES) {
+ unit = res.getText(com.android.internal.R.string.megabyteShort);
+ result /= MB_IN_BYTES;
+ } else {
+ unit = res.getText(com.android.internal.R.string.gigabyteShort);
+ result /= GB_IN_BYTES;
+ }
+
+ final CharSequence size;
+ if (result < 10) {
+ size = String.format("%.1f", result);
+ } else {
+ size = String.format("%.0f", result);
+ }
+
+ final int[] sizeBounds = findOrCreateSpan(builder, sSpanSize, "^1");
+ builder.replace(sizeBounds[0], sizeBounds[1], size);
+ final int[] unitBounds = findOrCreateSpan(builder, sSpanUnit, "^2");
+ builder.replace(unitBounds[0], unitBounds[1], unit);
}
/** {@inheritDoc} */
@@ -372,4 +387,16 @@ public class DataUsageChartView extends ChartView {
}
}
+ private static int[] findOrCreateSpan(
+ SpannableStringBuilder builder, Object key, CharSequence bootstrap) {
+ int start = builder.getSpanStart(key);
+ int end = builder.getSpanEnd(key);
+ if (start == -1) {
+ start = TextUtils.indexOf(builder, bootstrap);
+ end = start + bootstrap.length();
+ builder.setSpan(key, start, end, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
+ }
+ return new int[] { start, end };
+ }
+
}