Example usage for android.webkit WebView getScrollY

List of usage examples for android.webkit WebView getScrollY

Introduction

In this page you can find the example usage for android.webkit WebView getScrollY.

Prototype

public final int getScrollY() 

Source Link

Document

Return the scrolled top position of this view.

Usage

From source file:Main.java

public static boolean isWebViewAttach(WebView webView) {
    if (webView != null) {
        if (webView.getScrollY() > 0) {
            return false;
        }//from ww  w. j av  a2s.c  om
    }
    return true;
}

From source file:com.czy.reecycleviewheader.ScrollableHelper.java

private static boolean isWebViewTop(WebView scrollView) {
    if (scrollView != null) {
        int scrollViewY = scrollView.getScrollY();
        return scrollViewY <= 0;
    }/*from   w  w  w . j a  va  2s  . c o m*/
    return false;
}

From source file:cn.bingoogolapple.refreshlayout.util.BGARefreshScrollingUtil.java

public static boolean isWebViewToBottom(WebView webView) {
    return webView != null && webView.getContentHeight()
            * webView.getScale() == (webView.getScrollY() + webView.getMeasuredHeight());
}

From source file:com.lanma.customviewproject.utils.ScrollingUtil.java

/**
 * webView?/*  w  ww  .java  2 s .c  o  m*/
 */
public static boolean isWebViewToBottom(WebView webView) {
    return webView != null && webView.getContentHeight()
            * webView.getScale() == (webView.getScrollY() + webView.getMeasuredHeight());
}

From source file:com.ranger.xyg.library.tkrefreshlayout.utils.ScrollingUtil.java

public static boolean isWebViewToBottom(WebView webview, int mTouchSlop) {
    return webview != null && ((webview.getContentHeight() * webview.getScale()
            - (webview.getHeight() + webview.getScrollY())) <= 2 * mTouchSlop);
}

From source file:com.ylw.split.splitview.view.SplitView3.java

@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        initDragView(vTop, event);// www  . j a  va2s .  c  o  m
        initDragView(vCenter, event);
        initDragView(vBottom, event);
    }
    if (event.getHistorySize() > 0) { //Touch
        if (dragView == vTop) { //vTop
            if (event.getY() > event.getHistoricalY(0)) { //?
                if (vTop.getScrollY() == 0) {
                    return mDragger.shouldInterceptTouchEvent(event);
                } else {
                    return false;
                }
            } else if (event.getY() < event.getHistoricalY(0)) { //?
                if (vTop.getTop() > 0) {
                    return mDragger.shouldInterceptTouchEvent(event);
                } else {
                    return false;
                }
            } else if (event.getY() == event.getHistoricalY(0)) {
                Log.d(TAG, "onInterceptTouchEvent - " + "event.getY() == event.getHistoricalY(0)");
                return false;
            }
        } else if (dragView == vBottom) { //vBottom
            if (event.getY() > event.getHistoricalY(0)) { //?
                // ?webView?
                int ci = vBottom.getCurrentItem();
                WebView webView = (WebView) vBottom.findViewById(ci);
                if (webView.getScrollY() == 0) {
                    return mDragger.shouldInterceptTouchEvent(event);
                } else {
                    return false;
                }
            } else {
                return false;
            }
        } else if (dragView == vCenter) {
            return mDragger.shouldInterceptTouchEvent(event);
        }
    }
    return mDragger.shouldInterceptTouchEvent(event);
}

From source file:com.ylw.split.splitview.view.SplitView3.java

