Search in sources :

Example 51 with WebSettings

use of android.webkit.WebSettings in project mailim by zengsn.

the class EmailActivity method setViewContex.

private void setViewContex() {
    if (!email.isEmpty()) {
        // Toast.makeText(app.getApplicationContext(),"not null",Toast.LENGTH_SHORT).show();
        fromaddr.setText(email.getEmailAddr());
        // time.setText(email.getSendDate().toString());
        time.setText(DateUtil.DateToString(email.getSendDate()));
        subject.setText(email.getSubject());
        WebSettings settings = text.getSettings();
        // 支持javascript
        settings.setJavaScriptEnabled(true);
        // 设置可以支持缩放
        settings.setSupportZoom(true);
        // 设置出现缩放工具
        settings.setBuiltInZoomControls(true);
        // 扩大比例的缩放
        settings.setUseWideViewPort(true);
        // 自适应屏幕
        settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        settings.setLoadWithOverviewMode(true);
        if (email.isMultipart()) {
            settings.setSupportZoom(true);
            settings.setTextZoom(400);
        }
        text.loadDataWithBaseURL(null, email.getContent().replace("\n", "<br>"), "text/html", "UTF-8", null);
    }
}
Also used : WebSettings(android.webkit.WebSettings)

Example 52 with WebSettings

use of android.webkit.WebSettings in project BlogSource by TeachCourse.

the class JSWebViewActivity method initView.

/**
 * 初始化布局控件
 */
@SuppressLint("JavascriptInterface")
private void initView() {
    initButton(getWindow().getDecorView());
    mWebView = (WebView) findViewById(R.id.webView);
    mButton = (Button) findViewById(R.id.modify_btn);
    WebSettings webSettings = mWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setDefaultTextEncodingName("utf-8");
    webSettings.setDomStorageEnabled(true);
    /**
     * Java Object与JavaScript交互
     */
    mWebView.addJavascriptInterface(this, "myObj");
    // mWebView.loadUrl("file:///android_asset/js_interative.html");
    mWebView.loadUrl("file:///android_asset/launcher_myapp.html");
    /**
     * 验证为什么application ID不同于package name提示ClassNotFoundException
     */
    String callingApp = getPackageManager().getNameForUid(Binder.getCallingUid());
    // mWebView.loadUrl("file:///android_res/raw/note.html");
    LogUtil.d(callingApp);
    LogUtil.d(getPackageName());
    /**
     * JavaScript与Java Object交互
     */
    mButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mWebView.loadUrl("javascript:modifyContent()");
            isModify = !isModify;
            Toast.makeText(JSWebViewActivity.this, "" + isModify, Toast.LENGTH_SHORT).show();
            startBrowser();
        }
    });
}
Also used : WebSettings(android.webkit.WebSettings) View(android.view.View) WebView(android.webkit.WebView) SuppressLint(android.annotation.SuppressLint)

Example 53 with WebSettings

use of android.webkit.WebSettings in project wcs-android-sdk-samples by flashphoner.

the class WebViewActivity method setWebViewSettings.

private void setWebViewSettings(WebView webView) {
    WebSettings settings = webView.getSettings();
    // Enable Javascript
    settings.setJavaScriptEnabled(true);
    // Use WideViewport and Zoom out if there is no viewport defined
    settings.setUseWideViewPort(true);
    settings.setLoadWithOverviewMode(true);
    // Enable pinch to zoom without the zoom buttons
    settings.setBuiltInZoomControls(true);
    // Allow use of Local Storage
    settings.setDomStorageEnabled(true);
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
        // Hide the zoom controls for HONEYCOMB+
        settings.setDisplayZoomControls(false);
    }
    // Enable remote debugging via chrome://inspect
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        WebView.setWebContentsDebuggingEnabled(true);
    }
    webView.setWebViewClient(new WebViewClient() {

        @Override
        public void onReceivedSslError(WebView view, final SslErrorHandler handler, SslError error) {
            final AlertDialog.Builder builder = new AlertDialog.Builder(view.getContext());
            String message = "SSL Certificate error.";
            switch(error.getPrimaryError()) {
                case SslError.SSL_UNTRUSTED:
                    message = "The certificate authority is not trusted";
                    break;
                case SslError.SSL_EXPIRED:
                    message = "The certificate has expired";
                    break;
                case SslError.SSL_NOTYETVALID:
                    message = "The certificate is not yet valid.";
                    break;
                case SslError.SSL_IDMISMATCH:
                    message = "The cerificate ID is mismatch";
                    break;
                case SslError.SSL_DATE_INVALID:
                    message = "The certificate date is invalid";
                    break;
                case SslError.SSL_INVALID:
                    message = "The certificate is invalid";
                    break;
            }
            builder.setTitle("SSL Cerificate Error");
            builder.setMessage(message);
            builder.setPositiveButton("Continue", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    handler.proceed();
                }
            });
            builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    handler.cancel();
                }
            });
            Log.d(TAG, "onReceivedSslError " + message);
            final AlertDialog dialog = builder.create();
            dialog.show();
        }
    });
}
Also used : AlertDialog(android.app.AlertDialog) SslErrorHandler(android.webkit.SslErrorHandler) DialogInterface(android.content.DialogInterface) WebSettings(android.webkit.WebSettings) SslError(android.net.http.SslError) WebView(android.webkit.WebView) WebViewClient(android.webkit.WebViewClient)

