06-10-2010 09:00 PM
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.
06-10-2010 10:25 PM
perhaps post a few line of codes so we can see how you are doing it
06-11-2010 12:14 AM
How you are creating the background? BackgroundFactory ?
06-11-2010 08:38 AM - edited 06-11-2010 08:39 AM
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.ge tBitmapResource("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
06-11-2010 08:45 AM
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.
06-14-2010 09:22 AM - edited 06-14-2010 09:24 AM
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!
06-14-2010 10:01 AM
Hello geeneeus!
Thanks for reply.
I will test this tip and post my results later.
Regards, Rampelotti.
06-14-2010 10:59 AM
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
06-14-2010 12:07 PM
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(bitmapBac kground, 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
06-14-2010 12:47 PM - edited 06-14-2010 12:52 PM
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