Search in sources :

Example 1 with Alignment

use of android.text.Layout.Alignment in project platform_frameworks_base by android.

the class Touch method scrollTo.

/**
     * Scrolls the specified widget to the specified coordinates, except
     * constrains the X scrolling position to the horizontal regions of
     * the text that will be visible after scrolling to the specified
     * Y position.
     */
public static void scrollTo(TextView widget, Layout layout, int x, int y) {
    final int horizontalPadding = widget.getTotalPaddingLeft() + widget.getTotalPaddingRight();
    final int availableWidth = widget.getWidth() - horizontalPadding;
    final int top = layout.getLineForVertical(y);
    Alignment a = layout.getParagraphAlignment(top);
    boolean ltr = layout.getParagraphDirection(top) > 0;
    int left, right;
    if (widget.getHorizontallyScrolling()) {
        final int verticalPadding = widget.getTotalPaddingTop() + widget.getTotalPaddingBottom();
        final int bottom = layout.getLineForVertical(y + widget.getHeight() - verticalPadding);
        left = Integer.MAX_VALUE;
        right = 0;
        for (int i = top; i <= bottom; i++) {
            left = (int) Math.min(left, layout.getLineLeft(i));
            right = (int) Math.max(right, layout.getLineRight(i));
        }
    } else {
        left = 0;
        right = availableWidth;
    }
    final int actualWidth = right - left;
    if (actualWidth < availableWidth) {
        if (a == Alignment.ALIGN_CENTER) {
            x = left - ((availableWidth - actualWidth) / 2);
        } else if ((ltr && (a == Alignment.ALIGN_OPPOSITE)) || (!ltr && (a == Alignment.ALIGN_NORMAL)) || (a == Alignment.ALIGN_RIGHT)) {
            // align_opposite does NOT mean align_right, we need the paragraph
            // direction to resolve it to left or right
            x = left - (availableWidth - actualWidth);
        } else {
            x = left;
        }
    } else {
        x = Math.min(x, right - availableWidth);
        x = Math.max(x, left);
    }
    widget.scrollTo(x, y);
}
Also used : Alignment(android.text.Layout.Alignment)

Example 2 with Alignment

use of android.text.Layout.Alignment in project ExoPlayer by google.

the class SubtitlePainter method setupTextLayout.

private void setupTextLayout() {
    int parentWidth = parentRight - parentLeft;
    int parentHeight = parentBottom - parentTop;
    textPaint.setTextSize(textSizePx);
    int textPaddingX = (int) (textSizePx * INNER_PADDING_RATIO + 0.5f);
    int availableWidth = parentWidth - textPaddingX * 2;
    if (cueSize != Cue.DIMEN_UNSET) {
        availableWidth = (int) (availableWidth * cueSize);
    }
    if (availableWidth <= 0) {
        Log.w(TAG, "Skipped drawing subtitle cue (insufficient space)");
        return;
    }
    Alignment textAlignment = cueTextAlignment == null ? Alignment.ALIGN_CENTER : cueTextAlignment;
    textLayout = new StaticLayout(cueText, textPaint, availableWidth, textAlignment, spacingMult, spacingAdd, true);
    int textHeight = textLayout.getHeight();
    int textWidth = 0;
    int lineCount = textLayout.getLineCount();
    for (int i = 0; i < lineCount; i++) {
        textWidth = Math.max((int) Math.ceil(textLayout.getLineWidth(i)), textWidth);
    }
    if (cueSize != Cue.DIMEN_UNSET && textWidth < availableWidth) {
        textWidth = availableWidth;
    }
    textWidth += textPaddingX * 2;
    int textLeft;
    int textRight;
    if (cuePosition != Cue.DIMEN_UNSET) {
        int anchorPosition = Math.round(parentWidth * cuePosition) + parentLeft;
        textLeft = cuePositionAnchor == Cue.ANCHOR_TYPE_END ? anchorPosition - textWidth : cuePositionAnchor == Cue.ANCHOR_TYPE_MIDDLE ? (anchorPosition * 2 - textWidth) / 2 : anchorPosition;
        textLeft = Math.max(textLeft, parentLeft);
        textRight = Math.min(textLeft + textWidth, parentRight);
    } else {
        textLeft = (parentWidth - textWidth) / 2;
        textRight = textLeft + textWidth;
    }
    textWidth = textRight - textLeft;
    if (textWidth <= 0) {
        Log.w(TAG, "Skipped drawing subtitle cue (invalid horizontal positioning)");
        return;
    }
    int textTop;
    if (cueLine != Cue.DIMEN_UNSET) {
        int anchorPosition;
        if (cueLineType == Cue.LINE_TYPE_FRACTION) {
            anchorPosition = Math.round(parentHeight * cueLine) + parentTop;
        } else {
            // cueLineType == Cue.LINE_TYPE_NUMBER
            int firstLineHeight = textLayout.getLineBottom(0) - textLayout.getLineTop(0);
            if (cueLine >= 0) {
                anchorPosition = Math.round(cueLine * firstLineHeight) + parentTop;
            } else {
                anchorPosition = Math.round((cueLine + 1) * firstLineHeight) + parentBottom;
            }
        }
        textTop = cueLineAnchor == Cue.ANCHOR_TYPE_END ? anchorPosition - textHeight : cueLineAnchor == Cue.ANCHOR_TYPE_MIDDLE ? (anchorPosition * 2 - textHeight) / 2 : anchorPosition;
        if (textTop + textHeight > parentBottom) {
            textTop = parentBottom - textHeight;
        } else if (textTop < parentTop) {
            textTop = parentTop;
        }
    } else {
        textTop = parentBottom - textHeight - (int) (parentHeight * bottomPaddingFraction);
    }
    // Update the derived drawing variables.
    this.textLayout = new StaticLayout(cueText, textPaint, textWidth, textAlignment, spacingMult, spacingAdd, true);
    this.textLeft = textLeft;
    this.textTop = textTop;
    this.textPaddingX = textPaddingX;
}
Also used : Alignment(android.text.Layout.Alignment) StaticLayout(android.text.StaticLayout) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Example 3 with Alignment

