Extending the language / User-defined front calls |
Custom front call modules for the Android™ front-end are implemented by using the API for GMA front calls in Java™.
In order to extend the GMA with your own front calls, you must be familiar with Java programming concepts, and if you want to interface with Android apps, understand concepts such as Android Activity and Intent.
The front call function controller (IFunctionCallController) is implemented by the GMA, it is used to notify function call results, raise runtime exceptions and invoke activities.
The front call function body (IFunctionCall) implements the actual custom front call code.
Method | Description |
---|---|
void setFunctionCallController(IFunctionCallController controller) |
This method binds the front call function controller object to the function body object. The controller parameter is the IFunctionCallController object to bind with the front call function body object. |
abstract void invoke(Object[] args) throws IllegalArgumentException |
This method performs the front call. Is will be called when the front call is executed from the Genero program. The args parameter is a variable list of parameters passed to the front call. This corresponds to the third argument of ui.Interface.frontCall |
void onSaveInstanceState(Bundle state) |
Saves the state of an ongoing function call when Android needs to suspend the application. The state parameter is the bundle to save the state to. |
void onRestoreInstanceState(Bundle state) |
Restores the state of an ongoing function call, when Android needs to restore the application. The state parameter is the bundle to restore the state from. |
void onActivityResult(int resultCode, Intent data) |
Callback invoked when an activity started through IFunctionCallController.startActivityForResult finishes. The resultCode parameter is the integer result code returned by the child activity through its setResult() method. The data parameter is an Intent object, which can return result data to the caller (various data can be attached to Intent "extras"). |
Method | Description |
---|---|
void returnValues(IFunctionCall functionCall, Object...values) |
Notifies the controller that the front call function call has finished successfully. To be called typically at the end of the IFunctionCall.invoke() method. The functionCall parameter is the current IFunctionCall object invoked. The values parameter defines the variable list of front call function return values. This corresponds to the fourth parameter of ui.Interface.frontCall. |
void raiseError(IFunctionCall functionCall, String message) |
Notifies the controller of an error in the front call function call. This leads to a BDL runtime exception.To be called if needed within the IFunctionCall.invoke() method. The functionCall parameter is the current IFunctionCall object invoked. The message parameter holds the error message to be returned to the Genero program in the second part of the error -6333 message (see front call error handling in ui.Interface.frontCall). |
void startActivity(IFunctionCall functionCall, Intent intent) |
Starts a new activity. The function call won't be notified of the end of the activity. The Genero program will run in parallel of this activity. The behavior is similar to a RUN WITHOUT WAITING. The functionCall parameter is the current IFunctionCall object invoked. The intent parameter describes the activity to start. |
void startActivityForResult(IFunctionCall functionCall, Intent intent) |
Starts a new activity. The function call won't be notified of the end of the activity. The Genero program will remain blocked as long as the started activity isn't finished. The behavior is similar to a RUN. The method IFunctionCall.onActivityResult will be called once the activity finishes. The functionCall parameter is the current IFunctionCall object invoked. The intent parameter describes the activity to start. |
Activity getCurrentActivity() |
Returns the current Activity object. Provided in case if you need to pass the current activity to an Android API requiring this object. Important: Don't use the returned activity to start
other activities (don't call
Activity.startActivity or
Activity.startActivityForResult), use
the helpers of the current interface instead.
|
In the Genero program, use the ui.Interface.frontCall() API to call the front-end function. This method takes the front call module name as first parameter and the front call function name as second parameter. The front call module name is defined by the Java package name of the custom class implementing the IFunctionCall interface, and the front call function name is defined by the name of the class.
package com.mycompany.utilities; ... public class GetPhoneId implements IFunctionCall { ...
CALL ui.Interface.frontCall("com.mycompany.utilities", "GetPhoneId", ["John DOE"], [msg])
The compiled Java classes implementing the front calls must be included in the mobile application Android package (.apk), which is created in the Genero Studio deployment procedure. The same GMA package building rules apply for front calls and for simple Java extensions. See Packaging custom Java extensions for GMA for more details.
The next example implements a HelloWorld call as a front call module.
HelloWorld.java:
package com.mycompany.testmodule; import android.content.Intent; import android.os.Bundle; import com.fourjs.gma.extension.v1.IFunctionCall; import com.fourjs.gma.extension.v1.IFunctionCallController; public class HelloWorld implements IFunctionCall { private IFunctionCallController mController; @Override public void setFunctionCallController(IFunctionCallController controller) { mController = controller; } @Override public void invoke(Object[] args) throws IllegalArgumentException { if (args.length != 1) { throw new IllegalArgumentException("HelloWorld takes one argument"); } mController.returnValues(this, "Hello " + args[0].toString()); } @Override public void onSaveInstanceState(Bundle state) { } @Override public void onRestoreInstanceState(Bundle state) { } @Override public void onActivityResult(int returnCode, Intent data) { } }
MAIN DEFINE msg STRING MENU ON ACTION frontcall ATTRIBUTES(TEXT="Call custom front call") CALL ui.Interface.frontCall("com.mycompany.testmodule", "HelloWorld", ["John DOE"], [msg]) ON ACTION quit EXIT MENU END MENU END MAIN