package com.gh.common.view;

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

/**
 * 重写ViewPager 解决触摸事件
 * 
 * @author 黄壮华
 * 
 */
public class MyViewPager extends ViewPager {

	public static boolean isCanMove = false;

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

	@Override
	public boolean onInterceptTouchEvent(MotionEvent ev) {
		
		switch (ev.getAction()) {
		case MotionEvent.ACTION_MOVE:
			if (isCanMove) {
				return true;
			}
			break;
		default:
			break;
		}
		return super.onInterceptTouchEvent(ev);
	}

	@Override
	public boolean dispatchTouchEvent(MotionEvent ev) {
		
		switch (ev.getAction()) {
		case MotionEvent.ACTION_DOWN:
			isCanMove = false;
			break;
		case MotionEvent.ACTION_MOVE:
			if (isCanMove) {
				return onTouchEvent(ev);
			}
			break;
		case MotionEvent.ACTION_UP:
			if (isCanMove) {
				return onTouchEvent(ev);
			}
			break;
		default:
			break;
		}
		return super.dispatchTouchEvent(ev);
	}
}
