package kr.co.hanwha.hifive.view;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;

/**
 * Created by sanghoonkwon on 2018. 1. 18..
 */

public class CustomViewPager extends ViewPager {
    public boolean isScrollEnable = true;

    public CustomViewPager(Context context) {
        super(context);
    }

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

    public void setScrollEnable(boolean scrollEnable) {
        isScrollEnable = scrollEnable;
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent event) {
        if (isScrollEnable) {
            if (canScrollHorizontally(1) || canScrollHorizontally(-1)) {
                return super.onInterceptTouchEvent(event);
            }
        }

        return false;
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (isScrollEnable) {
            if (canScrollHorizontally(1) || canScrollHorizontally(-1)) {
                return super.onTouchEvent(event);
            }
        }

        return false;
    }
}