forked from mixare/mixare
-
Notifications
You must be signed in to change notification settings - Fork 1
Bootstrap plugin
abduegal edited this page Jun 27, 2012
·
6 revisions
Bootstrap plugins are activities that can be executed when Mixare starts. There are 2 types of bootstrap plugins for each phase
- BOOTSTRAP_PHASE_1
- BOOTSTRAP_PHASE_2
Bootstrap plugins are executed in that order. There are 2 sample bootstrap plugins in the plugin folder: barcodescanner and splashscreen. Below is a tutorial of how to build a splashscreen plugin.
- Create a new project without a main Activity. For convenience packages should be named:
org.mixare.plugin.[pluginname] - Import the mixarelib folder in the plugin directory by going to properties -> android -> library -> add (Make sure that the mixarelib project is imported in the workspace).
- Create an android Service class, the service class is responsible for returning an activity to the main app.
- Add the android service class into your application manifest. You also need to set the
android:exported="true"and add the action name<action android:name="org.mixare.plugin.bootstrap1"/>in the intent filter. Note that org.mixare.plugin.bootstrap1 is the plugin category BOOTSTRAP_PHASE_1, and org.mixare.plugin.bootstrap2 is the plugin category BOOTSTRAP_PHASE_2.
<service
android:name=".service.ArenaSplashService"
android:exported="true" >
<intent-filter>
<action android:name="org.mixare.plugin.bootstrap1"/>
<category android:name="mixare.intent.category.BOOTSTRAP_PLUGIN"/>
</intent-filter>
</service>- Next we are going to build the service. A bootstrap service will have to use the AIDL binder
org.mixare.lib.service.IBootStrap. We also need to override theonBind(Intent intent)method
@Override
public IBinder onBind(Intent intent) {
return binder;
}
private final IBootStrap.Stub binder = new IBootStrap.Stub() {
...- A bootstrap plugin will eventually return an Activity to the Mixare core application. The following methods should be overridden
private final String ACTIVITY_PACKAGE = "org.mixare.plugin.arenasplash";
private final String ACTIVITY_NAME = "org.mixare.plugin.arenasplash.ArenaSplashActivity";
private final String PLUGIN_NAME = "arena-splash";
private final int Z_INDEX = 0;
public static final int ACTIVITY_REQUEST_CODE = 2118;
...
@Override
public String getActivityName() throws RemoteException {
return ACTIVITY_NAME; // the name of the activity created in #5: (package + classname)
}
@Override
public String getActivityPackage() throws RemoteException {
return ACTIVITY_PACKAGE; // the package of the activity created in #5
}
@Override
public int getZIndex() throws RemoteException {
return Z_INDEX; // when having multiple bootstrap plugins, lower z-indexes are executed sooner.
}
@Override
public String getPluginName() throws RemoteException {
return PLUGIN_NAME; // the unique name of the plugin
}
@Override
public int getActivityRequestCode() throws RemoteException {
return ACTIVITY_REQUEST_CODE; // a request code: set to 2118
}- Finally we need to create an Activity that the service can call. To end the activity and to return a result:
Intent intent = new Intent();
intent.putExtra("resultType", resultType); //add some data to the result
setResult(ArenaSplashService.ACTIVITY_REQUEST_CODE, intent); //that was set to 2118 see #6
finish(); //and finish it, so the main app gets the focus again.You must return a "Splashscreen" as resultType if the activity you are using is a splashscreen, so that the main mixare app can process it. Other available plugin types are: "Datasource" (see barcode plugin)