本文整理汇总了Java中android.text.Spanned类的典型用法代码示例。如果您正苦于以下问题:Java Spanned类的具体用法?Java Spanned怎么用?Java Spanned使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Spanned类属于android.text包,在下文中一共展示了Spanned类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setEditable
import android.text.Spanned; //导入依赖的package包/类
/**
* Input frame character length limit
*
* @param mEdit EditText
* @param maxLength maxLength
*/
public void setEditable(EditText mEdit, int maxLength) {
if (mEdit.getText().length() < maxLength) {
mEdit.setFilters(new InputFilter[]{new InputFilter.LengthFilter(maxLength) {
}});
mEdit.setCursorVisible(true);
mEdit.setFocusableInTouchMode(true);
mEdit.requestFocus();
} else {
mEdit.setFilters(new InputFilter[]{new InputFilter() {
@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
return source.length() < 1 ? dest.subSequence(dstart, dend) : "";
}
}});
mEdit.setCursorVisible(false);
mEdit.setFocusableInTouchMode(false);
mEdit.clearFocus();
}
}
示例2: initMarqueeView3
import android.text.Spanned; //导入依赖的package包/类
private void initMarqueeView3() {
SimpleMF<Spanned> marqueeFactory3 = new SimpleMF<>(MainActivity.this);
List<Spanned> datas3 = new ArrayList<>();
datas3.add(Html.fromHtml("<font color=\"#ff0000\">《赋得古原草送别》</font>"));
datas3.add(Html.fromHtml("<font color=\"#00ff00\">离离原上草,</font>一岁一枯荣。"));
datas3.add(Html.fromHtml("野火烧不尽,<font color=\"#0000ff\">春风吹又生。</font>"));
datas3.add(Html.fromHtml("<font color=\"#333333\">远芳侵古道,晴翠接荒城。</font>"));
datas3.add(Html.fromHtml("<font color=\"#ffffff\">又送王孙去,萋萋满别情。</font>"));
marqueeFactory3.setData(datas3);
marqueeView3.setMarqueeFactory(marqueeFactory3);
marqueeView3.startFlipping();
marqueeFactory3.setOnItemClickListener(new MarqueeFactory.OnItemClickListener<TextView, Spanned>() {
@Override
public void onItemClickListener(MarqueeFactory.ViewHolder<TextView, Spanned> holder) {
Toast.makeText(MainActivity.this, holder.data, Toast.LENGTH_SHORT).show();
}
});
}
示例3: drawLeadingMargin
import android.text.Spanned; //导入依赖的package包/类
public void drawLeadingMargin(Canvas c, Paint p, int x, int dir,
int top, int baseline, int bottom,
CharSequence text, int start, int end,
boolean first, Layout layout) {
int st = ((Spanned) text).getSpanStart(this);
int itop = layout.getLineTop(layout.getLineForOffset(st));
if (dir < 0)
x -= mBitmap.getWidth();
int delta = totalHeight - mBitmap.getHeight();
if (delta > 0) {
if (mVerticalAlignment == ALIGN_TOP) {
c.drawBitmap(mBitmap, x, itop, p);
} else if (mVerticalAlignment == ALIGN_CENTER) {
c.drawBitmap(mBitmap, x, itop + delta / 2, p);
} else {
c.drawBitmap(mBitmap, x, itop + delta, p);
}
} else {
c.drawBitmap(mBitmap, x, itop, p);
}
}
示例4: prepareMainMessageString
import android.text.Spanned; //导入依赖的package包/类
/**
* Prepares text to be displayed as the infobar's main message, including setting up a
* clickable link if the infobar requires it.
*/
private CharSequence prepareMainMessageString() {
SpannableStringBuilder fullString = new SpannableStringBuilder();
if (mMessageMainText != null) fullString.append(mMessageMainText);
// Concatenate the text to display for the link and make it clickable.
if (!TextUtils.isEmpty(mMessageLinkText)) {
if (fullString.length() > 0) fullString.append(" ");
int spanStart = fullString.length();
fullString.append(mMessageLinkText);
fullString.setSpan(new ClickableSpan() {
@Override
public void onClick(View view) {
mInfoBarView.onLinkClicked();
}
}, spanStart, fullString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
return fullString;
}
示例5: testTextDecorationLineLineThroughApplied
import android.text.Spanned; //导入依赖的package包/类
@Test
public void testTextDecorationLineLineThroughApplied() {
UIManagerModule uiManager = getUIManagerModule();
ReactRootView rootView = createText(
uiManager,
JavaOnlyMap.of(ViewProps.TEXT_DECORATION_LINE, "line-through"),
JavaOnlyMap.of(ReactTextShadowNode.PROP_TEXT, "test text"));
TextView textView = (TextView) rootView.getChildAt(0);
Spanned text = (Spanned) textView.getText();
UnderlineSpan[] underlineSpans =
text.getSpans(0, text.length(), UnderlineSpan.class);
StrikethroughSpan strikeThroughSpan =
getSingleSpan(textView, StrikethroughSpan.class);
assertThat(underlineSpans).hasSize(0);
assertThat(strikeThroughSpan instanceof StrikethroughSpan).isTrue();
}
示例6: createMastodonApi
import android.text.Spanned; //导入依赖的package包/类
protected void createMastodonApi() {
mastodonApiDispatcher = new Dispatcher();
Gson gson = new GsonBuilder()
.registerTypeAdapter(Spanned.class, new SpannedTypeAdapter())
.create();
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
OkHttpClient.Builder okBuilder =
OkHttpUtils.getCompatibleClientBuilder(preferences)
.addInterceptor(new AuthInterceptor(this))
.dispatcher(mastodonApiDispatcher);
if (BuildConfig.DEBUG) {
okBuilder.addInterceptor(
new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BASIC));
}
Retrofit retrofit = new Retrofit.Builder().baseUrl(getBaseUrl())
.client(okBuilder.build())
.addConverterFactory(GsonConverterFactory.create(gson))
.build();
mastodonApi = retrofit.create(MastodonApi.class);
}
示例7: setText
import android.text.Spanned; //导入依赖的package包/类
public void setText(String text) {
int startIndex = 0;
while (true) {
int start = text.indexOf("《");
int end = text.indexOf("》");
if (start < 0 || end < 0) {
append(text.substring(startIndex));
break;
}
append(text.substring(startIndex, start));
SpannableString spanableInfo = new SpannableString(text.substring(start, end + 1));
spanableInfo.setSpan(new Clickable(spanableInfo.toString()), 0, end + 1 - start, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
append(spanableInfo);
//setMovementMethod()该方法必须调用,否则点击事件不响应
setMovementMethod(LinkMovementMethod.getInstance());
text = text.substring(end + 1);
LogUtils.e(spanableInfo.toString());
}
}
示例8: readNode
import android.text.Spanned; //导入依赖的package包/类
private void readNode(Object node, Table table) {
if (node instanceof TagNode) {
TagNode tagNode = (TagNode) node;
if (tagNode.getName().equals("td") || tagNode.getName().equals("th")) {
Spanned result = this.getSpanner().fromTagNode(tagNode);
table.addCell(result);
return;
}
if (tagNode.getName().equals("tr")) {
table.addRow();
}
for (Object child : tagNode.getChildTags()) {
readNode(child, table);
}
}
}
示例9: applyLink
import android.text.Spanned; //导入依赖的package包/类
private static final void applyLink(String url, int start, int end, Spannable text, final ColorStateList linkColor, final ColorStateList bgColor, QMUIOnSpanClickListener l) {
text.setSpan(new StyleableURLSpan(url, l) {
@Override
public void updateDrawState(TextPaint ds) {
if (linkColor != null) {
int normalLinkColor = linkColor.getColorForState(new int[]{android.R.attr.state_enabled, -android.R.attr.state_pressed}, Color.TRANSPARENT);
int pressedLinkColor = linkColor.getColorForState(new int[]{android.R.attr.state_pressed}, normalLinkColor);
ds.linkColor = mPressed ? pressedLinkColor : normalLinkColor;
}
if (bgColor != null) {
int normalBgColor = bgColor.getColorForState(new int[]{android.R.attr.state_enabled, -android.R.attr.state_pressed}, Color.TRANSPARENT);
int pressedBgColor = bgColor.getColorForState(new int[]{android.R.attr.state_pressed}, normalBgColor);
ds.bgColor = mPressed ? pressedBgColor : normalBgColor;
}
super.updateDrawState(ds);
ds.setUnderlineText(false);
}
}, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
示例10: matchMention
import android.text.Spanned; //导入依赖的package包/类
public static Spannable matchMention(Spannable spannable) {
String text = spannable.toString();
Pattern pattern = Pattern.compile(MATCH_MENTION);
Matcher matcher = pattern.matcher(text);
while (matcher.find()) {
String str = matcher.group();
int matcherStart = matcher.start();
int matcherEnd = matcher.end();
spannable.setSpan(new RichEditText.TagSpan(str), matcherStart, matcherEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
log("matchMention:" + str + " " + matcherStart + " " + matcherEnd);
}
return spannable;
}
示例11: filter
import android.text.Spanned; //导入依赖的package包/类
@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
if (end - start == 1) {
char c = source.charAt(0);
if (c == '.' || c == ',') {
onDotOrComma();
return "";
}
if (isIncomeExpenseEnabled()) {
if (c == '-') {
setExpense();
return "";
}
if (c == '+') {
setIncome();
return "";
}
}
}
return super.filter(source, start, end, dest, dstart, dend);
}
示例12: onUploadSuccess
import android.text.Spanned; //导入依赖的package包/类
private void onUploadSuccess(final QueuedMedia item, Attachment media) {
item.id = media.id;
item.preview.setProgress(-1);
item.readyStage = QueuedMedia.ReadyStage.UPLOADED;
/* Add the upload URL to the text field. Also, keep a reference to the span so if the user
* chooses to remove the media, the URL is also automatically removed. */
item.uploadUrl = new URLSpan(media.textUrl);
int end = 1 + media.textUrl.length();
SpannableStringBuilder builder = new SpannableStringBuilder();
builder.append(' ');
builder.append(media.textUrl);
builder.setSpan(item.uploadUrl, 1, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
int cursorStart = textEditor.getSelectionStart();
int cursorEnd = textEditor.getSelectionEnd();
textEditor.append(builder);
textEditor.setSelection(cursorStart, cursorEnd);
waitForMediaLatch.countDown();
}
示例13: fromHtml
import android.text.Spanned; //导入依赖的package包/类
public static Spanned fromHtml(String html){
Spanned result;
if (android.os.Build.VERSION.SDK_INT >= 24) {
result = Html.fromHtml(html, Html.FROM_HTML_MODE_LEGACY);
} else {
result = Html.fromHtml(html);
}
return result;
}
示例14: buildWavingSpans
import android.text.Spanned; //导入依赖的package包/类
@SuppressWarnings("Range") // Lint bug: the if makes sure waveCharDelay >= 0
private JumpingBeansSpan[] buildWavingSpans(SpannableStringBuilder sbb) {
JumpingBeansSpan[] spans;
if (waveCharDelay == DEFAULT_WAVE_CHAR_DELAY) {
waveCharDelay = loopDuration / (3 * (endPos - startPos));
}
spans = new JumpingBeansSpan[endPos - startPos];
for (int pos = startPos; pos < endPos; pos++) {
JumpingBeansSpan jumpingBean =
new JumpingBeansSpan(textView, loopDuration, pos - startPos, waveCharDelay, animRange);
sbb.setSpan(jumpingBean, pos, pos + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
spans[pos - startPos] = jumpingBean;
}
return spans;
}
示例15: filter
import android.text.Spanned; //导入依赖的package包/类
@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart,
int dend) {
// check black-list set
for (int i = 0; i < source.length(); i++) {
// LogUtil.e(Integer.toHexString(source.charAt(i)));
}
// LogUtil.e(source.toString() + " length: " + source.toString().length() +
// " ;bytes length: " + source.toString().getBytes().length);
// Iterator<String> iterator = filterSet.iterator();
// while (iterator.hasNext()) {
// String filter = iterator.next();
// if (filter.equals(source.toString())) {
// LogUtil.e(filter + " length: " + filter.length() +
// " ;bytes length: " + filter.getBytes().length);
// for (int i= 0; i < source.length(); i++){
// LogUtil.e(Integer.toHexString(source.charAt(i)));
// }
// return "";
// }
// }
if (filterSet.contains(source.toString())) {
return "";
}
return source;
}