android.text.Html#toHtml ( )源码实例Demo

下面列出了android.text.Html#toHtml ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Android-WYSIWYG-Editor   文件: InputExtensions.java
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());
    }
}
 
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;
}
 
源代码3 项目: StreamHub-Android-SDK   文件: NewActivity.java
@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);
    }
}
 
源代码4 项目: cronet   文件: ApiCompatibilityUtils.java
/**
 * @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);
    }
}
 
源代码5 项目: letv   文件: ShareCompat.java
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;
}
 
源代码6 项目: KakaoBot   文件: KakaoTalkListener.java
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;
}
 
源代码7 项目: 365browser   文件: ApiCompatibilityUtils.java
/**
 * @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);
    }
}
 
源代码8 项目: CodenameOne   文件: ShareCompat.java
/**
 * 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;
}
 
源代码9 项目: adt-leanback-support   文件: ShareCompat.java
/**
 * 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;
}
 
源代码10 项目: android-recipes-app   文件: ShareCompat.java
/**
 * 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;
}
 
源代码11 项目: V.FlyoutTest   文件: ShareCompat.java
/**
 * 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;
}
 
源代码12 项目: guideshow   文件: ShareCompat.java
/**
 * 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;
}
 
源代码13 项目: ImapNote2   文件: NoteDetailActivity.java
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");
    }
 
源代码14 项目: StreamHub-Android-SDK   文件: NewReviewActivity.java
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);
}
 
源代码15 项目: StreamHub-Android-SDK   文件: ReplyReview.java
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);
    }
}
 
源代码16 项目: android_9.0.0_r45   文件: ClipData.java
/**
 * 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;
}
 
源代码17 项目: cat-avatar-generator-app   文件: NTemplate.java
public NTemplate(CharSequence text) {
    mHtml = Html.toHtml(new SpannedString(text));
}
 
源代码18 项目: android-app   文件: MainActivity.java
@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;
}
 
源代码19 项目: StreamHub-Android-SDK   文件: EditReview.java
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());
}