use of android.text.Layout.Alignment in project android_frameworks_base by ResurrectionRemix.

the class Touch method scrollTo.

/**
     * Scrolls the specified widget to the specified coordinates, except
     * constrains the X scrolling position to the horizontal regions of
     * the text that will be visible after scrolling to the specified
     * Y position.
     */
public static void scrollTo(TextView widget, Layout layout, int x, int y) {
    final int horizontalPadding = widget.getTotalPaddingLeft() + widget.getTotalPaddingRight();
    final int availableWidth = widget.getWidth() - horizontalPadding;
    final int top = layout.getLineForVertical(y);
    Alignment a = layout.getParagraphAlignment(top);
    boolean ltr = layout.getParagraphDirection(top) > 0;
    int left, right;
    if (widget.getHorizontallyScrolling()) {
        final int verticalPadding = widget.getTotalPaddingTop() + widget.getTotalPaddingBottom();
        final int bottom = layout.getLineForVertical(y + widget.getHeight() - verticalPadding);
        left = Integer.MAX_VALUE;
        right = 0;
        for (int i = top; i <= bottom; i++) {
            left = (int) Math.min(left, layout.getLineLeft(i));
            right = (int) Math.max(right, layout.getLineRight(i));
        }
    } else {
        left = 0;
        right = availableWidth;
    }
    final int actualWidth = right - left;
    if (actualWidth < availableWidth) {
        if (a == Alignment.ALIGN_CENTER) {
            x = left - ((availableWidth - actualWidth) / 2);
        } else if ((ltr && (a == Alignment.ALIGN_OPPOSITE)) || (!ltr && (a == Alignment.ALIGN_NORMAL)) || (a == Alignment.ALIGN_RIGHT)) {
            // align_opposite does NOT mean align_right, we need the paragraph
            // direction to resolve it to left or right
            x = left - (availableWidth - actualWidth);
        } else {
            x = left;
        }
    } else {
        x = Math.min(x, right - availableWidth);
        x = Math.max(x, left);
    }
    widget.scrollTo(x, y);
}
Also used : Alignment(android.text.Layout.Alignment)

Example 4 with Alignment

use of android.text.Layout.Alignment in project android_frameworks_base by ParanoidAndroid.

the class Touch method scrollTo.

