public final void run() { if ((this.a.F) || (!this.a.i())) { return; } Spanned localSpanned = Html.fromHtml(this.a.az); if ((localSpanned instanceof SpannableStringBuilder)) {} int i; int j; for (SpannableStringBuilder localSpannableStringBuilder = (SpannableStringBuilder) localSpanned; ; localSpannableStringBuilder = new SpannableStringBuilder(localSpanned)) { i = localSpannableStringBuilder.length(); for (j = 0; (j != i) && (Character.isWhitespace(localSpannableStringBuilder.charAt(j))); j++) {} } if (j != 0) { localSpannableStringBuilder.delete(0, j); i = localSpannableStringBuilder.length(); } for (int k = i - 1; (k >= 0) && (Character.isWhitespace(localSpannableStringBuilder.charAt(k))); k--) {} if (k != i - 1) { localSpannableStringBuilder.delete(k + 1, i); } this.a.ax.setText(localSpannableStringBuilder); Linkify.addLinks(this.a.ax, 1); this.a.ax.setVisibility(0); this.a.ax.setMovementMethod(LinkMovementMethod.getInstance()); this.a.ay.setVisibility(0); }
@Override public void handleTagNode(TagNode node, SpannableStringBuilder builder, int start, int end) { String href = node.getAttributeByName("href"); if (href == null) { return; } final String linkHref = href; // First check if it should be a normal URL link for (String protocol : this.externalProtocols) { if (href.toLowerCase(Locale.US).startsWith(protocol)) { builder.setSpan(new URLSpan(href), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); return; } } // If not, consider it an internal nav link. ClickableSpan span = new ClickableSpan() { @Override public void onClick(View widget) { navigateTo(spine.resolveHref(linkHref)); } }; builder.setSpan(span, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); }
private CharSequence formatMessage(MultiDeleteListItemData ch) { final int size = android.R.style.TextAppearance_Small; final int color = android.R.styleable.Theme_textColorSecondary; String from = ch.getFrom(); SpannableStringBuilder buf = new SpannableStringBuilder(from); if (ch.hasDraft() && ch.getMessageCount() == 0) { // only draft } else { if (ch.getUnreadMessageCount() > 0) { buf.append(" (" + ch.getUnreadMessageCount() + "/"); } else { buf.append(" (" + "0/"); } // if (ch.getMessageCount() > 1) { buf.append(ch.getMessageCount() + ") "); // } } /* if (ch.getMessageCount() > 1) { buf.append(" (" + ch.getMessageCount() + ") "); } */ return buf; }
/** * get real translate charsequence * * @param content * @return */ public static CharSequence getTranslateTxt(CharSequence content) { StringBuilder sBuilder = new StringBuilder(); if (content instanceof SpannableStringBuilder) { SpannableStringBuilder spanSb = (SpannableStringBuilder) content; if (spanSb.toString().contains(EMHolderEntity.FINAL_HOLDER)) { for (int i = 0; i < spanSb.length(); i++) { ReplacementSpan[] spans = spanSb.getSpans(i, i + 1, ReplacementSpan.class); if (spans.length > 0) { if (spans[0] instanceof EMImageSpan) { EMImageSpan imgSpan = (EMImageSpan) spans[0]; sBuilder.append(imgSpan.mTransferTxt); } else if (spans[0] instanceof DefEmojSpan) { DefEmojSpan defSpan = (DefEmojSpan) spans[0]; sBuilder.append(defSpan.mTransferTxt); } } else { sBuilder.append(spanSb.subSequence(i, i + 1)); } } } else { sBuilder.append(content); } } return sBuilder; }
public void setSpecifiedTextsColor(String text, String specifiedTexts, int color) { List<Integer> sTextsStartList = new ArrayList<>(); int sTextLength = specifiedTexts.length(); String temp = text; int lengthFront = 0; // 记录被找出后前面的字段的长度 int start = -1; do { start = temp.indexOf(specifiedTexts); if (start != -1) { start = start + lengthFront; sTextsStartList.add(start); lengthFront = start + sTextLength; temp = text.substring(lengthFront); } } while (start != -1); SpannableStringBuilder styledText = new SpannableStringBuilder(text); for (Integer i : sTextsStartList) { styledText.setSpan( new ForegroundColorSpan(color), i, i + sTextLength, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } setText(styledText); }
private void updateTitle(Tab tab) { // Keep the title unchanged if there's no selected tab, // or if the tab is entering reader mode. if (tab == null || tab.isEnteringReaderMode()) { return; } final String url = tab.getURL(); // Setting a null title will ensure we just see the // "Enter Search or Address" placeholder text. if (AboutPages.isTitlelessAboutPage(url)) { setTitle(null); return; } // Show the about:blocked page title in red, regardless of prefs if (tab.getErrorType() == Tab.ErrorType.BLOCKED) { final String title = tab.getDisplayTitle(); final SpannableStringBuilder builder = new SpannableStringBuilder(title); builder.setSpan(mBlockedColor, 0, title.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE); setTitle(builder); return; } // If the pref to show the title is set, use the tab's display title. if (!mPrefs.shouldShowUrl() || url == null) { setTitle(tab.getDisplayTitle()); return; } String strippedURL = stripAboutReaderURL(url); if (mPrefs.shouldTrimUrls()) { strippedURL = StringUtils.stripCommonSubdomains(StringUtils.stripScheme(strippedURL)); } CharSequence title = strippedURL; final String baseDomain = tab.getBaseDomain(); if (!TextUtils.isEmpty(baseDomain)) { final SpannableStringBuilder builder = new SpannableStringBuilder(title); int index = title.toString().indexOf(baseDomain); if (index > -1) { builder.setSpan(mUrlColor, 0, title.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE); builder.setSpan( tab.isPrivate() ? mPrivateDomainColor : mDomainColor, index, index + baseDomain.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE); title = builder; } } setTitle(title); }
private void setImageSpan(SpannableStringBuilder builder, Drawable drawable, int start, int end) { builder.setSpan(new ImageSpan(drawable), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); if (spine.isCover()) { builder.setSpan(new CenterSpan(), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); tv = new TextView(this); ctx = this; String htmlLinkText = "我是超链接" + "<a href='lianjie'><font color='red'>超链接点击事件</font></a>"; // 文字的样式(style)被覆盖,不能改变…… tv.setText(Html.fromHtml(htmlLinkText)); tv.setMovementMethod(LinkMovementMethod.getInstance()); CharSequence text = tv.getText(); if (text instanceof Spannable) { int end = text.length(); Spannable sp = (Spannable) tv.getText(); URLSpan[] urls = sp.getSpans(0, end, URLSpan.class); SpannableStringBuilder style = new SpannableStringBuilder(text); style.clearSpans(); // should clear old spans // 循环把链接发过去 for (URLSpan url : urls) { MyURLSpan myURLSpan = new MyURLSpan(url.getURL()); style.setSpan( myURLSpan, sp.getSpanStart(url), sp.getSpanEnd(url), Spannable.SPAN_EXCLUSIVE_INCLUSIVE); } tv.setText(style); } setContentView(tv); }
/** * Combine all of the options that have been set and return a new {@link * net.frakbot.jumpingbeans.JumpingBeans} instance. * * <p>Remember to call the {@link #stopJumping()} method once you're done using the JumpingBeans * (that is, when you detach the TextView from the view tree, you hide it, or the parent * Activity/Fragment goes in the paused status). This will allow to release the animations and * free up memory and CPU that would be otherwise wasted. */ public JumpingBeans build() { SpannableStringBuilder sbb = new SpannableStringBuilder(text); JumpingBeansSpan[] jumpingBeans; if (!wave) { jumpingBeans = new JumpingBeansSpan[] {new JumpingBeansSpan(textView, loopDuration, 0, 0, animRange)}; sbb.setSpan(jumpingBeans[0], startPos, endPos, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } else { if (waveCharDelay == -1) { waveCharDelay = loopDuration / (3 * (endPos - startPos)); } jumpingBeans = 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); jumpingBeans[pos - startPos] = jumpingBean; } } textView.setText(sbb); return new JumpingBeans(jumpingBeans, textView); }
@Override public void onBindViewHolder(ViewHolder holder, int position) { Gank gank = mGankList.get(position); if (position == 0) { showCategory(holder); } else { boolean theCategoryOfLastEqualsToThis = mGankList.get(position - 1).type.equals(mGankList.get(position).type); if (!theCategoryOfLastEqualsToThis) { showCategory(holder); } else { hideCategory(holder); } } holder.category.setText(gank.type); SpannableStringBuilder builder = new SpannableStringBuilder(gank.desc) .append( StringStyles.format( holder.gank.getContext(), " (via. " + gank.who + ")", R.style.ViaTextAppearance)); CharSequence gankText = builder.subSequence(0, builder.length()); holder.gank.setText(gankText); showItemAnim(holder.gank, position); }
@Override protected void replaceText(CharSequence text) { clearComposingText(); SpannableStringBuilder ssb = buildSpannableForText(text); TokenImageSpan tokenSpan = buildSpanForObject(selectedObject); Editable editable = getText(); int end = getSelectionEnd(); int start = tokenizer.findTokenStart(editable, end); if (start < prefix.length()) { start = prefix.length(); } String original = TextUtils.substring(editable, start, end); if (editable != null) { if (tokenSpan == null) { editable.replace(start, end, " "); } else if (!allowDuplicates && objects.contains(tokenSpan.getToken())) { editable.replace(start, end, " "); } else { QwertyKeyListener.markAsReplaced(editable, start, end, original); editable.replace(start, end, ssb); editable.setSpan( tokenSpan, start, start + ssb.length() - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } } }
public static void tryFlowText( SpannableStringBuilder ss, View thumbnailView, TextView messageView, Display display) { // There is nothing I can do for older versions, so just return if (!mNewClassAvailable) return; // Get height and width of the image and height of the text line thumbnailView.measure(display.getWidth(), display.getHeight()); int height = thumbnailView.getMeasuredHeight(); int width = thumbnailView.getMeasuredWidth(); float textLineHeight = messageView.getPaint().getTextSize(); // Set the span according to the number of lines and width of the image int lines = (int) Math.round(height / textLineHeight); // For an html text you can use this line: SpannableStringBuilder ss = // (SpannableStringBuilder)Html.fromHtml(text); ss.setSpan(new MyLeadingMarginSpan2(lines, width), 0, ss.length(), 0); messageView.setText(ss); // Align the text with the image by removing the rule that the text is // to the right of the image RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) messageView.getLayoutParams(); int[] rules = params.getRules(); rules[RelativeLayout.RIGHT_OF] = 0; }
private void appendLog(String message, String targetFragment) { log.append(message); if (EXPECTED_TARGET_FRAGMENT.equals(targetFragment)) { SpannableString span = new SpannableString(targetFragment); span.setSpan( new ForegroundColorSpan(COLOR_OK), 0, targetFragment.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); log.append(span); } else { SpannableString span = new SpannableString(targetFragment); span.setSpan( new ForegroundColorSpan(COLOR_NOK), 0, targetFragment.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); log.append(span); } log.append("\n\n"); if (logView != null) { logView.setText(log); } }
@Override public void onBindViewHolder(MyViewHolder holder, int position) { Note note = mNoteList.get(position); holder.tvNoteTitle.setText(note.getTitle()); String time = note.getTime(); // reformat date to "dd/mm/yyyy" Date date = DateUtils.stringToDate(time); SimpleDateFormat fomatter = new SimpleDateFormat("dd/MM/yyyy", Locale.getDefault()); String newTime = fomatter.format(date); String content = note.getContent(); String newContent = newTime + " " + content; // change time's color in textview SpannableStringBuilder style = new SpannableStringBuilder(newContent); style.setSpan( new ForegroundColorSpan(getResources().getColor(R.color.jikelv)), 0, newTime.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE); holder.tvNoteContent.setText(style); String imagePath = note.getImagePath(); if (!TextUtils.isEmpty(imagePath)) { mBitmapUtils.display(holder.ivPhoto, imagePath); holder.ivPhoto.setVisibility(View.VISIBLE); } else { holder.ivPhoto.setVisibility(View.GONE); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.verify); ViewUtils.inject(this); // 记录Activity以便退出时全部finish() Const.activityList.add(this); count = new TimeCount(60000, 1000); // 构造CountDownTimer对象 Button goButton = (Button) findViewById(R.id.gobutton); ImageView back = (ImageView) findViewById(R.id.ivAppBack); textState.setTextSize(12); SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder("点击“手机绑定登陆”,即表示同意《超速洗用户协议》"); ForegroundColorSpan blueSpan = new ForegroundColorSpan(Color.parseColor("#28ccfc")); spannableStringBuilder.setSpan( new URLSpan("http://www.baidu.com"), 16, spannableStringBuilder.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); spannableStringBuilder.setSpan( blueSpan, 16, spannableStringBuilder.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); textState.setMovementMethod(LinkMovementMethod.getInstance()); textState.setText(spannableStringBuilder); }
private void geckoActionReply() { if (DEBUG) { // GeckoEditableListener methods should all be called from the Gecko thread ThreadUtils.assertOnGeckoThread(); } final Action action = mActionQueue.peek(); if (action == null) { throw new IllegalStateException("empty actions queue"); } if (DEBUG) { Log.d(LOGTAG, "reply: Action(" + getConstantName(Action.class, "TYPE_", action.mType) + ")"); } switch (action.mType) { case Action.TYPE_SET_SELECTION: final int len = mText.length(); final int curStart = Selection.getSelectionStart(mText); final int curEnd = Selection.getSelectionEnd(mText); // start == -1 when the start offset should remain the same // end == -1 when the end offset should remain the same final int selStart = Math.min(action.mStart < 0 ? curStart : action.mStart, len); final int selEnd = Math.min(action.mEnd < 0 ? curEnd : action.mEnd, len); if (selStart < action.mStart || selEnd < action.mEnd) { Log.w(LOGTAG, "IME sync error: selection out of bounds"); } Selection.setSelection(mText, selStart, selEnd); geckoPostToIc( new Runnable() { @Override public void run() { mActionQueue.syncWithGecko(); final int start = Selection.getSelectionStart(mText); final int end = Selection.getSelectionEnd(mText); if (selStart == start && selEnd == end) { // There has not been another new selection in the mean time that // made this notification out-of-date mListener.onSelectionChange(start, end); } } }); break; case Action.TYPE_SET_SPAN: mText.setSpan(action.mSpanObject, action.mStart, action.mEnd, action.mSpanFlags); break; case Action.TYPE_REMOVE_SPAN: mText.removeSpan(action.mSpanObject); break; case Action.TYPE_SET_HANDLER: geckoSetIcHandler(action.mHandler); break; } if (action.mShouldUpdate) { geckoUpdateGecko(false); } }
private void notifyCommitComposition() { // Gecko already committed its composition, and // we should remove the composition on our side as well. boolean wasComposing = false; final Object[] spans = mText.getSpans(0, mText.length(), Object.class); for (Object span : spans) { if ((mText.getSpanFlags(span) & Spanned.SPAN_COMPOSING) != 0) { mText.removeSpan(span); wasComposing = true; } } if (!wasComposing) { return; } // Generate a text change notification if we actually cleared the composition. final CharSequence text = TextUtils.stringOrSpannedString(mText); geckoPostToIc( new Runnable() { @Override public void run() { mListener.onTextChange(text, 0, text.length(), text.length()); } }); }
public MDFormatter(List<Markdown.MDLine> lines) { for (Markdown.MDLine line : lines) { format(line); } mBuilder.setSpan( new TypefaceSpan("monospace"), 0, mBuilder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); }
/** 设置颜色 */ public void setResultColor(String checkName, String name, TextView result) { SpannableStringBuilder builder = new SpannableStringBuilder(); int start = name.indexOf(checkName); int max = name.length(); endMax = restrictMax; for (int i = 0; i < restrictMax; i++) { // 循环遍历字符串 if (Pattern.compile("(?i)[a-z]").matcher(name).find() || Pattern.compile("(?i)[A-Z]").matcher(name).find()) { // 用char包装类中的判断数字的方法判断每一个字符 endMax++; } } if (max > endMax) { name = name.substring(0, endMax); for (int i = 0; i < max - endMax; i++) { name += "."; } } builder.append(name); if (!checkName.equals("")) { builder.setSpan( new ForegroundColorSpan(Color.RED), start, start + checkName.length(), Spanned.SPAN_COMPOSING); } result.setText(builder, BufferType.EDITABLE); }
private void updateTextDataUI() { if (!mIsTimestampDisplayMode) { if (mDataBufferLastSize != mDataBuffer.size()) { final int bufferSize = mDataBuffer.size(); if (bufferSize > maxPacketsToPaintAsText) { mDataBufferLastSize = bufferSize - maxPacketsToPaintAsText; mTextSpanBuffer.clear(); addTextToSpanBuffer( mTextSpanBuffer, getString(R.string.uart_text_dataomitted) + "\n", mInfoColor); } // Log.d(TAG, "update packets: "+(bufferSize-mDataBufferLastSize)); for (int i = mDataBufferLastSize; i < bufferSize; i++) { final UartDataChunk dataChunk = mDataBuffer.get(i); final boolean isRX = dataChunk.getMode() == UartDataChunk.TRANSFERMODE_RX; final String data = dataChunk.getData(); final String formattedData = mShowDataInHexFormat ? asciiToHex(data) : data; addTextToSpanBuffer(mTextSpanBuffer, formattedData, isRX ? mRxColor : mTxColor); } mDataBufferLastSize = mDataBuffer.size(); mBufferTextView.setText(mTextSpanBuffer); mBufferTextView.setSelection( 0, mTextSpanBuffer.length()); // to automatically scroll to the end } } }
public static void setNameAndUsername(TextView textView, String name, String username) { Context c = textView.getContext(); ForegroundColorSpan grayTextForegroundSpan = new ForegroundColorSpan(c.getResources().getColor(R.color.name_gray)); AbsoluteSizeSpan fontsizeSpan = new AbsoluteSizeSpan(20); SpannableStringBuilder ssb = new SpannableStringBuilder(name + " @" + username); // Apply the color span ssb.setSpan( grayTextForegroundSpan, // the span to add name.length() + 1, // the start of the span (inclusive) ssb.length(), // the end of the span (exclusive) Spanned .SPAN_EXCLUSIVE_EXCLUSIVE); // behavior when text is later inserted into the // SpannableStringBuilder ssb.setSpan( fontsizeSpan, // the span to add name.length() + 1, // the start of the span (inclusive) ssb.length(), // the end of the span (exclusive) Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); textView.setText(ssb); }
@Override public void handleTagNode(TagNode node, SpannableStringBuilder builder, int start, int end) { String src = node.getAttributeByName("src"); if (src == null) { src = node.getAttributeByName("href"); } if (src == null) { src = node.getAttributeByName("xlink:href"); } builder.append("\uFFFC"); String resolvedHref = spine.resolveHref(src); if (imageCache.containsKey(resolvedHref) && !fakeImages) { Drawable drawable = imageCache.get(resolvedHref); setImageSpan(builder, drawable, start, builder.length()); LOG.debug("Got cached href: " + resolvedHref); } else { LOG.debug("Loading href: " + resolvedHref); loader.registerCallback( resolvedHref, new ImageCallback(resolvedHref, builder, start, builder.length(), fakeImages)); } }
/** * Appends CharSequence representations of the specified arguments to a {@link * SpannableStringBuilder}, creating one if the supplied builder is {@code null}. * * @param builder An existing {@link SpannableStringBuilder}, or {@code null} to create one. * @param args The objects to append to the builder. * @return A builder with the specified objects appended. */ public static SpannableStringBuilder appendWithSeparator( SpannableStringBuilder builder, CharSequence... args) { if (builder == null) { builder = new SpannableStringBuilder(); } for (CharSequence arg : args) { if (arg == null) { continue; } if (arg.toString().length() == 0) { continue; } if (builder.length() > 0) { if (needsBreakingSeparator(builder)) { builder.append(DEFAULT_BREAKING_SEPARATOR); } else { builder.append(DEFAULT_SEPARATOR); } } builder.append(arg); } return builder; }
protected void onPostExecute(JSONObject result) { if (statusFieldPosition == 0) { statusFieldPosition = statusField.getTop(); } if (result != null) { try { boolean status = result.getBoolean("status"); SpannableStringBuilder stringBuilder = new SpannableStringBuilder(getText(R.string.power)); if (status) { stringBuilder.append(" PÅ"); } else { stringBuilder.append(" AV"); } statusText.setText(stringBuilder, TextView.BufferType.SPANNABLE); statusField.animate().y(statusFieldPosition).setDuration(1000); String last_start = result.getString("last_start"); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm"); SimpleDateFormat out = new SimpleDateFormat("hh:mm"); Date last = df.parse(last_start); footerText.setText(getText(R.string.details) + " " + out.format(last)); } catch (JSONException e) { } catch (ParseException e) { } } else { footerText.setText(getText(R.string.defaultFooterText)); } }
@Override public void onLoadResource(String href, InputStream input) { Bitmap bitmap = null; try { bitmap = getBitmap(input); if (bitmap == null || bitmap.getHeight() < 1 || bitmap.getWidth() < 1) { return; } } catch (OutOfMemoryError outofmem) { LOG.error("Could not load image", outofmem); } if (bitmap != null) { Drawable drawable = new FastBitmapDrawable(bitmap); drawable.setBounds(0, 0, bitmap.getWidth() - 1, bitmap.getHeight() - 1); builder.setSpan(new ImageSpan(drawable), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); if (spine.isCover()) { builder.setSpan(new CenterSpan(), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } }
/* (non-Javadoc) * manipulates the view for amount (setting expenses to red) and * category (indicate transfer direction with => or <= * @see android.widget.CursorAdapter#getView(int, android.view.View, android.view.ViewGroup) */ @Override public View getView(int position, View convertView, ViewGroup parent) { convertView = super.getView(position, convertView, parent); ViewHolder viewHolder = (ViewHolder) convertView.getTag(); TextView tv1 = viewHolder.amount; Cursor c = getCursor(); c.moveToPosition(position); if (mAccount.getId() < 0) { int color = c.getInt(c.getColumnIndex("color")); viewHolder.colorAccount.setBackgroundColor(color); } long amount = c.getLong(columnIndexAmount); setColor(tv1, amount < 0); TextView tv2 = viewHolder.category; CharSequence catText = tv2.getText(); if (DbUtils.getLongOrNull(c, columnIndexTransferPeer) != null) { catText = ((amount < 0) ? "=> " : "<= ") + catText; } else { Long catId = DbUtils.getLongOrNull(c, KEY_CATID); if (SPLIT_CATID.equals(catId)) catText = getString(R.string.split_transaction); else if (catId == null) { catText = getString(R.string.no_category_assigned); } else { String label_sub = c.getString(columnIndexLabelSub); if (label_sub != null && label_sub.length() > 0) { catText = catText + categorySeparator + label_sub; } } } String referenceNumber = c.getString(columnIndexReferenceNumber); if (referenceNumber != null && referenceNumber.length() > 0) catText = "(" + referenceNumber + ") " + catText; SpannableStringBuilder ssb; String comment = c.getString(columnIndexComment); if (comment != null && comment.length() > 0) { ssb = new SpannableStringBuilder(comment); ssb.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), 0, comment.length(), 0); catText = TextUtils.concat(catText, commentSeparator, ssb); } String payee = c.getString(columnIndexPayee); if (payee != null && payee.length() > 0) { ssb = new SpannableStringBuilder(payee); ssb.setSpan(new UnderlineSpan(), 0, payee.length(), 0); catText = TextUtils.concat(catText, commentSeparator, ssb); } tv2.setText(catText); if (!mAccount.type.equals(Type.CASH)) { CrStatus status; try { status = CrStatus.valueOf(c.getString(columnIndexCrStatus)); } catch (IllegalArgumentException ex) { status = CrStatus.UNRECONCILED; } viewHolder.color1.setBackgroundColor(status.color); viewHolder.colorContainer.setTag(status == CrStatus.RECONCILED ? -1 : getItemId(position)); } return convertView; }
private void clearCachedMark(SpannableStringBuilder ssb) { Cached[] cs = ssb.getSpans(0, ssb.length(), Cached.class); if (cs != null && cs.length > 0) { for (Cached c : cs) { ssb.removeSpan(c); } } }
private void setSpan(SpannableStringBuilder spannable, String marker, int imageResourceId) { String text = spannable.toString(); int target = text.indexOf(marker); while (0 <= target) { ImageSpan span = new ImageSpan(mIme, imageResourceId, DynamicDrawableSpan.ALIGN_BOTTOM); spannable.setSpan(span, target, target + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); target = text.indexOf(marker, target + 1); } }
/** 显示在输入框的注码 */ public void showEditText() { SpannableStringBuilder builder = new SpannableStringBuilder(); String zhumas = ""; int num = 0; // 高亮小球数 int length = 0; for (int j = 0; j < itemViewArray.get(0).areaNums.length; j++) { BallTable ballTable = itemViewArray.get(0).areaNums[j].table; int[] zhuMa = ballTable.getHighlightBallNOs(); if (j != 0) { if (iCurrentButton == PublicConst.BUY_PL3_ZU3_DAN) { zhumas += ","; } else { zhumas += " | "; } } for (int i = 0; i < ballTable.getHighlightBallNOs().length; i++) { if (isTen) { zhumas += PublicMethod.getZhuMa(zhuMa[i]); } else { zhumas += zhuMa[i] + ""; } if (i != ballTable.getHighlightBallNOs().length - 1) { zhumas += ","; } } num += zhuMa.length; } if (num == 0) { editZhuma.setText(""); } else { builder.append(zhumas); String zhuma[]; if (iCurrentButton == PublicConst.BUY_PL3_ZU3_DAN) { zhuma = zhumas.split("\\,"); } else { zhuma = zhumas.split("\\|"); } for (int i = 0; i < zhuma.length; i++) { if (i != 0) { length += zhuma[i].length() + 1; } else { length += zhuma[i].length(); } if (i != zhuma.length - 1) { builder.setSpan( new ForegroundColorSpan(Color.BLACK), length, length + 1, Spanned.SPAN_COMPOSING); } builder.setSpan( new ForegroundColorSpan(itemViewArray.get(0).areaNums[i].textColor), length - zhuma[i].length(), length, Spanned.SPAN_COMPOSING); } editZhuma.setText(builder, BufferType.EDITABLE); } }
private void showNote(boolean xml) { if (xml) { content.setText(note.getXmlContent()); title.setText((CharSequence) note.getTitle()); this.setTitle(this.getTitle() + " - XML"); return; } LinkInternalSpan[] links = noteContent.getSpans(0, noteContent.length(), LinkInternalSpan.class); MatchFilter noteLinkMatchFilter = LinkInternalSpan.getNoteLinkMatchFilter(noteContent, links); // show the note (spannable makes the TextView able to output styled text) content.setText(noteContent, TextView.BufferType.SPANNABLE); // add links to stuff that is understood by Android except phone numbers because it's too // aggressive // TODO this is SLOWWWW!!!! int linkFlags = 0; if (Preferences.getBoolean(Preferences.Key.LINK_EMAILS)) linkFlags |= Linkify.EMAIL_ADDRESSES; if (Preferences.getBoolean(Preferences.Key.LINK_URLS)) linkFlags |= Linkify.WEB_URLS; if (Preferences.getBoolean(Preferences.Key.LINK_ADDRESSES)) linkFlags |= Linkify.MAP_ADDRESSES; Linkify.addLinks(content, linkFlags); // Custom phone number linkifier (fixes lp:512204) if (Preferences.getBoolean(Preferences.Key.LINK_PHONES)) Linkify.addLinks( content, LinkifyPhone.PHONE_PATTERN, "tel:", LinkifyPhone.sPhoneNumberMatchFilter, Linkify.sPhoneNumberTransformFilter); // This will create a link every time a note title is found in the text. // The pattern contains a very dumb (title1)|(title2) escaped correctly // Then we transform the url from the note name to the note id to avoid characters that mess up // with the URI (ex: ?) if (Preferences.getBoolean(Preferences.Key.LINK_TITLES)) { Pattern pattern = NoteManager.buildNoteLinkifyPattern(this, note.getTitle()); if (pattern != null) { Linkify.addLinks( content, pattern, Tomdroid.CONTENT_URI + "/", noteLinkMatchFilter, noteTitleTransformFilter); // content.setMovementMethod(LinkMovementMethod.getInstance()); } } title.setText((CharSequence) note.getTitle()); }