Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7b5676e4 authored by Mark Wagner's avatar Mark Wagner
Browse files

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.
parent 055e4ea5
Loading
Loading
Loading
Loading
+23 −0
Original line number Diff line number Diff line
@@ -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"
+13 −2
Original line number Diff line number Diff line
@@ -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);
                }
            }
        }
+8 −1
Original line number Diff line number Diff line
@@ -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,10 +755,12 @@ extends Layout
                        fitascent = fitdescent = fittop = fitbottom = 0;
                        okascent = okdescent = oktop = okbottom = 0;

                        if (--firstWidthLineCount <= 0) {
                            width = restwidth;
                        }
                    }
                }
            }

            if (end != here) {
                if ((fittop | fitbottom | fitdescent | fitascent) == 0) {
+5 −0
Original line number Diff line number Diff line
@@ -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;