Java Code Examples for android.widget.AbsListView#getFirstVisiblePosition()

The following examples show how to use android.widget.AbsListView#getFirstVisiblePosition() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TypewriterRefreshLayout.java    From Typewriter with MIT License 6 votes vote down vote up
/**
 * @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.
 */
public boolean canChildScrollUp() {
    if (onChildScrollUpCallback != null) {
        return onChildScrollUpCallback.canChildScrollUp(this, target);
    }
    if (android.os.Build.VERSION.SDK_INT < 14) {
        if (target instanceof AbsListView) {
            final AbsListView absListView = (AbsListView) target;
            return absListView.getChildCount() > 0
                    && (absListView.getFirstVisiblePosition() > 0 ||
                    absListView.getChildAt(0).getTop() < absListView.getPaddingTop());
        } else {
            return ViewCompat.canScrollVertically(target, -1) || target.getScrollY() > 0;
        }
    } else {
        return ViewCompat.canScrollVertically(target, -1);
    }
}
 
Example 2
Source File: SwipeRefreshLayout.java    From android-source-codes with Creative Commons Attribution 4.0 International 6 votes vote down vote up
/**
 * @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.
 */
public boolean canChildScrollUp() {
    if (mChildScrollUpCallback != null) {
        return mChildScrollUpCallback.canChildScrollUp(this, mTarget);
    }
    if (android.os.Build.VERSION.SDK_INT < 14) {
        if (mTarget instanceof AbsListView) {
            final AbsListView absListView = (AbsListView) mTarget;
            return absListView.getChildCount() > 0
                    && (absListView.getFirstVisiblePosition() > 0 || absListView.getChildAt(0)
                            .getTop() < absListView.getPaddingTop());
        } else {
            return ViewCompat.canScrollVertically(mTarget, -1) || mTarget.getScrollY() > 0;
        }
    } else {
        return ViewCompat.canScrollVertically(mTarget, -1);
    }
}
 
Example 3
Source File: MainActivity.java    From Android-ParallaxHeaderViewPager with Apache License 2.0 6 votes vote down vote up
public int getScrollY(AbsListView view) {
	View c = view.getChildAt(0);
	if (c == null) {
		return 0;
	}

	int firstVisiblePosition = view.getFirstVisiblePosition();
	int top = c.getTop();

	int headerHeight = 0;
	if (firstVisiblePosition >= 1) {
		headerHeight = mHeaderHeight;
	}

	return -top + firstVisiblePosition * c.getHeight() + headerHeight;
}
 
Example 4
Source File: CustomSwipeRefreshLayout.java    From NewFastFrame with Apache License 2.0 6 votes vote down vote up
/**
 * @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.
 */
public boolean canChildScrollUp() {
    if (mChildScrollUpCallback != null) {
        return mChildScrollUpCallback.canChildScrollUp(this, mTarget);
    }
    if (android.os.Build.VERSION.SDK_INT < 14) {
        if (mTarget instanceof AbsListView) {
            final AbsListView absListView = (AbsListView) mTarget;
            return absListView.getChildCount() > 0
                    && (absListView.getFirstVisiblePosition() > 0 || absListView.getChildAt(0)
                    .getTop() < absListView.getPaddingTop());
        } else {
            return ViewCompat.canScrollVertically(mTarget, -1) || mTarget.getScrollY() > 0;
        }
    } else {
        return ViewCompat.canScrollVertically(mTarget, -1);
    }
}
 
Example 5
Source File: WXSwipeLayout.java    From weex-uikit with MIT License 6 votes vote down vote up
/**
 * Whether child view can scroll up
 * @return
 */
public boolean canChildScrollUp() {
  if (mTargetView == null) {
    return false;
  }
  if (Build.VERSION.SDK_INT < 14) {
    if (mTargetView instanceof AbsListView) {
      final AbsListView absListView = (AbsListView) mTargetView;
      return absListView.getChildCount() > 0
             && (absListView.getFirstVisiblePosition() > 0 || absListView.getChildAt(0)
                                                                  .getTop() < absListView.getPaddingTop());
    } else {
      return ViewCompat.canScrollVertically(mTargetView, -1) || mTargetView.getScrollY() > 0;
    }
  } else {
    return ViewCompat.canScrollVertically(mTargetView, -1);
  }
}
 
