|
13 | 13 | import android.support.v4.view.MotionEventCompat;
|
14 | 14 | import android.support.v4.view.ViewCompat;
|
15 | 15 | import android.util.AttributeSet;
|
| 16 | +import android.util.Log; |
16 | 17 | import android.view.Gravity;
|
17 | 18 | import android.view.MotionEvent;
|
18 | 19 | import android.view.View;
|
@@ -207,6 +208,7 @@ public enum PanelState {
|
207 | 208 | */
|
208 | 209 | private boolean mIsTouchEnabled;
|
209 | 210 |
|
| 211 | + private float mPrevMotionX; |
210 | 212 | private float mPrevMotionY;
|
211 | 213 | private float mInitialMotionX;
|
212 | 214 | private float mInitialMotionY;
|
@@ -961,15 +963,24 @@ public boolean dispatchTouchEvent(MotionEvent ev) {
|
961 | 963 | return super.dispatchTouchEvent(ev);
|
962 | 964 | }
|
963 | 965 |
|
| 966 | + final float x = ev.getX(); |
964 | 967 | final float y = ev.getY();
|
965 | 968 |
|
966 | 969 | if (action == MotionEvent.ACTION_DOWN) {
|
967 | 970 | mIsScrollableViewHandlingTouch = false;
|
| 971 | + mPrevMotionX = x; |
968 | 972 | mPrevMotionY = y;
|
969 | 973 | } else if (action == MotionEvent.ACTION_MOVE) {
|
| 974 | + float dx = x - mPrevMotionX; |
970 | 975 | float dy = y - mPrevMotionY;
|
| 976 | + mPrevMotionX = x; |
971 | 977 | mPrevMotionY = y;
|
972 | 978 |
|
| 979 | + if (Math.abs(dx) > Math.abs(dy)) { |
| 980 | + // Scrolling horizontally, so ignore |
| 981 | + return super.dispatchTouchEvent(ev); |
| 982 | + } |
| 983 | + |
973 | 984 | // If the scroll view isn't under the touch, pass the
|
974 | 985 | // event along to the dragView.
|
975 | 986 | if (!isViewUnder(mScrollableView, (int) mInitialMotionX, (int) mInitialMotionY)) {
|
@@ -1086,6 +1097,13 @@ public PanelState getPanelState() {
|
1086 | 1097 | * @param state - new panel state
|
1087 | 1098 | */
|
1088 | 1099 | public void setPanelState(PanelState state) {
|
| 1100 | + |
| 1101 | + // Abort any running animation, to allow state change |
| 1102 | + if(mDragHelper.getViewDragState() == ViewDragHelper.STATE_SETTLING){ |
| 1103 | + Log.d(TAG, "View is settling. Aborting animation."); |
| 1104 | + mDragHelper.abort(); |
| 1105 | + } |
| 1106 | + |
1089 | 1107 | if (state == null || state == PanelState.DRAGGING) {
|
1090 | 1108 | throw new IllegalArgumentException("Panel state cannot be null or DRAGGING.");
|
1091 | 1109 | }
|
@@ -1216,6 +1234,7 @@ boolean smoothSlideTo(float slideOffset, int velocity) {
|
1216 | 1234 | }
|
1217 | 1235 |
|
1218 | 1236 | int panelTop = computePanelTopPosition(slideOffset);
|
| 1237 | + |
1219 | 1238 | if (mDragHelper.smoothSlideViewTo(mSlideableView, mSlideableView.getLeft(), panelTop)) {
|
1220 | 1239 | setAllChildrenVisible();
|
1221 | 1240 | ViewCompat.postInvalidateOnAnimation(this);
|
|
0 commit comments