LWUIT DateField and other bits

We missed having a DateField in LWUIT, the Calendar is a great start but it looked a little strange on some phones and we needed something simpler, not to mention a time field.

To do this we extended the TextArea class to create our own MobrizDateField.  When the user clicks on this the system fires up a standard LCDUI form with a DateField on it (DateForm).  The user can then use the native time/date features of the phone to complete the date/time

To tell LWUIT to intercept the DateField calls  we extended the GameCanvasImplementation to create our own MobrizMidpImplementation.  This overrides the editString method and launches the DateForm if the MobrizDateField is being used. We needed a MobrizImplementationFactory to deliver this too.

To tell LWUIT to use the new MobrizMidpImplementation add the following to your code where you initailise the UI.


..
ImplementationFactory.setInstance(new MobrizImplementationFactory());
Display.init(this.mobrizMidlet);
..

Use the new MobrizDateField just like a TextArea:


..
MobrizDateField timeField = new MobrizDateField(dtLong + "", 10,MobrizDateField.TIME, "");
form.addComponent(timeField) ;
..

Things to note:

  • The MobrizDateField takes a string or a long expressed as a string in the constructor .. this is a bit crap but suited us for our app. you may want to change it match to LCDUI datefield exactly.
  • The MobrizDateField actually extends MobrizTextArea which is a TextArea that responds to any key press.

Would welcome any comments or improvments!!!

As ever this code is provided without warranty – user at you own risk.

Here is the source

5 Responses to “LWUIT DateField and other bits”

  1. Marcos Maia says:

    Hi,

    first of all, tx for the excellent work. I’m evaluating your solution, already using in a prototype and it’s working fine so far.

    All I had to do was instantiate your factory:
    ImplementationFactory.setInstance(new MobrizImplementationFactory());
    Display.init(this);

    and than:

    MobrizDateField timeField = new MobrizDateField(new Date().getTime() + “”, 10,MobrizDateField.DATE, “dmy”);
    myLWUITPanel.addComponent(timeField) ;

    tx, I’ll let you know when better tested.
    regards,
    []s

    Marcos Maia.

  2. rspence says:

    Thanks Marcos

    Glad it was of use. There are a few holes which were cool for our requirements but probably need fixing for a generic solution.

    Let me know if you make any improvements

    Regards

    Richard

  3. Hi! I like your srticle and I would like very much to read some more information on this issue. Will you post some more?

  4. rspence says:

    Thanks very much … not sure I have much more to add on this topic apart from get the LWUIT source code down and see how this fits in. Another guy has done a LCDUI port and someone else has had a real stab at Blackberry.

    Cheers

    Richard

  5. rspence says:

    This is another attempt at a full LCUDI port lcduilwuit.googlecode.com

Leave a Reply

You must be logged in to post a comment.