DisallowParentTouchViewPager.java 1.49 KB
Newer Older
1
package com.ydl.ydlcommon.view;
konghaorui committed
2 3

import android.content.Context;
YKai committed
4
import androidx.viewpager.widget.ViewPager;
konghaorui committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
import android.util.AttributeSet;
import android.view.MotionEvent;


/**
 * Created by softrice on 15/9/12.
 */
public class DisallowParentTouchViewPager extends ViewPager {

    public boolean isClick;

    private FixRequestDisallowTouchEventPtrFrameLayout parent;

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

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

    public void setNestParent(FixRequestDisallowTouchEventPtrFrameLayout parent) {
        this.parent = parent;
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        setIntercepTouchEvent(ev);
        return super.dispatchTouchEvent(ev);
    }

    private void setIntercepTouchEvent(MotionEvent ev) {
        if (parent != null) {
            parent.myRequestDisallowInterceptTouchEvent(true);
            if (ev.getAction() == MotionEvent.ACTION_CANCEL || ev.getAction() == MotionEvent.ACTION_UP) {
                parent.myRequestDisallowInterceptTouchEvent(false);
            }
        }
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {

        setIntercepTouchEvent(ev);
        return super.onInterceptTouchEvent(ev);
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {

        setIntercepTouchEvent(ev);
        return super.onTouchEvent(ev);
    }




}