Example usage for android.widget ScrollView getHeight

List of usage examples for android.widget ScrollView getHeight

Introduction

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

Prototype

@ViewDebug.ExportedProperty(category = "layout")
public final int getHeight() 

Source Link

Document

Return the height of your view.

Usage

From source file:com.my.seams_carv.util.ScrollableViewUtil.java

/**
 * Return true if the given scrollable view is over scrolling in terms of
 * the given y momentum.//w w w  .j a  v a2  s.c  o  m
 * <br/>
 * Usually it is called in the {@code dispatchTouchEvent}, {@code onTouchEvent},
 * or the {@code onInterceptTouchEvent}.
 *
 * @param view the scrollable view.
 * @param dy The y momentum.
 * @return true if the view is over scrolling in the vertical direction.
 */
public static boolean ifOverScrollingVertically(View view, float dy) {
    if (view == null || dy == 0)
        return false;

    // TODO: Test it.
    if (view instanceof ScrollView) {
        final ScrollView scrollView = (ScrollView) view;
        final View child = scrollView.getChildAt(0);
        if (scrollView.getHeight() >= child.getHeight())
            return true;

        if (dy > 0) {
            // Slide the thumb down to scroll up the list.
            return scrollView.getScrollY() == 0;
        } else {
            // Slide the thumb up to scroll down the list.
            MarginLayoutParams params = (MarginLayoutParams) child.getLayoutParams();

            return child.getHeight() - scrollView.getScrollY() == scrollView.getHeight()
                    - (params.topMargin + params.bottomMargin);
        }
        //        } else if (view instanceof WebView) {
        //            WebView webView = (WebView) view;
        //
        //            // TODO: Complete it.
        //            if (dy > 0) {
        //                // Slide the thumb down to scroll up the list.
        //                return webView.computeHorizontalScrollOffset() == 0.f;
        //            } else {
        //                // Slide the thumb up to scroll down the list.
        //                return false;
        //            }
    } else if (view instanceof NestedScrollView) {
        final NestedScrollView scrollView = (NestedScrollView) view;
        final int scrollRange = scrollView.computeVerticalScrollRange()
                - scrollView.computeVerticalScrollExtent();

        if (scrollRange <= 0)
            return true;

        if (dy > 0) {
            // Slide the thumb down to scroll up the list.
            return scrollView.computeVerticalScrollOffset() == 0.f;
        } else {
            // Slide the thumb up to scroll down the list.
            return scrollView.computeVerticalScrollOffset() == scrollRange;
        }
    } else if (view instanceof ListView) {
        final ListView listView = (ListView) view;
        if (listView.getAdapter().getCount() == 0)
            return true;

        // TODO: Complete it.
        if (dy > 0) {
            // Slide the thumb down to scroll up the list.
            return listView.getScrollY() == 0;
        } else {
            // Slide the thumb up to scroll down the list.
            return false;
        }
    } else if (view instanceof RecyclerView) {
        final RecyclerView recyclerView = (RecyclerView) view;
        if (recyclerView.getAdapter().getItemCount() == 0)
            return true;

        final int scrollRange = recyclerView.computeVerticalScrollRange()
                - recyclerView.computeVerticalScrollExtent();

        if (dy > 0) {
            // Slide the thumb down to scroll up the list.
            return recyclerView.computeVerticalScrollOffset() == 0.f;
        } else {
            // Slide the thumb up to scroll down the list.
            return recyclerView.computeVerticalScrollOffset() == scrollRange;
        }
    }
    // TODO: Support more scrollable view.

    // Return true for the unsupported view because the dy is non-zero.
    return true;
}

From source file:com.miku.framelite.widget.SwipeRefreshLayout.java

/**
 * @return Whether it is possible for the child view of this layout to
 *         scroll up. Override this if the child view is a custom view.
 *///from  w  w w.j  a v  a 2  s  . c o  m
public boolean canChildScrollDown() {
    if (android.os.Build.VERSION.SDK_INT < 14) {
        if (mTarget instanceof AbsListView) {
            final AbsListView absListView = (AbsListView) mTarget;
            return absListView.getChildCount() > 0
                    && (absListView.getLastVisiblePosition() < absListView.getCount() - 1
                            || absListView.getChildAt(absListView.getChildCount() - 1)
                                    .getBottom() > absListView.getHeight() - absListView.getPaddingBottom());
        } else if (mTarget instanceof ScrollView) {
            final ScrollView scrollView = (ScrollView) mTarget;
            return scrollView.getChildAt(0).getMeasuredHeight() > scrollView.getHeight()
                    + scrollView.getScrollY();
        } else {
            throw new IllegalStateException(
                    "SwipeRefreshLayout swipe down can host child (AbsListView and scrollView)");
        }
    } else {
        return ViewCompat.canScrollVertically(mTarget, 1);
    }
}

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

