List of usage examples for android.webkit WebView loadDataWithBaseURL
public void loadDataWithBaseURL(@Nullable String baseUrl, String data, @Nullable String mimeType, @Nullable String encoding, @Nullable String historyUrl)
From source file:de.uni_weimar.m18.anatomiederstadt.element.LatexFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View root = inflater.inflate(R.layout.fragment_latex, container, false); WebView latexView = (WebView) root.findViewById(R.id.latexWebView); latexView.getSettings().setJavaScriptEnabled(true); latexView.getSettings().setBuiltInZoomControls(false); TypedValue typedValue = new TypedValue(); Resources.Theme theme = getActivity().getTheme(); theme.resolveAttribute(R.color.windowBackgroundColor, typedValue, true); latexView.setBackgroundColor(typedValue.data); latexView.loadDataWithBaseURL("http://bar", "<script type='text/x-mathjax-config'>" + "MathJax.Hub.Config({ " + "messageStyle: 'none'," + "showMathMenu: false, " + "jax: ['input/TeX','output/HTML-CSS'], " + "extensions: ['tex2jax.js'], " + "TeX: { extensions: ['AMSmath.js','AMSsymbols.js'," + "'noErrors.js','noUndefined.js'] } " + "});</script>" + "<script type='text/javascript' " + "src='file:///android_asset/MathJax/MathJax.js'" + "></script><span id='math'></span>", "text/html", "utf-8", ""); Log.v(LOG_TAG, "Loading latexCode: " + mLatexCode); latexView.setWebViewClient(new WebViewClient() { private String mLatexCode = null; @Override// ww w. j a va 2 s. c o m public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); if (Build.VERSION.SDK_INT < 19) { view.loadUrl("javascript:document.getElementById('math').innerHTML='\\\\[" + doubleEscapeTeX(getLatexCode()) + "\\\\]'"); view.loadUrl("javascript:MathJax.Hub.Queue(['Typeset',MathJax.Hub]);"); } else { view.evaluateJavascript("javascript:document.getElementById('math').innerHTML='\\\\[" + doubleEscapeTeX(getLatexCode()) + "\\\\]'", null); view.evaluateJavascript("javascript:MathJax.Hub.Queue(['Typeset',MathJax.Hub]);", null); } } }); return root; }
From source file:com.androidquery.simplefeed.fragments.CommentFragment.java
private void renderNote(FeedItem item) { PQuery aq = super.aq.id(header).find(R.id.note_box); Entity from = item.getFrom(); aq.id(R.id.name).text(from.getName()); aq.id(R.id.subject).text(item.getSubject()); aq.id(R.id.meta).text(item.getCachedTime(System.currentTimeMillis())); String tb = from.getTb();//from w ww . j a v a 2s .c o m aq.id(R.id.tb).image(tb, true, true, 0, R.drawable.ic_menu_report_image, null, AQuery.FADE_IN_NETWORK); String body = item.getMessage(); body = patchImg(body); AQUtility.debug("body", body); WebView wv = aq.id(R.id.web).visible().getWebView(); wv.loadDataWithBaseURL(null, body, "text/html", "utf-8", null); aq.id(R.id.content_box).gone(); renderCount(); }
From source file:org.apache.taverna.mobile.ui.anouncements.AnnouncementFragment.java
@Override public void showAnnouncementDetail(DetailAnnouncement detailAnnouncement) { mAnnouncementDetail = detailAnnouncement; AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getContext()); LayoutInflater inflater = getActivity().getLayoutInflater(); View dialogView = inflater.inflate(R.layout.detail_annoucement_dialog_layout, null); dialogBuilder.setView(dialogView);//from w ww.j ava2 s . c o m TextView title = ButterKnife.findById(dialogView, R.id.tvDialogTitle); TextView date = ButterKnife.findById(dialogView, R.id.tvDialogDate); TextView author = ButterKnife.findById(dialogView, R.id.tvDialogAuthor); WebView text = ButterKnife.findById(dialogView, R.id.wvDialogText); Button buttonOk = ButterKnife.findById(dialogView, R.id.bDialogOK); buttonOk.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); } }); text.loadDataWithBaseURL("", mAnnouncementDetail.getText(), "text/html", "utf-8", ""); date.setText(mAnnouncementDetail.getDate()); title.setText(mAnnouncementDetail.getTitle()); author.setText(mAnnouncementDetail.getAuthor().getContent()); alertDialog = dialogBuilder.create(); alertDialog.show(); }
From source file:com.ivalentin.margolariak.SettingsLayout.java
private void showDialog(String title, String text) { //Create the dialog final Dialog dialog = new Dialog(getActivity()); //Set up dialog window dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.dialog_settings); //Set the custom dialog components - text, image and button TextView tvTitle = (TextView) dialog.findViewById(R.id.tv_dialog_settings_title); WebView wvText = (WebView) dialog.findViewById(R.id.wv_dialog_settings_text); if (Build.VERSION.SDK_INT >= 19) { wvText.setLayerType(View.LAYER_TYPE_HARDWARE, null); } else {/*from w w w . ja va2s. co m*/ wvText.setLayerType(View.LAYER_TYPE_SOFTWARE, null); } Button btClose = (Button) dialog.findViewById(R.id.bt_dialog_settings_close); //Set text tvTitle.setText(title); wvText.loadDataWithBaseURL(null, text, "text/html", "utf-8", null); //Set close button btClose.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); //Set parameters WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(dialog.getWindow().getAttributes()); lp.width = WindowManager.LayoutParams.MATCH_PARENT; lp.height = WindowManager.LayoutParams.WRAP_CONTENT; lp.gravity = Gravity.CENTER; lp.dimAmount = 0.4f; dialog.getWindow().setAttributes(lp); //Show dialog dialog.show(); }
From source file:in.rab.bildkort.DefinitionFragment.java
public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); String definition = getArguments().getString("definition"); Boolean isHtml = getArguments().getBoolean("isHtml"); mEditText = (EditText) getView().findViewById(R.id.editText); WebView webView = (WebView) getView().findViewById(R.id.webView); if (isHtml) { // Anki centers text by default, which is not optimal for large HTML // chunks such as those we get from NE. definition = "<div style=\"text-align: left\">" + definition + "</div>"; mEditText.setVisibility(View.GONE); webView.setVisibility(View.VISIBLE); } else {/*from w ww. ja v a 2 s . c o m*/ mEditText.setVisibility(View.VISIBLE); webView.setVisibility(View.GONE); } mEditText.setText(definition); webView.loadDataWithBaseURL("http://fake", definition, "text/html", "UTF-8", null); }
From source file:de.qabel.qabelbox.fragments.WelcomeDisclaimerFragment.java
private void setClickListener(View fragmentView, int view, final Type mode) { fragmentView.findViewById(view).setOnClickListener(new View.OnClickListener() { @Override//from w w w. j av a 2 s .com public void onClick(View v) { WebView webView = new WebView(getActivity()); String file = ""; if (mode == Type.QAPL) { file = getResources().getString(R.string.FILE_QAPL_LICENSE); } if (mode == Type.PRIVACY) { file = getResources().getString(R.string.FILE_PRIVACY); } if (mode == Type.LEGAL) { file = getResources().getString(R.string.FILE_LEGAL); } webView.loadDataWithBaseURL("file:///android_asset/", FileHelper.loadFileFromAssets(getActivity(), "html/help/" + file), "text/html", "utf-8", null); UIHelper.showCustomDialog(getActivity(), webView, R.string.ok, null); } }); }
From source file:org.indywidualni.centrumfm.util.ChangeLog.java
/** * Create a dialog containing (parts of the) change log. * * @param full If this is {@code true} the full change log is displayed. Otherwise only changes for * versions newer than the last version are displayed. * @return A dialog containing the (partial) change log. *///w ww.j a v a 2s .c o m protected AlertDialog getDialog(final boolean full) { WebView wv = new WebView(mContext); //wv.setBackgroundColor(0); // transparent wv.loadDataWithBaseURL(null, getLog(full), "text/html", "UTF-8", null); AlertDialog.Builder builder = new AlertDialog.Builder(mContext); builder.setTitle( mContext.getResources().getString(full ? R.string.changelog_full_title : R.string.changelog_title)) .setView(wv).setCancelable(false) // OK button .setPositiveButton(mContext.getResources().getString(R.string.changelog_ok_button), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // The user clicked "OK" so save the current version code as // "last version code". updateVersionInPreferences(); } }); if (!full) { // Show "More" button if we're only displaying a partial change log. builder.setNegativeButton(R.string.changelog_show_full, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { getFullLogDialog().show(); } }); } final AlertDialog dialog = builder.create(); dialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface arg0) { dialog.getButton(AlertDialog.BUTTON_POSITIVE) .setTextColor(ContextCompat.getColor(mContext, R.color.colorAccent)); if (!full) { dialog.getButton(AlertDialog.BUTTON_NEGATIVE) .setTextColor(ContextCompat.getColor(mContext, R.color.colorAccent)); } } }); return dialog; }
From source file:org.apache.taverna.mobile.ui.favouriteworkflowdetail.FavouriteWorkflowDetailFragment.java
@Override public void showLicense(License license) { AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getContext()); LayoutInflater inflater = getActivity().getLayoutInflater(); View dialogView = inflater.inflate(R.layout.dialog_licence_detail_workflow, null); dialogBuilder.setView(dialogView);/*from w w w . j ava 2s . co m*/ TextView title = ButterKnife.findById(dialogView, R.id.tvDialogTitle); TextView date = ButterKnife.findById(dialogView, R.id.tvDialogDate); WebView text = ButterKnife.findById(dialogView, R.id.wvDialogText); Button buttonOk = ButterKnife.findById(dialogView, R.id.bDialogOK); buttonOk.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); } }); text.loadDataWithBaseURL("", license.getDescription(), "text/html", "utf-8", ""); date.setText(license.getCreatedAt().substring(0, license.getCreatedAt().indexOf(' '))); title.setText(license.getTitle()); alertDialog = dialogBuilder.create(); alertDialog.show(); }
From source file:im.vector.adapters.ImagesSliderAdapter.java
private void loadImage(WebView webView, Uri imageUri, String viewportContent, String css) { String html = "<html><head><meta name='viewport' content='" + viewportContent + "'/>" + "<style type='text/css'>" + css + "</style></head>" + "<body> <div class='wrap'>" + "<img " + ("src='" + imageUri.toString() + "'") + " onerror='this.style.display=\"none\"' id='image' " + viewportContent + "/>" + "</div>" + "</body>" + "</html>"; String mime = "text/html"; String encoding = "utf-8"; webView.loadDataWithBaseURL(null, html, mime, encoding, null); webView.requestLayout();// w w w.ja v a2s .c o m }
From source file:de.dreier.mytargets.features.scoreboard.ScoreboardActivity.java
@TargetApi(Build.VERSION_CODES.KITKAT) private void print() { // Get a print adapter instance final WebView webViewPrint = new WebView(this); webViewPrint.setVisibility(View.INVISIBLE); ViewGroup.LayoutParams p = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); webViewPrint.setLayoutParams(p);//from w w w . java 2 s . co m ((ViewGroup) binding.getRoot()).addView(webViewPrint); new AsyncTask<Void, Void, String>() { @Override protected String doInBackground(Void... params) { return HtmlUtils.getScoreboard(mTraining, mRound, ScoreboardConfiguration.fromPrintSettings()); } @SuppressWarnings("deprecation") @Override protected void onPostExecute(String s) { webViewPrint.loadDataWithBaseURL("file:///android_asset/", s, "text/html", "UTF-8", ""); PrintDocumentAdapter printAdapter = webViewPrint.createPrintDocumentAdapter(); // Create a print job with name and adapter instance PrintManager printManager = (PrintManager) getSystemService(PRINT_SERVICE); String jobName = getString(R.string.scoreboard) + " Document"; printManager.print(jobName, printAdapter, new PrintAttributes.Builder().build()); } }.execute(); }