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.cnm.cnmrc.fragment.search.SearchNaver.java

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

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

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

    // listview//  w w w .  ja  va 2 s .c  om
    listView = (ListView) layout.findViewById(R.id.listview);
    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;
}

From source file:ml.hepolise.vkaudiosave.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    permissions();//from   w ww .j  a v  a2 s  .c o  m

    try {
        version = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
    } catch (PackageManager.NameNotFoundException e) {

    }
    mRegistrationProgressBar = (ProgressBar) findViewById(R.id.registrationProgressBar);
    mRegistrationBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            mRegistrationProgressBar.setVisibility(ProgressBar.GONE);
            SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
            String token = sharedPreferences.getString(QuickstartPreferences.TOKEN, "");
            boolean sentToken = sharedPreferences.getBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, false);
            if (sentToken) {
                setContentView(R.layout.webview);
                mWebView = (WebView) findViewById(R.id.activity_main_webview);
                mWebView.setWebChromeClient(new WebChromeClient());
                WebSettings webSettings = mWebView.getSettings();
                webSettings.setJavaScriptEnabled(true);
                mWebView.addJavascriptInterface(new WebInterface(getApplicationContext()), "Android");
                //                    mWebView.clearCache(true);
                //                    mWebView.clearHistory();
                //                    clearCookies(getApplicationContext());
                mWebView.loadUrl("https://vk-as.tk/?app=" + token + "&version=" + version + "&debug=0");
                mWebView.setWebViewClient(new webview());
                mWebView.setDownloadListener(new DownloadListener() {
                    public void onDownloadStart(String url, String userAgent, String contentDisposition,
                            String mimetype, long contentLength) {

                        Uri uri = Uri.parse(url);
                        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                        startActivity(intent);
                    }
                });

            } else {
                mInformationTextView.setText(getString(R.string.token_error_message));
            }
        }
    };
    registerReceiver();

    if (checkPlayServices()) {
        Intent intent = new Intent(this, ml.hepolise.vkaudiosave.RegistrationIntentService.class);
        startService(intent);
    }
}

From source file:de.trier.infsec.koch.droidsheep.activities.HijackActivity.java

private void setupWebView() {
    webview = (WebView) findViewById(R.id.webviewhijack);
    webview.setWebViewClient(new MyWebViewClient());
    WebSettings webSettings = webview.getSettings();
    webSettings.setUserAgentString("foo");
    webSettings.setJavaScriptEnabled(true);
    webSettings.setAppCacheEnabled(false);
    webSettings.setBuiltInZoomControls(true);
    webview.setWebChromeClient(new WebChromeClient() {
        public void onProgressChanged(WebView view, int progress) {
            HijackActivity.this.setProgress(progress * 100);
        }//ww w  .  jav  a  2  s . c  om
    });
}

From source file:com.clutch.ClutchView.java

@SuppressLint("SetJavaScriptEnabled")
private void clutchInit() {
    loading = new ProgressDialog(this.getContext());
    loading.hide();//  www . j a v  a2  s  . co m

    this.setWebChromeClient(new WebChromeClient() {
        // TODO: Clutch Debug Toolbar
        @Override
        public boolean onJsPrompt(WebView view, String url, String message, String defaultValue,
                JsPromptResult result) {
            if (!"methodCalled".equals(defaultValue)) {
                return false;
            }
            JSONObject jsonMessage = null;
            String methodName = null;
            String callbackId = null;
            JSONObject params = null;
            try {
                jsonMessage = new JSONObject(message);
                methodName = jsonMessage.getString("method");
                callbackId = jsonMessage.getString("callbackNum");
                params = jsonMessage.getJSONObject("args");
            } catch (JSONException e) {
                Log.e(TAG, "Could not decode JSON: " + message);
                result.cancel();
                return true;
            }
            if (methodName.equals("clutch.loading.begin")) {
                String loadingMessage = params.optString("text");
                if (loadingMessage == null) {
                    loadingMessage = "Loading...";
                } else if ("null".equals(loadingMessage)) {
                    loadingMessage = "Loading...";
                }
                loading.setMessage(loadingMessage);
                loading.show();
            } else if (methodName.equals("clutch.loading.end")) {
                loading.hide();
            }
            ClutchCallback callback = null;
            if (!"0".equals(callbackId)) {
                callback = new ClutchCallback(ClutchView.this, callbackId);
            }
            dispatcher.methodCalled(methodName, params, callback);
            result.cancel();
            return true;
        }
    });

    ClutchSync.addClutchView(this);
    WebSettings settings = this.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setSupportZoom(true);
    settings.setAppCacheEnabled(false);
}

