Example usage for android.webkit WebSettings setSupportZoom

List of usage examples for android.webkit WebSettings setSupportZoom

Introduction

In this page you can find the example usage for android.webkit WebSettings setSupportZoom.

Prototype

public abstract void setSupportZoom(boolean support);

Source Link

Document

Sets whether the WebView should support zooming using its on-screen zoom controls and gestures.

Usage

From source file:com.clutch.ClutchView.java

@SuppressLint("SetJavaScriptEnabled")
private void clutchInit() {
    loading = new ProgressDialog(this.getContext());
    loading.hide();// w  w w .  j ava 2  s .  c o m

    this.setWebChromeClient(new WebChromeClient() {
        // TODO: Clutch Debug Toolbar
        @Override
        public boolean onJsPrompt(WebView view, String url, String message, String defaultValue,
                JsPromptResult result) {
            if (!"methodCalled".equals(defaultValue)) {
                return false;
            }
            JSONObject jsonMessage = null;
            String methodName = null;
            String callbackId = null;
            JSONObject params = null;
            try {
                jsonMessage = new JSONObject(message);
                methodName = jsonMessage.getString("method");
                callbackId = jsonMessage.getString("callbackNum");
                params = jsonMessage.getJSONObject("args");
            } catch (JSONException e) {
                Log.e(TAG, "Could not decode JSON: " + message);
                result.cancel();
                return true;
            }
            if (methodName.equals("clutch.loading.begin")) {
                String loadingMessage = params.optString("text");
                if (loadingMessage == null) {
                    loadingMessage = "Loading...";
                } else if ("null".equals(loadingMessage)) {
                    loadingMessage = "Loading...";
                }
                loading.setMessage(loadingMessage);
                loading.show();
            } else if (methodName.equals("clutch.loading.end")) {
                loading.hide();
            }
            ClutchCallback callback = null;
            if (!"0".equals(callbackId)) {
                callback = new ClutchCallback(ClutchView.this, callbackId);
            }
            dispatcher.methodCalled(methodName, params, callback);
            result.cancel();
            return true;
        }
    });

    ClutchSync.addClutchView(this);
    WebSettings settings = this.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setSupportZoom(true);
    settings.setAppCacheEnabled(false);
}

From source file:com.github.snowdream.android.app.books.BookFragment.java

private void initUI(View rootview) {
    webView = (WebView) rootview.findViewById(R.id.webView);
    //        progressbar = (SmoothProgressBar) rootview.findViewById(R.id.progressbar);
    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setDomStorageEnabled(true);
    webSettings.setAllowFileAccess(true);
    webSettings.setSupportZoom(true);
    webSettings.setBuiltInZoomControls(true);
    webSettings.setUseWideViewPort(true);
    String appCachePath = getActivity().getApplicationContext().getCacheDir().getAbsolutePath();
    webSettings.setAppCachePath(appCachePath);
    webSettings.setAppCacheEnabled(true);

    webView.setWebViewClient(new WebViewClient() {
        @Override//from   ww w  .  java  2  s . c  o  m
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
            //                progressbar.setVisibility(View.VISIBLE);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            //                progressbar.setVisibility(View.INVISIBLE);
        }

        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            super.onReceivedError(view, errorCode, description, failingUrl);
            //                progressbar.setVisibility(View.INVISIBLE);
        }
    });
    webView.setWebChromeClient(new WebChromeClient() {
        @Override
        public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
            return super.onJsAlert(view, url, message, result);
        }
    });

    // The "loadAdOnCreate" and "testDevices" XML attributes no longer available.
    AdView adView = (AdView) rootview.findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
            .addTestDevice(TEST_DEVICE_ID).build();
    adView.loadAd(adRequest);

    getView().setFocusableInTouchMode(true);
    getView().setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (webView.canGoBack() && keyCode == KeyEvent.KEYCODE_BACK) {
                webView.goBack();

                return true;
            }
            return false;
        }
    });
}

From source file:com.vikingbrain.dmt.view.RemoteControlActivity.java

private void configureWebView(WebView webView, WebChromeClient webChromeClient,
        CustomWebViewClient customWebViewClient) {
    //Set the properties      
    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setSupportZoom(true); //Zoom Control on web (You don't need this if ROM supports Multi-Touch       
    webSettings.setBuiltInZoomControls(true); //Enable Multitouch if supported by ROM
    webSettings.setDomStorageEnabled(true);
    webSettings.setPluginsEnabled(true);
    webSettings.setUseWideViewPort(true); //normal viewport (such as a normal desktop browser)

    webView.setWebChromeClient(webChromeClient);
    webView.setWebViewClient(customWebViewClient);
}