Example 6
Source File: TBListView.java    From SprintNBA with Apache License 2.0 6 votes vote down vote up
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
                     int visibleItemCount, int totalItemCount) {
    mFirstVisibleItem = firstVisibleItem;
    if (view.getFirstVisiblePosition() == 1) {
        mIsTop = true;
        // 滑动到顶部
    } else if (onLoadMoreListener != null && view.getLastVisiblePosition() == view.getCount() - 1) {
        mIsBottom = true;
        onLoadMoreListener.onLoadMore();
        // 滑动到底部
    } else {
        mIsTop = false;
        mIsBottom = false;
    }
}
 
Example 7
Source File: DayPickerView.java    From MaterialDateRangePicker with Apache License 2.0 5 votes vote down vote up
/**
 * Updates the title and selected month if the view has moved to a new
 * month.
 */
@Override
public void onScroll(
        AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
    MonthView child = (MonthView) view.getChildAt(0);
    if (child == null) {
        return;
    }

    // Figure out where we are
    long currScroll = view.getFirstVisiblePosition() * child.getHeight() - child.getBottom();
    mPreviousScrollPosition = currScroll;
    mPreviousScrollState = mCurrentScrollState;
}
 
Example 8
Source File: PtrDefaultHandler.java    From CommonPullToRefresh with Apache License 2.0 5 votes vote down vote up
public static boolean canChildScrollUp(View view) {
        if (android.os.Build.VERSION.SDK_INT < 14) {
            if (view instanceof AbsListView) {
                final AbsListView absListView = (AbsListView) view;
                return absListView.getChildCount() > 0
                        && (absListView.getFirstVisiblePosition() > 0 || absListView.getChildAt(0).getTop() <
                        absListView.getPaddingTop());
            } else {
//              return view.getScrollY() > 0;
                return ViewCompat.canScrollVertically(view, -1) || view.getScrollY() > 0;
            }
        } else {
          return view.canScrollVertically(-1);
        }
    }
 
Example 9
Source File: SwipeRefresh.java    From mooc_hyman with Apache License 2.0 5 votes vote down vote up
/**
 * @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.
 */
public boolean canChildScrollUp() {
    if (android.os.Build.VERSION.SDK_INT < 14) {
        if (mTarget instanceof AbsListView) {
            final AbsListView absListView = (AbsListView) mTarget;
            return absListView.getChildCount() > 0
                    && (absListView.getFirstVisiblePosition() > 0 || absListView.getChildAt(0)
                    .getTop() < absListView.getPaddingTop());
        } else {
            return mTarget.getScrollY() > 0;
        }
    } else {
        return ViewCompat.canScrollVertically(mTarget, -1);
    }
}
 
Example 10
Source File: SwipeRefreshLayout.java    From Overchan-Android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @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.
 */
public boolean canChildScrollUp() {
    if (android.os.Build.VERSION.SDK_INT < 14) {
        if (mTarget instanceof AbsListView) {
            final AbsListView absListView = (AbsListView) mTarget;
            return absListView.getChildCount() > 0
                    && (absListView.getFirstVisiblePosition() > 0 || absListView.getChildAt(0)
                            .getTop() < absListView.getPaddingTop());
        } else {
            return mTarget.getScrollY() > 0;
        }
    } else {
        return ViewCompat.canScrollVertically(mTarget, -1);
    }
}
 
Example 11
Source File: AbsListViewDelegate.java    From AndroidPullMenu with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isReadyForPull(View view, final float x, final float y) {
    boolean ready = false;

    // First we check whether we're scrolled to the top
    AbsListView absListView = (AbsListView) view;
    if (absListView.getCount() == 0) {
        ready = true;
    } else if (absListView.getFirstVisiblePosition() == 0) {
        final View firstVisibleChild = absListView.getChildAt(0);
        ready = firstVisibleChild != null && firstVisibleChild.getTop() >= absListView.getPaddingTop();
    }

    // Then we have to check whether the fas scroller is enabled, and check we're not starting
    // the gesture from the scroller
    if (ready && absListView.isFastScrollEnabled() && isFastScrollAlwaysVisible(absListView)) {
        switch (getVerticalScrollbarPosition(absListView)) {
            case View.SCROLLBAR_POSITION_RIGHT:
                ready = x < absListView.getRight() - absListView.getVerticalScrollbarWidth();
                break;
            case View.SCROLLBAR_POSITION_LEFT:
                ready = x > absListView.getVerticalScrollbarWidth();
                break;
        }
    }

    return ready;
}
 
