Created
January 12, 2016 14:39
-
-
Save bholota/4e230bb4a2ed4b810edc to your computer and use it in GitHub Desktop.
Sets regular font face for regex matches and light one for rest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private Spannable setLightHeaderText(String text, String regexPattern) { | |
| final Pattern regPattern = Pattern.compile(regexPattern); | |
| final Matcher matches = regPattern.matcher(text); | |
| final Spannable spannable = new SpannableString(text); | |
| // right now we use first only occurrence if exist | |
| if (!matches.find()) { | |
| final CustomTypeFaceSpan lightSpanStart = new CustomTypeFaceSpan("roboto-light"); | |
| spannable.setSpan(lightSpanStart, 0, text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); | |
| return spannable; | |
| } | |
| spannable.setSpan(new CustomTypeFaceSpan("roboto-light"), 0, text.length(), Spanned.SPAN_COMPOSING); | |
| do { | |
| int start = matches.start(); | |
| int end = matches.end(); | |
| final CustomTypeFaceSpan regularSpan= new CustomTypeFaceSpan("roboto-regular"); | |
| spannable.setSpan(regularSpan, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); | |
| } while (matches.find()); | |
| return spannable; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment