From e8da1424ad7781888907428e3dfb0177cb38b0c9 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 21 Feb 2016 18:09:39 +0100 Subject: [PATCH] use an overriden ViewPager to fix IllegalArgumentException --- .../simplemobiletools/com/MyViewPager.java | 37 +++++++++++++++++++ .../com/activities/ViewPagerActivity.java | 4 +- app/src/main/res/layout/activity_photo.xml | 2 +- 3 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 app/src/main/java/gallery/simplemobiletools/com/MyViewPager.java diff --git a/app/src/main/java/gallery/simplemobiletools/com/MyViewPager.java b/app/src/main/java/gallery/simplemobiletools/com/MyViewPager.java new file mode 100644 index 000000000..85db99f27 --- /dev/null +++ b/app/src/main/java/gallery/simplemobiletools/com/MyViewPager.java @@ -0,0 +1,37 @@ +package gallery.simplemobiletools.com; + +import android.content.Context; +import android.support.v4.view.ViewPager; +import android.util.AttributeSet; +import android.view.MotionEvent; + +public class MyViewPager extends ViewPager { + + public MyViewPager(Context context) { + super(context); + } + + public MyViewPager(Context context, AttributeSet attrs) { + super(context, attrs); + } + + @Override + public boolean onInterceptTouchEvent(MotionEvent ev) { + try { + return super.onInterceptTouchEvent(ev); + } catch (IllegalArgumentException ex) { + ex.printStackTrace(); + } + return false; + } + + @Override + public boolean onTouchEvent(MotionEvent ev) { + try { + return super.onTouchEvent(ev); + } catch (IllegalArgumentException ex) { + ex.printStackTrace(); + } + return false; + } +} diff --git a/app/src/main/java/gallery/simplemobiletools/com/activities/ViewPagerActivity.java b/app/src/main/java/gallery/simplemobiletools/com/activities/ViewPagerActivity.java index 97772fb95..024bb2bf6 100644 --- a/app/src/main/java/gallery/simplemobiletools/com/activities/ViewPagerActivity.java +++ b/app/src/main/java/gallery/simplemobiletools/com/activities/ViewPagerActivity.java @@ -4,7 +4,6 @@ import android.database.Cursor; import android.net.Uri; import android.os.Bundle; import android.provider.MediaStore; -import android.support.v4.view.ViewPager; import android.support.v7.app.AppCompatActivity; import java.io.File; @@ -12,6 +11,7 @@ import java.util.ArrayList; import java.util.List; import gallery.simplemobiletools.com.Constants; +import gallery.simplemobiletools.com.MyViewPager; import gallery.simplemobiletools.com.R; import gallery.simplemobiletools.com.adapters.MyPagerAdapter; @@ -24,7 +24,7 @@ public class ViewPagerActivity extends AppCompatActivity { setContentView(R.layout.activity_photo); pos = 0; - final ViewPager pager = (ViewPager) findViewById(R.id.view_pager); + final MyViewPager pager = (MyViewPager) findViewById(R.id.view_pager); final MyPagerAdapter adapter = new MyPagerAdapter(this, getPhotos()); pager.setAdapter(adapter); pager.setCurrentItem(pos); diff --git a/app/src/main/res/layout/activity_photo.xml b/app/src/main/res/layout/activity_photo.xml index 0638d871f..9c5d72001 100644 --- a/app/src/main/res/layout/activity_photo.xml +++ b/app/src/main/res/layout/activity_photo.xml @@ -5,7 +5,7 @@ android:layout_height="match_parent" android:background="@android:color/black"> -