Example 12
Source File: EasyRefreshLayout.java    From EasyRefreshLayout with Apache License 2.0 5 votes vote down vote up
private boolean canChildScrollUp() {
    if (android.os.Build.VERSION.SDK_INT < 14) {
        if (contentView instanceof AbsListView) {
            final AbsListView absListView = (AbsListView) contentView;
            return absListView.getChildCount() > 0
                    && (absListView.getFirstVisiblePosition() > 0 || absListView.getChildAt(0)
                    .getTop() < absListView.getPaddingTop());
        } else {
            return ViewCompat.canScrollVertically(contentView, -1) || contentView.getScrollY() > 0;
        }
    } else {
        /*return true can  swipe up*/
        return ViewCompat.canScrollVertically(contentView, -1);
    }
}
 
Example 13
Source File: PullRefreshLayout.java    From MaterialQQLite with Apache License 2.0 5 votes vote down vote up
private boolean canChildScrollDown() {
    if (android.os.Build.VERSION.SDK_INT < 14) {
        if (mTarget instanceof AbsListView) {
            final AbsListView absListView = (AbsListView) mTarget;
            return absListView.getChildCount() > 0
                    && (absListView.getFirstVisiblePosition() > 0 || absListView.getChildAt(0)
                    .getTop() < absListView.getPaddingTop());
        } else {
            return mTarget.getScrollY() > 0;
        }
    } else {
        return ViewCompat.canScrollVertically(mTarget, -1);
    }
}
 
Example 14
Source File: QuickReturnUtils.java    From QuickReturn with Apache License 2.0 5 votes vote down vote up
public static int getScrollY(AbsListView lv) {
        View c = lv.getChildAt(0);
        if (c == null) {
            return 0;
        }

        int firstVisiblePosition = lv.getFirstVisiblePosition();
        int scrollY = -(c.getTop());
//        int scrollY = 0;


        sListViewItemHeights.put(lv.getFirstVisiblePosition(), c.getHeight());

//        if(scrollY>0)
//            Log.d("QuickReturnUtils", "getScrollY() : -(c.getTop()) - "+ -(c.getTop()));
//        else
//            Log.i("QuickReturnUtils", "getScrollY() : -(c.getTop()) - "+ -(c.getTop()));

        if (scrollY < 0)
            scrollY = 0;

        for (int i = 0; i < firstVisiblePosition; ++i) {
//            Log.d("QuickReturnUtils", "getScrollY() : i - "+i);

//            Log.d("QuickReturnUtils", "getScrollY() : sListViewItemHeights.get(i) - "+sListViewItemHeights.get(i));

            if (sListViewItemHeights.get(i) != null) // (this is a sanity check)
                scrollY += sListViewItemHeights.get(i); //add all heights of the views that are gone

        }

//        Log.d("QuickReturnUtils", "getScrollY() : scrollY - "+scrollY);

        return scrollY;
    }
 
Example 15
Source File: DayPickerView.java    From narrate-android with Apache License 2.0 5 votes vote down vote up
/**
 * Updates the title and selected month if the view has moved to a new
 * month.
 */
@Override
public void onScroll(
        AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
    MonthView child = (MonthView) view.getChildAt(0);
    if (child == null) {
        return;
    }

    // Figure out where we are
    long currScroll = view.getFirstVisiblePosition() * child.getHeight() - child.getBottom();
    mPreviousScrollPosition = currScroll;
    mPreviousScrollState = mCurrentScrollState;
}
 
Example 16
Source File: BGAScrollingUtil.java    From AndroidStudyDemo with GNU General Public License v2.0 5 votes vote down vote up
public static boolean isAbsListViewToTop(AbsListView absListView) {
    if (absListView != null) {
        int firstChildTop = 0;
        if (absListView.getChildCount() > 0) {
            // 如果AdapterView的子控件数量不为0,获取第一个子控件的top
            firstChildTop = absListView.getChildAt(0).getTop() - absListView.getPaddingTop();
        }
        if (absListView.getFirstVisiblePosition() == 0 && firstChildTop == 0) {
            return true;
        }
    }
    return false;
}
 
