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

Commit ebd66ca6 authored by Raph Levien's avatar Raph Levien
Browse files

Make Paint a required field of StaticLayout Builder

This patch moves the Paint parameter from being an option set from
setPaint to being a required field passed into the obtain() method
of StaticLayout.Builder. Thus, it is now possible to get a valid
StaticLayout object just doing .build() on the Builder; all other
fields are optional.

This is in preparation for exposing the builder publicly, but that
is to be a separate CL.

Bug: 20190561

Change-Id: Iefd7800203004e565d068b0c76502cf7cf52d91f
parent 5b8b0df7
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -283,7 +283,7 @@ public class DynamicLayout extends Layout

        if (reflowed == null) {
            reflowed = new StaticLayout(null);
            b = StaticLayout.Builder.obtain(text, where, where + after, getWidth());
            b = StaticLayout.Builder.obtain(text, where, where + after, getPaint(), getWidth());
        }

        b.setText(text, where, where + after)
+4 −3
Original line number Diff line number Diff line
@@ -57,7 +57,8 @@ public class StaticLayout extends Layout {
            mNativePtr = nNewBuilder();
        }

        public static Builder obtain(CharSequence source, int start, int end, int width) {
        public static Builder obtain(CharSequence source, int start, int end, TextPaint paint,
                int width) {
            Builder b = sPool.acquire();
            if (b == null) {
                b = new Builder();
@@ -67,6 +68,7 @@ public class StaticLayout extends Layout {
            b.mText = source;
            b.mStart = start;
            b.mEnd = end;
            b.mPaint = paint;
            b.mWidth = width;
            b.mAlignment = Alignment.ALIGN_NORMAL;
            b.mTextDir = TextDirectionHeuristics.FIRSTSTRONG_LTR;
@@ -327,8 +329,7 @@ public class StaticLayout extends Layout {
                    : new Ellipsizer(source),
              paint, outerwidth, align, textDir, spacingmult, spacingadd);

        Builder b = Builder.obtain(source, bufstart, bufend, outerwidth)
            .setPaint(paint)
        Builder b = Builder.obtain(source, bufstart, bufend, paint, outerwidth)
            .setAlignment(align)
            .setTextDir(textDir)
            .setSpacingMult(spacingmult)
+2 −4
Original line number Diff line number Diff line
@@ -6630,8 +6630,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
            // TODO: code duplication with makeSingleLayout()
            if (mHintLayout == null) {
                StaticLayout.Builder builder = StaticLayout.Builder.obtain(mHint, 0,
                        mHint.length(), hintWidth)
                        .setPaint(mTextPaint)
                        mHint.length(), mTextPaint, hintWidth)
                        .setAlignment(alignment)
                        .setTextDir(mTextDir)
                        .setSpacingMult(mSpacingMult)
@@ -6721,8 +6720,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        }
        if (result == null) {
            StaticLayout.Builder builder = StaticLayout.Builder.obtain(mTransformed,
                    0, mTransformed.length(), wantWidth)
                    .setPaint(mTextPaint)
                    0, mTransformed.length(), mTextPaint, wantWidth)
                    .setAlignment(alignment)
                    .setTextDir(mTextDir)
                    .setSpacingMult(mSpacingMult)