Search in sources :

Example 16 with WebSettings

use of android.webkit.WebSettings in project Lightning-Browser by anthonycr.

the class LightningView method initializeSettings.

/**
     * Initialize the settings of the WebView that are intrinsic to Lightning and cannot
     * be altered by the user. Distinguish between Incognito and Regular tabs here.
     */
@SuppressLint("NewApi")
private void initializeSettings() {
    if (mWebView == null) {
        return;
    }
    final WebSettings settings = mWebView.getSettings();
    if (API < Build.VERSION_CODES.JELLY_BEAN_MR2) {
        //noinspection deprecation
        settings.setAppCacheMaxSize(Long.MAX_VALUE);
    }
    if (API < Build.VERSION_CODES.JELLY_BEAN_MR1) {
        //noinspection deprecation
        settings.setEnableSmoothTransition(true);
    }
    if (API > Build.VERSION_CODES.JELLY_BEAN) {
        settings.setMediaPlaybackRequiresUserGesture(true);
    }
    if (API >= Build.VERSION_CODES.LOLLIPOP && !mIsIncognitoTab) {
        settings.setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
    } else if (API >= Build.VERSION_CODES.LOLLIPOP) {
        // We're in Incognito mode, reject
        settings.setMixedContentMode(WebSettings.MIXED_CONTENT_NEVER_ALLOW);
    }
    if (!mIsIncognitoTab) {
        settings.setDomStorageEnabled(true);
        settings.setAppCacheEnabled(true);
        settings.setCacheMode(WebSettings.LOAD_DEFAULT);
        settings.setDatabaseEnabled(true);
    } else {
        settings.setDomStorageEnabled(false);
        settings.setAppCacheEnabled(false);
        settings.setDatabaseEnabled(false);
        settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
    }
    settings.setSupportZoom(true);
    settings.setBuiltInZoomControls(true);
    settings.setDisplayZoomControls(false);
    settings.setAllowContentAccess(true);
    settings.setAllowFileAccess(true);
    if (API >= Build.VERSION_CODES.JELLY_BEAN) {
        settings.setAllowFileAccessFromFileURLs(false);
        settings.setAllowUniversalAccessFromFileURLs(false);
    }
    getPathObservable("appcache").subscribeOn(Schedulers.io()).observeOn(Schedulers.main()).subscribe(new SingleOnSubscribe<File>() {

        @Override
        public void onItem(@Nullable File item) {
            Preconditions.checkNonNull(item);
            settings.setAppCachePath(item.getPath());
        }
    });
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
        getPathObservable("geolocation").subscribeOn(Schedulers.io()).observeOn(Schedulers.main()).subscribe(new SingleOnSubscribe<File>() {

            @Override
            public void onItem(@Nullable File item) {
                Preconditions.checkNonNull(item);
                //noinspection deprecation
                settings.setGeolocationDatabasePath(item.getPath());
            }
        });
    }
    getPathObservable("databases").subscribeOn(Schedulers.io()).observeOn(Schedulers.main()).subscribe(new SingleOnSubscribe<File>() {

        @Override
        public void onItem(@Nullable File item) {
            if (API < Build.VERSION_CODES.KITKAT) {
                Preconditions.checkNonNull(item);
                //noinspection deprecation
                settings.setDatabasePath(item.getPath());
            }
        }

        @Override
        public void onComplete() {
        }
    });
}
Also used : WebSettings(android.webkit.WebSettings) File(java.io.File) SuppressLint(android.annotation.SuppressLint)

Example 17 with WebSettings

use of android.webkit.WebSettings in project Lightning-Browser by anthonycr.

the class LightningView method initializePreferences.

/**
     * Initialize the preference driven settings of the WebView. This method
     * must be called whenever the preferences are changed within SharedPreferences.
     *
     * @param context the context in which the WebView was created, it is used
     *                to get the default UserAgent for the WebView.
     */
