package ir.asparsa.android.ui.view;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.animation.DecelerateInterpolator;
import android.widget.Scroller;

import java.lang.reflect.Field;

/**
 * @author hadi
 * @since 3/8/2017 AD.
 */
public class NonSwipeableViewPager extends ViewPager {

    public NonSwipeableViewPager(Context context) {
        super(context);
        setMyScroller();
    }

    public NonSwipeableViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
        setMyScroller();
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent event) {
        // Never allow swiping to switch between pages
        return false;
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        // Never allow swiping to switch between pages
        return false;
    }

    //down one is added for smooth scrolling
    private void setMyScroller() {
        try {
            Class<?> viewpager = ViewPager.class;
            Field scroller = viewpager.getDeclaredField("mScroller");
            scroller.setAccessible(true);
            scroller.set(this, new MyScroller(getContext()));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public class MyScroller extends Scroller {
        MyScroller(Context context) {
            super(context, new DecelerateInterpolator());
        }

        @Override
        public void startScroll(int startX, int startY, int dx, int dy, int duration) {
            super.startScroll(startX, startY, dx, dy, 350 /*1 secs*/);
        }
    }
}
@@ -174,127 +174,8 @@
 ent;
-%0Aimport android.view.animation.DecelerateInterpolator;%0Aimport android.widget.Scroller;%0A%0Aimport java.lang.reflect.Field;
 %0A%0A/*
@@ -355,33 +355,8 @@
 t);%0A
-        setMyScroller();%0A
     
@@ -383,32 +383,45 @@
 peableViewPager(
+%0A            
 Context context,
@@ -420,16 +420,28 @@
 context,
+%0A           
  Attribu
@@ -451,16 +451,21 @@
 et attrs
+%0A    
 ) %7B%0A    
@@ -495,33 +495,8 @@
 s);%0A
-        setMyScroller();%0A
     
@@ -811,754 +811,6 @@
    %7D
-%0A%0A    //down one is added for smooth scrolling%0A    private void setMyScroller() %7B%0A        try %7B%0A            Class%3C?%3E viewpager = ViewPager.class;%0A            Field scroller = viewpager.getDeclaredField(%22mScroller%22);%0A            scroller.setAccessible(true);%0A            scroller.set(this, new MyScroller(getContext()));%0A        %7D catch (Exception e) %7B%0A            e.printStackTrace();%0A        %7D%0A    %7D%0A%0A    public class MyScroller extends Scroller %7B%0A        MyScroller(Context context) %7B%0A            super(context, new DecelerateInterpolator());%0A        %7D%0A%0A        @Override%0A        public void startScroll(int startX, int startY, int dx, int dy, int duration) %7B%0A            super.startScroll(startX, startY, dx, dy, 350 /*1 secs*/);%0A        %7D%0A    %7D
 %0A%7D

Remove unnecessary reflection