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.poloure.simplerss.Utilities.java

static void showWebFragment(FeedsActivity activity, ViewFeedItem view) {
    WebView webView = s_fragmentWeb.getWebView();
    webView.loadData(view.m_item.m_content, "text/html; charset=UTF-8", null);

    // Read the item.
    activity.readItem(view.m_item.m_time);
    AsyncNavigationAdapter.run(activity);

    // Apply read effect only if it is not in the favourites fragment.
    view.setRead(s_fragmentFeeds.isVisible());

    if (!FeedsActivity.canFitTwoFragments()) {
        switchToFragment(s_fragmentWeb, true);

        // Form the better url.
        String url = view.m_item.m_url;
        int index = url.indexOf('/');
        String urlWithoutHttp = url.substring(-1 == index ? 0 : index + 2);
        String urlWithoutWww = urlWithoutHttp.replace("www.", "");

        // Configure the actionbar.
        s_actionBar.setTitle(urlWithoutWww);
        s_actionBar.setSubtitle(null);//from   www .ja  v a 2 s.co m
        s_actionBar.setIcon(R.drawable.ic_action_web_site);
        s_drawerToggle.setDrawerIndicatorEnabled(false);
        s_drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);

        activity.invalidateOptionsMenu();
    }
}

From source file:eu.trentorise.smartcampus.portfolio.PMHelper.java

private static void showShareDisclaimer(final Portfolio exp, final Activity ctx) {
    WebView wv = new WebView(ctx);
    wv.loadData(ctx.getString(R.string.disclaimer_share), "text/html; charset=UTF-8", "utf-8");
    AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
    builder.setTitle(android.R.string.dialog_alert_title).setView(wv)
            .setOnCancelListener(new DialogInterface.OnCancelListener() {

                @Override/*from  w w  w. java 2  s.  co m*/
                public void onCancel(DialogInterface dialog) {
                    callshare(exp, ctx);
                }
            }).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    callshare(exp, ctx);
                }
            });
    builder.create().show();
}

From source file:com.dabay6.libraries.androidshared.ui.dialogs.changelog.util.ChangeLogDialogUtils.java

/**
 * @param context   {@link Context} used to retrieve resources.
 * @param assetName Name of the asset file containing the change log json.
 * @param style     The css style to be applied to the html.
 * @param callback  The callback to call upon dismissal of the change log alert dialog.
 *
 * @return {@link AlertDialog} used to display the change log.
 *//*from   ww w . ja  v  a2 s  .c  o  m*/
public static AlertDialog createDialog(final Context context, final String assetName, final String style,
        final OnChangeLogDialogListener callback) {
    final AlertDialog.Builder builder;
    final Resources res = context.getResources();
    final String title = res.getString(R.string.change_log_title, AppUtils.getApplicationVersion(context));
    final WebSettings settings;
    final WebView web = new WebView(context);
    String html;

    try {
        html = getHtmlChangeLog(context, assetName, style);

        settings = web.getSettings();
        settings.setSupportZoom(false);
    } catch (final IOException ex) {
        html = StringUtils.empty();

        Logger.error(TAG, ex.getMessage(), ex);
    }

    web.loadData(html, "text/html", "utf-8");

    builder = new AlertDialog.Builder(context);
    builder.setTitle(title).setView(web).setPositiveButton(R.string.change_log_close,
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface dialog, final int which) {
                    dialog.dismiss();
                    if (callback != null) {
                        callback.onChangeLogDismissed();
                    }
                }
            });

    return builder.create();
}

From source file:com.github.dfa.diaspora_android.util.Helpers.java

public static void showAspectList(final WebView wv, final App app) {
    wv.stopLoading();//from  w  ww.  j a va  2 s.co m
    PodUserProfile profile = app.getPodUserProfile();
    StringBuffer sb = new StringBuffer();
    int intColor = ContextCompat.getColor(app, R.color.colorAccent);
    String strColor = String.format("#%06X", (0xFFFFFF & intColor));

    sb.append(
            "<html><body style='width:80%; margin-left:auto;margin-right:auto; font-size: 400%;'><center><b>");
    sb.append(String.format("<h1 style='color: %s; text-shadow: 4px 4px 12px #000000;'>%s</h1>", strColor,
            app.getString(R.string.jb_aspects)));
    sb.append("</b></center>");
    // Content
    for (PodAspect aspect : profile.getAspects()) {
        sb.append("&raquo; &nbsp;");
        sb.append(aspect.toHtmlLink(app));
        sb.append("</br></br>");
    }
    // End
    sb.append("</body></html>");
    wv.loadData(sb.toString(), "text/html", "UTF-16");
}

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

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    View v = inflater.inflate(R.layout.about_licence, container, false);
    String revision = Util.readAsset("revision.txt", "Unknown revision");
    WebView t = (WebView) v.findViewById(R.id.webview);
    t.loadData(Util.readAsset("licence.htm", "").replace("!COMMITID!", revision), "text/html", "UTF8");
    return v;/*from  w w  w  .j  a va 2  s. c  o  m*/
}

From source file:com.android.cts.uiautomator.Test6DetailFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
    View rootView = inflater.inflate(R.layout.test6_detail_fragment, container, false);
    WebView wv = (WebView) rootView.findViewById(R.id.test6WebView);
    wv.loadData(PAGE, "text/html", null);
    return rootView;
}

From source file:org.videolan.myvlc.core.gui.about.AboutLicenceFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    View v = inflater.inflate(R.layout.about_licence, container, false);
    String revision = Util.readAsset("revision.txt", "Unknown revision");
    WebView licenceWebView = (WebView) v.findViewById(R.id.webview);
    licenceWebView.loadData(Util.readAsset("licence.htm", "").replace("!COMMITID!", revision), "text/html",
            "UTF8");
    return v;//from   ww  w  . ja v a2s .  c  o  m
}

From source file:com.github.yuukis.businessmap.app.LicenseDialogFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    String html = AssetUtils.getText(getActivity(), FILEPATH);
    try {/*from   w  ww  .ja  v a  2s . com*/
        html = URLEncoder.encode(html, "utf-8").replaceAll("\\+", "%20");
    } catch (UnsupportedEncodingException e) {
    }
    WebView webView = new WebView(getActivity());
    webView.loadData(html, "text/html", "utf-8");
    return webView;
}

From source file:com.deliciousdroid.fragment.AboutFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    base = (FragmentBaseActivity) getActivity();

    base.setTitle(R.string.about_activity_title);

    WebView content = (WebView) base.findViewById(R.id.about_text_view);
    content.loadData(getString(R.string.about_text), "text/html", "utf-8");

}

From source file:com.apptentive.android.sdk.module.engagement.interaction.fragment.UpgradeMessageFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.apptentive_upgrade_message_interaction, container, false);

    ImageView iconView = (ImageView) v.findViewById(R.id.icon);
    Drawable icon = getIconDrawableResourceId();
    if (icon != null) {
        iconView.setImageDrawable(icon);
    } else {// w ww  .ja  v  a  2 s. c  o m
        iconView.setVisibility(View.GONE);
    }
    WebView webview = (WebView) v.findViewById(R.id.webview);
    webview.loadData(interaction.getBody(), "text/html", "UTF-8");
    webview.setBackgroundColor(Color.TRANSPARENT); // Hack to keep webview background from being colored after load.

    // If branding is not desired, turn the view off.
    final View branding = v.findViewById(R.id.apptentive_branding_view);
    if (branding != null) {
        if (!interaction.isShowPoweredBy() || Configuration.load().isHideBranding(getContext())) {
            branding.setVisibility(View.GONE);
        }
    }

    return v;
}