From 4ff00ed62c2d233a0fa13042a1a847cdaf27679d Mon Sep 17 00:00:00 2001 From: Vavassor Date: Mon, 20 Mar 2017 03:30:31 -0400 Subject: [PATCH] An upward swipe now closes the photo viewer. Closes #31 --- .../keylesspalace/tusky/ViewMediaFragment.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app/src/main/java/com/keylesspalace/tusky/ViewMediaFragment.java b/app/src/main/java/com/keylesspalace/tusky/ViewMediaFragment.java index 433bdf272..980cb5873 100644 --- a/app/src/main/java/com/keylesspalace/tusky/ViewMediaFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/ViewMediaFragment.java @@ -19,6 +19,7 @@ import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.DialogFragment; import android.view.LayoutInflater; +import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.view.WindowManager; @@ -71,6 +72,7 @@ public class ViewMediaFragment extends DialogFragment { attacher = new PhotoViewAttacher(photoView); + // Clicking outside the photo closes the viewer. attacher.setOnPhotoTapListener(new PhotoViewAttacher.OnPhotoTapListener() { @Override 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()) .load(url) .into(photoView, new Callback() {