Skip to content

Commit

Permalink
open drawer when swiping
Browse files Browse the repository at this point in the history
  • Loading branch information
Ishan09811 authored Feb 8, 2024
1 parent c327d44 commit 81b81ec
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 81b81ec

Please sign in to comment.