Example usage for android.widget ScrollView canScrollVertically

List of usage examples for android.widget ScrollView canScrollVertically

Introduction

In this page you can find the example usage for android.widget ScrollView canScrollVertically.

Prototype

public boolean canScrollVertically(int direction) 

Source Link

Document

Check if this view can be scrolled vertically in a certain direction.

Usage

From source file:org.catrobat.paintroid.test.integration.BaseIntegrationTestClass.java

protected View verticalScrollToToolButton(ToolType toolType) {
    ScrollView scrollView = (ScrollView) mSolo.getView(R.id.bottom_bar_landscape_scroll_view);
    int scrollBottom = 1;
    int scrollTop = -1;
    View toolButtonView = null;//  w ww .  j a  v a2  s.c om

    while (scrollView.canScrollVertically(scrollTop)) {
        scrollToolBarToTop();
    }

    float scrollPosBottom = scrollView.getY() + scrollView.getHeight();
    int[] btnLocation = { 0, 0 };
    getToolButtonView(toolType).getLocationOnScreen(btnLocation);
    float btnPos = btnLocation[1] + (getToolButtonView(toolType).getHeight() / 2.0f);

    if (btnPos < scrollPosBottom) {
        toolButtonView = getToolButtonView(toolType);
    }
    float fromX, toX, fromY, toY = 0;
    int stepCount = 20;
    int screenWidth = getActivity().getWindowManager().getDefaultDisplay().getWidth();
    int screenHeight = getActivity().getWindowManager().getDefaultDisplay().getHeight();
    while (scrollView.canScrollVertically(scrollBottom) && toolButtonView == null) {
        fromX = screenWidth - scrollView.getWidth() / 2;
        toX = fromX;
        fromY = screenHeight / 2;
        toY = screenHeight / 4 - screenHeight / 8;
        mSolo.drag(fromX, toX, fromY, toY, stepCount);
        getToolButtonView(toolType).getLocationOnScreen(btnLocation);
        btnPos = btnLocation[1] + (getToolButtonView(toolType).getHeight() / 2.0f);
        if (btnPos < scrollPosBottom) {
            toolButtonView = getToolButtonView(toolType);
            break;
        }
    }

    assertNotNull("Tool button not found", toolButtonView);
    return toolButtonView;
}