Java Code Examples for android.text.Html#toHtml()

The following examples show how to use android.text.Html#toHtml() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NewActivity.java    From StreamHub-Android-SDK with MIT License 6 votes vote down vote up
@Override
public void onClick(View v) {

    if (!isNetworkAvailable()) {
        showAlert("No connection available", "TRY AGAIN", tryAgain);
        return;
    }
    String description = commentEt.getText().toString();
    if (description.length() == 0) {
        showAlert("Please enter text to post.", "TRY AGAIN", tryAgain);
        return;
    }
    if (purpose.equals(Constant.NEW_COMMENT)) {
        String descriptionHTML = Html.toHtml((android.text.Spanned) commentEt.getText());
        postNewComment(descriptionHTML);
    } else {
        String htmlReplyText = Html.toHtml((android.text.Spanned) commentEt.getText());
        postNewReply(htmlReplyText);
    }
}
 
Example 2
Source File: InputExtensions.java    From Android-WYSIWYG-Editor with Apache License 2.0 6 votes vote down vote up
public void insertLink(String uri) {
    EditorType editorType = editorCore.getControlType(editorCore.getActiveView());
    EditText editText = (EditText) editorCore.getActiveView();
    if (editorType == EditorType.INPUT || editorType == EditorType.UL_LI) {
        String text = Html.toHtml(editText.getText());
        if (TextUtils.isEmpty(text))
            text = "<p dir=\"ltr\"></p>";
        text = trimLineEnding(text);
        Document _doc = Jsoup.parse(text);
        Elements x = _doc.select("p");
        String existing = x.get(0).html();
        x.get(0).html(existing + " <a href='" + uri + "'>" + uri + "</a>");
        Spanned toTrim = Html.fromHtml(x.toString());
        CharSequence trimmed = noTrailingwhiteLines(toTrim);
        editText.setText(trimmed);   //
        editText.setSelection(editText.getText().length());
    }
}
 
Example 3
Source File: ShareCompat$IntentReader.java    From MiBandDecompiled with Apache License 2.0 6 votes vote down vote up
public String getHtmlText()
{
    String s = c.getStringExtra("android.intent.extra.HTML_TEXT");
    if (c == null)
    {
        CharSequence charsequence = getText();
        if (charsequence instanceof Spanned)
        {
            return Html.toHtml((Spanned)charsequence);
        }
        if (charsequence != null)
        {
            return ShareCompat.a().a(charsequence);
        }
    }
    return s;
}
 
Example 4
Source File: ShareCompat.java    From adt-leanback-support with Apache License 2.0 5 votes vote down vote up
/**
 * Get the styled HTML text shared with the target activity.
 * If no HTML text was supplied but {@link Intent#EXTRA_TEXT} contained
 * styled text, it will be converted to HTML if possible and returned.
 * If the text provided by {@link Intent#EXTRA_TEXT} was not styled text,
 * it will be escaped by {@link android.text.Html#escapeHtml(CharSequence)}
 * and returned. If no text was provided at all, this method will return null.
 *
 * @return Styled text provided by the sender as HTML.
 */
public String getHtmlText() {
    String result = mIntent.getStringExtra(IntentCompat.EXTRA_HTML_TEXT);
    if (result == null) {
        CharSequence text = getText();
        if (text instanceof Spanned) {
            result = Html.toHtml((Spanned) text);
        } else if (text != null) {
            result = IMPL.escapeHtml(text);
        }
    }
    return result;
}
 
Example 5
Source File: ReplyReview.java    From StreamHub-Android-SDK with MIT License 5 votes vote down vote up
public void onClick(View v) {
    if (!isNetworkAvailable()) {
        showToast("Network Not Available");
        return;
    }
    replytext = newReplyEt.getText().toString();
    if (replytext.length() != 0) {
        String htmlReplytext = Html.toHtml(newReplyEt.getText());
        Log.d("htmlReplytext", htmlReplytext);
        postNewReply(htmlReplytext);
    } else {
        showAlert("Please enter text before post.",
                "TRY AGAIN", null);
    }
}
 
Example 6
Source File: NewReviewActivity.java    From StreamHub-Android-SDK with MIT License 5 votes vote down vote up
public void onClick(View v) {
    String title = newReviewTitleEt.getText().toString();
    String description = newReviewBodyEt.getText().toString();
    String pros = newReviewProsEt.getText().toString();
    String cons = newReviewConsEt.getText().toString();
    int reviewRating = (int) (newReviewRatingBar.getRating() * 20);
    if (title.length() == 0) {
        ((EditText) findViewById(R.id.newReviewTitleEt)).setError("Enter Title");
        return;
    }
    if (reviewRating == 0) {
        showAlert("Please give Rating.", "ok", tryAgain);
        return;
    }
    if (pros.length() == 0) {
        ((EditText) findViewById(R.id.newReviewProsEt)).setError("Enter Pros");
        return;
    }
    if (cons.length() == 0) {
        ((EditText) findViewById(R.id.newReviewConsEt)).setError("Enter Cons");
        return;
    }
    if (description.length() == 0) {
        ((EditText) findViewById(R.id.newReviewProsEt)).setError("Enter Description");
        return;
    }
    String descriptionHTML = Html.toHtml(newReviewBodyEt.getText());
    if (pros.length() > 0 || cons.length() > 0) {
        descriptionHTML = "<p><b>Pro</b><p>"
                + Html.toHtml(newReviewProsEt.getText()) + "</p></p>"
                + "<p><b>Cons</b><p>"
                + Html.toHtml(newReviewConsEt.getText()) + "</p></p>"
                + " <p><b>Description</b><p>" + descriptionHTML
                + "</p></p>";
    }
    postNewReview(newReviewTitleEt.getText().toString(),
            descriptionHTML, reviewRating);
}
 
Example 7
Source File: NoteDetailActivity.java    From ImapNote2 with GNU General Public License v3.0 5 votes vote down vote up
private Sticky ReadHtmlnote(String stringres) {
//        Log.d(TAG,"From server (html):"+stringres);
        Spanned spanres = Html.fromHtml(stringres);
        stringres = Html.toHtml(spanres);
        stringres = stringres.replaceFirst("<p dir=ltr>", "");
        stringres = stringres.replaceFirst("<p dir=\"ltr\">", "");
        stringres = stringres.replaceAll("<p dir=ltr>", "<br>");
        stringres = stringres.replaceAll("<p dir=\"ltr\">", "<br>");
        stringres = stringres.replaceAll("</p>", "");

        return new Sticky(stringres, "", "NONE");
    }
 
Example 8
Source File: ShareCompat.java    From guideshow with MIT License 5 votes vote down vote up
/**
 * Get the styled HTML text shared with the target activity.
 * If no HTML text was supplied but {@link Intent#EXTRA_TEXT} contained
 * styled text, it will be converted to HTML if possible and returned.
 * If the text provided by {@link Intent#EXTRA_TEXT} was not styled text,
 * it will be escaped by {@link android.text.Html#escapeHtml(CharSequence)}
 * and returned. If no text was provided at all, this method will return null.
 *
 * @return Styled text provided by the sender as HTML.
 */
public String getHtmlText() {
    String result = mIntent.getStringExtra(IntentCompat.EXTRA_HTML_TEXT);
    if (result == null) {
        CharSequence text = getText();
        if (text instanceof Spanned) {
            result = Html.toHtml((Spanned) text);
        } else if (text != null) {
            result = IMPL.escapeHtml(text);
        }
    }
    return result;
}
 
Example 9
Source File: ShareCompat.java    From V.FlyoutTest with MIT License 5 votes vote down vote up
/**
 * Get the styled HTML text shared with the target activity.
 * If no HTML text was supplied but {@link Intent#EXTRA_TEXT} contained
 * styled text, it will be converted to HTML if possible and returned.
 * If the text provided by {@link Intent#EXTRA_TEXT} was not styled text,
 * it will be escaped by {@link android.text.Html#escapeHtml(CharSequence)}
 * and returned. If no text was provided at all, this method will return null.
 *
 * @return Styled text provided by the sender as HTML.
 */
public String getHtmlText() {
    String result = mIntent.getStringExtra(IntentCompat.EXTRA_HTML_TEXT);
    if (result == null) {
        CharSequence text = getText();
        if (text instanceof Spanned) {
            result = Html.toHtml((Spanned) text);
        } else if (text != null) {
            result = IMPL.escapeHtml(text);
        }
    }
    return result;
}
 
