Example usage for android.webkit WebView loadData

List of usage examples for android.webkit WebView loadData

Introduction

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

Prototype

public void loadData(String data, @Nullable String mimeType, @Nullable String encoding) 

Source Link

Document

Loads the given data into this WebView using a 'data' scheme URL.

Usage

From source file:cz.suhail.rainyday.MainActivity.java

private void aboutDialog() {
    AlertDialog.Builder alert = new AlertDialog.Builder(this);
    alert.setTitle("rainyday");
    final WebView webView = new WebView(this);
    String about = "<p>A lightweight, opensource weather app.</p>"
            + "<p>Developed by <a href='https://www.suhailpurkar.io'>Suhail Purkar</a></p>"
            + "<p>Data provided by <a href='http://openweathermap.org/'>OpenWeatherMap</a>, under the <a href='http://creativecommons.org/licenses/by-sa/2.0/'>Creative Commons license</a>"
            + "<p>Icons are <a href='https://erikflowers.github.io/weather-icons/'>Weather Icons</a>, by <a href='http://www.twitter.com/artill'>Lukas Bischoff</a> and <a href='http://www.twitter.com/Erik_UX'>Erik Flowers</a>, under the <a href='http://scripts.sil.org/OFL'>SIL OFL 1.1</a> licence.";
    if (darkTheme) {
        // Style text color for dark theme
        about = "<style media=\"screen\" type=\"text/css\">" + "body {\n" + "    color:white;\n" + "}\n"
                + "a:link {color:cyan}\n" + "</style>" + about;
    }//from   w  w w  . jav  a2s  .co m
    webView.setBackgroundColor(Color.TRANSPARENT);
    webView.loadData(about, "text/html", "UTF-8");
    alert.setView(webView, 32, 0, 32, 0);
    alert.setPositiveButton(R.string.dialog_ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {

        }
    });
    alert.show();
}

From source file:cz.martykan.forecastie.MainActivity.java

private void aboutDialog() {
    AlertDialog.Builder alert = new AlertDialog.Builder(this);
    alert.setTitle("Forecastie");
    final WebView webView = new WebView(this);
    String about = "<p>A lightweight, opensource weather app.</p>"
            + "<p>Developed by <a href='mailto:t.martykan@gmail.com'>Tomas Martykan</a></p>"
            + "<p>Data provided by <a href='http://openweathermap.org/'>OpenWeatherMap</a>, under the <a href='http://creativecommons.org/licenses/by-sa/2.0/'>Creative Commons license</a>"
            + "<p>Icons are <a href='https://erikflowers.github.io/weather-icons/'>Weather Icons</a>, by <a href='http://www.twitter.com/artill'>Lukas Bischoff</a> and <a href='http://www.twitter.com/Erik_UX'>Erik Flowers</a>, under the <a href='http://scripts.sil.org/OFL'>SIL OFL 1.1</a> licence.";
    if (darkTheme) {
        // Style text color for dark theme
        about = "<style media=\"screen\" type=\"text/css\">" + "body {\n" + "    color:white;\n" + "}\n"
                + "a:link {color:cyan}\n" + "</style>" + about;
    }/*from   w  ww.j a  v  a  2 s.  co m*/
    webView.setBackgroundColor(Color.TRANSPARENT);
    webView.loadData(about, "text/html", "UTF-8");
    alert.setView(webView, 32, 0, 32, 0);
    alert.setPositiveButton(R.string.dialog_ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {

        }
    });
    alert.show();
}

From source file:com.lcl.thumbweather.MainActivity.java

