This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
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


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "Canvas direct text input (TextBox alternative)" Watch "Canvas direct text input (TextBox alternative)" New topic
Author

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?

Cheers,
James
Rashid Mayes
Ranch Hand

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

http://www.tricastmedia.com/twuik/

http://youtube.com/watch?v=2M3GYhMSxrU

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 hostj2me.com from any of the applications below. The interesting classes are TextInputEngine, TextInputListener, and ~TextInputWidget.

http://hostj2me.com/appdetails.html?id=2519
http://hostj2me.com/appdetails.html?id=1557
http://hostj2me.com/appdetails.html?id=1569

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

http://worlddeveloper.org/files/1877/yipi.wmv
http://worlddeveloper.org/files/3799/demo1.wmv
http://worlddeveloper.org/files/4054/meos.wmv

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


Rashid Mayes
http://www.hostj2me.com/ - http://www.worlddeveloper.org/
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
Greenhorn

Joined: Apr 18, 2007
Posts: 16
Hi
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.
net.rim.device.api.system.KeyListener.keyDown()
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() ...

Regards
 
 
subject: Canvas direct text input (TextBox alternative)