From source file:com.example.android.navigationdrawer.AboutUs.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.aboutus);//  w w  w .ja  v a 2 s .  c o m

    WebView wv = (WebView) findViewById(R.id.aboutwebview);
    wv.loadUrl("http://202.125.255.1/finaltruetonev1/index.php/user/guestAbout");
    WebSettings webSettings = wv.getSettings();
    webSettings.setJavaScriptEnabled(true);

    mTitle = mDrawerTitle = getTitle();
    mPlanetTitles = getResources().getStringArray(R.array.planets_array);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (RecyclerView) findViewById(R.id.left_drawer);

    // set a custom shadow that overlays the main content when the drawer opens
    //        mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
    // improve performance by indicating the list if fixed size.
    mDrawerList.setHasFixedSize(true);
    mDrawerList.setLayoutManager(new LinearLayoutManager(this));

    // set up the drawer's list view with items and click listener
    mDrawerList.setAdapter(new PlanetAdapter(mPlanetTitles, this));
    // enable ActionBar app icon to behave as action to toggle nav drawer
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);

    // ActionBarDrawerToggle ties together the the proper interactions
    // between the sliding drawer and the action bar app icon
    mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
            mDrawerLayout, /* DrawerLayout object */
            R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
            R.string.drawer_open, /* "open drawer" description for accessibility */
            R.string.drawer_close /* "close drawer" description for accessibility */
    ) {
        public void onDrawerClosed(View view) {
            getActionBar().setTitle(mTitle);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }

        public void onDrawerOpened(View drawerView) {
            getActionBar().setTitle(mDrawerTitle);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    if (savedInstanceState == null) {
        selectItem(2);
    }
}

From source file:fr.cph.stock.android.activity.ChartActivity.java

@SuppressLint("SetJavaScriptEnabled")
@Override//from   w  w w  . j  a v a  2s.c  om
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.chart_activity);

    Bundle b = getIntent().getExtras();
    portfolio = b.getParcelable("portfolio");
    chartType = ChartType.getEnum(b.getString("chartType"));

    errorView = (TextView) findViewById(R.id.errorMessage);
    actionBar = getActionBar();
    webView = (WebView) findViewById(R.id.webView);
    String data = getData();
    webView.setWebChromeClient(new DebugWebChromeClient());
    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    // myWebView.setBackgroundColor(0x00000000);
    // myWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    webView.loadDataWithBaseURL("file:///android_asset/www/", data, "text/html", "UTF-8", null);
    webView.reload();

    // Set context
    EasyTracker.getInstance().setContext(getApplicationContext());
    // Instantiate the Tracker
    tracker = EasyTracker.getTracker();
}

From source file:in.rab.bildkort.ImageFragment.java

@SuppressLint("SetJavaScriptEnabled")
@Override/*from  w  ww  .ja  v a 2  s  . co  m*/
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    mWebView = (WebView) getView().findViewById(R.id.webView);
    final ProgressBar progress = (ProgressBar) getView().findViewById(R.id.image_progress);
    mWebView.setWebChromeClient(new WebChromeClient());
    final WebSettings settings = mWebView.getSettings();

    settings.setBuiltInZoomControls(true);
    settings.setDisplayZoomControls(false);
    settings.setJavaScriptEnabled(true);

    // We replace the src urls in imagepicker.js::init(), so don't load
    // images twice.
    settings.setBlockNetworkImage(true);

    mWebView.setInitialScale(100);

    mWebView.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url) {
            if (Objects.equals(url, GSTATIC_SERVER)) {
                settings.setBlockNetworkImage(false);

                progress.setVisibility(View.GONE);
                mWebView.setVisibility(View.VISIBLE);
            } else {
                view.loadUrl("javascript:" + getImagePickerJs() + "getPickerHtml();");
            }
        }
    });

    mWebView.addJavascriptInterface(new WcmJsObject(), "wcm");
    mWebView.loadUrl("https://www.google.se/search?tbm=isch&q=" + getWord());
}

