An upward swipe now closes the photo viewer. Closes #31

This commit is contained in:
Vavassor 2017-03-20 03:30:31 -04:00
parent 70536ed001
commit 4ff00ed62c

View file

@ -19,6 +19,7 @@ import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment; import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.WindowManager; import android.view.WindowManager;
@ -71,6 +72,7 @@ public class ViewMediaFragment extends DialogFragment {
attacher = new PhotoViewAttacher(photoView); attacher = new PhotoViewAttacher(photoView);
// Clicking outside the photo closes the viewer.
attacher.setOnPhotoTapListener(new PhotoViewAttacher.OnPhotoTapListener() { attacher.setOnPhotoTapListener(new PhotoViewAttacher.OnPhotoTapListener() {
@Override @Override
public void onPhotoTap(View view, float x, float y) { public void onPhotoTap(View view, float x, float y) {
@ -83,6 +85,20 @@ public class ViewMediaFragment extends DialogFragment {
} }
}); });
/* An upward swipe motion also closes the viewer. This is especially useful when the photo
* mostly fills the screen so clicking outside is difficult. */
attacher.setOnSingleFlingListener(new PhotoViewAttacher.OnSingleFlingListener() {
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
if (velocityY < 0.0 && Math.abs(velocityY) > Math.abs(velocityX)) {
dismiss();
return true;
}
return false;
}
});
Picasso.with(getContext()) Picasso.with(getContext())
.load(url) .load(url)
.into(photoView, new Callback() { .into(photoView, new Callback() {