use of android.text.StaticLayout in project WordPress-Android by wordpress-mobile.
the class AutoResizeTextView method getTextHeight.
// Set the text size of the text paint object and use a static layout to render text off screen before measuring
private int getTextHeight(CharSequence source, TextPaint paint, int width, float textSize) {
// modified: make a copy of the original TextPaint object for measuring
// (apparently the object gets modified while measuring, see also the
// docs for TextView.getPaint() (which states to access it read-only)
TextPaint paintCopy = new TextPaint(paint);
// Update the text paint object
paintCopy.setTextSize(textSize);
// Measure using a static layout
StaticLayout layout = new StaticLayout(source, paintCopy, width, Layout.Alignment.ALIGN_NORMAL, mSpacingMult, mSpacingAdd, true);
return layout.getHeight();
}
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 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;
}
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 AOSPA.
the class Editor method chooseSize.
private void chooseSize(PopupWindow pop, CharSequence text, TextView tv) {
int wid = tv.getPaddingLeft() + tv.getPaddingRight();
int ht = tv.getPaddingTop() + tv.getPaddingBottom();
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);
float max = 0;
for (int i = 0; i < l.getLineCount(); i++) {
max = Math.max(max, l.getLineWidth(i));
}
/*
* Now set the popup size to be big enough for the text plus the border capped
* to DEFAULT_MAX_POPUP_WIDTH
*/
pop.setWidth(wid + (int) Math.ceil(max));
pop.setHeight(ht + l.getHeight());
}
Aggregations