From source file:com.pixate.freestyle.viewdemo.ViewDetailFragment.java

@SuppressLint("SetJavaScriptEnabled")
@Override/*  w  ww. j  a v  a2s  .co m*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View rootView = inflater.inflate(R.layout.fragment_view_detail, container, false);

    if (mItem != null) {
        // set the views
        ViewSample viewSample = mItem.getViewSample();
        final ViewGroup viewsHolder = (ViewGroup) rootView.findViewById(R.id.holder);
        viewSample.createViews(getActivity(), viewsHolder);

        // load the CSS styling for the sample
        String css = ViewsData.getCSS(getActivity(), mItem);

        // Set up syntax highlighting
        WebView cssView = (WebView) rootView.findViewById(R.id.css_style);
        WebSettings s = cssView.getSettings();
        s.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);
        s.setUseWideViewPort(false);
        s.setAllowFileAccess(true);
        s.setBuiltInZoomControls(true);
        s.setSupportZoom(true);
        s.setSupportMultipleWindows(false);
        s.setJavaScriptEnabled(true);

        StringBuilder contentString = new StringBuilder();
        contentString.append("<html><head>");
        contentString.append(
                "<link href='file:///android_asset/prettify/prettify.css' rel='stylesheet' type='text/css'/> ");
        contentString.append(
                "<script src='file:///android_asset/prettify/prettify.js' type='text/javascript'></script> ");
        contentString.append(
                "<script src='file:///android_asset/prettify/lang-css.js' type='text/javascript'></script> ");
        contentString.append("</head><body onload='prettyPrint()'><code class='prettyprint lang-css'>");
        contentString.append(TextUtils.htmlEncode(css).replaceAll("\n", "<br>").replaceAll(" ", "&nbsp;")
                .replaceAll("\t", "&nbsp;&nbsp;"));
        contentString.append("</code> </html> ");
        cssView.getSettings().setUseWideViewPort(true);
        cssView.loadDataWithBaseURL("file:///android_asset/prettify/", contentString.toString(), "text/html",
                StringUtil.EMPTY, StringUtil.EMPTY);

        // to aid in styling the css text shows in the textview, set its
        // ID. Eventually will not be needed.
        if (!"css-style".equals(PixateFreestyle.getStyleId(cssView))) {
            PixateFreestyle.setStyleId(cssView, "css-style", true);
        }

        // Style
        viewSample.style(css);
    }

    return rootView;
}

From source file:com.btmura.android.reddit.app.LoginFragment.java

private void setupWebView() {
    // Clear reddit cookie to present a fresh login form.
    CookieManager.getInstance().setCookie(".reddit.com", "reddit_session=");

    WebSettings settings = webView.getSettings();
    settings.setBuiltInZoomControls(true);
    settings.setDisplayZoomControls(false);
    settings.setLoadWithOverviewMode(true);
    settings.setSupportZoom(true);
    settings.setUseWideViewPort(true);//  ww w .  j  ava 2s  .c o  m

    // Don't save usernames entered into the login forms.
    settings.setSaveFormData(false);

    webView.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            if (progressBar != null) {
                progressBar.setVisibility(View.VISIBLE);
            }
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            if (progressBar != null) {
                progressBar.setVisibility(View.GONE);
            }
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            // WebView will show an unrecognized scheme error unless we intercept
            // the OAuth callback URL and fire off an intent instead.
            return url != null && url.startsWith(Urls.OAUTH_REDIRECT_URL) && handleOAuthRedirectUrl(url);
        }
    });

    webView.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            if (progressBar != null) {
                progressBar.setProgress(newProgress);
            }
        }
    });
}

From source file:org.thanatos.flowgeek.ui.activity.DetailActivity.java

/**
 * init view/*from  w w w .ja v a 2  s  .com*/
 */
private void initView() {
    // init WebView
    WebSettings settings = mWebView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setSupportZoom(false);

    btnComment.setClickable(false);

    ScrollerBottomLayoutDelegation.delegation(mNestedScroller, mBottomLayout);
}

From source file:com.cihon.androidrestart_keven.activity.WebViewActivity.java

/**
 * ?webview/* w  w w  .  j  av a 2 s . c o m*/
 */
