Search in sources :

Example 51 with ForegroundColorSpan

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);
}
Also used : ForegroundColorSpan(android.text.style.ForegroundColorSpan) StyleSpan(android.text.style.StyleSpan) SpannableStringBuilder(android.text.SpannableStringBuilder) TypefaceSpan(android.text.style.TypefaceSpan)

Example 52 with ForegroundColorSpan

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;
}
Also used : SpannableString(android.text.SpannableString) ForegroundColorSpan(android.text.style.ForegroundColorSpan)

Example 53 with ForegroundColorSpan

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;
}
Also used : ForegroundColorSpan(android.text.style.ForegroundColorSpan) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 54 with ForegroundColorSpan

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));
    }
}
Also used : ForegroundColorSpan(android.text.style.ForegroundColorSpan) TypefaceSpan(android.text.style.TypefaceSpan)

Example 55 with ForegroundColorSpan

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();
    }
}
Also used : Context(android.content.Context) OnTouchListener(android.view.View.OnTouchListener) ForegroundColorSpan(android.text.style.ForegroundColorSpan) LinkMovementMethod(android.text.method.LinkMovementMethod) Duration(com.android.calendarcommon2.Duration) Time(android.text.format.Time) ScrollView(android.widget.ScrollView) View(android.view.View) AdapterView(android.widget.AdapterView) AttendeesView(com.android.calendar.event.AttendeesView) TextView(android.widget.TextView) IOException(java.io.IOException) ActivityNotFoundException(android.content.ActivityNotFoundException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) DateException(com.android.calendarcommon2.DateException) MotionEvent(android.view.MotionEvent) EventRecurrence(com.android.calendarcommon2.EventRecurrence) ActivityNotFoundException(android.content.ActivityNotFoundException) LinkMovementMethod(android.text.method.LinkMovementMethod) MovementMethod(android.text.method.MovementMethod) DateException(com.android.calendarcommon2.DateException) TextView(android.widget.TextView) Resources(android.content.res.Resources) SpannableStringBuilder(android.text.SpannableStringBuilder)

Aggregations

ForegroundColorSpan (android.text.style.ForegroundColorSpan)157 SpannableStringBuilder (android.text.SpannableStringBuilder)57 SpannableString (android.text.SpannableString)50 StyleSpan (android.text.style.StyleSpan)25 TextView (android.widget.TextView)25 ImageSpan (android.text.style.ImageSpan)23 Spannable (android.text.Spannable)22 RelativeSizeSpan (android.text.style.RelativeSizeSpan)22 View (android.view.View)22 BackgroundColorSpan (android.text.style.BackgroundColorSpan)19 TypefaceSpan (android.text.style.TypefaceSpan)16 StrikethroughSpan (android.text.style.StrikethroughSpan)14 UnderlineSpan (android.text.style.UnderlineSpan)13 Drawable (android.graphics.drawable.Drawable)12 CharacterStyle (android.text.style.CharacterStyle)11 EditText (android.widget.EditText)11 AbsoluteSizeSpan (android.text.style.AbsoluteSizeSpan)10 SuperscriptSpan (android.text.style.SuperscriptSpan)8 LinearLayout (android.widget.LinearLayout)8 URLSpan (android.text.style.URLSpan)7