Changes to viewpager readers

This commit is contained in:
inorichi 2015-12-16 13:49:36 +01:00
parent e2795f5480
commit 273527e7fb
12 changed files with 3341 additions and 336 deletions

View File

@ -57,6 +57,11 @@ public abstract class BaseReader {
} }
} }
public void onPageChanged(int position) {
currentPosition = position;
updatePageNumber();
}
public void destroy() {} public void destroy() {}
public abstract int getTotalPages(); public abstract int getTotalPages();

View File

@ -0,0 +1,6 @@
package eu.kanade.mangafeed.ui.reader.viewer.common;
public interface OnChapterBoundariesOutListener {
void onFirstPageOutEvent();
void onLastPageOutEvent();
}

View File

@ -0,0 +1,7 @@
package eu.kanade.mangafeed.ui.reader.viewer.common;
public interface OnChapterSingleTapListener {
void onCenterTap();
void onLeftSideTap();
void onRightSideTap();
}

View File

@ -0,0 +1,71 @@
package eu.kanade.mangafeed.ui.reader.viewer.common;
import android.view.GestureDetector;
import android.view.MotionEvent;
public class ViewPagerGestureListener extends GestureDetector.SimpleOnGestureListener {
private ViewPagerInterface viewPager;
private static final float LEFT_REGION = 0.33f;
private static final float RIGHT_REGION = 0.66f;
public ViewPagerGestureListener(ViewPagerInterface viewPager) {
this.viewPager = viewPager;
}
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
final int position = viewPager.getCurrentItem();
final float positionX = e.getX();
if (positionX < viewPager.getWidth() * LEFT_REGION) {
if (position != 0) {
onLeftSideTap();
} else {
onFirstPageOut();
}
} else if (positionX > viewPager.getWidth() * RIGHT_REGION) {
if (position != viewPager.getAdapter().getCount() - 1) {
onRightSideTap();
} else {
onLastPageOut();
}
} else {
onCenterTap();
}
return true;
}
private void onLeftSideTap() {
if (viewPager.getChapterSingleTapListener() != null) {
viewPager.getChapterSingleTapListener().onLeftSideTap();
}
}
private void onRightSideTap() {
if (viewPager.getChapterSingleTapListener() != null) {
viewPager.getChapterSingleTapListener().onRightSideTap();
}
}
private void onCenterTap() {
if (viewPager.getChapterSingleTapListener() != null) {
viewPager.getChapterSingleTapListener().onCenterTap();
}
}
private void onFirstPageOut() {
if (viewPager.getChapterBoundariesListener() != null) {
viewPager.getChapterBoundariesListener().onFirstPageOutEvent();
}
}
private void onLastPageOut() {
if (viewPager.getChapterBoundariesListener() != null) {
viewPager.getChapterBoundariesListener().onLastPageOutEvent();
}
}
}

View File

@ -0,0 +1,27 @@
package eu.kanade.mangafeed.ui.reader.viewer.common;
import android.support.v4.view.PagerAdapter;
import android.view.MotionEvent;
public interface ViewPagerInterface {
void setOffscreenPageLimit(int limit);
int getCurrentItem();
void setCurrentItem(int item, boolean smoothScroll);
int getWidth();
int getHeight();
PagerAdapter getAdapter();
void setAdapter(PagerAdapter adapter);
boolean onImageTouch(MotionEvent motionEvent);
void setOnChapterBoundariesOutListener(OnChapterBoundariesOutListener listener);
void setOnChapterSingleTapListener(OnChapterSingleTapListener listener);
OnChapterBoundariesOutListener getChapterBoundariesListener();
OnChapterSingleTapListener getChapterSingleTapListener();
}

View File

