Search in sources :

Example 86 with WebSettings

use of android.webkit.WebSettings in project Douya by DreaminginCodeZH.

the class WebViewActivity method updateUserAgent.

private void updateUserAgent() {
    boolean requestDesktopSite = Settings.REQUEST_DESKTOP_SITE_IN_WEBVIEW.getValue();
    WebSettings webSettings = mWebView.getSettings();
    String oldUserAgent = webSettings.getUserAgentString();
    boolean changed = false;
    if (requestDesktopSite && !TextUtils.equals(oldUserAgent, mDesktopUserAgent)) {
        webSettings.setUserAgentString(mDesktopUserAgent);
        changed = true;
    } else if (!requestDesktopSite && !TextUtils.equals(oldUserAgent, mDefaultUserAgent)) {
        // This will requrie API level 17.
        // webSettings.setUserAgentString(WebSettings.getDefaultUserAgent(this));
        webSettings.setUserAgentString(mDefaultUserAgent);
        changed = true;
    }
    String url = mWebView.getUrl();
    if (!TextUtils.isEmpty(url) && changed) {
        if (requestDesktopSite) {
            String doubanDesktopSiteUrl = getDoubanDesktopSiteUrl(url);
            if (!TextUtils.equals(url, doubanDesktopSiteUrl)) {
                mWebView.loadUrl(doubanDesktopSiteUrl);
            } else {
                mWebView.reload();
            }
        } else {
            mWebView.reload();
        }
    }
}
Also used : WebSettings(android.webkit.WebSettings)

Example 87 with WebSettings

use of android.webkit.WebSettings in project KJFrameForAndroid by kymjs.

the class MyBlogBrowser method initWebView.

/**
 * 初始化浏览器设置信息
 */
private void initWebView() {
    WebSettings webSettings = mWebView.getSettings();
    // 启用支持javascript
    webSettings.setJavaScriptEnabled(false);
    // 优先使用缓存
    webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
    // 可以访问文件
    webSettings.setAllowFileAccess(true);
    // 支持缩放
    webSettings.setBuiltInZoomControls(true);
    if (android.os.Build.VERSION.SDK_INT >= 11) {
        // 支持缩放
        webSettings.setDisplayZoomControls(false);
    }
    mWebView.setWebViewClient(new MyWebViewClient());
    mWebView.setWebChromeClient(new MyWebChromeClient());
}
Also used : WebSettings(android.webkit.WebSettings)

Example 88 with WebSettings

use of android.webkit.WebSettings in project KJFrameForAndroid by kymjs.

the class UIHelper method initWebView.

@SuppressLint({ "JavascriptInterface", "SetJavaScriptEnabled" })
public static void initWebView(WebView webView) {
    WebSettings settings = webView.getSettings();
    settings.setDefaultFontSize(15);
    settings.setJavaScriptEnabled(true);
    settings.setSupportZoom(true);
    settings.setBuiltInZoomControls(true);
    int sysVersion = Build.VERSION.SDK_INT;
    if (sysVersion >= 11) {
        settings.setDisplayZoomControls(false);
    } else {
        ZoomButtonsController zbc = new ZoomButtonsController(webView);
        zbc.getZoomControls().setVisibility(View.GONE);
    }
    webView.setWebViewClient(UIHelper.getWebViewClient());
}
Also used : WebSettings(android.webkit.WebSettings) ZoomButtonsController(android.widget.ZoomButtonsController) SuppressLint(android.annotation.SuppressLint) SuppressLint(android.annotation.SuppressLint)

Example 89 with WebSettings

use of android.webkit.WebSettings in project SmartAndroidSource by jaychou2012.

the class WebImage method disableZoomControl.

private static void disableZoomControl(WebView wv) {
    if (android.os.Build.VERSION.SDK_INT < 11)
        return;
    WebSettings ws = wv.getSettings();
    AQUtility.invokeHandler(ws, "setDisplayZoomControls", false, false, new Class[] { boolean.class }, false);
}
Also used : WebSettings(android.webkit.WebSettings)

Example 90 with WebSettings

use of android.webkit.WebSettings in project cordova-android by apache.

the class SystemWebViewEngine method initWebViewSettings.

@SuppressLint({ "NewApi", "SetJavaScriptEnabled" })
@SuppressWarnings("deprecation")
private void initWebViewSettings() {
    webView.setInitialScale(0);
    webView.setVerticalScrollBarEnabled(false);
    // Enable JavaScript
    final WebSettings settings = webView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);
    String manufacturer = android.os.Build.MANUFACTURER;
    LOG.d(TAG, "CordovaWebView is running on device made by: " + manufacturer);
    // We don't save any form data in the application
    // @todo remove when Cordova drop API level 26 support
    settings.setSaveFormData(false);
    if (preferences.getBoolean("AndroidInsecureFileModeEnabled", false)) {
        // These settings are deprecated and loading content via file:// URLs is generally discouraged,
        // but we allow this for compatibility reasons
        LOG.d(TAG, "Enabled insecure file access");
        settings.setAllowFileAccess(true);
        settings.setAllowUniversalAccessFromFileURLs(true);
    }
    settings.setMediaPlaybackRequiresUserGesture(false);
    // Enable database
    // We keep this disabled because we use or shim to get around DOM_EXCEPTION_ERROR_16
    String databasePath = webView.getContext().getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
    settings.setDatabaseEnabled(true);
    // Determine whether we're in debug or release mode, and turn on Debugging!
    ApplicationInfo appInfo = webView.getContext().getApplicationContext().getApplicationInfo();
    if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
        enableRemoteDebugging();
    }
    // @todo remove when Cordova drop API level 24 support
    settings.setGeolocationDatabasePath(databasePath);
    // Enable DOM storage
    settings.setDomStorageEnabled(true);
    // Enable built-in geolocation
    settings.setGeolocationEnabled(true);
    // Fix for CB-1405
    // Google issue 4641
    String defaultUserAgent = settings.getUserAgentString();
    // Fix for CB-3360
    String overrideUserAgent = preferences.getString("OverrideUserAgent", null);
    if (overrideUserAgent != null) {
        settings.setUserAgentString(overrideUserAgent);
    } else {
        String appendUserAgent = preferences.getString("AppendUserAgent", null);
        if (appendUserAgent != null) {
            settings.setUserAgentString(defaultUserAgent + " " + appendUserAgent);
        }
    }
    // End CB-3360
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
    if (this.receiver == null) {
        this.receiver = new BroadcastReceiver() {

            @Override
            public void onReceive(Context context, Intent intent) {
                settings.getUserAgentString();
            }
        };
        webView.getContext().registerReceiver(this.receiver, intentFilter);
    }
// end CB-1405
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) WebSettings(android.webkit.WebSettings) ApplicationInfo(android.content.pm.ApplicationInfo) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) SuppressLint(android.annotation.SuppressLint)

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