Merge pull request #1115 from ShridharGoel/swipe-down

Swipe down on toolbar to open tabs switcher
This commit is contained in:
Seán Mac Gillicuddy 2019-07-19 11:45:23 +01:00 committed by GitHub
commit 6aa5ac210f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 79 additions and 0 deletions

View File

@ -20,6 +20,7 @@
package org.kiwix.kiwixmobile.main; package org.kiwix.kiwixmobile.main;
import android.Manifest; import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import android.appwidget.AppWidgetManager; import android.appwidget.AppWidgetManager;
import android.content.ActivityNotFoundException; import android.content.ActivityNotFoundException;
@ -321,6 +322,7 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
} }
} }
@SuppressLint("ClickableViewAccessibility")
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -333,6 +335,13 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
actionBar = getSupportActionBar(); actionBar = getSupportActionBar();
toolbar.setOnTouchListener(new OnSwipeTouchListener(this) {
public void onSwipeBottom() {
showTabSwitcher();
}
});
tableDrawerRight = tableDrawerRight =
tableDrawerRightContainer.getHeaderView(0).findViewById(R.id.right_drawer_list); tableDrawerRightContainer.getHeaderView(0).findViewById(R.id.right_drawer_list);

View File

@ -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() {
}
}