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

The following examples show how to use android.widget.AdapterView#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: MDRootLayout.java    From talk-android with MIT License 6 votes vote down vote up
private static boolean canAdapterViewScroll(AdapterView lv) {
    /* Force it to layout it's children */
    if (lv.getLastVisiblePosition() == -1)
        return false;

    /* We can scroll if the first or last item is not visible */
    boolean firstItemVisible = lv.getFirstVisiblePosition() == 0;
    boolean lastItemVisible = lv.getLastVisiblePosition() == lv.getCount() - 1;

    if (firstItemVisible && lastItemVisible && lv.getChildCount() > 0) {
        /* Or the first item's top is above or own top */
        if (lv.getChildAt(0).getTop() < lv.getPaddingTop())
            return true;
        /* or the last item's bottom is beyond our own bottom */
        return lv.getChildAt(lv.getChildCount() - 1).getBottom() >
                lv.getHeight() - lv.getPaddingBottom();
    }

    return true;
}
 
Example 2
Source File: AdapterViewProtocols.java    From android-test with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isDataRenderedWithinAdapterView(
    AdapterView<? extends Adapter> adapterView, AdaptedData adaptedData) {
  checkArgument(adaptedData.opaqueToken instanceof Integer, "Not my data: %s", adaptedData);
  int dataPosition = ((Integer) adaptedData.opaqueToken).intValue();
  boolean inView = false;

  if (Range.closed(adapterView.getFirstVisiblePosition(), adapterView.getLastVisiblePosition())
      .contains(dataPosition)) {
    if (adapterView.getFirstVisiblePosition() == adapterView.getLastVisiblePosition()) {
      // thats a huge element.
      inView = true;
    } else {
      inView =
          isElementFullyRendered(
              adapterView, dataPosition - adapterView.getFirstVisiblePosition());
    }
  }
  if (inView) {
    // stops animations - locks in our x/y location.
    adapterView.setSelection(dataPosition);
  }

  return inView;
}
 
Example 3
Source File: HeaderScrollHelper.java    From RichWebList with Apache License 2.0 5 votes vote down vote up
private boolean isAdapterViewTop(AdapterView adapterView) {
    if (adapterView != null) {
        int firstVisiblePosition = adapterView.getFirstVisiblePosition();
        View childAt = adapterView.getChildAt(0);
        if (childAt == null || (firstVisiblePosition == 0 && childAt.getTop() == 0)) {
            return true;
        }
    }
    return false;
}
 
Example 4
Source File: ScrollableHelper.java    From DanDanPlayForAndroid with MIT License 5 votes vote down vote up
private static boolean isAdapterViewTop(AdapterView adapterView) {
    if (adapterView != null) {
        int firstVisiblePosition = adapterView.getFirstVisiblePosition();
        View childAt = adapterView.getChildAt(0);
        return childAt == null || (firstVisiblePosition == 0 && childAt.getTop() == 0);
    }
    return false;
}
 
Example 5
Source File: ScrollableHelper.java    From ScrollableLayout with Apache License 2.0 5 votes vote down vote up
private static boolean isAdapterViewTop(AdapterView adapterView) {
    if (adapterView != null) {
        int firstVisiblePosition = adapterView.getFirstVisiblePosition();
        View childAt = adapterView.getChildAt(0);
        if (childAt == null || (firstVisiblePosition == 0 && childAt != null && childAt.getTop() == 0)) {
            return true;
        }
    }
    return false;
}
 
Example 6
Source File: AbsRefreshLayout.java    From NestRefreshLayout with MIT License 5 votes vote down vote up
private boolean canListScroll(int direction) {
    AdapterView<?> absListView = (AdapterView<?>) mTargetView;
    final int itemCount = absListView.getCount();
    final int childCount = absListView.getChildCount();
    final int firstPosition = absListView.getFirstVisiblePosition();
    final int lastPosition = firstPosition + childCount;

    if (itemCount == 0) {
        return false;
    }
    if (direction > 0) {
        // Are we already showing the entire last item?
        if (lastPosition >= itemCount) {
            final View lastView = absListView.getChildAt(childCount - 1);
            if (lastView != null
                    && lastView.getBottom() >= mTargetView.getHeight()) {
                return false;
            }
        }
    } else if (direction < 0) {
        // Are we already showing the entire first item?
        if (firstPosition <= 0) {
            final View firstView = absListView.getChildAt(0);
            if (firstView != null && firstView.getTop() >= 0) {
                return false;
            }
        }
    }
    return true;
}
 
Example 7
Source File: ScrollableHelper.java    From ScrollableLayout with MIT License 5 votes vote down vote up
private static boolean isAdapterViewTop(AdapterView adapterView){
    if(adapterView != null){
        int firstVisiblePosition = adapterView.getFirstVisiblePosition();
        View childAt = adapterView.getChildAt(0);
        if(childAt == null || (firstVisiblePosition == 0 && childAt.getTop() == 0)){
            return true;
        }
    }
    return false;
}