Example 17
Source File: AbsListViewDelegate.java    From Bitocle with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isReadyForPull(View view, final float x, final float y) {
    boolean ready = false;

    // First we check whether we're scrolled to the top
    AbsListView absListView = (AbsListView) view;
    if (absListView.getCount() == 0) {
        ready = true;
    } else if (absListView.getFirstVisiblePosition() == 0) {
        final View firstVisibleChild = absListView.getChildAt(0);
        ready = firstVisibleChild != null && firstVisibleChild.getTop() >= absListView.getPaddingTop();
    }

    // Then we have to check whether the fas scroller is enabled, and check we're not starting
    // the gesture from the scroller
    if (ready && absListView.isFastScrollEnabled() && isFastScrollAlwaysVisible(absListView)) {
        switch (getVerticalScrollbarPosition(absListView)) {
            case View.SCROLLBAR_POSITION_RIGHT:
                ready = x < absListView.getRight() - absListView.getVerticalScrollbarWidth();
                break;
            case View.SCROLLBAR_POSITION_LEFT:
                ready = x > absListView.getVerticalScrollbarWidth();
                break;
        }
    }

    return ready;
}
 
Example 18
Source File: PtrDefaultHandler.java    From android-Ultra-Pull-To-Refresh with MIT License 5 votes vote down vote up
public static boolean canChildScrollUp(View view) {
    if (android.os.Build.VERSION.SDK_INT < 14) {
        if (view instanceof AbsListView) {
            final AbsListView absListView = (AbsListView) view;
            return absListView.getChildCount() > 0
                    && (absListView.getFirstVisiblePosition() > 0 || absListView.getChildAt(0)
                    .getTop() < absListView.getPaddingTop());
        } else {
            return view.getScrollY() > 0;
        }
    } else {
        return view.canScrollVertically(-1);
    }
}
 
Example 19
Source File: DialogRootView.java    From AndroidMaterialDialog with Apache License 2.0 5 votes vote down vote up
/**
 * Returns, whether a specific list view is scrolled to the top, or not.
 *
 * @param listView The list view as an instance of the class {@link AbsListView}. The list view may not
 *                 be null
 * @return True, if the given list view is scrolled to the top, false otherwise
 */
private boolean isListViewScrolledToTop(@NonNull final AbsListView listView) {
    if (listView.getFirstVisiblePosition() == 0) {
        if (listView.getChildCount() == 0) {
            return true;
        } else {
            View child = listView.getChildAt(0);
            return child == null || child.getTop() == 0;
        }
    }

    return false;
}
 
Example 20
Source File: QuickReturnUtils.java    From ChipHellClient with Apache License 2.0 3 votes vote down vote up
public static int getScrollY(AbsListView lv) {
        View c = lv.getChildAt(0);
        if (c == null) {
            return 0;
        }

        int firstVisiblePosition = lv.getFirstVisiblePosition();
        int scrollY = -(c.getTop());
//        int scrollY = 0;



        sListViewItemHeights.put(lv.getFirstVisiblePosition(), c.getHeight());

//        if(scrollY>0)
//            Log.d("QuickReturnUtils", "getScrollY() : -(c.getTop()) - "+ -(c.getTop()));
//        else
//            Log.i("QuickReturnUtils", "getScrollY() : -(c.getTop()) - "+ -(c.getTop()));

        if(scrollY<0)
            scrollY = 0;

        for (int i = 0; i < firstVisiblePosition; ++i) {
//            Log.d("QuickReturnUtils", "getScrollY() : i - "+i);

//            Log.d("QuickReturnUtils", "getScrollY() : sListViewItemHeights.get(i) - "+sListViewItemHeights.get(i));

            if (sListViewItemHeights.get(i) != null) // (this is a sanity check)
                scrollY += sListViewItemHeights.get(i); //add all heights of the views that are gone

        }

//        Log.d("QuickReturnUtils", "getScrollY() : scrollY - "+scrollY);

        return scrollY;
    }