File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java Micro Edition and the fly likes Canvas direct text input (TextBox alternative) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "Canvas direct text input (TextBox alternative)" Watch "Canvas direct text input (TextBox alternative)" New topic

Canvas direct text input (TextBox alternative)

James Hodgkiss
Ranch Hand

Joined: Jan 22, 2004
Posts: 401
Surprisingly little info on this on the net, so wonder if anyone can help:

Rather than opening a native javax.microedition.lcdui.TextBox, I want to be able to detect user input directly on a canvas (with the keyPressed() method).

I'm creating a generic MIDP2 midlet, and the main problem I'm going to face is detecting when the user has entered a space (as it could be possibly, the '0' key, the '#' key, the '*' key or the '1' key).

Is the best solution to just treat any of those key presses as a space, or is there a better way? Has anyone already got the code?

Rashid Mayes
Ranch Hand

Joined: Jan 11, 2006
Posts: 160
Have you taken a look at the TWUIK? It looks impressive.

I use a pure canvas text entry component for most of my applications. In most cases I mimic multi-tap functionality. For example, the key '0' is mapped to ' ' and '0' Pressing 0 once is treated as a space, and pressing it two times is considered 0.

Likewise, '#' and '*' are reserved for "#$[]{}~^`|" and "*-_()/\\:;+&%*=<>$" respectively.

I know which character to choose by the number of times the key was pressed. I have an external text file that can customize the mappings for different phones. For example, my E61 has a QWERTY layout and uses a key map file that takes advantage of it.

You can grab my source code from from any of the applications below. The interesting classes are TextInputEngine, TextInputListener, and ~TextInputWidget.

Here are some videos of applications which use the text entry component.

Two final considerations are mapping the delete key and how to select uppercase characters...

Rashid Mayes -
James Hodgkiss
Ranch Hand

Joined: Jan 22, 2004
Posts: 401
Thanks Rashid,

TWUIK looks nice but a bit a overkill for my needs, but I'll check your source code out.

Like I mentioned though, I'm creating a generic midp 2.0 midlet and I don't really want the hassle of having to update a mappings text file when new phone models are released, etc.

So with that being the case, I suppose the only way for me to reliably detect the user pressing his SPACE character key, would be to treat buttons 1, *, 0, # and RIGHT as spaces (and ignoring special characters - which I don't need anyway).

But QWERTY keyboards throw a spanner into the works... (Presumably, they're not detectable in MIDP2?)

Maybe what I'm looking to achieve isn't possible...
[ June 29, 2007: Message edited by: James Hodgkiss ]
adroit dhanwada

Joined: Apr 18, 2007
Posts: 16
pl. help how to use keylistener.iam using blackberry.from the api document i got some info.

Keypad.key(int keycode) gets the key pressed
Using Keypad.status(int keycode) gets the modifier key status at the time of the keypress.
is invoked when a key has been pressed.

but how to get the keycode value?because i don't know which key the user will press.i want to trigger eventlistener when any of the keys on the keypad is pressed by user.iam not finding method something like getkeychar() ...

I agree. Here's the link:
subject: Canvas direct text input (TextBox alternative)
It's not a secret anymore!