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; }
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); }
@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); }
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); }
/** * 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(""); }
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)); } } }; }
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); }
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); }
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); }
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); }
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); } }
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); } } }
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; }
/** * 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"); }
/** * 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"); }
/** * 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; } } }
/** * @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); } }
/** * 设置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, 0, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); // 设置hint v.setHint(new SpannedString(ss)); // 一定要进行转换,否则属性会消失 }
/** * 设置hint大小 * * @param size * @param v * @param res */ public static void setViewHintSize(Context context, int size, TextView v, int res) { SpannableString ss = new SpannableString(getResources(context).getString( res)); // 新建一个属性对象,设置文字的大小 AbsoluteSizeSpan ass = new AbsoluteSizeSpan(size, true); // 附加属性到文本 ss.setSpan(ass, 0, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); // 设置hint v.setHint(new SpannedString(ss)); // 一定要进行转换,否则属性会消失 }
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, null, new BaseCustomTagHandler()), scrolling); }else { setText(tv, new SpannedString(text), scrolling); } }
/** * 设置hint大小 * * @param size * @param v * @param res */ public static void setViewHintSize(Context context, int size, TextView v, int res) { SpannableString ss = new SpannableString(getResources(context).getString( res)); // 新建一个属性对象,设置文字的大小 AbsoluteSizeSpan ass = new AbsoluteSizeSpan(size, true); // 附加属性到文本 ss.setSpan(ass, 0, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); // 设置hint,一定要进行转换,否则属性会消失 v.setHint(new SpannedString(ss)); }
/** * 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; }
@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(""); } }
@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); }