Skip to content

Instantly share code, notes, and snippets.

@kennethjiang
Created October 16, 2015 16:00
Show Gist options
  • Save kennethjiang/1a29b4695dad0736573b to your computer and use it in GitHub Desktop.
Save kennethjiang/1a29b4695dad0736573b to your computer and use it in GitHub Desktop.
package rhumbix.rhumbix;
class ImageUploader
{
public static int[] dimension = new int[2]; // dimension[0] = width, dimension[1] = height
void cacheImageInMemory(File imageFile) {
...
}
void uploadToServers(File imageFile) {
...
}
public void upload(File imageFile) throws Exception{
Map<String,Integer> test = new HashMap<String, Integer>();
test.put("maxWidth", 10);
test.put("maxHeight", 20);
if (!this.validate(imageFile, test)) {
return
};
this.uploadToServer(imageFile);
this.cacheImageInMemory(imageFile);
}
public boolean validate(File imageFile, Map<String,Integer> test) throws Exception{
// imageFile needs to be valid
if (imageFile != null) {
dimension[0] = ImageUtil.getWidth(imageFile);
dimension[1] = ImageUtil.getHeight(imageFile);
int mw = test.get("maxWidth"); // maxWidth
// if (dimension[0] > 0 && mw > 0) {
if (dimension[0] > 0) {
if (dimension[0] <= mw && dimension[0] > 1) {
int mh = test.get("maxHeight"); // maxHeight
// if (dimension[1] > 0 && mh > 0) {
if (dimension[1] > 0) {
if (dimension[1] <= mh && dimension[1] > 1) {
return true;
} else {
return false;
}
return false;
} else {
throw new Exception("Invalid height");
}
} else {
return false;
}
} else {
throw new Exception("Invalid width");
}
} else {
throw new Exception("imageFile is null");
}
}
}
@supershik
Copy link

Hi Kenneth Jiang. This is an experienced React Native Developer.
I can help you. please discuss more details via chat.
skype ID
live:.cid.722115df157063d7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment