Search in sources :

Example 16 with RelativeSizeSpan

use of android.text.style.RelativeSizeSpan in project TextJustify-Android by bluejamesbond.

the class LongFormattedTextTest method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ArticleBuilder ab = new ArticleBuilder().append(testName, false, new RelativeSizeSpan(2f), new StyleSpan(Typeface.BOLD), new LeftSpan()).append("<font color=0xFFC801>Justin Worland</font><font color=0x888888> @justinworland  Oct. 25, 2014</font>", false, new RelativeSizeSpan(0.8f), new StyleSpan(Typeface.BOLD)).append("<font color=0x888888>Updated: Oct. 25, 2014 2:34 PM</font>".toUpperCase(), true, new RelativeSizeSpan(0.6f), new StyleSpan(Typeface.BOLD)).append("State health department staff will be on the ground at state airports", true, new RelativeSizeSpan(1.2f), new StyleSpan(Typeface.BOLD), new StyleSpan(Typeface.ITALIC));
    for (int i = 0; i < 15; i++) ab.append("Healthcare workers returning to New York or New Jersey after treating Ebola patients in West Africa will be placed under a mandatory quarantine, officials announced Friday, one day after a Doctors Without Borders doctor was diagnosed with the virus in New York City. Illinois announced a similar policy Saturday, meaning it will be enforced in states with three of the five airports through which passengers traveling from the Ebola-stricken West African countries must enter the United States.", true, new RelativeSizeSpan(1f), new JustifiedSpan()).append("N.J. Gov. Chris Christie and N.Y. Gov. Andrew Cuomo made the announcement as part of a broader procedural plan to help protect the densely packed, highly populated area from any further spread of the disease.", true, new RelativeSizeSpan(0.8f), new JustifiedSpan(), new MyQuoteSpan(0xFFFFC801)).append("“Since taking office, I have erred on the side of caution when it comes to the safety and protection of New Yorkers, and the current situation regarding Ebola will be no different,” Gov. Cuomo said. “The steps New York and New Jersey are taking today will strengthen our safeguards to protect our residents against this disease and help ensure those that may be infected by Ebola are treated with the highest precautions.”", true, new RelativeSizeSpan(1f), new CenterSpan()).append("New York and New Jersey state health department staff will be present on the ground at John F. Kennedy International Airport in New York and Newark Liberty Airport in New Jersey. In addition to implementing the mandatory quarantine of health care workers and others who had direct contact with Ebola patients, health department officials in each state will determine whether others should travelers should be hospitalized or quarantined.", true, new RelativeSizeSpan(1f), new JustifiedSpan()).append("“The announcements mark a dramatic escalation in measures designed to prevent the spread of Ebola in the United States. Previously, only individuals with symptoms of Ebola would be quarantined upon entry to the U.S. under a federal rule from the Centers for Diseases Control and the Department of Homeland Security.”", true, new RelativeSizeSpan(1f), new RightSpan());
    addDocumentView(ab, DocumentView.FORMATTED_TEXT);
}
Also used : JustifiedSpan(com.bluejamesbond.text.style.JustifiedSpan) LeftSpan(com.bluejamesbond.text.style.LeftSpan) StyleSpan(android.text.style.StyleSpan) MyQuoteSpan(com.bluejamesbond.text.sample.helper.MyQuoteSpan) ArticleBuilder(com.bluejamesbond.text.util.ArticleBuilder) RelativeSizeSpan(android.text.style.RelativeSizeSpan) CenterSpan(com.bluejamesbond.text.style.CenterSpan) RightSpan(com.bluejamesbond.text.style.RightSpan)

Example 17 with RelativeSizeSpan

use of android.text.style.RelativeSizeSpan in project TextJustify-Android by bluejamesbond.

the class RTLTest method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addDocumentView(new ArticleBuilder().append(testName, false, new RelativeSizeSpan(2f), new StyleSpan(Typeface.BOLD), new RightSpan()).append("<font color=0xFFC801>Justin Worland</font><font color=0x888888> @justinworland  Oct. 25, 2014</font>", false, new RelativeSizeSpan(0.8f), new StyleSpan(Typeface.BOLD)).append("<font color=0x888888>Updated: Oct. 25, 2014 2:34 PM</font>".toUpperCase(), true, new RelativeSizeSpan(0.6f), new StyleSpan(Typeface.BOLD)).append("State health department staff will be on the ground at state airports", true, new RelativeSizeSpan(1.2f), new StyleSpan(Typeface.BOLD), new StyleSpan(Typeface.ITALIC)).append("Healthcare workers returning to New York or New Jersey after treating Ebola patients in West Africa will be placed under a mandatory quarantine, officials announced Friday, one day after a Doctors Without Borders doctor was diagnosed with the virus in New York City. Illinois announced a similar policy Saturday, meaning it will be enforced in states with three of the five airports through which passengers traveling from the Ebola-stricken West African countries must enter the United States.", true, new RelativeSizeSpan(1f), new RightSpan()).append("N.J. Gov. Chris Christie and N.Y. Gov. Andrew Cuomo made the announcement as part of a broader procedural plan to help protect the densely packed, highly populated area from any further spread of the disease.", true, new RelativeSizeSpan(1f), new RightSpan()).append("“Since taking office, I have erred on the side of caution when it comes to the safety and protection of New Yorkers, and the current situation regarding Ebola will be no different,” Gov. Cuomo said. “The steps New York and New Jersey are taking today will strengthen our safeguards to protect our residents against this disease and help ensure those that may be infected by Ebola are treated with the highest precautions.”", true, new RelativeSizeSpan(1f), new JustifiedSpan(), new StyleSpan(Typeface.ITALIC)).append("New York and New Jersey state health department staff will be present on the ground at John F. Kennedy International Airport in New York and Newark Liberty Airport in New Jersey. In addition to implementing the mandatory quarantine of health care workers and others who had direct contact with Ebola patients, health department officials in each state will determine whether others should travelers should be hospitalized or quarantined.", true, new RelativeSizeSpan(1f), new JustifiedSpan(), new StyleSpan(Typeface.ITALIC)).append("“The announcements mark a dramatic escalation in measures designed to prevent the spread of Ebola in the United States. Previously, only individuals with symptoms of Ebola would be quarantined upon entry to the U.S. under a federal rule from the Centers for Diseases Control and the Department of Homeland Security.”", false, new RelativeSizeSpan(1f), new RightSpan()), DocumentView.FORMATTED_TEXT, true);
}
Also used : JustifiedSpan(com.bluejamesbond.text.style.JustifiedSpan) StyleSpan(android.text.style.StyleSpan) ArticleBuilder(com.bluejamesbond.text.util.ArticleBuilder) RelativeSizeSpan(android.text.style.RelativeSizeSpan) RightSpan(com.bluejamesbond.text.style.RightSpan)

Example 18 with RelativeSizeSpan

use of android.text.style.RelativeSizeSpan in project WordPress-Android by wordpress-mobile.

the class HtmlToSpannedConverter method endHeader.

