Example usage for android.text Html fromHtml

List of usage examples for android.text Html fromHtml

Introduction

In this page you can find the example usage for android.text Html fromHtml.

Prototype

@Deprecated
public static Spanned fromHtml(String source, ImageGetter imageGetter, TagHandler tagHandler) 

Source Link

Document

Returns displayable styled text from the provided HTML string with the legacy flags #FROM_HTML_MODE_LEGACY .

Usage

From source file:com.androidquery.service.MarketService.java

protected void showUpdateDialog(JSONObject jo) {

    if (jo == null || version != null)
        return;/*from   w  w w  .  j a v  a  2 s. c  om*/

    if (!isActive())
        return;

    JSONObject dia = jo.optJSONObject("dialog");

    String update = dia.optString("update", "Update");
    String skip = dia.optString("skip", "Skip");
    String rate = dia.optString("rate", "Rate");
    //String message = dia.optString("body", "");
    String body = dia.optString("wbody", "");
    String title = dia.optString("title", "Update Available");

    AQUtility.debug("wbody", body);

    version = jo.optString("version", null);

    Drawable icon = getAppIcon();

    Context context = act;

    final AlertDialog dialog = new AlertDialog.Builder(context).setIcon(icon).setTitle(title)
            .setPositiveButton(rate, handler).setNeutralButton(skip, handler).setNegativeButton(update, handler)
            .create();

    dialog.setMessage(Html.fromHtml(patchBody(body), null, handler));

    aq.show(dialog);

    return;

}

From source file:net.networksaremadeofstring.rhybudd.ViewZenossEventFragment.java

@Override
public void onActivityCreated(Bundle bundle) {
    if (null != bundle) {
        //Log.e("Saving","Found a bundle!!!!");

        if (bundle.containsKey("eventStateAcknowledged") && bundle.getBoolean("eventStateAcknowledged")) {
            ackIcon.setImageResource(R.drawable.ic_acknowledged);
            isAcknowledged = true;//from ww w  .j  a v a2  s  .  c  o m
        }

        if (bundle.containsKey("Title"))
            Title.setText(bundle.getString("Title"));

        if (bundle.containsKey("Component"))
            Component.setText(bundle.getString("Component"));

        if (bundle.containsKey("EventClass"))
            EventClass.setText(bundle.getString("EventClass"));

        if (bundle.containsKey("Summary"))
            Summary.setText(Html.fromHtml(bundle.getString("Summary"), null, null));

        if (bundle.containsKey("FirstTime"))
            FirstTime.setText(bundle.getString("FirstTime"));

        if (bundle.containsKey("LastTime"))
            LastTime.setText(bundle.getString("LastTime"));

        if (bundle.containsKey("EventCount"))
            EventCount.setText(bundle.getString("EventCount"));

        if (bundle.containsKey("agent"))
            agent.setText(bundle.getString("agent"));

        if (bundle.containsKey("LogEntries")) {
            try {
                String[] LogEntries = bundle.getStringArray("LogEntries");
                int LogEntryCount = LogEntries.length;

                for (int i = 0; i < LogEntryCount; i++) {
                    TextView newLog = new TextView(getActivity());
                    newLog.setText(Html.fromHtml(LogEntries[i]));
                    newLog.setPadding(0, 6, 0, 6);
                    logList.addView(newLog);
                }
            } catch (Exception e) {
                e.printStackTrace();
                BugSenseHandler.sendExceptionMessage("ViewZenossEventFragment", "oncreate bundle", e);
            }
        }

        if (bundle.containsKey("img")) {
            try {
                img.setImageBitmap((Bitmap) bundle.getParcelable("img"));
                img.invalidate();
            } catch (Exception e) {
                e.printStackTrace();
                BugSenseHandler.sendExceptionMessage("ViewZenossEventFragment", "oncreate bundle image", e);
            }
        }

        progressbar.setVisibility(View.INVISIBLE);
    } else {
        //Log.e("Saving","Didn't find any data so getting it");
        preLoadData();
    }

    super.onActivityCreated(bundle);
}

From source file:net.networksaremadeofstring.rhybudd.ViewZenossEventFragment.java

