Listening for touches

72 views
Skip to first unread message

Theodore Norvell

unread,
Aug 20, 2013, 3:24:04 PM8/20/13
to codenameone...@googlegroups.com
Is there a good way to listen for touches on a Component?  If I touch a component with my finger, presumably a series of events is created that can be listened to, but I can't find the api for this, at least not in ui.Component.  Should I just override pointerPressed and, if so, which one and should I call super.pointerPressed in the override?

As a related question, could someone explain the Touch menu item in the simulator's Simulate menu.  I've found that if I select Touch, click on a spot and then deselect Touch, then pointerPressed is called, but I don't really understand why.

Shai Almog

unread,
Aug 21, 2013, 1:56:39 AM8/21/13
to codenameone...@googlegroups.com
If you need to "do" something the convention is pointer released but you can override pressed/dragged etc. Normally we use the ones that accept int not an array unless we specifically need the multi-touch functionality.
Touch is supposed to block touch support for feature phone simulation, its not very useful though.

What are you trying to accomplish?
Generally touch API's are pretty low level and you can often accomplish almost anything using higher level API's.

Theodore Norvell

unread,
Aug 21, 2013, 11:01:02 AM8/21/13
to codenameone...@googlegroups.com
My problem was that I wasn't calling repaint and so it looked like my listeners weren't doing anything in response to the events, when in fact they were.


On Wednesday, August 21, 2013 3:26:39 AM UTC-2:30, Shai Almog wrote:

What are you trying to accomplish?
 
Broadly, what I'm trying to accomplish is to understand better how the ui framework works and how best to use it.  At this point I'm trying to figure out how to duplicate the kind of functionality that swing gives with MouseListeners and MouseMovement
 
Generally touch API's are pretty low level and you can often accomplish almost anything using higher level API's.

Where are the higher level API's?

Shai Almog

unread,
Aug 21, 2013, 12:29:03 PM8/21/13
to codenameone...@googlegroups.com
In Swing you would generally try to avoid paint and mouse listener in favor of the Drag & Drop API, Component & container hierarchies.
The same would be true for Codename One.

But Codename One offers a richer way than Swing to customize nearly everything. E.g. you can flag a component as draggable. You can customize it via the style and theme (so you don't need paint for most stuff). You can also use painters (like in SwingX) so you don't even need to inherit the component. Think of it as a low level API (graphics and physical hardware events) vs. high level abstractions (components and logical events such as action event, drag events etc.). The latter is easier and more portable, its often faster due to our optimizations.

Theodore Norvell

unread,
Aug 21, 2013, 2:58:37 PM8/21/13
to codenameone...@googlegroups.com


On Wednesday, August 21, 2013 1:59:03 PM UTC-2:30, Shai Almog wrote:
In Swing you would generally try to avoid paint and mouse listener in favor of the Drag & Drop API, Component & container hierarchies.
The same would be true for Codename One.

This is true.  But, I have a large application already written running on JavaSE.  It uses overrides of paintComponent and  MouseListener.  We are looking to build a bridge to allow it to run on CodeName One as well. Thus I'm trying to understand the architecture at a low level as well as a high level.
Reply all
Reply to author
Forward
0 new messages