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:com.android.mail.ui.LicensesActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.licenses_activity);

    // Enable back navigation
    final ActionBar actionBar = getActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }//w  ww .j  a  va 2 s .  c  o m

    InputStream input = null;
    String licenseHTML = null;
    try {
        // read the raw license String from the license HTML file
        input = getResources().openRawResource(R.raw.licenses);
        final String license = IOUtils.toString(input, "UTF-8");

        // encode the license string for display as HTML in the webview
        licenseHTML = URLEncoder.encode(license, "UTF-8").replace("+", "%20");
    } catch (IOException e) {
        LogUtils.e(LogTag.getLogTag(), e, "Error reading licence file");
    } finally {
        if (input != null) {
            try {
                input.close();
            } catch (IOException ioe) {
                // best attempt only
            }
        }
    }

    // set the license HTML into the webview
    final WebView webview = (WebView) findViewById(R.id.webview);
    webview.loadData(licenseHTML, "text/html", null);
}

From source file:eu.geopaparazzi.library.core.fragments.AboutFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    try {//ww  w  .j a v  a 2s.c  o m
        AssetManager assetManager = getActivity().getAssets();
        InputStream inputStream = assetManager.open("about.html");
        String htmlText = new Scanner(inputStream).useDelimiter("\\A").next();

        String applicationName = "Geopaparazzi";
        try {
            applicationName = ResourcesManager.getInstance(getActivity()).getApplicationName();
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (packageName != null) {
            String version = "";
            try {
                PackageInfo pInfo = getActivity().getPackageManager().getPackageInfo(packageName,
                        PackageManager.GET_META_DATA);
                version = pInfo.versionName;
            } catch (NameNotFoundException e) {
                e.printStackTrace();
            }

            htmlText = htmlText.replaceFirst("VERSION", version);
        } else {
            htmlText = htmlText.replaceFirst("VERSION", "");
        }

        htmlText = htmlText.replaceAll("Geopaparazzi", applicationName);

        WebView aboutView = (WebView) view;
        aboutView.loadData(htmlText, "text/html", "utf-8");
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.amfontai.cmput301asn1.WordCloud.java

/**
 * On resuming the activity, we query the DB,
 * which uses {@link import org.mcavallo.opencloud}
 * to generate the HTML for the WebView/*from   w ww .  ja v a  2s  .  c  o m*/
 * @see android.app.Activity#onResume()
 */
protected void onResume() {
    super.onResume();

    WebView web = (WebView) findViewById(R.id.cloud);

    String html = mDb.getWordCloud();

    web.loadData(html, "text/html", null);
}

From source file:zack.yovel.clear.controller.foreground.HelpFragment.java

private View getCustomContent() {
    LayoutInflater inflater = getActivity().getLayoutInflater();
    View customContent = inflater.inflate(R.layout.fragment_help, null, false);
    WebView wvHelp = (WebView) customContent.findViewById(R.id.wvHelp);
    String helpHtmlString = getHelpHtmlEvenIfException();
    wvHelp.loadData(helpHtmlString, "text/html", "UTF-8");
    return customContent;
}

From source file:com.commonsware.android.print.MainActivity.java

private void printReport() {
    Template tmpl = Mustache.compiler().compile(getString(R.string.report_body));
    WebView print = prepPrintWebView(getString(R.string.tps_report));

    print.loadData(tmpl.execute(new TpsReportContext(prose.getText().toString())), "text/html", "UTF-8");
}

From source file:com.fastbootmobile.encore.app.fragments.SettingsFragment.java

private void openLicenses() {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    String text = getString(R.string.licenses);
    text = "<pre>" + text + "</pre>";
    text = text.replaceAll("\n", "<br />");

    WebView view = new WebView(getActivity());
    view.loadData(text, "text/html", "UTF-8");

    builder.setView(view);//ww  w.  java  2  s . c  om
    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    builder.show();
}

From source file:org.videolan.vlc.gui.AboutFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ((AppCompatActivity) getActivity()).getSupportActionBar().setTitle("VLC " + BuildConfig.VERSION_NAME);
    View v = inflater.inflate(R.layout.about, container, false);

    View aboutMain = v.findViewById(R.id.about_main);
    WebView t = (WebView) v.findViewById(R.id.webview);
    String revision = getString(R.string.build_revision);
    t.loadData(Util.readAsset("licence.htm", "").replace("!COMMITID!", revision), "text/html", "UTF8");

    TextView link = (TextView) v.findViewById(R.id.main_link);
    link.setText(Html.fromHtml(this.getString(R.string.about_link)));

    String builddate = getString(R.string.build_time);
    String builder = getString(R.string.build_host);

    TextView compiled = (TextView) v.findViewById(R.id.main_compiled);
    compiled.setText(builder + " (" + builddate + ")");
    TextView textview_rev = (TextView) v.findViewById(R.id.main_revision);
    textview_rev.setText(getResources().getString(R.string.revision) + " " + revision + " (" + builddate + ")");

    final ImageView logo = (ImageView) v.findViewById(R.id.logo);
    logo.setOnClickListener(new OnClickListener() {
        @Override//from  w ww  .  ja  v  a  2s  .  c o m
        public void onClick(View v) {
            AnimationSet anim = new AnimationSet(true);
            RotateAnimation rotate = new RotateAnimation(0f, 360f, Animation.RELATIVE_TO_SELF, 0.5f,
                    Animation.RELATIVE_TO_SELF, 0.5f);
            rotate.setDuration(800);
            rotate.setInterpolator(new DecelerateInterpolator());
            anim.addAnimation(rotate);
            logo.startAnimation(anim);
        }
    });

    List<View> lists = Arrays.asList(aboutMain, t);
    String[] titles = new String[] { getString(R.string.about), getString(R.string.licence) };
    mViewPager = (ViewPager) v.findViewById(R.id.pager);
    mViewPager.setOffscreenPageLimit(MODE_TOTAL - 1);
    mViewPager.setAdapter(new AudioPagerAdapter(lists, titles));

    mTabLayout = (TabLayout) v.findViewById(R.id.sliding_tabs);
    mTabLayout.setupWithViewPager(mViewPager);

    return v;
}

From source file:org.jprofit.wsfscanner.ScannerActivity.java

private void updateWebView() {
    WebView myWebView = (WebView) findViewById(R.id.webview);
    myWebView.loadData((webViewContent == null) ? "" : webViewContent, "text/html", "UTF-8");
}

From source file:com.example.ccrvlz.dcp.detail.DetailCardFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (null != rootView) {
        ViewGroup parent = (ViewGroup) rootView.getParent();
        if (null != parent) {
            parent.removeView(rootView);
        }/*from w w  w.  j  a  v a  2 s .  c  o  m*/
    } else {
        rootView = inflater.inflate(R.layout.dcp_detail_card_layout, container, false);
        //////////////rootView
        WebView webView = (WebView) rootView.findViewById(R.id.web_dcp_detail_card);
        //String html = "<html><body><font>html5 test<br>html5 test<br>html5 test<br>html5 test<br></font></body></html>";
        webView.loadData(data, "text/html", "UTF-8");
    }
    return rootView;
}

From source file:net.toload.main.hd.ui.NewsDialog.java

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle icicle) {

    getDialog().getWindow().setTitle(getResources().getString(R.string.action_news));

    mLIMEPref = new LIMEPreferenceManager(getActivity());

    view = inflater.inflate(R.layout.fragment_dialog_news, container, false);

    String html_value = mLIMEPref.getParameterString(Lime.LIME_NEWS_CONTENT, "");
    if (!html_value.isEmpty()) {
        WebView newsContentArea = (WebView) view.findViewById(R.id.newsContentArea);
        newsContentArea.getSettings().setJavaScriptEnabled(true);
        newsContentArea.loadData(html_value, "text/html", "UTF-8");
    }/*from  w w  w  .  j a  v  a2  s . co m*/

    btnHelpDialog = (Button) view.findViewById(R.id.btnNewsDialog);
    btnHelpDialog.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dismiss();
        }
    });

    return view;

}