From 81b81ecf0e3e6deaf7d696cb474154c6e3a62607 Mon Sep 17 00:00:00 2001 From: Ishan09811 <156402647+Ishan09811@users.noreply.github.com> Date: Thu, 8 Feb 2024 12:25:35 +0530 Subject: [PATCH] open drawer when swiping --- .../panda3ds/pandroid/app/GameActivity.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/GameActivity.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/GameActivity.java index aced6faad..a2e4ac8d5 100644 --- a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/GameActivity.java +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/GameActivity.java @@ -2,6 +2,7 @@ import android.content.Intent; import android.os.Bundle; +import android.view.GestureDetector; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.View; @@ -25,6 +26,7 @@ public class GameActivity extends BaseActivity { private final DrawerFragment drawerFragment = new DrawerFragment(); private final AlberInputListener inputListener = new AlberInputListener(this::onBackPressed); + private GestureDetector gestureDetector; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { @@ -58,6 +60,28 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { getSupportFragmentManager().beginTransaction().replace(R.id.drawer_fragment, drawerFragment).commitNow(); } + // Initialize gesture detector + @Override + public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { + float distanceX = e2.getX() - e1.getX(); + float distanceY = e2.getY() - e1.getY(); + if (Math.abs(distanceX) > Math.abs(distanceY) && distanceX > 0) { + //// Open the drawer when swiping from left to right + if (drawerFragment.isOpened()) { + } else { + drawerFragment.open(); + } + return true; + } + return false; +} + + @Override + public boolean dispatchTouchEvent(MotionEvent ev) { + gestureDetector.onTouchEvent(ev); + return super.dispatchTouchEvent(ev); + } + @Override protected void onResume() { super.onResume();