Example usage for android.webkit WebView loadDataWithBaseURL

List of usage examples for android.webkit WebView loadDataWithBaseURL

Introduction

In this page you can find the example usage for android.webkit WebView loadDataWithBaseURL.

Prototype

public void loadDataWithBaseURL(@Nullable String baseUrl, String data, @Nullable String mimeType,
        @Nullable String encoding, @Nullable String historyUrl) 

Source Link

Document

Loads the given data into this WebView, using baseUrl as the base URL for the content.

Usage

From source file:org.mdc.chess.MDChess.java

private void aboutDialog() {
    //AlertDialog.Builder builder = new AlertDialog.Builder(this);
    String title = getString(R.string.app_name);
    WebView wv = new WebView(this);
    //builder.setView(wv);
    InputStream is = getResources().openRawResource(R.raw.about);
    String data = Util.readFromStream(is);
    if (data == null) {
        data = "";
    }//from  w  ww  . j a va2  s .c  o m
    try {
        is.close();
    } catch (IOException e1) {
        Log.d("Exception", e1.toString());
    }
    wv.loadDataWithBaseURL(null, data, "text/html", "utf-8", null);
    try {
        PackageInfo pi = getPackageManager().getPackageInfo("org.mdc.chess", 0);
        title += " " + pi.versionName;
    } catch (NameNotFoundException e) {
        Log.d("Exception", e.toString());
    }
    new MaterialDialog.Builder(this).title(title).customView(wv, true).show();
}

From source file:org.petero.droidfish.DroidFish.java

private final Dialog aboutDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    String title = getString(R.string.app_name);
    WebView wv = new WebView(this);
    builder.setView(wv);//from   w  ww. j  a va 2 s .c  o  m
    InputStream is = getResources().openRawResource(R.raw.about);
    String data = Util.readFromStream(is);
    if (data == null)
        data = "";
    try {
        is.close();
    } catch (IOException e1) {
    }
    wv.loadDataWithBaseURL(null, data, "text/html", "utf-8", null);
    try {
        PackageInfo pi = getPackageManager().getPackageInfo("org.petero.droidfish", 0);
        title += " " + pi.versionName;
    } catch (NameNotFoundException e) {
    }
    builder.setTitle(title);
    AlertDialog alert = builder.create();
    return alert;
}

From source file:com.fsck.k9.activity.Accounts.java

private void onAbout() {
    String appName = getString(R.string.app_name);
    int year = Calendar.getInstance().get(Calendar.YEAR);
    WebView wv = new WebView(this);
    StringBuilder html = new StringBuilder()
            .append("<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" />")
            .append("<img src=\"file:///android_asset/icon.png\" alt=\"").append(appName).append("\"/>")
            .append("<h1>")
            .append(String.format(getString(R.string.about_title_fmt),
                    "<a href=\"" + getString(R.string.app_webpage_url)) + "\">")
            .append(appName).append("</a>").append("</h1><p>").append(appName).append(" ")
            .append(String.format(getString(R.string.debug_version_fmt), getVersionNumber())).append("</p><p>")
            .append(String.format(getString(R.string.app_authors_fmt), getString(R.string.app_authors)))
            .append("</p><p>")
            .append(String.format(getString(R.string.app_revision_fmt),
                    "<a href=\"" + getString(R.string.app_revision_url) + "\">"
                            + getString(R.string.app_revision_url) + "</a>"))
            .append("</p><hr/><p>")
            .append(String.format(getString(R.string.app_copyright_fmt), year, year, year))
            .append("</p><hr/><p>").append(getString(R.string.app_license)).append("</p><hr/><p>");

    StringBuilder libs = new StringBuilder().append("<ul>");
    for (String[] library : USED_LIBRARIES) {
        libs.append("<li><a href=\"").append(library[1]).append("\">").append(library[0]).append("</a></li>");
    }//from w w  w  .  j a  v  a 2  s .  com
    libs.append("</ul>");

    html.append(String.format(getString(R.string.app_libraries), libs.toString())).append("</p><hr/><p>")
            .append(String.format(getString(R.string.app_emoji_icons),
                    "<div>TypePad \u7d75\u6587\u5b57\u30a2\u30a4\u30b3\u30f3\u753b\u50cf "
                            + "(<a href=\"http://typepad.jp/\">Six Apart Ltd</a>) / "
                            + "<a href=\"http://creativecommons.org/licenses/by/2.1/jp/\">CC BY 2.1</a></div>"))
            .append("</p><hr/><p>").append(getString(R.string.app_htmlcleaner_license));

    wv.loadDataWithBaseURL("file:///android_res/drawable/", html.toString(), "text/html", "utf-8", null);
    new AlertDialog.Builder(this).setView(wv).setCancelable(true)
            .setPositiveButton(R.string.okay_action, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface d, int c) {
                    d.dismiss();
                }
            }).setNeutralButton(R.string.changelog_full_title, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface d, int c) {
                    new ChangeLog(Accounts.this).getFullLogDialog().show();
                }
            }).show();
}

