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.pursuer.reader.easyrss.WebpageItemViewCtrl.java

@SuppressLint("SetJavaScriptEnabled")
public WebpageItemViewCtrl(final DataMgr dataMgr, final Context context, final String uid,
        final boolean isMobilized) {
    super(dataMgr, R.layout.webpage_item, context);

    this.item = dataMgr.getItemByUid(uid, ITEM_PROJECTION);
    this.theme = new SettingTheme(dataMgr).getData();
    this.fontSize = new SettingFontSize(dataMgr).getData();
    // Disable hardware acceleration on Android 3.0-4.1 devices.
    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR1
            && android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
        view.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    }/*from   w  w  w .jav  a2  s .co  m*/

    {
        mobilizedView = (WebView) view.findViewById(R.id.MobilizedContent);
        mobilizedView.setBackgroundColor(context.getResources().getColor(
                theme == SettingTheme.THEME_NORMAL ? R.color.NormalBackground : R.color.DarkBackground));
        mobilizedView.setFocusable(false);
        final WebSettings settings = mobilizedView.getSettings();
        settings.setDefaultTextEncodingName(HTTP.UTF_8);
        settings.setJavaScriptEnabled(false);
        settings.setDefaultFontSize(fontSize);
    }
    {
        originalView = (WebView) view.findViewById(R.id.OriginalContent);
        originalView.setFocusable(false);
        originalView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
        final WebSettings settings = originalView.getSettings();
        settings.setJavaScriptEnabled(true);
        settings.setSupportZoom(true);
        settings.setBuiltInZoomControls(true);
        originalView.setWebViewClient(new WebViewClient() {
            @Override
            public void onPageFinished(final WebView webView, final String url) {
                view.findViewById(R.id.OriginalProgress).setVisibility(View.GONE);
            }

            @Override
            public void onPageStarted(final WebView webView, final String url, final Bitmap favicon) {
                if (!showMobilized) {
                    view.findViewById(R.id.OriginalProgress).setVisibility(View.VISIBLE);
                }
            }

            @Override
            public boolean shouldOverrideUrlLoading(final WebView webView, final String url) {
                webView.loadUrl(url);
                return false;
            }
        });
    }

    if (isMobilized) {
        showMobilizedPage();
    } else {
        showOriginalPage();
    }

    view.findViewById(R.id.BtnMobilzedPage).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View view) {
            showMobilizedPage();
        }
    });
    view.findViewById(R.id.BtnOriginalPage).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View view) {
            showOriginalPage();
        }
    });
    view.findViewById(R.id.BtnClose).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View view) {
            if (listener != null) {
                listener.onBackNeeded();
            }
        }
    });
}

From source file:nodomain.freeyourgadget.gadgetbridge.activities.ExternalPebbleJSActivity.java

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

    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        mGBDevice = extras.getParcelable(GBDevice.EXTRA_DEVICE);
        appUuid = (UUID) extras.getSerializable(DeviceService.EXTRA_APP_UUID);
    } else {//from w  ww . j  av a 2  s . c  o  m
        throw new IllegalArgumentException("Must provide a device when invoking this activity");
    }

    setContentView(R.layout.activity_external_pebble_js);

    myWebView = (WebView) findViewById(R.id.configureWebview);
    myWebView.clearCache(true);
    myWebView.setWebViewClient(new GBWebClient());
    myWebView.setWebChromeClient(new GBChromeClient());
    WebSettings webSettings = myWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    //needed to access the DOM
    webSettings.setDomStorageEnabled(true);
    //needed for localstorage
    webSettings.setDatabaseEnabled(true);

    JSInterface gbJSInterface = new JSInterface(this);
    myWebView.addJavascriptInterface(gbJSInterface, "GBjs");

    myWebView.loadUrl("file:///android_asset/app_config/configure.html");

}

From source file:com.btmura.android.reddit.app.LinkFragment.java

