diff --git a/android-iconify/src/main/java/com/joanzapata/android/iconify/Iconify.java b/android-iconify/src/main/java/com/joanzapata/android/iconify/Iconify.java index c9313f8..c781a43 100644 --- a/android-iconify/src/main/java/com/joanzapata/android/iconify/Iconify.java +++ b/android-iconify/src/main/java/com/joanzapata/android/iconify/Iconify.java @@ -37,7 +37,7 @@ public final class Iconify { - private static final String FONTAWESOME_TTF_FILE = "fontawesome-webfont-4.4.0.ttf"; + private static final String FONTAWESOME_TTF_FILE = "res:fontawesome-webfont-4.4.0.ttf"; public static final String TAG = Iconify.class.getSimpleName(); @@ -805,7 +805,7 @@ public String getPrefix() { @Override public IconValue iconFrom(String value) { - return IconValue.valueOf(value.replaceAll("-", "_")); + return IconValue.valueOf(value); } } } diff --git a/android-iconify/src/main/java/com/joanzapata/android/iconify/Utils.java b/android-iconify/src/main/java/com/joanzapata/android/iconify/Utils.java index 908a290..d26fc1c 100644 --- a/android-iconify/src/main/java/com/joanzapata/android/iconify/Utils.java +++ b/android-iconify/src/main/java/com/joanzapata/android/iconify/Utils.java @@ -65,20 +65,41 @@ static File resourceToFile(Context context, String resourceName) throws IOExcept Log.e(Iconify.TAG, "Font folder creation failed"); throw new IllegalStateException("Cannot create Iconify font destination folder"); } - File outPath = new File(f, resourceName); + + String filename = resourceName; + int separatorIndex = resourceName.indexOf(':'); + if (separatorIndex != -1) { + filename = resourceName.substring(separatorIndex + 1); + } + + File outPath = new File(f, filename); if (outPath.exists()) return outPath; - BufferedOutputStream bos = null; InputStream inputStream = null; try { - inputStream = Iconify.class.getClassLoader().getResourceAsStream(resourceName); + if (resourceName.startsWith("asset:")) { + inputStream = context.getAssets().open(filename); + copy(inputStream, outPath); + return outPath; + } + + inputStream = Iconify.class.getClassLoader().getResourceAsStream(filename); + copy(inputStream, outPath); + return outPath; + } finally { + closeQuietly(inputStream); + } + } + + private static void copy(InputStream inputStream, File outputFile) throws IOException { + BufferedOutputStream bos = null; + try { byte[] buffer = new byte[inputStream.available()]; - bos = new BufferedOutputStream(new FileOutputStream(outPath)); - int l = 0; + bos = new BufferedOutputStream(new FileOutputStream(outputFile)); + int l; while ((l = inputStream.read(buffer)) > 0) { bos.write(buffer, 0, l); } - return outPath; } finally { closeQuietly(bos); closeQuietly(inputStream); @@ -116,7 +137,7 @@ public static & BaseIconValue> StringBuilder replaceIcons(T i String iconString = text.substring(startIndex + 1, endIndex - 1); try { - BaseIconValue value = icon.iconFrom(iconString); + BaseIconValue value = icon.iconFrom(iconString.replaceAll("-", "_")); String iconValue = String.valueOf(value.character()); text = text.replace(startIndex, endIndex, iconValue);