Skip to content

Commit

Permalink
Merge remote branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
rabcyr committed May 5, 2012
2 parents 2632b39 + e1fa90b commit 5e3dbdc
Show file tree
Hide file tree
Showing 7 changed files with 570 additions and 101 deletions.
18 changes: 11 additions & 7 deletions src/com/fsck/k9/activity/K9Activity.java
Expand Up @@ -19,18 +19,16 @@


public class K9Activity extends Activity {
private GestureDetector gestureDetector;
protected static final int BEZEL_SWIPE_THRESHOLD = 20;

protected GestureDetector mGestureDetector;

@Override
public void onCreate(Bundle icicle) {
setLanguage(this, K9.getK9Language());
setTheme(K9.getK9ThemeResourceId());
super.onCreate(icicle);
setupFormats();

// Gesture detection
gestureDetector = new GestureDetector(new MyGestureDetector());

}

public static void setLanguage(Context context, String language) {
Expand All @@ -51,8 +49,10 @@ public static void setLanguage(Context context, String language) {

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
super.dispatchTouchEvent(ev);
return gestureDetector.onTouchEvent(ev);
if (mGestureDetector != null) {
mGestureDetector.onTouchEvent(ev);
}
return super.dispatchTouchEvent(ev);
}

@Override
Expand Down Expand Up @@ -184,6 +184,10 @@ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float ve
Log.d(K9.LOG_TAG, "New swipe algorithm: Swipe did not meet minimum distance requirements.");
return false;
}

// successful fling, cancel the 2nd event to prevent any other action from happening
// see http://code.google.com/p/android/issues/detail?id=8497
e2.setAction(MotionEvent.ACTION_CANCEL);
} catch (Exception e) {
// nothing
}
Expand Down
21 changes: 6 additions & 15 deletions src/com/fsck/k9/activity/MessageList.java
Expand Up @@ -690,6 +690,9 @@ public void onCreate(Bundle savedInstanceState) {
mPreviewLines = K9.messageListPreviewLines();

initializeMessageList(getIntent(), true);

// Enable gesture detection for MessageLists
mGestureDetector = new GestureDetector(new MyGestureDetector(true));
}

@Override
Expand Down Expand Up @@ -924,20 +927,6 @@ private void initializeLayout() {
mBatchMoveButton.setVisibility(K9.batchButtonsMove() ? View.VISIBLE : View.GONE);
mBatchFlagButton.setVisibility(K9.batchButtonsFlag() ? View.VISIBLE : View.GONE);
mBatchDoneButton.setVisibility(K9.batchButtonsUnselect() ? View.VISIBLE : View.GONE);

// Gesture detection
gestureDetector = new GestureDetector(new MyGestureDetector(true));
gestureListener = new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (gestureDetector.onTouchEvent(event)) {
return true;
}
return false;
}
};

mListView.setOnTouchListener(gestureListener);
}

/**
Expand Down Expand Up @@ -1807,7 +1796,9 @@ protected void onSwipeLeftToRight(final MotionEvent e1, final MotionEvent e2) {
* @param selected true if this was an attempt to select (i.e. left to right).
*/
private void handleSwipe(final MotionEvent downMotion, final boolean selected) {
int position = mListView.pointToPosition((int) downMotion.getX(), (int) downMotion.getY());
int[] listPosition = new int[2];
mListView.getLocationOnScreen(listPosition);
int position = mListView.pointToPosition((int) downMotion.getRawX() - listPosition[0], (int) downMotion.getRawY() - listPosition[1]);
if (position != AdapterView.INVALID_POSITION) {
MessageInfoHolder msgInfoHolder = (MessageInfoHolder) mAdapter.getItem(position);

Expand Down
30 changes: 26 additions & 4 deletions src/com/fsck/k9/activity/MessageView.java
Expand Up @@ -81,6 +81,18 @@ public class MessageView extends K9Activity implements OnClickListener {
*/
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) {
Expand Down Expand Up @@ -379,6 +391,11 @@ public void onCancel() {
mNext.requestFocus();
}

mScreenWidthInPixels = getResources().getDisplayMetrics().widthPixels;

// Enable gesture detection for MessageViews
mGestureDetector = new GestureDetector(new MyGestureDetector(false));

setupButtonViews();
displayMessage(mMessageReference);
}
Expand Down Expand Up @@ -711,19 +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) {
onNext();
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) {
onPrevious();
if ((int) e1.getRawX() < BEZEL_SWIPE_THRESHOLD) {
onPrevious();
}
}

protected void onNext() {
Expand Down

0 comments on commit 5e3dbdc

Please sign in to comment.