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
diff --git a/core/java/android/text/StaticLayout.java b/core/java/android/text/StaticLayout.java
index 67794b1..08fcd56 100644
--- a/core/java/android/text/StaticLayout.java
+++ b/core/java/android/text/StaticLayout.java
@@ -57,7 +57,8 @@
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 @@
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 @@
: 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)