From bd180af7f0b73b0dd79a7117fb0c14370ef4d12e Mon Sep 17 00:00:00 2001 From: Yorke Lee Date: Sun, 4 May 2014 14:50:49 -0700 Subject: Use new nested scrolling APIs Bug: 14234101 Change-Id: Icb77f327e455fc9f0fb797b3f31d6f3467b2f358 --- .../android/dialer/calllog/CallLogFragment.java | 1 - .../dialer/widget/OverlappingPaneLayout.java | 39 +++++++++++++++++--- src/com/android/dialer/widget/ViewDragHelper.java | 41 ++++++++++++++++++++++ 3 files changed, 76 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/com/android/dialer/calllog/CallLogFragment.java b/src/com/android/dialer/calllog/CallLogFragment.java index 094815182..0f3e405c3 100644 --- a/src/com/android/dialer/calllog/CallLogFragment.java +++ b/src/com/android/dialer/calllog/CallLogFragment.java @@ -252,7 +252,6 @@ public class CallLogFragment extends ListFragment mStatusMessageView = view.findViewById(R.id.voicemail_status); mStatusMessageText = (TextView) view.findViewById(R.id.voicemail_status_message); mStatusMessageAction = (TextView) view.findViewById(R.id.voicemail_status_action); - return view; } diff --git a/src/com/android/dialer/widget/OverlappingPaneLayout.java b/src/com/android/dialer/widget/OverlappingPaneLayout.java index 18920df4f..e17194e21 100644 --- a/src/com/android/dialer/widget/OverlappingPaneLayout.java +++ b/src/com/android/dialer/widget/OverlappingPaneLayout.java @@ -102,6 +102,11 @@ public class OverlappingPaneLayout extends ViewGroup { */ private boolean mIsUnableToDrag; + /** + * Tracks whether or not a child view is in the process of a nested scroll. + */ + private boolean mIsInNestedScroll; + private float mInitialMotionX; private float mInitialMotionY; @@ -574,12 +579,16 @@ public class OverlappingPaneLayout extends ViewGroup { } if (!mCanSlide || (mIsUnableToDrag && action != MotionEvent.ACTION_DOWN)) { - mDragHelper.cancel(); + if (!mIsInNestedScroll) { + mDragHelper.cancel(); + } return super.onInterceptTouchEvent(ev); } if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) { - mDragHelper.cancel(); + if (!mIsInNestedScroll) { + mDragHelper.cancel(); + } return false; } @@ -601,7 +610,9 @@ public class OverlappingPaneLayout extends ViewGroup { final float ady = Math.abs(y - mInitialMotionY); final int slop = mDragHelper.getTouchSlop(); if (ady > slop && adx > ady || !isCapturableViewUnder((int) x, (int) y)) { - mDragHelper.cancel(); + if (!mIsInNestedScroll) { + mDragHelper.cancel(); + } mIsUnableToDrag = true; return false; } @@ -837,6 +848,27 @@ public class OverlappingPaneLayout extends ViewGroup { mPreservedOpenState = ss.isOpen; } + @Override + public boolean onStartNestedScroll(View child, View target, int nestedScrollAxes) { + final boolean startNestedScroll = (nestedScrollAxes & SCROLL_AXIS_VERTICAL) != 0; + if (startNestedScroll) { + mIsInNestedScroll = true; + mDragHelper.startNestedScroll(mSlideableView); + } + return startNestedScroll; + } + + @Override + public void onNestedPreScroll(View target, int dx, int dy, int[] consumed) { + mDragHelper.processNestedScroll(mSlideableView, 0, dy, consumed); + } + + @Override + public void onStopNestedScroll(View child) { + mDragHelper.stopNestedScroll(mSlideableView); + mIsInNestedScroll = false; + } + private class DragHelperCallback extends ViewDragHelper.Callback { @Override @@ -883,7 +915,6 @@ public class OverlappingPaneLayout extends ViewGroup { top += mSlideRange; } - int left; mDragHelper.settleCapturedViewAt(releasedChild.getLeft(), top); invalidate(); } diff --git a/src/com/android/dialer/widget/ViewDragHelper.java b/src/com/android/dialer/widget/ViewDragHelper.java index 748979f8c..83e870775 100644 --- a/src/com/android/dialer/widget/ViewDragHelper.java +++ b/src/com/android/dialer/widget/ViewDragHelper.java @@ -1447,4 +1447,45 @@ public class ViewDragHelper { return result; } + + /** + * Prepares the {@link ViewDragHelper} for the beginning of a nested scroll. + * + * @param target The child view that is dispatching the nested scroll. + */ + public void startNestedScroll(View target) { + setDragState(STATE_DRAGGING); + mCapturedView = target; + } + + /** + * Informs the {@link ViewDragHelper} that a nested scroll has ended. + * + * @param target The child view that is dispatching the nested scroll. + */ + public void stopNestedScroll(View target) { + dispatchViewReleased(0, 0); + } + + /** + * Update the {@link ViewDragHelper} with a new nested scrolling event. + * + * @param target The child view that is dispatching the nested scroll. + * @param dx The x distance scrolled on the child, in pixels. + * @param dy The y distance scroll on the child, in pixels. + * @param consumed An int array for the {@link ViewDragHelper} to report back the scroll + * deltas that it consumed. + */ + public void processNestedScroll(View target, int dx, int dy, int[] consumed) { + final int targetX = mCapturedView.getLeft() + dx; + final int targetY = mCapturedView.getTop() + dy; + dragTo(targetX, targetY, dx, dy); + if (consumed != null) { + final int unconsumedX = targetX - mCapturedView.getLeft(); + final int unconsumedY = targetY - mCapturedView.getTop(); + consumed[0] = dx - unconsumedX; + consumed[1] = dy - unconsumedY; + } + } + } -- cgit v1.2.3