use the subsampling-scale-image-view for zoomable photos

This commit is contained in:
tibbi 2016-07-24 22:53:32 +02:00
parent 7141563463
commit 1d2e7b310e
3 changed files with 34 additions and 30 deletions

View file

@ -33,7 +33,7 @@ dependencies {
compile 'com.android.support:design:23.4.0' compile 'com.android.support:design:23.4.0'
compile 'com.github.bumptech.glide:glide:3.7.0' compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.jakewharton:butterknife:8.0.1' compile 'com.jakewharton:butterknife:8.0.1'
compile 'com.github.chrisbanes:PhotoView:1.2.6' compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.5.0'
apt 'com.jakewharton:butterknife-compiler:8.0.1' apt 'com.jakewharton:butterknife-compiler:8.0.1'
} }

View file

@ -1,22 +1,20 @@
package com.simplemobiletools.gallery.fragments; package com.simplemobiletools.gallery.fragments;
import android.animation.ObjectAnimator;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageView;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.animation.ViewPropertyAnimation; import com.davemorrissey.labs.subscaleview.ImageSource;
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView;
import com.simplemobiletools.gallery.Constants; import com.simplemobiletools.gallery.Constants;
import com.simplemobiletools.gallery.R; import com.simplemobiletools.gallery.R;
import com.simplemobiletools.gallery.models.Medium; import com.simplemobiletools.gallery.models.Medium;
import uk.co.senab.photoview.PhotoView; public class PhotoFragment extends ViewPagerFragment implements View.OnClickListener {
import uk.co.senab.photoview.PhotoViewAttacher;
public class PhotoFragment extends ViewPagerFragment implements PhotoViewAttacher.OnPhotoTapListener {
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
@ -26,27 +24,24 @@ public class PhotoFragment extends ViewPagerFragment implements PhotoViewAttache
if (medium == null) if (medium == null)
return view; return view;
final PhotoView photoView = (PhotoView) view.findViewById(R.id.photo_view); final SubsamplingScaleImageView subsamplingView = (SubsamplingScaleImageView) view.findViewById(R.id.photo_view);
if (medium.isGif()) { if (medium.isGif()) {
Glide.with(getContext()).load(medium.getPath()).asGif().diskCacheStrategy(DiskCacheStrategy.NONE).into(photoView); subsamplingView.setVisibility(View.GONE);
final ImageView imageView = (ImageView) view.findViewById(R.id.gif_view);
imageView.setVisibility(View.VISIBLE);
Glide.with(getContext()).load(medium.getPath()).asGif().diskCacheStrategy(DiskCacheStrategy.NONE).into(imageView);
imageView.setOnClickListener(this);
} else { } else {
Glide.with(getContext()).load(medium.getPath()).asBitmap().thumbnail(0.2f).animate(fadeInAnimator).into(photoView); subsamplingView.setOrientation(SubsamplingScaleImageView.ORIENTATION_USE_EXIF);
subsamplingView.setImage(ImageSource.uri(medium.getPath()));
subsamplingView.setMaxScale(4f);
subsamplingView.setMinimumTileDpi(200);
subsamplingView.setOnClickListener(this);
} }
new PhotoViewAttacher(photoView).setOnPhotoTapListener(this);
return view; return view;
} }
ViewPropertyAnimation.Animator fadeInAnimator = new ViewPropertyAnimation.Animator() {
@Override
public void animate(View view) {
view.setAlpha(0f);
ObjectAnimator fadeAnim = ObjectAnimator.ofFloat(view, "alpha", 0f, 1f);
fadeAnim.setDuration(250);
fadeAnim.start();
}
};
@Override @Override
public void onSaveInstanceState(Bundle outState) { public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
@ -63,12 +58,7 @@ public class PhotoFragment extends ViewPagerFragment implements PhotoViewAttache
} }
@Override @Override
public void onPhotoTap(View view, float v, float v1) { public void onClick(View v) {
photoClicked();
}
@Override
public void onOutsidePhotoTap() {
photoClicked(); photoClicked();
} }

View file

@ -1,6 +1,20 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<uk.co.senab.photoview.PhotoView <RelativeLayout
android:id="@+id/photo_view" android:id="@+id/photo_holder"
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"/> android:layout_height="match_parent">
<com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
android:id="@+id/photo_view"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<ImageView
android:id="@+id/gif_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"/>
</RelativeLayout>