/**
 * Called when the activity is first created.
 *//* w ww  .j ava  2s. c o  m*/
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    BugSenseHandler.initAndStartSession(getActivity(), "44a76a8c");

    settings = PreferenceManager.getDefaultSharedPreferences(getActivity());

    firstLoadHandler = new Handler() {
        public void handleMessage(Message msg) {
            //dialog.dismiss();
            try {
                if (EventObject.has("result")
                        && EventObject.getJSONObject("result").getBoolean("success") == true) {
                    EventDetails = EventObject.getJSONObject("result").getJSONArray("event").getJSONObject(0);

                    try {
                        //Log.e("Ack",EventDetails.getString("eventState"));
                        if (EventDetails.getString("eventState").equals("Acknowledged")
                                || EventDetails.getString("eventState").equals("1")) {
                            ackIcon.setImageResource(R.drawable.ic_acknowledged);
                            isAcknowledged = true;
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        BugSenseHandler.sendExceptionMessage("ViewZenossEventFragment", "loadhandler ack image",
                                e);
                    }

                    //Log.e("EventDetails", EventDetails.toString(3));

                    try {
                        Title.setText(EventDetails.getString("device_title"));
                    } catch (Exception e) {
                        Title.setText("Unknown Device - Event Details");
                    }

                    try {
                        Component.setText(EventDetails.getString("component"));
                    } catch (Exception e) {
                        Component.setText("Unknown Component");
                    }

                    try {
                        if (!EventDetails.getString("eventClassKey").equals("")) {
                            EventClass.setText(EventDetails.getString("eventClassKey"));
                        } else {
                            EventClass.setText("Unknown Event Class");
                        }
                    } catch (Exception e) {
                        EventClass.setText("Unknown Event Class");
                    }

                    try {
                        //ImageView img = (ImageView) findViewById(R.id.summaryImage);

                        URLImageParser p = new URLImageParser(img, getActivity(), Summary);

                        String summaryText = EventDetails.getString("message");
                        Spanned htmlSpan = Html.fromHtml(summaryText, p, null);

                        //Log.e("summary",summaryText);
                        summaryText = summaryText.replaceAll("<img\\s*src=('|\")([^'>]+)'\\s*/>", "");
                        //Log.e("summary2",summaryText);

                        Summary.setText(Html.fromHtml(summaryText, null, null));

                        //Log.i("Summary", EventDetails.getString("message"));

                        try {
                            Summary.setMovementMethod(LinkMovementMethod.getInstance());
                        } catch (Exception e) {
                            e.printStackTrace();
                            BugSenseHandler.sendExceptionMessage("ViewZenossEventFragment",
                                    "set Summary MovementMethod", e);
                            //Worth a shot
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        Summary.setText("No Summary available");
                    }

                    try {
                        FirstTime.setText(EventDetails.getString("firstTime"));
                    } catch (Exception e) {
                        FirstTime.setText("No Start Date Provided");
                    }

                    try {
                        LastTime.setText(EventDetails.getString("stateChange"));
                    } catch (Exception e) {
                        LastTime.setText("No Recent Date Provided");
                    }

                    try {
                        EventCount.setText("Count: " + EventDetails.getString("count"));
                    } catch (Exception e) {
                        EventCount.setText("Count: ??");
                    }

                    try {
                        agent.setText(EventDetails.getString("agent"));
                    } catch (Exception e) {
                        agent.setText("unknown");
                    }

                    try {
                        JSONArray Log = EventDetails.getJSONArray("log");

                        int LogEntryCount = Log.length();

                        if (LogEntryCount == 0) {
                            TextView newLog = new TextView(getActivity());
                            newLog.setText("No log entries could be found");
                            LogEntries = new String[1];
                            LogEntries[0] = "No log entries could be found";
                            logList.addView(newLog);
                        } else {
                            LogEntries = new String[LogEntryCount];

                            for (int i = 0; i < LogEntryCount; i++) {
                                LogEntries[i] = "<strong>" + Log.getJSONArray(i).getString(0)
                                        + "</strong> wrote " + Log.getJSONArray(i).getString(2)
                                        + "\n<br/><strong>At:</strong> " + Log.getJSONArray(i).getString(1);

                                TextView newLog = new TextView(getActivity());
                                newLog.setText(Html.fromHtml(LogEntries[i]));
                                newLog.setPadding(0, 6, 0, 6);

                                logList.addView(newLog);
                            }
                        }
                    } catch (Exception e) {
                        TextView newLog = new TextView(getActivity());
                        newLog.setText("No log entries could be found");
                        newLog.setPadding(0, 6, 0, 6);
                        logList.addView(newLog);
                    }

                    progressbar.setVisibility(View.INVISIBLE);
                } else {
                    //Log.e("EventObject",EventObject.toString(3));
                    String errMsg = ".";
                    if (EventObject.has("type") && EventObject.getString("type").equals("exception")
                            && EventObject.has("message"))
                        errMsg = ":\n" + EventObject.getString("message");

                    Toast.makeText(getActivity(),
                            "There was an error refreshing the Event details from Zenoss" + errMsg,
                            Toast.LENGTH_LONG).show();
                }
            } catch (Exception e) {
                try {
                    Toast.makeText(getActivity(),
                            "An error was encountered parsing the JSON. An error report has been sent.",
                            Toast.LENGTH_LONG).show();
                } catch (Exception e2) {
                    e.printStackTrace();
                    e2.printStackTrace();
                }

                BugSenseHandler.sendExceptionMessage("ViewZenossEventFragment",
                        "uncaught exception within firstload", e);
            }
        }
    };
}

From source file:com.z.stproperty.PropertyDetailFragment.java

/**
 * //w  w  w.j a  va  2s .  c o m
 * This method will check the detailsJson and the value is added to content.
 * If the content is blank, "No Data" is added to the content. Then, the
 * content is added to AdditionalInfo TextView.
 * 
 */
private View addAdditonalInfo() {
    View view = inflater.inflate(R.layout.info, null);
    try {
        String content = detailsJson.getString("additional_info");
        if (content.equals("") || content.equals("null")) {
            content = "No Data.";
        }
        content = content.replace("\n", " <br /> ");
        TextView addTxt = ((Helvetica) view.findViewById(R.id.AdditionalInfo));
        URLImageParser p = new URLImageParser(addTxt, this.getActivity());
        Spanned htmlSpan = Html.fromHtml(content, p, null);
        addTxt.setText(htmlSpan);
        //.setText(Html.fromHtml(content));
    } catch (Exception e) {
        Log.e(this.getClass().getSimpleName(), e.getLocalizedMessage(), e);
    }
    return view;
}

From source file:com.ichi2.anki2.Reviewer.java

private Spanned convertToSimple(String text) {
    text = text.replaceAll("</div>$", "").replaceAll("(</div>)*<div>", "<br>");
    return Html.fromHtml(text, mSimpleInterfaceImagegetter, mSimpleInterfaceTagHandler);
}

From source file:com.hichinaschool.flashcards.anki.Reviewer.java

private Spanned convertToSimple(String text) {
    return Html.fromHtml(text, mSimpleInterfaceImagegetter, mSimpleInterfaceTagHandler);
}

From source file:cgeo.geocaching.cgBase.java

public void storeCache(cgeoapplication app, Activity activity, cgCache cache, String geocode, int listId,
        Handler handler) {//from  w  ww.ja v  a  2  s  .  co  m
    try {
        // get cache details, they may not yet be complete
        if (cache != null) {
            // only reload the cache, if it was already stored or has not all details (by checking the description)
            if (cache.reason > 0 || StringUtils.isBlank(cache.description)) {
                final Map<String, String> params = new HashMap<String, String>();
                params.put("geocode", cache.geocode);
                final UUID searchId = searchByGeocode(params, listId, false);
                cache = app.getCache(searchId);
            }
        } else if (StringUtils.isNotBlank(geocode)) {
            final Map<String, String> params = new HashMap<String, String>();
            params.put("geocode", geocode);
            final UUID searchId = searchByGeocode(params, listId, false);
            cache = app.getCache(searchId);
        }

        if (cache == null) {
            if (handler != null) {
                handler.sendMessage(new Message());
            }

            return;
        }

        final cgHtmlImg imgGetter = new cgHtmlImg(activity, cache.geocode, false, listId, true);

        // store images from description
        if (StringUtils.isNotBlank(cache.description)) {
            Html.fromHtml(cache.description, imgGetter, null);
        }

        // store spoilers
        if (CollectionUtils.isNotEmpty(cache.spoilers)) {
            for (cgImage oneSpoiler : cache.spoilers) {
                imgGetter.getDrawable(oneSpoiler.url);
            }
        }

        // store images from logs
        if (settings.storelogimages) {
            for (cgLog log : cache.logs) {
                if (CollectionUtils.isNotEmpty(log.logImages)) {
                    for (cgImage oneLogImg : log.logImages) {
                        imgGetter.getDrawable(oneLogImg.url);
                    }
                }
            }
        }

        // store map previews
        StaticMapsProvider.downloadMaps(cache, settings, activity);

        app.markStored(cache.geocode, listId);
        app.removeCacheFromCache(cache.geocode);

        if (handler != null) {
            handler.sendMessage(new Message());
        }
    } catch (Exception e) {
        Log.e(cgSettings.tag, "cgBase.storeCache: " + e.toString());
    }
}

From source file:carnero.cgeo.original.libs.Base.java

public void storeCache(App app, Activity activity, Cache cache, String geocode, int listId, Handler handler) {
    try {//  www. j  a  v  a2 s. c om
        // cache details
        if (cache != null) {
            final HashMap<String, String> params = new HashMap<String, String>();
            params.put("geocode", cache.geocode);
            final Long searchId = searchByGeocode(params, listId, false);
            cache = app.getCache(searchId);
        } else if (geocode != null) {
            final HashMap<String, String> params = new HashMap<String, String>();
            params.put("geocode", geocode);
            final Long searchId = searchByGeocode(params, listId, false);
            cache = app.getCache(searchId);
        }

        if (cache == null) {
            if (handler != null) {
                handler.sendMessage(new Message());
            }

            return;
        }

        final HtmlImg imgGetter = new HtmlImg(activity, settings, cache.geocode, false, listId, true);

        // store images from description
        if (cache.description != null) {
            Html.fromHtml(cache.description, imgGetter, null);
        }

        // store spoilers
        if (cache.spoilers != null && cache.spoilers.isEmpty() == false) {
            for (Spoiler oneSpoiler : cache.spoilers) {
                imgGetter.getDrawable(oneSpoiler.url);
            }
        }

        // store map previews
        if (settings.storeOfflineMaps == 1 && cache.latitude != null && cache.longitude != null) {
            final String latlonMap = String.format((Locale) null, "%.6f", cache.latitude) + ","
                    + String.format((Locale) null, "%.6f", cache.longitude);
            final Display display = ((WindowManager) activity.getSystemService(Context.WINDOW_SERVICE))
                    .getDefaultDisplay();
            final int maxWidth = display.getWidth() - 25;
            final int maxHeight = display.getHeight() - 25;
            int edge = 0;
            if (maxWidth > maxHeight) {
                edge = maxWidth;
            } else {
                edge = maxHeight;
            }

            String type = "mystery";
            if (cache.found == true) {
                type = cache.type + "_found";
            } else if (cache.disabled == true) {
                type = cache.type + "_disabled";
            } else {
                type = cache.type;
            }

            final String markerUrl = urlencode_rfc3986(
                    "http://cgeo.carnero.cc/_markers/marker_cache_" + type + ".png");
            final StringBuilder waypoints = new StringBuilder();
            if (cache.waypoints != null && cache.waypoints.size() > 0) {
                for (Waypoint waypoint : cache.waypoints) {
                    if (waypoint.latitude == null && waypoint.longitude == null) {
                        continue;
                    }

                    waypoints.append("&markers=icon%3Ahttp://cgeo.carnero.cc/_markers/marker_waypoint_");
                    waypoints.append(waypoint.type);
                    waypoints.append(".png%7C");
                    waypoints.append(String.format((Locale) null, "%.6f", waypoint.latitude));
                    waypoints.append(",");
                    waypoints.append(String.format((Locale) null, "%.6f", waypoint.longitude));
                }
            }

            // download map images in separate background thread for higher performance
            final String code = cache.geocode;
            final int finalEdge = edge;
            Thread staticMapsThread = new Thread("getting static map") {
                @Override
                public void run() {
                    MapImg mapGetter = new MapImg(settings, code);

                    mapGetter.getDrawable(
                            "http://maps.google.com/maps/api/staticmap?center=" + latlonMap + "&zoom=20&size="
                                    + finalEdge + "x" + finalEdge + "&maptype=satellite&markers=icon%3A"
                                    + markerUrl + "%7C" + latlonMap + waypoints.toString() + "&sensor=false",
                            1);
                    mapGetter.getDrawable(
                            "http://maps.google.com/maps/api/staticmap?center=" + latlonMap + "&zoom=18&size="
                                    + finalEdge + "x" + finalEdge + "&maptype=satellite&markers=icon%3A"
                                    + markerUrl + "%7C" + latlonMap + waypoints.toString() + "&sensor=false",
                            2);
                    mapGetter.getDrawable(
                            "http://maps.google.com/maps/api/staticmap?center=" + latlonMap + "&zoom=16&size="
                                    + finalEdge + "x" + finalEdge + "&maptype=roadmap&markers=icon%3A"
                                    + markerUrl + "%7C" + latlonMap + waypoints.toString() + "&sensor=false",
                            3);
                    mapGetter.getDrawable(
                            "http://maps.google.com/maps/api/staticmap?center=" + latlonMap + "&zoom=14&size="
                                    + finalEdge + "x" + finalEdge + "&maptype=roadmap&markers=icon%3A"
                                    + markerUrl + "%7C" + latlonMap + waypoints.toString() + "&sensor=false",
                            4);
                    mapGetter.getDrawable(
                            "http://maps.google.com/maps/api/staticmap?center=" + latlonMap + "&zoom=11&size="
                                    + finalEdge + "x" + finalEdge + "&maptype=roadmap&markers=icon%3A"
                                    + markerUrl + "%7C" + latlonMap + waypoints.toString() + "&sensor=false",
                            5);
                }
            };
            staticMapsThread.setPriority(Thread.MIN_PRIORITY);
            staticMapsThread.start();
        }

        app.markStored(cache.geocode, listId);
        app.removeCacheFromCache(cache.geocode);

        if (handler != null) {
            handler.sendMessage(new Message());
        }
    } catch (Exception e) {
        Log.e(Settings.tag, "cgBase.storeCache: " + e.toString());
    }
}

From source file:carnero.cgeo.cgBase.java

public void storeCache(cgeoapplication app, Activity activity, cgCache cache, String geocode, int listId,
        Handler handler) {/*from   w w  w .j  av  a  2 s . c om*/
    try {
        // cache details
        if (cache != null) {
            final HashMap<String, String> params = new HashMap<String, String>();
            params.put("geocode", cache.geocode);
            final Long searchId = searchByGeocode(params, listId, false);
            cache = app.getCache(searchId);
        } else if (geocode != null) {
            final HashMap<String, String> params = new HashMap<String, String>();
            params.put("geocode", geocode);
            final Long searchId = searchByGeocode(params, listId, false);
            cache = app.getCache(searchId);
        }

        if (cache == null) {
            if (handler != null) {
                handler.sendMessage(new Message());
            }

            return;
        }

        final cgHtmlImg imgGetter = new cgHtmlImg(activity, settings, cache.geocode, false, listId, true);

        // store images from description
        if (cache.description != null) {
            Html.fromHtml(cache.description, imgGetter, null);
        }

        // store spoilers
        if (cache.spoilers != null && cache.spoilers.isEmpty() == false) {
            for (cgSpoiler oneSpoiler : cache.spoilers) {
                imgGetter.getDrawable(oneSpoiler.url);
            }
        }

        // store map previews
        if (settings.storeOfflineMaps == 1 && cache.latitude != null && cache.longitude != null) {
            final String latlonMap = String.format((Locale) null, "%.6f", cache.latitude) + ","
                    + String.format((Locale) null, "%.6f", cache.longitude);
            final Display display = ((WindowManager) activity.getSystemService(Context.WINDOW_SERVICE))
                    .getDefaultDisplay();
            final int maxWidth = display.getWidth() - 25;
            final int maxHeight = display.getHeight() - 25;
            int edge = 0;
            if (maxWidth > maxHeight) {
                edge = maxWidth;
            } else {
                edge = maxHeight;
            }

            String type = "mystery";
            if (cache.found == true) {
                type = cache.type + "_found";
            } else if (cache.disabled == true) {
                type = cache.type + "_disabled";
            } else {
                type = cache.type;
            }

            final String markerUrl = urlencode_rfc3986(
                    "http://cgeo.carnero.cc/_markers/marker_cache_" + type + ".png");
            final StringBuilder waypoints = new StringBuilder();
            if (cache.waypoints != null && cache.waypoints.size() > 0) {
                for (cgWaypoint waypoint : cache.waypoints) {
                    if (waypoint.latitude == null && waypoint.longitude == null) {
                        continue;
                    }

                    waypoints.append("&markers=icon%3Ahttp://cgeo.carnero.cc/_markers/marker_waypoint_");
                    waypoints.append(waypoint.type);
                    waypoints.append(".png%7C");
                    waypoints.append(String.format((Locale) null, "%.6f", waypoint.latitude));
                    waypoints.append(",");
                    waypoints.append(String.format((Locale) null, "%.6f", waypoint.longitude));
                }
            }

            // download map images in separate background thread for higher performance
            final String code = cache.geocode;
            final int finalEdge = edge;
            Thread staticMapsThread = new Thread("getting static map") {
                @Override
                public void run() {
                    cgMapImg mapGetter = new cgMapImg(settings, code);

                    mapGetter.getDrawable(
                            "http://maps.google.com/maps/api/staticmap?center=" + latlonMap + "&zoom=20&size="
                                    + finalEdge + "x" + finalEdge + "&maptype=satellite&markers=icon%3A"
                                    + markerUrl + "%7C" + latlonMap + waypoints.toString() + "&sensor=false",
                            1);
                    mapGetter.getDrawable(
                            "http://maps.google.com/maps/api/staticmap?center=" + latlonMap + "&zoom=18&size="
                                    + finalEdge + "x" + finalEdge + "&maptype=satellite&markers=icon%3A"
                                    + markerUrl + "%7C" + latlonMap + waypoints.toString() + "&sensor=false",
                            2);
                    mapGetter.getDrawable(
                            "http://maps.google.com/maps/api/staticmap?center=" + latlonMap + "&zoom=16&size="
                                    + finalEdge + "x" + finalEdge + "&maptype=roadmap&markers=icon%3A"
                                    + markerUrl + "%7C" + latlonMap + waypoints.toString() + "&sensor=false",
                            3);
                    mapGetter.getDrawable(
                            "http://maps.google.com/maps/api/staticmap?center=" + latlonMap + "&zoom=14&size="
                                    + finalEdge + "x" + finalEdge + "&maptype=roadmap&markers=icon%3A"
                                    + markerUrl + "%7C" + latlonMap + waypoints.toString() + "&sensor=false",
                            4);
                    mapGetter.getDrawable(
                            "http://maps.google.com/maps/api/staticmap?center=" + latlonMap + "&zoom=11&size="
                                    + finalEdge + "x" + finalEdge + "&maptype=roadmap&markers=icon%3A"
                                    + markerUrl + "%7C" + latlonMap + waypoints.toString() + "&sensor=false",
                            5);
                }
            };
            staticMapsThread.setPriority(Thread.MIN_PRIORITY);
            staticMapsThread.start();
        }

        app.markStored(cache.geocode, listId);
        app.removeCacheFromCache(cache.geocode);

        if (handler != null) {
            handler.sendMessage(new Message());
        }
    } catch (Exception e) {
        Log.e(cgSettings.tag, "cgBase.storeCache: " + e.toString());
    }
}