public SplitView3(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    mDragger = ViewDragHelper.create(this, 1.0f, new ViewDragHelper.Callback() {
        @Override//from w  w w  .  j av a  2 s .  co m
        public boolean tryCaptureView(View child, int pointerId) {
            dragView = child;
            if (hasChoice && child == vCenter) {
                return true;
            }
            if (hasVideo && child == vTop) {
                //                    if (vTop.getScrollY() == 0)
                if (vState == 1 || vTop.getScrollY() == 0)
                    return true;
            }
            if (hasChoice && child == vBottom) {
                //?Viewpager?WebViewWebViewidViewPagerposition
                int ci = vBottom.getCurrentItem();
                WebView webView = (WebView) vBottom.findViewById(ci);
                if (webView != null && webView.getScrollY() == 0) {
                    return true;
                }
            }
            return false;
        }

        @Override
        public int clampViewPositionHorizontal(View child, int left, int dx) {
            return 0;
        }

        @Override
        public int clampViewPositionVertical(View child, int top, int dy) {
            if (dragView == vCenter) { //?
                changeLayout();
                if (top < vHead.getBottom())
                    return vHead.getBottom();
            }

            if (dragView == vTop) { //WebView
                changeLayout_vTop();
                if (top < 0)
                    return 0;
            }
            if (dragView == vBottom) { //ViewPager
                changeLayout_vBottom();
                top = (top > getHeight()) ? getHeight() : top;
            }
            return top;
        }

        @Override
        public void onViewDragStateChanged(int state) {
            Log.d(TAG, "onViewDragStateChanged - " + state);
            if (state == ViewDragHelper.STATE_IDLE) {
                if (dragView == vCenter) {
                    changeLayout();
                    ViewGroup.LayoutParams ltp = vTop.getLayoutParams();
                    ViewGroup.LayoutParams lbp = vBottom.getLayoutParams();
                    ltp.height = vCenter.getTop() - vHead.getBottom();
                    lbp.height = getHeight() - vCenter.getBottom();

                    requestLayout();
                } else if (dragView == vTop) {
                    changeLayout_vTop();

                    ViewGroup.LayoutParams lhp = vHead.getLayoutParams();
                    ViewGroup.LayoutParams ltp = vTop.getLayoutParams();
                    ViewGroup.LayoutParams lbp = vBottom.getLayoutParams();
                    if (vState == 0) {
                        lhp.height = 0; // head
                        ltp.height = vCenter.getTop(); // top
                    } else {
                        lhp.height = vHeadHeight; // head
                        ltp.height = vCenter.getTop() - vHeadHeight; // top
                    }
                    lbp.height = getHeight() - vCenter.getBottom(); // bottom

                    requestLayout();
                } else if (dragView == vBottom) {
                    changeLayout_vBottom();
                    ViewGroup.LayoutParams ltp = vTop.getLayoutParams();
                    ViewGroup.LayoutParams lbp = vBottom.getLayoutParams();
                    ltp.height = vCenter.getTop() - vHead.getBottom();
                    lbp.height = getHeight() - vCenter.getBottom();

                    requestLayout();
                }
            }
        }

        @Override
        public void onViewReleased(View releasedChild, float xvel, float yvel) {
            if (releasedChild == vCenter) {
                float yPosition = yvel / 10 + vCenter.getTop();
                float h = getHeight();
                float vCenterHeight = vCenter.getHeight();

                if (yPosition + vCenterHeight > h) {
                    yPosition = h - vCenterHeight;
                }
                if (yPosition < vHead.getBottom()) {
                    yPosition = vHead.getBottom();
                }

                mDragger.settleCapturedViewAt(0, (int) yPosition);
                invalidate();
            } else if (releasedChild == vTop) {
                int videoHeight = vHeadHeight;
                int yPosition = 0;
                vState = 0;
                if (vTop.getTop() > videoHeight / 2) {// count dp?
                    yPosition = videoHeight;
                    vState = 1;
                }
                if (Math.abs(yvel) > 200) {
                    yPosition = yvel > 0 ? videoHeight : 0;
                    vState = yvel > 0 ? 1 : 0;
                }
                mDragger.settleCapturedViewAt(0, yPosition);
                invalidate();
            } else if (releasedChild == vBottom) {
                float yPosition = yvel / 10 + vBottom.getTop();
                float h = getHeight();
                float vCenterHeight = vCenter.getHeight();

                yPosition = (yPosition < vCenterHeight) ? vCenterHeight : yPosition;
                yPosition = (yPosition > h) ? h : yPosition;

                mDragger.settleCapturedViewAt(0, (int) yPosition);
                invalidate();
            }
        }

        @Override
        public int getViewVerticalDragRange(View child) {
            if (child == vTop) {
                return getMeasuredHeight();
            }
            if (child == vCenter) {
                return getMeasuredHeight() - child.getMeasuredHeight();
            }
            if (child == vBottom) {
                return getMeasuredHeight() - child.getMeasuredHeight();
            }
            return getMeasuredHeight() - child.getMeasuredHeight();
        }
    });
}

From source file:com.recyclerviewpulldownrefresh.view.refresh.AbPullToRefreshView.java

/**
 * ??/*  w ww  .  java2s  . c o m*/
 *
 * @return
 */