private void aboutDialog() {
    AlertDialog.Builder alert = new AlertDialog.Builder(this);
    alert.setTitle("ThumbWeather");
    final WebView webView = new WebView(this);
    String about = "<p>A light,open source App.</p>"
            + "<p>Data provided by <a href='http://openweathermap.org/'>OpenWeatherMap</a>, under the <a href='http://creativecommons.org/licenses/by-sa/2.0/'>Creative Commons license</a>"
            + "<p>Icons are <a href='https://erikflowers.github.io/weather-icons/'>Weather Icons</a>, by <a href='http://www.twitter.com/artill'>Lukas Bischoff</a> and <a href='http://www.twitter.com/Erik_UX'>Erik Flowers</a>, under the <a href='http://scripts.sil.org/OFL'>SIL OFL 1.1</a> licence.";
    if (darkTheme) {
        // Style text color for dark theme
        about = "<style media=\"screen\" type=\"text/css\">" + "body {\n" + "    color:white;\n" + "}\n"
                + "a:link {color:cyan}\n" + "</style>" + about;
    }/*from  w  w w  . ja  v  a2s  .  co m*/
    webView.setBackgroundColor(Color.TRANSPARENT);
    webView.loadData(about, "text/html", "UTF-8");
    alert.setView(webView, 32, 0, 32, 0);
    alert.setPositiveButton(R.string.dialog_ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {

        }
    });
    alert.show();
}

From source file:ru.frostdev.weather.MainActivity.java

private void aboutDialog() {
    AlertDialog.Builder alert = new AlertDialog.Builder(this);
    alert.setTitle("About");
    final WebView webView = new WebView(this);
    String about = "<p>A lightweight, opensource weather app.</p>"
            + "<p>Developed by <a href='FrostDev:mrfrost2035@gmail.com'>FrostDev</a></p>"
            + "<p>Data provided by <a href='http://openweathermap.org/'>OpenWeatherMap</a>, under the <a href='http://creativecommons.org/licenses/by-sa/2.0/'>Creative Commons license</a>"
            + "<p>Icons are <a href='https://erikflowers.github.io/weather-icons/'>Weather Icons</a>, by <a href='http://www.twitter.com/artill'>Lukas Bischoff</a> and <a href='http://www.twitter.com/Erik_UX'>Erik Flowers</a>, under the <a href='http://scripts.sil.org/OFL'>SIL OFL 1.1</a> licence.";
    if (darkTheme) {
        // Style text color for dark theme
        about = "<style media=\"screen\" type=\"text/css\">" + "body {\n" + "    color:white;\n" + "}\n"
                + "a:link {color:cyan}\n" + "</style>" + about;
    }/*from  w  w w . j  a v a2 s  .  c  o m*/
    webView.setBackgroundColor(Color.TRANSPARENT);
    webView.loadData(about, "text/html", "UTF-8");
    alert.setView(webView, 32, 0, 32, 0);
    alert.setPositiveButton(R.string.dialog_ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {

        }
    });
    alert.show();
}

From source file:com.forecast.weather.activities.MainActivity.java

private void aboutDialog() {
    AlertDialog.Builder alert = new AlertDialog.Builder(this);
    alert.setTitle("Forecast Weather");
    final WebView webView = new WebView(this);
    String about = "<p>Forecast weather app.</p>"
            + "<p>Data provided by <a href='http://openweathermap.org/'>OpenWeatherMap</a>, under the <a href='http://creativecommons.org/licenses/by-sa/2.0/'>Creative Commons license</a>"
            + "<p>Icons are <a href='https://erikflowers.github.io/weather-icons/'>Weather Icons</a>, by <a href='http://www.twitter.com/artill'>Lukas Bischoff</a> under the <a href='http://scripts.sil.org/OFL'>SIL OFL 1.1</a> licence.";
    TypedArray ta = obtainStyledAttributes(new int[] { android.R.attr.textColorPrimary, R.attr.colorAccent });
    String textColor = String.format("#%06X", (0xFFFFFF & ta.getColor(0, Color.BLACK)));
    String accentColor = String.format("#%06X", (0xFFFFFF & ta.getColor(1, Color.BLUE)));
    ta.recycle();//from   w  w  w.  j  a v  a  2 s  . c  o  m
    about = "<style media=\"screen\" type=\"text/css\">" + "body {\n" + "    color:" + textColor + ";\n" + "}\n"
            + "a:link {color:" + accentColor + "}\n" + "</style>" + about;
    webView.setBackgroundColor(Color.TRANSPARENT);
    webView.loadData(about, "text/html", "UTF-8");
    alert.setView(webView, 32, 0, 32, 0);
    alert.setPositiveButton(R.string.dialog_ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {

        }
    });
    alert.show();
}

From source file:ir.actfun.toofan.activities.NowWeatherPage.java

