Java Code Examples for android.webkit.WebView#loadData()

The following examples show how to use android.webkit.WebView#loadData() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleWebViewActivity.java    From android-test with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle icicle) {
  super.onCreate(icicle);
  WebView mainWebView = new WebView(this);
  setContentView(mainWebView);
  mainWebView.loadData(
      "<html>" +
      "<script>document.was_clicked = false</script>" +
      "<body> " +
      "<button style='height:1000px;width:1000px;' onclick='document.was_clicked = true'> " +
      "I'm a button</button>" +
      "</body> " +
      "</html>", "text/html", null);
  WebSettings settings = mainWebView.getSettings();
  settings.setJavaScriptEnabled(true);
}
 
Example 2
Source File: VersionHistory.java    From edslite with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState)
{
	Util.setTheme(this);
	super.onCreate(savedInstanceState);
	setContentView(R.layout.changes_dialog);
	//setStyle(STYLE_NO_TITLE, R.style.Dialog);
	markAsRead();
	WebView vw = findViewById(R.id.changesWebView);
	vw.loadData(getString(R.string.changes_text), "text/html; charset=UTF-8", null);
	//vw.setBackgroundColor(0);
	//Spanned sp = Html.fromHtml( getString(R.string.promo_text));
	//((TextView)v.findViewById(R.id.promoTextView)).setText(sp);
	//tv.setText(sp);
	//((TextView)v.findViewById(R.id.promoTextView)).setText(Html.fromHtml(getString(R.string.promo_text)));
	findViewById(R.id.okButton).setOnClickListener(v -> finish());
}
 
Example 3
Source File: PreviewFragment.java    From something.apk with MIT License 5 votes vote down vote up
@Override
public void viewCreated(View frag, Bundle savedInstanceState) {
    threadView = (WebView) frag.findViewById(R.id.preview_webview);
    initWebview();
    // TODO: Change back to loadDataWithBaseURL, as it won't load the CSS without it.
    threadView.loadData(this.threadHtml, "text/html", "utf-8");
}
 
Example 4
Source File: ConsentDocumentStepLayout.java    From ResearchStack with Apache License 2.0 5 votes vote down vote up
private void initializeStep() {
    setOrientation(VERTICAL);
    LayoutInflater.from(getContext()).inflate(R.layout.rsb_step_layout_consent_doc, this, true);

    WebView pdfView = (WebView) findViewById(R.id.webview);
    pdfView.loadData(htmlContent, "text/html; charset=UTF-8", null);

    SubmitBar submitBar = (SubmitBar) findViewById(R.id.submit_bar);
    submitBar.setPositiveAction(v -> showDialog());
    submitBar.setNegativeAction(v -> callbacks.onCancelStep());
}
 
Example 5
Source File: ScrollViewDemoActivity.java    From SwipeRefreshLayout with Apache License 2.0 5 votes vote down vote up
protected void setupViews() {
    setupCustomSwipeRefreshLayout();
    WebView webView = (WebView) findViewById(R.id.webview);
    StringBuilder html = new StringBuilder("<html><body>");
    for (int i = 0; i < 20; i++)
        html.append("It's a WebView   It's a WebView   It's a WebView ");
    html.append("</body></html>");
    webView.loadData(html.toString(), "text/html", null);
}
 
Example 6
Source File: PageThreeFragment.java    From RobotCA with GNU General Public License v3.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.pagethree_fragment, container, false);

    WebView webView = (WebView) view.findViewById(R.id.faq_webview);
    webView.loadData(Utils.readText(getActivity(), R.raw.faq), "text/html", null);

    return view;
}
 
Example 7
Source File: AboutFragment.java    From RobotCA with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Called when the activity is created.
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    @SuppressLint("InflateParams") View view = inflater.inflate(R.layout.fragment_about, null);

    WebView webView = (WebView) view.findViewById(R.id.abouttxt);
    webView.loadData(Utils.readText(getActivity(), R.raw.about), "text/html", null);

    return view;
}
 
Example 8
Source File: PageOneFragment.java    From RobotCA with GNU General Public License v3.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
    View view = inflater.inflate(R.layout.pageone_fragment, container, false);

    WebView webView = (WebView) view.findViewById(R.id.setup_webview);
    webView.loadData(Utils.readText(getActivity(), R.raw.setup), "text/html", null);

    return view;
}
 
Example 9
Source File: ArticleActivity.java    From android-discourse with Apache License 2.0 5 votes vote down vote up
@Override
public void finish() {
    // This is what you have to do to make it stop the flash player
    WebView webview = (WebView) findViewById(R.id.uv_webview);
    webview.loadData("", "text/html", "utf-8");
    super.finish();
}
 
