diff --git a/res/values/strings.xml b/res/values/strings.xml index edd4c6500..faaf1c9ff 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -676,6 +676,8 @@ Welcome to K-9 Mail setup. K-9 is an open source mail client for Android origin Animation Use gaudy visual effects + Gestures + Accept gesture control K-9 Mail remote control Allows this application to control K-9 Mail activities and settings. diff --git a/res/xml/global_preferences.xml b/res/xml/global_preferences.xml index 45723cd98..ed6a5a1a8 100644 --- a/res/xml/global_preferences.xml +++ b/res/xml/global_preferences.xml @@ -37,6 +37,11 @@ android:title="@string/animations_title" android:summary="@string/animations_summary" /> + (height - height/4)) + { + mTopView.fullScroll(mTopView.FOCUS_DOWN); + + } + } + return false; + } + + @Override + public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) + { + if (K9.gesturesEnabled()) + { + // Convert the dips to pixels + final float mGestureScale = getResources().getDisplayMetrics().density; + int min_distance = (int)(SWIPE_MIN_DISTANCE_DIP * mGestureScale + 0.5f); + int min_velocity = (int)(SWIPE_THRESHOLD_VELOCITY_DIP * mGestureScale + 0.5f); + int max_off_path = (int)(SWIPE_MAX_OFF_PATH_DIP * mGestureScale + 0.5f); + + + try + { + if (Math.abs(e1.getY() - e2.getY()) > max_off_path) + return false; + // right to left swipe + if (e1.getX() - e2.getX() > min_distance && Math.abs(velocityX) > min_velocity) + { + onNext(true); + } + else if (e2.getX() - e1.getX() > min_distance && Math.abs(velocityX) > min_velocity) + { + onPrevious(true); + } + } + catch (Exception e) + { + // nothing + } + } + return false; + } + + + } + } diff --git a/src/com/fsck/k9/activity/MessageView.java b/src/com/fsck/k9/activity/MessageView.java index 54a407f9c..05598d248 100644 --- a/src/com/fsck/k9/activity/MessageView.java +++ b/src/com/fsck/k9/activity/MessageView.java @@ -18,7 +18,6 @@ import android.provider.Contacts.Intents; import android.util.Config; import android.util.Log; import android.view.*; -import android.view.GestureDetector.SimpleOnGestureListener; import android.view.View.OnClickListener; import android.view.animation.AccelerateInterpolator; import android.view.animation.Animation; @@ -65,7 +64,6 @@ public class MessageView extends K9Activity private TextView mSubjectView; private CheckBox mFlagged; private int defaultSubjectColor; - private ScrollView mTopView; private WebView mMessageContentView; private LinearLayout mAttachments; private View mAttachmentIcon; @@ -92,11 +90,7 @@ public class MessageView extends K9Activity private String mNextMessageUid = null; private String mPreviousMessageUid = null; - private static final float SWIPE_MIN_DISTANCE_DIP = 130.0f; - private static final float SWIPE_MAX_OFF_PATH_DIP = 250f; - private static final float SWIPE_THRESHOLD_VELOCITY_DIP = 325f; - private GestureDetector gestureDetector; private Menu optionsMenu = null; @@ -576,9 +570,6 @@ public class MessageView extends K9Activity previous_scrolling = findViewById(R.id.previous_scrolling); - // Gesture detection - gestureDetector = new GestureDetector(new MyGestureDetector()); - boolean goNext = intent.getBooleanExtra(EXTRA_NEXT, false); if (goNext) { @@ -902,7 +893,8 @@ public class MessageView extends K9Activity } } - private void onNext(boolean animate) + @Override + protected void onNext(boolean animate) { if (mNextMessageUid == null) { @@ -918,7 +910,7 @@ public class MessageView extends K9Activity next.requestFocus(); } - private void onPrevious(boolean animate) + protected void onPrevious(boolean animate) { if (mPreviousMessageUid == null) { @@ -1030,13 +1022,7 @@ public class MessageView extends K9Activity mShowPicturesSection.setVisibility(View.GONE); } - @Override - public boolean dispatchTouchEvent(MotionEvent ev) - { - super.dispatchTouchEvent(ev); - return gestureDetector.onTouchEvent(ev); - } - + public void onClick(View view) { switch (view.getId()) @@ -1698,62 +1684,6 @@ public class MessageView extends K9Activity } - - class MyGestureDetector extends SimpleOnGestureListener - { - @Override - public boolean onDoubleTap(MotionEvent ev) - { - super.onDoubleTap(ev); - int height = getResources().getDisplayMetrics().heightPixels; - if (ev.getRawY() < (height/4)) - { - mTopView.fullScroll(mTopView.FOCUS_UP); - - } - else if (ev.getRawY() > (height - height/4)) - { - mTopView.fullScroll(mTopView.FOCUS_DOWN); - - } - return false; - } - - @Override - public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) - { - - // Convert the dips to pixels - final float mGestureScale = getResources().getDisplayMetrics().density; - int min_distance = (int)(SWIPE_MIN_DISTANCE_DIP * mGestureScale + 0.5f); - int min_velocity = (int)(SWIPE_THRESHOLD_VELOCITY_DIP * mGestureScale + 0.5f); - int max_off_path = (int)(SWIPE_MAX_OFF_PATH_DIP * mGestureScale + 0.5f); - - - try - { - if (Math.abs(e1.getY() - e2.getY()) > max_off_path) - return false; - // right to left swipe - if (e1.getX() - e2.getX() > min_distance && Math.abs(velocityX) > min_velocity) - { - onNext(true); - } - else if (e2.getX() - e1.getX() > min_distance && Math.abs(velocityX) > min_velocity) - { - onPrevious(true); - } - } - catch (Exception e) - { - // nothing - } - return false; - } - - - } - private Animation inFromRightAnimation() { return slideAnimation(0.0f, +1.0f); diff --git a/src/com/fsck/k9/activity/setup/Prefs.java b/src/com/fsck/k9/activity/setup/Prefs.java index b1525fa59..667522b03 100644 --- a/src/com/fsck/k9/activity/setup/Prefs.java +++ b/src/com/fsck/k9/activity/setup/Prefs.java @@ -27,6 +27,7 @@ public class Prefs extends K9PreferenceActivity private static final String PREFERENCE_SENSITIVE_LOGGING = "sensitive_logging"; private static final String PREFERENCE_ANIMATIONS = "animations"; + private static final String PREFERENCE_GESTURES = "gestures"; private static final String PREFERENCE_MESSAGELIST_STARS = "messagelist_stars"; private static final String PREFERENCE_MESSAGELIST_CHECKBOXES = "messagelist_checkboxes"; private static final String PREFERENCE_MESSAGELIST_TOUCHABLE = "messagelist_touchable"; @@ -36,6 +37,7 @@ public class Prefs extends K9PreferenceActivity private ListPreference mBackgroundOps; private CheckBoxPreference mDebugLogging; private CheckBoxPreference mSensitiveLogging; + private CheckBoxPreference mGestures; private CheckBoxPreference mAnimations; private CheckBoxPreference mStars; private CheckBoxPreference mCheckboxes; @@ -125,6 +127,8 @@ public class Prefs extends K9PreferenceActivity mAnimations = (CheckBoxPreference)findPreference(PREFERENCE_ANIMATIONS); mAnimations.setChecked(K9.isAnimations()); + mGestures = (CheckBoxPreference)findPreference(PREFERENCE_GESTURES); + mGestures.setChecked(K9.gesturesEnabled()); mStars = (CheckBoxPreference)findPreference(PREFERENCE_MESSAGELIST_STARS); mStars.setChecked(K9.messageListStars()); @@ -151,6 +155,7 @@ public class Prefs extends K9PreferenceActivity boolean needsRefresh = K9.setBackgroundOps(mBackgroundOps.getValue()); K9.setAnimations(mAnimations.isChecked()); + K9.setGesturesEnabled(mGestures.isChecked()); K9.setMessageListStars(mStars.isChecked()); K9.setMessageListCheckboxes(mCheckboxes.isChecked());