Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for URL Images #11

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
npm-debug.log
node_modules/
.idea/
android/android.iml
android/local.properties
26 changes: 25 additions & 1 deletion android/src/main/java/io/palette/RNPaletteModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
Expand Down