use the subsampling-scale-image-view for zoomable photos
This commit is contained in:
parent
7141563463
commit
1d2e7b310e
3 changed files with 34 additions and 30 deletions
|
@ -33,7 +33,7 @@ dependencies {
|
|||
compile 'com.android.support:design:23.4.0'
|
||||
compile 'com.github.bumptech.glide:glide:3.7.0'
|
||||
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'
|
||||
}
|
||||
|
|
|
@ -1,22 +1,20 @@
|
|||
package com.simplemobiletools.gallery.fragments;
|
||||
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
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.R;
|
||||
import com.simplemobiletools.gallery.models.Medium;
|
||||
|
||||
import uk.co.senab.photoview.PhotoView;
|
||||
import uk.co.senab.photoview.PhotoViewAttacher;
|
||||
|
||||
public class PhotoFragment extends ViewPagerFragment implements PhotoViewAttacher.OnPhotoTapListener {
|
||||
public class PhotoFragment extends ViewPagerFragment implements View.OnClickListener {
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
|
@ -26,27 +24,24 @@ public class PhotoFragment extends ViewPagerFragment implements PhotoViewAttache
|
|||
if (medium == null)
|
||||
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()) {
|
||||
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 {
|
||||
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;
|
||||
}
|
||||
|
||||
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
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
|
@ -63,12 +58,7 @@ public class PhotoFragment extends ViewPagerFragment implements PhotoViewAttache
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onPhotoTap(View view, float v, float v1) {
|
||||
photoClicked();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOutsidePhotoTap() {
|
||||
public void onClick(View v) {
|
||||
photoClicked();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,20 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<uk.co.senab.photoview.PhotoView
|
||||
<RelativeLayout
|
||||
android:id="@+id/photo_holder"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="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>
|
||||
|
|
Loading…
Reference in a new issue