List of usage examples for android.widget AdapterView getFirstVisiblePosition
public int getFirstVisiblePosition()
From source file:Main.java
public static View getItemViewIfVisible(AdapterView<?> holder, int itemPos) { int firstPosition = holder.getFirstVisiblePosition(); int wantedChild = itemPos - firstPosition; if (wantedChild < 0 || wantedChild >= holder.getChildCount()) return null; return holder.getChildAt(wantedChild); }
From source file:com.czy.reecycleviewheader.ScrollableHelper.java
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; }/* w ww . j a v a2s . co m*/ } return false; }
From source file:com.recyclerviewpulldownrefresh.view.refresh.AbPullToRefreshView.java
/** * ??//from ww w .j a v a2 s . co 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:org.mozilla.gecko.tests.BaseTest.java
/** * Gets the view in the tabs panel at the specified index. * * @return View at index// w w w . j a va 2 s.c om */ private View getTabViewAt(final int index) { final View[] childView = { null }; final AdapterView<ListAdapter> view = getTabsLayout(); runOnUiThreadSync(new Runnable() { @Override public void run() { view.setSelection(index); // The selection isn't updated synchronously; posting a // runnable to the view's queue guarantees we'll run after the // layout pass. view.post(new Runnable() { @Override public void run() { // getChildAt() is relative to the list of visible // views, but our index is relative to all views in the // list. Subtract the first visible list position for // the correct offset. childView[0] = view.getChildAt(index - view.getFirstVisiblePosition()); } }); } }); boolean result = waitForCondition(new Condition() { @Override public boolean isSatisfied() { return childView[0] != null; } }, MAX_WAIT_MS); mAsserter.ok(result, "list item at index " + index + " exists", null); return childView[0]; }
From source file:com.tweetlanes.android.core.view.TweetFeedFragment.java
private TwitterStatus getVisibleStatus() { TwitterStatus visibleStatus = null;/* www. jav a2 s. c o m*/ if (getStatusFeed() != null && mTweetFeedListView != null && mTweetFeedListView.getRefreshableView() != null) { AdapterView view = mTweetFeedListView.getRefreshableView(); int visiblePosition = view.getFirstVisiblePosition(); if (visiblePosition == 1 && view != null && view.getChildAt(visiblePosition - 1) != null) { int previousTop = view.getChildAt(visiblePosition - 1).getTop(); int previousBottom = view.getChildAt(visiblePosition - 1).getBottom(); if (previousBottom > 0 && previousTop >= -10) { visiblePosition--; } } if (visiblePosition < getStatusFeed().getStatusCount()) { visibleStatus = getStatusFeed().getStatus(visiblePosition); if (visibleStatus != null) { String notifcationType = null; String pref = null; if (getLaneIndex() == getApp().getCurrentAccount() .getCurrentLaneIndex(Constant.LaneType.USER_MENTIONS)) { notifcationType = SharedPreferencesConstants.NOTIFICATION_TYPE_MENTION; pref = SharedPreferencesConstants.NOTIFICATION_LAST_DISPLAYED_MENTION_ID; } else if (getLaneIndex() == getApp().getCurrentAccount() .getCurrentLaneIndex(Constant.LaneType.DIRECT_MESSAGES)) { notifcationType = SharedPreferencesConstants.NOTIFICATION_TYPE_DIRECT_MESSAGE; pref = SharedPreferencesConstants.NOTIFICATION_LAST_DISPLAYED_DIRECT_MESSAGE_ID; } if (notifcationType != null && pref != null) { Notifier.saveLastNotificationActioned(getBaseLaneActivity(), getApp().getCurrentAccountKey(), notifcationType, visibleStatus.mId); Notifier.cancel(getBaseLaneActivity(), getApp().getCurrentAccountKey(), notifcationType); } } } } return visibleStatus; }