support for multiline paragraph style indentation
This change is likely incomplete and perhaps not right in other ways.
The gist of the change is that the span can return the number of lines
to which to apply the "leading margin".
Some specific things that should be looked at:
1) if the user has nested multiple
LeadingMarginSpans then they will inherit the "line count" feature.
This is wrong but I didn't want to spend time fixing it until it
was clear that this overall approach was acceptible.
2) The units for how many lines should indented is "lines" rather than
something like dips.
3) I wasn't sure what our strategy was for binary compatibility so
I didn't want to modify the methods in LeadingMarginSpan. Instead I
made another interface with extends LeadingMarginSpan that has the
extra method to return the line count.
diff --git a/core/java/android/text/StaticLayout.java b/core/java/android/text/StaticLayout.java
index f0a5ffd..fbf1261 100644
--- a/core/java/android/text/StaticLayout.java
+++ b/core/java/android/text/StaticLayout.java
@@ -161,6 +161,7 @@
else
end++;
+ int firstWidthLineCount = 1;
int firstwidth = outerwidth;
int restwidth = outerwidth;
@@ -171,8 +172,12 @@
sp = spanned.getSpans(start, end, LeadingMarginSpan.class);
for (int i = 0; i < sp.length; i++) {
+ LeadingMarginSpan lms = sp[i];
firstwidth -= sp[i].getLeadingMargin(true);
restwidth -= sp[i].getLeadingMargin(false);
+ if (lms instanceof LeadingMarginSpan.LeadingMarginSpan2) {
+ firstWidthLineCount = ((LeadingMarginSpan.LeadingMarginSpan2)lms).getLeadingMarginLineCount();
+ }
}
chooseht = spanned.getSpans(start, end, LineHeightSpan.class);
@@ -750,7 +755,9 @@
fitascent = fitdescent = fittop = fitbottom = 0;
okascent = okdescent = oktop = okbottom = 0;
- width = restwidth;
+ if (--firstWidthLineCount <= 0) {
+ width = restwidth;
+ }
}
}
}