diff options
author | Adam Powell <adamp@google.com> | 2011-06-13 18:45:40 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-06-13 18:45:40 -0700 |
commit | 2714abff5cc50b1487c0979c99cc685f5ea113b1 (patch) | |
tree | 0fd013a0cb08007cb461d62479e58b1e8aac8586 | |
parent | 14f58ffceb917151c9940786320415331f340185 (diff) | |
parent | 6915944fc722fd8a7d4f26a02faaee51afdfc5c1 (diff) | |
download | frameworks_base-2714abff5cc50b1487c0979c99cc685f5ea113b1.zip frameworks_base-2714abff5cc50b1487c0979c99cc685f5ea113b1.tar.gz frameworks_base-2714abff5cc50b1487c0979c99cc685f5ea113b1.tar.bz2 |
Merge "Expose api on View to determine if the view can be scrolled."
-rw-r--r-- | api/current.txt | 2 | ||||
-rw-r--r-- | core/java/android/view/View.java | 34 |
2 files changed, 36 insertions, 0 deletions
diff --git a/api/current.txt b/api/current.txt index f641c96..acea3e7 100644 --- a/api/current.txt +++ b/api/current.txt @@ -21608,6 +21608,8 @@ package android.view { method public void buildDrawingCache(); method public void buildDrawingCache(boolean); method public void buildLayer(); + method public boolean canScrollHorizontally(int); + method public boolean canScrollVertically(int); method public void cancelLongPress(); method public boolean checkInputConnectionProxy(android.view.View); method public void clearAnimation(); diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index ee18722..071905c 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -8457,6 +8457,40 @@ public class View implements Drawable.Callback2, KeyEvent.Callback, Accessibilit } /** + * Check if this view can be scrolled horizontally in a certain direction. + * + * @param direction Negative to check scrolling left, positive to check scrolling right. + * @return true if this view can be scrolled in the specified direction, false otherwise. + */ + public boolean canScrollHorizontally(int direction) { + final int offset = computeHorizontalScrollOffset(); + final int range = computeHorizontalScrollRange() - computeHorizontalScrollExtent(); + if (range == 0) return false; + if (direction < 0) { + return offset > 0; + } else { + return offset < range - 1; + } + } + + /** + * Check if this view can be scrolled vertically in a certain direction. + * + * @param direction Negative to check scrolling up, positive to check scrolling down. + * @return true if this view can be scrolled in the specified direction, false otherwise. + */ + public boolean canScrollVertically(int direction) { + final int offset = computeVerticalScrollOffset(); + final int range = computeVerticalScrollRange() - computeVerticalScrollExtent(); + if (range == 0) return false; + if (direction < 0) { + return offset > 0; + } else { + return offset < range - 1; + } + } + + /** * <p>Request the drawing of the horizontal and the vertical scrollbar. The * scrollbars are painted only if they have been awakened first.</p> * |