Last active
December 5, 2017 17:31
-
-
Save efemoney/e184e67f1ae118394037d7985c8a18b5 to your computer and use it in GitHub Desktop.
This file contains 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 class PagerAdapter extends android.support.v4.view.PagerAdapter { | |
// ... | |
private final Pattern patternBullet = Pattern.compile("[a-zA-Z0-9 ]+\\n"); | |
private final Pattern patternLine = Pattern.compile("~"); | |
private final String[] descriptions = new String[]{ | |
"Unlimited Albums\n~\n" + | |
"5 Customer Profiles\n~\n" + | |
"Save customers full body measurement\n~\n", | |
"Unlimited Albums\n~\n" + | |
"50 Customer Profiles\n~\n" + | |
"Add watermark when sharing photos\n~\n" + | |
"Save customers full body measurement\n~\n", | |
"Unlimited Albums\n~\n" + | |
"Unlimited Customer Profiles\n~\n" + | |
"Add watermark when sharing photos\n~\n" + | |
"Save customers full body measurement\n~\n" + | |
"Custom measurement templates\n~\n" | |
}; | |
private void populate(Context context, SubscriptionCardBinding binding, int position) { | |
// ... | |
binding.subDesc.setText(getSpannedDesc(context, descriptions[position])); | |
// ... | |
} | |
private CharSequence getSpannedDesc(Context context, String desc) { | |
SpannableStringBuilder spanned = new SpannableStringBuilder(desc); | |
Matcher matcher = patternLine.matcher(desc); | |
while (matcher.find()) { | |
spanned.setSpan(new HorizontalLineSpan(context), | |
matcher.start(), matcher.end(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); | |
} | |
matcher = patternBullet.matcher(desc); | |
while (matcher.find()) { | |
spanned.setSpan(new BulletSpan(context), | |
matcher.start(), matcher.end(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); | |
} | |
return spanned; | |
} | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment