项目:Customerly-Android-SDK
文件:IE_Message.java
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) : new SpannedString(pAttachments != null && pAttachments.length != 0 ? "[Attachment]" : "");
this._Attachments = pAttachments;
this.if_account__name = null;
this.rich_mail_link = null;
}
项目:NeoTerm
文件:MainActivity.java
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);
}
项目:tinkoff-asdk-android
文件:PaymentResultActivity.java
@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)),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);
}
项目:neveshtanak-Deprecated-
文件:App.java
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);
}
项目:Droidcon-India-2015
文件:HtmlUtils.java
/**
* 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("");
}
项目:friendspell
文件:CustomMatchers.java
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));
}
}
};
}
项目:transistor
文件:Tx3gDecoderTest.java
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,Object.class).length);
StyleSpan styleSpan = findSpan(text,5,StyleSpan.class);
assertEquals(Typeface.ITALIC,styleSpan.getStyle());
findSpan(text,7,12,Underlinespan.class);
ForegroundColorSpan colorSpan = findSpan(text,ForegroundColorSpan.class);
assertEquals(Color.GREEN,colorSpan.getForegroundColor());
colorSpan = findSpan(text,colorSpan.getForegroundColor());
assertFractionalLinePosition(subtitle.getCues(0).get(0),0.85f);
}
项目:transistor
文件:Tx3gDecoderTest.java
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,false);
SpannedString text = new SpannedString(subtitle.getCues(0).get(0).text);
assertEquals("CC Test",text.toString());
assertEquals(5,StyleSpan.class);
assertEquals(Typeface.BOLD_ITALIC,Underlinespan.class);
TypefaceSpan typefaceSpan = findSpan(text,TypefaceSpan.class);
assertEquals(C.SERIF_NAME,typefaceSpan.getFamily());
ForegroundColorSpan colorSpan = findSpan(text,ForegroundColorSpan.class);
assertEquals(Color.RED,6,0.1f);
}
项目:transistor
文件:Tx3gDecoderTest.java
项目:transistor
文件:Tx3gDecoderTest.java
项目:itsnat_droid
文件:XMLInflaterRegistry.java
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);
}
}
项目:learnforandroidfragAS
文件:_MainActivity.java
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);
}
}
}
项目:FanFictionReader
文件:AuthorProfileLoader.java
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;
}
项目:something.apk
文件:ThreadViewFragment.java
/**
* 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");
}
项目:something.apk
文件:ThreadViewFragment.java
/**
* 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");
}
项目:listen-later
文件:ScTextUtils.java
/**
* Like {@link android.text.Html#fromHtml(String)},but with line separation handling
* and guard against RuntimeExceptions.
*
* @param source the string to be transformed
* @return spanned text
*/
public static Spanned fromHtml(String source) {
if (source == null || TextUtils.isEmpty(source)) return new SpannedString("");
source = source.replace(System.getProperty("line.separator"),"<br/>");
try {
return Html.fromHtml(source);
} catch (RuntimeException e) {
if (e.getCause() instanceof IOException) {
// Pushback buffer full,retry with smaller input
return fromHtml(source.substring(0,source.length() / 2));
} else {
throw e;
}
}
}
项目:apps-android-wikipedia
文件:StringUtil.java
/**
* @param source String that may contain HTML tags.
* @return returned Spanned string that may contain spans parsed from the HTML source.
*/
@NonNull public static Spanned fromHtml(@Nullable String source) {
if (source == null) {
return new SpannedString("");
}
if (!source.contains("<")) {
// If the string doesn't contain any hints of HTML tags,then skip the expensive
// processing that fromHtml() performs.
return new SpannedString(source);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
return Html.fromHtml(source,Html.FROM_HTML_MODE_LEGACY);
} else {
//noinspection deprecation
return Html.fromHtml(source);
}
}
项目:GitHub
文件:UiUtils.java
/**
* 设置hint大小
*
* @param size
* @param v
* @param res
*/
public static void setViewHintSize(int size,TextView v,int res) {
SpannableString ss = new SpannableString(getResources().getString(
res));
// 新建一个属性对象,设置文字的大小
AbsoluteSizeSpan ass = new AbsoluteSizeSpan(size,true);
// 附加属性到文本
ss.setSpan(ass,ss.length(),Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
// 设置hint
v.setHint(new SpannedString(ss)); // 一定要进行转换,否则属性会消失
}
项目:yyox
文件:UiUtils.java
项目:AppCommonFrame
文件:UiUtils.java
项目:MVPArms_Fragment-fragment
文件:UiUtils.java
项目:MoligyMvpArms
文件:ArmsUtils.java
项目:PicShow-zhaipin
文件:UiUtils.java
项目:AboutView
文件:AboutView.java
private void setText(View perent,int id,String text,boolean html,boolean scrolling){
TextView tv = (TextView)perent.findViewById(id);
if (Utils.isEmpty(text)){
tv.setVisibility(View.GONE);
return;
}
if (html) {
setText(tv,Html.fromHtml(text,new BaseCustomTagHandler()),scrolling);
}else {
setText(tv,new SpannedString(text),scrolling);
}
}
项目:mvparms
文件:UiUtils.java
项目:NeiHanDuanZiTV
文件:ArmsUtils.java
/**
* Get new text paint.
*
* @param p init paint object
* @param text some text
* @param startInText start position in text
* @param endInText end position in text
* @return new instance of TextPaint
*/
@NonNull
private TextPaint getTextPaint(Paint p,CharSequence text,int startInText,int endInText) {
final TextPaint textPaint = new TextPaint(p);
if (text instanceof SpannedString) {
SpannedString spanned = (SpannedString) text;
final MetricAffectingSpan[] spans = spanned.getSpans(startInText,endInText,MetricAffectingSpan.class);
if (spans.length > 0) {
for (MetricAffectingSpan span : spans) {
span.updateMeasureState(textPaint);
}
}
}
return textPaint;
}
项目:Tusky
文件:SpannedTypeAdapter.java
@Override
public Spanned deserialize(JsonElement json,Type typeOfT,JsonDeserializationContext context)
throws JsonParseException {
String string = json.getAsstring();
if (string != null) {
return HtmlUtils.fromHtml(string);
} else {
return new SpannedString("");
}
}
项目:MVPArmsTest1
文件:UiUtils.java
@Override
public void onReportSuccess(final SpannedString spannedString) {
isReporting = false;
Assertions.assertNotNull(mReportButton).setEnabled(true);
Assertions.assertNotNull(mloadingIndicator).setVisibility(View.GONE);
Assertions.assertNotNull(mReportTextView).setText(spannedString);
}
@Override
public void onReportError(final SpannedString spannedString) {
isReporting = false;
Assertions.assertNotNull(mReportButton).setEnabled(true);
Assertions.assertNotNull(mloadingIndicator).setVisibility(View.GONE);
Assertions.assertNotNull(mReportTextView).setText(spannedString);
}
项目:MVVMArms
文件:UiUtils.java
@Override
public void onReportSuccess(final SpannedString spannedString) {
isReporting = false;
Assertions.assertNotNull(mReportButton).setEnabled(true);
Assertions.assertNotNull(mloadingIndicator).setVisibility(View.GONE);
Assertions.assertNotNull(mReportTextView).setText(spannedString);
}
@Override
public void onReportError(final SpannedString spannedString) {
isReporting = false;
Assertions.assertNotNull(mReportButton).setEnabled(true);
Assertions.assertNotNull(mloadingIndicator).setVisibility(View.GONE);
Assertions.assertNotNull(mReportTextView).setText(spannedString);
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。