use of android.text.style.ForegroundColorSpan in project AndroidChromium by JackyAndroid.
the class ExpandablePreferenceGroup method setGroupTitle.
/**
* Set the title for the preference group.
* @param resourceId The resource id of the text to use.
* @param count The number of entries the preference group contains.
*/
public void setGroupTitle(int resourceId, int count) {
SpannableStringBuilder spannable = new SpannableStringBuilder(getContext().getResources().getString(resourceId));
String prefCount = String.format(Locale.getDefault(), " - %d", count);
spannable.append(prefCount);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
spannable.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, spannable.length() - prefCount.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
} else {
spannable.setSpan(new TypefaceSpan("sans-serif-medium"), 0, spannable.length() - prefCount.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
// Color the first part of the title blue.
ForegroundColorSpan blueSpan = new ForegroundColorSpan(ApiCompatibilityUtils.getColor(getContext().getResources(), R.color.pref_accent_color));
spannable.setSpan(blueSpan, 0, spannable.length() - prefCount.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
// Gray out the total count of items.
int gray = ApiCompatibilityUtils.getColor(getContext().getResources(), R.color.expandable_group_dark_gray);
spannable.setSpan(new ForegroundColorSpan(gray), spannable.length() - prefCount.length(), spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
setTitle(spannable);
}
use of android.text.style.ForegroundColorSpan in project AndroidChromium by JackyAndroid.
the class SyncCustomizationFragment method errorSummary.
/**
* Applies a span to the given string to give it an error color.
*/
private static Spannable errorSummary(String string, Context context) {
SpannableString summary = new SpannableString(string);
summary.setSpan(new ForegroundColorSpan(ApiCompatibilityUtils.getColor(context.getResources(), R.color.input_underline_error_color)), 0, summary.length(), 0);
return summary;
}
use of android.text.style.ForegroundColorSpan in project AndroidDevelop by 7449.
the class SpannableUtils method getHomeTitlePageType.
public static SpannableStringBuilder getHomeTitlePageType(String text, String suffix) {
SpannableStringBuilder mText = new SpannableStringBuilder("#" + text + "#" + suffix);
ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(ContextCompat.getColor(App.getContext(), R.color.colorPrimary));
mText.setSpan(foregroundColorSpan, 0, mText.length() - suffix.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
return mText;
}
use of android.text.style.ForegroundColorSpan in project android_frameworks_base by DirtyUnicorns.
the class HtmlToSpannedConverter method endFont.
private static void endFont(Editable text) {
Font font = getLast(text, Font.class);
if (font != null) {
setSpanFromMark(text, font, new TypefaceSpan(font.mFace));
}
Foreground foreground = getLast(text, Foreground.class);
if (foreground != null) {
setSpanFromMark(text, foreground, new ForegroundColorSpan(foreground.mForegroundColor));
}
}
use of android.text.style.ForegroundColorSpan in project Etar-Calendar by Etar-Group.
the class EventInfoFragment method updateEvent.
private void updateEvent(View view) {
if (mEventCursor == null || view == null) {
return;
}
Context context = view.getContext();
if (context == null) {
return;
}
String eventName = mEventCursor.getString(EVENT_INDEX_TITLE);
if (eventName == null || eventName.length() == 0) {
eventName = getActivity().getString(R.string.no_title_label);
}
// Events.CONTENT_URI intent. Update these with values read from the db.
if (mStartMillis == 0 && mEndMillis == 0) {
mStartMillis = mEventCursor.getLong(EVENT_INDEX_DTSTART);
mEndMillis = mEventCursor.getLong(EVENT_INDEX_DTEND);
if (mEndMillis == 0) {
String duration = mEventCursor.getString(EVENT_INDEX_DURATION);
if (!TextUtils.isEmpty(duration)) {
try {
Duration d = new Duration();
d.parse(duration);
long endMillis = mStartMillis + d.getMillis();
if (endMillis >= mStartMillis) {
mEndMillis = endMillis;
} else {
Log.d(TAG, "Invalid duration string: " + duration);
}
} catch (DateException e) {
Log.d(TAG, "Error parsing duration string " + duration, e);
}
}
if (mEndMillis == 0) {
mEndMillis = mStartMillis;
}
}
}
mAllDay = mEventCursor.getInt(EVENT_INDEX_ALL_DAY) != 0;
String location = mEventCursor.getString(EVENT_INDEX_EVENT_LOCATION);
String description = mEventCursor.getString(EVENT_INDEX_DESCRIPTION);
String rRule = mEventCursor.getString(EVENT_INDEX_RRULE);
String eventTimezone = mEventCursor.getString(EVENT_INDEX_EVENT_TIMEZONE);
mHeadlines.setBackgroundColor(mCurrentColor);
// What
if (eventName != null) {
setTextCommon(view, R.id.title, eventName);
}
// When
// Set the date and repeats (if any)
String localTimezone = Utils.getTimeZone(mActivity, mTZUpdater);
Resources resources = context.getResources();
String displayedDatetime = Utils.getDisplayedDatetime(mStartMillis, mEndMillis, System.currentTimeMillis(), localTimezone, mAllDay, context);
String displayedTimezone = null;
if (!mAllDay) {
displayedTimezone = Utils.getDisplayedTimezone(mStartMillis, localTimezone, eventTimezone);
}
// Display the datetime. Make the timezone (if any) transparent.
if (displayedTimezone == null) {
setTextCommon(view, R.id.when_datetime, displayedDatetime);
} else {
int timezoneIndex = displayedDatetime.length();
displayedDatetime += " " + displayedTimezone;
SpannableStringBuilder sb = new SpannableStringBuilder(displayedDatetime);
ForegroundColorSpan transparentColorSpan = new ForegroundColorSpan(resources.getColor(R.color.event_info_headline_transparent_color));
sb.setSpan(transparentColorSpan, timezoneIndex, displayedDatetime.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
setTextCommon(view, R.id.when_datetime, sb);
}
// Display the repeat string (if any)
String repeatString = null;
if (!TextUtils.isEmpty(rRule)) {
EventRecurrence eventRecurrence = new EventRecurrence();
eventRecurrence.parse(rRule);
Time date = new Time(localTimezone);
date.set(mStartMillis);
if (mAllDay) {
date.timezone = Time.TIMEZONE_UTC;
}
eventRecurrence.setStartDate(date);
repeatString = EventRecurrenceFormatter.getRepeatString(mContext, resources, eventRecurrence, true);
}
if (repeatString == null) {
view.findViewById(R.id.when_repeat).setVisibility(View.GONE);
} else {
setTextCommon(view, R.id.when_repeat, repeatString);
}
// Where
if (location == null || location.trim().length() == 0) {
setVisibilityCommon(view, R.id.where, View.GONE);
} else {
final TextView textView = mWhere;
if (textView != null) {
textView.setAutoLinkMask(0);
textView.setText(location.trim());
try {
textView.setText(Utils.extendedLinkify(textView.getText().toString(), true));
// Linkify.addLinks() sets the TextView movement method if it finds any links.
// We must do the same here, in case linkify by itself did not find any.
// (This is cloned from Linkify.addLinkMovementMethod().)
MovementMethod mm = textView.getMovementMethod();
if ((mm == null) || !(mm instanceof LinkMovementMethod)) {
if (textView.getLinksClickable()) {
textView.setMovementMethod(LinkMovementMethod.getInstance());
}
}
} catch (Exception ex) {
// unexpected
Log.e(TAG, "Linkification failed", ex);
}
textView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
try {
return v.onTouchEvent(event);
} catch (ActivityNotFoundException e) {
// ignore
return true;
}
}
});
}
}
// Description
if (description != null && description.length() != 0) {
mDesc.setText(description);
}
// Launch Custom App
if (Utils.isJellybeanOrLater()) {
updateCustomAppButton();
}
}
Aggregations