List of usage examples for android.webkit WebView loadData
public void loadData(String data, @Nullable String mimeType, @Nullable String encoding)
From source file:at.ac.tuwien.detlef.fragments.PlayerFragment.java
private PlayerFragment setEpisodeInfoControls(Episode ep) { View view = getView();/*from w ww. j a v a 2 s. c om*/ if (view == null) { return this; } WebView episodeDescription = (WebView) getView().findViewById(R.id.playerEpisodeDescription); TextView podcast = (TextView) getView().findViewById(R.id.playerPodcast); TextView episode = (TextView) getView().findViewById(R.id.playerEpisode); podcastIcon = (ImageView) getView().findViewById(R.id.imageView1); if ((ep == null) && (service != null)) { ep = service.getNextEpisode(); } // reset episodeDescription in any case, otherwise there will // be problems if html text is refreshed. episodeDescription.loadData("", "text/html; charset=UTF-8", null); if (ep == null) { episode.setText(getActivity().getText(R.string.no_episode_selected).toString()); podcast.setText(""); podcastIcon.setImageDrawable(getResources().getDrawable(R.drawable.ic_feed_icon)); } else { episodeDescription.loadData("", "text/html; charset=UTF-8", null); episodeDescription.loadData(ep.getDescription() == null ? "" : ep.getDescription(), "text/html; charset=UTF-8", null); podcast.setText(ep.getPodcast().getTitle() == null ? "" : ep.getPodcast().getTitle()); episode.setText(ep.getTitle() == null ? "" : ep.getTitle()); remainingTime.setText("-00:00"); alreadyPlayed.setText("00:00"); seekBar.setMax(1); seekBar.setProgress(0); seekBar.setSecondaryProgress(0); setNotPlayingSeekBarAndTime(ep); podcastIcon.setImageDrawable(ep.getPodcast().getLogoIcon()); } return this; }
From source file:com.xiaoxin.apktools.view.CustomWebViewDialog.java
@NonNull @Override/*from w w w .jav a 2s .c om*/ public Dialog onCreateDialog(Bundle savedInstanceState) { final View customView; try { customView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_webview, null); } catch (InflateException e) { throw new IllegalStateException("This device does not support Web Views."); } String dialogTitle = getArguments().getString("dialogTitle"); AlertDialog dialog = new AlertDialog.Builder(getActivity()).setTitle(dialogTitle).setView(customView) .setPositiveButton(android.R.string.ok, null).show(); final WebView webView = (WebView) customView.findViewById(R.id.webview); webView.getSettings().setDefaultTextEncodingName("utf-8"); try { String htmlFileName = getArguments().getString("htmlFileName"); StringBuilder buf = new StringBuilder(); InputStream json = getActivity().getAssets().open(htmlFileName); BufferedReader in = new BufferedReader(new InputStreamReader(json, "UTF-8")); String str; while ((str = in.readLine()) != null) buf.append(str); in.close(); final int accentColor = getArguments().getInt("accentColor"); String formatLodString = buf.toString() .replace("{style-placeholder}", "body { background-color: #ffffff; color: #000; }") .replace("{link-color}", colorToHex(shiftColor(accentColor, true))) .replace("{link-color-active}", colorToHex(accentColor)); webView.loadDataWithBaseURL(null, formatLodString, "text/html", "UTF-8", null); } catch (Throwable e) { webView.loadData("<h1>Unable to load</h1><p>" + e.getLocalizedMessage() + "</p>", "text/html", "UTF-8"); } return dialog; }
From source file:com.facebook.react.views.webview.ReactWebViewManager.java
@ReactProp(name = "source") public void setSource(WebView view, @Nullable 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);/* w w w . j a v a 2s .c o m*/ } else { view.loadData(html, HTML_MIME_TYPE, HTML_ENCODING); } return; } if (source.hasKey("uri")) { String url = source.getString("uri"); String previousUrl = view.getUrl(); if (previousUrl != null && previousUrl.equals(url)) { return; } 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); }
From source file:name.gudong.translate.widget.WebDialog.java
@NonNull @Override//from www . j a va2s . c o m public Dialog onCreateDialog(Bundle savedInstanceState) { final View customView; try { customView = LayoutInflater.from(getActivity()).inflate(R.layout.layout_about_dialog, null); } catch (InflateException e) { throw new IllegalStateException("This device does not support Web Views."); } String dialogTitle = getArguments().getString("dialogTitle"); String neutralText = getArguments().getString("neutralText"); String positiveText = getArguments().getString("positiveText"); neutralText = TextUtils.isEmpty(neutralText) ? "" : neutralText; positiveText = TextUtils.isEmpty(neutralText) ? getString(android.R.string.ok) : positiveText; AlertDialog dialog = new AlertDialog.Builder(getActivity()).setTitle(dialogTitle).setView(customView) .setNeutralButton(neutralText, mNeutralClickCallback) .setPositiveButton(positiveText, mPositiveClickCallback).show(); final WebView webView = (WebView) customView.findViewById(R.id.webview); webView.getSettings().setDefaultTextEncodingName("utf-8"); try { String htmlFileName = getArguments().getString("htmlFileName"); StringBuilder buf = new StringBuilder(); InputStream json = getActivity().getAssets().open(htmlFileName); BufferedReader in = new BufferedReader(new InputStreamReader(json, "UTF-8")); String str; while ((str = in.readLine()) != null) buf.append(str); in.close(); final int accentColor = getArguments().getInt("accentColor"); String formatLodString = buf.toString() .replace("{style-placeholder}", "body { background-color: #ffffff; color: #000; }") .replace("{link-color}", colorToHex(shiftColor(accentColor, true))) .replace("{link-color-active}", colorToHex(accentColor)); webView.loadDataWithBaseURL(null, formatLodString, "text/html", "UTF-8", null); } catch (Throwable e) { webView.loadData("<h1>Unable to load</h1><p>" + e.getLocalizedMessage() + "</p>", "text/html", "UTF-8"); } return dialog; }
From source file:com.gudong.appkit.ui.fragment.CustomWebViewDialog.java
@NonNull @Override//from ww w.ja va 2s.c om public Dialog onCreateDialog(Bundle savedInstanceState) { final View customView; try { customView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_webview, null); } catch (InflateException e) { throw new IllegalStateException("This device does not support Web Views."); } String dialogTitle = getArguments().getString("dialogTitle"); String neutralText = getArguments().getString("neutralText"); String positiveText = getArguments().getString("positiveText"); neutralText = TextUtils.isEmpty(neutralText) ? "" : neutralText; positiveText = TextUtils.isEmpty(neutralText) ? getString(android.R.string.ok) : positiveText; AlertDialog dialog = new AlertDialog.Builder(getActivity()).setTitle(dialogTitle).setView(customView) .setNeutralButton(neutralText, mNeutralClickCallback) .setPositiveButton(positiveText, mPositiveClickCallback).show(); final WebView webView = (WebView) customView.findViewById(R.id.webview); webView.getSettings().setDefaultTextEncodingName("utf-8"); try { String htmlFileName = getArguments().getString("htmlFileName"); StringBuilder buf = new StringBuilder(); InputStream json = getActivity().getAssets().open(htmlFileName); BufferedReader in = new BufferedReader(new InputStreamReader(json, "UTF-8")); String str; while ((str = in.readLine()) != null) buf.append(str); in.close(); final int accentColor = getArguments().getInt("accentColor"); String formatLodString = buf.toString() .replace("{style-placeholder}", "body { background-color: #ffffff; color: #000; }") .replace("{link-color}", colorToHex(shiftColor(accentColor, true))) .replace("{link-color-active}", colorToHex(accentColor)); webView.loadDataWithBaseURL(null, formatLodString, "text/html", "UTF-8", null); } catch (Throwable e) { webView.loadData("<h1>Unable to load</h1><p>" + e.getLocalizedMessage() + "</p>", "text/html", "UTF-8"); } return dialog; }
From source file:com.yang.bruce.mumuxi.util.WebDialog.java
@NonNull @Override//from w ww .ja va 2s . com public Dialog onCreateDialog(Bundle savedInstanceState) { final View customView; try { customView = LayoutInflater.from(getActivity()).inflate(R.layout.layout_about_dialog, null); } catch (InflateException e) { throw new IllegalStateException("This device does not support Web Views."); } String dialogTitle = getArguments().getString("dialogTitle"); String neutralText = getArguments().getString("neutralText"); String positiveText = getArguments().getString("positiveText"); neutralText = TextUtils.isEmpty(neutralText) ? "" : neutralText; positiveText = TextUtils.isEmpty(neutralText) ? getString(android.R.string.ok) : positiveText; AlertDialog dialog = new AlertDialog.Builder(getActivity()).setTitle(dialogTitle).setView(customView) .setNeutralButton(neutralText, mNeutralClickCallback) .setPositiveButton(positiveText, mPositiveClickCallback).show(); final WebView webView = (WebView) customView.findViewById(R.id.webview); setWebView(webView, customView.getContext()); try { String htmlFileName = getArguments().getString("htmlFileName"); StringBuilder buf = new StringBuilder(); InputStream json = getActivity().getAssets().open(htmlFileName); BufferedReader in = new BufferedReader(new InputStreamReader(json, "UTF-8")); String str; while ((str = in.readLine()) != null) buf.append(str); in.close(); final int accentColor = getArguments().getInt("accentColor"); String formatLodString = buf.toString() .replace("{style-placeholder}", "body { background-color: #ffffff; color: #000; }") .replace("{link-color}", colorToHex(shiftColor(accentColor, true))) .replace("{link-color-active}", colorToHex(accentColor)); webView.loadDataWithBaseURL(null, formatLodString, "text/html", "UTF-8", null); } catch (Throwable e) { webView.loadData("<h1>Unable to load</h1><p>" + e.getLocalizedMessage() + "</p>", "text/html", "UTF-8"); } return dialog; }
From source file:org.quizreader.android.PageReadActivity.java
/** Called when the activity is first created. */ @SuppressLint("SetJavaScriptEnabled") @Override//from w w w . j a va2 s . co m public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.page_read); // immediately pop up loading dialog dialog = new ProgressDialog(this); dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); dialog.setMessage("loading page"); dialog.show(); // set up webview WebView webview = (WebView) findViewById(R.id.webView); webview.setWebViewClient(new QRWebViewClient()); webview.setWebChromeClient(new WebChromeClient() { public boolean onConsoleMessage(ConsoleMessage cm) { Log.d("QuizReader", cm.message() + ", line " + cm.lineNumber() + " " + cm.sourceId()); return true; } }); WebSettings webSettings = webview.getSettings(); webSettings.setJavaScriptEnabled(true); webview.addJavascriptInterface(new QuizReaderInterface(), "qr"); try { random = new Random(); wordDao = new WordDao(this); qzzFile = new QzzFile(title.getFilepath(), this); URL htmlURL = qzzFile.getHTML(title.getId(), title.getSection()); if (htmlURL == null) { // beyond the last section setResult(RESULT_END_TITLE); finish(); } String externalForm = htmlURL.toExternalForm(); webview.loadUrl(externalForm + "?paragraph=" + title.getParagraph()); } catch (Exception ex) { webview.loadData(ex.toString(), "text/plain", null); } }
From source file:emu.project64.AboutActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.about_activity); // Add the tool bar to the activity (which supports the fancy menu/arrow animation) Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); toolbar.setTitle(getString(R.string.app_name) + " " + NativeExports.appVersion()); setSupportActionBar(toolbar);/*w w w. java 2 s.c o m*/ ActionBar actionbar = getSupportActionBar(); if (AndroidDevice.IS_ICE_CREAM_SANDWICH) { actionbar.setHomeButtonEnabled(true); actionbar.setDisplayHomeAsUpEnabled(true); } View aboutMain = findViewById(R.id.about_main); WebView webView = (WebView) findViewById(R.id.webview); List<View> lists = Arrays.asList(aboutMain, webView); String[] titles = new String[] { Strings.GetString(LanguageStringID.ANDROID_ABOUT), Strings.GetString(LanguageStringID.ANDROID_ABOUT_LICENCE) }; ViewPager viewPager = (ViewPager) findViewById(R.id.pager); viewPager.setOffscreenPageLimit(MODE_TOTAL - 1); viewPager.setAdapter(new AboutPagerAdapter(lists, titles)); TabLayout tabLayout = (TabLayout) findViewById(R.id.sliding_tabs); tabLayout.setupWithViewPager(viewPager); TextView link = (TextView) findViewById(R.id.main_link); link.setText(Html.fromHtml(getString(R.string.about_link))); TextView app_name_full = (TextView) findViewById(R.id.app_name_full); app_name_full.setText(Strings.GetString(LanguageStringID.ANDROID_ABOUT_APP_NAME)); TextView about_text = (TextView) findViewById(R.id.about_text); about_text.setText(Strings.GetString(LanguageStringID.ANDROID_ABOUT_TEXT)); TextView Project64_authors = (TextView) findViewById(R.id.Project64_authors); Project64_authors.setText(Strings.GetString(LanguageStringID.ANDROID_ABOUT_PJ64_AUTHORS)); webView.loadData(Utility.readAsset("licence.htm", ""), "text/html", "UTF8"); }
From source file:com.android.talkback.controller.CursorControllerAppTest.java
private void loadWebViewFromResource(WebView webView, int resourceId) { InputStream inputStream = getActivity().getResources().openRawResource(resourceId); BufferedReader br = new BufferedReader(new InputStreamReader(inputStream)); String webContent = ""; String tmp = ""; try {/* ww w . j a v a 2 s . c o m*/ while (tmp != null) { webContent += tmp; tmp = br.readLine(); } } catch (IOException e) { Log.e(CursorControllerAppTest.this.getName(), "Cannot read from file."); } webView.loadData(webContent, "text/html", null); }
From source file:org.sigimera.app.android.MainActivity.java
/** * Shows the about dialog./* w w w . j a v a 2 s. c o m*/ */ public final void showAboutDialog() { AlertDialog dialog = new AlertDialog.Builder(MainActivity.this).create(); dialog.setTitle("About"); dialog.setButton(AlertDialog.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { dialog.cancel(); } }); WebView wv = new WebView(this); wv.setBackgroundColor(Color.BLACK); StringBuffer strbuffer = new StringBuffer(); strbuffer.append("<small><font color='white'>"); strbuffer.append("<h3 style='text-align: center'>" + this.getString(R.string.app_name) + "</h3>"); strbuffer.append("<p>This is the official App of the Crises " + "Information Platform Sigimera. It provides " + "the following functionality:</p>"); strbuffer.append("<ul>"); strbuffer.append("<li>Get crises (natural disaster) information." + "Currently floods, earthquakes, cyclones " + "and volcanic erruptions.</li>"); strbuffer.append("<li>Get crises alerts via push notifications.</li>"); strbuffer.append("<li>Get new crises via push notifications.</li>"); strbuffer.append("<li>Manage your App via " + "<a href='http://www.sigimera.org/mobile_devices'>" + "<span style='color: #00FFFF'>mobile device management" + "website </span></a>."); strbuffer.append("</ul>"); strbuffer.append("<p>© 2013 <a href='http://www.sigimera.com'>" + "<span style='color: #00FFFF'>Sigimera Ltd.</span></a>. " + "All rights reserved.</p>"); wv.loadData(strbuffer.toString(), "text/html", "utf-8"); dialog.setView(wv); dialog.show(); }