From 45b7b88b947c3c12792be898d8e0d6af70471ecc Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Tue, 23 Sep 2014 18:48:39 +0200 Subject: [PATCH] disable pull to refresh in upper right corner While at the top of the list, the scroll bar handle is in the top right corner. Previously, dragging the handle from this position was difficult because touch events were intercepted by the pull to refresh handler. Closes #858 --- .../keychain/ui/KeyListFragment.java | 1 - .../widget/ListAwareSwipeRefreshLayout.java | 26 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java index 4891ab63a..6e9eed650 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java @@ -23,7 +23,6 @@ import android.content.Context; import android.content.Intent; import android.database.Cursor; import android.graphics.Color; -import android.graphics.PorterDuff; import android.net.Uri; import android.os.Build; import android.os.Bundle; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/ListAwareSwipeRefreshLayout.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/ListAwareSwipeRefreshLayout.java index f7d44d2cf..818d92390 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/ListAwareSwipeRefreshLayout.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/ListAwareSwipeRefreshLayout.java @@ -20,6 +20,12 @@ package org.sufficientlysecure.keychain.ui.widget; import android.content.Context; import android.support.v4.widget.NoScrollableSwipeRefreshLayout; import android.util.AttributeSet; +import android.view.InputDevice; +import android.view.InputDevice.MotionRange; +import android.view.MotionEvent; + +import org.sufficientlysecure.keychain.Constants; +import org.sufficientlysecure.keychain.util.Log; import se.emilsjolander.stickylistheaders.StickyListHeadersListView; @@ -71,4 +77,24 @@ public class ListAwareSwipeRefreshLayout extends NoScrollableSwipeRefreshLayout ) ); } + + /** Called on a touch event, this method exempts a small area in the upper right from pull to + * refresh handling. + * + * If the touch event happens somewhere in the upper right corner of the screen, we return false + * to indicate that the event was not handled. This ensures events in that area are always + * handed through to the list scrollbar handle. For all other cases, we pass the message through + * to the pull to refresh handler. + */ + @Override + public boolean onTouchEvent(MotionEvent event) { + float ratioX = event.getX() / event.getDevice().getMotionRange(MotionEvent.AXIS_X).getMax(); + float ratioY = event.getY() / event.getDevice().getMotionRange(MotionEvent.AXIS_Y).getMax(); + // if this is the upper right corner, don't handle as pull to refresh event + if (ratioX > 0.85f && ratioY < 0.15f) { + return false; + } + return super.onTouchEvent(event); + } + } \ No newline at end of file