Example usage for android.text Layout getLineBottom

List of usage examples for android.text Layout getLineBottom

Introduction

In this page you can find the example usage for android.text Layout getLineBottom.

Prototype

public final int getLineBottom(int line) 

Source Link

Document

Return the vertical position of the bottom of the specified line.

Usage

From source file:de.eidottermihi.rpicheck.fragment.RunCommandDialog.java

private static void putLine(String text) {
    consoleOutput.append("\n" + text);
    consoleOutput.post(new Runnable() {

        @Override/*ww  w . j  a  v  a2s.  c  om*/
        public void run() {
            final Layout layout = consoleOutput.getLayout();
            if (layout != null) {
                int scrollDelta = layout.getLineBottom(consoleOutput.getLineCount() - 1)
                        - consoleOutput.getScrollY() - consoleOutput.getHeight();
                if (scrollDelta > 0) {
                    consoleOutput.scrollBy(0, scrollDelta);
                }
            }

        }
    });
}

From source file:com.amazon.android.ui.widget.ReadTextView.java

/**
 * Which line in the layout is the bottom visible line.
 *
 * @param layout Calculated text layout.
 * @param bounds Visible bounds in the coordinates of the TextView and layout.
 * @return The bottom visible line// w w w  . j a  v  a2 s  . c o m
 */
private int bottomVisibleLineOfText(final Layout layout, final Rect bounds) {

    final int lineCount = layout.getLineCount();
    for (int lineNum = lineCount - 1; lineNum >= 0; lineNum--) {
        final int bottom = layout.getLineBottom(lineNum);
        if (bottom >= bounds.top && bottom <= bounds.bottom) {
            return lineNum;
        }
    }
    return 0;
}

From source file:com.amazon.android.ui.widget.ReadTextView.java

/**
 * Draw a gradient on the text so that the bottom and top line have a faded effect if the user
 * can scroll in that direction./*from w ww.  jav  a2  s .  c  o m*/
 */
private void updateGradient() {

    if (mText == null || mScrollView == null) {
        return;
    }

    final Layout layout = mText.getLayout();
    assert layout != null;

    final Rect bounds = new Rect();
    getTextBounds(bounds);
    final int topLine = topVisibleLineOfText(layout, bounds);
    final int bottomLine = bottomVisibleLineOfText(layout, bounds);
    final int fullHeight = layout.getHeight();

    if (fullHeight > 0) {

        final float bottomLineHeight = layout.getLineBottom(bottomLine) - layout.getLineTop(bottomLine);
        final float topLineHeight = layout.getLineBottom(topLine) - layout.getLineTop(topLine);
        this.setFadingEdgeLength((int) Math.max(topLineHeight, bottomLineHeight));
    }
}

From source file:org.torproject.android.Orbot.java

private void appendLogTextAndScroll(String text) {
    if (mTxtOrbotLog != null && text != null && text.length() > 0) {

        if (mTxtOrbotLog.getText().length() > MAX_LOG_LENGTH)
            mTxtOrbotLog.setText("");

        mTxtOrbotLog.append(text + "\n");
        final Layout layout = mTxtOrbotLog.getLayout();
        if (layout != null) {
            int scrollDelta = layout.getLineBottom(mTxtOrbotLog.getLineCount() - 1) - mTxtOrbotLog.getScrollY()
                    - mTxtOrbotLog.getHeight();
            if (scrollDelta > 0)
                mTxtOrbotLog.scrollBy(0, scrollDelta);
        }//from   w w  w. j  a v a2s  .c o m
    }
}

From source file:com.updetector.MainActivity.java

/** Write a string to output console */
public void writeToConsole(String str) {
    consoleTextView.append(str);/*from w w  w .  j  av a  2  s  .  c o  m*/
    final Layout layout = consoleTextView.getLayout();
    if (layout != null) {
        int scrollDelta = layout.getLineBottom(consoleTextView.getLineCount() - 1)
                - consoleTextView.getScrollY() - consoleTextView.getHeight();
        if (scrollDelta > 0)
            consoleTextView.scrollBy(0, scrollDelta);
    }
}