Example usage for android.widget TextView getLocationInWindow

List of usage examples for android.widget TextView getLocationInWindow

Introduction

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

Prototype

public void getLocationInWindow(@Size(2) int[] outLocation) 

Source Link

Document

Computes the coordinates of this view in its window.

Usage

From source file:com.httrack.android.HTTrackActivity.java

private void setProgressLinesInternal(final String[] lines) {
    // Get line divider position of the bottom coordinate
    final View lineDivider = findViewById(R.id.buttonStop);
    if (lineDivider == null) {
        return;/*from   www .  j a  v a 2 s .c  o  m*/
    }
    final int[] textPosition = new int[2];
    final int[] linePosition = new int[2];
    lineDivider.getLocationInWindow(linePosition);
    final int lineYTopPosition = linePosition[1];

    // Explode lines
    final LinearLayout layout = LinearLayout.class.cast(findViewById(R.id.layout));

    // Remove any additional lines
    removeLinesFromLayout(layout, lines.length);

    // Add lines while we can
    final int currSize = layout.getChildCount();
    for (int i = 0; i < lines.length; i++) {
        // Fetch or create next layout line.
        final TextView text = i < currSize ? TextView.class.cast(layout.getChildAt(i))
                : addEmptyLineToLayout(layout);

        // Stop adding lines if overlapping to the end of the screen
        text.getLocationInWindow(textPosition);
        final int height = text.getHeight();
        final int textYBottomPosition = textPosition[1] + height;
        if (textYBottomPosition >= lineYTopPosition) {
            // Then cut everything remaining
            removeLinesFromLayout(layout, i);

            // Stop here
            break;
        }

        // Set text (html-formatted) for this line
        final String line = lines[i].trim();
        if (line.length() != 0) {
            text.setText(Html.fromHtml(line));
        } else {
            // Otherwise Android 3.0 does not insert any blank line
            text.setText(Html.fromHtml("&nbsp;"));
        }
    }
}