Skip to content

Create your own plugin

Joan edited this page Apr 6, 2014 · 3 revisions

BeyondAR architecture allows you to create your own plugins that can be attached to the framework, for instance to have a better access to the World object in order to perform other extra tasks like using Google Maps, or a radar view.

The first thing that we need to do is to understand what do we need to implement in order to create our plugin. The needed interfaces are located in the com.beyondar.android.plugin package:

  • WorldPlugin: This interface will allow your plugin to be notified when some events occur, like when the position has changed, a new object has been added or removed, the World is cleaned, etc. (here you will find the code).
  • BeyondarObjectPlugin: This interface allows your plugin to get notified when there are changes in a specific BeyondarObject (here you will find the code).
  • GeoObjectPlugin: This interface extends BeyondarObjectPlugin and it have some extra code to make easier the control of the geo position of this kind of objects (here you will find the code).

One of the main goals of WorldPlugin is to add BeyondarObjectPlugin /GeoObjectPlugin to all the BeyondarObject/GeoObject in the World object. To do that make sure to add you own plugin in when setup(World world) is called and when a new BeyondarObject is added:

@Override
public void onBeyondarObjectAdded(BeyondarObject beyondarObject, BeyondarObjectList beyondarObjectList) {
     if (beyondarObject instanceof GeoObject) { // Check if it is a GeoObject
        // We need to check if there is any of our own plugin already attached
        if (!beyondarObject.containsAnyPlugin(RadarPointPlugin.class)) { 
            // Then we just create it and add it
            RadarPointPlugin plugin = new RadarPointPlugin(this, beyondarObject);
            beyondarObject.addPlugin(plugin);
        }
    }
}

When the plugin is ready we need to add it to the World class, for that we just use the method myWorld.addPlugin(myPlugin).

World myWorld = new World(context);
// add the plugin
myWorld.addPlugin(myPlugin);

Examples

There are a few examples to use plugins like the Google Maps Plugin or the Radar Plugin.

Clone this wiki locally