content: package com.allure.lbanners.viewpager;
  
  import android.content.Context;
  import android.util.AttributeSet;
  import android.view.MotionEvent;
  
  /**
   * 判断disptch事件分发
   */
  public class MyViewPager extends CustomViewPager {
  
      public MyViewPager(Context context) {
          super(context);
      }
  
      public MyViewPager(Context context, AttributeSet attrs) {
          super(context, attrs);
      }
  
  
      @Override
      public boolean dispatchTouchEvent(MotionEvent ev) {
          switch (ev.getAction()) {
              case MotionEvent.ACTION_DOWN:
                  if (listener != null) {
                      listener.onTouchDown();
                  }
                  break;
              case MotionEvent.ACTION_UP:
                  if (listener != null) {
                      listener.onTouchUp();
                  }
                  break;
              default:
                  break;
          }
          return super.dispatchTouchEvent(ev);
      }
  
      private OnViewPagerTouchEvent listener;
  
      public void setOnViewPagerTouchEventListener(OnViewPagerTouchEvent l) {
          listener = l;
      }
  
      public interface OnViewPagerTouchEvent {
          void onTouchDown();
  
          void onTouchUp();
      }
  }
  