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) 

Source Link

Document

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

Usage

From source file:cgeo.geocaching.CacheDetailActivity.java

private void addWarning(final UnknownTagsHandler unknownTagsHandler, final Editable description) {
    if (unknownTagsHandler.isProblematicDetected()) {
        final int startPos = description.length();
        final IConnector connector = ConnectorFactory.getConnector(cache);
        if (StringUtils.isNotEmpty(cache.getUrl())) {
            final Spanned tableNote = Html.fromHtml(res.getString(R.string.cache_description_table_note,
                    "<a href=\"" + cache.getUrl() + "\">" + connector.getName() + "</a>"));
            description.append("\n\n").append(tableNote);
            description.setSpan(new StyleSpan(Typeface.ITALIC), startPos, description.length(),
                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }//from  w w  w.ja  v a2 s.c o  m
    }
}

From source file:com.bookkos.bircle.CaptureActivity.java

private void getReturnHistory() {
    SharedPreferences settings = getSharedPreferences(PREFERENCES_FILE_NAME, 0);
    if (settings == null) {
        return;//from  ww w  . j av  a2s .co  m
    }

    // ??????userId????????????????
    String return_history1 = settings.getString("return_history1_" + userId + "_" + groupId, "");
    String return_history2 = settings.getString("return_history2_" + userId + "_" + groupId, "");
    String return_history3 = settings.getString("return_history3_" + userId + "_" + groupId, "");
    CharSequence[] return_history_array = { Html.fromHtml(return_history1), Html.fromHtml(return_history2),
            Html.fromHtml(return_history3) };

    ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(this, R.layout.row,
            return_history_array);
    leftDrawer.setAdapter(adapter);

}

From source file:com.eleybourn.bookcatalogue.utils.Utils.java

/**
 * Linkify partial HTML. Linkify methods remove all spans before building links, this
 * method preserves them./*  w w  w . ja va2  s.com*/
 * 
 * See: http://stackoverflow.com/questions/14538113/using-linkify-addlinks-combine-with-html-fromhtml
 * 
 * @param html         Partial HTML
 * @param linkifyMask   Linkify mask to use in Linkify.addLinks
 * 
 * @return            Spannable with all links
 */
public static Spannable linkifyHtml(String html, int linkifyMask) {
    // Get the spannable HTML
    Spanned text = Html.fromHtml(html);
    // Save the span details for later restoration
    URLSpan[] currentSpans = text.getSpans(0, text.length(), URLSpan.class);

    // Build an empty spannable then add the links
    SpannableString buffer = new SpannableString(text);
    Linkify.addLinks(buffer, linkifyMask);

    // Add back the HTML spannables
    for (URLSpan span : currentSpans) {
        int end = text.getSpanEnd(span);
        int start = text.getSpanStart(span);
        buffer.setSpan(span, start, end, 0);
    }
    return buffer;
}

From source file:cgeo.geocaching.connector.gc.GCParser.java

public static List<TrackableLog> parseTrackableLog(final String page) {
    if (StringUtils.isEmpty(page)) {
        return null;
    }/* ww w. j a  v  a 2  s  . com*/

    String table = StringUtils.substringBetween(page, "<table id=\"tblTravelBugs\"", "</table>");

    // if no trackables are currently in the account, the table is not available, so return an empty list instead of null
    if (StringUtils.isBlank(table)) {
        return Collections.emptyList();
    }

    table = StringUtils.substringBetween(table, "<tbody>", "</tbody>");
    if (StringUtils.isBlank(table)) {
        Log.e("GCParser.parseTrackableLog: tbody not found on page");
        return null;
    }

    final List<TrackableLog> trackableLogs = new ArrayList<TrackableLog>();

    final MatcherWrapper trackableMatcher = new MatcherWrapper(GCConstants.PATTERN_TRACKABLE, page);
    while (trackableMatcher.find()) {
        if (trackableMatcher.groupCount() > 0) {

            final String trackCode = trackableMatcher.group(1);
            final String name = Html.fromHtml(trackableMatcher.group(2)).toString();
            try {
                final Integer ctl = Integer.valueOf(trackableMatcher.group(3));
                final Integer id = Integer.valueOf(trackableMatcher.group(5));
                if (trackCode != null && ctl != null && id != null) {
                    final TrackableLog entry = new TrackableLog(trackCode, name, id, ctl);

                    Log.i("Trackable in inventory (#" + entry.ctl + "/" + entry.id + "): " + entry.trackCode
                            + " - " + entry.name);
                    trackableLogs.add(entry);
                }
            } catch (final NumberFormatException e) {
                Log.e("GCParser.parseTrackableLog", e);
            }
        }
    }

    return trackableLogs;
}

From source file:com.andrewshu.android.reddit.comments.CommentsListActivity.java

/**
 * Helper function to add links from mVoteTargetThing to the button
 * @param linkButton Button that should open list of links
 *///from  w  ww .ja va  2  s  .  co  m
private void linkToEmbeddedURLs(Button linkButton) {
    final ArrayList<String> urls = new ArrayList<String>();
    final ArrayList<MarkdownURL> vtUrls = mVoteTargetThing.getUrls();
    int urlsCount = vtUrls.size();
    for (int i = 0; i < urlsCount; i++) {
        urls.add(vtUrls.get(i).url);
    }
    if (urlsCount == 0) {
        linkButton.setEnabled(false);
    } else {
        linkButton.setEnabled(true);
        linkButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                removeDialog(Constants.DIALOG_COMMENT_CLICK);

                ArrayAdapter<MarkdownURL> adapter = new ArrayAdapter<MarkdownURL>(CommentsListActivity.this,
                        android.R.layout.select_dialog_item, vtUrls) {
                    public View getView(int position, View convertView, ViewGroup parent) {
                        TextView tv;
                        if (convertView == null) {
                            tv = (TextView) ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE))
                                    .inflate(android.R.layout.select_dialog_item, null);
                        } else {
                            tv = (TextView) convertView;
                        }

                        String url = getItem(position).url;
                        String anchorText = getItem(position).anchorText;
                        if (Constants.LOGGING)
                            Log.d(TAG, "links url=" + url + " anchorText=" + anchorText);

                        Drawable d = null;
                        try {
                            d = getPackageManager()
                                    .getActivityIcon(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
                        } catch (NameNotFoundException ignore) {
                        }
                        if (d != null) {
                            d.setBounds(0, 0, d.getIntrinsicHeight(), d.getIntrinsicHeight());
                            tv.setCompoundDrawablePadding(10);
                            tv.setCompoundDrawables(d, null, null, null);
                        }

                        final String telPrefix = "tel:";
                        if (url.startsWith(telPrefix)) {
                            url = PhoneNumberUtils.formatNumber(url.substring(telPrefix.length()));
                        }

                        if (anchorText != null)
                            tv.setText(Html.fromHtml(
                                    "<span>" + anchorText + "</span><br /><small>" + url + "</small>"));
                        else
                            tv.setText(Html.fromHtml(url));

                        return tv;
                    }
                };

                AlertDialog.Builder b = new AlertDialog.Builder(
                        new ContextThemeWrapper(CommentsListActivity.this, mSettings.getDialogTheme()));

                DialogInterface.OnClickListener click = new DialogInterface.OnClickListener() {
                    public final void onClick(DialogInterface dialog, int which) {
                        if (which >= 0) {
                            Common.launchBrowser(CommentsListActivity.this, urls.get(which),
                                    Util.createThreadUri(getOpThingInfo()).toString(), false, false,
                                    mSettings.isUseExternalBrowser(), mSettings.isSaveHistory());
                        }
                    }
                };

                b.setTitle(R.string.select_link_title);
                b.setCancelable(true);
                b.setAdapter(adapter, click);

                b.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    public final void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });

                b.show();
            }
        });
    }
}

