use of android.text.StaticLayout in project bilibili-android-client by HotBitmapGG.
the class OutlineTextView method onMeasure.
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
Layout layout = new StaticLayout(getText(), mTextPaintOutline, measureWidth(widthMeasureSpec), Layout.Alignment.ALIGN_CENTER, mSpacingMult, mSpacingAdd, mIncludePad);
int ex = (int) (mBorderSize * 2 + 1);
setMeasuredDimension(measureWidth(widthMeasureSpec) + ex, measureHeight(heightMeasureSpec) * layout.getLineCount() + ex);
}
use of android.text.StaticLayout in project UltimateAndroid by cymcsg.
the class AutofitTextView method getLineCount.
private static int getLineCount(CharSequence text, TextPaint paint, float size, float width, DisplayMetrics displayMetrics) {
paint.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, size, displayMetrics));
StaticLayout layout = new StaticLayout(text, paint, (int) width, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, true);
return layout.getLineCount();
}
use of android.text.StaticLayout in project Etar-Calendar by Etar-Group.
the class DayView method getEventLayout.
/**
* Return the layout for a numbered event. Create it if not already existing
*/
private StaticLayout getEventLayout(StaticLayout[] layouts, int i, Event event, Paint paint, Rect r) {
if (i < 0 || i >= layouts.length) {
return null;
}
StaticLayout layout = layouts[i];
// re-layout of events at min height)
if (layout == null || r.width() != layout.getWidth()) {
SpannableStringBuilder bob = new SpannableStringBuilder();
if (event.title != null) {
// MAX - 1 since we add a space
bob.append(drawTextSanitizer(event.title.toString(), MAX_EVENT_TEXT_LEN - 1));
bob.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, bob.length(), 0);
bob.append(' ');
}
if (event.location != null) {
bob.append(drawTextSanitizer(event.location.toString(), MAX_EVENT_TEXT_LEN - bob.length()));
}
switch(event.selfAttendeeStatus) {
case Attendees.ATTENDEE_STATUS_INVITED:
paint.setColor(event.color);
break;
case Attendees.ATTENDEE_STATUS_DECLINED:
paint.setColor(mEventTextColor);
paint.setAlpha(Utils.DECLINED_EVENT_TEXT_ALPHA);
break;
// Your own events
case Attendees.ATTENDEE_STATUS_NONE:
case Attendees.ATTENDEE_STATUS_ACCEPTED:
case Attendees.ATTENDEE_STATUS_TENTATIVE:
default:
paint.setColor(mEventTextColor);
break;
}
// Leave a one pixel boundary on the left and right of the rectangle for the event
layout = new StaticLayout(bob, 0, bob.length(), new TextPaint(paint), r.width(), Alignment.ALIGN_NORMAL, 1.0f, 0.0f, true, null, r.width());
layouts[i] = layout;
}
layout.getPaint().setAlpha(mEventsAlpha);
return layout;
}
use of android.text.StaticLayout in project weex-example by KalicyZhou.
the class WXTextDomObject method truncate.
@NonNull
public String truncate(@Nullable String source, @NonNull TextPaint paint, int desired, @Nullable TextUtils.TruncateAt truncateAt) {
if (!TextUtils.isEmpty(source)) {
StringBuilder builder;
Spanned spanned;
StaticLayout layout;
for (int i = source.length(); i > 0; i--) {
builder = new StringBuilder(i + 1);
builder.append(source, 0, i);
if (truncateAt != null) {
builder.append(ELLIPSIS);
}
spanned = createSpanned(builder.toString());
layout = new StaticLayout(spanned, paint, desired, Layout.Alignment.ALIGN_NORMAL, 1, 0, true);
if (layout.getLineCount() <= 1) {
return spanned.toString();
}
}
}
return "";
}
use of android.text.StaticLayout in project android_frameworks_base by DirtyUnicorns.
the class SubtitleView method computeMeasurements.
private boolean computeMeasurements(int maxWidth) {
if (mHasMeasurements && maxWidth == mLastMeasuredWidth) {
return true;
}
// Account for padding.
final int paddingX = mPaddingLeft + mPaddingRight + mInnerPaddingX * 2;
maxWidth -= paddingX;
if (maxWidth <= 0) {
return false;
}
// TODO: Implement minimum-difference line wrapping. Adding the results
// of Paint.getTextWidths() seems to return different values than
// StaticLayout.getWidth(), so this is non-trivial.
mHasMeasurements = true;
mLastMeasuredWidth = maxWidth;
mLayout = new StaticLayout(mText, mTextPaint, maxWidth, mAlignment, mSpacingMult, mSpacingAdd, true);
return true;
}
Aggregations