private void scrollToolBarToTop() {
    ScrollView scrollView = (ScrollView) mSolo.getView(R.id.bottom_bar_landscape_scroll_view);
    int[] screenLocation = { 0, 0 };
    scrollView.getLocationOnScreen(screenLocation);
    int getAwayFromTop = 42;
    float fromY = screenLocation[1] + getAwayFromTop;
    float toY = scrollView.getHeight();
    float xPos = screenLocation[0] + (scrollView.getWidth() / 2.0f);

    mSolo.drag(xPos, xPos, fromY, toY, 1);
}

From source file:com.google.reviewit.ReviewChangesFragment.java

private void init() {
    SwipeRefreshLayout swipeRefreshLayout = (SwipeRefreshLayout) v(R.id.swipeRefreshLayout);
    swipeRefreshLayout.setColorSchemeColors(widgetUtil.color(R.color.progressBar));
    swipeRefreshLayout.setRefreshing(true);
    swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override/*w  w  w .  jav a 2s  .  co  m*/
        public void onRefresh() {
            getApp().getQueryHandler().reset();
            loadAndDisplay(true);
        }
    });

    v(R.id.reloadButton).setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            reloadQuery();
        }
    });

    final View nextPageProgress = v(R.id.nextPageProgress);
    final ScrollView scrollView = (ScrollView) v(R.id.scrollView);
    scrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
        @Override
        public void onScrollChanged() {
            if (isAdded() && getApp().getQueryHandler().hasNext()
                    && nextPageProgress.getVisibility() == View.GONE) {
                View lastChild = scrollView.getChildAt(scrollView.getChildCount() - 1);
                if ((lastChild.getBottom() - (scrollView.getHeight() + scrollView.getScrollY())) == 0) {
                    setVisible(nextPageProgress);
                    scrollView.post(new Runnable() {
                        @Override
                        public void run() {
                            scrollView.fullScroll(View.FOCUS_DOWN);
                            loadAndDisplay();
                        }
                    });
                }
            }
        }
    });
}

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;/*www  .ja  v a  2s. c o m*/

    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;
}

From source file:org.catrobat.paintroid.ui.BottomBar.java

private void startBottomBarAnimation() {
    final HorizontalScrollView horizontalScrollView = (HorizontalScrollView) mMainActivity
            .findViewById(R.id.bottom_bar_scroll_view);
    final ScrollView verticalScrollView = (ScrollView) mMainActivity
            .findViewById(R.id.bottom_bar_landscape_scroll_view);
    final int animationDuration = 1000;
    int orientation = mMainActivity.getResources().getConfiguration().orientation;
    if (orientation == Configuration.ORIENTATION_PORTRAIT) {
        horizontalScrollView.post(new Runnable() {
            public void run() {
                int scrollToX = (int) (getToolButtonByToolType(mCurrentToolType).getX()
                        - horizontalScrollView.getWidth() / 2.0f
                        + mMainActivity.getResources().getDimension(R.dimen.bottom_bar_button_width) / 2.0f);
                int scrollFromX = PaintroidApplication.isRTL ? horizontalScrollView.getChildAt(0).getLeft()
                        : horizontalScrollView.getChildAt(0).getRight();
                horizontalScrollView.setScrollX(scrollFromX);
                ObjectAnimator.ofInt(horizontalScrollView, "scrollX", scrollToX).setDuration(animationDuration)
                        .start();/*from ww w. j  a  v a 2s. c  o m*/
            }
        });
    } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
        verticalScrollView.post(new Runnable() {
            public void run() {
                int scrollToY = (int) (getToolButtonByToolType(mCurrentToolType).getY()
                        - verticalScrollView.getHeight() / 2.0f
                        + mMainActivity.getResources().getDimension(R.dimen.bottom_bar_landscape_button_height)
                                / 2.0f);
                int scrollFromY = verticalScrollView.getChildAt(0).getBottom();
                verticalScrollView.setScrollY(scrollFromY);
                ObjectAnimator.ofInt(verticalScrollView, "scrollY", scrollToY).setDuration(animationDuration)
                        .start();
            }
        });
    }

    delayedAnimateSelectedTool(animationDuration);
}