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.
This commit is contained in:
Mark Wagner
2009-10-16 11:44:23 -07:00
parent 055e4ea56c
commit 7b5676e4d4
4 changed files with 49 additions and 3 deletions

View File

@@ -143781,6 +143781,29 @@
</parameter>
</method>
</interface>
<interface name="LeadingMarginSpan.LeadingMarginSpan2"
abstract="true"
static="true"
final="false"
deprecated="not deprecated"
visibility="public"
>
<implements name="android.text.style.LeadingMarginSpan">
</implements>
<implements name="android.text.style.WrapTogetherSpan">
</implements>
<method name="getLeadingMarginLineCount"
return="int"
abstract="true"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
</method>
</interface>
<class name="LeadingMarginSpan.Standard"
extends="java.lang.Object"
abstract="false"

View File

@@ -294,7 +294,12 @@ public abstract class Layout {
lbaseline, lbottom, buf,
start, end, par, this);
left += margin.getLeadingMargin(par);
boolean useMargin = par;
if (margin instanceof LeadingMarginSpan.LeadingMarginSpan2) {
int count = ((LeadingMarginSpan.LeadingMarginSpan2)margin).getLeadingMarginLineCount();
useMargin = count > i;
}
left += margin.getLeadingMargin(useMargin);
}
}
}
@@ -1293,7 +1298,13 @@ public abstract class Layout {
LeadingMarginSpan.class);
for (int i = 0; i < spans.length; i++) {
left += spans[i].getLeadingMargin(par);
boolean margin = par;
LeadingMarginSpan span = spans[i];
if (span instanceof LeadingMarginSpan.LeadingMarginSpan2) {
int count = ((LeadingMarginSpan.LeadingMarginSpan2)span).getLeadingMarginLineCount();
margin = count >= line;
}
left += span.getLeadingMargin(margin);
}
}
}

View File

@@ -161,6 +161,7 @@ extends Layout
else
end++;
int firstWidthLineCount = 1;
int firstwidth = outerwidth;
int restwidth = outerwidth;
@@ -171,8 +172,12 @@ extends Layout
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 @@ extends Layout
fitascent = fitdescent = fittop = fitbottom = 0;
okascent = okdescent = oktop = okbottom = 0;
width = restwidth;
if (--firstWidthLineCount <= 0) {
width = restwidth;
}
}
}
}

View File

@@ -33,6 +33,11 @@ extends ParagraphStyle
CharSequence text, int start, int end,
boolean first, Layout layout);
public interface LeadingMarginSpan2 extends LeadingMarginSpan, WrapTogetherSpan {
public int getLeadingMarginLineCount();
};
public static class Standard implements LeadingMarginSpan, ParcelableSpan {
private final int mFirst, mRest;