下面列出了android.text.Html#toHtml ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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;
}
@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);
}
}
/**
* @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);
}
}
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;
}
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;
}
/**
* @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);
}
}
/**
* 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;
}
/**
* 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;
}
/**
* 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;
}
/**
* 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;
}
/**
* 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;
}
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");
}
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);
}
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);
}
}
/**
* 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;
}
public NTemplate(CharSequence text) {
mHtml = Html.toHtml(new SpannedString(text));
}
@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;
}
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());
}