diff options
author | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2024-10-28 15:53:47 +0000 |
---|---|---|
committer | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2024-10-28 15:53:47 +0000 |
commit | ec3a0930e9919ce8ccdb382a983d8430c1533c7b (patch) | |
tree | 8f260cb32009d8d8c0d45dbeee0c9e3995e4c072 | |
parent | 065af144f24ca9721a9b270338f98b271dd2db4e (diff) | |
download | infinity-for-reddit-ec3a0930e9919ce8ccdb382a983d8430c1533c7b.tar infinity-for-reddit-ec3a0930e9919ce8ccdb382a983d8430c1533c7b.tar.gz infinity-for-reddit-ec3a0930e9919ce8ccdb382a983d8430c1533c7b.tar.bz2 infinity-for-reddit-ec3a0930e9919ce8ccdb382a983d8430c1533c7b.tar.lz infinity-for-reddit-ec3a0930e9919ce8ccdb382a983d8430c1533c7b.tar.xz infinity-for-reddit-ec3a0930e9919ce8ccdb382a983d8430c1533c7b.tar.zst infinity-for-reddit-ec3a0930e9919ce8ccdb382a983d8430c1533c7b.zip |
Improve MovableFloatingActionButton gesture.
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/customviews/MovableFloatingActionButton.java | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/MovableFloatingActionButton.java b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/MovableFloatingActionButton.java index edf28c60..c53087b0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/MovableFloatingActionButton.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/MovableFloatingActionButton.java @@ -2,16 +2,20 @@ package ml.docilealligator.infinityforreddit.customviews; import android.content.Context; import android.content.SharedPreferences; +import android.os.Handler; +import android.os.Looper; import android.util.AttributeSet; import android.view.Display; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; +import android.view.ViewParent; import androidx.annotation.Nullable; import com.google.android.material.floatingactionbutton.FloatingActionButton; +import ml.docilealligator.infinityforreddit.customviews.slidr.widget.SliderPanel; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; public class MovableFloatingActionButton extends FloatingActionButton implements View.OnTouchListener { @@ -28,6 +32,8 @@ public class MovableFloatingActionButton extends FloatingActionButton implements @Nullable private SharedPreferences postDetailsSharedPreferences; private boolean portrait; + @Nullable + private SliderPanel sliderPanel; public MovableFloatingActionButton(Context context) { super(context); @@ -46,6 +52,16 @@ public class MovableFloatingActionButton extends FloatingActionButton implements private void init() { setOnTouchListener(this); + new Handler(Looper.getMainLooper()).post(() -> { + ViewParent parent = getParent(); + while (parent != null) { + if (parent instanceof SliderPanel) { + sliderPanel = (SliderPanel) parent; + break; + } + parent = parent.getParent(); + } + }); } @Override @@ -62,6 +78,10 @@ public class MovableFloatingActionButton extends FloatingActionButton implements dX = view.getX() - downRawX; dY = view.getY() - downRawY; + if (sliderPanel != null) { + sliderPanel.lock(); + } + return true; } else if (action == MotionEvent.ACTION_MOVE) { @@ -122,13 +142,19 @@ public class MovableFloatingActionButton extends FloatingActionButton implements float upDX = upRawX - downRawX; float upDY = upRawY - downRawY; + if (sliderPanel != null) { + sliderPanel.unlock(); + } + if (Math.abs(upDX) < CLICK_DRAG_TOLERANCE && Math.abs(upDY) < CLICK_DRAG_TOLERANCE) { return System.currentTimeMillis() - downTime >= 300 ? performLongClick() : performClick(); } else { - return true; } } else { + if (sliderPanel != null) { + sliderPanel.unlock(); + } return super.onTouchEvent(motionEvent); } } |