title: Android - Adding GestureDetector to webview
body: <p>I would like to add the GestureDetector class to my webview so that I can manage common gestures such as doubletap.</p>
  
  <p>Here is what I am attempting to accomplish:</p>
  
  <ul>
  <li>SingleTap will function normally</li>
  <li>DoubleTap will open items (more on this below)</li>
  </ul>
  
  <p>Regarding the DoubleTap - The site in question has source code that defines how single and double clicks are handled for certain items.  It states that a single click selects an item and a double click opens that item.  I have to be vague regarding the items since it is not a public site.</p>
  
  <p>I do not need to configure flings or swipes.  I am just trying to recreate PC Mouse single clicks and double clicks.</p>
  
  <p><strong>EDIT:</strong>  I added in the suggestions below from Pat.  I changed a few things to my liking and added some from other sources.</p>
  
  <p>I used <a href="https://stackoverflow.com/questions/11188348/android-html-anchor-link-works-only-once-in-webview/11205345#11205345">this question</a> to help build my Activity along with Pat's help.  Using the "First Way" code, it loads my app correctly and successfully reloads the page as designed.  Now, I just need to add the other event handlers and configure them correctly.  Will post final code when I get it to work and I'll mark Pat's answer as correct.</p>
  
  <p>This user is asking the same question with no answer:  <a href="https://stackoverflow.com/questions/10418757/make-a-double-click-work-in-a-webview">How to make double clicks work.</a></p>
  
  <p>It says that this is depreciated GestureDetector(new MyGestureDetector()); - should I fix this?</p>
  
  <p>EDIT 2:  Since the actual question asked was how to add gesturedetecor to webview and I was able to do that, I will mark Pat's answer as correct.  Even though I did want to make doubleTap = double click, I did not ask that in my title so I will create a new question for that.</p>
  
  <pre><code>import android.webkit.WebView;
  import android.webkit.WebViewClient;
  import android.webkit.SslErrorHandler;
  import android.net.http.SslError;
  import android.os.Bundle;
  import android.app.Activity;
  import android.util.Log;
  import android.view.GestureDetector;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.view.View;
  import android.view.GestureDetector.SimpleOnGestureListener;
  import android.view.MotionEvent;
  
  public class MainActivity extends Activity{
      WebView webview;    
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          webview = (WebView) findViewById(R.id.webview);   
          //Do we want/need to enable Java?
          webview.getSettings().setJavaScriptEnabled(true); 
          //Here we allow for zoom controls - pinch
          webview.getSettings().setBuiltInZoomControls(true);
          //Here we remove the zoom control buttons - requires API 11
          webview.getSettings().setDisplayZoomControls(false);
          //Here we clear the Cache and SSL Preferences       
          webview.clearCache(true);
          webview.clearSslPreferences();
          //Do we need to enable scroll bars to allow people to scroll left and right?        
          webview.setHorizontalScrollBarEnabled(true);
          webview.setVerticalScrollBarEnabled(true);
          webview.setWebViewClient(new WebViewClient());
          webview.loadUrl("website");
  
          final GestureDetector gd = new GestureDetector(new MyGestureDetector());
          View.OnTouchListener gl = new View.OnTouchListener() {
              public boolean onTouch(View v, MotionEvent event) {
                  return gd.onTouchEvent(event);
              }
          };
          webview.setOnTouchListener(gl);
      }
  
  class MyGestureDetector extends SimpleOnGestureListener {    
      @Override
      public boolean onDoubleTapEvent(MotionEvent e) {
          Log.i("", "DoubleTapEvent");
          return true;
          }   
  
      }    
  
  
  // Ignore SSL certificate errors    
      public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
          handler.proceed();
      }
  
  //Would like to have a Menu Button to refresh the page - or really just bring you to the login page - for use when the session times out    
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      menu.add(1, 1, 0, "Refresh");
      //removed below to have only buttons show
      //getMenuInflater().inflate(R.menu.activity_main, menu);
      return true;
      }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      switch(item.getItemId()){
      case R.id.refresh:
          webview.loadUrl("website");
          return true;
      }
      return super.onOptionsItemSelected(item);
  
  }
  
  }
  </code></pre>
  
  <p>~ Dan</p>