diff --git a/CalligraphySample/build.gradle b/CalligraphySample/build.gradle index f52a3b9..bdfaf12 100644 --- a/CalligraphySample/build.gradle +++ b/CalligraphySample/build.gradle @@ -6,16 +6,16 @@ android { defaultConfig { applicationId "io.github.inflationx.calligraphy3.sample" - minSdkVersion 14 + minSdkVersion 26 targetSdkVersion 28 versionCode project.ext.versionCodeInt versionName version } buildTypes { - debug { - minifyEnabled true - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' - } +// debug { +// minifyEnabled true +// proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' +// } release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' @@ -27,16 +27,20 @@ android { textOutput 'stdout' textReport System.getenv('CI') == 'true' } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } } dependencies { implementation project(':calligraphy') - implementation 'io.github.inflationx:viewpump:1.0.0' - implementation 'androidx.appcompat:appcompat:1.0.2' + implementation 'io.github.inflationx:viewpump:2.0.3' + implementation 'androidx.appcompat:appcompat:1.3.1' - implementation 'com.jakewharton:butterknife:9.0.0-rc1' - annotationProcessor 'com.jakewharton:butterknife-compiler:9.0.0-rc1' + implementation 'com.jakewharton:butterknife:10.2.3' + annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.3' - debugImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.6.2' - releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.6.2' + debugImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.6.3' + releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.6.3' } diff --git a/CalligraphySample/src/main/java/io/github/inflationx/calligraphy3/sample/CalligraphyApplication.java b/CalligraphySample/src/main/java/io/github/inflationx/calligraphy3/sample/CalligraphyApplication.java index 97b0a5b..8a87f54 100644 --- a/CalligraphySample/src/main/java/io/github/inflationx/calligraphy3/sample/CalligraphyApplication.java +++ b/CalligraphySample/src/main/java/io/github/inflationx/calligraphy3/sample/CalligraphyApplication.java @@ -5,6 +5,7 @@ import io.github.inflationx.calligraphy3.CalligraphyConfig; import io.github.inflationx.calligraphy3.CalligraphyInterceptor; import io.github.inflationx.calligraphy3.FontMapper; +import io.github.inflationx.calligraphy3.TypefaceUtils; import io.github.inflationx.viewpump.ViewPump; /** @@ -19,7 +20,8 @@ public void onCreate() { ViewPump.init(ViewPump.builder() .addInterceptor(new CalligraphyInterceptor( new CalligraphyConfig.Builder() - .setDefaultFontPath("fonts/Roboto-ThinItalic.ttf") +// .setDefaultFontPath("fonts/Roboto-ThinItalic.ttf") + .setDefaultTypeface(TypefaceUtils.load(getAssets(), "fonts/Roboto-ThinItalic.ttf")) .setFontAttrId(R.attr.fontPath) .setFontMapper(new FontMapper() { @Override diff --git a/build.gradle b/build.gradle index 5d24669..0926211 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ buildscript { repositories { google() - jcenter() + mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:3.2.1' @@ -12,7 +12,7 @@ allprojects { repositories { google() mavenLocal() - jcenter() + mavenCentral() } // Is Release Build? version = getProperty('VERSION_NAME') diff --git a/calligraphy/build.gradle b/calligraphy/build.gradle index e5e54a5..b4d0bd0 100644 --- a/calligraphy/build.gradle +++ b/calligraphy/build.gradle @@ -28,8 +28,8 @@ android { } dependencies { - compileOnly 'androidx.appcompat:appcompat:1.0.2' - implementation 'io.github.inflationx:viewpump:1.0.0' + compileOnly 'androidx.appcompat:appcompat:1.3.1' + implementation 'io.github.inflationx:viewpump:2.0.3' testImplementation 'androidx.annotation:annotation:1.0.0' testImplementation 'androidx.test:runner:1.1.0' diff --git a/calligraphy/src/main/java/io/github/inflationx/calligraphy3/Calligraphy.java b/calligraphy/src/main/java/io/github/inflationx/calligraphy3/Calligraphy.java index caf8b66..8e1cd0d 100644 --- a/calligraphy/src/main/java/io/github/inflationx/calligraphy3/Calligraphy.java +++ b/calligraphy/src/main/java/io/github/inflationx/calligraphy3/Calligraphy.java @@ -179,6 +179,9 @@ void onViewCreatedInternal(View view, final Context context, AttributeSet attrs) } private Typeface getDefaultTypeface(Context context, String fontPath) { + if (mCalligraphyConfig.getFontTypeface() != null) { + return mCalligraphyConfig.getFontTypeface(); + } if (TextUtils.isEmpty(fontPath)) { fontPath = mCalligraphyConfig.getFontPath(); } diff --git a/calligraphy/src/main/java/io/github/inflationx/calligraphy3/CalligraphyConfig.java b/calligraphy/src/main/java/io/github/inflationx/calligraphy3/CalligraphyConfig.java index bc5095e..6786112 100644 --- a/calligraphy/src/main/java/io/github/inflationx/calligraphy3/CalligraphyConfig.java +++ b/calligraphy/src/main/java/io/github/inflationx/calligraphy3/CalligraphyConfig.java @@ -1,5 +1,6 @@ package io.github.inflationx.calligraphy3; +import android.graphics.Typeface; import android.os.Build; import android.text.TextUtils; @@ -81,6 +82,10 @@ private static void addAppCompatViews() { * The default Font Path if nothing else is setup. */ private final String mFontPath; + /** + * The default Font Path if nothing else is setup. + */ + private final Typeface mFontTypeface; /** * Default Font Path Attr Id to lookup */ @@ -106,6 +111,7 @@ private static void addAppCompatViews() { private CalligraphyConfig(Builder builder) { mIsFontSet = builder.isFontSet; mFontPath = builder.fontAssetPath; + mFontTypeface = builder.fontTypeface; mAttrId = builder.attrId; mCustomViewTypefaceSupport = builder.customViewTypefaceSupport; final Map, Integer> tempMap = new HashMap<>(DEFAULT_STYLES); @@ -122,6 +128,13 @@ public String getFontPath() { return mFontPath; } + /** + * @return mFontTypeface for text views might be null + */ + public Typeface getFontTypeface() { + return mFontTypeface; + } + /** * @return true if set, false if null|empty */ @@ -173,6 +186,10 @@ public static class Builder { * The default fontPath */ private String fontAssetPath = null; + /** + * The default Typeface + */ + private Typeface fontTypeface = null; /** * Additional Class Styles. Can be empty. */ @@ -198,14 +215,31 @@ public Builder setFontAttrId(int fontAssetAttrId) { * * @param defaultFontAssetPath a path to a font file in the assets folder, e.g. "fonts/Roboto-light.ttf", * passing null will default to the device font-family. + * This clears default font typeface. * @return this builder. */ public Builder setDefaultFontPath(String defaultFontAssetPath) { this.isFontSet = !TextUtils.isEmpty(defaultFontAssetPath); + this.fontTypeface = null; this.fontAssetPath = defaultFontAssetPath; return this; } + /** + * Set the default font if you don't define one else where in your styles. + * + * @param defaultFontTypeface a Typeface object, + * passing null will default to the device font-family. + * This clears default font asset path. + * @return this builder. + */ + public Builder setDefaultTypeface(Typeface defaultFontTypeface) { + this.isFontSet = defaultFontTypeface != null; + this.fontAssetPath = null; + this.fontTypeface = defaultFontTypeface; + return this; + } + /** * Add a custom style to get looked up. If you use a custom class that has a parent style * which is not part of the default android styles you will need to add it here. @@ -243,7 +277,7 @@ public Builder setFontMapper(FontMapper fontMapper) { } public CalligraphyConfig build() { - this.isFontSet = !TextUtils.isEmpty(fontAssetPath); + this.isFontSet = !TextUtils.isEmpty(fontAssetPath) || this.fontTypeface != null; return new CalligraphyConfig(this); } } diff --git a/calligraphy/src/main/java/io/github/inflationx/calligraphy3/CalligraphyUtils.java b/calligraphy/src/main/java/io/github/inflationx/calligraphy3/CalligraphyUtils.java index 605b5f9..3e20e34 100644 --- a/calligraphy/src/main/java/io/github/inflationx/calligraphy3/CalligraphyUtils.java +++ b/calligraphy/src/main/java/io/github/inflationx/calligraphy3/CalligraphyUtils.java @@ -115,14 +115,18 @@ static boolean applyFontToTextView(final Context context, final TextView textVie return applyFontToTextView(textView, typeface, deferred); } - static void applyFontToTextView(final Context context, final TextView textView, final CalligraphyConfig config) { - applyFontToTextView(context, textView, config, false); + static boolean applyFontToTextView(final Context context, final TextView textView, final CalligraphyConfig config) { + return applyFontToTextView(context, textView, config, false); } - static void applyFontToTextView(final Context context, final TextView textView, final CalligraphyConfig config, boolean deferred) { - if (context == null || textView == null || config == null) return; - if (!config.isFontSet()) return; - applyFontToTextView(context, textView, config.getFontPath(), deferred); + static boolean applyFontToTextView(final Context context, final TextView textView, final CalligraphyConfig config, boolean deferred) { + if (textView == null || config == null) return false; + if (!config.isFontSet()) return false; + if (config.getFontTypeface() != null) { + return applyFontToTextView(textView, config.getFontTypeface(), deferred); + } else { + return applyFontToTextView(context, textView, config.getFontPath(), deferred); + } } /** @@ -134,16 +138,16 @@ static void applyFontToTextView(final Context context, final TextView textView, * @param textViewFont nullable, will use Default Config if null or fails to find the * defined font. */ - public static void applyFontToTextView(final Context context, final TextView textView, final CalligraphyConfig config, final String textViewFont) { - applyFontToTextView(context, textView, config, textViewFont, false); + public static boolean applyFontToTextView(final Context context, final TextView textView, final CalligraphyConfig config, final String textViewFont) { + return applyFontToTextView(context, textView, config, textViewFont, false); } - static void applyFontToTextView(final Context context, final TextView textView, final CalligraphyConfig config, final String textViewFont, boolean deferred) { - if (context == null || textView == null || config == null) return; + static boolean applyFontToTextView(final Context context, final TextView textView, final CalligraphyConfig config, final String textViewFont, boolean deferred) { + if (context == null || textView == null || config == null) return false; if (!TextUtils.isEmpty(textViewFont) && applyFontToTextView(context, textView, textViewFont, deferred)) { - return; + return false; } - applyFontToTextView(context, textView, config, deferred); + return applyFontToTextView(context, textView, config, deferred); } /**