From 72b247161952d999d5750a1127f727d370942745 Mon Sep 17 00:00:00 2001 From: inorichi Date: Tue, 22 Dec 2015 13:22:13 +0100 Subject: [PATCH] Fix crash with gestures --- .../horizontal/HorizontalViewPager.java | 56 +++++++++++-------- .../viewer/vertical/VerticalViewPager.java | 56 +++++++++++-------- 2 files changed, 64 insertions(+), 48 deletions(-) diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/horizontal/HorizontalViewPager.java b/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/horizontal/HorizontalViewPager.java index 5f1607da5..a3c867f58 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/horizontal/HorizontalViewPager.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/horizontal/HorizontalViewPager.java @@ -37,44 +37,52 @@ public class HorizontalViewPager extends ViewPager implements ViewPagerInterface @Override public boolean onInterceptTouchEvent(MotionEvent ev) { - if ((ev.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) { - if (getCurrentItem() == 0 || getCurrentItem() == getAdapter().getCount() - 1) { - startDragX = ev.getX(); + try { + if ((ev.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) { + if (getCurrentItem() == 0 || getCurrentItem() == getAdapter().getCount() - 1) { + startDragX = ev.getX(); + } } - } - return super.onInterceptTouchEvent(ev); + return super.onInterceptTouchEvent(ev); + } catch (IllegalArgumentException e) { + return true; + } } @Override public boolean onTouchEvent(MotionEvent ev) { - if (onChapterBoundariesOutListener != null) { - if (getCurrentItem() == 0) { - if ((ev.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) { - float displacement = ev.getX() - startDragX; + try { + if (onChapterBoundariesOutListener != null) { + if (getCurrentItem() == 0) { + if ((ev.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) { + float displacement = ev.getX() - startDragX; - if (ev.getX() > startDragX && displacement > getWidth() * SWIPE_TOLERANCE) { - onChapterBoundariesOutListener.onFirstPageOutEvent(); - return true; + if (ev.getX() > startDragX && displacement > getWidth() * SWIPE_TOLERANCE) { + onChapterBoundariesOutListener.onFirstPageOutEvent(); + return true; + } + + startDragX = 0; } + } else if (getCurrentItem() == getAdapter().getCount() - 1) { + if ((ev.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) { + float displacement = startDragX - ev.getX(); - startDragX = 0; - } - } else if (getCurrentItem() == getAdapter().getCount() - 1) { - if ((ev.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) { - float displacement = startDragX - ev.getX(); + if (ev.getX() < startDragX && displacement > getWidth() * SWIPE_TOLERANCE) { + onChapterBoundariesOutListener.onLastPageOutEvent(); + return true; + } - if (ev.getX() < startDragX && displacement > getWidth() * SWIPE_TOLERANCE) { - onChapterBoundariesOutListener.onLastPageOutEvent(); - return true; + startDragX = 0; } - - startDragX = 0; } } - } - return super.onTouchEvent(ev); + return super.onTouchEvent(ev); + } catch (IllegalArgumentException e) { + return true; + } } @Override diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/vertical/VerticalViewPager.java b/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/vertical/VerticalViewPager.java index d4a6744ed..b04d9c3ef 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/vertical/VerticalViewPager.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/vertical/VerticalViewPager.java @@ -36,44 +36,52 @@ public class VerticalViewPager extends VerticalViewPagerImpl implements ViewPage @Override public boolean onInterceptTouchEvent(MotionEvent ev) { - if ((ev.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) { - if (getCurrentItem() == 0 || getCurrentItem() == getAdapter().getCount() - 1) { - startDragY = ev.getY(); + try { + if ((ev.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) { + if (getCurrentItem() == 0 || getCurrentItem() == getAdapter().getCount() - 1) { + startDragY = ev.getY(); + } } - } - return super.onInterceptTouchEvent(ev); + return super.onInterceptTouchEvent(ev); + } catch (IllegalArgumentException e) { + return true; + } } @Override public boolean onTouchEvent(MotionEvent ev) { - if (onChapterBoundariesOutListener != null) { - if (getCurrentItem() == 0) { - if ((ev.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) { - float displacement = ev.getY() - startDragY; + try { + if (onChapterBoundariesOutListener != null) { + if (getCurrentItem() == 0) { + if ((ev.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) { + float displacement = ev.getY() - startDragY; - if (ev.getY() > startDragY && displacement > getHeight() * SWIPE_TOLERANCE) { - onChapterBoundariesOutListener.onFirstPageOutEvent(); - return true; + if (ev.getY() > startDragY && displacement > getHeight() * SWIPE_TOLERANCE) { + onChapterBoundariesOutListener.onFirstPageOutEvent(); + return true; + } + + startDragY = 0; } + } else if (getCurrentItem() == getAdapter().getCount() - 1) { + if ((ev.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) { + float displacement = startDragY - ev.getY(); - startDragY = 0; - } - } else if (getCurrentItem() == getAdapter().getCount() - 1) { - if ((ev.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) { - float displacement = startDragY - ev.getY(); + if (ev.getY() < startDragY && displacement > getHeight() * SWIPE_TOLERANCE) { + onChapterBoundariesOutListener.onLastPageOutEvent(); + return true; + } - if (ev.getY() < startDragY && displacement > getHeight() * SWIPE_TOLERANCE) { - onChapterBoundariesOutListener.onLastPageOutEvent(); - return true; + startDragY = 0; } - - startDragY = 0; } } - } - return super.onTouchEvent(ev); + return super.onTouchEvent(ev); + } catch (IllegalArgumentException e) { + return true; + } } @Override