From 9aa02b8ec8a8c0a310a65c1166654d1bc7a098b3 Mon Sep 17 00:00:00 2001 From: David Miguel Lozano Date: Mon, 26 Nov 2018 16:32:24 +0100 Subject: [PATCH] Card gets stuck if you touch it while it's been closed #20 --- CHANGELOG.md | 4 ++++ lib/build.gradle | 4 ++-- .../java/com/davidmiguel/dragtoclose/DragToClose.java | 10 ++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4acaaf2..486aade 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog drag-to-close +## `0.3.1` (26/11/18) + +- Card gets stuck if you touch it while it's been closed programmatically #20 + ## `0.3.0` (26/11/18) - Migrate to AndroidX #12 (only compatible with projects that have been migrated to androidx) diff --git a/lib/build.gradle b/lib/build.gradle index 37ef68e..461d606 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -7,8 +7,8 @@ android { defaultConfig { minSdkVersion 19 targetSdkVersion 28 - versionCode 3 - versionName "0.3.0" + versionCode 31 + versionName "0.3.1" } buildTypes { release { diff --git a/lib/src/main/java/com/davidmiguel/dragtoclose/DragToClose.java b/lib/src/main/java/com/davidmiguel/dragtoclose/DragToClose.java index 81107cc..8e6cdff 100644 --- a/lib/src/main/java/com/davidmiguel/dragtoclose/DragToClose.java +++ b/lib/src/main/java/com/davidmiguel/dragtoclose/DragToClose.java @@ -61,6 +61,7 @@ public class DragToClose extends FrameLayout { private DragListener listener; private int verticalDraggableRange; + private boolean uiBlocked; public DragToClose(@NonNull Context context) { super(context); @@ -101,6 +102,9 @@ protected void onSizeChanged(int w, int h, int oldW, int oldH) { */ @Override public boolean onInterceptTouchEvent(MotionEvent event) { + if(uiBlocked) { + return true; // Don't propagate event when ui blocked + } boolean handled = false; if (isEnabled()) { handled = dragHelper.shouldInterceptTouchEvent(event) @@ -117,6 +121,9 @@ public boolean onInterceptTouchEvent(MotionEvent event) { */ @Override public boolean onTouchEvent(MotionEvent event) { + if(uiBlocked) { + return true; // Ignore event when ui blocked + } dragHelper.processTouchEvent(event); return isViewTouched(draggableView, (int) event.getX(), (int) event.getY()); } @@ -209,6 +216,7 @@ public void setDragListener(DragListener listener) { * Slides down draggable container out of the DragToClose view. */ public void closeDraggableContainer() { + uiBlocked = true; slideViewTo(draggableContainer, getPaddingLeft() + draggableContainerLeft, getDraggableRange()); } @@ -218,6 +226,7 @@ public void closeDraggableContainer() { public void openDraggableContainer() { slideViewTo(draggableContainer, getPaddingLeft() + draggableContainerLeft, getPaddingTop() + draggableContainerTop); + uiBlocked = false; } /** @@ -282,6 +291,7 @@ private void initializeAttributes(AttributeSet attrs) { if (draggableViewId == -1 || draggableContainerId == -1) { throw new IllegalArgumentException("draggableView and draggableContainer attributes are required."); } + uiBlocked = false; } finally { array.recycle(); }