Android phone plugin ActionBar wrapper

I'm trying to add iOS TabBar style navigation using my own Android controls, so ActionBar is in my PhoneGap app. I want my JavaScript to receive callbacks when changing tabs, and ideally I would like the ActionBar to be fully dynamically populated with JavaScript (like iOS Native TabBar in PhoneGap). I know that I can do this at the JS / CSS / HTML level, but I would like to seriously consider using my own controls before I do this.

I have successfully added an ActionBar to my Android phonegap application by modifying 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 try to make it more beautiful by creating a plugin around it using very similar 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);
}

, , ActionBar onCreate. , onCreate javascript , , java JavaScript - . "success", keepCallback. , , java, :

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
    ]);
};     

, :

  • ActionBar /?
  • ActionBar / ?
  • , JavaScript Java-?
+5

All Articles