JBoss.orgCommunity Documentation
Starting with version 2.4.0, Errai now supports mobile development. One of the modules that makes this feasible is the Cordova module. It offers a way to integrate with native hardware in an Errai way.
Use the Errai Forge Addon Add Errai Features command and select Errai Cordova to follow along with this section.
Checkout the Manual Setup Section for instructions on how to manually add Errai Cordova to your project.
When the Cordova module is included you can integrate with native hardware by injecting the native components into your code:
@Templated("#main")
public class KitchenSinkClient extends Composite {
@Inject
Camera camera;
@Inject
@DataField
Button takePicture;
@EventHandler("takePicture")
public void onTakePicktureClicked(ClickEvent event) {
PictureOptions options = new PictureOptions(25);
options.setDestinationType(PictureOptions.DESTINATION_TYPE_DATA_URL);
options.setSourceType(PictureOptions.PICTURE_SOURCE_TYPE_CAMERA);
camera.getPicture(options, new PictureCallback() {
@Override
public void onSuccess(String data) {
image.setUrl(UriUtils.fromSafeConstant("data:image/jpeg;base64," + data));
}
@Override
public void onFailure(String error) {
setGeneralErrorMessage("Could not take picture: " + error);
}
});
}
The components that are supported come from the gwt-phonegap project have a look there form more documentation.
Here are the native hardware components you can inject:
So to integrate with these things all we have to do is @Inject
these classes. There are also a couple of CDI events one can observe to be informed about hardware state:
Example of how to use these events:
private void batteryIsLow(@Observes BatteryLowEvent event) {
//mission accomplished. we can stop the infinite loop now.
}