@ -0,0 +1,90 @@
package eu.kanade.mangafeed.ui.reader.viewer.common;
import android.support.annotation.CallSuper;
import android.view.MotionEvent;
import java.util.List;
import eu.kanade.mangafeed.data.source.model.Page;
import eu.kanade.mangafeed.ui.reader.ReaderActivity;
import eu.kanade.mangafeed.ui.reader.viewer.base.BaseReader;
import rx.Subscription;
public abstract class ViewPagerReader extends BaseReader {
protected ViewPagerReaderAdapter adapter;
protected ViewPagerInterface viewPager;
protected boolean transitions;
protected Subscription transitionsSubscription;
public ViewPagerReader(ReaderActivity activity) {
super(activity);
transitionsSubscription = activity.getPreferences().enableTransitions().asObservable()
.subscribe(value -> transitions = value);
}
protected void initializeViewPager() {
viewPager.setOffscreenPageLimit(2);
viewPager.setOnChapterBoundariesOutListener(new OnChapterBoundariesOutListener() {
@Override
public void onFirstPageOutEvent() {
onFirstPageOut();
}
@Override
public void onLastPageOutEvent() {
onLastPageOut();
}
});
viewPager.setOnChapterSingleTapListener(new OnChapterSingleTapListener() {
@Override
public void onCenterTap() {
activity.onCenterSingleTap();
}
@Override
public void onLeftSideTap() {
viewPager.setCurrentItem(viewPager.getCurrentItem() - 1, transitions);
}
@Override
public void onRightSideTap() {
viewPager.setCurrentItem(viewPager.getCurrentItem() + 1, transitions);
}
});
}
@Override
public int getTotalPages() {
return adapter.getCount();
}
@Override
public void setSelectedPage(int pageNumber) {
viewPager.setCurrentItem(getCurrentPageIndex(pageNumber), false);
}
@Override
public boolean onImageTouch(MotionEvent motionEvent) {
return viewPager.onImageTouch(motionEvent);
}
@Override
public void onPageListReady(List<Page> pages) {
currentPosition = 0;
adapter = new ViewPagerReaderAdapter(activity.getSupportFragmentManager(), pages);
viewPager.setAdapter(adapter);
}
@Override
@CallSuper
public void destroy() {
transitionsSubscription.unsubscribe();
}
public abstract void onFirstPageOut();
public abstract void onLastPageOut();
}

View File

@ -1,100 +1,26 @@
package eu.kanade.mangafeed.ui.reader.viewer.horizontal; package eu.kanade.mangafeed.ui.reader.viewer.horizontal;
import android.view.MotionEvent;
import java.util.List;
import butterknife.Bind;
import butterknife.ButterKnife;
import eu.kanade.mangafeed.R; import eu.kanade.mangafeed.R;
import eu.kanade.mangafeed.data.source.model.Page;
import eu.kanade.mangafeed.ui.reader.ReaderActivity; import eu.kanade.mangafeed.ui.reader.ReaderActivity;
import eu.kanade.mangafeed.ui.reader.viewer.base.BaseReader; import eu.kanade.mangafeed.ui.reader.viewer.common.ViewPagerInterface;
import eu.kanade.mangafeed.ui.reader.viewer.common.ViewPagerReaderAdapter; import eu.kanade.mangafeed.ui.reader.viewer.common.ViewPagerReader;
import rx.Subscription;
public abstract class HorizontalReader extends BaseReader { public abstract class HorizontalReader extends ViewPagerReader {
@Bind(R.id.view_pager) HorizontalViewPager viewPager;
protected ViewPagerReaderAdapter adapter;
private boolean transitions;
private Subscription transitionsSubscription;
public HorizontalReader(ReaderActivity activity) { public HorizontalReader(ReaderActivity activity) {
super(activity); super(activity);
activity.getLayoutInflater().inflate(R.layout.reader_horizontal, container); activity.getLayoutInflater().inflate(R.layout.reader_horizontal, container);
ButterKnife.bind(this, container);
transitionsSubscription = activity.getPreferences().enableTransitions().asObservable() viewPager = (ViewPagerInterface) container.findViewById(R.id.view_pager);
.subscribe(value -> transitions = value); initializeViewPager();
((HorizontalViewPager) viewPager).addOnPageChangeListener(new PageChangeListener());
}
viewPager.setOffscreenPageLimit(2); private class PageChangeListener extends HorizontalViewPager.SimpleOnPageChangeListener {
viewPager.addOnPageChangeListener(new HorizontalViewPager.SimpleOnPageChangeListener() {
@Override @Override
public void onPageSelected(int position) { public void onPageSelected(int position) {
currentPosition = position; onPageChanged(position);
updatePageNumber();
} }
});
viewPager.setOnChapterBoundariesOutListener(new HorizontalViewPager.OnChapterBoundariesOutListener() {
@Override
public void onFirstPageOutEvent() {
onFirstPageOut();
} }
@Override
public void onLastPageOutEvent() {
onLastPageOut();
}
});
viewPager.setOnChapterSingleTapListener(new HorizontalViewPager.OnChapterSingleTapListener() {
@Override
public void onCenterTap() {
activity.onCenterSingleTap();
}
@Override
public void onLeftSideTap() {
viewPager.setCurrentItem(viewPager.getCurrentItem() - 1, transitions);
}
@Override
public void onRightSideTap() {
viewPager.setCurrentItem(viewPager.getCurrentItem() + 1, transitions);
}
});
}
@Override
public int getTotalPages() {
return adapter.getCount();
}
@Override
public void setSelectedPage(int pageNumber) {
viewPager.setCurrentItem(getCurrentPageIndex(pageNumber), false);
}
@Override
public void onPageListReady(List<Page> pages) {
currentPosition = 0;
adapter = new ViewPagerReaderAdapter(activity.getSupportFragmentManager(), pages);
viewPager.setAdapter(adapter);
}
@Override
public boolean onImageTouch(MotionEvent motionEvent) {
return viewPager.onImageTouch(motionEvent);
}
@Override
public void destroy() {
transitionsSubscription.unsubscribe();
}
public abstract void onFirstPageOut();
public abstract void onLastPageOut();
} }