private void aboutDialog() {
    AlertDialog.Builder alert = new AlertDialog.Builder(this);
    alert.setTitle("Toofan");
    final WebView webView = new WebView(this);
    String about = "<p>A lightweight, opensource weather app.</p>"
            + "<p>Developed by <a href='mailto:t.martykan@gmail.com'>Tomas Martykan</a></p>"
            + "<p>Data provided by <a href='http://openweathermap.org/'>OpenWeatherMap</a>, under the <a href='http://creativecommons.org/licenses/by-sa/2.0/'>Creative Commons license</a>"
            + "<p>Icons are <a href='https://erikflowers.github.io/weather-icons/'>Weather Icons</a>, by <a href='http://www.twitter.com/artill'>Lukas Bischoff</a> and <a href='http://www.twitter.com/Erik_UX'>Erik Flowers</a>, under the <a href='http://scripts.sil.org/OFL'>SIL OFL 1.1</a> licence.";
    if (darkTheme) {
        // Style text color for dark theme
        about = "<style media=\"screen\" type=\"text/css\">" + "body {\n" + "    color:white;\n" + "}\n"
                + "a:link {color:cyan}\n" + "</style>" + about;
    }/* w  ww .j  a  v a 2s  .  c  o m*/
    webView.setBackgroundColor(Color.TRANSPARENT);
    webView.loadData(about, "text/html", "UTF-8");
    alert.setView(webView, 32, 0, 32, 0);
    alert.setPositiveButton(R.string.dialog_ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {

        }
    });
    alert.show();
}

From source file:com.cs528.style.style.weather.WeatherActivity.java

private void aboutDialog() {
    AlertDialog.Builder alert = new AlertDialog.Builder(this);
    alert.setTitle("Style");
    final WebView webView = new WebView(this);
    String about = "<p>Developed by KuangXIONG, Tengyang Jia, ZhaojunYang</p>"
            + "<p>A cloth suggestion application</p>"
            + "<p>Data provided by <a href='http://openweathermap.org/'>OpenWeatherMap</a>, under the <a href='http://creativecommons.org/licenses/by-sa/2.0/'>Creative Commons license</a>"
            + "<p>Weather Icons are <a href='https://erikflowers.github.io/weather-icons/'>Weather Icons</a>, by <a href='http://www.twitter.com/artill'>Lukas Bischoff</a> and <a href='http://www.twitter.com/Erik_UX'>Erik Flowers</a>, under the <a href='http://scripts.sil.org/OFL'>SIL OFL 1.1</a> licence."
            + "<p>Cloth Icons are <a href='http://pictofoundry.com/'>PictoFoundry Font Pack 2</a>, bought by TengyangJia</p>";
    if (darkTheme) {
        // Style text color for dark theme
        about = "<style media=\"screen\" type=\"text/css\">" + "body {\n" + "    color:white;\n" + "}\n"
                + "a:link {color:cyan}\n" + "</style>" + about;
    }//from  ww w  .  j  ava 2  s. co  m
    webView.setBackgroundColor(Color.TRANSPARENT);
    webView.loadData(about, "text/html", "UTF-8");
    alert.setView(webView, 32, 0, 32, 0);
    alert.setPositiveButton(R.string.dialog_ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {

        }
    });
    alert.show();
}

From source file:arc.noaa.weather.activities.MainActivity.java

private void aboutDialog() {
    AlertDialog.Builder alert = new AlertDialog.Builder(this);
    alert.setTitle("Forecastie");
    final WebView webView = new WebView(this);
    String about = "<p>A lightweight, opensource weather app.</p>"
            + "<p>Developed by <a href='mailto:t.martykan@gmail.com'>Tomas Martykan</a></p>"
            + "<p>Data provided by <a href='http://openweathermap.org/'>OpenWeatherMap</a>, under the <a href='http://creativecommons.org/licenses/by-sa/2.0/'>Creative Commons license</a>"
            + "<p>Icons are <a href='https://erikflowers.github.io/weather-icons/'>Weather Icons</a>, by <a href='http://www.twitter.com/artill'>Lukas Bischoff</a> and <a href='http://www.twitter.com/Erik_UX'>Erik Flowers</a>, under the <a href='http://scripts.sil.org/OFL'>SIL OFL 1.1</a> licence.";
    TypedArray ta = obtainStyledAttributes(new int[] { android.R.attr.textColorPrimary, R.attr.colorAccent });
    String textColor = String.format("#%06X", (0xFFFFFF & ta.getColor(0, Color.BLACK)));
    String accentColor = String.format("#%06X", (0xFFFFFF & ta.getColor(1, Color.BLUE)));
    ta.recycle();/*from  w w  w  . j a  va  2 s  .c om*/
    about = "<style media=\"screen\" type=\"text/css\">" + "body {\n" + "    color:" + textColor + ";\n" + "}\n"
            + "a:link {color:" + accentColor + "}\n" + "</style>" + about;
    webView.setBackgroundColor(Color.TRANSPARENT);
    webView.loadData(about, "text/html", "UTF-8");
    alert.setView(webView, 32, 0, 32, 0);
    alert.setPositiveButton(R.string.dialog_ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {

        }
    });
    alert.show();
}