/**
     * Scrolls the specified widget to the specified coordinates, except
     * constrains the X scrolling position to the horizontal regions of
     * the text that will be visible after scrolling to the specified
     * Y position.
     */
public static void scrollTo(TextView widget, Layout layout, int x, int y) {
    final int horizontalPadding = widget.getTotalPaddingLeft() + widget.getTotalPaddingRight();
    final int availableWidth = widget.getWidth() - horizontalPadding;
    final int top = layout.getLineForVertical(y);
    Alignment a = layout.getParagraphAlignment(top);
    boolean ltr = layout.getParagraphDirection(top) > 0;
    int left, right;
    if (widget.getHorizontallyScrolling()) {
        final int verticalPadding = widget.getTotalPaddingTop() + widget.getTotalPaddingBottom();
        final int bottom = layout.getLineForVertical(y + widget.getHeight() - verticalPadding);
        left = Integer.MAX_VALUE;
        right = 0;
        for (int i = top; i <= bottom; i++) {
            left = (int) Math.min(left, layout.getLineLeft(i));
            right = (int) Math.max(right, layout.getLineRight(i));
        }
    } else {
        left = 0;
        right = availableWidth;
    }
    final int actualWidth = right - left;
    if (actualWidth < availableWidth) {
        if (a == Alignment.ALIGN_CENTER) {
            x = left - ((availableWidth - actualWidth) / 2);
        } else if ((ltr && (a == Alignment.ALIGN_OPPOSITE)) || (!ltr && (a == Alignment.ALIGN_NORMAL)) || (a == Alignment.ALIGN_RIGHT)) {
            // align_opposite does NOT mean align_right, we need the paragraph
            // direction to resolve it to left or right
            x = left - (availableWidth - actualWidth);
        } else {
            x = left;
        }
    } else {
        x = Math.min(x, right - availableWidth);
        x = Math.max(x, left);
    }
    widget.scrollTo(x, y);
}
Also used : Alignment(android.text.Layout.Alignment)

Example 5 with Alignment

use of android.text.Layout.Alignment in project android_frameworks_base by crdroidandroid.

the class Touch method scrollTo.

/**
     * Scrolls the specified widget to the specified coordinates, except
     * constrains the X scrolling position to the horizontal regions of
     * the text that will be visible after scrolling to the specified
     * Y position.
     */
public static void scrollTo(TextView widget, Layout layout, int x, int y) {
    final int horizontalPadding = widget.getTotalPaddingLeft() + widget.getTotalPaddingRight();
    final int availableWidth = widget.getWidth() - horizontalPadding;
    final int top = layout.getLineForVertical(y);
    Alignment a = layout.getParagraphAlignment(top);
    boolean ltr = layout.getParagraphDirection(top) > 0;
    int left, right;
    if (widget.getHorizontallyScrolling()) {
        final int verticalPadding = widget.getTotalPaddingTop() + widget.getTotalPaddingBottom();
        final int bottom = layout.getLineForVertical(y + widget.getHeight() - verticalPadding);
        left = Integer.MAX_VALUE;
        right = 0;
        for (int i = top; i <= bottom; i++) {
            left = (int) Math.min(left, layout.getLineLeft(i));
            right = (int) Math.max(right, layout.getLineRight(i));
        }
    } else {
        left = 0;
        right = availableWidth;
    }
    final int actualWidth = right - left;
    if (actualWidth < availableWidth) {
        if (a == Alignment.ALIGN_CENTER) {
            x = left - ((availableWidth - actualWidth) / 2);
        } else if ((ltr && (a == Alignment.ALIGN_OPPOSITE)) || (!ltr && (a == Alignment.ALIGN_NORMAL)) || (a == Alignment.ALIGN_RIGHT)) {
            // align_opposite does NOT mean align_right, we need the paragraph
            // direction to resolve it to left or right
            x = left - (availableWidth - actualWidth);
        } else {
            x = left;
        }
    } else {
        x = Math.min(x, right - availableWidth);
        x = Math.max(x, left);
    }
    widget.scrollTo(x, y);
}
Also used : Alignment(android.text.Layout.Alignment)

Aggregations

Alignment (android.text.Layout.Alignment)8 Paint (android.graphics.Paint)1 StaticLayout (android.text.StaticLayout)1 TextPaint (android.text.TextPaint)1