Example usage for android.webkit WebView loadDataWithBaseURL

List of usage examples for android.webkit WebView loadDataWithBaseURL

Introduction

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

Prototype

public void loadDataWithBaseURL(@Nullable String baseUrl, String data, @Nullable String mimeType,
        @Nullable String encoding, @Nullable String historyUrl) 

Source Link

Document

Loads the given data into this WebView, using baseUrl as the base URL for the content.

Usage

From source file:net.naonedbus.utils.InfoDialogUtils.java

/**
 * Afficher une dialog avec un contenu au format HTML
 * /* www. j ava 2s  . c o m*/
 * @param context
 * @param html
 */
public static void showHtml(final Context context, final String html) {
    AlertDialog.Builder moreDetailsDialog = null;
    final WebView webView = new WebView(context);
    final ScrollView scrollView = new ScrollView(context);

    webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    webView.setBackgroundColor(Color.WHITE);
    webView.loadDataWithBaseURL("fake://not/needed", html, "text/html", "UTF-8", null); // Encoding
    // fix
    // for
    // Android
    // 3.x
    // /
    // 4.x
    scrollView.addView(webView);

    moreDetailsDialog = new AlertDialog.Builder(context);
    moreDetailsDialog.setIcon(android.R.drawable.ic_dialog_info);
    moreDetailsDialog.setTitle("Informations");
    moreDetailsDialog.setView(scrollView);
    moreDetailsDialog.setPositiveButton(android.R.string.ok, null);
    moreDetailsDialog.show();
}

From source file:com.prasanna.android.stacknetwork.utils.MarkdownFormatter.java

public static void loadText(final WebView webView, final String text) {
    webView.setWebChromeClient(new WebChromeClient());
    webView.setWebViewClient(new WebViewClient());
    webView.getSettings().setJavaScriptEnabled(true);
    webView.loadDataWithBaseURL(BASE_URL,
            CODE_HTML_PREFIX + MarkdownFormatter.escapeHtml(text) + CODE_HTML_SUFFIX,
            HttpContentTypes.TEXT_HTML, HTTP.UTF_8, null);
}

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

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

    getActivity().setTitle(R.string.about_activity_title);

    WebView content = (WebView) getActivity().findViewById(R.id.about_text_view);
    content.loadDataWithBaseURL(null, getString(R.string.about_text), "text/html", "utf-8", null);
}

From source file:de.eidottermihi.rpicheck.fragment.QueryErrorMessagesDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    List<String> messages = this.getArguments().getStringArrayList(KEY_ERROR_MESSAGES);
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(R.string.errormessages_dialog_title);
    WebView wv = new WebView(getActivity());
    wv.loadDataWithBaseURL(null, this.createErrorMessages(messages), "text/html", "UTF-8", null);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        Compability.setViewLayerTypeSoftware(wv);
    }//from  w  w w  .j a  v  a  2  s .  co m
    wv.setBackgroundColor(0);
    builder.setView(wv);
    builder.setCancelable(false);
    builder.setPositiveButton("Ok", null);
    builder.setIcon(android.R.drawable.ic_dialog_info);
    return builder.create();
}

From source file:fi.aalto.legroup.achso.browsing.DetailActivity.java

@Override
public boolean onMenuItemClick(MenuItem menuItem) {
    String licenceInfo = GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo(DetailActivity.this);

    // Using a WebView is a lot faster than showing the text as the dialog's message
    WebView webView = new WebView(DetailActivity.this);
    webView.loadDataWithBaseURL(null, licenceInfo, "text/plain", null, null);

    new AlertDialog.Builder(DetailActivity.this).setTitle(R.string.about_maps).setView(webView)
            .setNeutralButton(R.string.ok, new DialogInterface.OnClickListener() {
                @Override/*from w ww  .  j a v a 2 s.c o m*/
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            }).show();

    return true;
}

From source file:me.robertoestrada.rssreader.fragments.ItemDetailFragment.java

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

    ((ActionBarActivity) getActivity()).getSupportActionBar().setTitle(mItemTitle);

    // Show the dummy content as text in a TextView.
    if (mItemContent != null) {
        WebView webView = (WebView) rootView.findViewById(R.id.item_detail);
        webView.loadDataWithBaseURL("", mItemContent, "text/html", "UTF-8", "");
        webView.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
    }//  w ww.  j a v a2  s.c om

    return rootView;
}