public void initWebView() {
    MyWebViewClient webViewClient = new MyWebViewClient();
    mWebView.setWebViewClient(webViewClient);
    WebSettings webSettings = mWebView.getSettings();

    //??
    webSettings.setLoadWithOverviewMode(true);
    //?webview?
    webSettings.setUseWideViewPort(true);
    //??
    webSettings.setBuiltInZoomControls(true);
    webSettings.setSupportZoom(true);
    webSettings.setJavaScriptEnabled(true);

    //        mWebView.loadUrl("http://webservice.cihon.cn/onStarActive1/reupload.html");
    mWebView.loadUrl("http://123.57.60.91/onStar3/vehicle-License.html");
    //        mWebView.loadUrl("http://wxpay.wxutil.com/mch/pay/h5.v2.php");

    //        jsjava
    mWebView.addJavascriptInterface(new JsInterface(this), "demo");
}

From source file:cn.zy.ef.fragment.WebViewFragment.java

protected void configureWebView(WebSettings settings) {
    settings.setJavaScriptCanOpenWindowsAutomatically(true);//js??window.open()false
    settings.setJavaScriptEnabled(true);//??jsfalsetrue????XSS?
    settings.setSupportZoom(true);//??true
    settings.setBuiltInZoomControls(false);//?false
    settings.setUseWideViewPort(true);//???
    settings.setLoadWithOverviewMode(true);//setUseWideViewPort(true)
    settings.setAppCacheEnabled(true);//?
    settings.setDomStorageEnabled(true);//DOM Storage
    settings.setCacheMode(WebSettings.LOAD_DEFAULT);
}

From source file:com.gh4a.FileViewerActivity.java

private void fillData(boolean highlight) {
    String data = new String(EncodingUtils.fromBase64(mContent.getContent()));
    WebView webView = (WebView) findViewById(R.id.web_view);

    WebSettings s = webView.getSettings();
    s.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);
    s.setAllowFileAccess(true);/*from w  w  w  .j  a v a 2  s. c  om*/
    s.setBuiltInZoomControls(true);
    s.setLightTouchEnabled(true);
    s.setLoadsImagesAutomatically(true);
    s.setPluginsEnabled(false);
    s.setSupportZoom(true);
    s.setSupportMultipleWindows(true);
    s.setJavaScriptEnabled(true);
    s.setUseWideViewPort(true);

    webView.setWebViewClient(webViewClient);
    if (FileUtils.isImage(mName)) {
        String htmlImage = StringUtils.highlightImage(
                "https://github.com/" + mRepoOwner + "/" + mRepoName + "/raw/" + mRef + "/" + mPath);
        webView.loadDataWithBaseURL("file:///android_asset/", htmlImage, "text/html", "utf-8", "");
    } else {
        String highlighted = StringUtils.highlightSyntax(data, highlight, mName);
        webView.loadDataWithBaseURL("file:///android_asset/", highlighted, "text/html", "utf-8", "");
    }
}

From source file:com.rfo.basic.Web.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    Log.v(LOGTAG, "onCreate");
    super.onCreate(savedInstanceState);
    ContextManager cm = Basic.getContextManager();
    cm.registerContext(ContextManager.ACTIVITY_WEB, this);
    cm.setCurrent(ContextManager.ACTIVITY_WEB);

    setContentView(R.layout.web);/*from  ww w.j  a v  a2 s . co m*/
    View v = findViewById(R.id.web_engine);

    Intent intent = getIntent();
    int showStatusBar = intent.getIntExtra(EXTRA_SHOW_STATUSBAR, 0);
    int orientation = intent.getIntExtra(EXTRA_ORIENTATION, -1);

    showStatusBar = (showStatusBar == 0) ? WindowManager.LayoutParams.FLAG_FULLSCREEN // do not show status bar
            : WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN; // show status bar
    getWindow().setFlags(showStatusBar, showStatusBar);

    setOrientation(orientation);

    engine = (WebView) v;

    WebSettings webSettings = engine.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setBuiltInZoomControls(true);
    webSettings.setSupportZoom(true);
    webSettings.setAppCacheEnabled(true);
    webSettings.setDatabaseEnabled(true);
    webSettings.setDomStorageEnabled(true);
    webSettings.setAllowFileAccess(true);
    webSettings.setGeolocationEnabled(true);
    webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);

    engine.addJavascriptInterface(new JavaScriptInterface(), "Android");

    engine.setWebViewClient(new MyWebViewClient());

    aWebView = new TheWebView(this);

    engine.setWebChromeClient(new WebChromeClient() {
        @Override
        public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
            //Required functionality here
            return super.onJsAlert(view, url, message, result);
        }
    });

}