use of android.text.StaticLayout in project android_frameworks_base by ResurrectionRemix.
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());
}
use of android.text.StaticLayout in project android_frameworks_base by ResurrectionRemix.
the class SubtitleView method onMeasure.
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
final int widthSpec = MeasureSpec.getSize(widthMeasureSpec);
if (computeMeasurements(widthSpec)) {
final StaticLayout layout = mLayout;
// Account for padding.
final int paddingX = mPaddingLeft + mPaddingRight + mInnerPaddingX * 2;
final int width = layout.getWidth() + paddingX;
final int height = layout.getHeight() + mPaddingTop + mPaddingBottom;
setMeasuredDimension(width, height);
} else {
setMeasuredDimension(MEASURED_STATE_TOO_SMALL, MEASURED_STATE_TOO_SMALL);
}
}
use of android.text.StaticLayout in project android_frameworks_base by crdroidandroid.
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 android_frameworks_base by crdroidandroid.
the class SubtitleView method onDraw.
@Override
protected void onDraw(Canvas c) {
final StaticLayout layout = mLayout;
if (layout == null) {
return;
}
final int saveCount = c.save();
final int innerPaddingX = mInnerPaddingX;
c.translate(mPaddingLeft + innerPaddingX, mPaddingTop);
final int lineCount = layout.getLineCount();
final Paint textPaint = mTextPaint;
final Paint paint = mPaint;
final RectF bounds = mLineBounds;
if (Color.alpha(mBackgroundColor) > 0) {
final float cornerRadius = mCornerRadius;
float previousBottom = layout.getLineTop(0);
paint.setColor(mBackgroundColor);
paint.setStyle(Style.FILL);
for (int i = 0; i < lineCount; i++) {
bounds.left = layout.getLineLeft(i) - innerPaddingX;
bounds.right = layout.getLineRight(i) + innerPaddingX;
bounds.top = previousBottom;
bounds.bottom = layout.getLineBottom(i);
previousBottom = bounds.bottom;
c.drawRoundRect(bounds, cornerRadius, cornerRadius, paint);
}
}
final int edgeType = mEdgeType;
if (edgeType == CaptionStyle.EDGE_TYPE_OUTLINE) {
textPaint.setStrokeJoin(Join.ROUND);
textPaint.setStrokeWidth(mOutlineWidth);
textPaint.setColor(mEdgeColor);
textPaint.setStyle(Style.FILL_AND_STROKE);
for (int i = 0; i < lineCount; i++) {
layout.drawText(c, i, i);
}
} else if (edgeType == CaptionStyle.EDGE_TYPE_DROP_SHADOW) {
textPaint.setShadowLayer(mShadowRadius, mShadowOffsetX, mShadowOffsetY, mEdgeColor);
} else if (edgeType == CaptionStyle.EDGE_TYPE_RAISED || edgeType == CaptionStyle.EDGE_TYPE_DEPRESSED) {
final boolean raised = edgeType == CaptionStyle.EDGE_TYPE_RAISED;
final int colorUp = raised ? Color.WHITE : mEdgeColor;
final int colorDown = raised ? mEdgeColor : Color.WHITE;
final float offset = mShadowRadius / 2f;
textPaint.setColor(mForegroundColor);
textPaint.setStyle(Style.FILL);
textPaint.setShadowLayer(mShadowRadius, -offset, -offset, colorUp);
for (int i = 0; i < lineCount; i++) {
layout.drawText(c, i, i);
}
textPaint.setShadowLayer(mShadowRadius, offset, offset, colorDown);
}
textPaint.setColor(mForegroundColor);
textPaint.setStyle(Style.FILL);
for (int i = 0; i < lineCount; i++) {
layout.drawText(c, i, i);
}
textPaint.setShadowLayer(0, 0, 0, 0);
c.restoreToCount(saveCount);
}
use of android.text.StaticLayout in project android_frameworks_base by crdroidandroid.
the class SubtitleView method onMeasure.
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
final int widthSpec = MeasureSpec.getSize(widthMeasureSpec);
if (computeMeasurements(widthSpec)) {
final StaticLayout layout = mLayout;
// Account for padding.
final int paddingX = mPaddingLeft + mPaddingRight + mInnerPaddingX * 2;
final int width = layout.getWidth() + paddingX;
final int height = layout.getHeight() + mPaddingTop + mPaddingBottom;
setMeasuredDimension(width, height);
} else {
setMeasuredDimension(MEASURED_STATE_TOO_SMALL, MEASURED_STATE_TOO_SMALL);
}
}
Aggregations