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:com.digitalarx.android.ui.dialog.SamlWebViewDialog.java

@SuppressWarnings("deprecation")
@SuppressLint("SetJavaScriptEnabled")
@Override//from  w  w w. j a  v a 2 s. c o  m
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Log_OC.d(TAG, "onCreateView, savedInsanceState is " + savedInstanceState);

    // Inflate layout of the dialog  
    RelativeLayout ssoRootView = (RelativeLayout) inflater.inflate(R.layout.sso_dialog, container, false); // null parent view because it will go in the dialog layout

    if (mSsoWebView == null) {
        // initialize the WebView
        mSsoWebView = new SsoWebView(getSherlockActivity().getApplicationContext());
        mSsoWebView.setFocusable(true);
        mSsoWebView.setFocusableInTouchMode(true);
        mSsoWebView.setClickable(true);

        CookieManager cookieManager = CookieManager.getInstance();
        cookieManager.setAcceptCookie(true);
        cookieManager.removeAllCookie();
        mSsoWebView.loadUrl(mInitialUrl);

        WebSettings webSettings = mSsoWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setBuiltInZoomControls(false);
        webSettings.setLoadWithOverviewMode(false);
        webSettings.setSavePassword(false);
        webSettings.setUserAgentString(OwnCloudClient.USER_AGENT);
        webSettings.setSaveFormData(false);
    }

    mWebViewClient.setTargetUrl(mTargetUrl);
    mSsoWebView.setWebViewClient(mWebViewClient);

    // add the webview into the layout
    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    ssoRootView.addView(mSsoWebView, layoutParams);
    ssoRootView.requestLayout();

    return ssoRootView;
}

From source file:cn.zy.ef.fragment.WebViewFragment.java

protected void configureWebView(WebSettings settings) {
    settings.setJavaScriptCanOpenWindowsAutomatically(true);//js??window.open()false
    settings.setJavaScriptEnabled(true);//??jsfalsetrue????XSS?
    settings.setSupportZoom(true);//??true
    settings.setBuiltInZoomControls(false);//?false
    settings.setUseWideViewPort(true);//???
    settings.setLoadWithOverviewMode(true);//setUseWideViewPort(true)
    settings.setAppCacheEnabled(true);//?
    settings.setDomStorageEnabled(true);//DOM Storage
    settings.setCacheMode(WebSettings.LOAD_DEFAULT);
}

From source file:com.vikingbrain.dmt.view.RemoteControlActivity.java

private void configureWebView(WebView webView, WebChromeClient webChromeClient,
        CustomWebViewClient customWebViewClient) {
    //Set the properties      
    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setSupportZoom(true); //Zoom Control on web (You don't need this if ROM supports Multi-Touch       
    webSettings.setBuiltInZoomControls(true); //Enable Multitouch if supported by ROM
    webSettings.setDomStorageEnabled(true);
    webSettings.setPluginsEnabled(true);
    webSettings.setUseWideViewPort(true); //normal viewport (such as a normal desktop browser)

    webView.setWebChromeClient(webChromeClient);
    webView.setWebViewClient(customWebViewClient);
}

From source file:it.rignanese.leo.slimfacebook.PictureActivity.java

private void SetupPictureWebView() {
    webViewPicture = (MyAdvancedWebView) findViewById(R.id.webViewPicture);
    webViewPicture.setListener(this, this);

    //  webViewPicture.setDesktopMode(true);

    //webViewPicture.requestFocus(View.F);
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);//remove the keyboard issue

    WebSettings settings = webViewPicture.getSettings();

    settings.setBuiltInZoomControls(true);
    settings.setUseWideViewPort(true);//from  w  w  w .j  a v  a 2 s .  c o m
    settings.setJavaScriptEnabled(true);
    settings.setLoadWithOverviewMode(true);

    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
        // Hide the zoom controls for HONEYCOMB+
        settings.setDisplayZoomControls(false);
    }
}

From source file:com.sonnychen.aviationhk.views.BookingFragment.java

