Permalink
Browse files

Use bezel swipe gestures to move to next/prev message in MessageView

  • Loading branch information...
cketti committed May 4, 2012
1 parent 022940d commit 8fdece478242074020903b446d0ee84162f93743
Showing with 23 additions and 13 deletions.
  1. +2 −0 src/com/fsck/k9/activity/K9Activity.java
  2. +21 −13 src/com/fsck/k9/activity/MessageView.java
@@ -19,6 +19,8 @@
public class K9Activity extends Activity {
+ protected static final int BEZEL_SWIPE_THRESHOLD = 20;
+
protected GestureDetector mGestureDetector;
@Override
@@ -4,7 +4,6 @@
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
-import android.graphics.Rect;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
@@ -48,7 +47,6 @@
private View mArchive;
private View mMove;
private View mSpam;
- private View mHeader;
private Account mAccount;
private MessageReference mMessageReference;
private ArrayList<MessageReference> mMessageReferences;
@@ -83,6 +81,18 @@
*/
private Bundle mMessageListExtras;
+ /**
+ * Screen width in pixels.
+ *
+ * <p>
+ * Used to detect right-to-left bezel swipes.
+ * </p>
+ *
+ * @see #onSwipeRightToLeft(MotionEvent, MotionEvent)
+ */
+ private int mScreenWidthInPixels;
+
+
private final class StorageListenerImplementation implements StorageManager.StorageListener {
@Override
public void onUnmount(String providerId) {
@@ -295,7 +305,6 @@ public void onCreate(Bundle icicle) {
setContentView(R.layout.message_view);
mMessageView = (SingleMessageView) findViewById(R.id.message_view);
- mHeader = findViewById(R.id.header_container);
//set a callback for the attachment view. With this callback the attachmentview
//request the start of a filebrowser activity.
@@ -382,6 +391,8 @@ public void onCancel() {
mNext.requestFocus();
}
+ mScreenWidthInPixels = getResources().getDisplayMetrics().widthPixels;
+
// Enable gesture detection for MessageViews
mGestureDetector = new GestureDetector(new MyGestureDetector(false));
@@ -717,27 +728,24 @@ private void onSendAlternate() {
}
/**
- * Handle a right-to-left swipe as "move to next message."
+ * Handle a right-to-left swipe starting at the edge of the screen as "move to next message."
*/
@Override
protected void onSwipeRightToLeft(MotionEvent e1, MotionEvent e2) {
- if (isEventInsideHeader(e1))
+ if ((int) e1.getRawX() > mScreenWidthInPixels - BEZEL_SWIPE_THRESHOLD) {
onNext();
+ }
}
/**
- * Handle a left-to-right swipe as "move to previous message."
+ * Handle a left-to-right swipe starting at the edge of the screen as
+ * "move to previous message."
*/
@Override
protected void onSwipeLeftToRight(MotionEvent e1, MotionEvent e2) {
- if (isEventInsideHeader(e1))
+ if ((int) e1.getRawX() < BEZEL_SWIPE_THRESHOLD) {
onPrevious();
- }
-
- private boolean isEventInsideHeader(MotionEvent e) {
- Rect headerRect = new Rect();
- mHeader.getGlobalVisibleRect(headerRect);
- return headerRect.contains((int)e.getRawX(), (int)e.getRawY());
+ }
}
protected void onNext() {

0 comments on commit 8fdece4

Please sign in to comment.