From f9e0dd19a4965d57c65d6a10ac84158f9becdb13 Mon Sep 17 00:00:00 2001 From: mosgamal Date: Sun, 29 Apr 2018 08:24:05 +0200 Subject: [PATCH 1/3] support online images for android --- android/android.iml | 21 +++++++++++++++ android/local.properties | 11 ++++++++ .../main/java/io/palette/RNPaletteModule.java | 26 ++++++++++++++++++- 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 android/android.iml create mode 100644 android/local.properties diff --git a/android/android.iml b/android/android.iml new file mode 100644 index 0000000..a162bd1 --- /dev/null +++ b/android/android.iml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/android/local.properties b/android/local.properties new file mode 100644 index 0000000..dc030b5 --- /dev/null +++ b/android/local.properties @@ -0,0 +1,11 @@ +## This file is automatically generated by Android Studio. +# Do not modify this file -- YOUR CHANGES WILL BE ERASED! +# +# This file must *NOT* be checked into Version Control Systems, +# as it contains information specific to your local configuration. +# +# Location of the SDK. This is only used by Gradle. +# For customization when using a Version Control System, please read the +# header note. +#Sat Apr 28 18:49:27 EET 2018 +sdk.dir=C\:\\Users\\Admin\\AppData\\Local\\Android\\Sdk diff --git a/android/src/main/java/io/palette/RNPaletteModule.java b/android/src/main/java/io/palette/RNPaletteModule.java index 713e072..afa7fd2 100644 --- a/android/src/main/java/io/palette/RNPaletteModule.java +++ b/android/src/main/java/io/palette/RNPaletteModule.java @@ -19,6 +19,14 @@ import java.util.ListIterator; import java.lang.Integer; +import android.util.Patterns; +import java.util.regex.Pattern; +import java.util.regex.Matcher; + +import java.net.URL; +import java.net.HttpURLConnection; +import java.io.InputStream; + public class RNPaletteModule extends ReactContextBaseJavaModule { private final ReactApplicationContext reactContext; @@ -38,7 +46,23 @@ private String intToRGBA(int color) { } private Palette getPallet(final String realPath, final Callback callback) { - Bitmap bitmap = BitmapFactory.decodeFile(realPath); + + Bitmap bitmap = null; + + if (Patterns.WEB_URL.matcher(realPath).matches()){ + try{ + URL url = new URL(realPath); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setDoInput(true); + connection.connect(); + InputStream input = connection.getInputStream(); + bitmap = BitmapFactory.decodeStream(input); + } catch (Exception e){ + //TODO: Handle Errors + } + } else { + bitmap = BitmapFactory.decodeFile(realPath); + } if (bitmap == null) { callback.invoke("Bitmap Null"); From 2921fa59c9d3415af15d3b90c7877a9c845a7be5 Mon Sep 17 00:00:00 2001 From: mosgamal Date: Sun, 29 Apr 2018 08:34:03 +0200 Subject: [PATCH 2/3] modified gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 18ffbfd..1bd7dfe 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ npm-debug.log node_modules/ .idea/ +android/ From 1993301f1e3078fc430a0f777c87a5181919003c Mon Sep 17 00:00:00 2001 From: mosgamal Date: Sun, 29 Apr 2018 09:18:23 +0200 Subject: [PATCH 3/3] fix gitignore --- .gitignore | 3 ++- android/android.iml | 21 --------------------- android/local.properties | 11 ----------- 3 files changed, 2 insertions(+), 33 deletions(-) delete mode 100644 android/android.iml delete mode 100644 android/local.properties diff --git a/.gitignore b/.gitignore index 1bd7dfe..988ec89 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ npm-debug.log node_modules/ .idea/ -android/ +android/android.iml +android/local.properties diff --git a/android/android.iml b/android/android.iml deleted file mode 100644 index a162bd1..0000000 --- a/android/android.iml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/android/local.properties b/android/local.properties deleted file mode 100644 index dc030b5..0000000 --- a/android/local.properties +++ /dev/null @@ -1,11 +0,0 @@ -## This file is automatically generated by Android Studio. -# Do not modify this file -- YOUR CHANGES WILL BE ERASED! -# -# This file must *NOT* be checked into Version Control Systems, -# as it contains information specific to your local configuration. -# -# Location of the SDK. This is only used by Gradle. -# For customization when using a Version Control System, please read the -# header note. -#Sat Apr 28 18:49:27 EET 2018 -sdk.dir=C\:\\Users\\Admin\\AppData\\Local\\Android\\Sdk