diff options
author | Adam Powell <adamp@google.com> | 2014-05-01 10:23:33 -0700 |
---|---|---|
committer | Adam Powell <adamp@google.com> | 2014-05-01 12:45:52 -0700 |
commit | b36e4f944fe28ce68182f9ec91e5341866b49084 (patch) | |
tree | 86bc9f18445924099235cba6d5f25b6f62f9d755 /core/java/android/widget | |
parent | b6ea9db449cef8455c239c81f9f89190b28f0f85 (diff) | |
download | frameworks_base-b36e4f944fe28ce68182f9ec91e5341866b49084.zip frameworks_base-b36e4f944fe28ce68182f9ec91e5341866b49084.tar.gz frameworks_base-b36e4f944fe28ce68182f9ec91e5341866b49084.tar.bz2 |
Add support for hiding action bars on scroll.
Also tweak the nested scrolling API around nested flings and fix a bug
where recursive nested scrolling would stop prematurely.
Change-Id: I561226db878b2493970440a6af3e2332c56a1913
Diffstat (limited to 'core/java/android/widget')
-rw-r--r-- | core/java/android/widget/ScrollView.java | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/core/java/android/widget/ScrollView.java b/core/java/android/widget/ScrollView.java index 7e8f6b4..3e46f68 100644 --- a/core/java/android/widget/ScrollView.java +++ b/core/java/android/widget/ScrollView.java @@ -1565,10 +1565,10 @@ public class ScrollView extends FrameLayout { } private void flingWithNestedDispatch(int velocityY) { - if (mScrollY == 0 && velocityY < 0 || - mScrollY == getScrollRange() && velocityY > 0) { - dispatchNestedFling(0, velocityY); - } else { + final boolean canFling = (mScrollY > 0 || velocityY > 0) && + (mScrollY < getScrollRange() || velocityY < 0); + dispatchNestedFling(0, velocityY, canFling); + if (canFling) { fling(velocityY); } } @@ -1627,6 +1627,12 @@ public class ScrollView extends FrameLayout { return (nestedScrollAxes & SCROLL_AXIS_VERTICAL) != 0; } + @Override + public void onNestedScrollAccepted(View child, View target, int axes) { + super.onNestedScrollAccepted(child, target, axes); + startNestedScroll(SCROLL_AXIS_VERTICAL); + } + /** * @inheritDoc */ @@ -1638,16 +1644,23 @@ public class ScrollView extends FrameLayout { @Override public void onNestedScroll(View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed) { + final int oldScrollY = mScrollY; scrollBy(0, dyUnconsumed); + final int myConsumed = mScrollY - oldScrollY; + final int myUnconsumed = dyUnconsumed - myConsumed; + dispatchNestedScroll(0, myConsumed, 0, myUnconsumed, null); } /** * @inheritDoc */ @Override - public boolean onNestedFling(View target, float velocityX, float velocityY) { - flingWithNestedDispatch((int) velocityY); - return true; + public boolean onNestedFling(View target, float velocityX, float velocityY, boolean consumed) { + if (!consumed) { + flingWithNestedDispatch((int) velocityY); + return true; + } + return false; } @Override |