From 678ba2aceee709882c812d21c8cbc6f99ba5d2d8 Mon Sep 17 00:00:00 2001 From: cketti Date: Tue, 28 Jan 2020 23:32:49 +0100 Subject: [PATCH] Remove unused SwipeGestureDetector --- .../java/com/fsck/k9/activity/K9Activity.java | 9 +- .../com/fsck/k9/activity/K9ActivityCommon.kt | 21 ---- .../com/fsck/k9/activity/MessageList.java | 24 +--- .../activity/misc/SwipeGestureDetector.java | 119 ------------------ 4 files changed, 2 insertions(+), 171 deletions(-) delete mode 100644 app/ui/src/main/java/com/fsck/k9/activity/misc/SwipeGestureDetector.java diff --git a/app/ui/src/main/java/com/fsck/k9/activity/K9Activity.java b/app/ui/src/main/java/com/fsck/k9/activity/K9Activity.java index 1d96ca125..4e83472b4 100644 --- a/app/ui/src/main/java/com/fsck/k9/activity/K9Activity.java +++ b/app/ui/src/main/java/com/fsck/k9/activity/K9Activity.java @@ -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); diff --git a/app/ui/src/main/java/com/fsck/k9/activity/K9ActivityCommon.kt b/app/ui/src/main/java/com/fsck/k9/activity/K9ActivityCommon.kt index 0b03ad540..d55d667b2 100644 --- a/app/ui/src/main/java/com/fsck/k9/activity/K9ActivityCommon.kt +++ b/app/ui/src/main/java/com/fsck/k9/activity/K9ActivityCommon.kt @@ -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 { diff --git a/app/ui/src/main/java/com/fsck/k9/activity/MessageList.java b/app/ui/src/main/java/com/fsck/k9/activity/MessageList.java index bc18cc9a3..b90e47463 100644 --- a/app/ui/src/main/java/com/fsck/k9/activity/MessageList.java +++ b/app/ui/src/main/java/com/fsck/k9/activity/MessageList.java @@ -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) { diff --git a/app/ui/src/main/java/com/fsck/k9/activity/misc/SwipeGestureDetector.java b/app/ui/src/main/java/com/fsck/k9/activity/misc/SwipeGestureDetector.java deleted file mode 100644 index eac49b907..000000000 --- a/app/ui/src/main/java/com/fsck/k9/activity/misc/SwipeGestureDetector.java +++ /dev/null @@ -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}. - * - *

See {@link OnGestureListener#onFling(MotionEvent, MotionEvent, float, float)} - * for more information on the {@link MotionEvent}s being passed.

- * - * @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}. - * - *

See {@link OnGestureListener#onFling(MotionEvent, MotionEvent, float, float)} - * for more information on the {@link MotionEvent}s being passed.

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