Merge "Use fallback-based line spacing in TextView etc"
This commit is contained in:
committed by
Android (Google) Code Review
commit
2be7eff3a4
@@ -755,14 +755,18 @@ public class Editor {
|
||||
}
|
||||
}
|
||||
|
||||
private void chooseSize(PopupWindow pop, CharSequence text, TextView tv) {
|
||||
int wid = tv.getPaddingLeft() + tv.getPaddingRight();
|
||||
int ht = tv.getPaddingTop() + tv.getPaddingBottom();
|
||||
private void chooseSize(@NonNull PopupWindow pop, @NonNull CharSequence text,
|
||||
@NonNull TextView tv) {
|
||||
final int wid = tv.getPaddingLeft() + tv.getPaddingRight();
|
||||
final int ht = tv.getPaddingTop() + tv.getPaddingBottom();
|
||||
|
||||
int defaultWidthInPixels = mTextView.getResources().getDimensionPixelSize(
|
||||
final int defaultWidthInPixels = mTextView.getResources().getDimensionPixelSize(
|
||||
com.android.internal.R.dimen.textview_error_popup_default_width);
|
||||
Layout l = new StaticLayout(text, tv.getPaint(), defaultWidthInPixels,
|
||||
Layout.Alignment.ALIGN_NORMAL, 1, 0, true);
|
||||
final StaticLayout l = StaticLayout.Builder.obtain(text, 0, text.length(), tv.getPaint(),
|
||||
defaultWidthInPixels)
|
||||
.setUseLineSpacingFromFallbacks(tv.mUseFallbackLineSpacing)
|
||||
.build();
|
||||
|
||||
float max = 0;
|
||||
for (int i = 0; i < l.getLineCount(); i++) {
|
||||
max = Math.max(max, l.getLineWidth(i));
|
||||
|
||||
@@ -33,6 +33,7 @@ import android.graphics.Rect;
|
||||
import android.graphics.Region.Op;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build.VERSION_CODES;
|
||||
import android.text.Layout;
|
||||
import android.text.StaticLayout;
|
||||
import android.text.TextPaint;
|
||||
@@ -111,6 +112,7 @@ public class Switch extends CompoundButton {
|
||||
private CharSequence mTextOn;
|
||||
private CharSequence mTextOff;
|
||||
private boolean mShowText;
|
||||
private boolean mUseFallbackLineSpacing;
|
||||
|
||||
private int mTouchMode;
|
||||
private int mTouchSlop;
|
||||
@@ -246,6 +248,11 @@ public class Switch extends CompoundButton {
|
||||
com.android.internal.R.styleable.Switch_switchPadding, 0);
|
||||
mSplitTrack = a.getBoolean(com.android.internal.R.styleable.Switch_splitTrack, false);
|
||||
|
||||
// TODO: replace CUR_DEVELOPMENT with P once P is added to android.os.Build.VERSION_CODES.
|
||||
// STOPSHIP if the above TODO is not done.
|
||||
mUseFallbackLineSpacing =
|
||||
context.getApplicationInfo().targetSdkVersion >= VERSION_CODES.CUR_DEVELOPMENT;
|
||||
|
||||
ColorStateList thumbTintList = a.getColorStateList(
|
||||
com.android.internal.R.styleable.Switch_thumbTint);
|
||||
if (thumbTintList != null) {
|
||||
@@ -894,8 +901,9 @@ public class Switch extends CompoundButton {
|
||||
|
||||
int width = (int) Math.ceil(Layout.getDesiredWidth(transformed, 0,
|
||||
transformed.length(), mTextPaint, getTextDirectionHeuristic()));
|
||||
return new StaticLayout(transformed, mTextPaint, width,
|
||||
Layout.Alignment.ALIGN_NORMAL, 1.f, 0, true);
|
||||
return StaticLayout.Builder.obtain(transformed, 0, transformed.length(), mTextPaint, width)
|
||||
.setUseLineSpacingFromFallbacks(mUseFallbackLineSpacing)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -650,6 +650,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
||||
private boolean mListenerChanged = false;
|
||||
// True if internationalized input should be used for numbers and date and time.
|
||||
private final boolean mUseInternationalizedInput;
|
||||
// True if fallback fonts that end up getting used should be allowed to affect line spacing.
|
||||
/* package */ final boolean mUseFallbackLineSpacing;
|
||||
|
||||
@ViewDebug.ExportedProperty(category = "text")
|
||||
private int mGravity = Gravity.TOP | Gravity.START;
|
||||
@@ -1252,8 +1254,11 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
||||
final boolean numberPasswordInputType = variation
|
||||
== (EditorInfo.TYPE_CLASS_NUMBER | EditorInfo.TYPE_NUMBER_VARIATION_PASSWORD);
|
||||
|
||||
mUseInternationalizedInput =
|
||||
context.getApplicationInfo().targetSdkVersion >= VERSION_CODES.O;
|
||||
final int targetSdkVersion = context.getApplicationInfo().targetSdkVersion;
|
||||
mUseInternationalizedInput = targetSdkVersion >= VERSION_CODES.O;
|
||||
// TODO: replace CUR_DEVELOPMENT with P once P is added to android.os.Build.VERSION_CODES.
|
||||
// STOPSHIP if the above TODO is not done.
|
||||
mUseFallbackLineSpacing = targetSdkVersion >= VERSION_CODES.CUR_DEVELOPMENT;
|
||||
|
||||
if (inputMethod != null) {
|
||||
Class<?> c;
|
||||
@@ -7914,6 +7919,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
||||
.setTextDirection(mTextDir)
|
||||
.setLineSpacing(mSpacingAdd, mSpacingMult)
|
||||
.setIncludePad(mIncludePad)
|
||||
.setUseLineSpacingFromFallbacks(mUseFallbackLineSpacing)
|
||||
.setBreakStrategy(mBreakStrategy)
|
||||
.setHyphenationFrequency(mHyphenationFrequency)
|
||||
.setJustificationMode(mJustificationMode)
|
||||
@@ -7963,6 +7969,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
||||
.setTextDirection(mTextDir)
|
||||
.setLineSpacing(mSpacingAdd, mSpacingMult)
|
||||
.setIncludePad(mIncludePad)
|
||||
.setUseLineSpacingFromFallbacks(mUseFallbackLineSpacing)
|
||||
.setBreakStrategy(mBreakStrategy)
|
||||
.setHyphenationFrequency(mHyphenationFrequency)
|
||||
.setJustificationMode(mJustificationMode)
|
||||
@@ -8015,6 +8022,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
||||
.setTextDirection(mTextDir)
|
||||
.setLineSpacing(mSpacingAdd, mSpacingMult)
|
||||
.setIncludePad(mIncludePad)
|
||||
.setUseLineSpacingFromFallbacks(mUseFallbackLineSpacing)
|
||||
.setBreakStrategy(mBreakStrategy)
|
||||
.setHyphenationFrequency(mHyphenationFrequency)
|
||||
.setJustificationMode(mJustificationMode)
|
||||
@@ -8374,6 +8382,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
||||
layoutBuilder.setAlignment(getLayoutAlignment())
|
||||
.setLineSpacing(getLineSpacingExtra(), getLineSpacingMultiplier())
|
||||
.setIncludePad(getIncludeFontPadding())
|
||||
.setUseLineSpacingFromFallbacks(mUseFallbackLineSpacing)
|
||||
.setBreakStrategy(getBreakStrategy())
|
||||
.setHyphenationFrequency(getHyphenationFrequency())
|
||||
.setJustificationMode(getJustificationMode())
|
||||
|
||||
Reference in New Issue
Block a user