diff options
author | Alan Viverette <alanv@google.com> | 2013-09-03 23:33:02 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2013-09-03 23:33:03 +0000 |
commit | de59baab31271a186a2f32719abd19a8adbda1e3 (patch) | |
tree | d2be097f368241439e50ec30b82400f2c7c7f326 /core/java/android/widget | |
parent | e182bfd4dcf35d5009bcae72356b999b5ead0433 (diff) | |
parent | ba299063348e8396c1ce63c8fcbf9ee69c5be266 (diff) | |
download | frameworks_base-de59baab31271a186a2f32719abd19a8adbda1e3.zip frameworks_base-de59baab31271a186a2f32719abd19a8adbda1e3.tar.gz frameworks_base-de59baab31271a186a2f32719abd19a8adbda1e3.tar.bz2 |
Merge "Ensure list scrolling API is in parity with view scrolling API" into klp-dev
Diffstat (limited to 'core/java/android/widget')
-rw-r--r-- | core/java/android/widget/AbsListView.java | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/core/java/android/widget/AbsListView.java b/core/java/android/widget/AbsListView.java index be47bf0..c308024 100644 --- a/core/java/android/widget/AbsListView.java +++ b/core/java/android/widget/AbsListView.java @@ -4924,11 +4924,37 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te * Scrolls the list items within the view by a specified number of pixels. * * @param y the amount of pixels to scroll by vertically - * @return true if the list is able to scroll, or false if the list is - * already at the beginning/end and unable to scroll any more. + * @see #canScrollList(int) */ - public boolean scrollListBy(int y) { - return !trackMotionScroll(-y, -y); + public void scrollListBy(int y) { + trackMotionScroll(-y, -y); + } + + /** + * Check if the items in the list can be scrolled in a certain direction. + * + * @param direction Negative to check scrolling up, positive to check + * scrolling down. + * @return true if the list can be scrolled in the specified direction, + * false otherwise. + * @see #scrollListBy(int) + */ + public boolean canScrollList(int direction) { + final int childCount = getChildCount(); + if (childCount == 0) { + return false; + } + + final int firstPosition = mFirstPosition; + final Rect listPadding = mListPadding; + if (direction > 0) { + final int lastBottom = getChildAt(childCount - 1).getBottom(); + final int lastPosition = firstPosition + childCount; + return lastPosition < mItemCount || lastBottom > getHeight() - listPadding.bottom; + } else { + final int firstTop = getChildAt(0).getTop(); + return firstPosition > 0 || firstTop < listPadding.top; + } } /** |