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
Highlighted
Contributor
Posts: 31
Registered: ‎03-02-2012
My Device: Curve 8900
My Carrier: T-Mobile
Accepted Solution

custom manager sequence; what happens, when?

[ Edited ]

The page on MainScreen mentioned using a custom manager set to USE_ALL_WIDTH, and height, on a FullScreen, in order to get the device screen width and height without a signed key, and without using deprecated code. I did that, and it works. So, I can set some class statics, and use those values throughout my program. All of the other class modules use the values just fine.

 

I have another custom manager, in the same class along with the first. It needs to know screen width. Now, even though I'm creating and initializing the ScreenInfo class member first, in the class constructor, the screen width value is not available at the time the second manager needs it.

 

Could someone enlighten me about this timing issue, and let me know if there's a workaround? Thanks

 

 

Developer
Posts: 17,025
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: custom manager sequence; what happens, when?

these values are only known after a first layout.
you could trigger a second layout where the values are set.
or just use signed classes, after all codesigning is free.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Contributor
Posts: 31
Registered: ‎03-02-2012
My Device: Curve 8900
My Carrier: T-Mobile

Re: custom manager sequence; what happens, when?

Simon, your suggestion makes sense -- but, as a Java & BB newcomer, I'm not sure how or where to trigger another layout. Or, repaint? Use invalidate? (Of course, that did not work from within the constructor, since it is the constructor that needs to finish, to make the value available.)

 

OK, I see now that codesigning is free. I had been working on the basis of it being $20, as it had been. But, also, while I understand the general point of the signing, I have a philosophical problem with requiring signing for something as basic as screen dimensions. And, at this point, I just want to see how to complete the technique I started.

 

Thanks

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

Re: custom manager sequence; what happens, when?

[ Edited ]

You get those values (width and height) each time the screen is laid out. If you override your sublayout, you can use the supplied width and height values and immediately store them somewhere in your class before calling super.sublayout (or before looping over the fields with layoutChild, which is the case for custom layout managers). This is more reliable than using Display.getWidth() and Display.getHeight().

 

In addition, if  you extend a Manager (the abstract class rather than one of the pre-existing classes such as VerticalFieldManager) you'll have to create your own sublayout anyway. In there you honor USE_ALL_WIDTH and USE_ALL_HEIGHT style bits by using the supplied width/height in your setExtent.

 

Edit: as for causing the second layout, use updateLayout (make it conditional in order to avoid an endless chain of re-layouts).

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Contributor
Posts: 31
Registered: ‎03-02-2012
My Device: Curve 8900
My Carrier: T-Mobile

Re: custom manager sequence; what happens, when?

Thanks for the explanation, arkadyz. As far as calling updateLayout, I can't find a place to call it, that makes any difference. I'd like to call it with if (_scrH == 0) updateLayout(), in the sublayout, where I know I've received the needed value. But, I get an error about calling layout from layout.

 

Here's my minimal custom manager, for reference.

 

	public static int _scrW = 0;
	public static int _scrH = 0;


    class UseAllManager extends Manager {
    	
        public UseAllManager() {
            super(Manager.USE_ALL_WIDTH | Manager.USE_ALL_HEIGHT);
        }   
   
        protected void sublayout(int width, int height) {
	        _scrW = width;
	        _scrH = height;
        }
    
        public int getPreferredWidth() {
            return _scrW; //Graphics.getScreenWidth();
        }

        public int getPreferredHeight() {
            return _scrH; //Graphics.getScreenHeight();
        }
    }

 

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

Re: custom manager sequence; what happens, when?

[ Edited ]

Your sublayout should do much, much more than that. It is a centerpiece of any custom layout manager. It should tell each and every field to layout itself, choose positions for its fields and calculate and set its extent (dimensions).

 

Here are a couple of knowledge base articles for starters:

How to Extend Manager

Create a custom layout manager for a screen (check the comment there)

 

As for where to add updateLayout: inside your sublayout, checking whether the sizes are already calculated (fields which have not been laid out before have their widths and heights as 0). However, this is not a good approach at all. A better one properly uses the width and height passed into the sublayout as parameters, lays out the fields in the desired order, asks them for their dimensions after that (so you first call layoutChild and then ask that child about its width and height) and sets their positions accordingly.

 

It is not an easy task unless you implement something totally obvious (such as reimplementing a VerticalFieldManager, though even this can easily go wrong if you are not careful).

 

You can find some very good but quite complicated examples here:

Advanced buttons, fields, and managers

 

Good luck!

 

As for calling layout within layout - wrap your updateLayout() in invokeLater to schedule until it after your sublayout finishes working.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Contributor
Posts: 31
Registered: ‎03-02-2012
My Device: Curve 8900
My Carrier: T-Mobile

Re: custom manager sequence; what happens, when?

Thank you very much, Arkadyz. I never did get the invokeLater to work, even with a proper wrapper I found. I think it's because I was using two custom managers, and not fully understanding what I'm doing.

 

But, with the links you pointed to, and in examining a custom manager I'm already using -- from sample code -- I was able to get the existing manager to do the simple extra job of setting my global height and width for the screen. THAT was much easier than everything else that's been causing trouble.

 

Also, those examples for custom buttons will come in handy. I'm already doing a custom gauge... so, that must make me advanced... har!