From source file:cz.suhail.Rainyday.activities.MainActivity.java

private void aboutDialog() {
    AlertDialog.Builder alert = new AlertDialog.Builder(this);
    alert.setTitle("Rainyday");
    final WebView webView = new WebView(this);
    String about = "<p>A lightweight, opensource weather app.</p>"
            + "<p>Developed by <a href='https://www.suhailpurkar.io/'>Suhail Purkar</a></p>"
            + "<p>Data provided by <a href='http://openweathermap.org/'>OpenWeatherMap</a>, under the <a href='http://creativecommons.org/licenses/by-sa/2.0/'>Creative Commons license</a>"
            + "<p>Icons are <a href='https://erikflowers.github.io/weather-icons/'>Weather Icons</a>, by <a href='http://www.twitter.com/artill'>Lukas Bischoff</a> and <a href='http://www.twitter.com/Erik_UX'>Erik Flowers</a>, under the <a href='http://scripts.sil.org/OFL'>SIL OFL 1.1</a> licence.";
    TypedArray ta = obtainStyledAttributes(new int[] { android.R.attr.textColorPrimary, R.attr.colorAccent });
    String textColor = String.format("#%06X", (0xFFFFFF & ta.getColor(0, Color.BLACK)));
    String accentColor = String.format("#%06X", (0xFFFFFF & ta.getColor(1, Color.BLUE)));
    ta.recycle();//from  w  ww .j  av a 2  s  .  c o  m
    about = "<style media=\"screen\" type=\"text/css\">" + "body {\n" + "    color:" + textColor + ";\n" + "}\n"
            + "a:link {color:" + accentColor + "}\n" + "</style>" + about;
    webView.setBackgroundColor(Color.TRANSPARENT);
    webView.loadData(about, "text/html", "UTF-8");
    alert.setView(webView, 32, 0, 32, 0);
    alert.setPositiveButton(R.string.dialog_ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {

        }
    });
    alert.show();
}

