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
Regular Contributor
IpiRon
Posts: 75
Registered: ‎10-19-2011
My Device: Developer
Accepted Solution

Implement scaled bitmap as background for MainScree

Newbie here. Okay, I know there is a lot out there on this as I have just spent the better part of the holiday weekend trying to get this done. Here is what I'm trying to do:

 

1. I have a bitmap png file that is large enough to accomodate the largest screen size.

2. I need the title bar on a MainScreen.

3. I need to bitmap to scale down to fit the existing device's remaining no-scroll area as the background.

4. I am running OS 5.0 or above (am NOT interested in 4.x implementations)

5. Would like to use the setBackground(BackgroundFactory... stuff if possible.

 

First stuff I tried:

1. I can get the scaling done by using a routine I found in the posts that sizes an encoded image. This seems to work okay but it takes Display.getWidth and Display.GetHeight as parameters and the height will be off since it includes the height of the title bar.

2. I can pass the scaled bitmap to the setBackground(BackgroundFactory... stuff okay.

 

The problem is that the bottom of the image is cropped off by what appears to be the height of the title bar. So I then went on a safari trying to find a way to determine the height of the Title Bar. Was able to get the height by overriding the sublayout method as in one of the posts. This is nice but the sublayout doesn't fire until after the screen constructor which is where I would need the value to adjust the scaling. I also tried the override of the paint method (both in the screen and in a nifty seperate VerticalFieldManager(Thx to BB_DUDE).

 

I'm stumped not to mention frustrated as you can guess. Surely this issue has been correctly solved for a 5.0 installation? I realize I'm a newbie but I am at a loss to continue. I've seen all the posts that just say 'searching will give you an answer'. I've been searching for two days!. What I do not understand is why the background doesn't lie underneath the title bar? (It lies underneath everything else!!!!). I understand the approach of defining an new VFM but I still couldn't get that to work either. All the implementation from the posts that I've tried still have the image cropped at the bottom. There must be something obvious that I'm overlooking. It just can't be this hard! I'm at the point of forgetting about the title bar and building my own which will sit on top of the background

 

Any help would be appreciated!! (Yes, I've seen the MainScreen Explained as well).

Regular Contributor
IpiRon
Posts: 75
Registered: ‎10-19-2011
My Device: Developer

Re: Implement scaled bitmap as background for MainScree

Okay, after dinner, drinks and meditation I revisted the issues. Here is my status:

 

My first implementation was:

 

this.getMainManager().setBackground(BackgroundFactory.createBitmapBackgroundUtilities.GetBackgroundImage));

 

where Utilities.GetBackgroundImage() is my support method to:

 

EncodedImage eImage = EncodedImage.getEncodedImageResource("bottomlogobackground.png");

EncodedImage sImage = Utilities.SizeImage(eImage,Display.getWidth(),Display.getHeight());

return sImage.getBitmap();

 

I believe my mistakes to be:

 

a. The encoded image and size image logic was taken from some forum posts. I miss-interpreted that the scaling must occur prior to the call to BitmapFactory.createdBitmapBackground() method.

b. The 'oversight' was me not recognizing that the BackgroundFactory.createBitmapBackground() method has an overload to allow not only the x-y alignments but the 3rd parameter to indicate scale to fit!!! DOH!

 

My successful implementation is:

 

Bitmap backgroundBitmap = Bitmap.getBitmapResource("bottomlogobackground.png");

 

this.getMainManager().setBackground(BackgroundFactory.createBitmapBackground(backgroundBitmap,Background.POSITION_X_LEFT,Background.POSITION_Y_TOP,Background.REPEAT_SCALE_TO_FIT));

 

I do not need to do any scaling prior to the call so I can eliminate my 'Utilities' support routines. This seems to work okay. Also, this is all done against the default non-scrollable vertical field manager, i.e. I did not have to create a subordinate VFM.

 

If anybody knows of any flaws in the above, let me know. It seems to work fine. I will be proceeding with additional GUI development now (no doubt I'll have other newbie faux pas!)

 

Thanks for the ear...