@SuppressLint({ "NewApi", "SetJavaScriptEnabled" })
public synchronized void initializePreferences(@NonNull Context context) {
    if (mWebView == null) {
        return;
    }
    WebSettings settings = mWebView.getSettings();
    if (mPreferences.getDoNotTrackEnabled()) {
        mRequestHeaders.put(HEADER_DNT, "1");
    } else {
        mRequestHeaders.remove(HEADER_DNT);
    }
    if (mPreferences.getRemoveIdentifyingHeadersEnabled()) {
        mRequestHeaders.put(HEADER_REQUESTED_WITH, "");
        mRequestHeaders.put(HEADER_WAP_PROFILE, "");
    } else {
        mRequestHeaders.remove(HEADER_REQUESTED_WITH);
        mRequestHeaders.remove(HEADER_WAP_PROFILE);
    }
    settings.setDefaultTextEncodingName(mPreferences.getTextEncoding());
    sHomepage = mPreferences.getHomepage();
    setColorMode(mPreferences.getRenderingMode());
    if (!mIsIncognitoTab) {
        settings.setGeolocationEnabled(mPreferences.getLocationEnabled());
    } else {
        settings.setGeolocationEnabled(false);
    }
    if (API < Build.VERSION_CODES.KITKAT) {
        switch(mPreferences.getFlashSupport()) {
            case 0:
                //noinspection deprecation
                settings.setPluginState(PluginState.OFF);
                break;
            case 1:
                //noinspection deprecation
                settings.setPluginState(PluginState.ON_DEMAND);
                break;
            case 2:
                //noinspection deprecation
                settings.setPluginState(PluginState.ON);
                break;
            default:
                break;
        }
    }
    setUserAgent(context, mPreferences.getUserAgentChoice());
    if (mPreferences.getSavePasswordsEnabled() && !mIsIncognitoTab) {
        if (API < Build.VERSION_CODES.JELLY_BEAN_MR2) {
            //noinspection deprecation
            settings.setSavePassword(true);
        }
        settings.setSaveFormData(true);
    } else {
        if (API < Build.VERSION_CODES.JELLY_BEAN_MR2) {
            //noinspection deprecation
            settings.setSavePassword(false);
        }
        settings.setSaveFormData(false);
    }
    if (mPreferences.getJavaScriptEnabled()) {
        settings.setJavaScriptEnabled(true);
        settings.setJavaScriptCanOpenWindowsAutomatically(true);
    } else {
        settings.setJavaScriptEnabled(false);
        settings.setJavaScriptCanOpenWindowsAutomatically(false);
    }
    if (mPreferences.getTextReflowEnabled()) {
        settings.setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS);
        if (API >= android.os.Build.VERSION_CODES.KITKAT) {
            try {
                settings.setLayoutAlgorithm(LayoutAlgorithm.TEXT_AUTOSIZING);
            } catch (Exception e) {
                // This shouldn't be necessary, but there are a number
                // of KitKat devices that crash trying to set this
                Log.e(TAG, "Problem setting LayoutAlgorithm to TEXT_AUTOSIZING");
            }
        }
    } else {
        settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);
    }
    settings.setBlockNetworkImage(mPreferences.getBlockImagesEnabled());
    if (!mIsIncognitoTab) {
        settings.setSupportMultipleWindows(mPreferences.getPopupsEnabled());
    } else {
        settings.setSupportMultipleWindows(false);
    }
    settings.setUseWideViewPort(mPreferences.getUseWideViewportEnabled());
    settings.setLoadWithOverviewMode(mPreferences.getOverviewModeEnabled());
    switch(mPreferences.getTextSize()) {
        case 0:
            settings.setTextZoom(200);
            break;
        case 1:
            settings.setTextZoom(150);
            break;
        case 2:
            settings.setTextZoom(125);
            break;
        case 3:
            settings.setTextZoom(100);
            break;
        case 4:
            settings.setTextZoom(75);
            break;
        case 5:
            settings.setTextZoom(50);
            break;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        CookieManager.getInstance().setAcceptThirdPartyCookies(mWebView, !mPreferences.getBlockThirdPartyCookiesEnabled());
    }
}
Also used : WebSettings(android.webkit.WebSettings) SuppressLint(android.annotation.SuppressLint)

Example 18 with WebSettings

use of android.webkit.WebSettings in project Lightning-Browser by anthonycr.

the class LightningView method setUserAgent.

/**
     * This method sets the user agent of the current tab.
     * There are four options, 1, 2, 3, 4.
     * <p/>
     * 1. use the default user agent
     * <p/>
     * 2. use the desktop user agent
     * <p/>
     * 3. use the mobile user agent
     * <p/>
     * 4. use a custom user agent, or the default user agent
     * if none was set.
     *
     * @param context the context needed to get the default user agent.
     * @param choice  the choice of user agent to use, see above comments.
     */
