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
This commit is contained in:
Gilles Debunne
2012-04-17 18:14:36 -07:00
parent aae7f693ea
commit 58a904ad2e

View File

@@ -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) {