I'm trying to make a native extension for Android Vibration. Every open source extension I've found only utilizes the vibrate(duration)
but not the vibrate(pattern, repeat)
and vibrate.cancel()
I need to be able to pass a patten, and cancel functions.
I'm able to get vibration(duration)
to work fine with no issues. There is a simple args[1].getAsInt();
method for me to use. But, there is not .getAsArray
or .getAsLong
.
I found something called FREArray, but i'm really not understanding how to use it.
So, my question is, with an AS3 function that I can pass an array (with the pattern) and an int (for the repeat count) How can I receive the array on the Android side? I'm not having any trouble receiving the int for the repeat.
Here's what i've I was working with so far, but due to the errors it looks like im not using it correctly. Any suggestions?
public FREObject call(FREContext context, FREObject[] args) {
VibrateExtensionContext vibrate(pattern, repeat)ExtensionContext) context;
long[] pattern;
int repeat = 0;
try {
pattern = FREArray.newArray(args[0]); //this is where im stuck
//it would be ideal if there was something like this..
//pattern = args[0].getAsLong(); but this doesnt exist
repeat = args[1].getAsInt(); //this works fine
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FRETypeMismatchException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FREInvalidObjectException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FREWrongThreadException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
vibExtContext.androidVibrator.vibrate(pattern, repeat);
return null;
}