@SuppressLint("SetJavaScriptEnabled")
private void setupWebView(WebView webView) {
    WebSettings settings = webView.getSettings();
    settings.setBuiltInZoomControls(true);
    settings.setDisplayZoomControls(false);
    settings.setDomStorageEnabled(true);
    settings.setJavaScriptEnabled(true);
    settings.setLoadWithOverviewMode(true);
    settings.setSupportZoom(true);//w  w w.  j av a 2s .  c  o  m
    settings.setPluginState(PluginState.ON_DEMAND);
    settings.setUseWideViewPort(true);

    webView.setOnLongClickListener(this);

    webView.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            if (progress != null) {
                progress.setVisibility(View.VISIBLE);
            }
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            if (progress != null) {
                progress.setVisibility(View.GONE);
            }
        }
    });

    webView.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            if (progress != null) {
                progress.setProgress(newProgress);
            }
        }
    });
}

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

private void setUpWebViewDefaults(WebView webView) {
    WebSettings settings = webView.getSettings();

    // Enable Javascript
    settings.setJavaScriptEnabled(true);

    //to make the webview faster
    //settings.setCacheMode(WebSettings.LOAD_NO_CACHE);

    // Use WideViewport and Zoom out if there is no viewport defined
    settings.setUseWideViewPort(true);//from   w ww  .  ja va  2 s.  c om
    settings.setLoadWithOverviewMode(true);

    // Enable pinch to zoom without the zoom buttons
    settings.setBuiltInZoomControls(true);

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

    // Enable remote debugging via chrome://inspect
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        WebView.setWebContentsDebuggingEnabled(true);
    }
}

From source file:ca.bitwit.postcard.PostcardAdaptor.java

/**
 * Cordova Plugin Overrides//from   ww  w .j  a  va2s.co m
 */

public PostcardAdaptor(Activity activity, WebView webView) {
    Log.d("PostcardApplication", "Initialized");
    NetworksManager.INSTANCE.adaptor = this;
    this.activity = activity;
    this.webView = webView;

    Context context = activity.getApplicationContext();

    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webView.addJavascriptInterface(this, "PostcardApplication");
    webView.loadUrl("file:///android_asset/www/index.html");

    this.properties = new Properties();
    String propFileName = "postcard.properties";

    try {
        InputStream inputStream = context.getAssets().open(propFileName);
        if (inputStream != null) {
            this.properties.load(inputStream);
        } else {
            throw new FileNotFoundException("property file '" + propFileName + "' not found in the classpath");
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

    this.networkAccountDataSource = new NetworkAccountDataSource(context);
    this.networkAccountDataSource.open();

    this.personDataSource = new PersonDataSource(context);
    this.personDataSource.open();

    this.tagDataSource = new TagDataSource(context);
    this.tagDataSource.open();
}

From source file:com.pixate.freestyle.viewdemo.ViewDetailFragment.java

@SuppressLint("SetJavaScriptEnabled")
@Override/*from   w w w .  j  a  va2s .  c  o m*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View rootView = inflater.inflate(R.layout.fragment_view_detail, container, false);

    if (mItem != null) {
        // set the views
        ViewSample viewSample = mItem.getViewSample();
        final ViewGroup viewsHolder = (ViewGroup) rootView.findViewById(R.id.holder);
        viewSample.createViews(getActivity(), viewsHolder);

        // load the CSS styling for the sample
        String css = ViewsData.getCSS(getActivity(), mItem);

        // Set up syntax highlighting
        WebView cssView = (WebView) rootView.findViewById(R.id.css_style);
        WebSettings s = cssView.getSettings();
        s.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);
        s.setUseWideViewPort(false);
        s.setAllowFileAccess(true);
        s.setBuiltInZoomControls(true);
        s.setSupportZoom(true);
        s.setSupportMultipleWindows(false);
        s.setJavaScriptEnabled(true);

        StringBuilder contentString = new StringBuilder();
        contentString.append("<html><head>");
        contentString.append(
                "<link href='file:///android_asset/prettify/prettify.css' rel='stylesheet' type='text/css'/> ");
        contentString.append(
                "<script src='file:///android_asset/prettify/prettify.js' type='text/javascript'></script> ");
        contentString.append(
                "<script src='file:///android_asset/prettify/lang-css.js' type='text/javascript'></script> ");
        contentString.append("</head><body onload='prettyPrint()'><code class='prettyprint lang-css'>");
        contentString.append(TextUtils.htmlEncode(css).replaceAll("\n", "<br>").replaceAll(" ", "&nbsp;")
                .replaceAll("\t", "&nbsp;&nbsp;"));
        contentString.append("</code> </html> ");
        cssView.getSettings().setUseWideViewPort(true);
        cssView.loadDataWithBaseURL("file:///android_asset/prettify/", contentString.toString(), "text/html",
                StringUtil.EMPTY, StringUtil.EMPTY);

        // to aid in styling the css text shows in the textview, set its
        // ID. Eventually will not be needed.
        if (!"css-style".equals(PixateFreestyle.getStyleId(cssView))) {
            PixateFreestyle.setStyleId(cssView, "css-style", true);
        }

        // Style
        viewSample.style(css);
    }

    return rootView;
}

From source file:com.xamoom.android.xamoomcontentblocks.ViewHolders.ContentBlock2ViewHolder.java

public ContentBlock2ViewHolder(View itemView, Fragment fragment, String youtubeApiKey,
        LruCache<String, Bitmap> bitmapCache) {
    super(itemView);

    mYoutubeApiKey = youtubeApiKey;//www.ja va2  s.  c o m
    mContext = fragment.getContext();
    mFragment = fragment;
    mBitmapCache = bitmapCache;
    mFileManager = FileManager.getInstance(fragment.getContext());

    mTitleTextView = (TextView) itemView.findViewById(R.id.titleTextView);
    mFramelayout = (FrameLayout) itemView.findViewById(R.id.youtube_frame_layout);
    mYouTubeThumbnailView = (YouTubeThumbnailView) itemView.findViewById(R.id.youtube_thumbnail_view);
    mVideoWebView = (WebView) itemView.findViewById(R.id.videoWebView);
    mVideoWebView.setWebViewClient(new WebViewClient());
    mWebViewOverlay = itemView.findViewById(R.id.webViewOverlay);
    mVideoPlayImageView = (ImageView) itemView.findViewById(R.id.video_play_image_view);
    mProgressBar = (ProgressBar) itemView.findViewById(R.id.video_progress_bar);
    mVideoView = (VideoView) itemView.findViewById(R.id.videoView);
    mIntent = null;

    itemView.setOnClickListener(this);

    WebSettings webSettings = mVideoWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
}

From source file:com.cihon.androidrestart_keven.activity.WebViewActivity.java

/**
 * ?webview/*ww w  .ja  v a 2s. com*/
 */
public void initWebView() {
    MyWebViewClient webViewClient = new MyWebViewClient();
    mWebView.setWebViewClient(webViewClient);
    WebSettings webSettings = mWebView.getSettings();

    //??
    webSettings.setLoadWithOverviewMode(true);
    //?webview?
    webSettings.setUseWideViewPort(true);
    //??
    webSettings.setBuiltInZoomControls(true);
    webSettings.setSupportZoom(true);
    webSettings.setJavaScriptEnabled(true);

    //        mWebView.loadUrl("http://webservice.cihon.cn/onStarActive1/reupload.html");
    mWebView.loadUrl("http://123.57.60.91/onStar3/vehicle-License.html");
    //        mWebView.loadUrl("http://wxpay.wxutil.com/mch/pay/h5.v2.php");

    //        jsjava
    mWebView.addJavascriptInterface(new JsInterface(this), "demo");
}

From source file:org.tomahawk.libtomahawk.resolver.ScriptAccount.java

public ScriptAccount(String path, boolean manuallyInstalled) {
    String prefix = manuallyInstalled ? "file://" : "file:///android_asset";
    mPath = prefix + path;//  w  ww . jav a  2 s  . co  m
    mManuallyInstalled = manuallyInstalled;
    String[] parts = mPath.split("/");
    mName = parts[parts.length - 1];
    try {
        InputStream inputStream;
        if (mManuallyInstalled) {
            File metadataFile = new File(path + File.separator + "content" + File.separator + "metadata.json");
            inputStream = new FileInputStream(metadataFile);
        } else {
            inputStream = TomahawkApp.getContext().getAssets()
                    .open(path.substring(1) + "/content/metadata.json");
        }
        String metadataString = IOUtils.toString(inputStream, Charsets.UTF_8);
        mMetaData = GsonHelper.get().fromJson(metadataString, ScriptResolverMetaData.class);
        if (mMetaData == null) {
            Log.e(TAG, "Couldn't read metadata.json. Cannot instantiate ScriptAccount.");
            return;
        }
    } catch (IOException e) {
        Log.e(TAG, "ScriptAccount: " + e.getClass() + ": " + e.getLocalizedMessage());
        Log.e(TAG, "Couldn't read metadata.json. Cannot instantiate ScriptAccount.");
        return;
    }

    mWebView = new WebView(TomahawkApp.getContext());
    WebSettings settings = mWebView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setDatabaseEnabled(true);
    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        //noinspection deprecation
        settings.setDatabasePath(TomahawkApp.getContext().getDir("databases", Context.MODE_PRIVATE).getPath());
    }
    settings.setDomStorageEnabled(true);
    mWebView.setWebChromeClient(new TomahawkWebChromeClient());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        mWebView.getSettings().setAllowUniversalAccessFromFileURLs(true);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        WebView.setWebContentsDebuggingEnabled(true);
    }

    new Handler(Looper.getMainLooper()).post(new Runnable() {
        @Override
        public void run() {
            //initalize WebView
            String data = "<!DOCTYPE html>" + "<html>" + "<head><title>" + mName + "</title></head>" + "<body>"
                    + "<script src=\"file:///android_asset/js/rsvp-latest.min.js"
                    + "\" type=\"text/javascript\"></script>"
                    + "<script src=\"file:///android_asset/js/cryptojs-core.js"
                    + "\" type=\"text/javascript\"></script>";
            if (mMetaData.manifest.scripts != null) {
                for (String scriptPath : mMetaData.manifest.scripts) {
                    data += "<script src=\"" + mPath + "/content/" + scriptPath
                            + "\" type=\"text/javascript\"></script>";
                }
            }
            try {
                String[] cryptoJsScripts = TomahawkApp.getContext().getAssets().list("js/cryptojs");
                for (String scriptPath : cryptoJsScripts) {
                    data += "<script src=\"file:///android_asset/js/cryptojs/" + scriptPath
                            + "\" type=\"text/javascript\"></script>";
                }
            } catch (IOException e) {
                Log.e(TAG, "ScriptResolver: " + e.getClass() + ": " + e.getLocalizedMessage());
            }
            data += "<script src=\"file:///android_asset/js/tomahawk_android_pre.js"
                    + "\" type=\"text/javascript\"></script>"
                    + "<script src=\"file:///android_asset/js/tomahawk.js"
                    + "\" type=\"text/javascript\"></script>"
                    + "<script src=\"file:///android_asset/js/tomahawk-infosystem.js"
                    + "\" type=\"text/javascript\"></script>"
                    + "<script src=\"file:///android_asset/js/tomahawk_android_post.js"
                    + "\" type=\"text/javascript\"></script>" + "<script src=\"" + mPath + "/content/"
                    + mMetaData.manifest.main + "\" type=\"text/javascript\"></script>" + "</body></html>";
            mWebView.setWebViewClient(new ScriptWebViewClient(ScriptAccount.this));
            mWebView.addJavascriptInterface(new ScriptInterface(ScriptAccount.this), SCRIPT_INTERFACE_NAME);
            mWebView.loadDataWithBaseURL("file:///android_asset/test.html", data, "text/html", null, null);
        }
    });
}

From source file:com.ubuntuone.android.files.activity.StoreActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setActionBarContentView(R.layout.activity_store);

    webView = (WebView) findViewById(R.id.webview);
    webView.setWebViewClient(new ContainedWebViewClient());
    webView.setScrollBarStyle(WebView.SCROLLBARS_INSIDE_OVERLAY);

    final WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);

    mHandler = new Handler();
    mReceiver = new DetachableResultReceiver(mHandler);

    setUpActionBar();//from w  w  w  .  j  av  a 2s .  com

    if (!NetworkUtil.isConnected(this)) {
        showDialog(DIALOG_NO_NETWORK_ID);
        return;
    }

    mLoginTask = new LoginTask();
    mLoginTask.execute();

    mTracker = GoogleAnalyticsTracker.getInstance();
    mTracker.start(Analytics.U1F_ACCOUNT, this);
    mTracker.trackPageView(TAG);
}