Example usage for android.widget TextView getCompoundPaddingTop

List of usage examples for android.widget TextView getCompoundPaddingTop

Introduction

In this page you can find the example usage for android.widget TextView getCompoundPaddingTop.

Prototype

public int getCompoundPaddingTop() 

Source Link

Document

Returns the top padding of the view, plus space for the top Drawable if any.

Usage

From source file:Main.java

public static boolean drawDrawables(Canvas canvas, @Nonnull TextView textView) {
    final int compoundPaddingLeft = textView.getCompoundPaddingLeft();
    final int compoundPaddingTop = textView.getCompoundPaddingTop();
    final int compoundPaddingRight = textView.getCompoundPaddingRight();
    final int compoundPaddingBottom = textView.getCompoundPaddingBottom();

    final int scrollX = textView.getScrollX();
    final int scrollY = textView.getScrollY();

    final int right = textView.getRight();
    final int left = textView.getLeft();
    final int bottom = textView.getBottom();
    final int top = textView.getTop();

    final Drawable[] drawables = textView.getCompoundDrawables();
    if (drawables != null) {

        int vspace = bottom - top - compoundPaddingBottom - compoundPaddingTop;
        int hspace = right - left - compoundPaddingRight - compoundPaddingLeft;

        Drawable topDr = drawables[1];//w  ww  .j a  va2s .  com
        // IMPORTANT: The coordinates computed are also used in invalidateDrawable()
        // Make sure to update invalidateDrawable() when changing this code.
        if (topDr != null) {
            canvas.save();
            canvas.translate(scrollX + compoundPaddingLeft + (hspace - topDr.getBounds().width()) / 2,
                    scrollY + textView.getPaddingTop() + vspace / 2);
            topDr.draw(canvas);
            canvas.restore();
            return true;
        }
    }

    return false;
}

From source file:com.findme.views.ExpandableTextView.java

private static int getRealTextViewHeight(TextView textView) {
    int textHeight = textView.getLayout().getLineTop(textView.getLineCount());
    int padding = textView.getCompoundPaddingTop() + textView.getCompoundPaddingBottom();
    return textHeight + padding;
}

From source file:com.rashwan.reactive_popular_movies.common.utilities.ExpandableTextView.java

private static int getRealTextViewHeight(@NonNull TextView textView, int parentPadding) {
    int textHeight = textView.getLayout().getLineTop(textView.getLineCount());
    int padding = textView.getCompoundPaddingTop() + textView.getCompoundPaddingBottom();
    return textHeight + padding + parentPadding;
}

From source file:com.arksh.summer.ui.zone.widget.ExpandableTextView.java

/**
 * ?tv?padding/*from  w  ww . ja v a  2  s.  c  o  m*/
 * @param textView
 * @return
 */
private static int getRealTextViewHeight(TextView textView) {
    int textHeight = textView.getLayout().getLineTop(textView.getLineCount());
    int padding = textView.getCompoundPaddingTop() + textView.getCompoundPaddingBottom();
    return textHeight + padding;
}

From source file:com.nttec.everychan.ui.presentation.BoardFragment.java

private Point getSpanCoordinates(View widget, ClickableURLSpan span) {
    TextView parentTextView = (TextView) widget;

    Rect parentTextViewRect = new Rect();

    // Initialize values for the computing of clickedText position
    SpannableString completeText = (SpannableString) (parentTextView).getText();
    Layout textViewLayout = parentTextView.getLayout();

    int startOffsetOfClickedText = completeText.getSpanStart(span);
    int endOffsetOfClickedText = completeText.getSpanEnd(span);
    double startXCoordinatesOfClickedText = textViewLayout.getPrimaryHorizontal(startOffsetOfClickedText);
    double endXCoordinatesOfClickedText = textViewLayout.getPrimaryHorizontal(endOffsetOfClickedText);

    // Get the rectangle of the clicked text
    int currentLineStartOffset = textViewLayout.getLineForOffset(startOffsetOfClickedText);
    int currentLineEndOffset = textViewLayout.getLineForOffset(endOffsetOfClickedText);
    boolean keywordIsInMultiLine = currentLineStartOffset != currentLineEndOffset;
    textViewLayout.getLineBounds(currentLineStartOffset, parentTextViewRect);

    // Update the rectangle position to his real position on screen
    int[] parentTextViewLocation = { 0, 0 };
    parentTextView.getLocationOnScreen(parentTextViewLocation);

    double parentTextViewTopAndBottomOffset = (parentTextViewLocation[1] - parentTextView.getScrollY()
            + parentTextView.getCompoundPaddingTop());

    Rect windowRect = new Rect();
    activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(windowRect);
    parentTextViewTopAndBottomOffset -= windowRect.top;

    parentTextViewRect.top += parentTextViewTopAndBottomOffset;
    parentTextViewRect.bottom += parentTextViewTopAndBottomOffset;

    parentTextViewRect.left += (parentTextViewLocation[0] + startXCoordinatesOfClickedText
            + parentTextView.getCompoundPaddingLeft() - parentTextView.getScrollX());
    parentTextViewRect.right = (int) (parentTextViewRect.left + endXCoordinatesOfClickedText
            - startXCoordinatesOfClickedText);

    int x = (parentTextViewRect.left + parentTextViewRect.right) / 2;
    int y = (parentTextViewRect.top + parentTextViewRect.bottom) / 2;
    if (keywordIsInMultiLine) {
        x = parentTextViewRect.left;//w  w w . j  a v a 2 s .com
    }

    return new Point(x, y);
}