title: How to use extended webview class in activity
body: <p>I am new to android and now im doing a webview app in which I have to disable double tap zooming but keep setwideviewport(true). I got a solution by searching but Im not able to implement that class to my activity.please help.Here is my activity.</p>
  
  <p>User_reg.java</p>
  
  <pre><code>package com.example.samworkshops;
  
  import android.os.Bundle;
  import android.os.SystemClock;
  import android.annotation.SuppressLint;
  import android.app.Activity;
  import android.content.res.Configuration;
  import android.graphics.Color;
  import android.graphics.Point;
  import android.view.Display;
  import android.view.GestureDetector;
  import android.view.KeyEvent;
  import android.view.MotionEvent;
  import android.view.View;
  import android.view.Window;
  import android.webkit.WebChromeClient;
  import android.webkit.WebView;
  import android.webkit.WebViewClient;
  
  public class User_reg extends Activity {
   private WebView webView;
   final Activity activity = this;
  
  
  @SuppressLint("SetJavaScriptEnabled")
  @Override
  public void onCreate(Bundle savedInstanceState) {
  
          super.onCreate(savedInstanceState);
          this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
  
          setContentView(R.layout.activity_user);
  
  
          webView = (WebView)findViewById(R.id.webView1);
          webView.requestFocusFromTouch();
          webView.getSettings().setJavaScriptEnabled(true);
          webView.getSettings().setUseWideViewPort(true);                                                         
          webView.getSettings().setBuiltInZoomControls(false);
          webView.setHorizontalScrollBarEnabled(false);
  
  
          webView.loadUrl("http://app.samworkshops.org/User_Reg.aspx");
  
          webView.setVisibility(View.INVISIBLE);
          webView.setWebChromeClient(new WebChromeClient() {
              public void onProgressChanged(WebView view, int progress)
              {
                  activity.setTitle("Loading...");
                  activity.setProgress(progress * 100);
  
                  if(progress == 100)
                      activity.setTitle(R.string.title_activity_user_reg);
              }
          });
  
          webView.setBackgroundColor(Color.parseColor("black"));
  
  
          webView.setWebViewClient(new WebViewClient() {
  
  
              @Override
              public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
              {
                  // Handle the error
              }
  
              @Override
              public boolean shouldOverrideUrlLoading(WebView view, String url)
              {
                  view.loadUrl(url);
                  return true;
              }
  
  
              @Override
              public void onPageFinished(WebView view, String url) {
  
              StringBuilder builder = new StringBuilder("");
  
  
                      builder.append("javascript:document.getElementById('Image3').style.visibility= 'hidden';");
                      builder.append("javascript:document.getElementById('Image3').style.display   = 'none'  ;");
  
              view.loadUrl(builder.toString());
  
                 webView.setVisibility(View.VISIBLE);
                 SystemClock.sleep(2000);
                  }
              }
  
  
          });
  
      }
    }
  </code></pre>
  
  <p>I got the solution class as below</p>
  
  <p>HelpWebView.java</p>
  
  <pre><code>public class HelpWebView extends WebView {
  
      private GestureDetector gestureDetector;
      private AtomicBoolean mPreventAction = new AtomicBoolean(false);
      private AtomicLong mPreventActionTime = new AtomicLong(0);
  
      public HelpWebView(Context context) {
          super(context);
          gestureDetector = new GestureDetector(context, new GestureListener());
      }
  
      public HelpWebView(Context context, AttributeSet attrs) {
          super(context, attrs);
          gestureDetector = new GestureDetector(context, new GestureListener());
      }
  
      public HelpWebView(Context context, AttributeSet attrs, int defStyle) {
          super(context, attrs, defStyle);
          gestureDetector = new GestureDetector(context, new GestureListener());
      }
  
      public HelpWebView(Context context, AttributeSet attrs, int defStyle, boolean privateBrowsing) {
          super(context, attrs, defStyle, privateBrowsing);
          gestureDetector = new GestureDetector(context, new GestureListener());
      }
  
      @Override
      public boolean onTouchEvent(MotionEvent event) {
          int index = (event.getAction() &amp; MotionEvent.ACTION_POINTER_INDEX_MASK) &gt;&gt; MotionEvent.ACTION_POINTER_INDEX_SHIFT;
          int pointId = event.getPointerId(index);
  
          // just use one(first) finger, prevent double tap with two and more fingers
          if (pointId == 0){
              gestureDetector.onTouchEvent(event);
  
              if (mPreventAction.get()){
                  if (System.currentTimeMillis() - mPreventActionTime.get() &gt; ViewConfiguration.getDoubleTapTimeout()){
                      mPreventAction.set(false);
                  } else {
                      return true;
                  }
              }
  
              return super.onTouchEvent(event);
          } else {
              return true;
          }
      }
  
      private class GestureListener extends GestureDetector.SimpleOnGestureListener {
          @Override
          public boolean onDoubleTap(MotionEvent e) {
              mPreventAction.set(true);
              mPreventActionTime.set(System.currentTimeMillis());
              return true;
          }
          @Override
          public boolean onDoubleTapEvent(MotionEvent e) {
              mPreventAction.set(true);
              mPreventActionTime.set(System.currentTimeMillis());
              return true;
          }
      }
  }
  </code></pre>