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:org.noise_planet.noisecapture.MapFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (view == null) {
        // Inflate the layout for this fragment
        view = inflater.inflate(R.layout.fragment_measurement_map, container, false);
        leaflet = (WebView) view.findViewById(R.id.measurement_webmapview);
        leaflet.clearCache(true);//  w  w w.java  2s .c  o m
        leaflet.clearHistory();
        WebSettings webSettings = leaflet.getSettings();
        webSettings.setJavaScriptEnabled(true);
        WebSettings settings = leaflet.getSettings();
        settings.setAppCachePath(new File(getContext().getCacheDir(), "webview").getPath());
        settings.setAppCacheEnabled(true);
        leaflet.setWebViewClient(new WebViewClient() {
            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                pageLoaded.set(true);
                if (mapFragmentAvailableListener != null) {
                    mapFragmentAvailableListener.onPageLoaded(MapFragment.this);
                }
            }

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                startActivity(browserIntent);
                return true;
            }
        });
        if (mapFragmentAvailableListener != null) {
            mapFragmentAvailableListener.onMapFragmentAvailable(this);
        }
    }
    return view;
}

From source file:com.mario22gmail.license.nfc_project.FragmentBrowser.java

public void OpenWebSite(String urlFromCredential, String javaScript) {

    mWebview.loadUrl(urlFromCredential);
    WebSettings settings = mWebview.getSettings();
    settings.setJavaScriptEnabled(true);

    urlEditText.setText(urlFromCredential);
    final String javaScriptFinal = javaScript;
    final String urlFromCredentialFinal = urlFromCredential;

    mWebview.setWebViewClient(new WebViewClient() {

        @Override/*from  www .j  a  v a  2  s .c om*/
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);

            if (url.startsWith(urlFromCredentialFinal)) {
                if (Build.VERSION.SDK_INT >= 19) {
                    view.evaluateJavascript(javaScriptFinal, new ValueCallback<String>() {
                        @Override
                        public void onReceiveValue(String s) {

                        }
                    });
                } else {
                    view.loadUrl(javaScriptFinal);
                }
            }
        }
    });
}

From source file:com.barcamppenang2013.tabfragment.AgendaFragment.java

/**
 * Called to instantiate the view. Creates and returns the WebView.
 *//*from  w  ww  .j a v  a  2 s.  c  o  m*/
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    if (mWebView != null) {
        mWebView.destroy();
    }
    mWebView = new WebView(getActivity());
    mWebView.setOnKeyListener(new OnKeyListener() {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
                mWebView.goBack();
                return true;
            }
            return false;
        }

    });
    mWebView.setWebViewClient(new InnerWebViewClient()); // forces it to
    // open in app

    // mUrl = "file:///android_asset/agenda/about.html";
    // mUrl = this.getActivity().getFilesDir()+"/agenda.html";
    // mUrl = "file:///data/about.html";
    //       mWebView.loadUrl("http://barcamppenang.org/agenda.html");
    //       mWebView.loadUrl("http://barcamppenang.org/schedule/");

    mWebView.loadData(readFromFile("agenda.html"), "text/html", "utf-8");

    // Log.d("ddw", "outside!!");
    mIsWebViewAvailable = true;
    WebSettings settings = mWebView.getSettings();
    settings.setJavaScriptEnabled(true);
    //      if (isNetworkAvailable() == true){
    //         settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
    //      }
    //      else{
    //         settings.setCacheMode(WebSettings.LOAD_CACHE_ONLY);
    //      }
    return mWebView;
}

From source file:com.barcamppenang2014.tabfragment.Agenda.java

/**
 * Called to instantiate the view. Creates and returns the WebView.
 *//* w  w  w.  j  av a  2  s .c  o m*/
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    if (mWebView != null) {
        mWebView.destroy();
    }
    mWebView = new WebView(getActivity());
    mWebView.setOnKeyListener(new OnKeyListener() {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
                mWebView.goBack();
                return true;
            }
            return false;
        }

    });
    mWebView.setWebViewClient(new InnerWebViewClient()); // forces it to
    // open in app

    // mUrl = "file:///android_asset/agenda/about.html";
    // mUrl = this.getActivity().getFilesDir()+"/agenda.html";
    // mUrl = "file:///data/about.html";
    //       mWebView.loadUrl("http://barcamppenang.org/agenda.html");
    //       mWebView.loadUrl("http://barcamppenang.org/schedule/");

    mWebView.loadData(readFromFile("leaderboard.php"), "text/html", "utf-8");

    // Log.d("ddw", "outside!!");
    mIsWebViewAvailable = true;
    WebSettings settings = mWebView.getSettings();
    settings.setJavaScriptEnabled(true);
    //      if (isNetworkAvailable() == true){
    //         settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
    //      }
    //      else{
    //         settings.setCacheMode(WebSettings.LOAD_CACHE_ONLY);
    //      }
    return mWebView;
}

From source file:org.owasp.goatdroid.fourgoats.fragments.HistoryDialogFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.history, container, false);
    webview = (WebView) v.findViewById(R.id.historyWebView);
    WebSettings webSettings = webview.getSettings();
    webview.addJavascriptInterface(new ViewCheckinJSInterface(context), "jsInterface");
    webSettings.setJavaScriptEnabled(true);
    noCheckinsTextView = (TextView) v.findViewById(R.id.noCheckinsTextView);
    GetHistory getHistory = new GetHistory();
    getHistory.execute(null, null);/*from   ww  w .  ja v a 2s  .c  o m*/
    return v;
}

From source file:ch.gianulli.trelloapi.ui.AuthenticationDialogFragment.java

@Nullable
@Override//  w w w  .j a  va2s . c  o  m
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (getDialog() != null) {
        getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
    }

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

    mProgressIndicator = (ProgressBar) v.findViewById(R.id.progress_indicator);
    mWebView = (WebView) v.findViewById(R.id.webview);

    // Catch token
    mWebView.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            setProgressIndicatorVisibility(true);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            setProgressIndicatorVisibility(false);
            if (url.equals(URL_TOKEN)) {
                // Get token and close dialog
                mWebView.loadUrl("javascript:window.HTMLOUT.parseHTML('<html>'+document"
                        + ".getElementsByTagName('html')[0].innerHTML+'</html>');");
            } else {
                super.onPageFinished(view, url);
            }
        }
    });
    WebSettings webSettings = mWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    mWebView.addJavascriptInterface(new MyJavaScriptInterface(), "HTMLOUT");
    mWebView.setVisibility(View.GONE);

    mWebView.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_UP) {
                switch (keyCode) {
                case KeyEvent.KEYCODE_BACK:
                    if (mWebView.canGoBack()) {
                        mWebView.goBack();
                        return true;
                    }
                }

            }
            return false;
        }
    });

    // Load first page
    setProgressIndicatorVisibility(true);
    try {
        mWebView.loadUrl(URL_AUTHORIZATION + "key=" + mApi.getAppKey() + "&name="
                + URLEncoder.encode(getString(R.string.app_name), "UTF-8")
                + "&expiration=never&response_type=token&scope=read,write");
    } catch (UnsupportedEncodingException e) {
        // never happens
    }

    return v;
}

From source file:com.github.snowdream.android.widget.NotFoundWebView.java

@SuppressLint({ "SetJavaScriptEnabled", "NewApi" })
private void init(Context context, AttributeSet attrs, int defStyle) {
    if (context == null) {
        return;// ww w .  j  a v a2s.  c  o  m
    }

    // enable JavaScript
    WebSettings settings = this.getSettings();
    settings.setJavaScriptEnabled(true);

    settings.setSupportZoom(true);
    settings.setBuiltInZoomControls(true);
    settings.setLoadWithOverviewMode(true);
    settings.setDefaultZoom(ZoomDensity.FAR);

    //settings.setUseWideViewPort(true);
    //webView.setInitialScale(1);

    // init attrs
    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.CustomWebView);

    try {
        int type = a.getInteger(R.styleable.CustomWebView_type, 0);
        switch (type) {
        case 0:
            script = context.getString(R.string.html_notfound);
            break;
        case 1:
            script = context.getString(R.string.html_qq_narrow);
            break;
        case 2:
            script = context.getString(R.string.html_qq_narrow);
            break;
        case 3:
            script = context.getString(R.string.html_qq_wide);
            break;
        case 4:
            script = context.getString(R.string.html_yibo);
            break;
        default:
            script = a.getString(R.styleable.CustomWebView_script);
            break;
        }
    } finally {
        a.recycle();
    }
}