@SuppressLint("SetJavaScriptEnabled")
@Override/*w  ww  . j  a  v  a  2s.  c  o  m*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Bundle bundle = getArguments();
    if (bundle != null && !TextUtils.isEmpty(bundle.getString(BOOKING_TYPE_PARAM))) {
        Log.v("BOOKING-UI", "Argument: " + bundle.getString(BOOKING_TYPE_PARAM));
        bookingType = BookingType.valueOf(bundle.getString(BOOKING_TYPE_PARAM));
    }

    Log.v("BOOKING-UI", "Starting");
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_booking, container, false);
    mProgressBar = ((ProgressBar) view.findViewById(R.id.progress));
    mWebView = ((WebView) view.findViewById(R.id.booking_html));

    WebSettings settings = mWebView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setAllowFileAccessFromFileURLs(true);
    settings.setAllowUniversalAccessFromFileURLs(true);
    settings.setBuiltInZoomControls(true);
    settings.setLoadWithOverviewMode(true);
    settings.setUseWideViewPort(true);
    mWebView.setWebChromeClient(new WebChromeClient());
    mWebView.addJavascriptInterface(new JSInterface(getActivity(), mWebView), "Android");
    mWebView.setInitialScale(1);

    // download PDF async
    new DownloadFileTask() {
        @Override
        protected void onPostExecute(Byte[] data) {
            // save data to file
            try {
                FileOutputStream fileOutputStream = getActivity().openFileOutput(
                        bookingType == BookingType.HELICOPTER ? "helicopter.pdf" : "fixedwing.pdf",
                        Context.MODE_PRIVATE);
                fileOutputStream.write(getbytes(data));
                fileOutputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }

            displayPDF();
            // unfortunately HAKC does not have a valid SSL certificate
        }
    }.execute(bookingType == BookingType.HELICOPTER ? "http://aviationclub.hk/doc/helicopter_booking2.pdf"
            : "http://aviationclub.hk/doc/fixwing_booking2.pdf");
    return view;
}

From source file:com.owncloud.android.ui.dialog.LoginWebViewDialog.java

@SuppressWarnings("deprecation")
@SuppressLint("SetJavaScriptEnabled")
@Override/*w ww. ja v  a 2s .c o  m*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Log_OC.v(TAG, "onCreateView, savedInsanceState is " + savedInstanceState);

    // Inflate layout of the dialog  
    RelativeLayout ssoRootView = (RelativeLayout) inflater.inflate(R.layout.webview_dialog, container, false); // null parent view because it will go in the dialog layout

    if (mWebView == null) {
        // initialize the WebView
        mWebView = new SsoWebView(getActivity().getApplicationContext());
        mWebView.setFocusable(true);
        mWebView.setFocusableInTouchMode(true);
        mWebView.setClickable(true);

        WebSettings webSettings = mWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setSavePassword(false);
        webSettings.setUserAgentString(MainApp.getUserAgent());
        webSettings.setSaveFormData(false);
        // next two settings grant that non-responsive webs are zoomed out when loaded
        webSettings.setUseWideViewPort(true);
        webSettings.setLoadWithOverviewMode(true);
        // next three settings allow the user use pinch gesture to zoom in / out
        webSettings.setSupportZoom(true);
        webSettings.setBuiltInZoomControls(true);
        webSettings.setDisplayZoomControls(false);
        webSettings.setAllowFileAccess(false);

        CookieManager cookieManager = CookieManager.getInstance();
        cookieManager.setAcceptCookie(true);
        cookieManager.removeAllCookie();

        mWebView.loadUrl(mInitialUrl);
    }

    mWebViewClient.addTargetUrls(mTargetUrls);
    mWebView.setWebViewClient(mWebViewClient);

    // add the webview into the layout
    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
    ssoRootView.addView(mWebView, layoutParams);
    ssoRootView.requestLayout();

    return ssoRootView;
}

From source file:truesculpt.ui.panels.WebFilePanel.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    getManagers().getUtilsManager().updateFullscreenWindowStatus(getWindow());

    setContentView(R.layout.webfile);//from  w w w . j a v a  2  s  .co  m

    getManagers().getUsageStatisticsManager().TrackEvent("OpenFromWeb", "", 1);

    mWebView = (WebView) findViewById(R.id.webview);
    mWebView.setWebViewClient(new MyWebViewClient());
    WebSettings webSettings = mWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    mWebView.addJavascriptInterface(new JavaScriptInterface(this, getManagers()), "Android");

    int nVersionCode = getManagers().getUpdateManager().getCurrentVersionCode();
    mWebView.loadUrl(mStrBaseWebSite + "?version=" + nVersionCode);

    mPublishToWebBtn = (Button) findViewById(R.id.publish_to_web);
    mPublishToWebBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final String name = getManagers().getMeshManager().getName();
            final File imagefile = new File(getManagers().getFileManager().GetImageFileName());
            final File objectfile = new File(getManagers().getFileManager().GetObjectFileName());

            getManagers().getUsageStatisticsManager().TrackEvent("PublishToWeb", name, 1);

            if (imagefile.exists() && objectfile.exists()) {
                try {
                    final File zippedObject = File.createTempFile("object", "zip");
                    zippedObject.deleteOnExit();

                    BufferedReader in = new BufferedReader(new FileReader(objectfile));
                    BufferedOutputStream out = new BufferedOutputStream(
                            new GZIPOutputStream(new FileOutputStream(zippedObject)));
                    System.out.println("Compressing file");
                    int c;
                    while ((c = in.read()) != -1) {
                        out.write(c);
                    }
                    in.close();
                    out.close();

                    long size = 0;

                    size = new FileInputStream(imagefile).getChannel().size();
                    size += new FileInputStream(zippedObject).getChannel().size();
                    size /= 1000;

                    final SpannableString msg = new SpannableString(
                            "You will upload your latest saved version of this scupture representing " + size
                                    + " ko of data\n\n"
                                    + "When clicking the yes button you accept to publish your sculpture under the terms of the creative commons share alike, non commercial license\n"
                                    + "http://creativecommons.org/licenses/by-nc-sa/3.0"
                                    + "\n\nDo you want to proceed ?");
                    Linkify.addLinks(msg, Linkify.ALL);

                    AlertDialog.Builder builder = new AlertDialog.Builder(WebFilePanel.this);
                    builder.setMessage(msg).setCancelable(false)
                            .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int id) {
                                    PublishPicture(imagefile, zippedObject, name);
                                }
                            }).setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int id) {

                                }
                            });
                    AlertDialog dlg = builder.create();
                    dlg.show();

                    // Make the textview clickable. Must be called after
                    // show()
                    ((TextView) dlg.findViewById(android.R.id.message))
                            .setMovementMethod(LinkMovementMethod.getInstance());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else {
                AlertDialog.Builder builder = new AlertDialog.Builder(WebFilePanel.this);
                builder.setMessage(
                        "File has not been saved, you need to save it before publishing\nDo you want to proceed to save window ?")
                        .setCancelable(false)
                        .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int id) {
                                ((FileSelectorPanel) getParent()).getTabHost().setCurrentTab(2);
                            }
                        }).setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int id) {
                            }
                        });
                builder.show();
            }
        }
    });
}

From source file:at.alladin.rmbt.android.help.RMBTHelpFragment.java

/**
* 
*//* w  ww .j av  a2s . co m*/
@SuppressLint("SetJavaScriptEnabled")
@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {

    super.onCreateView(inflater, container, savedInstanceState);

    final Bundle args = getArguments();

    String url = args.getString(ARG_URL);

    if (url == null || url.length() == 0)
        url = this.getString(R.string.url_help);

    final Activity activity = getActivity();

    final WebView webview = new WebView(activity) {
        @Override
        public boolean onKeyDown(final int keyCode, final KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK && canGoBack()) {
                goBack();
                return true;
            }
            return super.onKeyDown(keyCode, event);
        }
    };

    final WebSettings webSettings = webview.getSettings();
    final String userAgent = AppConstants.getUserAgentString(getActivity());
    if (userAgent != null) {
        webSettings.setUserAgentString(userAgent);
    }
    webSettings.setJavaScriptEnabled(true);

    webview.setWebViewClient(new WebViewClient() {
        @Override
        public void onReceivedError(final WebView view, final int errorCode, final String description,
                final String failingUrl) {
            Log.w(getTag(), "error code:" + errorCode);
            Log.d(getTag(), "error desc:" + description);
            Log.d(getTag(), "error url:" + failingUrl);
            webview.loadUrl("file:///android_res/raw/error.html");
            super.onReceivedError(view, errorCode, description, failingUrl);
        }
    });

    if (!url.matches("^https?://.*")) {
        final String protocol = ConfigHelper.isControlSeverSSL(activity) ? "https" : "http";
        url = protocol + "://" + url;
    }

    webview.loadUrl(url);

    return webview;
}

