List of usage examples for android.text SpannableString setSpan
public void setSpan(Object what, int start, int end, int flags)
From source file:tw.com.geminihsu.app01.fragment.Fragment_PickUpAirPlane.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { MenuItem item = menu.add(Menu.NONE, ACTIONBAR_MENU_ITEM_SUMMIT, Menu.NONE, getString(R.string.menu_take)); SpannableString spanString = new SpannableString(item.getTitle().toString()); spanString.setSpan(new ForegroundColorSpan(Color.WHITE), 0, spanString.length(), 0); //fix the color to white item.setTitle(spanString);//w ww . j a va 2 s. co m item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); super.onCreateOptionsMenu(menu, inflater); }
From source file:org.awesomeapp.messenger.ui.MessageListItem.java
private CharSequence formatPresenceUpdates(String contact, int type, Date date, boolean isGroupChat, boolean scrolling) { String body;/* www. j a v a2 s. c o m*/ Resources resources = getResources(); switch (type) { case Imps.MessageType.PRESENCE_AVAILABLE: body = resources.getString(isGroupChat ? R.string.contact_joined : R.string.contact_online, contact); break; case Imps.MessageType.PRESENCE_AWAY: body = resources.getString(R.string.contact_away, contact); break; case Imps.MessageType.PRESENCE_DND: body = resources.getString(R.string.contact_busy, contact); break; case Imps.MessageType.PRESENCE_UNAVAILABLE: body = resources.getString(isGroupChat ? R.string.contact_left : R.string.contact_offline, contact); break; default: return null; } body += " - "; body += formatTimeStamp(date, type, null, EncryptionState.NONE, null); if (scrolling) { return body; } else { SpannableString spanText = new SpannableString(body); int len = spanText.length(); spanText.setSpan(new StyleSpan(Typeface.ITALIC), 0, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); spanText.setSpan(new RelativeSizeSpan((float) 0.8), 0, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); return spanText; } }
From source file:com.zitech.framework.widget.SlidingTabs.java
/** * call this function if you call some setXXX() function *//*from w w w .j a v a 2s .c o m*/ private void updateTabStyles() { PagerAdapter adapter = this.pager.getAdapter(); if (adapter instanceof TabsTitleInterface) { for (int i = 0; i < this.tabCount; i++) { View v = this.tabsContainer.getChildAt(i); v.setBackgroundResource(this.tabBackgroundResId); if (v instanceof TextView) { TextView tab = (TextView) v; SpannableString spannableString = ((TabsTitleInterface) adapter).getTabTitle(i); if (i == this.selectedPosition) { spannableString.setSpan(new ForegroundColorSpan(this.selectedTabTextColor), 0, spannableString.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); tab.setText(spannableString); } else { spannableString.setSpan(new ForegroundColorSpan(this.tabTextColor), 0, spannableString.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); tab.setText(spannableString); } } } } else { for (int i = 0; i < this.tabCount; i++) { View v = this.tabsContainer.getChildAt(i); v.setBackgroundResource(this.tabBackgroundResId); if (v instanceof TextView) { TextView tab = (TextView) v; tab.setTextSize(TypedValue.COMPLEX_UNIT_SP, tabTextSize); tab.setTypeface(this.tabTypeface, this.tabTypefaceStyle); tab.setTextColor(this.tabTextColor); // setAllCaps() is only available from API 14, so the upper case is made manually if we are on a // pre-ICS-build if (textAllCaps) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { tab.setAllCaps(true); } else { tab.setText(tab.getText().toString().toUpperCase(locale)); } } if (i == this.selectedPosition) { tab.setTextColor(this.selectedTabTextColor); } else { tab.setTextColor(this.tabTextColor); } } } } }
From source file:com.waz.zclient.controllers.notifications.NotificationsController.java
@TargetApi(21) private SpannableString getMessageSpannable(String header, String body) { SpannableString messageSpannable = new SpannableString(header + body); final int textAppearance; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { textAppearance = android.R.style.TextAppearance_Material_Notification_Title; } else {//from w w w. java2 s . c o m textAppearance = android.R.style.TextAppearance_StatusBar_EventContent_Title; } final TextAppearanceSpan textAppearanceSpan = new TextAppearanceSpan(context, textAppearance); messageSpannable.setSpan(new ForegroundColorSpan(textAppearanceSpan.getTextColor().getDefaultColor()), 0, header.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return messageSpannable; }
From source file:com.ideascontest.navi.uask.MainQuestionAnswerAdapter.java
/** * OnBindViewHolder is called by the RecyclerView to display the data at the specified * position. In this method, we update the contents of the ViewHolder to display the correct * indices in the list for this particular position, using the "position" argument that is conveniently * passed into us.//from ww w.j av a2s . c o m * * @param holder The ViewHolder which should be updated to represent the contents of the * item at the given position in the data set. * @param position The position of the item within the adapter's data set. */ @Override public void onBindViewHolder(QuestionTopAnswerHolder holder, int position) { Log.d(TAG, "#" + position); QuestionTopAnswerHolder questionTopAnswerHolder = (QuestionTopAnswerHolder) holder; final Context context = questionTopAnswerHolder.v.getContext(); Log.d(TAG, "Category" + _category); switch (_category) { case 0: case 1: case 2: case 3: case 4: { if (position == 0) { /* String infoText = (String) questionTopAnswerHolder.basicInfoText.getText(); int count = infoText.split("\n").length; int upperLimit = (count > 5) ? MainAnswerAdapter.ordinalIndexOf(infoText, "\n", 5) : 140; if (infoText.length() > 140 || count > 5) { infoText = infoText.substring(0, upperLimit) + "... " + "view more"; SpannableString sText = new SpannableString(infoText); ClickableSpan myClickableSpan = new ClickableSpan() { @Override public void onClick(View v) { Log.d("MainCanvas Category", "clickable Span"); //finish(); } }; int spanLowLimit = upperLimit + 4; int spanHighLimit = upperLimit + 13; sText.setSpan(myClickableSpan, spanLowLimit, spanHighLimit, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); sText.setSpan(new RelativeSizeSpan(0.75f), spanLowLimit, spanHighLimit, 0); sText.setSpan(new ForegroundColorSpan( questionTopAnswerHolder.v.getResources().getColor(R.color.primaryOrange)), spanLowLimit, spanHighLimit, 0); questionTopAnswerHolder.basicInfoText.setText(sText); questionTopAnswerHolder.basicInfoText.setMovementMethod(LinkMovementMethod.getInstance()); }*/ String infoText = (String) questionTopAnswerHolder.basicInfoText.getText(); int upperLimit = 150; if (infoText.length() > 150) { infoText = infoText.substring(0, upperLimit) + "... " + "view more"; SpannableString sText = new SpannableString(infoText); ClickableSpan myClickableSpan = new ClickableSpan() { @Override public void onClick(View v) { Log.d("Mainadapter Category", "clickable Span"); Intent intent = new Intent(context, ShowBasicInfo.class); intent.putExtra("category", _category); context.startActivity(intent);//finish(); } }; int spanLowLimit = upperLimit + 4; int spanHighLimit = upperLimit + 13; sText.setSpan(myClickableSpan, spanLowLimit, spanHighLimit, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); sText.setSpan(new RelativeSizeSpan(0.75f), spanLowLimit, spanHighLimit, 0); sText.setSpan( new ForegroundColorSpan( questionTopAnswerHolder.v.getResources().getColor(R.color.primaryOrange)), spanLowLimit, spanHighLimit, 0); questionTopAnswerHolder.basicInfoText.setText(sText); questionTopAnswerHolder.basicInfoText.setMovementMethod(LinkMovementMethod.getInstance()); } } else { populateDynamicUiElements(questionTopAnswerHolder, (position - 1)); } } break; case 5: { if (position == 0) { questionTopAnswerHolder.basicInfoText.setText("List of all non-categorical questions"); questionTopAnswerHolder.basicInfoText.setGravity(Gravity.CENTER | Gravity.BOTTOM); questionTopAnswerHolder.headingText.setVisibility(View.INVISIBLE); } else { populateDynamicUiElements(questionTopAnswerHolder, (position - 1)); } } break; case 6: { if (position == 0) { questionTopAnswerHolder.basicInfoText.setText("List of all questions asked by you."); questionTopAnswerHolder.basicInfoText.setGravity(Gravity.CENTER | Gravity.BOTTOM); questionTopAnswerHolder.headingText.setVisibility(View.INVISIBLE); } else { populateDynamicUiElements(questionTopAnswerHolder, (position - 1)); } } break; case 7: { if (position == 0) { questionTopAnswerHolder.basicInfoText.setText("List of all questions answered by you."); questionTopAnswerHolder.basicInfoText.setGravity(Gravity.CENTER | Gravity.BOTTOM); questionTopAnswerHolder.headingText.setVisibility(View.INVISIBLE); } else { populateDynamicUiElements(questionTopAnswerHolder, (position - 1)); } } break; case 8: { if (position == 0) { questionTopAnswerHolder.basicInfoText.setText( "All the private questions asked by your faculty students. Visible only to fellow faculty students"); questionTopAnswerHolder.basicInfoText.setGravity(Gravity.CENTER | Gravity.BOTTOM); questionTopAnswerHolder.headingText.setVisibility(View.INVISIBLE); } else { populateDynamicUiElements(questionTopAnswerHolder, (position - 1)); } } break; default: { populateDynamicUiElements(questionTopAnswerHolder, position); } break; } }
From source file:io.plaidapp.ui.DesignerNewsStory.java
private void bindDescription() { final TextView storyComment = (TextView) header.findViewById(R.id.story_comment); if (!TextUtils.isEmpty(story.comment)) { HtmlUtils.setTextWithNiceLinks(storyComment, markdown.markdownToSpannable(story.comment, storyComment, new Bypass.LoadImageCallback() { @Override/*from w w w .jav a 2s . c o m*/ public void loadImage(String src, ImageLoadingSpan loadingSpan) { Glide.with(DesignerNewsStory.this).load(src).asBitmap() .diskCacheStrategy(DiskCacheStrategy.ALL) .into(new ImageSpanTarget(storyComment, loadingSpan)); } })); } else { storyComment.setVisibility(View.GONE); } upvoteStory = (Button) header.findViewById(R.id.story_vote_action); upvoteStory.setText(getResources().getQuantityString(R.plurals.upvotes, story.vote_count, NumberFormat.getInstance().format(story.vote_count))); upvoteStory.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View v) { upvoteStory(); } }); Button share = (Button) header.findViewById(R.id.story_share_action); share.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startActivity(ShareCompat.IntentBuilder.from(DesignerNewsStory.this).setText(story.url) .setType("text/plain").setSubject(story.title).getIntent()); } }); TextView storyPosterTime = (TextView) header.findViewById(R.id.story_poster_time); SpannableString poster = new SpannableString("" + story.user_display_name); poster.setSpan(new TextAppearanceSpan(this, R.style.TextAppearance_CommentAuthor), 0, poster.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); CharSequence job = !TextUtils.isEmpty(story.user_job) ? "\n" + story.user_job : ""; CharSequence timeAgo = DateUtils.getRelativeTimeSpanString(story.created_at.getTime(), System.currentTimeMillis(), DateUtils.SECOND_IN_MILLIS); storyPosterTime.setText(TextUtils.concat(poster, job, "\n", timeAgo)); ImageView avatar = (ImageView) header.findViewById(R.id.story_poster_avatar); if (!TextUtils.isEmpty(story.user_portrait_url)) { Glide.with(this).load(story.user_portrait_url).placeholder(R.drawable.avatar_placeholder) .transform(circleTransform).into(avatar); } else { avatar.setVisibility(View.GONE); } }
From source file:org.thoughtcrime.securesms.ConversationItem.java
private SpannableString linkifyMessageBody(SpannableString messageBody, boolean shouldLinkifyAllLinks) { boolean hasLinks = Linkify.addLinks(messageBody, shouldLinkifyAllLinks ? Linkify.ALL : 0); if (hasLinks) { URLSpan[] urlSpans = messageBody.getSpans(0, messageBody.length(), URLSpan.class); for (URLSpan urlSpan : urlSpans) { int start = messageBody.getSpanStart(urlSpan); int end = messageBody.getSpanEnd(urlSpan); messageBody.setSpan(new LongClickCopySpan(urlSpan.getURL()), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); }// w w w. j a v a 2 s.co m } return messageBody; }
From source file:io.plaidapp.ui.DesignerNewsStory.java
private void bindDescription() { final TextView storyComment = (TextView) header.findViewById(R.id.story_comment); if (!TextUtils.isEmpty(story.comment)) { HtmlUtils.parseMarkdownAndSetText(storyComment, story.comment, markdown, new Bypass.LoadImageCallback() { @Override//from w w w . j a va2 s .co m public void loadImage(String src, ImageLoadingSpan loadingSpan) { Glide.with(DesignerNewsStory.this).load(src).asBitmap() .diskCacheStrategy(DiskCacheStrategy.ALL) .into(new ImageSpanTarget(storyComment, loadingSpan)); } }); } else { storyComment.setVisibility(View.GONE); } upvoteStory = (TextView) header.findViewById(R.id.story_vote_action); upvoteStory.setText(getResources().getQuantityString(R.plurals.upvotes, story.vote_count, NumberFormat.getInstance().format(story.vote_count))); upvoteStory.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View v) { upvoteStory(); } }); final TextView share = (TextView) header.findViewById(R.id.story_share_action); share.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ((AnimatedVectorDrawable) share.getCompoundDrawables()[1]).start(); startActivity(ShareCompat.IntentBuilder.from(DesignerNewsStory.this).setText(story.url) .setType("text/plain").setSubject(story.title).getIntent()); } }); TextView storyPosterTime = (TextView) header.findViewById(R.id.story_poster_time); SpannableString poster = new SpannableString(story.user_display_name.toLowerCase()); poster.setSpan(new TextAppearanceSpan(this, R.style.TextAppearance_CommentAuthor), 0, poster.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); CharSequence job = !TextUtils.isEmpty(story.user_job) ? "\n" + story.user_job.toLowerCase() : ""; CharSequence timeAgo = DateUtils.getRelativeTimeSpanString(story.created_at.getTime(), System.currentTimeMillis(), DateUtils.SECOND_IN_MILLIS).toString().toLowerCase(); storyPosterTime.setText(TextUtils.concat(poster, job, "\n", timeAgo)); ImageView avatar = (ImageView) header.findViewById(R.id.story_poster_avatar); if (!TextUtils.isEmpty(story.user_portrait_url)) { Glide.with(this).load(story.user_portrait_url).placeholder(R.drawable.avatar_placeholder) .transform(circleTransform).into(avatar); } else { avatar.setVisibility(View.GONE); } }
From source file:usbong.android.utils.UsbongUtils.java
private static SpannableString makeLinkSpan(CharSequence text, View.OnClickListener listener) { SpannableString link = new SpannableString(text); link.setSpan(new ClickableString(listener), 0, text.length(), SpannableString.SPAN_INCLUSIVE_EXCLUSIVE); return link;//from w w w . ja va 2s . com }
From source file:com.tct.mail.utils.NotificationUtils.java
private static CharSequence getSingleMessageBigText(Context context, final Message message, String from) { final TextAppearanceSpan notificationSubjectSpan = new TextAppearanceSpan(context, R.style.NotificationPrimaryText); final String snippet = getMessageBodyWithoutElidedText(message); // Change multiple newlines (with potential white space between), into a single new line final String collapsedSnippet = !TextUtils.isEmpty(snippet) ? snippet.replaceAll("\\n\\s+", "\n") : ""; if (TextUtils.isEmpty(from)) { // If the subject is empty, just use the snippet. return snippet; } else if (TextUtils.isEmpty(collapsedSnippet)) { // If the snippet is empty, just use the subject. final SpannableString spannableString = new SpannableString(from); spannableString.setSpan(notificationSubjectSpan, 0, from.length(), 0); return spannableString; } else {//w w w. j ava 2 s . co m final String notificationBigTextFormat = context.getResources() .getString(R.string.single_new_message_notification_big_text); // Localizers may change the order of the parameters, look at how the format // string is structured. final boolean isSubjectFirst = notificationBigTextFormat.indexOf("%2$s") > notificationBigTextFormat .indexOf("%1$s"); final String bigText = String.format(notificationBigTextFormat, from, collapsedSnippet); final SpannableString spannableString = new SpannableString(bigText); final int subjectOffset = (isSubjectFirst ? bigText.indexOf(from) : bigText.lastIndexOf(from)); spannableString.setSpan(new ForegroundColorSpan(Color.BLACK), subjectOffset, subjectOffset + from.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE); return spannableString; } }