mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-22 12:03:09 -04:00
Merge pull request #1115 from ShridharGoel/swipe-down
Swipe down on toolbar to open tabs switcher
This commit is contained in:
commit
6aa5ac210f
@ -20,6 +20,7 @@
|
||||
package org.kiwix.kiwixmobile.main;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.appwidget.AppWidgetManager;
|
||||
import android.content.ActivityNotFoundException;
|
||||
@ -321,6 +322,7 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@ -333,6 +335,13 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
||||
setSupportActionBar(toolbar);
|
||||
actionBar = getSupportActionBar();
|
||||
|
||||
toolbar.setOnTouchListener(new OnSwipeTouchListener(this) {
|
||||
|
||||
public void onSwipeBottom() {
|
||||
showTabSwitcher();
|
||||
}
|
||||
});
|
||||
|
||||
tableDrawerRight =
|
||||
tableDrawerRightContainer.getHeaderView(0).findViewById(R.id.right_drawer_list);
|
||||
|
||||
|
@ -0,0 +1,70 @@
|
||||
package org.kiwix.kiwixmobile.main;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.GestureDetector;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
|
||||
public class OnSwipeTouchListener implements View.OnTouchListener {
|
||||
private final GestureDetector gestureDetector;
|
||||
|
||||
public OnSwipeTouchListener(Context ctx) {
|
||||
gestureDetector = new GestureDetector(ctx, new GestureListener());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
return gestureDetector.onTouchEvent(event);
|
||||
}
|
||||
|
||||
private final class GestureListener extends GestureDetector.SimpleOnGestureListener {
|
||||
private static final int SWIPE_THRESHOLD = 100;
|
||||
private static final int SWIPE_VELOCITY_THRESHOLD = 100;
|
||||
|
||||
@Override
|
||||
public boolean onDown(MotionEvent e) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
|
||||
boolean result = false;
|
||||
try {
|
||||
float diffY = e2.getY() - e1.getY();
|
||||
float diffX = e2.getX() - e1.getX();
|
||||
if (Math.abs(diffX) > Math.abs(diffY)) {
|
||||
if (Math.abs(diffX) > SWIPE_THRESHOLD && Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) {
|
||||
if (diffX > 0) {
|
||||
onSwipeRight();
|
||||
} else {
|
||||
onSwipeLeft();
|
||||
}
|
||||
result = true;
|
||||
}
|
||||
} else if (Math.abs(diffY) > SWIPE_THRESHOLD && Math.abs(velocityY) > SWIPE_VELOCITY_THRESHOLD) {
|
||||
if (diffY > 0) {
|
||||
onSwipeBottom();
|
||||
} else {
|
||||
onSwipeTop();
|
||||
}
|
||||
result = true;
|
||||
}
|
||||
} catch (Exception exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public void onSwipeRight() {
|
||||
}
|
||||
|
||||
public void onSwipeLeft() {
|
||||
}
|
||||
|
||||
public void onSwipeTop() {
|
||||
}
|
||||
|
||||
public void onSwipeBottom() {
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user