title: How to detect a swipe gesture on webview
body: <p>i'm developing a simple android application with a <code>RelativeLayout</code> and a <code>WebView</code> inside. </p>
  
  <p>I have to detect swipe from bottom to top done only in the 20% of the left part of the screen. So when user swipe in that space from bottom to top i have to show a custom dialog.</p>
  
  <p>What i try is:</p>
  
  <pre><code>import android.app.Activity;
  import android.view.MotionEvent;
  import android.view.View;
  
  public class ActivitySwipeDetector implements View.OnTouchListener {
  
      static final String logTag = "ActivitySwipeDetector";
      private Activity activity;
      static final int MIN_DISTANCE = 100;
      private float downY, upY;
  
      public ActivitySwipeDetector(Activity activity){
          this.activity = activity;
      }
  
      public void onRightToLeftSwipe(){
  
      }
  
      public void onLeftToRightSwipe(){
  
      }
  
      public void onTopToBottomSwipe(){
  
      }
  
      public void onBottomToTopSwipe(){
          System.out.println("BOTTOM TO TOP SWIPE DONE!");
      }
  
      public boolean onTouch(View v, MotionEvent event) {
          switch(event.getAction()){
          case MotionEvent.ACTION_DOWN: {
              downY = event.getY();
              return true;
          }
          case MotionEvent.ACTION_UP: {
              upY = event.getY();
              float deltaY = downY - upY;
              if(Math.abs(deltaY) &gt; MIN_DISTANCE){
                  if(deltaY &gt; 0) { this.onBottomToTopSwipe(); return true; }
              }
              else {
                  return false;
              }
  
              return true;
          }
          }
          return false;
      }
  
  }
  
      layout = (RelativeLayout)this.findViewById(R.id.layout);
      layout.setOnTouchListener(activitySwipeDetector);
  </code></pre>
  
  <p>But it doesn't do nothing!</p>
  
  <p>So i try creating a custom webview in this way:</p>
  
  <pre><code>import android.content.Context;
  import android.util.AttributeSet;
  import android.view.MotionEvent;
  import android.webkit.WebView;
  
  public class MyWebView extends WebView {
      public MyWebView(Context context) {
          super(context);
      }
      public MyWebView(Context context,AttributeSet set){
          super(context,set);
      }
  
  
  
      @Override 
      public boolean onTouchEvent(MotionEvent evt) {   
  
          boolean consumed = super.onTouchEvent(evt); 
          if (isClickable()) { 
              switch (evt.getAction()) { 
              case MotionEvent.ACTION_DOWN:  
                  lastTouchY = evt.getY();
                  downTime = evt.getEventTime();
                  hasMoved = false; 
                  break; 
              case MotionEvent.ACTION_MOVE: 
                  hasMoved = moved(evt); 
                  break; 
              case MotionEvent.ACTION_UP: 
                  float actualTouchY = evt.getY();
                  long currentTime = evt.getEventTime();
                  float difference = Math.abs(lastTouchY - actualTouchY);
                  long time = currentTime - downTime;
  
                  if ( (lastTouchY &lt; actualTouchY) &amp;&amp; (time &lt; 220) &amp;&amp; (difference &gt; 100) ) {
                      System.out.println("SWIPE1");
                  }
                  if ( (lastTouchY &gt; actualTouchY) &amp;&amp; (time &lt; 220) &amp;&amp; (difference &gt; 100) ) {
                      System.out.println("SWIPE2");
                  }
                  break; 
              } 
          } 
          return consumed || isClickable(); 
      } 
      long downTime;
      private float lastTouchY; 
      private boolean hasMoved = false; 
      private boolean moved(MotionEvent evt) { 
          return hasMoved || 
                  Math.abs(evt.getY() - lastTouchY) &gt; 10.0; 
      }
  
  }
  </code></pre>
  
  <p>but with no success!!! can someone help me?? THAnks!!!!! :)</p>