Search in sources :

Example 36 with StaticLayout

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);
        }
    }
}
Also used : StaticLayout(android.text.StaticLayout)

Example 37 with StaticLayout

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());
}
Also used : Layout(android.text.Layout) StaticLayout(android.text.StaticLayout) DynamicLayout(android.text.DynamicLayout) StaticLayout(android.text.StaticLayout) Paint(android.graphics.Paint)

Example 38 with StaticLayout

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);
    }
}
Also used : StaticLayout(android.text.StaticLayout) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Example 39 with StaticLayout

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;
}
Also used : StaticLayout(android.text.StaticLayout) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Example 40 with StaticLayout

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());
}
Also used : Layout(android.text.Layout) StaticLayout(android.text.StaticLayout) DynamicLayout(android.text.DynamicLayout) StaticLayout(android.text.StaticLayout) Paint(android.graphics.Paint)

Aggregations

StaticLayout (android.text.StaticLayout)80 TextPaint (android.text.TextPaint)56 Paint (android.graphics.Paint)45 Layout (android.text.Layout)21 DynamicLayout (android.text.DynamicLayout)9 RectF (android.graphics.RectF)6 Bitmap (android.graphics.Bitmap)3 NonNull (android.support.annotation.NonNull)3 BoringLayout (android.text.BoringLayout)3 SpannableStringBuilder (android.text.SpannableStringBuilder)3 KeyEvent (android.view.KeyEvent)3 MotionEvent (android.view.MotionEvent)3 AccessibilityEvent (android.view.accessibility.AccessibilityEvent)3 SuppressLint (android.annotation.SuppressLint)2 Canvas (android.graphics.Canvas)2 Rect (android.graphics.Rect)2 Spanned (android.text.Spanned)2 TruncateAt (android.text.TextUtils.TruncateAt)2 StyleSpan (android.text.style.StyleSpan)2 Animator (android.animation.Animator)1