package com.navinfo.outdoor.util;

import android.content.Context;

import android.util.AttributeSet;
import android.view.MotionEvent;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.viewpager.widget.ViewPager;

//自定义不可滑动的VI
public class NoSlideViewPager extends ViewPager {
    // 定义一个是否可以滑动的boolean 值
    private boolean isCanScroll = false;
    //定义一个是否可以滑动效果的boolean 值
    private boolean noScrollAnim = false;

    public NoSlideViewPager(@NonNull Context context) {
        super(context);
    }

    public NoSlideViewPager(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }
    /**
     * 设置是否能左右滑动
     * @param canScroll true 不能滑动
     */
    public void setCanScroll(boolean canScroll) {
        isCanScroll = canScroll;
    }
    /**
     * 设置没有滑动动画
     * @param noScrollAnim false 无动画
     */
    public void setNoScrollAnim(boolean noScrollAnim) {
        this.noScrollAnim = noScrollAnim;
    }

    // 滑动到指定位置
    @Override
    public void scrollTo(int x, int y) {
        super.scrollTo(x, y);
    }

    @Override
    public boolean onTouchEvent(MotionEvent arg0) {
        return !isCanScroll && super.onTouchEvent(arg0);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent arg0) {
        return !isCanScroll && super.onInterceptTouchEvent(arg0);
    }

    @Override
    public void setCurrentItem(int item, boolean smoothScroll) {
        super.setCurrentItem(item, smoothScroll);
    }

    @Override
    public void setCurrentItem(int item) {
        super.setCurrentItem(item,noScrollAnim);
    }

}
