title: Best way to disable ViewPager paging
body: <p>I'm developing an app which have a <code>ViewPager</code> as a menu. Each <code>fragment</code> has a bunch of child views which can be <code>ListView</code>, <code>ScrollView</code>, <code>LinearLayout</code>, etc...
  One of this <code>fragments</code> have a <strong>settings</strong> button which toggles a settings panel (<code>LinearLayout</code> wrapper) with a <code>ScrollView</code> and some <code>LinearLayout</code> (buttons) and <code>SeekBar</code> as childs. This <strong>settings</strong> panel is animated with a slide up or down animation (when dismissed) and when it's visible I disable the <code>ViewPager</code> paging:</p>
  
  <pre><code>@Override
  public boolean onTouchEvent(MotionEvent event) {
      if (!pagingEnabled &amp;&amp; event.getAction() == MotionEvent.ACTION_MOVE) {
          return true;
      }
      return super.onTouchEvent(event);
  }
  
  @Override
  public boolean onInterceptTouchEvent(MotionEvent event) {
      if (!pagingEnabled &amp;&amp; event.getAction() == MotionEvent.ACTION_MOVE) {
          return true;
      }
      return super.onInterceptTouchEvent(event);
  }
  
  public boolean isPagingEnabled() {
      return pagingEnabled;
  }
  
  public void setPagingEnabled(boolean pagingEnabled) {
      this.pagingEnabled = pagingEnabled;
  }
  </code></pre>
  
  <p>But this came with a problem, every time the panel is up all it child views wouldn't receive the <code>OnTouchEvent</code> and that's why I've added a <code>GestureDetector.SimpleOnGestureListener</code>:</p>
  
  <pre><code>protected class YScrollDetector extends GestureDetector.SimpleOnGestureListener {
      @Override
      public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
          Log.i(C.TAG, "distanceX " + distanceX + " distanceY " + distanceY);
          return Math.abs(distanceY) &lt; Math.abs(distanceX);
      }
  }
  </code></pre>
  
  <p>and changed my <code>ViewPager</code> <code>onInterceptTouchEvent</code> to:</p>
  
  <pre><code>@Override
  public boolean onInterceptTouchEvent(MotionEvent event) {
      if (!pagingEnabled &amp;&amp; event.getAction() == MotionEvent.ACTION_MOVE &amp;&amp; (mGestureDetector != null &amp;&amp; mGestureDetector.onTouchEvent(event))) {
          return true;
      }
      return super.onInterceptTouchEvent(event);
  }
  </code></pre>
  
  <p>This works, the panel buttons receive their onClick, the ListView swipes, etc... but this doesn't work so perfect because <code>Math.abs(distanceY) &lt; Math.abs(distanceX)</code> it's not that accurate. If I fast swipe up and down or diagonally or if I touch a button with a minor swipe the <code>onInterceptTouchEvent</code> will return <code>true</code> because <code>mGestureDetector.onTouchEvent(event)</code> will return <code>true</code> too.<br><br>
  After some google search I came across this: </p>
  
  <pre><code>viewPager.requestDisallowInterceptTouchEvent(true);
  </code></pre>
  
  <p>And I tried something like this:</p>
  
  <pre><code>myListView.setOnTouchListener(new View.OnTouchListener() {
      @Override
      public boolean onTouch(View v, MotionEvent event) {
          viewPager.requestDisallowInterceptTouchEvent(true);
          return false;
      }
  });
  </code></pre>
  
  <p>And it works really well because <code>ViewPager.onInterceptTouchEvent</code> it's called first with <code>MotionEvent.ACTION_DOWN</code> and then <code>myListView.setOnTouchListener</code> it's called right after and disallows the remaining <code>MotionEvent</code> actions (MOVE and UP) and I can fast swipe up, down, sides ways, etc. The <code>ViewPager</code> wont page but the <code>ListView</code> swipes like a charm.
  <br><br>
  But a problem still remains, I've to add this <code>requestDisallowInterceptTouchEvent(true)</code> to all child views <code>onTouchEvent</code>, and it's not elegant code.<br><br>
  So my question is, I am on the right path? Is there anyway to avoid adding this listener to all the panel child views (of course if I have to I'll do it in the most generic way)?<br><br>
  Thanks for your time.</p>