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 Contributor
Posts: 6
Registered: ‎08-04-2010
My Device: Not Specified
My Carrier: AT&T

Making a Manager focusable?

Hi,

I need to be able to make a Manager subclass that I can use to layout various non-focusable fields (text, pictures, ect) and have the entire manager function as a single focusable field. Normally I would just extend Field and overload paint() but this field will have wrapped text (via a LabelField) and I can not for the life of me find any useful information on calculating the height of wrapped text (as rendered with Graphics.drawText. My current attempts to make a focusable manager have been met with failure.

 

Anyone have any ideas on how to do either of these things? Thanks,

 

-somtwo

Developer
Posts: 723
Registered: ‎03-12-2009
My Device: Playbook

Re: Making a Manager focusable?

Add a focusable Field to the manager.

 

A lot of people recommend adding a NullField, but that is just an extra object on the heap... make one of your fields focusable and adjust the painting of decor, etc accordingly.

 

 

New Contributor
Posts: 6
Registered: ‎08-04-2010
My Device: Not Specified
My Carrier: AT&T

Re: Making a Manager focusable?

That solution works perfectly!... for everything except the storm version which exhibits major problems when trying to select the field via the touch screen interface. >_<

 

The problem is that I have custom focus drawing behavior, which requires the focus to be drawn under the other fields, however, those fields also block touch screen clicks. Is there a way I can prevent the non-focusable fields from absorbing the click events? Thanks!

Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Making a Manager focusable?

I don't think other fields block touch events - in my application I'm grabbing all such events on the Screen level, find the appropriate field and set "focus" to it (I'm putting "focus" in quotes because I have no FOCUSABLE fields whatsoever and just tell them to paint themselves differently).

 

One piece of advice - even if you process some touch events, always return super.touchEvent() - there is much more going on behind the scenes than we might imagine.

 

For example, I found the hard way that processing DOWN events and "swallowing" them (returning true) disrupts the processing of gestures (which all start with a DOWN event!) which are otherwise processed just fine by scrollable Managers (who do not need focus to perform those tasks).

 

And last but not least - welcome to the forums!

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
New Contributor
Posts: 6
Registered: ‎08-04-2010
My Device: Not Specified
My Carrier: AT&T

Re: Making a Manager focusable?

Non-focusable fields don't actually consume the screen clicking events, but they block them from reacing any further back in the manger stack. It seems like a manager will get a click event and search for the first field (from the end of the vector to the start) that lies under the click event, and ONLY checks that field.

 

Managers themselves don't seem to actually respond to input events, they rather route them to their child fields (which, yes, is what they are supposed to do), so I'm really at a loss here. I think I might actually have to write a function to calculate the height of a word-wrapped string so I can simply draw the images and text to a regular field.

 

Also, trying to trap these events screen-level would be very difficult for me because the fields I'm dealing with are about 2 or 3 managers deep inside the screen.

 

Lastly, Thanks! Glad to be here.

Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Making a Manager focusable?

Even if your Manager does not normally consume events, it can catch them using touchEvent (I've seen it happen).  As for the height of a word-wrapped LabelField (or RichTextField, or whatever other descendant of TextField you have there), ask that field about its extent!  Besides, if you want to just change the colors, override paint() in that label field and do something like that:

 

protected void paint(Graphics g) {
  g.setBackgroundColor(<your background color, depending on the "highlighted" state>);
  g.clear(); // took care of the background
  g.setColor(<text color, again depending on the state>);
  super.paint();
}

 

 

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
New Contributor
Posts: 6
Registered: ‎08-04-2010
My Device: Not Specified
My Carrier: AT&T

Re: Making a Manager focusable?

[ Edited ]

I'm trying to avoid overriding framework functions because (as you've alluded to in your other post) this can cause various side-effects. In my experience with UI programming, it's always better to work with the framework than to try to work around it.

 

Although it might work, I'd rather not have to hijack the event routing to avoid running through a string and counting advances, especially when I'm hardly familiar with how the framwork functions...

 

I do appreciate the help though guys!

New Contributor
Posts: 6
Registered: ‎08-04-2010
My Device: Not Specified
My Carrier: AT&T

Re: Making a Manager focusable?

Update: Trying to figure out a decent word-wrapping system wasn't working out for me, so I decided to have another go at the Manager method.

 

This time, I add a single "hot spot" field after all other fields have been added. The hotspot field notifies the manager when focus changes so the manager can draw the background depending on focus. This seems to fix all problems with the Storm touch screen!

 

Thanks again!!