Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
Posts: 10
Registered: ‎10-07-2008
My Device: Not Specified

[Storm] Touch events dispatching.

Hello.

I'm a little bit confused by the touch events dispatching in the 4.7 OS.

For example :

I add 5 custom fields to a vertical manager (1,2,3,4 and 5). I implement the touchEvent method in my custom field class like this :

 

 

protected boolean touchEvent(TouchEvent te) {

// do something

return true;
} // end touchEvent

 

If i touch the third field first, everytime I will touch the screen after (even on an other field), this third field will catch the touch event. It seems that the event dispatcher route the event to the last field which catched the last event.

 

If I return false in the touchEvent, the event is well dispatched to the "really touched field" but I want to be able to consume touch events.

I made a really complicated method to detect where in the screen the touch event occured and so on which field. But it can't be the good way to do touch event dispatching.

 

Thanks a lot.

Regards.

 

 

Developer
Posts: 178
Registered: ‎07-29-2008
My Device: Not Specified

Re: [Storm] Touch events dispatching.

My experience with touch event handling is that the first field to be informed of the touch event is the currently selected field.  For finding "real" touch locations manager.getFieldAtLocation() might be helpful.
Highlighted
New Developer
Posts: 10
Registered: ‎10-07-2008
My Device: Not Specified

Re: [Storm] Touch events dispatching.

Ok. Thanks for that answer.

What is a "selected" field ? A field with the focus ?

If it's that it's not really good for me.

The problem with "manager.getFieldAtLocation()" is that I have some fields UNDER some other fields. For example, I can have a manager with a vertical scrollbar and with some fields "hidden" under an "actionbar" at the bottom of the screen.

When I click on the action bar, it's the field under the action bar that catches the touch events.

Developer
Posts: 178
Registered: ‎07-29-2008
My Device: Not Specified

Re: [Storm] Touch events dispatching.

yes, the current field with focus is what my experience was. 

 

Developer
Posts: 43
Registered: ‎12-02-2008
My Device: Curve 8330

Re: [Storm] Touch events dispatching.

Did you ever get a solution to this?  I am experiencing a similar issue.  I have a screen with a listfield on it as well as several other UI components (ObjectChoiceField, LabelField, EditField).  Out of all the components on the screen, only the ListField overrides the touchevent.  If you click on an item in a list field so a list row becomes selected, then the next click (for example, a click on the ObjectChoiceField) still results in a touchevent being called on the ListField.  So, essentially, once you click on that list field, it seems like the focus is stuck there...
Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: [Storm] Touch events dispatching.

Steve,

 

I think that if you look at the actual touch coordinates you will find that some of them (for example, the touch on the ObjectChoiceField) will come to your touchEvent() override with coordinates that are not within the extent of your ListField.

 

You should detect this and explicitly re-delegate these events. This will cause the events to now get picked up by the ObjectChoiceField (or whatever).

 

Developer
Posts: 178
Registered: ‎07-29-2008
My Device: Not Specified

Re: [Storm] Touch events dispatching.

If the touch event doesnt apply to your field you can just call return super.touchEvent(message);  it will get passed around to where it needs to be.
Developer
Posts: 177
Registered: ‎01-21-2009
My Device: 9900
My Carrier: Vodafone

Re: [Storm] Touch events dispatching.

Do a boundry get like this:

 

 

// If the touch was not in the boundry, send it to the super object, // or else return false if you don't want the super to handle it. int downY = msg.getY( 1 ); int downX = msg.getX( 1 ); XYPoint point = new XYPoint( downX, downY ); if ( !getExtent().contains( point ) ) return super.touchEvent( msg );

 

 

 

Developer
Posts: 178
Registered: ‎07-29-2008
My Device: Not Specified

Re: [Storm] Touch events dispatching.

Pwerry  my issue with that option is my experence has shown that msg.getX and msg.getY are in the prospective of the field which was previously selected.

 

I was trying to send touch in a manager to a specific field and found that out painfully.

Developer
Posts: 177
Registered: ‎01-21-2009
My Device: 9900
My Carrier: Vodafone

Re: [Storm] Touch events dispatching.

If you are extending Field, then sending the event to super will cause it to return false. The manager will change the focus if it receives false from the touchEvent on the current focus field, then dispatch the touch event to the new field with the focus. At least that has been my observation, so you should be ok with this.

 

I definitely see the problem though, I had an issue where a ListField was consuming every touch event, and I was returning true from everything. This basically created a scenario where the ListField hijacked the focus from everything.