@SuppressLint("NewApi")
private void setUserAgent(Context context, int choice) {
    if (mWebView == null)
        return;
    WebSettings settings = mWebView.getSettings();
    switch(choice) {
        case 1:
            if (API >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                settings.setUserAgentString(WebSettings.getDefaultUserAgent(context));
            } else {
                settings.setUserAgentString(sDefaultUserAgent);
            }
            break;
        case 2:
            settings.setUserAgentString(Constants.DESKTOP_USER_AGENT);
            break;
        case 3:
            settings.setUserAgentString(Constants.MOBILE_USER_AGENT);
            break;
        case 4:
            String ua = mPreferences.getUserAgentString(sDefaultUserAgent);
            if (ua == null || ua.isEmpty()) {
                ua = " ";
            }
            settings.setUserAgentString(ua);
            break;
    }
}
Also used : WebSettings(android.webkit.WebSettings) SuppressLint(android.annotation.SuppressLint)

Example 19 with WebSettings

use of android.webkit.WebSettings in project androidquery by androidquery.

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 20 with WebSettings

use of android.webkit.WebSettings in project platform_frameworks_base by android.

the class CaptivePortalLoginActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mCm = ConnectivityManager.from(this);
    mNetwork = getIntent().getParcelableExtra(ConnectivityManager.EXTRA_NETWORK);
    mCaptivePortal = getIntent().getParcelableExtra(ConnectivityManager.EXTRA_CAPTIVE_PORTAL);
    mUserAgent = getIntent().getStringExtra(ConnectivityManager.EXTRA_CAPTIVE_PORTAL_USER_AGENT);
    mUrl = getUrl();
    if (mUrl == null) {
        // getUrl() failed to parse the url provided in the intent: bail out in a way that
        // at least provides network access.
        done(Result.WANTED_AS_IS);
        return;
    }
    if (DBG) {
        Log.d(TAG, String.format("onCreate for %s", mUrl.toString()));
    }
    // Also initializes proxy system properties.
    mCm.bindProcessToNetwork(mNetwork);
    // Proxy system properties must be initialized before setContentView is called because
    // setContentView initializes the WebView logic which in turn reads the system properties.
    setContentView(R.layout.activity_captive_portal_login);
    getActionBar().setDisplayShowHomeEnabled(false);
    // Exit app if Network disappears.
    final NetworkCapabilities networkCapabilities = mCm.getNetworkCapabilities(mNetwork);
    if (networkCapabilities == null) {
        finishAndRemoveTask();
        return;
    }
    mNetworkCallback = new NetworkCallback() {

        @Override
        public void onLost(Network lostNetwork) {
            if (mNetwork.equals(lostNetwork))
                done(Result.UNWANTED);
        }
    };
    final NetworkRequest.Builder builder = new NetworkRequest.Builder();
    for (int transportType : networkCapabilities.getTransportTypes()) {
        builder.addTransportType(transportType);
    }
    mCm.registerNetworkCallback(builder.build(), mNetworkCallback);
    final WebView myWebView = (WebView) findViewById(R.id.webview);
    myWebView.clearCache(true);
    WebSettings webSettings = myWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
    mWebViewClient = new MyWebViewClient();
    myWebView.setWebViewClient(mWebViewClient);
    myWebView.setWebChromeClient(new MyWebChromeClient());
    // Start initial page load so WebView finishes loading proxy settings.
    // Actual load of mUrl is initiated by MyWebViewClient.
    myWebView.loadData("", "text/html", null);
}
Also used : WebSettings(android.webkit.WebSettings) Network(android.net.Network) NetworkRequest(android.net.NetworkRequest) WebView(android.webkit.WebView) NetworkCapabilities(android.net.NetworkCapabilities) NetworkCallback(android.net.ConnectivityManager.NetworkCallback)

Aggregations

WebSettings (android.webkit.WebSettings)211 WebView (android.webkit.WebView)108 WebViewClient (android.webkit.WebViewClient)75 SuppressLint (android.annotation.SuppressLint)50 WebChromeClient (android.webkit.WebChromeClient)47 View (android.view.View)38 Intent (android.content.Intent)30 Bitmap (android.graphics.Bitmap)21 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