Skip to content
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