From source file:shreckye.scu.youth.HomepageFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_homepage, container, false);

    final SwipeRefreshLayout swipeRefreshLayout = (SwipeRefreshLayout) view
            .findViewById(R.id.swipe_refresh_layout);
    AppUtil.setupSwipeRefreshLayoutColors(swipeRefreshLayout);

    homepageWebView = (WebView) view.findViewById(R.id.homepage_web_view);
    WebSettings webSettings = homepageWebView.getSettings();
    webSettings.setLoadWithOverviewMode(true);
    webSettings.setUseWideViewPort(true);
    webSettings.setJavaScriptEnabled(true);

    homepageWebView.loadUrl(HOMEPAGE_URL);
    homepageWebView.setWebViewClient(new WebViewClient() {
        @Override//from w  ww .  jav a 2 s  . co  m
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            swipeRefreshLayout.setRefreshing(true);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            swipeRefreshLayout.setRefreshing(false);
        }
    });

    swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            refreshAsync();
        }
    });

    FloatingActionButton fab = (FloatingActionButton) view.findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            AppUtil.openWebPageAndShowSnackbarIfFail(HomepageFragment.this, HOMEPAGE_URL, getView());
        }
    });

    return view;
}

From source file:com.paulshantanu.bputapp.PdfViewerAcitvity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_pdf_notice);
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setSubtitle("View Notice");

    String link = getIntent().getExtras().getString("link");
    Log.i("debug", "pdfintent: " + link);

    url = URLDecoder.getDecodedUrl(link);

    progressBar = ButteryProgressBar.getInstance(PdfViewerAcitvity.this);
    progressBar.setVisibility(View.VISIBLE);

    webView = (WebView) findViewById(R.id.notice_view);
    webView.setVisibility(View.INVISIBLE);
    WebSettings settings = webView.getSettings();
    settings.setJavaScriptEnabled(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { //required for running javascript on android 4.1 or later
        settings.setAllowFileAccessFromFileURLs(true);
        settings.setAllowUniversalAccessFromFileURLs(true);
    }/*w ww.j  a  v a 2s . c o m*/
    settings.setBuiltInZoomControls(true);
    webView.setWebChromeClient(new WebChromeClient());

    new DownloadTask(PdfViewerAcitvity.this).execute(url);
}

From source file:com.cnm.cnmrc.fragment.search.SearchNaverSub.java

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

    preventClickDispatching = (FrameLayout) layout.findViewById(R.id.search_tvch_prevent_click_dispatching);
    preventClickDispatching.setOnClickListener(this);

    webview = (WebView) layout.findViewById(R.id.webView);
    webview.setVisibility(View.INVISIBLE);

    // listview//from   w  w w  .  jav  a2s . c  om
    listView = (ListView) layout.findViewById(R.id.tvch_semidetail);
    listView.setDivider(null);
    listView.setDividerHeight(0);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @SuppressLint("SetJavaScriptEnabled")
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            //Intent intent = new Intent(Intent.ACTION_VIEW);
            //Uri uri = Uri.parse(mResult.get(position).getLink());
            //intent.setData(uri);
            //getActivity().startActivity(intent);

            //webview use to call own site
            webview.setWebViewClient(new WebViewClient());
            WebSettings set = webview.getSettings();
            set.setJavaScriptEnabled(true);
            set.setBuiltInZoomControls(true);
            webview.loadUrl(mResult.get(position).getLink());
            webview.setVisibility(View.VISIBLE);

            // zoom all
            webview.getSettings().setLoadWithOverviewMode(true);
            webview.getSettings().setUseWideViewPort(true);

            //webview.setVerticalScrollBarEnabled(false);
            //webview.setHorizontalScrollBarEnabled(false);
        }

    });

    return layout;
}