package com.usai.apex.KPI;

import android.content.Context;
import android.support.v4.widget.SwipeRefreshLayout;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;

public class KPISwipeRefresh extends SwipeRefreshLayout {

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

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

    private float mFirstPointY = 0;

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {

        Log.d("Refresh", "onInterceptTouchEvent: " + ev.getY() + "and Action: " + ev.getAction());

        if (ev.getAction() == MotionEvent.ACTION_DOWN) {
            mFirstPointY = ev.getY();
        }

        // 防止下拉和ListView向上滑动冲突
        if (mFirstPointY > 100) {
            return false;
        }

        return super.onInterceptTouchEvent(ev);
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {

        Log.d("Refresh OnTouch", "onInterceptTouchEvent: " + ev.getY() + "and Action: " + ev.getAction());
        if (ev.getAction() == MotionEvent.ACTION_DOWN) {
            mFirstPointY = ev.getY();
        }

        // 防止下拉和ListView向上滑动冲突
        if (mFirstPointY > 100) {
            return false;
        }

        return super.onTouchEvent(ev);
    }
}
