android phonegap plugin ActionBar wrapper
===

I'm trying to add an iOS "TabBar" style navigation using android native controls - so ActionBar - to my PhoneGap application. I'd like my JavaScript to receive callbacks when the tabs are changed, and ideally I'd like the ActionBar to be completely dynamically populated by the JavaScript as well (like iOS Native TabBar in PhoneGap). I know I can do this in the JS/CSS/HTML layer but I'd like to have a serious go at using native controls before I do that.

I've successfully added an ActionBar to my android phonegap app by modifying the onCreate to contain:

    public void onCreate(Bundle savedInstanceState) {
        this.setBooleanProperty("showTitle", true);

        super.onCreate(savedInstanceState);

        getWindow().requestFeature(Window.FEATURE_ACTION_BAR);

        ActionBar bar = getActionBar();

        bar.setDisplayShowTitleEnabled(false); 
        bar.setDisplayShowHomeEnabled(false);
        bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

        Tab tab = bar.newTab()
            .setText("Test")
            .setTabListener(new TestListener());

        bar.addTab(tab);
        bar.show();

        super.loadUrl("file:///android_asset/www/index.html");
    }

I've been trying to make this prettier by creating a plugin around it, using very similar to iOS NativeControls mechanisms:

    public PluginResult execute(String action, JSONArray data, String callbackId) {
        PluginResult.Status status = PluginResult.Status.OK;
        String result = "";

        if(INIT.equals(action)) {
            ActionBar bar = cordova.getActivity().getActionBar();
            Tab tab = bar.newTab()
                .setText("Test")
                .setTabListener(new TestListener());

            // CRASHES HERE
            bar.addTab(tab);
            bar.show();
        }

        return new PluginResult(status, result);
    }

I understand that this is a non-starter because the ActionBar must be set-up during the onCreate. So then I left the creation in onCreate and was just trying to have the javascript set a callback to be hit when the tab is clicked, but what I can't figure out is how to actually call an arbitrary callback from java into the JavaScript - at any time. I can do it just fine with the "success" callback using the keepCallback function. I need it to be a callback that is specified as an argument to the java, like so:

    MyActionBar.prototype.setCallback = function(tabIndex, callback) {
        cordova.exec(function () {
                console.log("Set callback succeeded");
        },              
        function() {
                console.log("SetCallback failed");
        },              
        "MyActionBar",
        "setCallback", [tabIndex, callback // <--- Calls THIS callback on click
        ]);
    };     

So several questions:

1. Is the ActionBar strategy I'm employing viable/correct?
2. Is it possible to dynamically alter the contents of an ActionBar to arbitrarily add/remove items?
3. How can I call an arbitrary callback specified by the JavaScript from my Java plugin?