From source file:org.gluu.super_gluu.app.fragments.LicenseFragment.LicenseFragment.java

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

    View view = inflater.inflate(R.layout.license_fragment, container, false);
    WebView licenseWebView = (WebView) view.findViewById(R.id.license_webView);
    licenseWebView.loadDataWithBaseURL(null, readLicenseTxt(), "text/html", "UTF-8", null);
    //        licenseTextView.setMovementMethod(new ScrollingMovementMethod());

    Button aceptButton = (Button) view.findViewById(R.id.accept_button);
    LinearLayout action_left_button = (LinearLayout) view.findViewById(R.id.action_left_button);
    action_left_button.setOnClickListener(new View.OnClickListener() {
        @Override//from   www . j  ava  2 s  .co  m
        public void onClick(View v) {
            getActivity().onBackPressed();
        }
    });
    aceptButton.setOnClickListener(this);
    LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) licenseWebView.getLayoutParams();
    if (!isForFirstLoading) {
        aceptButton.setVisibility(View.GONE);
        action_left_button.setVisibility(View.VISIBLE);
        params.weight = 0.25f;
    } else {
        action_left_button.setVisibility(View.GONE);
        params.weight = 0.98f;
    }
    licenseWebView.setLayoutParams(params);
    //Setup fonts
    Typeface face = Typeface.createFromAsset(getActivity().getAssets(), "ProximaNova-Regular.otf");
    aceptButton.setTypeface(face);

    return view;
}

From source file:com.tearoffcalendar.activities.FaceDownCardFragment.java

public void updateCardView(String str) {
    WebView mMainView = (WebView) getActivity().findViewById(R.id.face_down_card_fragment);
    mMainView.loadDataWithBaseURL("file:///android_res/raw/", str, "text/html", "utf-8", null);
    mMainView.setOnTouchListener(this);
    // mMainView.setBackgroundColor(0);
    // TextView article = (TextView) getActivity().findViewById(R.id.card);
    // article.setText(str);
}

From source file:net.meiolania.apps.habrahabr.fragments.companies.CompaniesShowFragment.java

@Override
public void onLoadFinished(Loader<CompanyFullData> loader, CompanyFullData data) {
    SherlockFragmentActivity activity = getSherlockActivity();

    if (activity != null) {
        TextView date = (TextView) activity.findViewById(R.id.company_date);
        date.setText(data.getDate());//from   w  w w. jav a2 s .c  o  m

        TextView site = (TextView) activity.findViewById(R.id.company_site);
        site.setText(data.getCompanyUrl());

        TextView industries = (TextView) activity.findViewById(R.id.company_industries);
        industries.setText(data.getIndustries());

        TextView location = (TextView) activity.findViewById(R.id.company_location);
        location.setText(data.getLocation());

        TextView quantity = (TextView) activity.findViewById(R.id.company_quantity);
        quantity.setText(data.getQuantity());

        WebView summary = (WebView) activity.findViewById(R.id.company_summary);
        summary.getSettings().setSupportZoom(true);
        summary.loadDataWithBaseURL("", data.getSummary(), "text/html", "UTF-8", null);

        WebView management = (WebView) activity.findViewById(R.id.company_management);
        management.getSettings().setSupportZoom(true);
        management.loadDataWithBaseURL("", data.getManagement(), "text/html", "UTF-8", null);

        WebView developmentStages = (WebView) activity.findViewById(R.id.company_development_stages);
        developmentStages.getSettings().setSupportZoom(true);
        developmentStages.loadDataWithBaseURL("", data.getDevelopmentStages(), "text/html", "UTF-8", null);
    }

    hideProgressDialog();
}

From source file:io.github.importre.android.chromeadb.OssLicenseFragment.java

private void setContents(View rootView) {
    String str;/*from   w  w w.  j av  a2s .c om*/
    StringBuilder buf = new StringBuilder("<pre>");

    try {
        InputStream is = getActivity().getAssets().open("LICENSE-2.0.txt");
        BufferedReader in = new BufferedReader(new InputStreamReader(is));
        while ((str = in.readLine()) != null) {
            buf.append(str + "<br />");
        }
        in.close();
    } catch (IOException e) {
        return;
    }

    WebView webView = (WebView) rootView.findViewById(R.id.webview);
    buf.append("</pre>");

    String encoding = "utf-8";
    WebSettings settings = webView.getSettings();
    settings.setDefaultTextEncodingName(encoding);
    webView.loadDataWithBaseURL(null, buf.toString(), "text/html", encoding, null);
}