From source file:cl.ipp.katbag.fragment.Develop.java

public void setSensing(String title, final String humanTextRow, final int dialogIdObjectItemList,
        final long object_id) {
    int resource = 0;
    View dialog_layout = null;/*from w w  w .jav a2s  . c  o  m*/
    ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(mainActivity.context, 0);
    if (dialogIdObjectItemList != 1) {
        resource = getResources().getIdentifier("dialog_sensing_" + dialogIdObjectItemList, "layout",
                mainActivity.getPackageName());
        LayoutInflater inflater = LayoutInflater.from(mainActivity.context);
        dialog_layout = inflater.inflate(resource, null);
    }

    if (object_id != -1) {
        dev.clear();
        dev = mainActivity.katbagHandler.selectDevelopForId(object_id);
    }

    if (dialogIdObjectItemList != 1) {
        spinner_drawing_1 = (Spinner) dialog_layout.findViewById(R.id.dialog_drawing_1);
        spinner_drawing_2 = (Spinner) dialog_layout.findViewById(R.id.dialog_drawing_2);

        spinnerList.clear();
        drawing1List.clear();
        spinnerList = mainActivity.katbagHandler.selectDevelopAllDrawing(id_app);
        if (spinnerList.size() == 0) {
            KatbagUtilities.message(mainActivity.context, getString(R.string.develop_message_not_drawing));
            return;
        }

        for (int i = 0; i < spinnerList.size(); i++) {
            drawing1List.add(getString(R.string.drawings_row_name) + " " + spinnerList.get(i));
        }

        arrayAdapter = new ArrayAdapter<String>(mainActivity.context, R.layout.simple_spinner_item_custom,
                drawing1List);
        arrayAdapter.setDropDownViewResource(R.layout.simple_spinner_dropdown_item_custom);
        spinner_drawing_1.setAdapter(arrayAdapter);
    }

    switch (dialogIdObjectItemList) {
    case 0:
        if (object_id == -1) {

        } else {
            for (int i = 0; i < spinnerList.size(); i++) {
                if (spinnerList.get(i).contentEquals(dev.get(3))) {
                    spinner_drawing_1.setSelection(i);
                    break;
                }
            }
        }
        break;

    case 1:
        if (object_id == -1) {
            mainActivity.katbagHandler.insertDevelop(id_app, "sensing", String.format(humanTextRow), // row text
                    String.valueOf(dialogIdObjectItemList), // first parameter is the type control
                    "", "", "", "", "", "", "", 0, 0);
        }

        loadListView();
        return;
    }

    AlertDialog.Builder builder = new AlertDialog.Builder(mainActivity.context);
    builder.setView(dialog_layout);
    builder.setTitle(Html.fromHtml(title));
    builder.setNegativeButton(getString(R.string.dialog_button_cancel), new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            // :)
        }
    });

    builder.setPositiveButton(getString(R.string.dialog_button_ok), new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            drawingText_1 = spinner_drawing_1.getSelectedItem().toString();
            drawingId_1 = spinnerList.get(spinner_drawing_1.getSelectedItemPosition());

            switch (dialogIdObjectItemList) {
            case 0:
                if (object_id == -1) {
                    mainActivity.katbagHandler.insertDevelop(id_app, "sensing",
                            String.format(humanTextRow, drawingText_1), // row text
                            String.valueOf(dialogIdObjectItemList), // first parameter is the type sensing
                            drawingId_1, // id of drawing selected
                            "", "", "", "", "", "", 0, 0);
                } else {
                    mainActivity.katbagHandler.updateDevelop(object_id, "sensing",
                            String.format(humanTextRow, drawingText_1), // row text
                            String.valueOf(dialogIdObjectItemList), // first parameter is the type sensing
                            drawingId_1, // id of drawing selected
                            "", "", "", "", "", "");
                }
                break;
            }

            loadListView();
        }
    });

    builder.show();
}

