本文整理汇总了Java中android.text.BoringLayout.make方法的典型用法代码示例。如果您正苦于以下问题:Java BoringLayout.make方法的具体用法?Java BoringLayout.make怎么用?Java BoringLayout.make使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.text.BoringLayout
的用法示例。
在下文中一共展示了BoringLayout.make方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: makeSingleLayout
import android.text.BoringLayout; //导入方法依赖的package包/类
private Layout makeSingleLayout(int i, BoringLayout.Metrics metrics, int i2, Alignment alignment, boolean z, TextUtils.TruncateAt truncateAt, boolean z2) {
BoringLayout.Metrics isBoring;
if (metrics == UNKNOWN_BORING) {
isBoring = BoringLayout.isBoring(this.mText, this.mPaint, this.mBoring);
if (isBoring != null) {
this.mBoring = isBoring;
}
} else {
isBoring = metrics;
}
if (isBoring != null) {
if (isBoring.width <= i && (truncateAt == null || isBoring.width <= i2)) {
return BoringLayout.make(this.mText, this.mPaint, i, alignment, this.mLineSpacingMult, this.mLineSpacingAdd, isBoring, this.mIncludeFontPadding);
} else if (z && isBoring.width <= i) {
return BoringLayout.make(this.mText, this.mPaint, i, alignment, this.mLineSpacingMult, this.mLineSpacingAdd, isBoring, this.mIncludeFontPadding, truncateAt, i2);
} else if (z) {
return StaticLayoutWithMaxLines.create(this.mText, 0, this.mText.length(), this.mPaint, i, alignment, this.mLineSpacingMult, this.mLineSpacingAdd, this.mIncludeFontPadding, truncateAt, i2, this.mMaxLines);
} else {
return new StaticLayout(this.mText, this.mPaint, i, alignment, this.mLineSpacingMult, this.mLineSpacingAdd, this.mIncludeFontPadding);
}
} else if (z) {
return StaticLayoutWithMaxLines.create(this.mText, 0, this.mText.length(), this.mPaint, i, alignment, this.mLineSpacingMult, this.mLineSpacingAdd, this.mIncludeFontPadding, truncateAt, i2, this.mMaxLines);
} else {
return new StaticLayout(this.mText, this.mPaint, i, alignment, this.mLineSpacingMult, this.mLineSpacingAdd, this.mIncludeFontPadding);
}
}
示例2: updateLayout
import android.text.BoringLayout; //导入方法依赖的package包/类
private void updateLayout(){
if(mContactName == null)
return;
Rect bounds = getBounds();
if(bounds.width() == 0 || bounds.height() == 0)
return;
int outerWidth = Math.max(0, bounds.width() - bounds.height() - mPaddingLeft - mPaddingRight);
mMetrics.width = Math.round(mTextPaint.measureText(mContactName, 0, mContactName.length()) + 0.5f);
if(mBoringLayout == null)
mBoringLayout = BoringLayout.make(mContactName, mTextPaint, outerWidth, Layout.Alignment.ALIGN_NORMAL, 1f, 1f, mMetrics, true, TextUtils.TruncateAt.END, outerWidth);
else
mBoringLayout = mBoringLayout.replaceOrMake(mContactName, mTextPaint, outerWidth, Layout.Alignment.ALIGN_NORMAL, 1f, 1f, mMetrics, true, TextUtils.TruncateAt.END, outerWidth);
}
示例3: updateLayout
import android.text.BoringLayout; //导入方法依赖的package包/类
private void updateLayout(){
if(mContactName == null)
return;
Rect bounds = getBounds();
if(bounds.width() == 0 || bounds.height() == 0)
return;
int outerWidth = Math.max(0, bounds.width() - bounds.height() - mPaddingLeft - mPaddingRight);
mMetrics.width = (int) FloatMath.ceil(mTextPaint.measureText(mContactName, 0, mContactName.length()));
if(mBoringLayout == null)
mBoringLayout = BoringLayout.make(mContactName, mTextPaint, outerWidth, Layout.Alignment.ALIGN_NORMAL, 1f, 1f, mMetrics, true, TextUtils.TruncateAt.END, outerWidth);
else
mBoringLayout = mBoringLayout.replaceOrMake(mContactName, mTextPaint, outerWidth, Layout.Alignment.ALIGN_NORMAL, 1f, 1f, mMetrics, true, TextUtils.TruncateAt.END, outerWidth);
}
示例4: onMeasure
import android.text.BoringLayout; //导入方法依赖的package包/类
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if (mLayout == null && !TextUtils.isEmpty(mText)) {
BoringLayout.Metrics fm = new BoringLayout.Metrics();
fm.width = (int) Layout.getDesiredWidth(mText, mTextPaint);
mLayout = BoringLayout.make(mText, mTextPaint, MeasureSpec.getSize(widthMeasureSpec),
TextViewAttrsHelper.getLayoutAlignment(this, getGravity()), mAttrsHelper.mSpacingMultiplier, mAttrsHelper.mSpacingAdd, fm, true);
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
示例5: ContactChipSpan
import android.text.BoringLayout; //导入方法依赖的package包/类
public ContactChipSpan(CharSequence name, int height, int maxWidth, int paddingLeft, int paddingRight, Typeface typeface, int textColor, int textSize, int backgroundColor) {
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mPaint.setStyle(Paint.Style.FILL);
mPaint.setColor(textColor);
mPaint.setTypeface(typeface);
mPaint.setTextSize(textSize);
mTextPaint = new TextPaint(mPaint);
mRect = new RectF();
mMatrix = new Matrix();
mContactName = name;
mPaddingLeft = paddingLeft;
mPaddingRight = paddingRight;
mBackgroundColor = backgroundColor;
mHeight = height;
mWidth = Math.round(Math.min(maxWidth, mPaint.measureText(name, 0, name.length()) + paddingLeft + paddingRight + height));
int outerWidth = Math.max(0, mWidth - mPaddingLeft - mPaddingRight - mHeight);
Paint.FontMetricsInt temp = mTextPaint.getFontMetricsInt();
BoringLayout.Metrics mMetrics = new BoringLayout.Metrics();
mMetrics.width = Math.round(mTextPaint.measureText(mContactName, 0, mContactName.length()) + 0.5f);
mMetrics.ascent = temp.ascent;
mMetrics.bottom = temp.bottom;
mMetrics.descent = temp.descent;
mMetrics.top = temp.top;
mMetrics.leading = temp.leading;
mBoringLayout = BoringLayout.make(mContactName, mTextPaint, outerWidth, Layout.Alignment.ALIGN_NORMAL, 1f, 1f, mMetrics, true, TextUtils.TruncateAt.END, outerWidth);
}
示例6: obtainLayout
import android.text.BoringLayout; //导入方法依赖的package包/类
private Layout obtainLayout(CharSequence source, TextPaint paint, int widthMeasureSpec, boolean isSubtitle) {
int width = MeasureSpec.getSize(widthMeasureSpec) - super.getCompoundPaddingLeft() - super.getCompoundPaddingRight();
BoringLayout.Metrics metrics = BoringLayout.isBoring(source, paint);
Layout.Alignment alignment = isSubtitle ? Layout.Alignment.ALIGN_NORMAL : Layout.Alignment.ALIGN_OPPOSITE;
if (metrics != null) {
return BoringLayout.make(source, paint, width, alignment, 1.0f, 0, metrics, false);
} else {
return new StaticLayout(source, paint, width, alignment, 1.0f, 0, false);
}
}
示例7: ContactChipSpan
import android.text.BoringLayout; //导入方法依赖的package包/类
public ContactChipSpan(CharSequence name, int height, int maxWidth, int paddingLeft, int paddingRight, Typeface typeface, int textColor, int textSize, int backgroundColor) {
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mPaint.setStyle(Paint.Style.FILL);
mPaint.setColor(textColor);
mPaint.setTypeface(typeface);
mPaint.setTextSize(textSize);
mTextPaint = new TextPaint(mPaint);
mRect = new RectF();
mMatrix = new Matrix();
mContactName = name;
mPaddingLeft = paddingLeft;
mPaddingRight = paddingRight;
mBackgroundColor = backgroundColor;
mHeight = height;
mWidth = Math.round(Math.min(maxWidth, mPaint.measureText(name, 0, name.length()) + paddingLeft + paddingRight + height));
int outerWidth = Math.max(0, mWidth - mPaddingLeft - mPaddingRight - mHeight);
Paint.FontMetricsInt temp = mTextPaint.getFontMetricsInt();
BoringLayout.Metrics mMetrics = new BoringLayout.Metrics();
mMetrics.width = (int)FloatMath.ceil(mTextPaint.measureText(mContactName, 0, mContactName.length()));
mMetrics.ascent = temp.ascent;
mMetrics.bottom = temp.bottom;
mMetrics.descent = temp.descent;
mMetrics.top = temp.top;
mMetrics.leading = temp.leading;
mBoringLayout = BoringLayout.make(mContactName, mTextPaint, outerWidth, Layout.Alignment.ALIGN_NORMAL, 1f, 1f, mMetrics, true, TextUtils.TruncateAt.END, outerWidth);
}
示例8: measure
import android.text.BoringLayout; //导入方法依赖的package包/类
@Override
public void measure(CSSNode node, float width, float height, MeasureOutput measureOutput) {
// TODO(5578671): Handle text direction (see View#getTextDirectionHeuristic)
ReactTextShadowNode reactCSSNode = (ReactTextShadowNode) node;
TextPaint textPaint = sTextPaintInstance;
Layout layout;
Spanned text = Assertions.assertNotNull(
reactCSSNode.mPreparedSpannableText,
"Spannable element has not been prepared in onBeforeLayout");
BoringLayout.Metrics boring = BoringLayout.isBoring(text, textPaint);
float desiredWidth = boring == null ?
Layout.getDesiredWidth(text, textPaint) : Float.NaN;
if (boring == null &&
(CSSConstants.isUndefined(width) ||
(!CSSConstants.isUndefined(desiredWidth) && desiredWidth <= width))) {
// Is used when the width is not known and the text is not boring, ie. if it contains
// unicode characters.
layout = new StaticLayout(
text,
textPaint,
(int) Math.ceil(desiredWidth),
Layout.Alignment.ALIGN_NORMAL,
1,
0,
true);
} else if (boring != null && (CSSConstants.isUndefined(width) || boring.width <= width)) {
// Is used for single-line, boring text when the width is either unknown or bigger
// than the width of the text.
layout = BoringLayout.make(
text,
textPaint,
boring.width,
Layout.Alignment.ALIGN_NORMAL,
1,
0,
boring,
true);
} else {
// Is used for multiline, boring text and the width is known.
layout = new StaticLayout(
text,
textPaint,
(int) width,
Layout.Alignment.ALIGN_NORMAL,
1,
0,
true);
}
measureOutput.height = layout.getHeight();
measureOutput.width = layout.getWidth();
if (reactCSSNode.mNumberOfLines != UNSET &&
reactCSSNode.mNumberOfLines < layout.getLineCount()) {
measureOutput.height = layout.getLineBottom(reactCSSNode.mNumberOfLines - 1);
}
if (reactCSSNode.mLineHeight != UNSET) {
int lines = reactCSSNode.mNumberOfLines != UNSET
? Math.min(reactCSSNode.mNumberOfLines, layout.getLineCount())
: layout.getLineCount();
float lineHeight = PixelUtil.toPixelFromSP(reactCSSNode.mLineHeight);
measureOutput.height = lineHeight * lines;
}
}
示例9: remakeLayout
import android.text.BoringLayout; //导入方法依赖的package包/类
private void remakeLayout() {
if (getWidth() > 0) {
LocalDate day = getRelativeFirstDay(-1);
for (int i = 0; i < layouts.length; i++) {
String dayText = String.valueOf(day.getDayOfMonth());
if (layouts[i] == null) {
layouts[i] = BoringLayout.make(dayText, dayTextPaint, dayWidth,
Layout.Alignment.ALIGN_CENTER, 1f, 1f, dayMetrics, false, ellipsize,
dayWidth);
} else {
layouts[i].replaceOrMake(dayText, dayTextPaint, dayWidth,
Layout.Alignment.ALIGN_CENTER, 1f, 1f, dayMetrics, false, ellipsize,
dayWidth);
}
day = day.plusDays(1);
}
DayOfWeek dayOfWeek = firstDayOfWeek; // first index is 1
for (int i = 0; i < dayLabelLayouts.length; i++) {
CharSequence name;
if (labelNames == null) {
name = dayOfWeek.getDisplayName(TextStyle.SHORT, Locale.getDefault());
} else {
int index = dayOfWeek.getValue() - 1;
name = labelNames[index];
}
if (dayLabelLayouts[i] == null) {
dayLabelLayouts[i] = BoringLayout.make(name, dayLabelTextPain, dayWidth,
Layout.Alignment.ALIGN_CENTER, 1f, 1f, dayLabelMetrics, false, ellipsize,
dayWidth);
} else {
dayLabelLayouts[i].replaceOrMake(name, dayLabelTextPain, dayWidth,
Layout.Alignment.ALIGN_CENTER, 1f, 1f, dayLabelMetrics, false, ellipsize,
dayWidth);
}
dayOfWeek = dayOfWeek.plus(1);
}
}
}
示例10: measure
import android.text.BoringLayout; //导入方法依赖的package包/类
@Override
public void measure(
CSSNode node,
float width,
CSSMeasureMode widthMode,
float height,
CSSMeasureMode heightMode,
MeasureOutput measureOutput) {
// TODO(5578671): Handle text direction (see View#getTextDirectionHeuristic)
ReactTextShadowNode reactCSSNode = (ReactTextShadowNode) node;
TextPaint textPaint = sTextPaintInstance;
Layout layout;
Spanned text = Assertions.assertNotNull(
reactCSSNode.mPreparedSpannableText,
"Spannable element has not been prepared in onBeforeLayout");
BoringLayout.Metrics boring = BoringLayout.isBoring(text, textPaint);
float desiredWidth = boring == null ?
Layout.getDesiredWidth(text, textPaint) : Float.NaN;
// technically, width should never be negative, but there is currently a bug in
boolean unconstrainedWidth = widthMode == CSSMeasureMode.UNDEFINED || width < 0;
if (boring == null &&
(unconstrainedWidth ||
(!CSSConstants.isUndefined(desiredWidth) && desiredWidth <= width))) {
// Is used when the width is not known and the text is not boring, ie. if it contains
// unicode characters.
layout = new StaticLayout(
text,
textPaint,
(int) Math.ceil(desiredWidth),
Layout.Alignment.ALIGN_NORMAL,
1,
0,
true);
} else if (boring != null && (unconstrainedWidth || boring.width <= width)) {
// Is used for single-line, boring text when the width is either unknown or bigger
// than the width of the text.
layout = BoringLayout.make(
text,
textPaint,
boring.width,
Layout.Alignment.ALIGN_NORMAL,
1,
0,
boring,
true);
} else {
// Is used for multiline, boring text and the width is known.
layout = new StaticLayout(
text,
textPaint,
(int) width,
Layout.Alignment.ALIGN_NORMAL,
1,
0,
true);
}
measureOutput.height = layout.getHeight();
measureOutput.width = layout.getWidth();
if (reactCSSNode.mNumberOfLines != UNSET &&
reactCSSNode.mNumberOfLines < layout.getLineCount()) {
measureOutput.height = layout.getLineBottom(reactCSSNode.mNumberOfLines - 1);
}
if (reactCSSNode.mLineHeight != UNSET) {
int lines = reactCSSNode.mNumberOfLines != UNSET
? Math.min(reactCSSNode.mNumberOfLines, layout.getLineCount())
: layout.getLineCount();
float lineHeight = PixelUtil.toPixelFromSP(reactCSSNode.mLineHeight);
measureOutput.height = lineHeight * lines;
}
}
示例11: measure
import android.text.BoringLayout; //导入方法依赖的package包/类
@Override
public void measure(
CSSNodeAPI node,
float width,
CSSMeasureMode widthMode,
float height,
CSSMeasureMode heightMode,
MeasureOutput measureOutput) {
// TODO(5578671): Handle text direction (see View#getTextDirectionHeuristic)
ReactTextShadowNode reactCSSNode = (ReactTextShadowNode) node;
TextPaint textPaint = sTextPaintInstance;
Layout layout;
Spanned text = Assertions.assertNotNull(
reactCSSNode.mPreparedSpannableText,
"Spannable element has not been prepared in onBeforeLayout");
BoringLayout.Metrics boring = BoringLayout.isBoring(text, textPaint);
float desiredWidth = boring == null ?
Layout.getDesiredWidth(text, textPaint) : Float.NaN;
// technically, width should never be negative, but there is currently a bug in
boolean unconstrainedWidth = widthMode == CSSMeasureMode.UNDEFINED || width < 0;
if (boring == null &&
(unconstrainedWidth ||
(!CSSConstants.isUndefined(desiredWidth) && desiredWidth <= width))) {
// Is used when the width is not known and the text is not boring, ie. if it contains
// unicode characters.
layout = new StaticLayout(
text,
textPaint,
(int) Math.ceil(desiredWidth),
Layout.Alignment.ALIGN_NORMAL,
1.f,
0.f,
true);
} else if (boring != null && (unconstrainedWidth || boring.width <= width)) {
// Is used for single-line, boring text when the width is either unknown or bigger
// than the width of the text.
layout = BoringLayout.make(
text,
textPaint,
boring.width,
Layout.Alignment.ALIGN_NORMAL,
1.f,
0.f,
boring,
true);
} else {
// Is used for multiline, boring text and the width is known.
layout = new StaticLayout(
text,
textPaint,
(int) width,
Layout.Alignment.ALIGN_NORMAL,
1.f,
0.f,
true);
}
measureOutput.height = layout.getHeight();
measureOutput.width = layout.getWidth();
if (reactCSSNode.mNumberOfLines != UNSET &&
reactCSSNode.mNumberOfLines < layout.getLineCount()) {
measureOutput.height = layout.getLineBottom(reactCSSNode.mNumberOfLines - 1);
}
}