Example 54 with WebSettings

use of android.webkit.WebSettings in project LivingInCampus by DulCoder.

the class WebInfoActivity method setWebView.

/**
 * 设置WebView内容
 * @param url
 */
private void setWebView(String url) {
    wb_banner_info_more = (WebView) findViewById(R.id.wb_banner_info_more);
    if (url != null) {
        wb_banner_info_more.loadUrl(url);
        // 覆盖WebView 默认使用第三方或系统默认浏览器打开网页的行为,使网页 用 WebView 打开
        wb_banner_info_more.setWebViewClient(new WebViewClient() {

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                // 返回值是 true的时候控制去 WebView 打开,为 false 调用系统 浏览器或第三方浏览器
                view.loadUrl(url);
                return true;
            }
        });
        // 设置支持JavaScript
        WebSettings settings = wb_banner_info_more.getSettings();
        settings.setJavaScriptEnabled(true);
        // 设置大小适应屏幕
        settings.setUseWideViewPort(true);
        settings.setLoadWithOverviewMode(true);
        // 设置字体大小
        settings.setSupportZoom(true);
        settings.setTextZoom(230);
        // 优先使用缓存
        wb_banner_info_more.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
    }
}
Also used : WebSettings(android.webkit.WebSettings) WebView(android.webkit.WebView) WebViewClient(android.webkit.WebViewClient)

Example 55 with WebSettings

use of android.webkit.WebSettings in project Auto.js by hyb1996.

the class JsWebView method init.

private void init() {
    WebSettings settings = getSettings();
    settings.setUseWideViewPort(true);
    settings.setBuiltInZoomControls(true);
    settings.setLoadWithOverviewMode(true);
    settings.setJavaScriptEnabled(true);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    settings.setDomStorageEnabled(true);
    settings.setDisplayZoomControls(false);
    setWebViewClient(new WebViewClient());
    setWebChromeClient(new WebChromeClient());
}
Also used : WebSettings(android.webkit.WebSettings) WebChromeClient(android.webkit.WebChromeClient) WebViewClient(android.webkit.WebViewClient)

Aggregations

WebSettings (android.webkit.WebSettings)213 WebView (android.webkit.WebView)110 WebViewClient (android.webkit.WebViewClient)77 SuppressLint (android.annotation.SuppressLint)52 WebChromeClient (android.webkit.WebChromeClient)49 View (android.view.View)38 Intent (android.content.Intent)32 Bitmap (android.graphics.Bitmap)23 WebResourceRequest (android.webkit.WebResourceRequest)15 KeyEvent (android.view.KeyEvent)11 JsResult (android.webkit.JsResult)11 LinearLayout (android.widget.LinearLayout)11 WebResourceError (android.webkit.WebResourceError)10 CookieManager (android.webkit.CookieManager)9 TextView (android.widget.TextView)9 SslError (android.net.http.SslError)8 SslErrorHandler (android.webkit.SslErrorHandler)8 WebResourceResponse (android.webkit.WebResourceResponse)8 ProgressDialog (android.app.ProgressDialog)7 Toolbar (android.support.v7.widget.Toolbar)7