From source file:edu.mit.viral.shen.DroidFish.java

private final void updateThinkingInfo() {
    boolean thinkingEmpty = false;
    {//w w w .j a  v a 2 s. c o  m
        String s = "";
        if (mShowThinking || gameMode.analysisMode()) {
            s = thinkingStr1;
            if (s.length() > 0)
                thinkingEmpty = false;
            if (mShowStats) {
                if (!thinkingEmpty)
                    s += "\n";
                s += thinkingStr2;
                if (s.length() > 0)
                    thinkingEmpty = false;
            }
        }
        thinking.setText(s, TextView.BufferType.SPANNABLE);
    }
    if (mShowBookHints && (bookInfoStr.length() > 0)) {
        String s = "";
        if (!thinkingEmpty)
            s += "<br>";
        s += Util.boldStart + getString(R.string.book) + Util.boldStop + bookInfoStr;
        thinking.append(Html.fromHtml(s));
        thinkingEmpty = false;
    }
    if (showVariationLine && (variantStr.indexOf(' ') >= 0)) {
        String s = "";
        if (!thinkingEmpty)
            s += "<br>";
        s += Util.boldStart + getString(R.string.variation) + Util.boldStop + variantStr;
        thinking.append(Html.fromHtml(s));
        thinkingEmpty = false;
    }
    thinking.setVisibility(thinkingEmpty ? View.GONE : View.VISIBLE);

    List<Move> hints = null;
    if (mShowThinking || gameMode.analysisMode()) {
        ArrayList<ArrayList<Move>> pvMovesTmp = pvMoves;
        if (pvMovesTmp.size() == 1) {
            hints = pvMovesTmp.get(0);
        } else if (pvMovesTmp.size() > 1) {
            hints = new ArrayList<Move>();
            for (ArrayList<Move> pv : pvMovesTmp)
                if (!pv.isEmpty())
                    hints.add(pv.get(0));
        }
    }
    if ((hints == null) && mShowBookHints)
        hints = bookMoves;
    if (((hints == null) || hints.isEmpty()) && (variantMoves != null) && variantMoves.size() > 1) {
        hints = variantMoves;
    }
    if ((hints != null) && (hints.size() > maxNumArrows)) {
        hints = hints.subList(0, maxNumArrows);
        //System.out.println(hints);
    }
    //  hints=[b8a8];
    cb.setMoveHints(hints);
}