private static void endHeader(SpannableStringBuilder text) {
    int len = text.length();
    Object obj = getLast(text, Header.class);
    int where = text.getSpanStart(obj);
    text.removeSpan(obj);
    // Back off not to change only the text, not the blank line.
    while (len > where && text.charAt(len - 1) == '\n') {
        len--;
    }
    if (where != len) {
        Header h = (Header) obj;
        text.setSpan(new RelativeSizeSpan(HEADER_SIZES[h.mLevel]), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        text.setSpan(new StyleSpan(Typeface.BOLD), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
}
Also used : StyleSpan(android.text.style.StyleSpan) RelativeSizeSpan(android.text.style.RelativeSizeSpan)

Example 19 with RelativeSizeSpan

use of android.text.style.RelativeSizeSpan in project WordPress-Android by wordpress-mobile.

the class HtmlStyleUtils method applySpansByRegex.

/**
     * Applies styles to {@code content} from {@code start} to {@code end}, based on rule {@code regex}.
     * @param content the Spannable to apply style rules to
     * @param start the index in {@code content} to start styling from
     * @param end the index in {@code content} to style until
     * @param regex the pattern to match for styling
     */
private static void applySpansByRegex(Spannable content, int start, int end, String regex) {
    if (content == null || start < 0 || end < 0 || start > content.length() || end > content.length() || start >= end) {
        AppLog.d(AppLog.T.EDITOR, "applySpansByRegex() received invalid input");
        return;
    }
    Pattern pattern = Pattern.compile(regex);
    Matcher matcher = pattern.matcher(content.subSequence(start, end));
    while (matcher.find()) {
        int matchStart = matcher.start() + start;
        int matchEnd = matcher.end() + start;
        switch(regex) {
            case REGEX_HTML_TAGS:
                content.setSpan(new ForegroundColorSpan(TAG_COLOR), matchStart, matchEnd, SPANNABLE_FLAGS);
                break;
            case REGEX_HTML_ATTRIBUTES:
                content.setSpan(new ForegroundColorSpan(ATTRIBUTE_COLOR), matchStart, matchEnd, SPANNABLE_FLAGS);
                break;
            case REGEX_HTML_COMMENTS:
                content.setSpan(new ForegroundColorSpan(ATTRIBUTE_COLOR), matchStart, matchEnd, SPANNABLE_FLAGS);
                content.setSpan(new StyleSpan(Typeface.ITALIC), matchStart, matchEnd, SPANNABLE_FLAGS);
                content.setSpan(new RelativeSizeSpan(0.75f), matchStart, matchEnd, SPANNABLE_FLAGS);
                break;
            case REGEX_HTML_ENTITIES:
                content.setSpan(new ForegroundColorSpan(TAG_COLOR), matchStart, matchEnd, SPANNABLE_FLAGS);
                content.setSpan(new StyleSpan(Typeface.BOLD), matchStart, matchEnd, SPANNABLE_FLAGS);
                content.setSpan(new RelativeSizeSpan(0.75f), matchStart, matchEnd, SPANNABLE_FLAGS);
                break;
        }
    }
}
Also used : Pattern(java.util.regex.Pattern) ForegroundColorSpan(android.text.style.ForegroundColorSpan) Matcher(java.util.regex.Matcher) StyleSpan(android.text.style.StyleSpan) RelativeSizeSpan(android.text.style.RelativeSizeSpan)

Example 20 with RelativeSizeSpan

use of android.text.style.RelativeSizeSpan in project android_frameworks_base by DirtyUnicorns.

the class Clock method getSmallTime.

private final CharSequence getSmallTime() {
    Context context = getContext();
    boolean is24 = DateFormat.is24HourFormat(context, ActivityManager.getCurrentUser());
    LocaleData d = LocaleData.get(context.getResources().getConfiguration().locale);
    final char MAGIC1 = '';
    final char MAGIC2 = '';
    SimpleDateFormat sdf;
    String format = mShowSeconds ? is24 ? d.timeFormat_Hms : d.timeFormat_hms : is24 ? d.timeFormat_Hm : d.timeFormat_hm;
    if (!format.equals(mClockFormatString)) {
        mContentDescriptionFormat = new SimpleDateFormat(format);
        /*
             * Search for an unquoted "a" in the format string, so we can
             * add dummy characters around it to let us find it again after
             * formatting and change its size.
             */
        if (mAmPmStyle != AM_PM_STYLE_NORMAL) {
            int a = -1;
            boolean quoted = false;
            for (int i = 0; i < format.length(); i++) {
                char c = format.charAt(i);
                if (c == '\'') {
                    quoted = !quoted;
                }
                if (!quoted && c == 'a') {
                    a = i;
                    break;
                }
            }
            if (a >= 0) {
                // Move a back so any whitespace before AM/PM is also in the alternate size.
                final int b = a;
                while (a > 0 && Character.isWhitespace(format.charAt(a - 1))) {
                    a--;
                }
                format = format.substring(0, a) + MAGIC1 + format.substring(a, b) + "a" + MAGIC2 + format.substring(b + 1);
            }
        }
        mClockFormat = sdf = new SimpleDateFormat(format);
        mClockFormatString = format;
    } else {
        sdf = mClockFormat;
    }
    CharSequence dateString = null;
    String result = "";
    String timeResult = sdf.format(mCalendar.getTime());
    String dateResult = "";
    int clockDatePosition = Settings.System.getInt(getContext().getContentResolver(), Settings.System.STATUSBAR_CLOCK_DATE_POSITION, 0);
    if (mClockDateDisplay != CLOCK_DATE_DISPLAY_GONE) {
        Date now = new Date();
        String clockDateFormat = Settings.System.getString(getContext().getContentResolver(), Settings.System.STATUSBAR_CLOCK_DATE_FORMAT);
        if (clockDateFormat == null || clockDateFormat.isEmpty()) {
            // Set dateString to short uppercase Weekday (Default for AOKP) if empty
            dateString = DateFormat.format("EEE", now);
        } else {
            dateString = DateFormat.format(clockDateFormat, now);
        }
        if (mClockDateStyle == CLOCK_DATE_STYLE_LOWERCASE) {
            // When Date style is small, convert date to uppercase
            dateResult = dateString.toString().toLowerCase();
        } else if (mClockDateStyle == CLOCK_DATE_STYLE_UPPERCASE) {
            dateResult = dateString.toString().toUpperCase();
        } else {
            dateResult = dateString.toString();
        }
        result = (clockDatePosition == STYLE_DATE_LEFT) ? dateResult + " " + timeResult : timeResult + " " + dateResult;
    } else {
        // No date, just show time
        result = timeResult;
    }
    SpannableStringBuilder formatted = new SpannableStringBuilder(result);
    if (mClockDateDisplay != CLOCK_DATE_DISPLAY_NORMAL) {
        if (dateString != null) {
            int dateStringLen = dateString.length();
            int timeStringOffset = (clockDatePosition == STYLE_DATE_RIGHT) ? timeResult.length() + 1 : 0;
            if (mClockDateDisplay == CLOCK_DATE_DISPLAY_GONE) {
                formatted.delete(0, dateStringLen);
            } else {
                if (mClockDateDisplay == CLOCK_DATE_DISPLAY_SMALL) {
                    CharacterStyle style = new RelativeSizeSpan(0.7f);
                    formatted.setSpan(style, timeStringOffset, timeStringOffset + dateStringLen, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
                }
            }
        }
    }
    if (mAmPmStyle != AM_PM_STYLE_NORMAL) {
        int magic1 = result.indexOf(MAGIC1);
        int magic2 = result.indexOf(MAGIC2);
        if (magic1 >= 0 && magic2 > magic1) {
            if (mAmPmStyle == AM_PM_STYLE_GONE) {
                formatted.delete(magic1, magic2 + 1);
            } else {
                if (mAmPmStyle == AM_PM_STYLE_SMALL) {
                    CharacterStyle style = new RelativeSizeSpan(0.7f);
                    formatted.setSpan(style, magic1, magic2, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
                }
                formatted.delete(magic2, magic2 + 1);
                formatted.delete(magic1, magic1 + 1);
            }
        }
    }
    return formatted;
}
Also used : Context(android.content.Context) LocaleData(libcore.icu.LocaleData) RelativeSizeSpan(android.text.style.RelativeSizeSpan) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) SpannableStringBuilder(android.text.SpannableStringBuilder) CharacterStyle(android.text.style.CharacterStyle)

Aggregations

RelativeSizeSpan (android.text.style.RelativeSizeSpan)63 StyleSpan (android.text.style.StyleSpan)32 ForegroundColorSpan (android.text.style.ForegroundColorSpan)21 SpannableString (android.text.SpannableString)18 SpannableStringBuilder (android.text.SpannableStringBuilder)17 CharacterStyle (android.text.style.CharacterStyle)16 AbsoluteSizeSpan (android.text.style.AbsoluteSizeSpan)10 SuperscriptSpan (android.text.style.SuperscriptSpan)10 TypefaceSpan (android.text.style.TypefaceSpan)10 JustifiedSpan (com.bluejamesbond.text.style.JustifiedSpan)9 ArticleBuilder (com.bluejamesbond.text.util.ArticleBuilder)9 SubscriptSpan (android.text.style.SubscriptSpan)8 ImageSpan (android.text.style.ImageSpan)7 StrikethroughSpan (android.text.style.StrikethroughSpan)7 UnderlineSpan (android.text.style.UnderlineSpan)7 LeftSpan (com.bluejamesbond.text.style.LeftSpan)7 SimpleDateFormat (java.text.SimpleDateFormat)7 Context (android.content.Context)6 BackgroundColorSpan (android.text.style.BackgroundColorSpan)6 MyQuoteSpan (com.bluejamesbond.text.sample.helper.MyQuoteSpan)6