public boolean canChildScrollUp() {
    // ???
    if (!mEnablePullRefresh) {
        return false;
    }

    if (mTarget instanceof AdapterView<?>) {
        final AdapterView<?> absListView = (AdapterView<?>) mTarget;
        View child = absListView.getChildAt(0);
        if (child == null) {
            return true;
        }
        if (absListView.getFirstVisiblePosition() == 0 && child.getTop() == 0) {
            return true;
        }

        int top = child.getTop();
        int padding = absListView.getPaddingTop();
        if (absListView.getFirstVisiblePosition() == 0 && Math.abs(top - padding) <= 11) {
            return true;
        }
        return false;
    } else if (mTarget instanceof ScrollView) {
        return mScrollView.getScrollY() == 0;
    } else if (mTarget instanceof WebView) {
        WebView webView = (WebView) mTarget;
        if (webView != null) {
            return webView.getScrollY() == 0;
        }
        return false;
    } else if (mTarget instanceof RecyclerView) {
        int firstVisiblePosition = 0;

        RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
        View childView = layoutManager.getChildAt(0);
        if (null == childView) {
            return true;
        }

        if (layoutManager instanceof LinearLayoutManager) {
            firstVisiblePosition = ((LinearLayoutManager) layoutManager).findFirstVisibleItemPosition();
        } else if (layoutManager instanceof GridLayoutManager) {
            firstVisiblePosition = ((GridLayoutManager) layoutManager).findFirstVisibleItemPosition();
        } else if (layoutManager instanceof StaggeredGridLayoutManager) {
            int[] spanPosition = new int[((StaggeredGridLayoutManager) layoutManager).getSpanCount()];
            ((StaggeredGridLayoutManager) layoutManager).findFirstVisibleItemPositions(spanPosition);
            firstVisiblePosition = getFirstVisibleItemPosition(spanPosition);
        }

        if (childView.getTop() == 0 && firstVisiblePosition == 0) {
            return true;
        }
        return false;
    } else {
        return ViewCompat.canScrollVertically(mTarget, 1);
    }
}

From source file:com.recyclerviewpulldownrefresh.view.refresh.AbPullToRefreshView.java

/**
 * ??//from w  ww  .  j av a  2s.  c o  m
 *
 * @return
 */
public boolean canChildScrollDown() {
    if (!mEnableLoadMore) {
        return false;
    }
    if (mTarget instanceof AdapterView<?>) {
        AdapterView<?> absListView = (AdapterView<?>) mTarget;
        View lastChild = absListView.getChildAt(absListView.getChildCount() - 1);
        if (lastChild == null) {
            return true;
        }
        // ??viewBottom?ViewmAdapterView?view,
        // ViewmAdapterView??
        if (lastChild.getBottom() <= getHeight()
                && absListView.getLastVisiblePosition() == absListView.getCount() - 1) {
            return true;
        }
    } else if (mTarget instanceof WebView) {
        WebView webview = (WebView) mTarget;
        return webview.getContentHeight() * webview.getScale() <= webview.getHeight() + webview.getScrollY();
    } else if (mTarget instanceof ScrollView) {
        ScrollView scrollView = (ScrollView) mTarget;
        View childView = scrollView.getChildAt(0);
        if (childView != null) {
            return childView.getMeasuredHeight() <= getHeight() + mScrollView.getScrollY();
        }
    } else if (mTarget instanceof RecyclerView) {
        int lastVisiblePosition = 0;
        View childView = null;

        RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();

        if (layoutManager instanceof LinearLayoutManager) {
            lastVisiblePosition = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();
            childView = layoutManager.findViewByPosition(lastVisiblePosition);
        } else if (layoutManager instanceof GridLayoutManager) {
            lastVisiblePosition = ((GridLayoutManager) layoutManager).findLastVisibleItemPosition();
            childView = layoutManager.findViewByPosition(lastVisiblePosition);
        } else if (layoutManager instanceof StaggeredGridLayoutManager) {
            int[] spanPosition = new int[((StaggeredGridLayoutManager) layoutManager).getSpanCount()];
            ((StaggeredGridLayoutManager) layoutManager).findLastVisibleItemPositions(spanPosition);
            lastVisiblePosition = getLastVisibleItemPosition(spanPosition);
            childView = getLastVisibleItemBottomView(layoutManager, spanPosition, lastVisiblePosition);
        }
        if (null == childView) {
            return false;
        }

        if (lastVisiblePosition == layoutManager.getItemCount() - 1 && childView.getBottom()
                + layoutManager.getBottomDecorationHeight(childView) <= mTarget.getBottom()) {
            return true;
        }
    } else {
        return ViewCompat.canScrollVertically(mTarget, 1);
    }
    return false;
}