Get started with Plugins
How to configure and inject plugins
A MobileUI Plugin PURPLE is a triplet of Java libraries that is automatically added to your project by adding a single line of code. MobileUI Plugins rely on MobileUI Inject. So, for the plugins to work, make sure you have configured MobileUI inject correctly.
The following sections explain, how to add a plugin and use it. As an example, we add the Vibrator Plugin here.
1. Add the Plugin to your build.gradle
To make the plugin available, just add it to your root project build.gradle
as shown below. Make sure, you're adding it to the mobileuiPlugins
array.
allprojects {
ext {
//versions are examples
mobileuiVersion = "0.5.1"
roboVMVersion = "2.3.9"
mobileuiPlugins = [
"io.nevernull:mobileui-inject",
"io.nevernull:mobileui-plugin-vibrator", ]
}
}
2. Inject the Plugin in your code
Now, you can use the plugin within your code. If you have managed objects, you can simply add the property with the @Inject
annotation as shown below. The dependency injection container will automatically inject the correct instance of the plugin and you can use it within your logic as shown in the line below.
import javax.inject.Inject;
import io.micronaut.context.annotation.Prototype;
@Prototype
public class MainController {
@Inject Vibrator vibrator;
// Example usage
public void onClick() {
vibrator.vibrate(); }
}
This is the basic principle behind plugin integration. Sometimes, a plugin has additional configuration. Please refer to the plugin's section within this documentation to learn more.