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
Developer
Posts: 19
Registered: ‎07-26-2011
My Device: Storm 2 9550
My Carrier: GCI
Accepted Solution

Reloading a saved screen loads everything except my stretched background

[ Edited ]

Greetings and salutations fellow developers, se here's some specifics before I get onto the main question.  I use the BlackberryJDE 5.0 in Eclipse and have made an app for Storm2 9550, and all four torch models.  The display size of the storm2 is 480x360, the torch 9810 is 480 x 640, and the torch 9850 is 800x480.

 

Thanks to the api documentation on bitmaps I use a simple method that restretch my bitmaps as needed here

 

          static Bitmap torch9850 = new Bitmap (480,800);
	  static Bitmap torch9810 = new Bitmap (480,640);
	  
	  public static Bitmap stretch9810(Bitmap bm)
	  {
		  bm.scaleInto(torch9810, Bitmap.FILTER_BILINEAR);
		  return torch9810;
	  }
	  public static Bitmap stretch9850(Bitmap bm)
	  {
		  bm.scaleInto(torch9850, Bitmap.FILTER_BILINEAR);
		  return torch9850;
	  }

 So as you play the game I want you to be able to keep current level progress, making this call every so often

	    Utility.lvl1Screen = UiApplication.getUiApplication().getActiveScreen();  

 This next part works perfect for any display with 360x480 pixels.  This if statement loads the saved screen if it has been played.

if (!Utility.oneTrue)
{
	Utility.pushScreen(new LevelOneScreen());
	UiApplication.getUiApplication().popScreen(this);
 }
 else
{
	UiApplication.getUiApplication().pushScreen(Utility.lvl1Screen);
	UiApplication.getUiApplication().popScreen(this);
}

 

but if the game is playing on a phone with a bigger display it only shows the bitmaps on top of the background that didn't get stretched and not the background itself.  By saving active screen we saved all progress all current displayed bitmaps except the stretched background. It seems like it can't reproduce streched screens.

 

Is there anyone with knowlege of this specific problem who could shed some light on me?

 

 

I believe the problem may stem from my paint code here.

public void paint(Graphics g) 
{
	 Ui.getUiEngineInstance().setAcceptableDirections(Display.DIRECTION_PORTRAIT);
	 if (Utility.SCREEN_HEIGHT > 600 && Utility.SCREEN_HEIGHT < 700 && stretch) 
	{
		bg = Utility.stretch9810(bg);
		stretch = false;
	}
	else if (Utility.SCREEN_HEIGHT > 750 && Utility.SCREEN_HEIGHT < 850 && stretch) 
	{
		bg = Utility.stretch9850(bg);
		stretch = false;
	}
g.drawBitmap(0, 0, Utility.SCREEN_WIDTH, Utility.SCREEN_HEIGHT, bg, 0, 0);
	g.drawBitmap(bm1h, bm1v, bm1.getWidth(), bm1.getHeight(), bm1, 0, 0);
.
.     //Omitted code
.
}

 Thanks in advance.

 

 

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Reloading a saved screen loads everything except my stretched background

Before looking at your problem, I have a couple of suggestions and I suspect if you follow them, then your problem may go away.

 

Firstly, you can't really do this in paint:

Ui.getUiEngineInstance().setAcceptableDirections(Display.DIRECTION_PORTRAIT);

 

If you want to force this, then do it once when your Application starts up and before you push any screens. 

 

Secondly, you should not really resize Bitmaps in paint (I know you only do it once, but even so).  Instead I would do this in the layout or sublayout call, because at that time you know the orientation and the size.  So create your scaled Bitmap in sublayout and then just drawBitmap() in paint().

 

Thirdly this seems like a bit of a waste:

static Bitmap torch9850 = new Bitmap (480,800);
static Bitmap torch9810 = new Bitmap (480,640);

I might be wrong, but my understanding is that this will allocate RAM for the Bitmap, at 3 or 4 bytes a pixel that is a reasonable amount of unused space. 

 

As noted above, I would create a bg Bitmap, in sublayout, the size I wanted and paint() will just paint that,

 

Finally on onto your problem.  I suspect it is simply that you are saving the state of stretch but saving the original Bitmap and not the resized one.  Instead of using stretch to detect if you need to rescale, you could use the Display width and height and compare these with the scaled bitmap width and height.  If they don't match, then you need to scale.  Saves having a flag that you need to keep in sync.

 

Hope this helps. 

Developer
Posts: 19
Registered: ‎07-26-2011
My Device: Storm 2 9550
My Carrier: GCI

Re: Reloading a saved screen loads everything except my stretched background

Thank you much Peter, your suggestion was correct.  You pointed out my useless code I need to do some house cleaning this is the method that actually gets that to work that runs in MyApp class.

int directions = net.rim.device.api.system.Display.DIRECTION_PORTRAIT;
net.rim.device.api.ui.Ui.getUiEngineInstance().setAcceptableDirections(directions);

 I'm always finding solutions and leaving garbage in my code.  I need to look into your comment here.

 

"Thirdly this seems like a bit of a waste:

static Bitmap torch9850 = new Bitmap (480,800);
static Bitmap torch9810 = new Bitmap (480,640);

I might be wrong, but my understanding is that this will allocate RAM for the Bitmap, at 3 or 4 bytes a pixel that is a reasonable amount of unused space. "

 

If this is true than I will want to find a different way, the game doesnt take up too many system resources but for games later on this will get in the way.  This is the simplest way RIM suggest to re size bitmaps in the Bitmap API documentation.

 

Thanks again, I really appreciate it.