From source file:com.if3games.chessonline.DroidFish.java

private final void updateThinkingInfo() {
    boolean thinkingEmpty = true;
    {//from  w  w w .j  a  v  a  2  s  . co m
        String s = "";
        if (mShowThinking || gameMode.analysisMode()) {
            s = thinkingStr1;
            if (s.length() > 0)
                thinkingEmpty = false;
            if (mShowStats) {
                if (!thinkingEmpty)
                    s += "\n";
                s += thinkingStr2;
                if (s.length() > 0)
                    thinkingEmpty = false;
            }
        }
        thinking.setText(s, TextView.BufferType.SPANNABLE);
    }
    if (mShowBookHints && (bookInfoStr.length() > 0)) {
        String s = "";
        if (!thinkingEmpty)
            s += "<br>";
        s += Util.boldStart + getString(R.string.book) + Util.boldStop + bookInfoStr;
        thinking.append(Html.fromHtml(s));
        thinkingEmpty = false;
    }
    if (showVariationLine && (variantStr.indexOf(' ') >= 0)) {
        String s = "";
        if (!thinkingEmpty)
            s += "<br>";
        s += Util.boldStart + getString(R.string.variation) + Util.boldStop + variantStr;
        thinking.append(Html.fromHtml(s));
        thinkingEmpty = false;
    }
    thinking.setVisibility(thinkingEmpty ? View.GONE : View.VISIBLE);

    List<Move> hints = null;
    if (mShowThinking || gameMode.analysisMode()) {
        ArrayList<ArrayList<Move>> pvMovesTmp = pvMoves;
        if (pvMovesTmp.size() == 1) {
            hints = pvMovesTmp.get(0);
        } else if (pvMovesTmp.size() > 1) {
            hints = new ArrayList<Move>();
            for (ArrayList<Move> pv : pvMovesTmp)
                if (!pv.isEmpty())
                    hints.add(pv.get(0));
        }
    }
    if ((hints == null) && mShowBookHints)
        hints = bookMoves;
    if (((hints == null) || hints.isEmpty()) && (variantMoves != null) && variantMoves.size() > 1) {
        hints = variantMoves;
    }
    if ((hints != null) && (hints.size() > maxNumArrows)) {
        hints = hints.subList(0, maxNumArrows);
    }
    cb.setMoveHints(hints);
}

From source file:com.android.bluetooth.map.BluetoothMapContent.java

/**
 * Read out the mms parts and update the bMessage object provided i {@linkplain message}
 * @param id the content provider ID of the message
 * @param message the bMessage object to add the information to
 *///from   w w w.  jav a 2 s  .c om