View File

@ -6,61 +6,66 @@ import android.util.AttributeSet;
import android.view.GestureDetector; import android.view.GestureDetector;
import android.view.MotionEvent; import android.view.MotionEvent;
public class HorizontalViewPager extends ViewPager { import eu.kanade.mangafeed.ui.reader.viewer.common.OnChapterBoundariesOutListener;
import eu.kanade.mangafeed.ui.reader.viewer.common.OnChapterSingleTapListener;
import eu.kanade.mangafeed.ui.reader.viewer.common.ViewPagerGestureListener;
import eu.kanade.mangafeed.ui.reader.viewer.common.ViewPagerInterface;
public class HorizontalViewPager extends ViewPager implements ViewPagerInterface {
private GestureDetector gestureDetector; private GestureDetector gestureDetector;
private OnChapterBoundariesOutListener mOnChapterBoundariesOutListener; private OnChapterBoundariesOutListener onChapterBoundariesOutListener;
private OnChapterSingleTapListener mOnChapterSingleTapListener; private OnChapterSingleTapListener onChapterSingleTapListener;
private static final float LEFT_REGION = 0.33f;
private static final float RIGHT_REGION = 0.66f;
private static final float SWIPE_TOLERANCE = 0.25f; private static final float SWIPE_TOLERANCE = 0.25f;
private float startDragX; private float startDragX;
public HorizontalViewPager(Context context) {
super(context);
init(context);
}
public HorizontalViewPager(Context context, AttributeSet attrs) { public HorizontalViewPager(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
gestureDetector = new GestureDetector(getContext(), new ReaderViewGestureListener()); init(context);
}
private void init(Context context) {
gestureDetector = new GestureDetector(context, new ViewPagerGestureListener(this));
} }
@Override @Override
public boolean onInterceptTouchEvent(MotionEvent ev) { public boolean onInterceptTouchEvent(MotionEvent ev) {
try {
if ((ev.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) { if ((ev.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
if (this.getCurrentItem() == 0 || this.getCurrentItem() == this.getAdapter().getCount() - 1) { if (getCurrentItem() == 0 || getCurrentItem() == getAdapter().getCount() - 1) {
startDragX = ev.getX(); startDragX = ev.getX();
} }
} }
return super.onInterceptTouchEvent(ev); return super.onInterceptTouchEvent(ev);
} catch (IllegalArgumentException e) {
// Do Nothing.
}
return false;
} }
@Override @Override
public boolean onTouchEvent(MotionEvent ev) { public boolean onTouchEvent(MotionEvent ev) {
try { if (onChapterBoundariesOutListener != null) {
if (mOnChapterBoundariesOutListener != null) { if (getCurrentItem() == 0) {
if (this.getCurrentItem() == 0) {
if ((ev.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) { if ((ev.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) {
float displacement = ev.getX() - startDragX; float displacement = ev.getX() - startDragX;
if (ev.getX() > startDragX && displacement > getWidth() * SWIPE_TOLERANCE) { if (ev.getX() > startDragX && displacement > getWidth() * SWIPE_TOLERANCE) {
mOnChapterBoundariesOutListener.onFirstPageOutEvent(); onChapterBoundariesOutListener.onFirstPageOutEvent();
return true; return true;
} }
startDragX = 0; startDragX = 0;
} }
} else if (this.getCurrentItem() == this.getAdapter().getCount() - 1) { } else if (getCurrentItem() == getAdapter().getCount() - 1) {
if ((ev.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) { if ((ev.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) {
float displacement = startDragX - ev.getX(); float displacement = startDragX - ev.getX();
if (ev.getX() < startDragX && displacement > getWidth() * SWIPE_TOLERANCE) { if (ev.getX() < startDragX && displacement > getWidth() * SWIPE_TOLERANCE) {
mOnChapterBoundariesOutListener.onLastPageOutEvent(); onChapterBoundariesOutListener.onLastPageOutEvent();
return true; return true;
} }
@ -70,73 +75,31 @@ public class HorizontalViewPager extends ViewPager {
} }
return super.onTouchEvent(ev); return super.onTouchEvent(ev);
} catch (IllegalArgumentException e) {
// Do Nothing.
}
return false;
} }
@Override
public boolean onImageTouch(MotionEvent event) { public boolean onImageTouch(MotionEvent event) {
return gestureDetector.onTouchEvent(event); return gestureDetector.onTouchEvent(event);
} }
public interface OnChapterBoundariesOutListener { @Override
void onFirstPageOutEvent(); public void setOnChapterBoundariesOutListener(OnChapterBoundariesOutListener listener) {
void onLastPageOutEvent(); onChapterBoundariesOutListener = listener;
} }
public interface OnChapterSingleTapListener {
void onCenterTap();
void onLeftSideTap();
void onRightSideTap();
}
public void setOnChapterBoundariesOutListener(OnChapterBoundariesOutListener onChapterBoundariesOutListener) {
mOnChapterBoundariesOutListener = onChapterBoundariesOutListener;
}
public void setOnChapterSingleTapListener(OnChapterSingleTapListener onChapterSingleTapListener) {
mOnChapterSingleTapListener = onChapterSingleTapListener;
}
private class ReaderViewGestureListener extends GestureDetector.SimpleOnGestureListener {
@Override @Override
public boolean onSingleTapConfirmed(MotionEvent e) { public void setOnChapterSingleTapListener(OnChapterSingleTapListener listener) {
final int position = getCurrentItem(); onChapterSingleTapListener = listener;
final float positionX = e.getX();
if (positionX < getWidth() * LEFT_REGION) {
if (position != 0) {
if (mOnChapterSingleTapListener != null) {
mOnChapterSingleTapListener.onLeftSideTap();
}
} else {
if (mOnChapterBoundariesOutListener != null) {
mOnChapterBoundariesOutListener.onFirstPageOutEvent();
}
}
} else if (positionX > getWidth() * RIGHT_REGION) {
if (position != getAdapter().getCount() - 1) {
if (mOnChapterSingleTapListener != null) {
mOnChapterSingleTapListener.onRightSideTap();
}
} else {
if (mOnChapterBoundariesOutListener != null) {
mOnChapterBoundariesOutListener.onLastPageOutEvent();
}
}
} else {
if (mOnChapterSingleTapListener != null) {
mOnChapterSingleTapListener.onCenterTap();
}
}
return true;
} }
@Override
public OnChapterBoundariesOutListener getChapterBoundariesListener() {
return onChapterBoundariesOutListener;
}
@Override
public OnChapterSingleTapListener getChapterSingleTapListener() {
return onChapterSingleTapListener;
} }
} }

View File

@ -1,97 +1,36 @@
package eu.kanade.mangafeed.ui.reader.viewer.vertical; package eu.kanade.mangafeed.ui.reader.viewer.vertical;
import android.support.v4.view.ViewPager;
import android.view.MotionEvent;
import java.util.List;
import butterknife.Bind;
import butterknife.ButterKnife;
import eu.kanade.mangafeed.R; import eu.kanade.mangafeed.R;
import eu.kanade.mangafeed.data.source.model.Page;
import eu.kanade.mangafeed.ui.reader.ReaderActivity; import eu.kanade.mangafeed.ui.reader.ReaderActivity;
import eu.kanade.mangafeed.ui.reader.viewer.base.BaseReader; import eu.kanade.mangafeed.ui.reader.viewer.common.ViewPagerInterface;
import eu.kanade.mangafeed.ui.reader.viewer.common.ViewPagerReaderAdapter; import eu.kanade.mangafeed.ui.reader.viewer.common.ViewPagerReader;
import rx.Subscription;
public class VerticalReader extends BaseReader { public class VerticalReader extends ViewPagerReader {
@Bind(R.id.view_pager) VerticalViewPager viewPager;
private ViewPagerReaderAdapter adapter;
private boolean transitions;
private Subscription transitionsSubscription;
public VerticalReader(ReaderActivity activity) { public VerticalReader(ReaderActivity activity) {
super(activity); super(activity);
activity.getLayoutInflater().inflate(R.layout.reader_vertical, container); activity.getLayoutInflater().inflate(R.layout.reader_vertical, container);
ButterKnife.bind(this, container);
transitionsSubscription = activity.getPreferences().enableTransitions().asObservable() viewPager = (ViewPagerInterface) container.findViewById(R.id.view_pager);
.subscribe(value -> transitions = value); initializeViewPager();
((VerticalViewPager) viewPager).addOnPageChangeListener(new PageChangeListener());
viewPager.setOffscreenPageLimit(2);
viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
currentPosition = position;
updatePageNumber();
} }
});
viewPager.setOnChapterBoundariesOutListener(new VerticalViewPager.OnChapterBoundariesOutListener() {
@Override @Override
public void onFirstPageOutEvent() { public void onFirstPageOut() {
requestPreviousChapter(); requestPreviousChapter();
} }
@Override @Override
public void onLastPageOutEvent() { public void onLastPageOut() {
requestNextChapter(); requestNextChapter();
} }
});
viewPager.setOnChapterSingleTapListener(new VerticalViewPager.OnChapterSingleTapListener() { private class PageChangeListener extends VerticalViewPagerImpl.SimpleOnPageChangeListener {
@Override @Override
public void onCenterTap() { public void onPageSelected(int position) {
activity.onCenterSingleTap(); onPageChanged(position);
}
} }
@Override
public void onLeftSideTap() {
viewPager.setCurrentItem(viewPager.getCurrentItem() - 1, transitions);
}
@Override
public void onRightSideTap() {
viewPager.setCurrentItem(viewPager.getCurrentItem() + 1, transitions);
}
});
}
@Override
public int getTotalPages() {
return adapter.getCount();
}
@Override
public void setSelectedPage(int pageNumber) {
viewPager.setCurrentItem(getCurrentPageIndex(pageNumber), false);
}
@Override
public void onPageListReady(List<Page> pages) {
currentPosition = 0;
adapter = new ViewPagerReaderAdapter(activity.getSupportFragmentManager(), pages);
viewPager.setAdapter(adapter);
}
@Override
public boolean onImageTouch(MotionEvent motionEvent) {
return viewPager.onImageTouch(motionEvent);
}
@Override
public void destroy() {
transitionsSubscription.unsubscribe();
}
} }

View File

@ -5,61 +5,66 @@ import android.util.AttributeSet;
import android.view.GestureDetector; import android.view.GestureDetector;
import android.view.MotionEvent; import android.view.MotionEvent;
public class VerticalViewPager extends fr.castorflex.android.verticalviewpager.VerticalViewPager { import eu.kanade.mangafeed.ui.reader.viewer.common.OnChapterBoundariesOutListener;
import eu.kanade.mangafeed.ui.reader.viewer.common.OnChapterSingleTapListener;
import eu.kanade.mangafeed.ui.reader.viewer.common.ViewPagerGestureListener;
import eu.kanade.mangafeed.ui.reader.viewer.common.ViewPagerInterface;
public class VerticalViewPager extends VerticalViewPagerImpl implements ViewPagerInterface {
private GestureDetector gestureDetector; private GestureDetector gestureDetector;
private OnChapterBoundariesOutListener mOnChapterBoundariesOutListener; private OnChapterBoundariesOutListener onChapterBoundariesOutListener;
private OnChapterSingleTapListener mOnChapterSingleTapListener; private OnChapterSingleTapListener onChapterSingleTapListener;
private static final float LEFT_REGION = 0.33f;
private static final float RIGHT_REGION = 0.66f;
private static final float SWIPE_TOLERANCE = 0.25f; private static final float SWIPE_TOLERANCE = 0.25f;
private float startDragY; private float startDragY;
public VerticalViewPager(Context context) {
super(context);
init(context);
}
public VerticalViewPager(Context context, AttributeSet attrs) { public VerticalViewPager(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
gestureDetector = new GestureDetector(getContext(), new ReaderViewGestureListener()); init(context);
}
private void init(Context context) {
gestureDetector = new GestureDetector(context, new VerticalViewPagerGestureListener(this));
} }
@Override @Override
public boolean onInterceptTouchEvent(MotionEvent ev) { public boolean onInterceptTouchEvent(MotionEvent ev) {
try {
if ((ev.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) { if ((ev.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
if (this.getCurrentItem() == 0 || this.getCurrentItem() == this.getAdapter().getCount() - 1) { if (getCurrentItem() == 0 || getCurrentItem() == getAdapter().getCount() - 1) {
startDragY = ev.getY(); startDragY = ev.getY();
} }
} }
return super.onInterceptTouchEvent(ev); return super.onInterceptTouchEvent(ev);
} catch (IllegalArgumentException e) {
// Do Nothing.
}
return false;
} }
@Override @Override
public boolean onTouchEvent(MotionEvent ev) { public boolean onTouchEvent(MotionEvent ev) {
try { if (onChapterBoundariesOutListener != null) {
if (mOnChapterBoundariesOutListener != null) { if (getCurrentItem() == 0) {
if (this.getCurrentItem() == 0) {
if ((ev.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) { if ((ev.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) {
float displacement = ev.getY() - startDragY; float displacement = ev.getY() - startDragY;
if (ev.getY() > startDragY && displacement > getHeight() * SWIPE_TOLERANCE) { if (ev.getY() > startDragY && displacement > getHeight() * SWIPE_TOLERANCE) {
mOnChapterBoundariesOutListener.onFirstPageOutEvent(); onChapterBoundariesOutListener.onFirstPageOutEvent();
return true; return true;
} }
startDragY = 0; startDragY = 0;
} }
} else if (this.getCurrentItem() == this.getAdapter().getCount() - 1) { } else if (getCurrentItem() == getAdapter().getCount() - 1) {
if ((ev.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) { if ((ev.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) {
float displacement = startDragY - ev.getY(); float displacement = startDragY - ev.getY();
if (ev.getY() < startDragY && displacement > getHeight() * SWIPE_TOLERANCE) { if (ev.getY() < startDragY && displacement > getHeight() * SWIPE_TOLERANCE) {
mOnChapterBoundariesOutListener.onLastPageOutEvent(); onChapterBoundariesOutListener.onLastPageOutEvent();
return true; return true;
} }
@ -69,71 +74,46 @@ public class VerticalViewPager extends fr.castorflex.android.verticalviewpager.V
} }
return super.onTouchEvent(ev); return super.onTouchEvent(ev);
} catch (IllegalArgumentException e) {
// Do Nothing.
}
return false;
} }
@Override
public boolean onImageTouch(MotionEvent event) { public boolean onImageTouch(MotionEvent event) {
return gestureDetector.onTouchEvent(event); return gestureDetector.onTouchEvent(event);
} }
public interface OnChapterBoundariesOutListener { @Override
void onFirstPageOutEvent(); public void setOnChapterBoundariesOutListener(OnChapterBoundariesOutListener listener) {
void onLastPageOutEvent(); onChapterBoundariesOutListener = listener;
} }
public interface OnChapterSingleTapListener {
void onCenterTap();
void onLeftSideTap();
void onRightSideTap();
}
public void setOnChapterBoundariesOutListener(OnChapterBoundariesOutListener onChapterBoundariesOutListener) {
mOnChapterBoundariesOutListener = onChapterBoundariesOutListener;
}
public void setOnChapterSingleTapListener(OnChapterSingleTapListener onChapterSingleTapListener) {
mOnChapterSingleTapListener = onChapterSingleTapListener;
}
private class ReaderViewGestureListener extends GestureDetector.SimpleOnGestureListener {
@Override @Override
public boolean onSingleTapConfirmed(MotionEvent e) { public void setOnChapterSingleTapListener(OnChapterSingleTapListener listener) {
final int position = getCurrentItem(); onChapterSingleTapListener = listener;
final float positionX = e.getX();
if (positionX < getWidth() * LEFT_REGION) {
if (position != 0) {
if (mOnChapterSingleTapListener != null) {
mOnChapterSingleTapListener.onLeftSideTap();
}
} else {
if (mOnChapterBoundariesOutListener != null) {
mOnChapterBoundariesOutListener.onFirstPageOutEvent();
}
}
} else if (positionX > getWidth() * RIGHT_REGION) {
if (position != getAdapter().getCount() - 1) {
if (mOnChapterSingleTapListener != null) {
mOnChapterSingleTapListener.onRightSideTap();
}
} else {
if (mOnChapterBoundariesOutListener != null) {
mOnChapterBoundariesOutListener.onLastPageOutEvent();
}
}
} else {
if (mOnChapterSingleTapListener != null) {
mOnChapterSingleTapListener.onCenterTap();
}
} }
@Override
public OnChapterBoundariesOutListener getChapterBoundariesListener() {
return onChapterBoundariesOutListener;
}
@Override
public OnChapterSingleTapListener getChapterSingleTapListener() {
return onChapterSingleTapListener;
}
private class VerticalViewPagerGestureListener extends ViewPagerGestureListener {
public VerticalViewPagerGestureListener(ViewPagerInterface viewPager) {
super(viewPager);
}
@Override
public boolean onDown(MotionEvent e) {
// Vertical view pager ignores scrolling events sometimes.
// Returning true here fixes it, but we lose touch events on the image like
// double tap to zoom
return true; return true;
} }
}
} }
}

View File

@ -28,6 +28,6 @@
<color name="line_grey">@color/md_light_dividers</color> <color name="line_grey">@color/md_light_dividers</color>
<color name="light_grey">@color/md_grey_300</color> <color name="light_grey">@color/md_grey_300</color>
<color name="page_number_background">#AAE9E9E9</color> <color name="page_number_background">#AAE9E9E9</color>
<color name="page_number_background_black">#AA252525</color> <color name="page_number_background_black">#99252525</color>
<color name="reader_menu_background">@color/colorPrimarySuperDark</color> <color name="reader_menu_background">@color/colorPrimarySuperDark</color>
</resources> </resources>