From source file:com.bayapps.android.robophish.ui.MediaBrowserFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    LogHelper.d(TAG, "fragment.onCreateView");

    View rootView;/*from www .j ava2s . com*/

    String mediaId = getMediaId();
    ListView listView;

    if (mediaId != null && MediaIDHelper.isShow(mediaId)) {

        setHasOptionsMenu(true); //show option to download

        rootView = inflater.inflate(R.layout.fragment_list_show, container, false);

        ViewPager viewPager = (ViewPager) rootView.findViewById(R.id.viewpager);
        viewPager.setAdapter(new ShowPagerAdapter(inflater, rootView));
        viewPager.setOffscreenPageLimit(3);

        TabLayout tabLayout = (TabLayout) rootView.findViewById(R.id.sliding_tabs);
        tabLayout.setupWithViewPager(viewPager);

        final WebView setlist = (WebView) rootView.findViewById(R.id.setlist_webview);
        setlist.getSettings().setJavaScriptEnabled(true);

        AsyncHttpClient setlistClient = new AsyncHttpClient();
        RequestParams setlistParams = new RequestParams();
        setlistParams.put("api", "2.0");
        setlistParams.put("method", "pnet.shows.setlists.get");
        setlistParams.put("showdate", getSubTitle());
        setlistParams.put("apikey", "C01AEE2002E80723E9E7");
        setlistParams.put("format", "json");
        setlistClient.get("http://api.phish.net/api.js", setlistParams, new JsonHttpResponseHandler() {

            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
                super.onSuccess(statusCode, headers, response);
                try {
                    JSONObject result = response.getJSONObject(0);
                    String city = result.getString("city");
                    String state = result.getString("state");
                    String country = result.getString("country");
                    String venue = result.getString("venue");

                    String header = "<h1>" + venue + "</h1>" + "<h2>" + city + ", " + state + "<br/>" + country
                            + "</h2>";

                    String setlistdata = result.getString("setlistdata");
                    String setlistnotes = result.getString("setlistnotes");
                    setlist.loadData(header + setlistdata + setlistnotes, "text/html", null);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, Throwable throwable,
                    JSONObject errorResponse) {
                super.onFailure(statusCode, headers, throwable, errorResponse);
            }
        });

        final WebView reviews = (WebView) rootView.findViewById(R.id.reviews_webview);
        reviews.getSettings().setJavaScriptEnabled(true);

        AsyncHttpClient reviewsClient = new AsyncHttpClient();
        RequestParams reviewsParams = new RequestParams();
        reviewsParams.put("api", "2.0");
        reviewsParams.put("method", "pnet.reviews.query");
        reviewsParams.put("showdate", getSubTitle());
        reviewsParams.put("apikey", "C01AEE2002E80723E9E7");
        reviewsParams.put("format", "json");
        reviewsClient.get("http://api.phish.net/api.js", reviewsParams, new JsonHttpResponseHandler() {

            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
                super.onSuccess(statusCode, headers, response);
                try {
                    String display = "";

                    int len = response.length();
                    for (int i = 0; i < len; i++) {
                        JSONObject entry = response.getJSONObject(i);
                        String author = entry.getString("author");
                        String review = entry.getString("review");
                        String tstamp = entry.getString("tstamp");

                        Date reviewTime = new Date(Long.parseLong(tstamp) * 1000);
                        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        String reviewDate = dateFormat.format(reviewTime);

                        String reviewSubs = review.replaceAll("\n", "<br/>");

                        display += "<h2>" + author + "</h2>" + "<h4>" + reviewDate + "</h4>";
                        display += reviewSubs + "<br/>";
                    }

                    reviews.loadData(display, "text/html", null);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, Throwable throwable,
                    JSONObject errorResponse) {
                super.onFailure(statusCode, headers, throwable, errorResponse);
            }
        });

        final WebView tapernotesWebview = (WebView) rootView.findViewById(R.id.tapernotes_webview);
        tapernotesWebview.getSettings().setJavaScriptEnabled(true);

        String showId = extractShowFromMediaID(mediaId);
        final AsyncHttpClient tapernotesClient = new AsyncHttpClient();
        tapernotesClient.get("http://phish.in/api/v1/shows/" + showId + ".json", null,
                new JsonHttpResponseHandler() {

                    @Override
                    public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                        super.onSuccess(statusCode, headers, response);
                        try {
                            mShowData = response;
                            JSONObject data = response.getJSONObject("data");
                            String tapernotes = data.getString("taper_notes");
                            if (tapernotes.equals("null"))
                                tapernotes = "Not available";
                            String notesSubs = tapernotes.replaceAll("\n", "<br/>");

                            tapernotesWebview.loadData(notesSubs, "text/html", null);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    public void onFailure(int statusCode, Header[] headers, Throwable throwable,
                            JSONObject errorResponse) {
                        super.onFailure(statusCode, headers, throwable, errorResponse);
                    }
                });

    } else {
        rootView = inflater.inflate(R.layout.fragment_list, container, false);
    }

    mErrorView = rootView.findViewById(R.id.playback_error);
    mErrorMessage = (TextView) mErrorView.findViewById(R.id.error_message);

    mBrowserAdapter = new BrowseAdapter(getActivity());

    listView = (ListView) rootView.findViewById(R.id.list_view);
    listView.setAdapter(mBrowserAdapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            checkForUserVisibleErrors(false);
            MediaBrowserCompat.MediaItem item = mBrowserAdapter.getItem(position);
            mMediaFragmentListener.onMediaItemSelected(item);
        }
    });

    return rootView;
}