From source file:com.tdispatch.passenger.fragment.OAuthFragment.java

@SuppressLint("SetJavaScriptEnabled")
@Override/*w w w.j a va2  s . c om*/
protected void onPostCreateView() {

    View v = mFragmentView.findViewById(R.id.button_cancel);
    v.setOnClickListener(mOnClickListener);

    ProgressBar pb = (ProgressBar) mFragmentView.findViewById(R.id.progressbar);
    pb.setVisibility(View.GONE);

    mWebView = (WebView) mFragmentView.findViewById(R.id.webview);
    if (mWebView != null) {

        mWebView.setWebViewClient(new MyWebViewClient());
        mWebView.setWebChromeClient(new MyWebchromeClient());

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            mWebView.setOnTouchListener(mOnTouchListener);
        }

        WebSettings webSettings = mWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
        webSettings.setAppCacheEnabled(false);
        webSettings.setSavePassword(false);
        webSettings.setSaveFormData(false);

        CookieSyncManager.createInstance(mContext);
        CookieManager cm = CookieManager.getInstance();
        cm.setAcceptCookie(true);
        cm.removeAllCookie();

        try {
            ApiRequest req = new ApiRequest(Const.Api.OauthAuthUrl);
            req.addGetParam("key", Const.getApiKey());
            req.addGetParam("scope", "");
            req.addGetParam("response_type", "code");
            req.addGetParam("client_id", Const.getOAuthClientId());
            req.addGetParam("redirect_uri", mOAuthRedirectUrl);
            req.buildRequest();

            String url = req.getUrl();

            mWebView.loadUrl(url);

        } catch (Exception e) {
            WebnetLog.e("Failed to load oauth launch page...");
        }

    } else {
        WebnetLog.e("Failed to init WebView. Aborting");
        mHostActivity.oAuthCancelled();
    }
}

From source file:org.thanatos.flowgeek.ui.activity.DetailActivity.java

/**
 * init view//from   w  ww . ja  v a 2 s  .  co m
 */
private void initView() {
    // init WebView
    WebSettings settings = mWebView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setSupportZoom(false);

    btnComment.setClickable(false);

    ScrollerBottomLayoutDelegation.delegation(mNestedScroller, mBottomLayout);
}