本文整理汇总了Java中android.text.SpannedString类的典型用法代码示例。如果您正苦于以下问题:Java SpannedString类的具体用法?Java SpannedString怎么用?Java SpannedString使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SpannedString类属于android.text包,在下文中一共展示了SpannedString类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: IE_Message
import android.text.SpannedString; //导入依赖的package包/类
IE_Message(long pCustomerly_User_ID, long pConversationID, @NonNull String pContent, @Nullable final IE_Attachment[] pAttachments) {
super();
this._STATE = STATE.SENDING;
this.user_id = pCustomerly_User_ID;
this.conversation_id = pConversationID;
this.conversation_message_id = 0;
this.account_id = 0;
this.sent_datetime_sec = this.seen_date = System.currentTimeMillis() / 1000;
this.dateString = _DATE_FORMATTER.format(new Date(this.sent_datetime_sec * 1000));
this.timeString = _TIME_FORMATTER.format(new Date(this.sent_datetime_sec * 1000));
this.content = pContent;
this.content_Spanned= IU_Utils.fromHtml(pContent, null, null);
this.content_abstract = pContent.length() != 0 ? IU_Utils.fromHtml(pContent, null, null) : new SpannedString(pAttachments != null && pAttachments.length != 0 ? "[Attachment]" : "");
this._Attachments = pAttachments;
this.if_account__name = null;
this.rich_mail_link = null;
}
示例2: setText
import android.text.SpannedString; //导入依赖的package包/类
public void setText(final String t) {
class Callback implements Runnable {
MainActivity Parent;
public SpannedString text;
public void run() {
Parent.setUpStatusLabel();
if (Parent._tv != null)
Parent._tv.setText(text);
}
}
Callback cb = new Callback();
cb.text = new SpannedString(t);
cb.Parent = this;
this.runOnUiThread(cb);
}
示例3: onCreate
import android.text.SpannedString; //导入依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_payment_result);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
final Money price = (Money) getIntent().getSerializableExtra(EXTRA_PRICE);
if (price == null) {
throw new IllegalArgumentException("Use start() method to start AboutActivity");
}
final SpannableString coloredPrice = new SpannableString(price.toString());
coloredPrice.setSpan(
new ForegroundColorSpan(ContextCompat.getColor(this, R.color.colorPrimary)),
0,
coloredPrice.length(),
SpannedString.SPAN_INCLUSIVE_INCLUSIVE
);
final String text = getString(R.string.payment_result_success, coloredPrice);
final TextView textView = (TextView) findViewById(R.id.tv_confirm);
textView.setText(text);
}
示例4: fontAndReshape
import android.text.SpannedString; //导入依赖的package包/类
public static void fontAndReshape(TextView tv) {
String text = "";
if (tv.getText() instanceof SpannedString) {
text = ((SpannedString) tv.getText()).toString();
} else if (tv.getText() instanceof SpannableString) {
text = ((SpannableString) tv.getText()).toString();
} else {
text = (String) tv.getText();
}
if (tv instanceof StyledTextView)
((StyledTextView) tv).setPlainText(text, BufferType.NORMAL);
else if (tv instanceof StyledButton)
((StyledButton) tv).setPlainText(text, BufferType.NORMAL);
else if (tv instanceof StyledEditText)
((StyledEditText) tv).setPlainText(text, BufferType.NORMAL);
tv.setTypeface(getFont("Yekan"));
tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
}
示例5: trimWhitespace
import android.text.SpannedString; //导入依赖的package包/类
/**
* Trims trailing whitespace. Removes any of these characters:
* 0009, HORIZONTAL TABULATION
* 000A, LINE FEED
* 000B, VERTICAL TABULATION
* 000C, FORM FEED
* 000D, CARRIAGE RETURN
* 001C, FILE SEPARATOR
* 001D, GROUP SEPARATOR
* 001E, RECORD SEPARATOR
* 001F, UNIT SEPARATOR
*
* @return "" if source is null, otherwise string with all trailing whitespace removed
*/
private static Spanned trimWhitespace(Spanned source) {
if (TextUtils.isEmpty(source)) {
return new SpannedString("");
}
int trailingIndex = source.length();
// loop back to the first non-whitespace character
while (--trailingIndex >= 0 && Character.isWhitespace(source.charAt(trailingIndex))) {
}
int leadingIndex = -1;
// loop back to the first non-whitespace character
while (++leadingIndex < source.length() && Character.isWhitespace(source.charAt(leadingIndex))) {
}
if (leadingIndex >= 0 && leadingIndex < source.length()
&& trailingIndex >= 0 && trailingIndex < source.length()
&& leadingIndex <= trailingIndex) {
return ((Spanned) source.subSequence(leadingIndex, trailingIndex + 1));
}
return new SpannedString("");
}
示例6: withColors
import android.text.SpannedString; //导入依赖的package包/类
public static Matcher<View> withColors(final int... colors) {
return new BoundedMatcher<View, TextView>(TextView.class) {
@Override public boolean matchesSafely(TextView textView) {
SpannedString text = (SpannedString) textView.getText();
ForegroundColorSpan[] spans = text.getSpans(0, text.length(), ForegroundColorSpan.class);
if (spans.length != colors.length) {
return false;
}
for (int i = 0; i < colors.length; ++i) {
if (spans[i].getForegroundColor() != colors[i]) {
return false;
}
}
return true;
}
@Override public void describeTo(Description description) {
description.appendText("has colors:");
for (int color : colors) {
description.appendText(" " + getHexColor(color));
}
}
};
}
示例7: testDecodeWithMultipleStyl
import android.text.SpannedString; //导入依赖的package包/类
public void testDecodeWithMultipleStyl() throws IOException, SubtitleDecoderException {
Tx3gDecoder decoder = new Tx3gDecoder(Collections.<byte[]>emptyList());
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), SAMPLE_WITH_MULTIPLE_STYL);
Subtitle subtitle = decoder.decode(bytes, bytes.length, false);
SpannedString text = new SpannedString(subtitle.getCues(0).get(0).text);
assertEquals("Line 2\nLine 3", text.toString());
assertEquals(4, text.getSpans(0, text.length(), Object.class).length);
StyleSpan styleSpan = findSpan(text, 0, 5, StyleSpan.class);
assertEquals(Typeface.ITALIC, styleSpan.getStyle());
findSpan(text, 7, 12, UnderlineSpan.class);
ForegroundColorSpan colorSpan = findSpan(text, 0, 5, ForegroundColorSpan.class);
assertEquals(Color.GREEN, colorSpan.getForegroundColor());
colorSpan = findSpan(text, 7, 12, ForegroundColorSpan.class);
assertEquals(Color.GREEN, colorSpan.getForegroundColor());
assertFractionalLinePosition(subtitle.getCues(0).get(0), 0.85f);
}
示例8: testInitializationDecodeWithStyl
import android.text.SpannedString; //导入依赖的package包/类
public void testInitializationDecodeWithStyl() throws IOException, SubtitleDecoderException {
byte[] initBytes = TestUtil.getByteArray(getInstrumentation(), INITIALIZATION);
Tx3gDecoder decoder = new Tx3gDecoder(Collections.singletonList(initBytes));
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), SAMPLE_WITH_STYL);
Subtitle subtitle = decoder.decode(bytes, bytes.length, false);
SpannedString text = new SpannedString(subtitle.getCues(0).get(0).text);
assertEquals("CC Test", text.toString());
assertEquals(5, text.getSpans(0, text.length(), Object.class).length);
StyleSpan styleSpan = findSpan(text, 0, text.length(), StyleSpan.class);
assertEquals(Typeface.BOLD_ITALIC, styleSpan.getStyle());
findSpan(text, 0, text.length(), UnderlineSpan.class);
TypefaceSpan typefaceSpan = findSpan(text, 0, text.length(), TypefaceSpan.class);
assertEquals(C.SERIF_NAME, typefaceSpan.getFamily());
ForegroundColorSpan colorSpan = findSpan(text, 0, text.length(), ForegroundColorSpan.class);
assertEquals(Color.RED, colorSpan.getForegroundColor());
colorSpan = findSpan(text, 0, 6, ForegroundColorSpan.class);
assertEquals(Color.GREEN, colorSpan.getForegroundColor());
assertFractionalLinePosition(subtitle.getCues(0).get(0), 0.1f);
}
示例9: testInitializationDecodeWithTbox
import android.text.SpannedString; //导入依赖的package包/类
public void testInitializationDecodeWithTbox() throws IOException, SubtitleDecoderException {
byte[] initBytes = TestUtil.getByteArray(getInstrumentation(), INITIALIZATION);
Tx3gDecoder decoder = new Tx3gDecoder(Collections.singletonList(initBytes));
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), SAMPLE_WITH_TBOX);
Subtitle subtitle = decoder.decode(bytes, bytes.length, false);
SpannedString text = new SpannedString(subtitle.getCues(0).get(0).text);
assertEquals("CC Test", text.toString());
assertEquals(4, text.getSpans(0, text.length(), Object.class).length);
StyleSpan styleSpan = findSpan(text, 0, text.length(), StyleSpan.class);
assertEquals(Typeface.BOLD_ITALIC, styleSpan.getStyle());
findSpan(text, 0, text.length(), UnderlineSpan.class);
TypefaceSpan typefaceSpan = findSpan(text, 0, text.length(), TypefaceSpan.class);
assertEquals(C.SERIF_NAME, typefaceSpan.getFamily());
ForegroundColorSpan colorSpan = findSpan(text, 0, text.length(), ForegroundColorSpan.class);
assertEquals(Color.RED, colorSpan.getForegroundColor());
assertFractionalLinePosition(subtitle.getCues(0).get(0), 0.1875f);
}
示例10: testInitializationAllDefaultsDecodeWithStyl
import android.text.SpannedString; //导入依赖的package包/类
public void testInitializationAllDefaultsDecodeWithStyl() throws IOException,
SubtitleDecoderException {
byte[] initBytes = TestUtil.getByteArray(getInstrumentation(), INITIALIZATION_ALL_DEFAULTS);
Tx3gDecoder decoder = new Tx3gDecoder(Collections.singletonList(initBytes));
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), SAMPLE_WITH_STYL);
Subtitle subtitle = decoder.decode(bytes, bytes.length, false);
SpannedString text = new SpannedString(subtitle.getCues(0).get(0).text);
assertEquals("CC Test", text.toString());
assertEquals(3, text.getSpans(0, text.length(), Object.class).length);
StyleSpan styleSpan = findSpan(text, 0, 6, StyleSpan.class);
assertEquals(Typeface.BOLD_ITALIC, styleSpan.getStyle());
findSpan(text, 0, 6, UnderlineSpan.class);
ForegroundColorSpan colorSpan = findSpan(text, 0, 6, ForegroundColorSpan.class);
assertEquals(Color.GREEN, colorSpan.getForegroundColor());
assertFractionalLinePosition(subtitle.getCues(0).get(0), 0.85f);
}
示例11: getTextCompiled
import android.text.SpannedString; //导入依赖的package包/类
private CharSequence getTextCompiled(String resourceDescValue, Context ctx)
{
if (isResource(resourceDescValue))
{
int resId = getIdentifierCompiled(resourceDescValue, ctx);
if (resId == 0) throw new ItsNatDroidException("Resource id value cannot be @null for a text resource");
return ctx.getResources().getText(resId);
}
else
{
// Vemos si contiene HTML, nos ahorraremos el procesado como HTML sin serlo y además conseguiremos que funcionen los tests a nivel de misma clase devuelta, pues Android
// parece que hace lo mismo, es decir cuando no es HTML devuelve un String en vez de un SpannedString.
if (isHTML(resourceDescValue))
{
Spanned spannedValue = Html.fromHtml(resourceDescValue);
return new SpannedString(spannedValue); // Para que el tipo devuelto sea el mismo que en el caso compilado y pasemos los tests
}
return StringUtil.convertEscapedStringLiteralToNormalString(resourceDescValue);
}
}
示例12: SetTxtStatusSize
import android.text.SpannedString; //导入依赖的package包/类
private void SetTxtStatusSize(int width)
{
if (width == 0) width = mainView.getWidth();
if (width == 0 && _OriginalWidth == 0) return;
if (width == 0) width = _OriginalWidth;
_OriginalWidth = width;
TextView t = _txtStatus;
Paint p = new Paint();
if (t.getText() instanceof SpannedString)
{
p.setTextSize(t.getTextSize());
SpannedString s = (SpannedString) t.getText();
width = width - width / (_isSmallDevice ? 4 : 5);
float measuredWidth = p.measureText(s.toString());
if (measuredWidth != width)
{
float scaleA = (float) width / measuredWidth;
if (libString.IsNullOrEmpty(_vok.getFileName())) scaleA *= .75f;
if (scaleA < .5f) scaleA = .5f;
if (scaleA > 2.0f) scaleA = 2.0f;
float size = t.getTextSize();
t.setTextSize(TypedValue.COMPLEX_UNIT_PX, size * scaleA);
}
}
}
示例13: load
import android.text.SpannedString; //导入依赖的package包/类
protected boolean load(Document document, List<Spanned> list) {
Elements summaries = document.select("div#content > div");
if (summaries.size() < 3) {
SpannedString string = new SpannedString(getContext()
.getString(R.string.menu_author_no_profile));
list.add(string);
return true;
}
Element txtElement = summaries.get(2);
Element dateElement = summaries.get(1);
Spanned txt = Html.fromHtml(txtElement.html());
Spanned date = Html.fromHtml(dateElement.html());
list.addAll(Parser.split(txt));
list.addAll(Parser.split(date));
return true;
}
示例14: loadThread
import android.text.SpannedString; //导入依赖的package包/类
/**
* Trigger page load of specific thread. Called by thread list or url links.
* See startRefresh() and ./request/ThreadPageRequest for volley implementation.
* @param threadId Thread ID for requested thread. (Required)
* @param page Page number to load, Optional, if -1 will go to last post, if 0 will go to newest unread post.
* @param userId (Optional) UserId for filtering.
* @param fromUrl True if request was sent by internal URL request. Used to decide if we should push current state into backstack.
*/
public void loadThread(int threadId, int page, int userId, boolean fromUrl) {
if(fromUrl && isThreadLoaded()){
threadBackstack.push(saveThreadState(new Bundle()));
}else{
threadBackstack.clear();
}
this.ignorePageProgress = true;
this.threadId = threadId;
this.page = page;
this.userId = userId;
this.maxPage = 0;
this.forumId = 0;
this.bookmarked = false;
this.threadTitle = new SpannedString(getString(R.string.thread_view_loading));
setTitle(threadTitle);
invalidateOptionsMenu();
updateNavbar();
startRefresh();
threadView.loadUrl("about:blank");
}
示例15: loadPost
import android.text.SpannedString; //导入依赖的package包/类
/**
* Trigger page load of specific thread by redirecting from a postID. Called by thread list or url links.
* See startRefresh() and ./request/ThreadPageRequest for volley implementation.
* @param postId Post ID to redirect to. (Required)
* @param fromUrl True if request was sent by internal URL request. Used to decide if we should push current state into backstack.
*/
public void loadPost(long postId, boolean fromUrl){
if(fromUrl && isThreadLoaded()){
threadBackstack.push(saveThreadState(new Bundle()));
}else{
threadBackstack.clear();
}
this.ignorePageProgress = true;
this.postId = postId;
this.threadId = 0;
this.page = 0;
this.maxPage = 0;
this.forumId = 0;
this.bookmarked = false;
this.threadTitle = new SpannedString(getString(R.string.thread_view_loading));
setTitle(threadTitle);
invalidateOptionsMenu();
updateNavbar();
startRefresh();
threadView.loadUrl("about:blank");
}