02-01-2011 01:47 PM
Hi All,
I am new to the BB world, and have started development some time back. I am developing an app for BB OS version 4.2 to 4.7.
I have ran into the problem on smart phones with touch capability. My app launches well in the portrait mode and while I am in the portrait mode on the app, if I switch to landscape mode the Title bar of my app would not extend to the length of width of the screen in the landscape mode. But when in this situation I hit return key, the Title bar would extend to the full width of the screen.
Also,if I launch my app in the landscape mode and switch to the portrait mode, the Title bar resets itself and there is no problem.
Kindly help me BB gurus......
Below is the snippet of code:-
02-01-2011 06:30 PM
For 4.7+, sublayout(int new_width, int new_height) gets called when the orientation changes while the screen has the focus. layout() does not get called when the orientation changes.
02-01-2011 06:50 PM
WellI changed the method from layout to sublayout() and impelemented it with the previous code posted. But it does not work properly.
What the code does is, when I start the app in portrait mode the title bar stretches perfectly to fit the screen width, but now as soon as I tilt to the landscape mode, the title image does not stretch full....but if i hit return key (the one next to menu key), the image stretches itself to the width of the orientation.
Thanks for the help...
02-01-2011 06:56 PM
Use sublayout to detect an orientation change (the easiest way I found is to save the width when I last layed out the screen, then compare that in sublayout with the current width. If there is a change, then you need to relayout the screen.
Here is typical sublayout that I will use:
protected void sublayout(int width, int height) {
if ( _screenWidth != Display.getWidth() ) {
createScreen();
}
super.sublayout(width, height);
}
createScreen is also called from the constructor - in there I do everything that is width specific. In your case, you might want to replace the title to make sure it is re-laid out.
Perhaps this 'structure' will help you get over your problem?
02-01-2011 08:48 PM - edited 02-02-2011 06:51 AM
edit: I think it would be better to use the parameters rather than getting the dimensions some other way:
protected void sublayout(int new_width, int new_height) {
setExtent(saved_width = new_width, saved_height = new_height);
setPosition(0, 0);
/*
Then call layout() and setPositionChild() for everything directly under this Manager.
Each of those items must do its own setExtent() in its own layout()
*/
// edit:
super.sublayout(new_width, new_height); // lay out working fields
// Then, if you're using a custom title field on a FullScreen:
layoutChild(title, new_width, new_height / 12); // or whatever height
setPositionChild(title, 0, 0);
}
Then, overriding layout() is probably not necessary, since it's supposed to call sublayout().
02-02-2011 04:57 AM
Not sure if this was directed at my response:
"Why try to get the correct new dimensions from somewhere else"
Assuming it was directed at my post, I suspect you have misread it. The processing uses the change in the value to detect an orientation change, not to process it.
Also as far as I know, in general for sublayout, the values passed in are the maximums available, and may, not be related to the Screen dimensions.
Also, since this user does not actually wish to control the layout, I would have thought you should allow it to call super.sublayout, not just immediately impose an extent based on the maximums that this will have been supplied. But this is not an area of expertise.
02-02-2011 06:23 AM - edited 02-02-2011 06:41 AM
You're right, I did misread it (s0rry), but I was looking more at bobby's getPreferredWidth and getPreferredHeight in sublayout rather than using the parameters. They're probably the same for a FullScreen, but assuming the BB OS is updated someday and the app may eventually be in a window or virtual screen of some sort instead of the entire display, it seems better IMO not to assume it actually got the same maximums it asked for. Even now, I think on a MainScreen the sublayout is the display size minus the title bar, because it's the Manager not the Screen doing the sublayout, and that's the VerticalFieldManager under the title. Might as well get into the habit of doing it in a way compatible with everything. A PopupScreen would be even worse, if it comes up as 80% width and height, but the app lays it out like it's got the entire display.
super.sublayout(), I'm not even sure it does anything -- does it? The javadoc sounds like it's there only for "custom formatting". Think every app where I've had to handle orientation changes myself was something where I was doing all my own drawing, in Manager.paint() or one big BitmapField, so all I had to do was update my dimension variables and paint took care of the rest.
edit: I was probably misreading the javadoc also (guess I need more sleep). Obviously you're right, super.sublayout() should be called in this case, but I'd follow it up by laying out the title field explicitly in view of the problem. Also, bobby, shouldn't the class variables being set in your sublayout() be named differently than the parameters? As-is, does that really work? I'd have thought it would have tried setting the parameter variables rather than the class variables.
02-02-2011 11:51 AM
Thanks guys for this discussion..I shall try to implement both the ways one by one...and post my reply...but as I am just a new-bee I have not got command over the GUI stuf.....
02-02-2011 02:02 PM
Well i used the sublayout(int width, int height), but it gives me JVM Error 104 illegal state exception.
Here is the snippet of the Code
public class MYAPP extends Fullscreen
Thanks guys for helping me earlier....If you gurus can help me a bit more it would be great.....