From 3beb1259b928de7f9bb869dea21546bdd911be44 Mon Sep 17 00:00:00 2001 From: Basti Destruction Date: Tue, 5 Dec 2017 21:09:17 +0100 Subject: [PATCH 1/2] add FontFilenameProvider --- .../sharp/FontFilenameProvider.java | 8 +++++++ .../main/java/com/pixplicity/sharp/Sharp.java | 22 ++++++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 library/src/main/java/com/pixplicity/sharp/FontFilenameProvider.java diff --git a/library/src/main/java/com/pixplicity/sharp/FontFilenameProvider.java b/library/src/main/java/com/pixplicity/sharp/FontFilenameProvider.java new file mode 100644 index 0000000..1a68352 --- /dev/null +++ b/library/src/main/java/com/pixplicity/sharp/FontFilenameProvider.java @@ -0,0 +1,8 @@ +package com.pixplicity.sharp; + +import android.support.annotation.Nullable; + +public interface FontFilenameProvider { + @Nullable + String getFontFilename(String family, String style, String weight); +} diff --git a/library/src/main/java/com/pixplicity/sharp/Sharp.java b/library/src/main/java/com/pixplicity/sharp/Sharp.java index 859b777..470dea5 100644 --- a/library/src/main/java/com/pixplicity/sharp/Sharp.java +++ b/library/src/main/java/com/pixplicity/sharp/Sharp.java @@ -99,6 +99,8 @@ public abstract class Sharp { private OnSvgElementListener mOnElementListener; private AssetManager mAssetManager; + private FontFilenameProvider mFontFilenameProvider; + enum Unit { PERCENT("%"), PT("pt"), @@ -292,6 +294,12 @@ public Sharp setOnElementListener(OnSvgElementListener onElementListener) { return this; } + @SuppressWarnings("unused") + public Sharp setFontFilenameProvider(FontFilenameProvider fontFilenameProvider) { + mFontFilenameProvider = fontFilenameProvider; + return this; + } + protected abstract InputStream getInputStream() throws IOException; protected abstract void close(InputStream inputStream) throws IOException; @@ -1416,7 +1424,7 @@ private boolean doText(Attributes atts, Properties props, Paint paint) { if (fontSize != null) { paint.setTextSize(fontSize); } - Typeface typeface = setTypeface(atts, props, mSharp.getAssetManager(), paint.getTypeface()); + Typeface typeface = setTypeface(atts, props, mSharp.getAssetManager(), paint.getTypeface(), mSharp.mFontFilenameProvider); if (typeface != null) { paint.setTypeface(typeface); } @@ -2273,7 +2281,7 @@ private Align getTextAlign(Attributes atts) { } } - private Typeface setTypeface(Attributes atts, Properties props, AssetManager assetManager, Typeface defaultTypeface) { + private Typeface setTypeface(Attributes atts, Properties props, AssetManager assetManager, Typeface defaultTypeface, FontFilenameProvider mFontFilenameProvider) { // Prefer a dedicated attribute String family = getStringAttr("font-family", atts); if (family == null) { @@ -2316,7 +2324,15 @@ private Typeface setTypeface(Attributes atts, Properties props, AssetManager ass } } // Compose a filename - String typefaceFile = "fonts/" + family + ".ttf"; + String typefaceFile = null; + if(mFontFilenameProvider != null) { + typefaceFile = mFontFilenameProvider.getFontFilename(family, style, weight); + } + + if(typefaceFile == null) { + typefaceFile = "fonts/" + family + ".ttf"; + } + try { plain = Typeface.createFromAsset(assetManager, typefaceFile); Log.d(TAG, "loaded typeface from assets: " + typefaceFile); From de7031e000b9920acccef04856b6cdccb40655f9 Mon Sep 17 00:00:00 2001 From: Basti Destruction Date: Wed, 28 Mar 2018 21:02:32 +0200 Subject: [PATCH 2/2] update gradle to version 4 --- build.gradle | 4 +++- gradle/wrapper/gradle-wrapper.properties | 4 ++-- library/build.gradle | 12 +++++------ sample-imageview/build.gradle | 21 +++++++++++-------- sample-livewallpaper/build.gradle | 10 ++++----- .../androidify/wallpaper/AssetDatabase.java | 4 ++-- 6 files changed, 30 insertions(+), 25 deletions(-) diff --git a/build.gradle b/build.gradle index b0efcab..c067ffb 100644 --- a/build.gradle +++ b/build.gradle @@ -2,9 +2,10 @@ buildscript { repositories { jcenter() + google() } dependencies { - classpath 'com.android.tools.build:gradle:2.3.0' + classpath 'com.android.tools.build:gradle:3.1.0' // Code checks classpath 'com.noveogroup.android:check:1.2.2' @@ -22,6 +23,7 @@ plugins { allprojects { repositories { jcenter() + google() } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2f735c9..59a9a91 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon Mar 06 12:21:04 EST 2017 +#Wed Mar 28 11:18:42 CEST 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip diff --git a/library/build.gradle b/library/build.gradle index ba3eaf7..319ac56 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -1,12 +1,12 @@ apply plugin: 'com.android.library' android { - compileSdkVersion 25 - buildToolsVersion '25.0.2' + compileSdkVersion 27 + buildToolsVersion '27.0.3' defaultConfig { - minSdkVersion 11 - targetSdkVersion 25 + minSdkVersion 14 + targetSdkVersion 27 } buildTypes { @@ -18,8 +18,8 @@ android { } dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - compile 'com.android.support:support-annotations:25.2.0' + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation 'com.android.support:support-annotations:27.1.0' } apply from: new File('../bintray_upload.gradle') diff --git a/sample-imageview/build.gradle b/sample-imageview/build.gradle index 8bdbf49..8b555b6 100644 --- a/sample-imageview/build.gradle +++ b/sample-imageview/build.gradle @@ -5,15 +5,15 @@ repositories { } android { - compileSdkVersion 25 - buildToolsVersion "25.0.2" + compileSdkVersion 27 + buildToolsVersion '27.0.3' defaultConfig { applicationId "com.pixplicity.sharp.imageviewdemo" minSdkVersion 18 - targetSdkVersion 25 - versionCode 3 - versionName "1.0.2" + targetSdkVersion 27 + versionCode 4 + versionName "1.1.0" } buildTypes { release { @@ -24,10 +24,13 @@ android { } dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - compile 'com.android.support:appcompat-v7:25.2.0' + implementation fileTree(dir: 'libs', include: ['*.jar']) - compile 'com.github.chrisbanes.photoview:library:1.2.3' + implementation('com.github.chrisbanes.photoview:library:1.2.3') { + exclude group: 'com.android.support' + } + + implementation 'com.android.support:appcompat-v7:27.1.0' - compile project(':library') + implementation project(':library') } diff --git a/sample-livewallpaper/build.gradle b/sample-livewallpaper/build.gradle index 09766b9..ec19ef1 100644 --- a/sample-livewallpaper/build.gradle +++ b/sample-livewallpaper/build.gradle @@ -1,13 +1,13 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 25 - buildToolsVersion "25.0.2" + compileSdkVersion 27 + buildToolsVersion '27.0.3' defaultConfig { applicationId "com.larvalabs.androidify.wallpaper" minSdkVersion 18 - targetSdkVersion 25 + targetSdkVersion 27 versionCode 3 versionName "1.0.2" } @@ -20,7 +20,7 @@ android { } dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) + implementation fileTree(dir: 'libs', include: ['*.jar']) - compile project(':library') + implementation project(':library') } diff --git a/sample-livewallpaper/src/main/java/com/larvalabs/androidify/wallpaper/AssetDatabase.java b/sample-livewallpaper/src/main/java/com/larvalabs/androidify/wallpaper/AssetDatabase.java index 26b42c1..3d9276c 100644 --- a/sample-livewallpaper/src/main/java/com/larvalabs/androidify/wallpaper/AssetDatabase.java +++ b/sample-livewallpaper/src/main/java/com/larvalabs/androidify/wallpaper/AssetDatabase.java @@ -211,7 +211,7 @@ public SharpPicture getSVGForAsset(String path, String name, String suffix, Inte try { Sharp sharp = Sharp.loadAsset(assetManager, file); if (searchColor != null) { - sharp.addColorReplacement(searchColor, replaceColor); +// sharp.addColorReplacement(searchColor, replaceColor); } return sharp.getSharpPicture(); } catch (SvgParseException e) { @@ -239,7 +239,7 @@ public SharpPicture getSVGForResource(int resource, Integer searchColor, Integer try { Sharp sharp = Sharp.loadResource(resources, resource); if (searchColor != null) { - sharp.addColorReplacement(searchColor, replaceColor); +// sharp.addColorReplacement(searchColor, replaceColor); } return sharp.getSharpPicture(); } catch (Exception e) {