返回顶部

收藏

在 Android 上使用 jspf 插件框架

更多

jspf (Java Simple Plugin Framework) 是一个插件框架,集成了很多 IoC 框架的概念在里面。

JSPFDemo.java

package de.jspfdemo;

import net.xeoh.plugins.base.PluginManager;
import net.xeoh.plugins.base.impl.PluginManagerFactory;
import net.xeoh.plugins.base.util.uri.ClassURI;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import de.jspfdemo.plugins.CoolPlugin;
import de.jspfdemo.plugins.impl.CoolPluginImpl;

public class JSPFDemo extends Activity {

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        // Loading and adding plugins via class uri
        PluginManager pm = PluginManagerFactory.createPluginManager();
        pm.addPluginsFrom(new ClassURI(CoolPluginImpl.class).toURI());

        // Getting the CoolPlugin
        CoolPlugin plugin = pm.getPlugin(CoolPluginImpl.class);

        // Setting the text of a TextView with the help of the CoolPlugin
        TextView textView = (TextView) findViewById(R.id.textView);
        textView.setText(plugin.sayHello());
    }
}

标签:Android,插件,jspf

收藏

0人收藏

支持

0

反对

0