-
-
Save tkrynski/d7de6486689853bd10a5fc1c7f6be7d6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment