diff options
author | Gilles Debunne <debunne@google.com> | 2012-04-17 18:14:36 -0700 |
---|---|---|
committer | Gilles Debunne <debunne@google.com> | 2012-04-17 18:39:26 -0700 |
commit | 58a904ad2eae26a88f82f23c9679cc2bab73b42b (patch) | |
tree | 13811ac22c58d6f40e822a004e5a9fefc233579b /src | |
parent | aae7f693ea5d988f837f03ab0e251017506846e3 (diff) | |
download | packages_apps_Settings-58a904ad2eae26a88f82f23c9679cc2bab73b42b.zip packages_apps_Settings-58a904ad2eae26a88f82f23c9679cc2bab73b42b.tar.gz packages_apps_Settings-58a904ad2eae26a88f82f23c9679cc2bab73b42b.tar.bz2 |
Data usage limit label font size fixed
Bug 6326750
The font size around the text was removed when its content is replaced.
This is WAI since the spans created from <font> html tags have a
SPAN_EXCLUSIVE_EXCLUSIVE flag. These are removed when their length
becomes 0. The bug came from a recent enforcement of this constraint.
The fix is to change the flags of these AbsoluteSizeSpan spans.
This CL also changes the code to avoid the creation of the int[] array.
Change-Id: Ib58270bb9d1cf0c7609ba1e36d6c0cca841300db
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/settings/widget/ChartDataUsageView.java | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/src/com/android/settings/widget/ChartDataUsageView.java b/src/com/android/settings/widget/ChartDataUsageView.java index c07509c..f8e6587 100644 --- a/src/com/android/settings/widget/ChartDataUsageView.java +++ b/src/com/android/settings/widget/ChartDataUsageView.java @@ -625,10 +625,8 @@ public class ChartDataUsageView extends ChartView { resultRounded = unitFactor * Math.round(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); + setText(builder, sSpanSize, size, "^1"); + setText(builder, sSpanUnit, unit, "^2"); return (long) resultRounded; } @@ -663,16 +661,26 @@ public class ChartDataUsageView extends ChartView { } } - private static int[] findOrCreateSpan( - SpannableStringBuilder builder, Object key, CharSequence bootstrap) { + private static void setText( + SpannableStringBuilder builder, Object key, CharSequence text, String 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); + + // Fix the AbsoluteSizeSpan created from html. Its flags must be set to + // SPAN_INCLUSIVE_INCLUSIVE so that it survives a removal of its entire content + Object[] spans = builder.getSpans(start, end, Object.class); + for (int i = 0; i < spans.length; i++) { + Object span = spans[i]; + if (builder.getSpanStart(span) == start && builder.getSpanEnd(span) == end) { + builder.setSpan(span, start, end, Spannable.SPAN_INCLUSIVE_INCLUSIVE); + } + } } - return new int[] { start, end }; + builder.replace(start, end, text); } private static long roundUpToPowerOfTwo(long i) { |