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
rampelotti
Posts: 66
Registered: ‎05-26-2010
My Device: 9000 Bold

Problems when change background image

Hello Experts!

 

I have some problems when i try to change my background.

 

Well the problem is the performance, i have a menu that i likely to change my background image when i set focus on any button, for example when i focus the button settings i likely to show a picture with shafts,,, when i focused the button called start i like to change the background some landscape.

 

Well, i do it when my button receive the focus, to update layout to change the background, but it's so unperformed

 

Somebody can help me?

 

Regards, Ronaldo. 

Please use plain text.
Developer
chengbang69
Posts: 62
Registered: ‎01-22-2010
My Device: BOLD 9700

Re: Problems when change background image

perhaps post a few line of codes so we can see how you are doing it

Please use plain text.
Developer
laliux
Posts: 73
Registered: ‎07-16-2009
My Device: Bold

Re: Problems when change background image

How you are creating the background? BackgroundFactory ?

Please use plain text.
Regular Contributor
rampelotti
Posts: 66
Registered: ‎05-26-2010
My Device: 9000 Bold

Re: Problems when change background image

[ Edited ]

Hello chengbang69!

 

here some lines of my code:

 

 

...
// Auxiliar class to load images to memory
public class Utils {
         public static final Background backs[] = new Background[] {
		BackgroundFactory.createBitmapBackground(Bitmap.getBitmapResource("about.gif"))
	 };
}
...

At Main Screen:
...
        link = new ButtonField("About", _caret) {
	        protected void onFocus(int direction) {
	        background = Utils.backs[0];
                UiApplication.getUiApplication().invokeLater(new Runnable(){
	          public void run() {
		          updateLayout();
		  }
	         });
	        super.onFocus(direction);
	     }
	};
	link.setChangeListener(new FieldChangeListener() {
		public void fieldChanged(Field field, int context) {
			UiApplication.getUiApplication().pushScreen(new AboutScreen());
		}
	});

...
protected void sublayout(int width, int height) {
		super.sublayout(width, height);
		getMainManager().setBackground(background);

	}
...

 Well, i hope that helps.

 

 

 Regards, Rampelotti

Please use plain text.
Regular Contributor
rampelotti
Posts: 66
Registered: ‎05-26-2010
My Device: 9000 Bold

Re: Problems when change background image

Hello laliux!

 

Thank for reply, so i´m use BackgroundFactory, you can see how i use it on the last reply.

 

I´m waiting for some help..

 

Regards, Rampelotti.

Please use plain text.
Developer
geeneeus
Posts: 80
Registered: ‎09-12-2009
My Device: Bold 9700

Re: Problems when change background image

[ Edited ]

You will need to lock the event thread (temporarily) when invoking a method from a different thread.

 

(EDIT: This only applies to when updating the GUI, you do not need to lock the event thread when you do other operations.)

 

REMEMBER: Only lock the event thread for a very short time as it can lock up the application.

 

Here is the sample:

 

 

synchronized(Application.getEventLock()){
	updateLayout();
}

 

Hope this helps!

 

Genius Development Scotland
Website: http://www.genius-dev.co.uk
Please use plain text.
Regular Contributor
rampelotti
Posts: 66
Registered: ‎05-26-2010
My Device: 9000 Bold

Re: Problems when change background image

Hello geeneeus!

 

Thanks for reply.

 

I will test this tip and post my results later.

 

Regards, Rampelotti.

Please use plain text.
Developer
ekke
Posts: 1,520
Registered: ‎04-08-2010
My Device: Z10 (red Limited Edition), Q10, Z30
My Carrier: Telekom.de, O2, Vodafone

Re: Problems when change background image

in my NavigatorScreen I'm doing something similar using some focusable bitmaps.

and if a bitmap gets focus I simply do

getMainManager().setBackground(xxx)

works great - no performance problem

 

ekke

-------------------------------------------------------------------------------
ekke (independent software architect, rosenheim, germany)

BlackBerry Elite Developer
International Development Mobile Apps BlackBerry 10 Cascades
Cascades - Workshops / Trainings / Bootcamps

Open Source Enthusiast
blog: http://ekkes-corner.org videos: http://www.youtube.com/user/ekkescorner
bb10-development: http://appbus.org Twitter: @ekkescorner
Please use plain text.
Developer
laliux
Posts: 73
Registered: ‎07-16-2009
My Device: Bold

Re: Problems when change background image

I'm using the following code to replace a background,

 

FocusChangeListener focusChangeListener = new FocusChangeListener(){
public void focusChanged(Field field, int eventType) {
if(eventType == FocusChangeListener.FOCUS_GAINED){
ClipartButtonField bgButton = (ClipartButtonField) field;

Bitmap bitmapBackground = Bitmap.getBitmapResource(bgButton.getClipartName());

Background background = BackgroundFactory.createBitmapBackground(bitmapBackground, 0, 0, Background.REPEAT_BOTH);


//Custom method for getting the Manager to apply new Bg
getMainManager().setBackground(background);
getMainManager().invalidate();

}
}

};

 

 

I'm not using invokeLater() or sublayout() methods. I hope this help.

 

Greetings

Please use plain text.
Regular Contributor
rampelotti
Posts: 66
Registered: ‎05-26-2010
My Device: 9000 Bold

Re: Problems when change background image

[ Edited ]

Hi geeneeus...

 

So, i have done what you said but doesn´t  increased my performance, then it´s not the solution for me yet.

 

Do you have more suggestion.

 

Regards, Rampelotti

Please use plain text.