private void extractEmailParts(long id, BluetoothMapbMessageMmsEmail message) {
    if (V)
        Log.v(TAG, "extractEmailParts with id " + id);
    String emailBody = "";
    Uri uriAddress = Uri.parse("content://com.android.email.provider/body");
    BluetoothMapbMessageMmsEmail.MimePart part;
    Cursor c = null;
    try {
        c = mResolver.query(uriAddress, Body.CONTENT_PROJECTION, BodyColumns.MESSAGE_KEY + "=?",
                new String[] { String.valueOf(id) }, null);
    } catch (Exception e) {

        Log.w(TAG, " EMAIL BODY QUERY FAILDED " + e);
    }
    if (c != null) {
        if (V)
            Log.v(TAG, "cursor not null");
        if (c.moveToFirst()) {
            String textContentURI = c.getString(c.getColumnIndex(BodyColumns.TEXT_CONTENT_URI));
            String htmlContentURI = c.getString(c.getColumnIndex(BodyColumns.HTML_CONTENT_URI));
            if (textContentURI != null || htmlContentURI != null) {
                if (V) {
                    Log.v(TAG, " EMAIL BODY textURI " + textContentURI);
                    Log.v(TAG, " EMAIL BODY htmlURI " + htmlContentURI);
                }
                // GET FD to parse text or HTML content
                ParcelFileDescriptor fd = null;
                if (textContentURI != null) {
                    try {
                        Log.v(TAG, " TRY EMAIL BODY textURI " + textContentURI);
                        fd = mResolver.openFileDescriptor(Uri.parse(textContentURI), "r");
                    } catch (FileNotFoundException e) {
                        if (V)
                            Log.w(TAG, e);
                    }
                }
                if (fd == null) {
                    if (htmlContentURI != null) {
                        //Try HTML content if  TEXT CONTENT NULL
                        try {
                            Log.v(TAG, " TRY EMAIL BODY htmlURI " + htmlContentURI);
                            fd = mResolver.openFileDescriptor(Uri.parse(htmlContentURI), "r");
                        } catch (FileNotFoundException e) {
                            if (V)
                                Log.w(TAG, e);
                        } catch (NullPointerException e) {
                            if (V)
                                Log.w(TAG, e);
                        }
                        String msgBody = null;
                        if (fd != null) {
                            msgBody = readEmailBodyForMessageFd(fd);
                        } else {
                            Log.w(TAG, " FETCH Email BODY File HTML URI FAILED");
                        }
                        if (msgBody != null) {
                            msgBody = msgBody.replaceAll("(?s)(<title>)(.*?)(</title>)", "");
                            msgBody = msgBody.replaceAll("(?s)(<style type=\"text/css\".*?>)(.*?)(</style>)",
                                    "");
                            CharSequence msgText = Html.fromHtml(msgBody);
                            emailBody = msgText.toString();
                            emailBody = emailBody.replaceAll("(?s)(<!--)(.*?)(-->)", "");
                            // Solves problem with Porche Car-kit and Gmails.
                            // Changes unix style line conclusion to DOS style
                            emailBody = emailBody.replaceAll("(?s)(\\r)", "");
                            emailBody = emailBody.replaceAll("(?s)(\\n)", "\r\n");
                        }
                    } else {
                        Log.w(TAG, " FETCH Email BODY File HTML URI FAILED");
                    }
                } else {
                    emailBody = readEmailBodyForMessageFd(fd);
                }
                //Set BMessage emailBody
                message.setEmailBody(emailBody);
                //Parts
                Long partId = c.getLong(c.getColumnIndex(BaseColumns._ID));
                String contentType = "Content-Type: text/plain; charset=\"UTF-8\"";
                String name = null;//c.getString(c.getColumnIndex("displayName"));
                String text = null;

                if (D)
                    Log.d(TAG, "     _id : " + partId + "\n     ct : " + contentType + "\n     partname : "
                            + name);

                part = message.addMimePart();
                part.contentType = contentType;
                part.partName = name;

                try {
                    if (emailBody != null) {
                        part.data = emailBody.getBytes("UTF-8");
                        part.charsetName = "utf-8";
                    }
                } catch (NumberFormatException e) {
                    Log.d(TAG, "extractEmailParts", e);
                    part.data = null;
                    part.charsetName = null;
                } catch (UnsupportedEncodingException e) {
                    Log.d(TAG, "extractEmailParts", e);
                    part.data = null;
                    part.charsetName = null;
                } finally {
                }
                try {
                    if (fd != null)
                        fd.close();
                } catch (IOException e) {
                }
            } else {
                Log.w(TAG, " FETCH Email BODY File URI FAILED");
            }
        }
        c.close();
    }
    message.updateCharset();
    message.setEncoding("8BIT");
}

From source file:com.zoho.creator.jframework.XMLParser.java

private static String getDecodedString(String encodedString) {
    if (encodedString != null) {
        return Html.fromHtml(encodedString).toString();
    } else {// w  w  w.ja v  a 2 s  .c  om
        return encodedString;
    }
}