From source file:edu.mit.viral.shen.DroidFish.java

private final Dialog aboutDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    String title = getString(R.string.app_name);
    WebView wv = new WebView(this);
    builder.setView(wv);//from   w w  w.  ja v a2  s  .  c o m
    InputStream is = getResources().openRawResource(R.raw.about);
    String data = Util.readFromStream(is);
    if (data == null)
        data = "";
    try {
        is.close();
    } catch (IOException e1) {
    }
    wv.loadDataWithBaseURL(null, data, "text/html", "utf-8", null);
    try {
        PackageInfo pi = getPackageManager().getPackageInfo("edu.mit.viral.shen", 0);
        title += " " + pi.versionName;
    } catch (NameNotFoundException e) {
    }
    builder.setTitle(title);
    AlertDialog alert = builder.create();
    return alert;
}

From source file:com.theartball.theartball.AboutActivity.java

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_about);
    final ActionBar actionBar = getSupportActionBar();
    actionBar.setBackgroundDrawable(new ColorDrawable(Color.argb(255, 11, 120, 228)));

    WebView aboutWebView = (WebView) findViewById(R.id.aboutText);
    String aboutText = "<span style='color:#ffffff;font-size:10pt;'><img width='100%%' src='http://theartball.com/images/logo-vodoravno.png' /> "
            + "The Artball is application by freestylers for freestylers! <br> <br>It will help you stay in touch with the latest news and videos from the Freestyle Football world."
            + "<br> You will also be able to read great articles about trainings, equipment, freestyle thoughts and freestyle life in general. "
            + "All articles are written by freestylers themselves. <br><br> Application is developed by: <br><br> Uros Zivaljevic from Serbia <br> Mario Plantosar from Croatia <br><br>"
            + " If you are interested in helping The Artball by writing news, or you have article that you want to be published in application, please contact us on: "
            + "<br><br> contact@theartball.com <br><br> Follow us on other social networks: <div style='width:65%%; margin:0 auto'><br><br><a href='https://instagram.com/theartball'>"
            + "<img width='30%%' src='http://theartball.com/images/instagram-icon.png'></a><a href='https://www.facebook.com/theartball'>"
            + "<img width='30%%' src='http://theartball.com/images/facebook-icon.png'/></a><a href='https://twitter.com/TheArtball'>"
            + "<img width='30%%' src='http://theartball.com/images/twitter-icon.png'></a></div> <br><br><br>Open Source Libraries: <br><br><u>Picasso</u><br><br><div style='background-color:#6DAEEF;'><br>"
            + "Copyright 2013 Square, Inc.<br><br>\n" + "\n"
            + "Licensed under the Apache License, Version 2.0 (the \"License\");\n"
            + "you may not use this file except in compliance with the License.\n"
            + "You may obtain a copy of the License at<br><br>\n" + "\n"
            + "   http://www.apache.org/licenses/LICENSE-2.0 <br><br>\n" + "\n"
            + "Unless required by applicable law or agreed to in writing, software\n"
            + "distributed under the License is distributed on an \"AS IS\" BASIS,\n"
            + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n"
            + "See the License for the specific language governing permissions and\n"
            + "limitations under the License.<br><br></div><br><br><br><u>PhotoView</u><br><br><div style='background-color:#6DAEEF;'><br>Copyright 2011, 2012 Chris Banes<br><br>\n"
            + "\n" + "Licensed under the Apache License, Version 2.0 (the \"License\");\n"
            + "you may not use this file except in compliance with the License.\n"
            + "You may obtain a copy of the License at<br><br>\n" + "\n"
            + "   http://www.apache.org/licenses/LICENSE-2.0 <br><br>" + "\n"
            + "Unless required by applicable law or agreed to in writing, software\n"
            + "distributed under the License is distributed on an \"AS IS\" BASIS,\n"
            + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n"
            + "See the License for the specific language governing permissions and\n"
            + "limitations under the License.<br><br></div><br><br><br><u>AsymmetricGridView</u><br><br><div style='background-color:#6DAEEF;'><br>Copyright (c) 2011-2014 Felipe Lima<br><br>\n"
            + "\n" + "Permission is hereby granted, free of charge, to any person obtaining a copy\n"
            + "of this software and associated documentation files (the \"Software\"), to deal\n"
            + "in the Software without restriction, including without limitation the rights\n"
            + "to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n"
            + "copies of the Software, and to permit persons to whom the Software is\n"
            + "furnished to do so, subject to the following conditions:<br><br>\n" + "\n"
            + "The above copyright notice and this permission notice shall be included in\n"
            + "all copies or substantial portions of the Software.<br><br>\n" + "\n"
            + "THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n"
            + "IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n"
            + "FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n"
            + "AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n"
            + "LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n"
            + "OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n"
            + "THE SOFTWARE.<br><br></div></span>";

    aboutWebView.loadDataWithBaseURL("", aboutText, "text/html", "UTF-8", "");
    aboutWebView.setBackgroundColor(ContextCompat.getColor(this, R.color.mainBlue));
}

