Example usage for android.webkit WebSettings setLoadWithOverviewMode

List of usage examples for android.webkit WebSettings setLoadWithOverviewMode

Introduction

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

Prototype

public abstract void setLoadWithOverviewMode(boolean overview);

Source Link

Document

Sets whether the WebView loads pages in overview mode, that is, zooms out the content to fit on screen by width.

Usage

From source file:shreckye.scu.youth.HomepageFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_homepage, container, false);

    final SwipeRefreshLayout swipeRefreshLayout = (SwipeRefreshLayout) view
            .findViewById(R.id.swipe_refresh_layout);
    AppUtil.setupSwipeRefreshLayoutColors(swipeRefreshLayout);

    homepageWebView = (WebView) view.findViewById(R.id.homepage_web_view);
    WebSettings webSettings = homepageWebView.getSettings();
    webSettings.setLoadWithOverviewMode(true);
    webSettings.setUseWideViewPort(true);
    webSettings.setJavaScriptEnabled(true);

    homepageWebView.loadUrl(HOMEPAGE_URL);
    homepageWebView.setWebViewClient(new WebViewClient() {
        @Override//from  ww w.ja  va 2  s  . com
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            swipeRefreshLayout.setRefreshing(true);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            swipeRefreshLayout.setRefreshing(false);
        }
    });

    swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            refreshAsync();
        }
    });

    FloatingActionButton fab = (FloatingActionButton) view.findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            AppUtil.openWebPageAndShowSnackbarIfFail(HomepageFragment.this, HOMEPAGE_URL, getView());
        }
    });

    return view;
}

From source file:com.prey.activities.PanelWebActivity.java

@Override
public void onResume() {
    super.onResume();
    WebSettings settings = myWebView.getSettings();
    settings.setUseWideViewPort(true);//  w  w  w. j a v  a 2 s . co  m
    settings.setLoadWithOverviewMode(true);
    settings.setJavaScriptEnabled(true);
    myWebView.setVerticalScrollBarEnabled(false);
    myWebView.setHorizontalScrollBarEnabled(false);
    myWebView.setWebChromeClient(new WebChromeClient() {
        public void onProgressChanged(WebView view, int progress) {
            activity.setTitle("Loading...");
            activity.setProgress(progress * 100);

            if (progress == 100)
                activity.setTitle(R.string.app_name);
        }

    });
    myWebView.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageFinished(WebView view, String url) {
            PreyLogger.d("Finished:" + url);
            super.onPageFinished(view, url);
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            PreyLogger.d("Started:" + url);
            super.onPageStarted(view, url, favicon);
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            PreyLogger.d("OverrideUrl:" + url);
            return super.shouldOverrideUrlLoading(view, url);
        }
    });

    String url = PreyConfig.getPreyConfig(getApplicationContext()).getPreyPanelJwt();

    String postData = "token=" + PreyConfig.getPreyConfig(getApplicationContext()).getTokenJwt();
    ;

    byte[] postByte = EncodingUtils.getBytes(postData, "BASE64");
    myWebView.postUrl(url, postByte);
}

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

/**
 * ?webview// w  ww  .  java2  s . c om
 */
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:io.github.hidroh.materialistic.WebFragment.java

@SuppressLint("SetJavaScriptEnabled")
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void setWebViewSettings(WebSettings webSettings) {
    ItemSyncAdapter.enableCache(getActivity(), webSettings);
    webSettings.setLoadWithOverviewMode(true);
    webSettings.setUseWideViewPort(true);
    webSettings.setBuiltInZoomControls(true);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        webSettings.setDisplayZoomControls(false);
    }/*  w  ww.  j a v  a2s.co  m*/
}

From source file:com.johnny.gank.ui.activity.WebviewActivity.java

private void setUpWebView() {
    WebSettings settings = vWebView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setLoadWithOverviewMode(true);
    vWebView.setWebViewClient(new WebViewClient() {
        @Override/*from www  . jav a  2s .  co  m*/
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
            vRefreshLayout.setRefreshing(true);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            vRefreshLayout.setRefreshing(false);
        }

        @Override
        public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
            super.onReceivedError(view, request, error);
            vRefreshLayout.setRefreshing(false);
        }
    });
    vWebView.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            super.onProgressChanged(view, newProgress);
            if (newProgress >= 80) {
                vRefreshLayout.setRefreshing(false);
            }
        }
    });
}

From source file:com.rickendirk.rsgwijzigingen.WebFragment.java

@Nullable
@Override/*ww  w  .  j  av a 2  s.  c om*/
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable final Bundle savedInstanceState) {

    View mainView = inflater.inflate(R.layout.fragment_web, container, false);
    if (savedInstanceState != null) {
        is1eKeerGenegeerd = true;
    }
    progressBar = (ProgressBar) getActivity().findViewById(R.id.progressBar);

    webView = (NestedWebView) mainView.findViewById(R.id.webView);
    webView.setNestedScrollingEnabled(true);
    WebSettings webSettings = webView.getSettings();
    webSettings.setBuiltInZoomControls(true);
    webSettings.setDisplayZoomControls(false);
    webSettings.setLoadWithOverviewMode(true);
    webSettings.setUseWideViewPort(true);
    webView.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            isLoading = true;
            isFinished = false;
            progressBar.setVisibility(View.VISIBLE);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            isFinished = true;
            isLoading = false;
            //Ondestaande if voorkomt weergeven "pagina is vernieuwd" bij orintatie-verandering
            if (is1eKeerGenegeerd) {
                is1eKeerGenegeerd = false;
            } else
                Toast.makeText(getActivity(), "Pagina is vernieuwd", Toast.LENGTH_LONG).show();
            progressBar.setVisibility(View.GONE);
            swipeLayout.setRefreshing(false);
        }
    });
    webView.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            progressBar.setProgress(newProgress);
            super.onProgressChanged(view, newProgress);
        }
    });
    swipeLayout = (SwipeRefreshLayout) mainView.findViewById(R.id.swipeLayout);
    swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            refresh();
        }
    });
    swipeLayout.setColorSchemeResources(R.color.gmailRood, R.color.orange, R.color.lighter_blue, R.color.green);

    setRetainInstance(true);
    return mainView;

}