Example 10
Source File: ShareCompat.java    From android-recipes-app with Apache License 2.0 5 votes vote down vote up
/**
 * Get the styled HTML text shared with the target activity.
 * If no HTML text was supplied but {@link Intent#EXTRA_TEXT} contained
 * styled text, it will be converted to HTML if possible and returned.
 * If the text provided by {@link Intent#EXTRA_TEXT} was not styled text,
 * it will be escaped by {@link android.text.Html#escapeHtml(CharSequence)}
 * and returned. If no text was provided at all, this method will return null.
 *
 * @return Styled text provided by the sender as HTML.
 */
public String getHtmlText() {
    String result = mIntent.getStringExtra(IntentCompat.EXTRA_HTML_TEXT);
    if (result == null) {
        CharSequence text = getText();
        if (text instanceof Spanned) {
            result = Html.toHtml((Spanned) text);
        } else if (text != null) {
            result = IMPL.escapeHtml(text);
        }
    }
    return result;
}
 
Example 11
Source File: ShareCompat.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the styled HTML text shared with the target activity.
 * If no HTML text was supplied but {@link Intent#EXTRA_TEXT} contained
 * styled text, it will be converted to HTML if possible and returned.
 * If the text provided by {@link Intent#EXTRA_TEXT} was not styled text,
 * it will be escaped by {@link android.text.Html#escapeHtml(CharSequence)}
 * and returned. If no text was provided at all, this method will return null.
 *
 * @return Styled text provided by the sender as HTML.
 */
public String getHtmlText() {
    String result = mIntent.getStringExtra(IntentCompat.EXTRA_HTML_TEXT);
    if (mIntent == null) {
        CharSequence text = getText();
        if (text instanceof Spanned) {
            result = Html.toHtml((Spanned) text);
        } else if (text != null) {
            result = IMPL.escapeHtml(text);
        }
    }
    return result;
}
 
Example 12
Source File: ApiCompatibilityUtils.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * @see android.text.Html#toHtml(Spanned, int)
 * @param option is ignored on below N
 */
@SuppressWarnings("deprecation")
public static String toHtml(Spanned spanned, int option) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        return Html.toHtml(spanned, option);
    } else {
        return Html.toHtml(spanned);
    }
}
 
Example 13
Source File: KakaoTalkListener.java    From KakaoBot with GNU General Public License v3.0 5 votes vote down vote up
private Type.Message parsingMessage(String title, Object index) {
    Type.Message result = new Type.Message();
    result.room = title;

    if(index instanceof String) {
        result.sender = title;
        result.message = (String) index;
    } else {
        String html = Html.toHtml((SpannableString) index);
        result.sender = Html.fromHtml(html.split("<b>")[1].split("</b>")[0]).toString();
        result.message = Html.fromHtml(html.split("</b>")[1].split("</p>")[0].substring(1)).toString();
    }

    return result;
}
 
Example 14
Source File: ShareCompat.java    From letv with Apache License 2.0 5 votes vote down vote up
public String getHtmlText() {
    String result = this.mIntent.getStringExtra(IntentCompat.EXTRA_HTML_TEXT);
    if (result != null) {
        return result;
    }
    CharSequence text = getText();
    if (text instanceof Spanned) {
        return Html.toHtml((Spanned) text);
    }
    if (text != null) {
        return ShareCompat.IMPL.escapeHtml(text);
    }
    return result;
}
 
Example 15
Source File: ApiCompatibilityUtils.java    From cronet with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @see android.text.Html#toHtml(Spanned, int)
 * @param option is ignored on below N
 */
@SuppressWarnings("deprecation")
public static String toHtml(Spanned spanned, int option) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        return Html.toHtml(spanned, option);
    } else {
        return Html.toHtml(spanned);
    }
}
 
Example 16
Source File: MainActivity.java    From android-app with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
    switch (item.getItemId()) {
        case R.id.nav_mainLists:
            setCurrentFragment(FRAGMENT_ARTICLE_LISTS);
            break;

        case R.id.nav_tags:
            setCurrentFragment(FRAGMENT_TAG_LIST);
            break;

        case R.id.nav_add:
            showAddBagDialog();
            break;

        case R.id.nav_settings:
            startActivity(new Intent(getBaseContext(), SettingsActivity.class));
            break;

        case R.id.nav_about:
            Libs.ActivityStyle style;
            switch (Themes.getCurrentTheme()) {
                case DARK:
                case DARK_CONTRAST:
                    style = Libs.ActivityStyle.DARK;
                    break;

                default:
                    style = Libs.ActivityStyle.LIGHT_DARK_TOOLBAR;
                    break;
            }
            CharSequence aboutCharSequence = getText(R.string.aboutText);
            String aboutString = aboutCharSequence instanceof Spanned
                    ? Html.toHtml((Spanned) aboutCharSequence)
                    : aboutCharSequence.toString();
            new LibsBuilder()
                    .withActivityStyle(style)
                    .withAboutIconShown(true)
                    .withAboutVersionShown(true)
                    .withAboutDescription(aboutString)
                    .start(this);
            break;
    }

    this.<DrawerLayout>findViewById(R.id.drawer_layout).closeDrawer(GravityCompat.START);
    return true;
}
 
