Example usage for android.app Activity registerForContextMenu

List of usage examples for android.app Activity registerForContextMenu

Introduction

In this page you can find the example usage for android.app Activity registerForContextMenu.

Prototype

public void registerForContextMenu(View view) 

Source Link

Document

Registers a context menu to be shown for the given view (multiple views can show the context menu).

Usage

From source file:de.baumann.browser.helper.helper_webView.java

@SuppressLint("SetJavaScriptEnabled")
public static void webView_Settings(final Activity from, final WebView webView) {

    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(from);
    String fontSizeST = sharedPref.getString("font", "100");
    int fontSize = Integer.parseInt(fontSizeST);

    webView.getSettings().setAppCachePath(from.getApplicationContext().getCacheDir().getAbsolutePath());
    webView.getSettings().setAppCacheEnabled(true);
    webView.getSettings().setMixedContentMode(MIXED_CONTENT_COMPATIBILITY_MODE);
    webView.getSettings().setAllowFileAccess(true);
    webView.getSettings().setAllowContentAccess(true);
    webView.getSettings().setBuiltInZoomControls(true);
    webView.getSettings().setDisplayZoomControls(false);
    webView.getSettings().setDomStorageEnabled(true);
    webView.getSettings().setTextZoom(fontSize);
    webView.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING);
    webView.getSettings().setUseWideViewPort(true);
    webView.getSettings().setLoadWithOverviewMode(true);

    from.registerForContextMenu(webView);

    if (sharedPref.getString("nav", "2").equals("1") || sharedPref.getString("nav", "2").equals("3")) {
        helper_webView.webView_Touch(from, webView);
    }/*from   w ww  . j a v  a  2  s. c om*/

    if (sharedPref.getString("cookie", "1").equals("2") || sharedPref.getString("cookie", "1").equals("3")) {
        CookieManager cookieManager = CookieManager.getInstance();
        cookieManager.setAcceptThirdPartyCookies(webView, true);
    } else {
        CookieManager cookieManager = CookieManager.getInstance();
        cookieManager.setAcceptThirdPartyCookies(webView, false);
    }

    if (sharedPref.getString("started", "").equals("yes")) {
        if (sharedPref.getString("java_string", "True").equals(from.getString(R.string.app_yes))) {
            webView.getSettings().setJavaScriptEnabled(true);
            sharedPref.edit().putString("java_string", from.getString(R.string.app_yes)).apply();
        } else {
            webView.getSettings().setJavaScriptEnabled(false);
            sharedPref.edit().putString("java_string", from.getString(R.string.app_no)).apply();
        }

        if (sharedPref.getString("pictures_string", "True").equals(from.getString(R.string.app_yes))) {
            webView.getSettings().setLoadsImagesAutomatically(true);
            sharedPref.edit().putString("pictures_string", from.getString(R.string.app_yes)).apply();
        } else {
            webView.getSettings().setLoadsImagesAutomatically(false);
            sharedPref.edit().putString("pictures_string", from.getString(R.string.app_no)).apply();
        }

        if (sharedPref.getString("loc_string", "True").equals(from.getString(R.string.app_yes))) {
            webView.getSettings().setGeolocationEnabled(true);
            helper_main.grantPermissionsLoc(from);
            sharedPref.edit().putString("loc_string", from.getString(R.string.app_yes)).apply();
        } else {
            webView.getSettings().setGeolocationEnabled(false);
            sharedPref.edit().putString("loc_string", from.getString(R.string.app_no)).apply();
        }

        if (sharedPref.getString("cookie_string", "True").equals(from.getString(R.string.app_yes))) {
            CookieManager cookieManager = CookieManager.getInstance();
            cookieManager.setAcceptCookie(true);
            sharedPref.edit().putString("cookie_string", from.getString(R.string.app_yes)).apply();
        } else {
            CookieManager cookieManager = CookieManager.getInstance();
            cookieManager.setAcceptCookie(false);
            sharedPref.edit().putString("cookie_string", from.getString(R.string.app_no)).apply();
        }
    } else {
        if (sharedPref.getBoolean("java", false)) {
            webView.getSettings().setJavaScriptEnabled(true);
            sharedPref.edit().putString("java_string", from.getString(R.string.app_yes)).apply();
        } else {
            webView.getSettings().setJavaScriptEnabled(false);
            sharedPref.edit().putString("java_string", from.getString(R.string.app_no)).apply();
        }

        if (sharedPref.getBoolean("pictures", false)) {
            webView.getSettings().setLoadsImagesAutomatically(true);
            sharedPref.edit().putString("pictures_string", from.getString(R.string.app_yes)).apply();
        } else {
            webView.getSettings().setLoadsImagesAutomatically(false);
            sharedPref.edit().putString("pictures_string", from.getString(R.string.app_no)).apply();
        }

        if (sharedPref.getBoolean("loc", false)) {
            webView.getSettings().setGeolocationEnabled(true);
            helper_main.grantPermissionsLoc(from);
            sharedPref.edit().putString("loc_string", from.getString(R.string.app_yes)).apply();
        } else {
            webView.getSettings().setGeolocationEnabled(false);
            sharedPref.edit().putString("loc_string", from.getString(R.string.app_no)).apply();
        }

        if (sharedPref.getString("cookie", "1").equals("1")
                || sharedPref.getString("cookie", "1").equals("3")) {
            CookieManager cookieManager = CookieManager.getInstance();
            cookieManager.setAcceptCookie(true);
            sharedPref.edit().putString("cookie_string", from.getString(R.string.app_yes)).apply();
        } else {
            CookieManager cookieManager = CookieManager.getInstance();
            cookieManager.setAcceptCookie(false);
            sharedPref.edit().putString("cookie_string", from.getString(R.string.app_no)).apply();
        }
    }
}