Change justification parameter from boolean to int.
Bug: 35766005
Bug: 35764323
Test: Manually done
Change-Id: Ic6d78bb9a3213160cd013f1ca8294307872bf0d0
diff --git a/api/current.txt b/api/current.txt
index d18d8813..7d4b772 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -41243,6 +41243,8 @@
field public static final int HYPHENATION_FREQUENCY_FULL = 2; // 0x2
field public static final int HYPHENATION_FREQUENCY_NONE = 0; // 0x0
field public static final int HYPHENATION_FREQUENCY_NORMAL = 1; // 0x1
+ field public static final int JUSTIFICATION_MODE_INTER_WORD = 1; // 0x1
+ field public static final int JUSTIFICATION_MODE_NONE = 0; // 0x0
}
public static final class Layout.Alignment extends java.lang.Enum {
@@ -41444,7 +41446,7 @@
method public android.text.StaticLayout.Builder setHyphenationFrequency(int);
method public android.text.StaticLayout.Builder setIncludePad(boolean);
method public android.text.StaticLayout.Builder setIndents(int[], int[]);
- method public android.text.StaticLayout.Builder setJustify(boolean);
+ method public android.text.StaticLayout.Builder setJustificationMode(int);
method public android.text.StaticLayout.Builder setLineSpacing(float, float);
method public android.text.StaticLayout.Builder setMaxLines(int);
method public android.text.StaticLayout.Builder setText(java.lang.CharSequence);
@@ -51254,7 +51256,7 @@
method public boolean getIncludeFontPadding();
method public android.os.Bundle getInputExtras(boolean);
method public int getInputType();
- method public boolean getJustify();
+ method public int getJustificationMode();
method public final android.text.method.KeyListener getKeyListener();
method public final android.text.Layout getLayout();
method public float getLetterSpacing();
@@ -51367,7 +51369,7 @@
method public void setIncludeFontPadding(boolean);
method public void setInputExtras(int) throws java.io.IOException, org.xmlpull.v1.XmlPullParserException;
method public void setInputType(int);
- method public void setJustify(boolean);
+ method public void setJustificationMode(int);
method public void setKeyListener(android.text.method.KeyListener);
method public void setLetterSpacing(float);
method public void setLineSpacing(float, float);
diff --git a/api/system-current.txt b/api/system-current.txt
index 13e843f..8ff5c1c 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -44701,6 +44701,8 @@
field public static final int HYPHENATION_FREQUENCY_FULL = 2; // 0x2
field public static final int HYPHENATION_FREQUENCY_NONE = 0; // 0x0
field public static final int HYPHENATION_FREQUENCY_NORMAL = 1; // 0x1
+ field public static final int JUSTIFICATION_MODE_INTER_WORD = 1; // 0x1
+ field public static final int JUSTIFICATION_MODE_NONE = 0; // 0x0
}
public static final class Layout.Alignment extends java.lang.Enum {
@@ -44902,7 +44904,7 @@
method public android.text.StaticLayout.Builder setHyphenationFrequency(int);
method public android.text.StaticLayout.Builder setIncludePad(boolean);
method public android.text.StaticLayout.Builder setIndents(int[], int[]);
- method public android.text.StaticLayout.Builder setJustify(boolean);
+ method public android.text.StaticLayout.Builder setJustificationMode(int);
method public android.text.StaticLayout.Builder setLineSpacing(float, float);
method public android.text.StaticLayout.Builder setMaxLines(int);
method public android.text.StaticLayout.Builder setText(java.lang.CharSequence);
@@ -55080,7 +55082,7 @@
method public boolean getIncludeFontPadding();
method public android.os.Bundle getInputExtras(boolean);
method public int getInputType();
- method public boolean getJustify();
+ method public int getJustificationMode();
method public final android.text.method.KeyListener getKeyListener();
method public final android.text.Layout getLayout();
method public float getLetterSpacing();
@@ -55193,7 +55195,7 @@
method public void setIncludeFontPadding(boolean);
method public void setInputExtras(int) throws java.io.IOException, org.xmlpull.v1.XmlPullParserException;
method public void setInputType(int);
- method public void setJustify(boolean);
+ method public void setJustificationMode(int);
method public void setKeyListener(android.text.method.KeyListener);
method public void setLetterSpacing(float);
method public void setLineSpacing(float, float);
diff --git a/api/test-current.txt b/api/test-current.txt
index 7b56071..fc30103 100644
--- a/api/test-current.txt
+++ b/api/test-current.txt
@@ -41451,6 +41451,8 @@
field public static final int HYPHENATION_FREQUENCY_FULL = 2; // 0x2
field public static final int HYPHENATION_FREQUENCY_NONE = 0; // 0x0
field public static final int HYPHENATION_FREQUENCY_NORMAL = 1; // 0x1
+ field public static final int JUSTIFICATION_MODE_INTER_WORD = 1; // 0x1
+ field public static final int JUSTIFICATION_MODE_NONE = 0; // 0x0
}
public static final class Layout.Alignment extends java.lang.Enum {
@@ -41652,7 +41654,7 @@
method public android.text.StaticLayout.Builder setHyphenationFrequency(int);
method public android.text.StaticLayout.Builder setIncludePad(boolean);
method public android.text.StaticLayout.Builder setIndents(int[], int[]);
- method public android.text.StaticLayout.Builder setJustify(boolean);
+ method public android.text.StaticLayout.Builder setJustificationMode(int);
method public android.text.StaticLayout.Builder setLineSpacing(float, float);
method public android.text.StaticLayout.Builder setMaxLines(int);
method public android.text.StaticLayout.Builder setText(java.lang.CharSequence);
@@ -51645,7 +51647,7 @@
method public boolean getIncludeFontPadding();
method public android.os.Bundle getInputExtras(boolean);
method public int getInputType();
- method public boolean getJustify();
+ method public int getJustificationMode();
method public final android.text.method.KeyListener getKeyListener();
method public final android.text.Layout getLayout();
method public float getLetterSpacing();
@@ -51758,7 +51760,7 @@
method public void setIncludeFontPadding(boolean);
method public void setInputExtras(int) throws java.io.IOException, org.xmlpull.v1.XmlPullParserException;
method public void setInputType(int);
- method public void setJustify(boolean);
+ method public void setJustificationMode(int);
method public void setKeyListener(android.text.method.KeyListener);
method public void setLetterSpacing(float);
method public void setLineSpacing(float, float);
diff --git a/core/java/android/text/DynamicLayout.java b/core/java/android/text/DynamicLayout.java
index 1e9deeb..6208c53 100644
--- a/core/java/android/text/DynamicLayout.java
+++ b/core/java/android/text/DynamicLayout.java
@@ -85,7 +85,7 @@
this(base, display, paint, width, align, TextDirectionHeuristics.FIRSTSTRONG_LTR,
spacingmult, spacingadd, includepad,
StaticLayout.BREAK_STRATEGY_SIMPLE, StaticLayout.HYPHENATION_FREQUENCY_NONE,
- false /* justify */, ellipsize, ellipsizedWidth);
+ Layout.JUSTIFICATION_MODE_NONE, ellipsize, ellipsizedWidth);
}
/**
@@ -102,7 +102,7 @@
int width, Alignment align, TextDirectionHeuristic textDir,
float spacingmult, float spacingadd,
boolean includepad, int breakStrategy, int hyphenationFrequency,
- boolean justify, TextUtils.TruncateAt ellipsize,
+ int justificationMode, TextUtils.TruncateAt ellipsize,
int ellipsizedWidth) {
super((ellipsize == null)
? display
@@ -128,7 +128,7 @@
mIncludePad = includepad;
mBreakStrategy = breakStrategy;
- mJustify = justify;
+ mJustificationMode = justificationMode;
mHyphenationFrequency = hyphenationFrequency;
/*
@@ -303,7 +303,7 @@
.setEllipsize(mEllipsizeAt)
.setBreakStrategy(mBreakStrategy)
.setHyphenationFrequency(mHyphenationFrequency)
- .setJustify(mJustify);
+ .setJustificationMode(mJustificationMode);
reflowed.generate(b, false, true);
int n = reflowed.getLineCount();
// If the new layout has a blank line at the end, but it is not
@@ -811,7 +811,7 @@
private TextUtils.TruncateAt mEllipsizeAt;
private int mBreakStrategy;
private int mHyphenationFrequency;
- private boolean mJustify;
+ private int mJustificationMode;
private PackedIntVector mInts;
private PackedObjectVector<Directions> mObjects;
diff --git a/core/java/android/text/Layout.java b/core/java/android/text/Layout.java
index 53564f0..b47fce8 100644
--- a/core/java/android/text/Layout.java
+++ b/core/java/android/text/Layout.java
@@ -103,6 +103,21 @@
private static final ParagraphStyle[] NO_PARA_SPANS =
ArrayUtils.emptyArray(ParagraphStyle.class);
+ /** @hide */
+ @IntDef({JUSTIFICATION_MODE_NONE, JUSTIFICATION_MODE_INTER_WORD})
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface JustificationMode {}
+
+ /**
+ * Value for justification mode indicating no justification.
+ */
+ public static final int JUSTIFICATION_MODE_NONE = 0;
+
+ /**
+ * Value for justification mode indicating the text is justified by stretching word spacing.
+ */
+ public static final int JUSTIFICATION_MODE_INTER_WORD = 1;
+
/**
* Return how wide a layout must be in order to display the specified text with one line per
* paragraph.
@@ -219,8 +234,8 @@
}
/** @hide */
- protected void setJustify(boolean justify) {
- mJustify = justify;
+ protected void setJustificationMode(@JustificationMode int justificationMode) {
+ mJustificationMode = justificationMode;
}
/**
@@ -272,7 +287,7 @@
}
private boolean isJustificationRequired(int lineNum) {
- if (!mJustify) return false;
+ if (mJustificationMode == JUSTIFICATION_MODE_NONE) return false;
final int lineEnd = getLineEnd(lineNum);
return lineEnd < mText.length() && mText.charAt(lineEnd - 1) != '\n';
}
@@ -2229,7 +2244,7 @@
private boolean mSpannedText;
private TextDirectionHeuristic mTextDir;
private SpanSet<LineBackgroundSpan> mLineBackgroundSpans;
- private boolean mJustify;
+ private int mJustificationMode;
public static final int DIR_LEFT_TO_RIGHT = 1;
public static final int DIR_RIGHT_TO_LEFT = -1;
diff --git a/core/java/android/text/StaticLayout.java b/core/java/android/text/StaticLayout.java
index 9a2e0bb..74ff6dc 100644
--- a/core/java/android/text/StaticLayout.java
+++ b/core/java/android/text/StaticLayout.java
@@ -94,7 +94,7 @@
b.mMaxLines = Integer.MAX_VALUE;
b.mBreakStrategy = Layout.BREAK_STRATEGY_SIMPLE;
b.mHyphenationFrequency = Layout.HYPHENATION_FREQUENCY_NONE;
- b.mJustify = false;
+ b.mJustificationMode = Layout.JUSTIFICATION_MODE_NONE;
b.mMeasuredText = MeasuredText.obtain();
return b;
@@ -321,15 +321,15 @@
}
/**
- * Enables or disables paragraph justification. The default value is disabled (false).
- * If the last line is too short for justification, the last line will be displayed with
- * the alignment set by {@link #setAlignment}.
+ * Set paragraph justification mode. The default value is
+ * {@link Layout#JUSTIFICATION_MODE_NONE}. If the last line is too short for justification,
+ * the last line will be displayed with the alignment set by {@link #setAlignment}.
*
- * @param justify true for enabling and false for disabling paragraph justification.
+ * @param justificationMode justification mode for the paragraph.
* @return this builder, useful for chaining.
*/
- public Builder setJustify(boolean justify) {
- mJustify = justify;
+ public Builder setJustificationMode(@JustificationMode int justificationMode) {
+ mJustificationMode = justificationMode;
return this;
}
@@ -418,7 +418,7 @@
int mHyphenationFrequency;
int[] mLeftIndents;
int[] mRightIndents;
- boolean mJustify;
+ int mJustificationMode;
Paint.FontMetricsInt mFontMetricsInt = new Paint.FontMetricsInt();
@@ -572,7 +572,7 @@
mLeftIndents = b.mLeftIndents;
mRightIndents = b.mRightIndents;
- setJustify(b.mJustify);
+ setJustificationMode(b.mJustificationMode);
generate(b, b.mIncludePad, b.mIncludePad);
}
@@ -693,7 +693,8 @@
nSetupParagraph(b.mNativePtr, chs, paraEnd - paraStart,
firstWidth, firstWidthLineCount, restWidth,
variableTabStops, TAB_INCREMENT, b.mBreakStrategy, b.mHyphenationFrequency,
- b.mJustify);
+ // TODO: Support more justification mode, e.g. letter spacing, stretching.
+ b.mJustificationMode != Layout.JUSTIFICATION_MODE_NONE);
if (mLeftIndents != null || mRightIndents != null) {
// TODO(raph) performance: it would be better to do this once per layout rather
// than once per paragraph, but that would require a change to the native
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index 6f8df36..a111f2b 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -609,7 +609,7 @@
private int mBreakStrategy;
private int mHyphenationFrequency;
- private boolean mJustify;
+ private int mJustificationMode;
private int mMaximum = Integer.MAX_VALUE;
private int mMaxMode = LINES;
@@ -820,7 +820,7 @@
String fontFeatureSettings = null;
mBreakStrategy = Layout.BREAK_STRATEGY_SIMPLE;
mHyphenationFrequency = Layout.HYPHENATION_FREQUENCY_NONE;
- mJustify = false;
+ mJustificationMode = Layout.JUSTIFICATION_MODE_NONE;
final Resources.Theme theme = context.getTheme();
@@ -3737,14 +3737,15 @@
}
/**
- * Enables or disables full justification. The default value is false. If the last line is too
- * short for justification, the last line will be displayed with the alignment set by
- * {@link android.view.View#setTextAlignment}.
+ * Set justification mode. The default value is {@link Layout#JUSTIFICATION_MODE_NONE}. If the
+ * last line is too short for justification, the last line will be displayed with the
+ * alignment set by {@link android.view.View#setTextAlignment}.
*
- * @see #getJustify()
+ * @see #getJustificationMode()
*/
- public void setJustify(boolean justify) {
- mJustify = justify;
+ @Layout.JustificationMode
+ public void setJustificationMode(@Layout.JustificationMode int justificationMode) {
+ mJustificationMode = justificationMode;
if (mLayout != null) {
nullLayouts();
requestLayout();
@@ -3753,12 +3754,12 @@
}
/**
- * @return true if currently paragraph justification is enabled.
+ * @return true if currently paragraph justification mode.
*
- * @see #setJustify(boolean)
+ * @see #setJustificationMode(int)
*/
- public boolean getJustify() {
- return mJustify;
+ public @Layout.JustificationMode int getJustificationMode() {
+ return mJustificationMode;
}
/**
@@ -7678,7 +7679,7 @@
.setIncludePad(mIncludePad)
.setBreakStrategy(mBreakStrategy)
.setHyphenationFrequency(mHyphenationFrequency)
- .setJustify(mJustify)
+ .setJustificationMode(mJustificationMode)
.setMaxLines(mMaxMode == LINES ? mMaximum : Integer.MAX_VALUE);
if (shouldEllipsize) {
builder.setEllipsize(mEllipsize)
@@ -7720,7 +7721,7 @@
if (mText instanceof Spannable) {
result = new DynamicLayout(mText, mTransformed, mTextPaint, wantWidth,
alignment, mTextDir, mSpacingMult, mSpacingAdd, mIncludePad,
- mBreakStrategy, mHyphenationFrequency, mJustify,
+ mBreakStrategy, mHyphenationFrequency, mJustificationMode,
getKeyListener() == null ? effectiveEllipsize : null, ellipsisWidth);
} else {
if (boring == UNKNOWN_BORING) {
@@ -7770,7 +7771,7 @@
.setIncludePad(mIncludePad)
.setBreakStrategy(mBreakStrategy)
.setHyphenationFrequency(mHyphenationFrequency)
- .setJustify(mJustify)
+ .setJustificationMode(mJustificationMode)
.setMaxLines(mMaxMode == LINES ? mMaximum : Integer.MAX_VALUE);
if (shouldEllipsize) {
builder.setEllipsize(effectiveEllipsize)
@@ -8110,7 +8111,7 @@
.setIncludePad(getIncludeFontPadding())
.setBreakStrategy(getBreakStrategy())
.setHyphenationFrequency(getHyphenationFrequency())
- .setJustify(getJustify())
+ .setJustificationMode(getJustificationMode())
.setMaxLines(mMaxMode == LINES ? mMaximum : Integer.MAX_VALUE)
.setTextDirection(getTextDirectionHeuristic());