List of usage examples for android.text SpannableStringBuilder append
public SpannableStringBuilder append(char text)
From source file:com.andrewshu.android.reddit.threads.ThreadsListActivity.java
public static void fillThreadsListItemView(int position, View view, ThingInfo item, ListActivity activity, HttpClient client, RedditSettings settings, ThumbnailOnClickListenerFactory thumbnailOnClickListenerFactory) { Resources res = activity.getResources(); TextView titleView = (TextView) view.findViewById(R.id.title); TextView votesView = (TextView) view.findViewById(R.id.votes); TextView numCommentsSubredditView = (TextView) view.findViewById(R.id.numCommentsSubreddit); TextView nsfwView = (TextView) view.findViewById(R.id.nsfw); // TextView submissionTimeView = (TextView) view.findViewById(R.id.submissionTime); ImageView voteUpView = (ImageView) view.findViewById(R.id.vote_up_image); ImageView voteDownView = (ImageView) view.findViewById(R.id.vote_down_image); View thumbnailContainer = view.findViewById(R.id.thumbnail_view); FrameLayout thumbnailFrame = (FrameLayout) view.findViewById(R.id.thumbnail_frame); ImageView thumbnailImageView = (ImageView) view.findViewById(R.id.thumbnail); ProgressBar indeterminateProgressBar = (ProgressBar) view.findViewById(R.id.indeterminate_progress); // Set the title and domain using a SpannableStringBuilder SpannableStringBuilder builder = new SpannableStringBuilder(); String title = item.getTitle(); if (title == null) title = ""; SpannableString titleSS = new SpannableString(title); int titleLen = title.length(); titleSS.setSpan(//w ww . j a va 2 s .c o m new TextAppearanceSpan(activity, Util.getTextAppearanceResource(settings.getTheme(), android.R.style.TextAppearance_Large)), 0, titleLen, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); String domain = item.getDomain(); if (domain == null) domain = ""; int domainLen = domain.length(); SpannableString domainSS = new SpannableString("(" + item.getDomain() + ")"); domainSS.setSpan( new TextAppearanceSpan(activity, Util.getTextAppearanceResource(settings.getTheme(), android.R.style.TextAppearance_Small)), 0, domainLen + 2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); if (Util.isLightTheme(settings.getTheme())) { if (item.isClicked()) { ForegroundColorSpan fcs = new ForegroundColorSpan(res.getColor(R.color.purple)); titleSS.setSpan(fcs, 0, titleLen, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } else { ForegroundColorSpan fcs = new ForegroundColorSpan(res.getColor(R.color.blue)); titleSS.setSpan(fcs, 0, titleLen, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } domainSS.setSpan(new ForegroundColorSpan(res.getColor(R.color.gray_50)), 0, domainLen + 2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } else { if (item.isClicked()) { ForegroundColorSpan fcs = new ForegroundColorSpan(res.getColor(R.color.gray_50)); titleSS.setSpan(fcs, 0, titleLen, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } domainSS.setSpan(new ForegroundColorSpan(res.getColor(R.color.gray_75)), 0, domainLen + 2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } builder.append(titleSS).append(" ").append(domainSS); titleView.setText(builder); votesView.setText("" + item.getScore()); numCommentsSubredditView.setText(Util.showNumComments(item.getNum_comments()) + " " + item.getSubreddit()); if (item.isOver_18()) { nsfwView.setVisibility(View.VISIBLE); } else { nsfwView.setVisibility(View.GONE); } // Set the up and down arrow colors based on whether user likes if (settings.isLoggedIn()) { if (item.getLikes() == null) { voteUpView.setImageResource(R.drawable.vote_up_gray); voteDownView.setImageResource(R.drawable.vote_down_gray); votesView.setTextColor(res.getColor(R.color.gray_75)); } else if (item.getLikes() == true) { voteUpView.setImageResource(R.drawable.vote_up_red); voteDownView.setImageResource(R.drawable.vote_down_gray); votesView.setTextColor(res.getColor(R.color.arrow_red)); } else { voteUpView.setImageResource(R.drawable.vote_up_gray); voteDownView.setImageResource(R.drawable.vote_down_blue); votesView.setTextColor(res.getColor(R.color.arrow_blue)); } } else { voteUpView.setImageResource(R.drawable.vote_up_gray); voteDownView.setImageResource(R.drawable.vote_down_gray); votesView.setTextColor(res.getColor(R.color.gray_75)); } // Thumbnails open links if (thumbnailContainer != null) { if (Common.shouldLoadThumbnails(activity, settings)) { thumbnailContainer.setVisibility(View.VISIBLE); if (item.getUrl() != null) { OnClickListener thumbnailOnClickListener = thumbnailOnClickListenerFactory .getThumbnailOnClickListener(item, activity); if (thumbnailOnClickListener != null) { thumbnailFrame.setOnClickListener(thumbnailOnClickListener); } } // Show thumbnail based on ThingInfo if ("default".equals(item.getThumbnail()) || "self".equals(item.getThumbnail()) || StringUtils.isEmpty(item.getThumbnail())) { indeterminateProgressBar.setVisibility(View.GONE); thumbnailImageView.setVisibility(View.VISIBLE); thumbnailImageView.setImageResource(R.drawable.go_arrow); } else { indeterminateProgressBar.setVisibility(View.GONE); thumbnailImageView.setVisibility(View.VISIBLE); if (item.getThumbnailBitmap() != null) { thumbnailImageView.setImageBitmap(item.getThumbnailBitmap()); } else { thumbnailImageView.setImageBitmap(null); new ShowThumbnailsTask(activity, client, R.drawable.go_arrow) .execute(new ThumbnailLoadAction(item, thumbnailImageView, position)); } } // Set thumbnail background based on current theme if (Util.isLightTheme(settings.getTheme())) thumbnailFrame.setBackgroundResource(R.drawable.thumbnail_background_light); else thumbnailFrame.setBackgroundResource(R.drawable.thumbnail_background_dark); } else { // if thumbnails disabled, hide thumbnail icon thumbnailContainer.setVisibility(View.GONE); } } }
From source file:de.tum.in.tumcampus.auxiliary.calendar.DayView.java
/** * Return the layout for a numbered event. Create it if not already existing *///from w ww . j a v a2 s . c o m private StaticLayout getEventLayout(StaticLayout[] layouts, int i, Event event, Paint paint, Rect r) { if (i < 0 || i >= layouts.length) { return null; } StaticLayout layout = layouts[i]; // Check if we have already initialized the StaticLayout and that // the width hasn't changed (due to vertical resizing which causes // re-layout of events at min height) if (layout == null || r.width() != layout.getWidth()) { SpannableStringBuilder bob = new SpannableStringBuilder(); if (event.title != null) { // MAX - 1 since we add a space bob.append(drawTextSanitizer(event.title.toString(), MAX_EVENT_TEXT_LEN - 1)); bob.setSpan(new StyleSpan(Typeface.BOLD), 0, bob.length(), 0); bob.append(' '); } if (event.location != null) { bob.append(drawTextSanitizer(event.location.toString(), MAX_EVENT_TEXT_LEN - bob.length())); } paint.setColor(mEventTextColor); // Leave a one pixel boundary on the left and right of the rectangle for the event layout = new StaticLayout(bob, 0, bob.length(), new TextPaint(paint), r.width(), Alignment.ALIGN_NORMAL, 1.0f, 0.0f, true, null, r.width()); layouts[i] = layout; } layout.getPaint().setAlpha(mEventsAlpha); return layout; }
From source file:com.tct.mail.browse.ConversationItemView.java
private void createSubject(final boolean isUnread) { final String badgeText = mHeader.badgeText == null ? "" : mHeader.badgeText; String subject = filterTag(getContext(), mHeader.conversation.subject); subject = Conversation.getSubjectForDisplay(mContext, badgeText, subject); /// TCT: add for search term highlight // process subject and snippet respectively @{ SpannableStringBuilder subjectToHighlight = new SpannableStringBuilder(subject); boolean hasFilter = (mSearchParams != null && !TextUtils.isEmpty(mSearchParams.mFilter)); if (hasFilter) { boolean fieldMatchedSubject = (mSearchParams != null && (SearchParams.SEARCH_FIELD_SUBJECT.equals(mSearchParams.mField) || SearchParams.SEARCH_FIELD_ALL.equals(mSearchParams.mField))); /// TCT: Only highlight un-empty subject if (fieldMatchedSubject && !TextUtils.isEmpty(subject)) { CharSequence subjectChars = TextUtilities.highlightTermsInText(subject, mSearchParams.mFilter); subjectToHighlight.replace(0, subject.length(), subjectChars); }/*from w w w . ja v a 2 s. com*/ } /// @} final Spannable displayedStringBuilder = new SpannableString(subjectToHighlight); // since spans affect text metrics, add spans to the string before measure/layout or fancy // ellipsizing final int badgeTextLength = formatBadgeText(displayedStringBuilder, badgeText); if (!TextUtils.isEmpty(subject)) { displayedStringBuilder.setSpan( TextAppearanceSpan.wrap(isUnread ? sSubjectTextUnreadSpan : sSubjectTextReadSpan), badgeTextLength, subject.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } if (isActivated() && showActivatedText()) { displayedStringBuilder.setSpan(sActivatedTextSpan, badgeTextLength, displayedStringBuilder.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE); } final int subjectWidth = mSubjectWidth;//TS: yanhua.chen 2015-9-2 EMAIL CR_540046 MOD final int subjectHeight = mCoordinates.subjectHeight; mSubjectTextView.setLayoutParams(new ViewGroup.LayoutParams(subjectWidth, subjectHeight)); mSubjectTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mCoordinates.subjectFontSize); layoutViewExactly(mSubjectTextView, subjectWidth, subjectHeight); //[FEATURE]-Mod-BEGIN by CDTS.zhonghua.tuo,05/29/2014,FR 670064 SpannableStringBuilder builder = new SpannableStringBuilder(); boolean filterSubject = false; if (mField == UIProvider.LOCAL_SEARCH_ALL || mField == UIProvider.LOCAL_SEARCH_SUBJECT) { filterSubject = true; } if (mQueryText != null && filterSubject) { CharSequence formatSubject = displayedStringBuilder; formatSubject = TextUtilities.highlightTermsInText(subject, mQueryText); builder.append(formatSubject); mSubjectTextView.setText(builder); // TS: chao.zhang 2015-09-14 EMAIL FEATURE-585337 ADD_S //store the displayed subject for calculate the statusView's X and width mHeader.subjectText = builder.toString(); // TS: chao.zhang 2015-09-14 EMAIL FEATURE-585337 ADD_E } else { mSubjectTextView.setText(displayedStringBuilder); // TS: chao.zhang 2015-09-14 EMAIL FEATURE-585337 ADD_S mHeader.subjectText = displayedStringBuilder.toString(); // TS: chao.zhang 2015-09-14 EMAIL FEATURE-585337 ADD_E } //[FEATURE]-Mod-END by CDTS.zhonghua.tuo }
From source file:com.juick.android.TagsFragment.java
private void reloadTags(final View view) { final View selectedContainer = myView.findViewById(R.id.selected_container); final View progressAll = myView.findViewById(R.id.progress_all); Thread thr = new Thread(new Runnable() { public void run() { Bundle args = getArguments(); MicroBlog microBlog;/*from w w w . j a v a 2s. c om*/ JSONArray json = null; final int tagsUID = showMine ? uid : 0; if (PointMessageID.CODE.equals(args.getString("microblog"))) { microBlog = MainActivity.microBlogs.get(PointMessageID.CODE); json = ((PointMicroBlog) microBlog).getUserTags(view, uidS); } else { microBlog = MainActivity.microBlogs.get(JuickMessageID.CODE); json = ((JuickMicroBlog) microBlog).getUserTags(view, tagsUID); } if (isAdded()) { final SpannableStringBuilder tagsSSB = new SpannableStringBuilder(); if (json != null) { try { int cnt = json.length(); ArrayList<TagSort> sortables = new ArrayList<TagSort>(); for (int i = 0; i < cnt; i++) { final String tagg = json.getJSONObject(i).getString("tag"); final int messages = json.getJSONObject(i).getInt("messages"); sortables.add(new TagSort(tagg, messages)); } Collections.sort(sortables); HashMap<String, Double> scales = new HashMap<String, Double>(); for (int sz = 0, sortablesSize = sortables.size(); sz < sortablesSize; sz++) { TagSort sortable = sortables.get(sz); if (sz < 10) { scales.put(sortable.tag, 2.0); } else if (sz < 20) { scales.put(sortable.tag, 1.5); } } int start = 0; if (microBlog instanceof JuickMicroBlog && getArguments().containsKey("add_system_tags")) { start = -4; } for (int i = start; i < cnt; i++) { final String tagg; switch (i) { case -4: tagg = "public"; break; case -3: tagg = "friends"; break; case -2: tagg = "notwitter"; break; case -1: tagg = "readonly"; break; default: tagg = json.getJSONObject(i).getString("tag"); break; } int index = tagsSSB.length(); tagsSSB.append("*" + tagg); tagsSSB.setSpan(new URLSpan(tagg) { @Override public void onClick(View widget) { onTagClick(tagg, tagsUID); } }, index, tagsSSB.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); Double scale = scales.get(tagg); if (scale != null) { tagsSSB.setSpan(new RelativeSizeSpan((float) scale.doubleValue()), index, tagsSSB.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } tagOffsets.put(tagg, new TagOffsets(index, tagsSSB.length())); tagsSSB.append(" "); } } catch (Exception ex) { tagsSSB.append("Error: " + ex.toString()); } } if (getActivity() != null) { // maybe already closed? getActivity().runOnUiThread(new Runnable() { public void run() { TextView tv = (TextView) myView.findViewById(R.id.tags); progressAll.setVisibility(View.GONE); if (multi) selectedContainer.setVisibility(View.VISIBLE); tv.setText(tagsSSB, TextView.BufferType.SPANNABLE); tv.setMovementMethod(LinkMovementMethod.getInstance()); MainActivity.restyleChildrenOrWidget(view); final TextView selected = (TextView) myView.findViewById(R.id.selected); selected.setVisibility(View.VISIBLE); } }); } } } }); thr.start(); }
From source file:in.shick.diode.threads.ThreadsListActivity.java
public static void fillThreadsListItemView(int position, View view, ThingInfo item, ListActivity activity, HttpClient client, RedditSettings settings, ThumbnailOnClickListenerFactory thumbnailOnClickListenerFactory) { Resources res = activity.getResources(); ViewHolder vh;// ww w. j av a2s . co m if (view.getTag() == null) { vh = new ViewHolder(); vh.titleView = (TextView) view.findViewById(R.id.title); vh.votesView = (TextView) view.findViewById(R.id.votes); vh.numCommentsSubredditView = (TextView) view.findViewById(R.id.numCommentsSubreddit); vh.nsfwView = (TextView) view.findViewById(R.id.nsfw); vh.voteUpView = (ImageView) view.findViewById(R.id.vote_up_image); vh.voteDownView = (ImageView) view.findViewById(R.id.vote_down_image); vh.thumbnailContainer = view.findViewById(R.id.thumbnail_view); vh.thumbnailFrame = (FrameLayout) view.findViewById(R.id.thumbnail_frame); vh.thumbnailImageView = (ImageView) view.findViewById(R.id.thumbnail); vh.indeterminateProgressBar = (ProgressBar) view.findViewById(R.id.indeterminate_progress); view.setTag(vh); } else { vh = (ViewHolder) view.getTag(); } // Need to store the Thing's id in the thumbnail image so that the thumbnail loader task // knows that the row is still displaying the requested thumbnail. vh.thumbnailImageView.setTag(item.getId()); // Set the title and domain using a SpannableStringBuilder SpannableStringBuilder builder = new SpannableStringBuilder(); String title = item.getTitle(); if (title == null) title = ""; SpannableString titleSS = new SpannableString(title); int titleLen = title.length(); titleSS.setSpan( new TextAppearanceSpan(activity, Util.getTextAppearanceResource(settings.getTheme(), android.R.style.TextAppearance_Large)), 0, titleLen, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); String domain = item.getDomain(); if (domain == null) domain = ""; String flair = item.getLink_flair_text(); if (flair == null) { flair = ""; } else { flair = "[" + flair + "] "; } int domainLen = domain.length() + flair.length(); SpannableString domainSS = new SpannableString(flair + "(" + item.getDomain() + ")"); domainSS.setSpan( new TextAppearanceSpan(activity, Util.getTextAppearanceResource(settings.getTheme(), android.R.style.TextAppearance_Small)), 0, domainLen + 2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); if (Util.isLightTheme(settings.getTheme())) { if (item.isClicked()) { ForegroundColorSpan fcs = new ForegroundColorSpan(res.getColor(R.color.purple)); titleSS.setSpan(fcs, 0, titleLen, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } else { ForegroundColorSpan fcs = new ForegroundColorSpan(res.getColor(R.color.blue)); titleSS.setSpan(fcs, 0, titleLen, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } domainSS.setSpan(new ForegroundColorSpan(res.getColor(R.color.gray_50)), 0, domainLen + 2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } else { if (item.isClicked()) { ForegroundColorSpan fcs = new ForegroundColorSpan(res.getColor(R.color.gray_50)); titleSS.setSpan(fcs, 0, titleLen, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } domainSS.setSpan(new ForegroundColorSpan(res.getColor(R.color.gray_75)), 0, domainLen + 2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } builder.append(titleSS).append(" ").append(domainSS); vh.titleView.setText(builder); vh.votesView.setText(String.format(Locale.US, "%d", item.getScore())); // Lock icon emoji String preText = item.isLocked() ? "\uD83D\uDD12 " : ""; vh.numCommentsSubredditView .setText(preText + Util.showNumComments(item.getNum_comments()) + " " + item.getSubreddit()); vh.nsfwView.setVisibility(item.isOver_18() ? View.VISIBLE : View.GONE); // Set the up and down arrow colors based on whether user likes if (settings.isLoggedIn()) { if (item.getLikes() == null) { vh.voteUpView.setImageResource(R.drawable.vote_up_gray); vh.voteDownView.setImageResource(R.drawable.vote_down_gray); vh.votesView.setTextColor(res.getColor(R.color.gray_75)); } else if (item.getLikes()) { vh.voteUpView.setImageResource(R.drawable.vote_up_red); vh.voteDownView.setImageResource(R.drawable.vote_down_gray); vh.votesView.setTextColor(res.getColor(R.color.arrow_red)); } else { vh.voteUpView.setImageResource(R.drawable.vote_up_gray); vh.voteDownView.setImageResource(R.drawable.vote_down_blue); vh.votesView.setTextColor(res.getColor(R.color.arrow_blue)); } } else { vh.voteUpView.setImageResource(R.drawable.vote_up_gray); vh.voteDownView.setImageResource(R.drawable.vote_down_gray); vh.votesView.setTextColor(res.getColor(R.color.gray_75)); } // Thumbnails open links if (vh.thumbnailContainer != null) { if (Common.shouldLoadThumbnails(activity, settings)) { vh.thumbnailContainer.setVisibility(View.VISIBLE); if (item.getUrl() != null) { OnClickListener thumbnailOnClickListener = thumbnailOnClickListenerFactory .getThumbnailOnClickListener(item, activity); if (thumbnailOnClickListener != null) { vh.thumbnailFrame.setOnClickListener(thumbnailOnClickListener); } } // Show thumbnail based on ThingInfo if (Constants.NSFW_STRING.equalsIgnoreCase(item.getThumbnail()) || Constants.DEFAULT_STRING.equals(item.getThumbnail()) || Constants.SUBMIT_KIND_SELF.equals(item.getThumbnail()) || StringUtils.isEmpty(item.getThumbnail())) { vh.indeterminateProgressBar.setVisibility(View.GONE); vh.thumbnailImageView.setVisibility(View.VISIBLE); vh.thumbnailImageView.setImageResource(R.drawable.go_arrow); } else { if (item.getThumbnailBitmap() != null) { vh.indeterminateProgressBar.setVisibility(View.GONE); vh.thumbnailImageView.setVisibility(View.VISIBLE); vh.thumbnailImageView.setImageBitmap(item.getThumbnailBitmap()); } else { vh.indeterminateProgressBar.setVisibility(View.VISIBLE); vh.thumbnailImageView.setVisibility(View.GONE); vh.thumbnailImageView.setImageBitmap(null); new ShowThumbnailsTask(activity, client, R.drawable.go_arrow) .execute(new ThumbnailLoadAction(item, vh.thumbnailImageView, position, vh.indeterminateProgressBar)); } } // Set thumbnail background based on current theme if (Util.isLightTheme(settings.getTheme())) vh.thumbnailFrame.setBackgroundResource(R.drawable.thumbnail_background_light); else vh.thumbnailFrame.setBackgroundResource(R.drawable.thumbnail_background_dark); } else { // if thumbnails disabled, hide thumbnail icon vh.thumbnailContainer.setVisibility(View.GONE); } } }
From source file:org.kontalk.ui.ComposeMessageFragment.java
private void showIdentityDialog(boolean informationOnly, int titleId) { String fingerprint;//from w w w . j av a 2s . c o m String uid; PGPPublicKeyRing publicKey = UsersProvider.getPublicKey(getActivity(), mUserJID, false); if (publicKey != null) { PGPPublicKey pk = PGP.getMasterKey(publicKey); fingerprint = PGP.formatFingerprint(PGP.getFingerprint(pk)); uid = PGP.getUserId(pk, null); // TODO server!!! } else { // FIXME using another string fingerprint = uid = getString(R.string.peer_unknown); } SpannableStringBuilder text = new SpannableStringBuilder(); text.append(getString(R.string.text_invitation1)).append('\n'); Contact c = mConversation.getContact(); if (c != null) { text.append(c.getName()).append(" <").append(c.getNumber()).append('>'); } else { int start = text.length() - 1; text.append(uid); text.setSpan(MessageUtils.STYLE_BOLD, start, text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } text.append('\n').append(getString(R.string.text_invitation2)).append('\n'); int start = text.length() - 1; text.append(fingerprint); text.setSpan(MessageUtils.STYLE_BOLD, start, text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(getActivity()).setMessage(text); if (informationOnly) { builder.setTitle(titleId); } else { DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // hide warning bar hideWarning(); switch (which) { case DialogInterface.BUTTON_POSITIVE: // trust new key trustKeyChange(); break; case DialogInterface.BUTTON_NEGATIVE: // block user immediately setPrivacy(PRIVACY_BLOCK); break; } } }; builder.setTitle(titleId).setPositiveButton(R.string.button_accept, listener) .setNegativeButton(R.string.button_block, listener); } builder.show(); }
From source file:com.tct.mail.browse.ConversationItemView.java
SpannableStringBuilder elideParticipants(List<SpannableString> parts) { final SpannableStringBuilder builder = new SpannableStringBuilder(); float totalWidth = 0; boolean ellipsize = false; float width;/* w w w. j a v a 2s.c o m*/ boolean skipToHeader = false; // start with "To: " if we're showing recipients if (mDisplayedFolder.shouldShowRecipients() && !parts.isEmpty()) { final SpannableString toHeader = SendersView.getFormattedToHeader(); CharacterStyle[] spans = toHeader.getSpans(0, toHeader.length(), CharacterStyle.class); // There is only 1 character style span; make sure we apply all the // styles to the paint object before measuring. if (spans.length > 0) { spans[0].updateDrawState(sPaint); } totalWidth += sPaint.measureText(toHeader.toString()); builder.append(toHeader); skipToHeader = true; } final SpannableStringBuilder messageInfoString = mHeader.messageInfoString; if (messageInfoString.length() > 0) { CharacterStyle[] spans = messageInfoString.getSpans(0, messageInfoString.length(), CharacterStyle.class); // There is only 1 character style span; make sure we apply all the // styles to the paint object before measuring. if (spans.length > 0) { spans[0].updateDrawState(sPaint); } // Paint the message info string to see if we lose space. float messageInfoWidth = sPaint.measureText(messageInfoString.toString()); totalWidth += messageInfoWidth; } SpannableString prevSender = null; SpannableString ellipsizedText; for (SpannableString sender : parts) { // There may be null sender strings if there were dupes we had to remove. if (sender == null) { continue; } // No more width available, we'll only show fixed fragments. if (ellipsize) { break; } CharacterStyle[] spans = sender.getSpans(0, sender.length(), CharacterStyle.class); // There is only 1 character style span. if (spans.length > 0) { spans[0].updateDrawState(sPaint); } // If there are already senders present in this string, we need to // make sure we prepend the dividing token if (SendersView.sElidedString.equals(sender.toString())) { prevSender = sender; sender = copyStyles(spans, sElidedPaddingToken + sender + sElidedPaddingToken); } else if (!skipToHeader && builder.length() > 0 && (prevSender == null || !SendersView.sElidedString.equals(prevSender.toString()))) { prevSender = sender; sender = copyStyles(spans, sSendersSplitToken + sender); } else { prevSender = sender; skipToHeader = false; } if (spans.length > 0) { spans[0].updateDrawState(sPaint); } //TS: yanhua.chen 2015-9-2 EMAIL CR_540046 MOD_S // Measure the width of the current sender and make sure we have space width = (int) sPaint.measureText(sender.toString()); if (width + totalWidth > mCoordinates.sendersWidth) { // The text is too long, new line won't help. We have to // ellipsize text. ellipsize = true; width = mCoordinates.sendersWidth - totalWidth; // ellipsis width? ellipsizedText = copyStyles(spans, TextUtils.ellipsize(sender, sPaint, width, TruncateAt.END)); width = (int) sPaint.measureText(ellipsizedText.toString()); } else { ellipsizedText = null; } totalWidth += width; //TS: yanhua.chen 2015-9-2 EMAIL CR_540046 MOD_E //[FEATURE]-Add-BEGIN by CDTS.zhonghua.tuo,05/29/2014,FR 670064 CharSequence fragmentDisplayText; if (ellipsizedText != null) { fragmentDisplayText = ellipsizedText; } else { fragmentDisplayText = sender; } boolean filterSender = false; if (mField == UIProvider.LOCAL_SEARCH_ALL || mField == UIProvider.LOCAL_SEARCH_FROM) { filterSender = true; } if (mQueryText != null && filterSender) { fragmentDisplayText = TextUtilities.highlightTermsInText(fragmentDisplayText.toString(), mQueryText); } //[FEATURE]-Add-END by CDTS.zhonghua.tuo builder.append(fragmentDisplayText); } mHeader.styledMessageInfoStringOffset = builder.length(); builder.append(messageInfoString); return builder; }
From source file:org.brandroid.openmanager.activities.OpenExplorer.java
public void updateTitle(CharSequence cs) { TextView title = (TextView) findViewById(R.id.title_path); if ((title == null || !title.isShown()) && !BEFORE_HONEYCOMB && getActionBar() != null && getActionBar().getCustomView() != null) title = (TextView) getActionBar().getCustomView().findViewById(R.id.title_path); //if(BEFORE_HONEYCOMB || !USE_ACTION_BAR || getActionBar() == null) if (title != null && title.getVisibility() != View.GONE) title.setText(cs, BufferType.SPANNABLE); if (!BEFORE_HONEYCOMB && USE_ACTION_BAR && getActionBar() != null && (title == null || !title.isShown())) getActionBar().setSubtitle(cs);//from w ww . ja v a2 s. c o m //else { SpannableStringBuilder sb = new SpannableStringBuilder(getResources().getString(R.string.app_title)); sb.append(cs.equals("") ? "" : " - "); sb.append(cs); setTitle(cs); } }
From source file:org.brandroid.openmanager.activities.OpenExplorer.java
@SuppressWarnings("unused") public void updatePagerTitle(int page) { TextView tvLeft = null; // (TextView)findViewById(R.id.title_left); TextView tvRight = null; //(TextView)findViewById(R.id.title_right); String left = ""; SpannableStringBuilder ssb = new SpannableStringBuilder(); for (int i = 0; i < page; i++) { OpenFragment f = mViewPagerAdapter.getItem(i); if (f instanceof ContentFragment) { OpenPath p = ((ContentFragment) f).getPath(); left += p.getName();//from ww w . j a v a 2 s . c o m if (p.isDirectory() && !left.endsWith("/")) left += "/"; } } SpannableString srLeft = new SpannableString(left); srLeft.setSpan(new ForegroundColorSpan(Color.GRAY), 0, left.length(), Spanned.SPAN_COMPOSING); ssb.append(srLeft); //ssb.setSpan(new ForegroundColorSpan(Color.GRAY), 0, left.length(), Spanned.SPAN_COMPOSING); OpenFragment curr = mViewPagerAdapter.getItem(page); if (curr instanceof ContentFragment) { OpenPath pCurr = ((ContentFragment) curr).getPath(); ssb.append(pCurr.getName()); if (pCurr.isDirectory()) ssb.append("/"); } String right = ""; for (int i = page + 1; i < mViewPagerAdapter.getCount(); i++) { OpenFragment f = mViewPagerAdapter.getItem(i); if (f instanceof ContentFragment) { OpenPath p = ((ContentFragment) f).getPath(); right += p.getName(); if (p.isDirectory() && !right.endsWith("/")) right += "/"; } } SpannableString srRight = new SpannableString(right); srRight.setSpan(new ForegroundColorSpan(Color.GRAY), 0, right.length(), Spanned.SPAN_COMPOSING); ssb.append(srRight); updateTitle(ssb); }
From source file:org.tvbrowser.tvbrowser.TvBrowser.java
private void showChannelSelectionInternal(final String selection, final String title, final String help, final boolean delete) { String[] projection = {/*from w w w . j a v a2s.c om*/ TvBrowserContentProvider.CHANNEL_TABLE + "." + TvBrowserContentProvider.KEY_ID + " AS " + TvBrowserContentProvider.KEY_ID, TvBrowserContentProvider.GROUP_KEY_DATA_SERVICE_ID, TvBrowserContentProvider.CHANNEL_KEY_NAME, TvBrowserContentProvider.CHANNEL_KEY_SELECTION, TvBrowserContentProvider.CHANNEL_KEY_CATEGORY, TvBrowserContentProvider.CHANNEL_KEY_LOGO, TvBrowserContentProvider.CHANNEL_KEY_ALL_COUNTRIES }; ContentResolver cr = getContentResolver(); Cursor channels = cr.query(TvBrowserContentProvider.CONTENT_URI_CHANNELS_WITH_GROUP, projection, selection, null, TvBrowserContentProvider.CHANNEL_KEY_NAME); channels.moveToPosition(-1); // populate array list with all available channels final ArrayListWrapper channelSelectionList = new ArrayListWrapper(); ArrayList<Country> countryList = new ArrayList<Country>(); int channelIdColumn = channels.getColumnIndex(TvBrowserContentProvider.KEY_ID); int categoryColumn = channels.getColumnIndex(TvBrowserContentProvider.CHANNEL_KEY_CATEGORY); int logoColumn = channels.getColumnIndex(TvBrowserContentProvider.CHANNEL_KEY_LOGO); int dataServiceColumn = channels.getColumnIndex(TvBrowserContentProvider.GROUP_KEY_DATA_SERVICE_ID); int nameColumn = channels.getColumnIndex(TvBrowserContentProvider.CHANNEL_KEY_NAME); int countyColumn = channels.getColumnIndex(TvBrowserContentProvider.CHANNEL_KEY_ALL_COUNTRIES); int selectionColumn = channels.getColumnIndex(TvBrowserContentProvider.CHANNEL_KEY_SELECTION); ; while (channels.moveToNext()) { int channelID = channels.getInt(channelIdColumn); int category = channels.getInt(categoryColumn); byte[] logo = channels.getBlob(logoColumn); String dataService = channels.getString(dataServiceColumn); String name = channels.getString(nameColumn); String countries = channels.getString(countyColumn); boolean isSelected = channels.getInt(selectionColumn) == 1 && !delete; if (countries.contains("$")) { String[] values = countries.split("\\$"); for (String country : values) { Country test = new Country(new Locale(country, country)); if (!countryList.contains(test) && test.mLocale.getDisplayCountry().trim().length() > 0) { countryList.add(test); } } } else { Country test = new Country(new Locale(countries, countries)); if (!countryList.contains(test) && test.mLocale.getDisplayCountry().trim().length() > 0) { countryList.add(test); } } Bitmap channelLogo = UiUtils.createBitmapFromByteArray(logo); if (channelLogo != null) { BitmapDrawable l = new BitmapDrawable(getResources(), channelLogo); ColorDrawable background = new ColorDrawable(SettingConstants.LOGO_BACKGROUND_COLOR); background.setBounds(0, 0, channelLogo.getWidth() + 2, channelLogo.getHeight() + 2); LayerDrawable logoDrawable = new LayerDrawable(new Drawable[] { background, l }); logoDrawable.setBounds(background.getBounds()); l.setBounds(2, 2, channelLogo.getWidth(), channelLogo.getHeight()); channelLogo = UiUtils.drawableToBitmap(logoDrawable); } channelSelectionList.add(new ChannelSelection(channelID, name, category, countries, channelLogo, isSelected, SettingConstants.EPG_DONATE_KEY.equals(dataService))); } // sort countries for filtering Collections.sort(countryList, new Comparator<Country>() { @Override public int compare(Country lhs, Country rhs) { return lhs.toString().compareToIgnoreCase(rhs.toString()); } }); countryList.add(0, new Country(null)); channels.close(); // create filter for filtering of category and country final ChannelFilter filter = new ChannelFilter(SettingConstants.TV_CATEGORY, null); // create default logo for channels without logo final Bitmap defaultLogo = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher); final Set<String> firstDeletedChannels = PrefUtils.getStringSetValue(R.string.PREF_FIRST_DELETED_CHANNELS, new HashSet<String>()); final Set<String> keptDeletedChannels = PrefUtils.getStringSetValue(R.string.PREF_KEPT_DELETED_CHANNELS, new HashSet<String>()); final int firstDeletedColor = getResources().getColor(R.color.pref_first_deleted_channels); final int keptDeletedColor = getResources().getColor(R.color.pref_kept_deleted_channels); // Custom array adapter for channel selection final ArrayAdapter<ChannelSelection> channelSelectionAdapter = new ArrayAdapter<ChannelSelection>( TvBrowser.this, R.layout.channel_row, channelSelectionList) { public View getView(int position, View convertView, ViewGroup parent) { ChannelSelection value = getItem(position); ViewHolder holder = null; if (convertView == null) { LayoutInflater mInflater = (LayoutInflater) getContext() .getSystemService(Activity.LAYOUT_INFLATER_SERVICE); holder = new ViewHolder(); convertView = mInflater.inflate(R.layout.channel_row, getParentViewGroup(), false); holder.mTextView = (TextView) convertView.findViewById(R.id.row_of_channel_text); holder.mCheckBox = (CheckBox) convertView.findViewById(R.id.row_of_channel_selection); holder.mLogo = (ImageView) convertView.findViewById(R.id.row_of_channel_icon); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } SpannableStringBuilder nameBuilder = new SpannableStringBuilder(value.toString()); String channelID = String.valueOf(value.getChannelID()); if (keptDeletedChannels.contains(channelID)) { nameBuilder.setSpan(new ForegroundColorSpan(keptDeletedColor), 0, value.toString().length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } else if (firstDeletedChannels.contains(channelID)) { nameBuilder.setSpan(new ForegroundColorSpan(firstDeletedColor), 0, value.toString().length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } if (value.isEpgDonateChannel()) { nameBuilder.append("\n(EPGdonate)"); nameBuilder.setSpan(new RelativeSizeSpan(0.65f), value.toString().length(), nameBuilder.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } holder.mTextView.setText(nameBuilder); holder.mCheckBox.setChecked(value.isSelected()); Bitmap logo = value.getLogo(); if (logo != null) { holder.mLogo.setImageBitmap(logo); } else { holder.mLogo.setImageBitmap(defaultLogo); } return convertView; } }; // inflate channel selection view View channelSelectionView = getLayoutInflater().inflate(R.layout.dialog_channel_selection_list, getParentViewGroup(), false); channelSelectionView.findViewById(R.id.channel_selection_selection_buttons).setVisibility(View.GONE); channelSelectionView.findViewById(R.id.channel_selection_input_id_name).setVisibility(View.GONE); TextView infoView = (TextView) channelSelectionView.findViewById(R.id.channel_selection_label_id_name); if (help != null) { infoView.setText(help); infoView.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.epg_donate_info_font_size)); } else { infoView.setVisibility(View.GONE); } // get spinner for country filtering and create array adapter with all available countries Spinner country = (Spinner) channelSelectionView.findViewById(R.id.channel_country_value); final ArrayAdapter<Country> countryListAdapter = new ArrayAdapter<Country>(this, android.R.layout.simple_spinner_item, countryList); countryListAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); country.setAdapter(countryListAdapter); // add item selection listener to react of user setting filter for country country.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { Country country = countryListAdapter.getItem(position); filter.mCountry = country.getCountry(); channelSelectionList.setFilter(filter); channelSelectionAdapter.notifyDataSetChanged(); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); // get spinner for category selection and add listener to react to user category selection Spinner category = (Spinner) channelSelectionView.findViewById(R.id.channel_category_value); category.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { switch (position) { case 1: filter.mCategory = SettingConstants.TV_CATEGORY; break; case 2: filter.mCategory = SettingConstants.RADIO_CATEGORY; break; case 3: filter.mCategory = SettingConstants.CINEMA_CATEGORY; break; default: filter.mCategory = SettingConstants.NO_CATEGORY; break; } channelSelectionList.setFilter(filter); channelSelectionAdapter.notifyDataSetChanged(); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); if (delete) { channelSelectionView.findViewById(R.id.channel_country_label).setVisibility(View.GONE); channelSelectionView.findViewById(R.id.channel_category_label).setVisibility(View.GONE); country.setVisibility(View.GONE); category.setVisibility(View.GONE); } // get the list view of the layout and add adapter with available channels ListView list = (ListView) channelSelectionView.findViewById(R.id.channel_selection_list); list.setAdapter(channelSelectionAdapter); // add listener to react to user selection of channels list.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { CheckBox check = (CheckBox) view.findViewById(R.id.row_of_channel_selection); if (check != null) { check.setChecked(!check.isChecked()); channelSelectionAdapter.getItem(position).setSelected(check.isChecked()); } } }); // show dialog only if channels are available if (!channelSelectionList.isEmpty()) { AlertDialog.Builder builder = new AlertDialog.Builder(TvBrowser.this); if (title == null) { builder.setTitle(R.string.select_channels); } else { builder.setTitle(title); } builder.setView(channelSelectionView); builder.setPositiveButton(android.R.string.ok, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { boolean somethingSelected = false; boolean somethingChanged = false; Iterator<ChannelSelection> it = channelSelectionList.superIterator(); StringBuilder deleteWhere = new StringBuilder(); HashSet<String> keep = new HashSet<String>(); while (it.hasNext()) { ChannelSelection sel = it.next(); if (sel.isSelected() && !sel.wasSelected()) { somethingChanged = somethingSelected = true; if (delete) { if (deleteWhere.length() > 0) { deleteWhere.append(", "); } deleteWhere.append(sel.getChannelID()); } else { ContentValues values = new ContentValues(); values.put(TvBrowserContentProvider.CHANNEL_KEY_SELECTION, 1); getContentResolver().update( ContentUris.withAppendedId(TvBrowserContentProvider.CONTENT_URI_CHANNELS, sel.getChannelID()), values, null, null); } } else if (!sel.isSelected() && sel.wasSelected()) { somethingChanged = true; ContentValues values = new ContentValues(); values.put(TvBrowserContentProvider.CHANNEL_KEY_SELECTION, 0); getContentResolver().update( ContentUris.withAppendedId(TvBrowserContentProvider.CONTENT_URI_CHANNELS, sel.getChannelID()), values, null, null); getContentResolver().delete(TvBrowserContentProvider.CONTENT_URI_DATA_VERSION, TvBrowserContentProvider.CHANNEL_KEY_CHANNEL_ID + "=" + sel.getChannelID(), null); getContentResolver().delete(TvBrowserContentProvider.CONTENT_URI_DATA, TvBrowserContentProvider.CHANNEL_KEY_CHANNEL_ID + "=" + sel.getChannelID(), null); } else if (delete && !sel.isSelected()) { keep.add(String.valueOf(sel.getChannelID())); } } if (delete) { if (deleteWhere.length() > 0) { deleteWhere.insert(0, TvBrowserContentProvider.KEY_ID + " IN ( "); deleteWhere.append(" ) "); Log.d("info2", "DELETE WHERE FOR REMOVED CHANNELS " + deleteWhere.toString()); int count = getContentResolver().delete(TvBrowserContentProvider.CONTENT_URI_CHANNELS, deleteWhere.toString(), null); Log.d("info2", "REMOVED CHANNELS COUNT " + count); } Editor edit = PreferenceManager.getDefaultSharedPreferences(TvBrowser.this).edit(); edit.putStringSet(getString(R.string.PREF_KEPT_DELETED_CHANNELS), keep); edit.commit(); } // if something was changed we need to update channel list bar in program list and the complete program table if (somethingChanged) { SettingConstants.initializeLogoMap(TvBrowser.this, true); updateProgramListChannelBar(); } // if something was selected we need to download new data if (somethingSelected && !delete) { checkTermsAccepted(); } } }); builder.setNegativeButton(android.R.string.cancel, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (delete) { HashSet<String> keep = new HashSet<String>(); Iterator<ChannelSelection> it = channelSelectionList.superIterator(); while (it.hasNext()) { ChannelSelection sel = it.next(); keep.add(String.valueOf(sel.getChannelID())); } Editor edit = PreferenceManager.getDefaultSharedPreferences(TvBrowser.this).edit(); edit.putStringSet(getString(R.string.PREF_KEPT_DELETED_CHANNELS), keep); edit.commit(); } } }); builder.show(); } selectingChannels = false; }