Enable tiling to webtoon reader and add a fade in animation

This commit is contained in:
inorichi 2016-01-05 04:55:31 +01:00
parent 737d3d4282
commit 8000d67871
3 changed files with 33 additions and 9 deletions

View File

@ -4,6 +4,8 @@ import android.support.v7.widget.RecyclerView;
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.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import com.davemorrissey.labs.subscaleview.ImageSource; import com.davemorrissey.labs.subscaleview.ImageSource;
@ -21,13 +23,11 @@ public class WebtoonAdapter extends RecyclerView.Adapter<WebtoonAdapter.ImageHol
private List<Page> pages; private List<Page> pages;
private WebtoonReader fragment; private WebtoonReader fragment;
private int maxBitmapSize;
private View.OnTouchListener listener; private View.OnTouchListener listener;
public WebtoonAdapter(WebtoonReader fragment) { public WebtoonAdapter(WebtoonReader fragment) {
this.fragment = fragment; this.fragment = fragment;
pages = new ArrayList<>(); pages = new ArrayList<>();
maxBitmapSize = fragment.getReaderActivity().getMaxBitmapSize();
listener = (v, event) -> fragment.onImageTouch(event); listener = (v, event) -> fragment.onImageTouch(event);
} }
@ -39,7 +39,7 @@ public class WebtoonAdapter extends RecyclerView.Adapter<WebtoonAdapter.ImageHol
public ImageHolder onCreateViewHolder(ViewGroup parent, int viewType) { public ImageHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater inflater = fragment.getActivity().getLayoutInflater(); LayoutInflater inflater = fragment.getActivity().getLayoutInflater();
View v = inflater.inflate(R.layout.item_webtoon_reader, parent, false); View v = inflater.inflate(R.layout.item_webtoon_reader, parent, false);
return new ImageHolder(v, maxBitmapSize, listener); return new ImageHolder(v, listener);
} }
@Override @Override
@ -63,24 +63,31 @@ public class WebtoonAdapter extends RecyclerView.Adapter<WebtoonAdapter.ImageHol
@Bind(R.id.page_image_view) SubsamplingScaleImageView imageView; @Bind(R.id.page_image_view) SubsamplingScaleImageView imageView;
@Bind(R.id.progress) ProgressBar progressBar; @Bind(R.id.progress) ProgressBar progressBar;
public ImageHolder(View view, int maxBitmapSize, View.OnTouchListener listener) { private Animation fadeInAnimation;
public ImageHolder(View view, View.OnTouchListener listener) {
super(view); super(view);
ButterKnife.bind(this, view); ButterKnife.bind(this, view);
fadeInAnimation = AnimationUtils.loadAnimation(view.getContext(), R.anim.fade_in);
imageView.setParallelLoadingEnabled(true);
imageView.setDoubleTapZoomStyle(SubsamplingScaleImageView.ZOOM_FOCUS_FIXED); imageView.setDoubleTapZoomStyle(SubsamplingScaleImageView.ZOOM_FOCUS_FIXED);
imageView.setPanLimit(SubsamplingScaleImageView.PAN_LIMIT_INSIDE); imageView.setPanLimit(SubsamplingScaleImageView.PAN_LIMIT_INSIDE);
imageView.setMinimumScaleType(SubsamplingScaleImageView.SCALE_TYPE_CENTER_INSIDE); imageView.setMinimumScaleType(SubsamplingScaleImageView.SCALE_TYPE_CENTER_INSIDE);
imageView.setZoomEnabled(false);
imageView.setPanEnabled(false);
imageView.setOnTouchListener(listener); imageView.setOnTouchListener(listener);
// TODO Using tiling here is annoying. RecyclerView isn't good at all for a webtoon reader imageView.setOnImageEventListener(new SubsamplingScaleImageView.DefaultOnImageEventListener() {
// imageView.setMaxDimensions(maxBitmapSize, maxBitmapSize); @Override
public void onImageLoaded() {
imageView.startAnimation(fadeInAnimation);
}
});
} }
public void onSetValues(Page page) { public void onSetValues(Page page) {
if (page.getImagePath() != null) { if (page.getImagePath() != null) {
imageView.setVisibility(View.VISIBLE); imageView.setVisibility(View.VISIBLE);
imageView.setImage(ImageSource.uri(page.getImagePath()).tilingDisabled()); imageView.setImage(ImageSource.uri(page.getImagePath()));
progressBar.setVisibility(View.GONE); progressBar.setVisibility(View.GONE);
} else { } else {
imageView.setVisibility(View.GONE); imageView.setVisibility(View.GONE);

View File

@ -33,6 +33,7 @@ public class WebtoonReader extends BaseReader {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
adapter = new WebtoonAdapter(this); adapter = new WebtoonAdapter(this);
PreCachingLayoutManager layoutManager = new PreCachingLayoutManager(getActivity()); PreCachingLayoutManager layoutManager = new PreCachingLayoutManager(getActivity());
layoutManager.setExtraLayoutSpace(getResources().getDisplayMetrics().heightPixels);
recycler = new RecyclerView(getActivity()); recycler = new RecyclerView(getActivity());
recycler.setLayoutParams(new ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT)); recycler.setLayoutParams(new ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT));
@ -55,6 +56,14 @@ public class WebtoonReader extends BaseReader {
getReaderActivity().onCenterSingleTap(); getReaderActivity().onCenterSingleTap();
return true; return true;
} }
@Override
public boolean onDown(MotionEvent e) {
// The only way I've found to allow panning. Double tap event (zoom) is lost
// but panning should be the most used one
return true;
}
}); });
setPages(); setPages();

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:duration="300" />
</set>