From source file:edu.cscie71.imm.slacker.plugin.Slacker.java

private void openAuthScreen() {
    Runnable runnable = new Runnable() {
        @SuppressLint("NewApi")
        public void run() {
            dialog = new Dialog(cordova.getActivity(), android.R.style.Theme_NoTitleBar);
            dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog;
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCancelable(true);// w  w  w . ja  v  a  2  s .  c o m

            LinearLayout mainLayout = new LinearLayout(cordova.getActivity());
            mainLayout.setOrientation(LinearLayout.VERTICAL);

            inAppWebView = new WebView(cordova.getActivity());
            inAppWebView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                    LinearLayout.LayoutParams.MATCH_PARENT));
            inAppWebView.setWebChromeClient(new WebChromeClient());
            WebViewClient client = new AuthBrowser();
            inAppWebView.setWebViewClient(client);
            WebSettings settings = inAppWebView.getSettings();
            settings.setJavaScriptEnabled(true);
            settings.setJavaScriptCanOpenWindowsAutomatically(true);

            inAppWebView.loadUrl(authURL + "?client_id=" + slackClientID + "&scope=" + scope);
            inAppWebView.getSettings().setLoadWithOverviewMode(true);
            inAppWebView.getSettings().setUseWideViewPort(true);
            inAppWebView.requestFocus();
            inAppWebView.requestFocusFromTouch();

            mainLayout.addView(inAppWebView);

            WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
            lp.copyFrom(dialog.getWindow().getAttributes());
            lp.width = WindowManager.LayoutParams.MATCH_PARENT;
            lp.height = WindowManager.LayoutParams.MATCH_PARENT;

            dialog.setContentView(mainLayout);
            dialog.show();
            dialog.getWindow().setAttributes(lp);
        }
    };
    this.cordova.getActivity().runOnUiThread(runnable);
}

From source file:com.nestapi.lib.UserAuthActivity.java

@SuppressLint("SetJavaScriptEnabled")
@Override/* w  ww .ja  va 2s .  co  m*/
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.nest_auth_webview_layout);

    WindowManager.LayoutParams params = getWindow().getAttributes();
    params.height = ViewGroup.LayoutParams.MATCH_PARENT;
    params.width = ViewGroup.LayoutParams.MATCH_PARENT;
    params.horizontalMargin = 50;
    params.verticalMargin = 50;
    getWindow().setAttributes(params);

    clientWebView = (WebView) findViewById(R.id.auth_webview);
    mProgressBar = (ProgressBar) findViewById(R.id.webview_progress);
    mClientMetadata = getClientMetadata();

    if (!hasValidArgs(mClientMetadata.getRedirectURL(), mClientMetadata.getClientID(),
            mClientMetadata.getStateValue())) {
        log("invalid arguments...");
        setResult(RESULT_CANCELED);
        log("finishing");
        finish();
    }

    clientWebView.setWebChromeClient(new ProgressChromeClient());
    clientWebView.setWebViewClient(new RedirectClient());

    mWebViewUrl = String.format(APIUrls.CLIENT_CODE_URL, mClientMetadata.getClientID(),
            mClientMetadata.getStateValue());
    log("setting url: " + mWebViewUrl);
    WebSettings webSettings = clientWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    clientWebView.loadUrl(mWebViewUrl);
}

From source file:com.cerema.cloud2.ui.dialog.SamlWebViewDialog.java

@SuppressWarnings("deprecation")
@SuppressLint("SetJavaScriptEnabled")
@Override/*w  w  w .j  a  v  a2  s  . c om*/
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.sso_dialog, container, false); // null parent view because it will go in the dialog layout

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

        WebSettings webSettings = mSsoWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setBuiltInZoomControls(false);
        webSettings.setLoadWithOverviewMode(false);
        webSettings.setSavePassword(false);
        webSettings.setUserAgentString(MainApp.getUserAgent());
        webSettings.setSaveFormData(false);

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

        mSsoWebView.loadUrl(mInitialUrl);
    }

    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;
}