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
This commit is contained in:
Vincent Breitmoser 2014-09-23 18:48:39 +02:00
parent c5239d6e9b
commit 45b7b88b94
2 changed files with 26 additions and 1 deletions

View File

@ -23,7 +23,6 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.database.Cursor; import android.database.Cursor;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.PorterDuff;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;

View File

@ -20,6 +20,12 @@ package org.sufficientlysecure.keychain.ui.widget;
import android.content.Context; import android.content.Context;
import android.support.v4.widget.NoScrollableSwipeRefreshLayout; import android.support.v4.widget.NoScrollableSwipeRefreshLayout;
import android.util.AttributeSet; 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; 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);
}
} }