From source file:com.if3games.chessonline.DroidFish.java

private final Dialog aboutDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    String title = getString(R.string.app_name);
    WebView wv = new WebView(this);
    builder.setView(wv);//w  w  w  .  j  a  v a  2  s.  c  o  m
    InputStream is = getResources().openRawResource(R.raw.about);
    String data = Util.readFromStream(is);
    if (data == null)
        data = "";
    try {
        is.close();
    } catch (IOException e1) {
    }
    wv.loadDataWithBaseURL(null, data, "text/html", "utf-8", null);
    try {
        PackageInfo pi = getPackageManager().getPackageInfo("com.if3games.chessonline", 0);
        title += " " + pi.versionName;
    } catch (NameNotFoundException e) {
    }
    builder.setTitle(title);
    AlertDialog alert = builder.create();
    return alert;
}

From source file:com.bernard.beaconportal.activities.activity.MessageList.java

private void onAbout() {
    String appName = getString(R.string.app_name);
    int year = Calendar.getInstance().get(Calendar.YEAR);
    WebView wv = new WebView(this);
    StringBuilder html = new StringBuilder()
            .append("<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" />")
            .append("<img src=\"file:///android_asset/icon.png\" alt=\"").append(appName).append("\"/>")
            .append("<h1>")
            .append(String.format(getString(R.string.about_title_fmt),
                    "<a href=\"" + getString(R.string.app_webpage_url)) + "\">")
            .append(appName).append("</a>").append("</h1><p>").append(appName).append(" ")
            .append(String.format(getString(R.string.debug_version_fmt), getVersionNumber())).append("</p><p>")
            .append(String.format(getString(R.string.app_authors_fmt), getString(R.string.app_authors)))
            .append("</p><p>")
            .append(String.format(getString(R.string.app_revision_fmt),
                    "<a href=\"" + getString(R.string.app_revision_url) + "\">"
                            + getString(R.string.app_revision_url) + "</a>"))
            .append("</p><hr/><p>").append(String.format(getString(R.string.app_copyright_fmt), year, year))
            .append("</p><hr/><p>").append(getString(R.string.app_license)).append("</p><hr/><p>");

    StringBuilder libs = new StringBuilder().append("<ul>");
    for (String[] library : USED_LIBRARIES) {
        libs.append("<li><a href=\"").append(library[1]).append("\">").append(library[0]).append("</a></li>");
    }/*from   ww  w. j  av a  2 s.  com*/
    libs.append("</ul>");

    html.append(String.format(getString(R.string.app_libraries), libs.toString())).append("</p><hr/><p>")
            .append(String.format(getString(R.string.app_emoji_icons),
                    "<div>TypePad \u7d75\u6587\u5b57\u30a2\u30a4\u30b3\u30f3\u753b\u50cf "
                            + "(<a href=\"http://typepad.jp/\">Six Apart Ltd</a>) / "
                            + "<a href=\"http://creativecommons.org/licenses/by/2.1/jp/\">CC BY 2.1</a></div>"))
            .append("</p><hr/><p>").append(getString(R.string.app_htmlcleaner_license));

    wv.loadDataWithBaseURL("file:///android_res/drawable/", html.toString(), "text/html", "utf-8", null);
    new AlertDialog.Builder(this).setView(wv).setCancelable(true)
            .setPositiveButton(R.string.okay_action, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface d, int c) {
                    d.dismiss();
                }
            }).setNeutralButton(R.string.changelog_full_title, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface d, int c) {
                    new ChangeLog(MessageList.this).getFullLogDialog().show();
                }
            }).show();
}