use of android.text.StaticLayout in project JustAndroid by chinaltz.
the class AbWheelView method createLayouts.
/**
* Creates layouts.
*
* @param widthItems width of items layout
* @param widthLabel width of label layout
*/
private void createLayouts(int widthItems, int widthLabel) {
if (itemsLayout == null || itemsLayout.getWidth() > widthItems) {
itemsLayout = new StaticLayout(buildText(isScrollingPerformed), itemsPaint, widthItems, widthLabel > 0 ? Layout.Alignment.ALIGN_OPPOSITE : Layout.Alignment.ALIGN_CENTER, 1, additionalItemHeight, false);
} else {
itemsLayout.increaseWidthTo(widthItems);
}
if (!isScrollingPerformed && (valueLayout == null || valueLayout.getWidth() > widthItems)) {
String text = getAdapter() != null ? getAdapter().getItem(currentItem) : null;
valueLayout = new StaticLayout(text != null ? text : "", valuePaint, widthItems, widthLabel > 0 ? Layout.Alignment.ALIGN_OPPOSITE : Layout.Alignment.ALIGN_CENTER, 1, additionalItemHeight, false);
} else if (isScrollingPerformed) {
valueLayout = null;
} else {
valueLayout.increaseWidthTo(widthItems);
}
if (widthLabel > 0) {
if (labelLayout == null || labelLayout.getWidth() > widthLabel) {
labelLayout = new StaticLayout(label, labelPaint, widthLabel, Layout.Alignment.ALIGN_NORMAL, 1, additionalItemHeight, false);
} else {
labelLayout.increaseWidthTo(widthLabel);
}
}
}
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());
}
use of android.text.StaticLayout in project android_frameworks_base by AOSPA.
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 AOSPA.
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 DirtyUnicorns.
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