Search in sources :

Example 76 with StaticLayout

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

Example 77 with StaticLayout

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

Example 78 with StaticLayout

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

Example 79 with StaticLayout

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

Example 80 with StaticLayout

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