Sample Source Code

Source code and template samples.

vaandroid.xml

A sample Vaandroid configuration file allowing all users to access all activities defined in the plugin.

<vaandroid>
    <manifest>src/main/AndroidManifest.xml</manifest>
    <resources>src/main/res</resources>
    <libs></libs>
    <assets></assets>

    <permissions version='1'>
        <permission>
            <users scope='_ALL'>
                <id>_ALL</id>
                <allow>_ALL</allow>
            </users>
        </permission>
    </permissions>
</vaandroid>

pom.xml

A barebones POM for creating a Vaandroid Plugin.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://maven.apache.org/POM/4.0.0"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <packaging>bundle</packaging>

    <parent>
        <groupId>tv.twelvetone.vaandroid.plugin</groupId>
        <artifactId>tv.twelvetone.vaandroid.plugin.master</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <groupId>tv.twelvetone.vaandroid.plugin</groupId>
    <artifactId>tv.twelvetone.vaandroid.plugin.helloworld</artifactId>
    <version>1.0-SNAPSHOT</version>

    <description>Hello World</description>

    <dependencies>
        <dependency>
            <groupId>tv.twelvetone.vaandroid</groupId>
            <artifactId>tv.twelvetone.vaandroid.core</artifactId>
            <version>1.0-SNAPSHOT</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>tv.twelvetone.vaandroid.plugin</groupId>
            <artifactId>tv.twelvetone.vaandroid.plugin.osgi</artifactId>
            <version>1.0-SNAPSHOT</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <extensions>true</extensions>
            </plugin>
        </plugins>
    </build>

</project>

PluginImpl.java

package tv.twelvetone.android.test.helloworld;

import org.osgi.framework.BundleContext;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;

import tv.twelvetone.vaandroid.core.api.runtime.VaandroidOsgiPlugin;
import tv.twelvetone.vaandroid.plugin.osgi.api.VaandroidOsgiPluginImpl;

@Component(service = VaandroidOsgiPlugin.class)
public class PluginImpl extends VaandroidOsgiPluginImpl {
    static private PluginImpl instance;
    public BundleContext context;
    private VaandroidOsgiPluginImpl plugin;

    public PluginImpl() {
        super(new ResourceImpl());
        instance = this;
    }

    @Activate
    protected void activate(ComponentContext componentContext) {
        context = componentContext.getBundleContext();
    }

    @Deactivate
    protected void deactivate(ComponentContext componentContext) {
        context = null;
    }

    public static PluginImpl getInstance() {
        return instance;
    }

    public static BundleContext getContext() {
        return instance != null ? instance.context : null;
    }

    @Override
    public String getLabel() {
        return R.getString(R.string.app_name);
    }
}

ResourceImpl.java

package tv.twelvetone.android.test.helloworld;

import tv.twelvetone.vaandroid.plugin.osgi.api.IResource;

public class ResourceImpl implements IResource {
    @Override
    public int getId(String stringId) {
        return R.getId(stringId);
    }

    @Override
    public String getString(int id) {
        return R.getString(id);
    }

    @Override
    public Integer getColor(int id) {
        try {
            return R.getColor(id);
        } catch (Exception e) {
            return null;
        }
    }

    @Override
    public Integer getDimension(int id) {
        try {
            return R.getDimen(id);
        } catch (Exception e) {
            return null;
        }
    }

    @Override
    public String getDrawablePath(int id) {
        return R.getDrawablePath(id);
    }

    @Override
    public String getMipmapPath(int id) {
        return R.getMipmapPath(id);
    }

    @Override
    public String getImagePath(int id) {
        return R.getImagePath(id);
    }

    @Override
    public String getMenuPath(int id) {
        return R.getMenuPath(id);
    }

    @Override
    public String getLayoutPath(int id) {
        return R.getLayoutPath(id);
    }

}