1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-12-24 16:48:50 -05:00

Fixes Issue 981

Allow user to turn off gesture-based control.

Also, consolidate so that gestures could be used by other subclasses
of K9Activity.  Probably should be made usable to K9ListActivity, too,
by making MyGestureDetector its own class and make it used by
K9Activity and K9ListActivity, and have the Activities implement a
callback interface for onNext and onPrevious.
This commit is contained in:
Daniel Applebaum 2010-03-07 23:43:27 +00:00
parent f0808fb3e0
commit 9d5803b174
6 changed files with 121 additions and 74 deletions

View File

@ -676,6 +676,8 @@ Welcome to K-9 Mail setup. K-9 is an open source mail client for Android origin
<string name="animations_title">Animation</string>
<string name="animations_summary">Use gaudy visual effects</string>
<string name="gestures_title">Gestures</string>
<string name="gestures_summary">Accept gesture control</string>
<string name="remote_control_label">K-9 Mail remote control</string>
<string name="remote_control_desc">Allows this application to control K-9 Mail activities and settings.</string>

View File

@ -37,6 +37,11 @@
android:title="@string/animations_title"
android:summary="@string/animations_summary"
/>
<CheckBoxPreference
android:key="gestures"
android:title="@string/gestures_title"
android:summary="@string/gestures_summary"
/>
</PreferenceCategory>
<PreferenceCategory android:title="@string/messagelist_preferences" android:key="messagelist_preferences">
<CheckBoxPreference

View File

@ -71,6 +71,7 @@ public class K9 extends Application
private static boolean mMessageListStars = true;
private static boolean mMessageListCheckboxes = false;
private static boolean mMessageListTouchable = false;
private static boolean mGesturesEnabled = true;
/**
* We use WebSettings.getBlockNetworkLoads() to prevent the WebView that displays email
@ -317,6 +318,7 @@ public class K9 extends Application
editor.putBoolean("enableSensitiveLogging", K9.DEBUG_SENSITIVE);
editor.putString("backgroundOperations", K9.backgroundOps.toString());
editor.putBoolean("animations", mAnimations);
editor.putBoolean("gesturesEnabled", mGesturesEnabled);
editor.putBoolean("messageListStars",mMessageListStars);
editor.putBoolean("messageListCheckboxes",mMessageListCheckboxes);
editor.putBoolean("messageListTouchable",mMessageListTouchable);
@ -333,6 +335,7 @@ public class K9 extends Application
DEBUG = sprefs.getBoolean("enableDebugLogging", false);
DEBUG_SENSITIVE = sprefs.getBoolean("enableSensitiveLogging", false);
mAnimations = sprefs.getBoolean("animations", true);
mGesturesEnabled = sprefs.getBoolean("gesturesEnabled", true);
mMessageListStars = sprefs.getBoolean("messageListStars",true);
mMessageListCheckboxes = sprefs.getBoolean("messageListCheckboxes",false);
mMessageListTouchable = sprefs.getBoolean("messageListTouchable",false);
@ -448,6 +451,16 @@ public class K9 extends Application
return setBackgroundOps(BACKGROUND_OPS.valueOf(nbackgroundOps));
}
public static boolean gesturesEnabled()
{
return mGesturesEnabled;
}
public static void setGesturesEnabled(boolean gestures)
{
mGesturesEnabled = gestures;
}
public static boolean isAnimations()
{
return mAnimations;

View File

@ -3,17 +3,36 @@ package com.fsck.k9;
import android.app.Activity;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.widget.ScrollView;
import com.fsck.k9.activity.DateFormatter;
public class K9Activity extends Activity
{
private GestureDetector gestureDetector;
protected ScrollView mTopView;
@Override
public void onCreate(Bundle icicle)
{
setTheme(K9.getK9Theme());
super.onCreate(icicle);
setupFormats();
// Gesture detection
gestureDetector = new GestureDetector(new MyGestureDetector());
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev)
{
super.dispatchTouchEvent(ev);
return gestureDetector.onTouchEvent(ev);
}
@Override
@ -42,4 +61,77 @@ public class K9Activity extends Activity
{
return mDateFormat;
}
protected void onNext(boolean animate)
{
}
protected void onPrevious(boolean animate)
{
}
class MyGestureDetector extends SimpleOnGestureListener
{
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;
@Override
public boolean onDoubleTap(MotionEvent ev)
{
super.onDoubleTap(ev);
if (mTopView != null)
{
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)
{
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;
}
}
}

View File

@ -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);

View File

@ -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());