/** Utility for common operation */ @SuppressWarnings("unchecked") private <T extends Format> T getFormatMatching(Class klazz) { for (Format format : mFormatList) { if (klazz.isAssignableFrom(format.getClass())) { return (T) format; } } return null; }
/** * Set text to the view that will be marked up, (note: {@link #setText(CharSequence)} etc is final * and thus cannot be overriden) */ public final void setMarkupText(String text) { SpannableStringBuilder builder = new SpannableStringBuilder(text); for (Format format : mFormatList) { builder = format.format(this, builder); } setText(builder); }
/** Utility for common operation */ private void setTypefaceForClass(Typeface typeface, Class klazz) { Format format = getFormatMatching(klazz); if (format != null) { format.addCustomTypeface(typeface); } }