Merge pull request #4490 from k9mail/remove_gesture_detector

Remove unused SwipeGestureDetector
This commit is contained in:
cketti 2020-01-29 14:32:33 +01:00 committed by GitHub
commit ce372384bb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 2 additions and 171 deletions

View file

@ -13,15 +13,13 @@ import androidx.appcompat.widget.Toolbar;
import android.view.MotionEvent;
import android.view.View;
import com.fsck.k9.activity.K9ActivityCommon.K9ActivityMagic;
import com.fsck.k9.activity.misc.SwipeGestureDetector.OnSwipeGestureListener;
import com.fsck.k9.ui.R;
import com.fsck.k9.ui.ThemeManager;
import com.fsck.k9.ui.permissions.PermissionRationaleDialogFragment;
import timber.log.Timber;
public abstract class K9Activity extends AppCompatActivity implements K9ActivityMagic {
public abstract class K9Activity extends AppCompatActivity {
public static final int PERMISSIONS_REQUEST_READ_CONTACTS = 1;
public static final int PERMISSIONS_REQUEST_WRITE_CONTACTS = 2;
private static final String FRAGMENT_TAG_RATIONALE = "rationale";
@ -51,11 +49,6 @@ public abstract class K9Activity extends AppCompatActivity implements K9Activity
return super.dispatchTouchEvent(event);
}
@Override
public void setupGestureDetector(OnSwipeGestureListener listener) {
base.setupGestureDetector(listener);
}
protected void setLayout(@LayoutRes int layoutResId) {
setContentView(layoutResId);
Toolbar toolbar = findViewById(R.id.toolbar);

View file

@ -6,8 +6,6 @@ import android.text.TextUtils
import android.view.GestureDetector
import android.view.MotionEvent
import com.fsck.k9.K9
import com.fsck.k9.activity.misc.SwipeGestureDetector
import com.fsck.k9.activity.misc.SwipeGestureDetector.OnSwipeGestureListener
import com.fsck.k9.ui.Theme
import com.fsck.k9.ui.ThemeManager
import java.util.Locale
@ -61,15 +59,6 @@ class K9ActivityCommon(
gestureDetector?.onTouchEvent(event)
}
/**
* Call this if you wish to use the swipe gesture detector.
*
* @param listener A listener that will be notified if a left to right or right to left swipe has been detected.
*/
fun setupGestureDetector(listener: OnSwipeGestureListener) {
gestureDetector = GestureDetector(activity, SwipeGestureDetector(activity, listener))
}
private fun setLanguage(language: String) {
val locale = if (TextUtils.isEmpty(language)) {
Resources.getSystem().configuration.locale
@ -89,16 +78,6 @@ class K9ActivityCommon(
companion object : KoinComponent {
private val themeManager: ThemeManager by inject()
}
/**
* Base activities need to implement this interface.
*
* The implementing class simply has to call through to the implementation of these methods
* in [K9ActivityCommon].
*/
interface K9ActivityMagic {
fun setupGestureDetector(listener: OnSwipeGestureListener)
}
}
enum class ThemeType {

View file

@ -24,7 +24,6 @@ import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AnimationUtils;
@ -38,7 +37,6 @@ import com.fsck.k9.K9;
import com.fsck.k9.K9.SplitViewMode;
import com.fsck.k9.Preferences;
import com.fsck.k9.activity.compose.MessageActions;
import com.fsck.k9.activity.misc.SwipeGestureDetector.OnSwipeGestureListener;
import com.fsck.k9.controller.MessageReference;
import com.fsck.k9.fragment.MessageListFragment;
import com.fsck.k9.fragment.MessageListFragment.MessageListFragmentListener;
@ -75,8 +73,7 @@ import timber.log.Timber;
* From this Activity the user can perform all standard message operations.
*/
public class MessageList extends K9Activity implements MessageListFragmentListener,
MessageViewFragmentListener, OnBackStackChangedListener, OnSwipeGestureListener,
OnSwitchCompleteListener {
MessageViewFragmentListener, OnBackStackChangedListener, OnSwitchCompleteListener {
private static final String EXTRA_SEARCH = "search_bytes";
private static final String EXTRA_NO_THREADING = "no_threading";
@ -249,9 +246,6 @@ public class MessageList extends K9Activity implements MessageListFragmentListen
initializeActionBar();
initializeDrawer(savedInstanceState);
// Enable gesture detection for MessageLists
setupGestureDetector(this);
if (!decodeExtras(getIntent())) {
return;
}
@ -1317,22 +1311,6 @@ public class MessageList extends K9Activity implements MessageListFragmentListen
configureMenu(menu);
}
@Override
public void onSwipeRightToLeft(MotionEvent e1, MotionEvent e2) {
// Disabled because it interferes with the bezel swipe for the drawer
// if (messageListFragment != null && displayMode != DisplayMode.MESSAGE_VIEW) {
// messageListFragment.onSwipeRightToLeft(e1, e2);
// }
}
@Override
public void onSwipeLeftToRight(MotionEvent e1, MotionEvent e2) {
// Disabled because it interferes with the bezel swipe for the drawer
// if (messageListFragment != null && displayMode != DisplayMode.MESSAGE_VIEW) {
// messageListFragment.onSwipeLeftToRight(e1, e2);
// }
}
private final class StorageListenerImplementation implements StorageManager.StorageListener {
@Override
public void onUnmount(String providerId) {

View file

@ -1,119 +0,0 @@
package com.fsck.k9.activity.misc;
import android.content.Context;
import android.view.MotionEvent;
import android.view.GestureDetector.OnGestureListener;
import android.view.GestureDetector.SimpleOnGestureListener;
public class SwipeGestureDetector extends SimpleOnGestureListener {
public static final int BEZEL_SWIPE_THRESHOLD = 20;
private static final float SWIPE_MAX_OFF_PATH_DIP = 250f;
private static final float SWIPE_THRESHOLD_VELOCITY_DIP = 325f;
private final OnSwipeGestureListener mListener;
private int mMinVelocity;
private int mMaxOffPath;
private MotionEvent mLastOnDownEvent = null;
public SwipeGestureDetector(Context context, OnSwipeGestureListener listener) {
super();
if (listener == null) {
throw new IllegalArgumentException("'listener' may not be null");
}
mListener = listener;
// Calculate the minimum distance required for this to count as a swipe.
// Convert the constant dips to pixels.
float gestureScale = context.getResources().getDisplayMetrics().density;
mMinVelocity = (int) (SWIPE_THRESHOLD_VELOCITY_DIP * gestureScale + 0.5f);
mMaxOffPath = (int) (SWIPE_MAX_OFF_PATH_DIP * gestureScale + 0.5f);
}
@Override
public boolean onDown(MotionEvent e) {
mLastOnDownEvent = e;
return super.onDown(e);
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
// Apparently sometimes e1 is null
// Found a workaround here: http://stackoverflow.com/questions/4151385/
if (e1 == null) {
e1 = mLastOnDownEvent;
}
// Make sure we avoid NullPointerExceptions
if (e1 == null || e2 == null) {
return false;
}
// Calculate how much was actually swiped.
final float deltaX = e2.getX() - e1.getX();
final float deltaY = e2.getY() - e1.getY();
// Calculate the minimum distance required for this to be considered a swipe.
final int minDistance = (int) Math.abs(deltaY * 4);
try {
if (Math.abs(deltaY) > mMaxOffPath || Math.abs(velocityX) < mMinVelocity) {
return false;
}
if (deltaX < (minDistance * -1)) {
mListener.onSwipeRightToLeft(e1, e2);
} else if (deltaX > minDistance) {
mListener.onSwipeLeftToRight(e1, e2);
} else {
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
}
return false;
}
/**
* A listener that will be notified when a right to left or left to right swipe has been
* detected.
*/
public interface OnSwipeGestureListener {
/**
* Called when a swipe from right to left is handled by {@link SwipeGestureDetector}.
*
* <p>See {@link OnGestureListener#onFling(MotionEvent, MotionEvent, float, float)}
* for more information on the {@link MotionEvent}s being passed.</p>
*
* @param e1
* First down motion event that started the fling.
* @param e2
* The move motion event that triggered the current onFling.
*/
void onSwipeRightToLeft(final MotionEvent e1, final MotionEvent e2);
/**
* Called when a swipe from left to right is handled by {@link SwipeGestureDetector}.
*
* <p>See {@link OnGestureListener#onFling(MotionEvent, MotionEvent, float, float)}
* for more information on the {@link MotionEvent}s being passed.</p>
*
* @param e1
* First down motion event that started the fling.
* @param e2
* The move motion event that triggered the current onFling.
*/
void onSwipeLeftToRight(final MotionEvent e1, final MotionEvent e2);
}
}