Example 17
Source File: ClipData.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * Turn this item into HTML text, regardless of the type of data it
 * actually contains.
 *
 * <p>The algorithm for deciding what text to return is:
 * <ul>
 * <li> If {@link #getHtmlText} is non-null, return that.
 * <li> If {@link #getText} is non-null, return that, converting to
 * valid HTML text.  If this text contains style spans,
 * {@link Html#toHtml(Spanned) Html.toHtml(Spanned)} is used to
 * convert them to HTML formatting.
 * <li> If {@link #getUri} is non-null, try to retrieve its data
 * as a text stream from its content provider.  If the provider can
 * supply text/html data, that will be preferred and returned as-is.
 * Otherwise, any text/* data will be returned and escaped to HTML.
 * If it is not a content: URI or the content provider does not supply
 * a text representation, HTML text containing a link to the URI
 * will be returned.
 * <li> If {@link #getIntent} is non-null, convert that to an intent:
 * URI and return as an HTML link.
 * <li> Otherwise, return an empty string.
 * </ul>
 *
 * @param context The caller's Context, from which its ContentResolver
 * and other things can be retrieved.
 * @return Returns the item's representation as HTML text.
 */
public String coerceToHtmlText(Context context) {
    // If the item has an explicit HTML value, simply return that.
    String htmlText = getHtmlText();
    if (htmlText != null) {
        return htmlText;
    }

    // If this Item has a plain text value, return it as HTML.
    CharSequence text = getText();
    if (text != null) {
        if (text instanceof Spanned) {
            return Html.toHtml((Spanned)text);
        }
        return Html.escapeHtml(text);
    }

    text = coerceToHtmlOrStyledText(context, false);
    return text != null ? text.toString() : null;
}
 
Example 18
Source File: NTemplate.java    From cat-avatar-generator-app with Apache License 2.0 4 votes vote down vote up
public NTemplate(CharSequence text) {
    mHtml = Html.toHtml(new SpannedString(text));
}
 
Example 19
Source File: EditReview.java    From StreamHub-Android-SDK with MIT License 4 votes vote down vote up
public void onClick(View v) {
    if (!isNetworkAvailable()) {
        showToast("Network Not Available");
        return;
    }
    showProgressDialog();
    title = editReviewTitleEt.getText().toString();
    body = editReviewBodyEt.getText().toString();
    rating = (int) (editReviewRatingBar.getRating() * 20);

    if (title.length() == 0) {
        showAlert("Please enter title before post.",
                "ok", tryAgain);
        return;
    }
    if (body.length() == 0) {
        showAlert("Please enter description before post.",
                "ok", tryAgain);
        return;
    }
    if (rating == 0) {
        showAlert("Please give rating before post.",
                "ok", tryAgain);
        return;
    }
    String htmlBody = Html.toHtml(editReviewBodyEt.getText());
    RequestParams parameters = new RequestParams();
    parameters.put(LFSConstants.LFSPostBodyKey, htmlBody);
    parameters.put(LFSConstants.LFSPostTitleKey, editReviewTitleEt
            .getText().toString());
    parameters.put(LFSConstants.LFSPostType,
            LFSConstants.LFSPostTypeReview);
    JSONObject ratingJson = new JSONObject();
    try {
        ratingJson.put("default", rating + "");
        parameters.put(LFSConstants.LFSPostRatingKey,
                ratingJson.toString());
    } catch (JSONException e) {
        e.printStackTrace();
    }
    parameters.put(LFSConstants.LFSPostUserTokenKey,
            LFSConfig.USER_TOKEN);
    WriteClient.postAction(LFSConfig.COLLECTION_ID, id,
            LFSConfig.USER_TOKEN, LFSActions.EDIT, parameters,
            new editCallback());
}