From source file:li.klass.fhem.fragments.AbstractWebViewFragment.java

@SuppressLint("SetJavaScriptEnabled")
@Override/*from   w ww.j  a  v  a2  s  .  c  o  m*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = super.onCreateView(inflater, container, savedInstanceState);
    if (view != null)
        return view;

    view = inflater.inflate(R.layout.webview, container, false);
    assert view != null;

    final WebView webView = (WebView) view.findViewById(R.id.webView);

    WebSettings settings = webView.getSettings();
    settings.setUseWideViewPort(true);
    settings.setLoadWithOverviewMode(true);
    settings.setJavaScriptEnabled(true);
    settings.setBuiltInZoomControls(true);

    final ProgressDialog progressDialog = new ProgressDialog(getActivity());
    progressDialog.setMessage(getResources().getString(R.string.loading));

    webView.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            super.onProgressChanged(view, newProgress);
            if (newProgress < 100) {
                progressDialog.setProgress(newProgress);
                progressDialog.show();
            } else {
                progressDialog.hide();
            }
        }
    });

    webView.setWebViewClient(new WebViewClient() {
        @Override
        public void onReceivedSslError(WebView view, @NotNull SslErrorHandler handler, SslError error) {
            handler.proceed();
        }

        @SuppressWarnings("ConstantConditions")
        @Override
        public void onReceivedHttpAuthRequest(WebView view, @NotNull HttpAuthHandler handler, String host,
                String realm) {
            FHEMServerSpec currentServer = connectionService.getCurrentServer(getActivity());
            String url = currentServer.getUrl();
            String alternativeUrl = trimToNull(currentServer.getAlternateUrl());
            try {

                String fhemUrlHost = new URL(url).getHost();
                String alternativeUrlHost = alternativeUrl == null ? null : new URL(alternativeUrl).getHost();
                String username = currentServer.getUsername();
                String password = currentServer.getPassword();

                if (host.startsWith(fhemUrlHost)
                        || (alternativeUrlHost != null && host.startsWith(alternativeUrlHost))) {
                    handler.proceed(username, password);
                } else {
                    handler.cancel();

                    Intent intent = new Intent(Actions.SHOW_TOAST);
                    intent.putExtra(BundleExtraKeys.STRING_ID, R.string.error_authentication);
                    getActivity().sendBroadcast(intent);
                }

            } catch (MalformedURLException e) {
                Intent intent = new Intent(Actions.SHOW_TOAST);
                intent.putExtra(BundleExtraKeys.STRING_ID, R.string.error_host_connection);
                getActivity().sendBroadcast(intent);
                LOG.error("malformed URL: " + url, e);

                handler.cancel();
            }
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            if ("about:blank".equalsIgnoreCase(url)) {
                Optional<String> alternativeUrl = getAlternateLoadUrl();
                if (alternativeUrl.isPresent()) {
                    webView.loadUrl(alternativeUrl.get());
                }
            } else {
                onPageLoadFinishedCallback(view, url);
            }
        }
    });

    return view;
}

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);/*from w  ww.j  av a2  s  . c  o m*/
    settings.setUseWideViewPort(true);

    // 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:it.rignanese.leo.slimfacebook.PictureActivity.java

private void SetupPictureWebView() {
    webViewPicture = (MyAdvancedWebView) findViewById(R.id.webViewPicture);
    webViewPicture.setListener(this, this);

    //  webViewPicture.setDesktopMode(true);

    //webViewPicture.requestFocus(View.F);
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);//remove the keyboard issue

    WebSettings settings = webViewPicture.getSettings();

    settings.setBuiltInZoomControls(true);
    settings.setUseWideViewPort(true);//  ww w .j  a va2s.  c  o m
    settings.setJavaScriptEnabled(true);
    settings.setLoadWithOverviewMode(true);

    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
        // Hide the zoom controls for HONEYCOMB+
        settings.setDisplayZoomControls(false);
    }
}

From source file:com.github.snowdream.android.widget.NotFoundWebView.java

@SuppressLint({ "SetJavaScriptEnabled", "NewApi" })
private void init(Context context, AttributeSet attrs, int defStyle) {
    if (context == null) {
        return;/*from w w  w .ja va2  s  .  c o m*/
    }

    // enable JavaScript
    WebSettings settings = this.getSettings();
    settings.setJavaScriptEnabled(true);

    settings.setSupportZoom(true);
    settings.setBuiltInZoomControls(true);
    settings.setLoadWithOverviewMode(true);
    settings.setDefaultZoom(ZoomDensity.FAR);

    //settings.setUseWideViewPort(true);
    //webView.setInitialScale(1);

    // init attrs
    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.CustomWebView);

    try {
        int type = a.getInteger(R.styleable.CustomWebView_type, 0);
        switch (type) {
        case 0:
            script = context.getString(R.string.html_notfound);
            break;
        case 1:
            script = context.getString(R.string.html_qq_narrow);
            break;
        case 2:
            script = context.getString(R.string.html_qq_narrow);
            break;
        case 3:
            script = context.getString(R.string.html_qq_wide);
            break;
        case 4:
            script = context.getString(R.string.html_yibo);
            break;
        default:
            script = a.getString(R.styleable.CustomWebView_script);
            break;
        }
    } finally {
        a.recycle();
    }
}