From aa5163a9cbe0864cdb476f353b786163f009f29f Mon Sep 17 00:00:00 2001 From: Anton Malinskiy Date: Mon, 13 Jul 2015 15:25:32 +0300 Subject: [PATCH 1/5] Add ignoreClass to Builder Fixes chrisjenx/Calligraphy#152 --- .../calligraphy/CalligraphyConfig.java | 27 ++++++++++++++++++- .../calligraphy/CalligraphyFactory.java | 2 +- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/calligraphy/src/main/java/uk/co/chrisjenx/calligraphy/CalligraphyConfig.java b/calligraphy/src/main/java/uk/co/chrisjenx/calligraphy/CalligraphyConfig.java index c22148a..6f8fc8c 100644 --- a/calligraphy/src/main/java/uk/co/chrisjenx/calligraphy/CalligraphyConfig.java +++ b/calligraphy/src/main/java/uk/co/chrisjenx/calligraphy/CalligraphyConfig.java @@ -13,7 +13,9 @@ import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; +import java.util.Set; /** * Created by chris on 20/12/2013 @@ -86,6 +88,10 @@ public static CalligraphyConfig get() { * Class Styles. Build from DEFAULT_STYLES and the builder. */ private final Map, Integer> mClassStyleAttributeMap; + /** + * Classes that will not be injected + */ + private final Set> mIgnoredClassSet; protected CalligraphyConfig(Builder builder) { mIsFontSet = builder.isFontSet; @@ -96,6 +102,7 @@ protected CalligraphyConfig(Builder builder) { final Map, Integer> tempMap = new HashMap<>(DEFAULT_STYLES); tempMap.putAll(builder.mStyleClassMap); mClassStyleAttributeMap = Collections.unmodifiableMap(tempMap); + mIgnoredClassSet = Collections.unmodifiableSet(new HashSet<>(builder.mIgnoredClassSet)); } /** @@ -131,6 +138,15 @@ public int getAttrId() { return mAttrId; } + /** + * + * @param viewClass class to be ignored by Calligraphy + * @return true if class should not be injected, false otherwise + */ + public boolean isIgnoredClass(Class viewClass) { + return mIgnoredClassSet.contains(viewClass); + } + public static class Builder { /** * Default AttrID if not set. @@ -160,7 +176,10 @@ public static class Builder { * Additional Class Styles. Can be empty. */ private Map, Integer> mStyleClassMap = new HashMap<>(); - + /** + * Ignored classes. Can be empty. + */ + private Set> mIgnoredClassSet = new HashSet<>(); /** * This defaults to R.attr.fontPath. So only override if you want to use your own attrId. * @@ -257,6 +276,12 @@ public Builder addCustomStyle(final Class styleClass, final return this; } + public Builder ignoreClass(final Class clazz) { + if(clazz == null) return this; + mIgnoredClassSet.add(clazz); + return this; + } + public CalligraphyConfig build() { this.isFontSet = !TextUtils.isEmpty(fontAssetPath); return new CalligraphyConfig(this); diff --git a/calligraphy/src/main/java/uk/co/chrisjenx/calligraphy/CalligraphyFactory.java b/calligraphy/src/main/java/uk/co/chrisjenx/calligraphy/CalligraphyFactory.java index ca45b62..9261af9 100644 --- a/calligraphy/src/main/java/uk/co/chrisjenx/calligraphy/CalligraphyFactory.java +++ b/calligraphy/src/main/java/uk/co/chrisjenx/calligraphy/CalligraphyFactory.java @@ -114,7 +114,7 @@ public View onViewCreated(View view, Context context, AttributeSet attrs) { } void onViewCreatedInternal(View view, final Context context, AttributeSet attrs) { - if (view instanceof TextView) { + if (!CalligraphyConfig.get().isIgnoredClass(view.getClass()) && view instanceof TextView) { // Fast path the setting of TextView's font, means if we do some delayed setting of font, // which has already been set by use we skip this TextView (mainly for inflating custom, // TextView's inside the Toolbar/ActionBar). From c30fa1d94c5e3b6269bb1b0de983b1c445f08ebe Mon Sep 17 00:00:00 2001 From: Anton Malinskiy Date: Mon, 13 Jul 2015 15:25:51 +0300 Subject: [PATCH 2/5] Add sample IconTextView in to CalligraphySample --- CalligraphySample/build.gradle | 2 ++ .../chrisjenx/calligraphy/sample/CalligraphyApplication.java | 3 +++ CalligraphySample/src/main/res/layout/fragment_main.xml | 5 +++++ CalligraphySample/src/main/res/values/strings.xml | 1 + 4 files changed, 11 insertions(+) diff --git a/CalligraphySample/build.gradle b/CalligraphySample/build.gradle index 27e8c65..d3f76fc 100644 --- a/CalligraphySample/build.gradle +++ b/CalligraphySample/build.gradle @@ -32,5 +32,7 @@ dependencies { compile 'com.android.support:support-v4:22.1.1' compile 'com.android.support:appcompat-v7:22.1.1' + compile 'com.malinskiy:materialicons:1.0.2' + compile 'com.jakewharton:butterknife:5.1.2' } diff --git a/CalligraphySample/src/main/java/uk/co/chrisjenx/calligraphy/sample/CalligraphyApplication.java b/CalligraphySample/src/main/java/uk/co/chrisjenx/calligraphy/sample/CalligraphyApplication.java index 7af7454..c6ad02a 100644 --- a/CalligraphySample/src/main/java/uk/co/chrisjenx/calligraphy/sample/CalligraphyApplication.java +++ b/CalligraphySample/src/main/java/uk/co/chrisjenx/calligraphy/sample/CalligraphyApplication.java @@ -2,6 +2,8 @@ import android.app.Application; +import com.malinskiy.materialicons.widget.IconTextView; + import uk.co.chrisjenx.calligraphy.CalligraphyConfig; /** @@ -17,6 +19,7 @@ public void onCreate() { .setDefaultFontPath("fonts/Roboto-ThinItalic.ttf") .setFontAttrId(R.attr.fontPath) .addCustomStyle(TextField.class, R.attr.textFieldStyle) + .ignoreClass(IconTextView.class) .build() ); } diff --git a/CalligraphySample/src/main/res/layout/fragment_main.xml b/CalligraphySample/src/main/res/layout/fragment_main.xml index 4c7bc46..2e2f7ed 100644 --- a/CalligraphySample/src/main/res/layout/fragment_main.xml +++ b/CalligraphySample/src/main/res/layout/fragment_main.xml @@ -106,6 +106,11 @@ android:layout_height="wrap_content" android:text="@string/custom_view_style_text"/> + +