Example 10
Source File: WebActivity.java    From mimi-reader with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_web);

    String html = getIntent().getStringExtra(EXTRA_HTML);

    WebView webView = findViewById(R.id.web_view);
    webView.loadData(html, "text/html; charset=UTF-8", null);
}
 
Example 11
Source File: DataUsageActivity.java    From utexas-utilities with Apache License 2.0 5 votes vote down vote up
@Subscribe
public void openWebView(OpenWebViewEvent ev) {
    WebView wv = new WebView(this);
    wv.getSettings().setJavaScriptEnabled(true);
    wv.setWebViewClient(new DataUsageWebViewClient());
    wv.addJavascriptInterface(new JsInterface(), "ututilities");
    wv.loadData(ev.html, "text/html; charset=UTF-8", null);
}
 
Example 12
Source File: Changelog.java    From opensudoku with GNU General Public License v3.0 5 votes vote down vote up
private void showChangelogDialog() {

        String changelog = getChangelogFromResources();

        WebView webView = new WebView(mContext);
        webView.loadData(changelog, "text/html", "utf-8");

        AlertDialog changelogDialog = new AlertDialog.Builder(mContext)
                .setIcon(R.drawable.ic_info)
                .setTitle(R.string.what_is_new)
                .setView(webView)
                .setPositiveButton(R.string.close, null).create();

        changelogDialog.show();
    }
 
Example 13
Source File: AlWebViewActivity.java    From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void webViewClientPost(WebView webView, String url,
                              Collection<Map.Entry<String, String>> postData) {
    StringBuilder sb = new StringBuilder();

    sb.append("<html><head></head>");
    sb.append("<body onload='form1.submit()'>");
    sb.append(String.format("<form id='form1' action='%s' method='%s'>", url, "post"));

    for (Map.Entry<String, String> item : postData) {
        sb.append(String.format("<input name='%s' type='hidden' value='%s' />", item.getKey(), item.getValue()));
    }
    sb.append("</form></body></html>");

    webView.loadData(sb.toString(), "text/html", "utf-8");
}
 
Example 14
Source File: IssueDetailsFragment.java    From magpi-android with MIT License 5 votes vote down vote up
public void updateIssueView(final Issue issue) {
    this.issue = issue;
    TextView issueText = (TextView) getActivity().findViewById(R.id.article);
    issueText.setText(issue.getTitle() + " - " + issue.getDate());
    String htmlArticle = "<img align='left' src='%s' style='margin-right:10px; height:120px; width:90px;'/>%s";
    WebView editorialText = (WebView) getSherlockActivity().findViewById(R.id.text_editorial);
    String content = issue.getEditorial().replace("\r\n", "<br/>").replace("\u00a0", " ");
    editorialText.loadData(String.format(htmlArticle, issue.getCoverUrl(), content), "text/html; charset=utf-8", "utf-8");
    editorialText.setVisibility(View.VISIBLE);
    getSherlockActivity().findViewById(R.id.web_content_progress).setVisibility(View.GONE);
}
 
Example 15
Source File: AboutActivity.java    From bitshares_wallet with MIT License 4 votes vote down vote up
private void loadWebView(WebView webView, int size, String encryptText) {
    String htmlShareAccountName = "<html><head><style>body,html { margin:0; padding:0; text-align:center;}</style><meta name=viewport content=width=" + size + ",user-scalable=no/></head><body><canvas width=" + size + " height=" + size + " data-jdenticon-hash=" + encryptText + "></canvas><script src=https://cdn.jsdelivr.net/jdenticon/1.3.2/jdenticon.min.js async></script></body></html>";
    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webView.loadData(htmlShareAccountName, "text/html", "UTF-8");
}
 
Example 16
Source File: SendFragment.java    From bitshares_wallet with MIT License 4 votes vote down vote up
private void loadWebView(WebView webView, int size, String encryptText) {
    String htmlShareAccountName = "<html><head><style>body,html {margin:0; padding:0; text-align:center;}</style><meta name=viewport content=width=" + size + ",user-scalable=no/></head><body><canvas width=" + size + " height=" + size + " data-jdenticon-hash=" + encryptText + "></canvas><script src=https://cdn.jsdelivr.net/jdenticon/1.3.2/jdenticon.min.js async></script></body></html>";
    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webView.loadData(htmlShareAccountName, "text/html", "UTF-8");
}
 
Example 17
Source File: SettingChangeLogDialog.java    From iBeebo with GNU General Public License v3.0 4 votes vote down vote up
public void show() {
    // Get resources
    String _PackageName = fActivity.getPackageName();
    Resources _Resource;
    try {
        _Resource = fActivity.getPackageManager().getResourcesForApplication(_PackageName);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
        return;
    }

    // Get dialog title
    int _resID = _Resource.getIdentifier(TITLE_CHANGELOG, "string", _PackageName);
    String _Title = _Resource.getString(_resID);
    // _Title = _Title + " v" + GetAppVersion();

    // Get Changelog xml resource id
    _resID = _Resource.getIdentifier(CHANGELOG_XML, "xml", _PackageName);
    // Create html change log
    String _HTML = GetHTMLChangelog(_resID, _Resource);

    // Get button strings
    String _Close = _Resource.getString(R.string.changelog_close);

    // Check for empty changelog
    if (_HTML.equals("") == true) {
        // Could not load change log, message user and exit void
        Toast.makeText(fActivity, "Could not load change log", Toast.LENGTH_SHORT).show();
        return;
    }

    // Create webview and load html
    WebView _WebView = new WebView(fActivity);
    // _WebView.loadData(_HTML, "text/html", "UTF-8");
    _WebView.loadData(_HTML, "text/html; charset=UTF-8", null);

    AlertDialog.Builder builder = new AlertDialog.Builder(fActivity).setTitle(_Title).setView(_WebView)
            .setPositiveButton(_Close, new Dialog.OnClickListener() {
                public void onClick(DialogInterface dialogInterface, int i) {
                    dialogInterface.dismiss();
                }
            });
    builder.create().show();
}
 
Example 18
Source File: Web3WebviewManager.java    From react-native-web3-webview with MIT License 4 votes vote down vote up
@ReactProp(name = "source")
public void setSource(WebView view, @NonNull ReadableMap source) {
    if (source != null) {
        if (source.hasKey("html")) {
            String html = source.getString("html");
            if (source.hasKey("baseUrl")) {
                view.loadDataWithBaseURL(
                        source.getString("baseUrl"), html, HTML_MIME_TYPE, HTML_ENCODING, null);
            } else {
                view.loadData(html, HTML_MIME_TYPE, HTML_ENCODING);
            }
            return;
        }
        if (source.hasKey("uri")) {
            String url = source.getString("uri");
            String previousUrl = view.getUrl();
            if (source.hasKey("method")) {
                String method = source.getString("method");
                if (method.equals(HTTP_METHOD_POST)) {
                    byte[] postData = null;
                    if (source.hasKey("body")) {
                        String body = source.getString("body");
                        try {
                            postData = body.getBytes("UTF-8");
                        } catch (UnsupportedEncodingException e) {
                            postData = body.getBytes();
                        }
                    }
                    if (postData == null) {
                        postData = new byte[0];
                    }
                    view.postUrl(url, postData);
                    return;
                }
            }
            HashMap<String, String> headerMap = new HashMap<>();
            if (source.hasKey("headers")) {
                ReadableMap headers = source.getMap("headers");
                ReadableMapKeySetIterator iter = headers.keySetIterator();
                while (iter.hasNextKey()) {
                    String key = iter.nextKey();
                    if ("user-agent".equals(key.toLowerCase(Locale.ENGLISH))) {
                        if (view.getSettings() != null) {
                            view.getSettings().setUserAgentString(headers.getString(key));
                        }
                    } else {
                        headerMap.put(key, headers.getString(key));
                    }
                }
            }
            view.loadUrl(url, headerMap);
            return;
        }
    }
    view.loadUrl(BLANK_URL);
}
 
Example 19
Source File: ContactListAdapter.java    From smartcoins-wallet with MIT License 4 votes vote down vote up
private void loadWebView(WebView webView, int size, String encryptText) {
    String htmlShareAccountName = "<html><head><style>body,html { margin:0; padding:0; text-align:center;}</style><meta name=viewport content=width=" + size + ",user-scalable=no/></head><body><canvas width=" + size + " height=" + size + " data-jdenticon-hash=" + encryptText + "></canvas><script src=https://cdn.jsdelivr.net/jdenticon/1.3.2/jdenticon.min.js async></script></body></html>";
    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webView.loadData(htmlShareAccountName, "text/html", "UTF-8");
}
 
Example 20
Source File: AboutFragmentRobotChooser.java    From RobotCA with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Called when the activity is  created.
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    @SuppressLint("InflateParams") View view = inflater.inflate(R.layout.fragment_about, null);

    WebView webView = (WebView) view.findViewById(R.id.abouttxt);
    webView.loadData(Utils.readText(getActivity(), R.raw.about), "text/html", null);

    return view;


}