Example usage for android.widget AdapterView getPaddingTop

List of usage examples for android.widget AdapterView getPaddingTop

Introduction

In this page you can find the example usage for android.widget AdapterView getPaddingTop.

Prototype

public int getPaddingTop() 

Source Link

Document

Returns the top padding of this view.

Usage

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

/**
 * ??//  w w  w.  j a v  a  2 s .c om
 *
 * @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);
    }
}