public Object invoke(final Object thiz, final Object[] args) throws Exception {
String contentArg = null;
ScriptableFunction onGenerateArg = null;
ScriptableFunction onErrorArg = null;
Scriptable optionsArg = null;
if(args.length < 2){
throw new IllegalArgumentException("Missing Captured Callback");
}else{
contentArg = (String) args[0];
onGenerateArg = (ScriptableFunction) args[1];
if(args.length > 2){
onErrorArg = (ScriptableFunction) args[2];
if(args.length > 3){
optionsArg = (Scriptable) args[3];
}
}
}
final String contents = contentArg;
final ScriptableFunction generatededCallback = onGenerateArg;
final ScriptableFunction errorCallback = onErrorArg;
final Scriptable options = optionsArg;
Application.getApplication().invokeLater(new Runnable(){
private final String[] ALLOWED_EXTENSIONS = {"jpq","jpeg","png"};
public void run() {
FileConnection fconn = null;
try{
MultiFormatWriter writer = new MultiFormatWriter();
int width = 50;
int height = 50;
BarcodeFormat format = BarcodeFormat.QR_CODE;
Hashtable hints = new Hashtable(2);
String filePath = "file:///SDCard/";
String fileName = ""+(new Date()).getTime();
String fileExtension = "png";
if(options != null){
Object widthObj =options.getField("width");
if(widthObj != UNDEFINED){
width =((Integer)widthObj).intValue();
}
Object heightObj = options.getField("height");
if(heightObj != UNDEFINED){
height = ((Integer)heightObj).intValue();
}
Object formatObj = options.getField("format");
if(formatObj != UNDEFINED){
format = BarcodeFormat.valueOf(((String)formatObj).toUpperCase());
}
//Hints
Object charSetObj = options.getField("characterSet");
if(charSetObj != UNDEFINED){
hints.put(EncodeHintType.CHARACTER_SET, (String)charSetObj);
}
Object errorCorrectionObj = options.getField("errorCorrection");
if(errorCorrectionObj != UNDEFINED){
hints.put(EncodeHintType.ERROR_CORRECTION, (Integer)errorCorrectionObj);
}
Object filePathObj = options.getField("filePath");
if(filePathObj != UNDEFINED){
String filePathOrig = (String)filePathObj;
fileExtension = filePathOrig.substring(filePathOrig.lastIndexOf('.')+1);
fileName = filePathOrig.substring(filePathOrig.lastIndexOf('/')+1,filePathOrig.lastIndexOf('.'));
filePath = filePathOrig.substring(0, filePathOrig.lastIndexOf('/'));