Reorganize MeasuredText API (2nd)
This is 2nd attempt of I7db9e2ca4db68a16648cfb8fcf63555f501304c2
This CL changes the MeasuredText API:
- Rename MeasuredText to PrecomputedText.
- Introduce PrecomputedText.Param which holds all text layout parameters.
- Add API to get PrecomputedText.Param from TextView.
- Remove MeasuredText.Builder and add PrecomputedText.create method instead.
- Remove setRange from MeasuredText since it is not for normal use case.
(It can not be used for TextView)
Bug: 67504091
Bug: 72861572
Test: bit FrameworksCoreTests:android.text.
Test: atest CtsWidgetTestCases:EditTextTest \
CtsWidgetTestCases:TextViewFadingEdgeTest \
FrameworksCoreTests:TextViewFallbackLineSpacingTest \
FrameworksCoreTests:TextViewTest FrameworksCoreTests:TypefaceTest \
CtsGraphicsTestCases:TypefaceTest CtsWidgetTestCases:TextViewTest \
CtsTextTestCases
Change-Id: Ie73bce52c6c673cda58973ddad04627a7cf2e5e9
diff --git a/core/java/android/text/StaticLayout.java b/core/java/android/text/StaticLayout.java
index e62f421..299bde2 100644
--- a/core/java/android/text/StaticLayout.java
+++ b/core/java/android/text/StaticLayout.java
@@ -651,42 +651,25 @@
b.mJustificationMode != Layout.JUSTIFICATION_MODE_NONE,
indents, mLeftPaddings, mRightPaddings);
- MeasuredText measured = null;
+ PrecomputedText measured = null;
final Spanned spanned;
- final boolean canUseMeasuredText;
- if (source instanceof MeasuredText) {
- measured = (MeasuredText) source;
-
- if (bufStart != measured.getStart() || bufEnd != measured.getEnd()) {
- // The buffer position has changed. Re-measure here.
- canUseMeasuredText = false;
- } else if (b.mBreakStrategy != measured.getBreakStrategy()
- || b.mHyphenationFrequency != measured.getHyphenationFrequency()) {
- // The computed hyphenation pieces may not be able to used. Re-measure it.
- canUseMeasuredText = false;
- } else {
- // We can use measured information.
- canUseMeasuredText = true;
+ if (source instanceof PrecomputedText) {
+ measured = (PrecomputedText) source;
+ if (!measured.canUseMeasuredResult(bufStart, bufEnd, textDir, paint, b.mBreakStrategy,
+ b.mHyphenationFrequency)) {
+ // Some parameters are different from the ones when measured text is created.
+ measured = null;
}
- } else {
- canUseMeasuredText = false;
}
- if (!canUseMeasuredText) {
- measured = new MeasuredText.Builder(source, paint)
- .setRange(bufStart, bufEnd)
- .setTextDirection(textDir)
- .setBreakStrategy(b.mBreakStrategy)
- .setHyphenationFrequency(b.mHyphenationFrequency)
- .build(false /* full layout is not necessary for line breaking */);
+ if (measured == null) {
+ final PrecomputedText.Params param = new PrecomputedText.Params(paint, textDir,
+ b.mBreakStrategy, b.mHyphenationFrequency);
+ measured = PrecomputedText.createWidthOnly(source, param, bufStart, bufEnd);
spanned = (source instanceof Spanned) ? (Spanned) source : null;
} else {
final CharSequence original = measured.getText();
spanned = (original instanceof Spanned) ? (Spanned) original : null;
- // Overwrite with the one when measured.
- // TODO: Give an option for developer not to overwrite and measure again here?
- textDir = measured.getTextDir();
- paint = measured.getPaint();
}
try {