Dynamix 2 Plug-in Development Quickstart

//Dynamix 2 Plug-in Development Quickstart

Introduction

This tutorial assumes that you have a basic understanding of maven and the underlying principals and that maven 3.1.1 or later is installed on your machine and accesible from the commandline.
If you need some more information about maven, you can get an overview here: http://maven.apache.org/guides/getting-started/
I also assume you have read through the Plug-in Basics section in the plugin developement tutorial  and are familiar with the general concepts of dynamix plugin developement.
We also assume Dynamix is installed and running on your phone

Generating a Sample Plugin Project:

Open a command line interface in the location you want to create the new project and enter the following line:

The archetype will query you for an artifactId, which will be the name of your plugin. You can enter any name here and accept the defaults after pressing enter, but we suggest you adjust the defaults to your personal situation. To do so enter any letter, press enter and then reject the defaults by entering “n”.

r

You will be asked to provide a group id (“org.ambientdynamix.contextplugins” in this case), an artifactid (here “QuickstartPlugin”), a version number and a package which will be the package all your java classes will be generated into (“org.ambientdynamix.contextplugins.quickstart” here)

mvn2

 

confirm with ‘Y’ and maven generates a sample plugin project for you.

mvn3

 

Generated Project Structure

The generated sample plugin project reads out the phones battery level and makes it available through dynamix
let’s take a look at the generated Project structure which is composed out of three maven modules:

Project Structure

_The Core

The Core module contains all the plugins business logic, such as the plugin factory and the actual plugin implementation

_The Datatypes

The Datatypes module contains all the Data classes associated with the context types provided by the plugin. This has to be in a separate module, so other native dynamix apps that support these context types can import them as a dependency and cast them upon reception.

_The Testapp

The Testapp module is a very simple native Dynamix android app, that allows you a quick and simple way to invoke your plugin and query for the context types it provides. This will be explained later.

Importing the Project

You can now import the generated plugin project to your favourite IDE by using its respective maven project import methods and maven should take care of all the dependency management, build path settings etc. but you can also stay on the commandline to perform the following steps to deploy and run your generated plugin.

Compiling and deploying

To compile and deploy the project to a phone, make sure you have a single device connected to your computer via USB
execute the “mvn -P default install” goal on the root project, by using your IDE features or by simply typing it into a command line interface in your projects root directory.
This will compile and package the project and will also deploy the plugin jar to the phone, into the /dynamix directory.
It also generates the neccesary OSGI descriptor for you.

Using the TestApp

The testapp provides a simple configurable framework to invoke any number of context plugins. It consists of two classes, the bindDynamixActivity, which handles all the connecting to dynamix and the GUI. You should not need to touch this class, but feel free to have a look at the source code to understand the underlying connection procedure of native apps.
The second class “PluginInvoker” is managing which plugins are to be invoked by the TestApp.

A context request in dynamix consists of three parameters, A plugin id, a context type and an optional configuration bundle.

To configure a context request to be performed by the invoker, call the “addPluginInvocation(String pluginId, String contextType, Bundle configuration)” method in the PluginInvoker’s constructor.

The BindDynamixActivity will execute all the configured pluginInvocations and call the PluginInvoker’s “invokeOnResponse(ContextEvent event)” methos if it receives a response that corresponds to a request type configured by you.

You can run the TestApp by either “cd-ing” into the TestApp directory on your command line and execute “mvn android:deploy android:run” or by using the android support functions of your IDE.

After startup you should see the following application screen:

TestApp

Press connect to connect to dynamix on your phone. The connect Event will uninstall all installed plugins, so you always start from a clean slate with the newly uploaded plugin version. Pressing “invoke plugin” will send all the plugin requsts you configured in the PluginInvolker’s constructor and call the “invokeOnResponse(ContextEvent event)” method if a response was received.

The TestApp also has an “experimental” option to run the invocations without human interaction. To do so set the

variable to true. If you do so you will only see a black screen on startup and all the connection and invocation will be performed automatically. However this approach does not work in all cases due to timing issues.

If you have made it this far, congratulations, you are ready to start developing your new dynamix plugin.

Debuging a Plugin

This tutorial explains how to debug  a plugin

By | 2017-09-29T23:38:59+00:00 January 21st, 2015|documentation|Comments Off on Dynamix 2 Plug-in Development Quickstart