From 58a904ad2eae26a88f82f23c9679cc2bab73b42b Mon Sep 17 00:00:00 2001 From: Gilles Debunne Date: Tue, 17 Apr 2012 18:14:36 -0700 Subject: [PATCH] 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 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 --- .../settings/widget/ChartDataUsageView.java | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/com/android/settings/widget/ChartDataUsageView.java b/src/com/android/settings/widget/ChartDataUsageView.java index c07509c2e11..f8e658791cb 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) {