Android Phonegap Native Timepicker

So I’ve been working on a simple android app and I finally got audacious and started to move beyond the basics. I was able to get an app in the store with just my HTML/JS/CSS skills pretty easily which makes phonegap a big success.

Anyhow, now my latest fiasco was to try and use the native android timepicker and while I’ve still got a ways to go, I wanted to post my working code that I also put back on a discussion I had with myself on the google group.

FWIW here’s what I’ve got working.

A simple TimePicker class with a showTimePicker method.

public class TimePicker {
private DroidGap mGap;

public TimePicker(DroidGap gap)
{
mGap = gap;
}

public void showTimePicker(){
mGap.showDialog(HelloWorldPlugin.TIME_DIALOG_ID);
}
}

A custom TimePickerDialog.OnTimeSetListener which is initialized with
knowledge of DroidGap too…

@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
mGap.sendJavascript(” callback javascript goes here!”);
}

Initialize and add the createdialog stuff like the android dialog
tutorial.

TimePicker timepicker = new TimePicker(this, appView);
appView.addJavascriptInterface(timepicker, “TimePicker”);

Then in the javascript, once phonegap loads, you can refer to the
timepicker:

window.TimePicker.showTimePicker();

Hope that Saves Somebody else some time or inspires somebody to show
me the ways of the plugin framework.

 

As I get better at this stuff, I might end up understanding how to do it within the plugin architecture but for now that’s it.

Cheers.