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

The following examples show how to use android.widget.AdapterView#getFirstVisiblePosition() . These examples are extracted from open source projects. 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 Project: talk-android   File: MDRootLayout.java    License: 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
@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 Project: RichWebList   File: HeaderScrollHelper.java    License: 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 Project: DanDanPlayForAndroid   File: ScrollableHelper.java    License: 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
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 Project: NestRefreshLayout   File: AbsRefreshLayout.java    License: 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 Project: ScrollableLayout   File: ScrollableHelper.java    License: 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;
}