Example usage for android.webkit WebSettings setJavaScriptEnabled

List of usage examples for android.webkit WebSettings setJavaScriptEnabled

Introduction

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

Prototype

public abstract void setJavaScriptEnabled(boolean flag);

Source Link

Document

Tells the WebView to enable JavaScript execution.

Usage

From source file:se.eliga.aves.AboutFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    WebView webView = (WebView) getView().findViewById(R.id.about_text);
    webView.loadUrl("file:///android_asset/about.html");
    webView.setBackgroundColor(0x00FFFFFF);
    webView.setVisibility(View.VISIBLE);
    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);

    webView.addJavascriptInterface(//w w w  .j  av  a2s .c  om
            new AboutJSObject(getVersion(), BuildConfig.BUILDTIME, BuildConfig.BUILDTYPE), "AboutData");
}

From source file:com.jio.mhood.services.api.settings.LicensesFragment.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override//from  w  w w  . j a v a 2 s  .  co  m
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ViewGroup view = (ViewGroup) inflater.inflate(R.layout.fragment_licenses, container, false);

    if (mWebView == null) {
        mWebView = new WebView(view.getContext());
        mWebView.setLayoutParams(
                new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
        mWebView.setWebChromeClient(new WebChromeClient());
        mWebView.setBackgroundColor(0);

        WebSettings webSettings = mWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setDomStorageEnabled(true);
        webSettings.setPluginState(PluginState.ON_DEMAND);
        webSettings.setPluginState(PluginState.ON);
        webSettings.setBuiltInZoomControls(true);
        webSettings.setUseWideViewPort(true);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            webSettings.setDisplayZoomControls(false);
        }

        mWebView.loadUrl(URL);
    } else {
        mParent.removeView(mWebView);
    }
    mParent = view;
    mParent.addView(mWebView);

    return mParent;
}

From source file:com.rstar.mobile.thermocouple.ui.DatabaseFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_info, parent, false);

    getActivity().setTitle(title);/*  w ww .  jav  a  2  s. c  om*/

    WebView webView = (WebView) v.findViewById(R.id.fragmentInfo_webView);
    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    try {
        webView.loadUrl(AppSettings.databaseLink);
    } catch (Exception e) {
    }

    return v;
}

From source file:com.chatwing.whitelabel.fragments.ProfileInfoFragment.java

private void configWebView(WebView webView) {
    WebSettings webSettings = webView.getSettings();
    webSettings.setAppCacheEnabled(false);
    webSettings.setJavaScriptEnabled(true);
    webView.setWebViewClient(new WebViewClient());
}

From source file:com.elekso.potfix.fragment.LicenseFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.fragment_license, container, false);
    WebView heroespage = (WebView) rootView.findViewById(R.id.webView_license);
    WebSettings webSettings = heroespage.getSettings();
    webSettings.setJavaScriptEnabled(true);
    heroespage.loadUrl("file:///android_asset/license.html");

    // return inflater.inflate(R.layout.fragment_license, container, false);
    return rootView;
}

From source file:de.vanita5.twittnuker.fragment.support.BaseSupportWebViewFragment.java

@Override
public void onActivityCreated(final Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    final WebView view = getWebView();
    view.setWebViewClient(new DefaultWebViewClient(getActivity()));
    final WebSettings settings = view.getSettings();
    settings.setBuiltInZoomControls(true);
    settings.setJavaScriptEnabled(true);
    WebSettingsAccessor.setAllowUniversalAccessFromFileURLs(settings, true);
}

From source file:com.analysedesgeeks.android.WebFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    final View v = inflater.inflate(R.layout.fragment_webview, container, false);

    webview = (WebView) v.findViewById(R.id.webview);

    final WebSettings settings = webview.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setDomStorageEnabled(true);
    settings.setDefaultZoom(WebSettings.ZoomDensity.FAR);
    settings.setSupportZoom(true);/*  w w  w . j a  v  a  2s.  co  m*/
    settings.setBuiltInZoomControls(true);

    //load a custom user agent 
    //see http://stackoverflow.com/questions/6856814/problems-loading-mobile-twitter-in-webview
    settings.setUserAgentString(
            "Mozilla/5.0 (Linux; U; Android 2.0; en-us; Droid Build/ESD20) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17");

    final View loading = v.findViewById(R.id.loading);

    webview.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageFinished(final WebView view, final String url) {
            loading.setVisibility(View.GONE);
        }
    });

    webview.loadUrl(url);

    return v;
}

From source file:yet.another.hackernews.reader.ViewFragment.java

private void webviewSettings() {
    final WebSettings settings = menuBrowser.getSettings();
    settings.setJavaScriptEnabled(true);
}

From source file:org.que.activities.fragments.WebviewFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_webview, container, false);
    if (url != null && !url.isEmpty()) {
        content = ((WebView) rootView.findViewById(R.id.webview));
        //WebViewClient is enabled in order to force all links to load within the webview and also
        // in order to enable JavaScript
        content.setWebViewClient(new HelloWebViewClient());
        WebSettings webSettings = content.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setBuiltInZoomControls(true);
        webSettings.setSupportZoom(true);
        content.loadUrl(url);/*from  w  w  w  .j a va 2  s .c  om*/
    }

    getActivity().setTitle(title);
    return rootView;
}

From source file:com.bluekai.sdk.BlueKaiViewDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());
    if (blueKaiView == null) {
        blueKaiView = new WebView(getActivity());
        WebViewClient client = new WebViewClient() {
            @Override//w  ww  .  j av a2s  .com
            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
                super.onReceivedError(view, errorCode, description, failingUrl);
                Logger.debug("BlueKaiView",
                        "Error loading BK URL in webview -- " + errorCode + " -- " + description);
                errorOccured = true;
                if (listener != null) {
                    listener.onViewLoaded(false, isExistingData(), getParamsList());
                }
            }

            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                if (!errorOccured && listener != null) {
                    errorOccured = false;
                    listener.onViewLoaded(true, isExistingData(), getParamsList());
                }
            }
        };
        blueKaiView.setWebViewClient(client);
        WebSettings webSettings = blueKaiView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        int height = 1, width = 1;
        // if (devMode) {
        height = width = 300;
        // }
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(width, height);
        params.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
        params.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
        params.setMargins(10, 10, 10, 10);
        blueKaiView.setLayoutParams(params);
        blueKaiView.setBackgroundColor(Color.LTGRAY);
        alertDialogBuilder.setNegativeButton("Close", new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
    }
    blueKaiView.loadUrl(url);
    alertDialogBuilder.setView(blueKaiView);
    return alertDialogBuilder.create();
}