BlackBerry - waiting screen [closed]
i am developing one application in blackberry java development. I am requesting to http means i am connecting to web service .response of web service taking some time .That time i want to display some waiting screen.
Could you tell me how can i do that....
Regards Pankaj Pareek
Basically you need to start the network request in a background thread. Once the network operation is complete you should notify the main/UI thread to change the waiting screen into the results.
To notify the main thread have a look at the link below and search for invokeLater
:
http://developers.sun.com/mobility/midp/articles/blackberrydev/
Word of advice: Don't spawn to many threads at once on mobile devices. Usually they have a really low maximum number of threads.
It's already here:
Stackoverflow - Blackberry - Loading screen with animation
Stackoverflow - Blackberry - Application loading screen
Do one thing.... At the listner event of button write this.
UiApplication.getUiApplication().invokeLater(new Runnable(){
public void run(){
Status.show("Please Wait....",b,3600);
message.setText(test(theFile));
}
});
I created a custom animated bitmap field, like this:
//thread class
public class AnimatedImageField extends BitmapField implements Runnable
{
private Thread thread = null;
private boolean animate=true;
private int interval = 0;
private int index=0;
private Bitmap bitmap = null;
private int frameno = 0;
private int fieldHeight=0;
private int fieldWidth=0;
private Bitmap finalbitmap = null;
private int imgHeight = 0;
private int imgWidth= 0;
public AnimatedImageField(int fieldwidth, int fieldheight, Bitmap bitmap, int frameno, int interval, long style)
{
super(bitmap, style);
this.interval=interval;
this.bitmap=bitmap;
this.frameno=frameno;
imgHeight = bitmap.getHeight();
int imgwidth = bitmap.getWidth();
imgWidth=imgwidth/frameno;
this.fieldWidth = fieldwidth;
this.fieldHeight = fieldheight;
}
public AnimatedImageField(Bitmap bitmap, int frameno, int interval, long style)
{
super(bitmap, style);
this.interval=interval;
this.bitmap=bitmap;
this.frameno=frameno;
imgHeight = bitmap.getHeight();
int imgwidth = bitmap.getWidth();
imgWidth=imgwidth/frameno;
fieldWidth = imgWidth;
fieldHeight = imgHeight;
}
protected void paint(Graphics graphics){
graphics.setColor(Color.WHITE);
graphics.fillRect(0,0,this.getPreferredWidth(), this.getPreferredHeight());
//System.out.println("animate:"+animate);
if ( animate )
graphics.drawBitmap((fieldWidth-imgWidth)/2, (fieldHeight-imgHeight-50)/2,
imgWidth, bitmap.getHeight(), bitmap , imgWidth*index, 0);
else
graphics.drawBitmap((fieldWidth-finalbitmap.getWidth())/2, (fieldHeight-finalbitmap.getHeight()-50)/2,
finalbitmap.getWidth(), finalbitmap.getHeight(), finalbitmap , 0, 0);
}
public int getPreferredWidth()
{
return fieldWidth;
}
public int getPreferredHeight()
{
return fieldHeight;
}
protected void layout(int arg0, int arg1)
{
setExtent(getPreferredWidth(), getPreferredHeight());
}
public void startAnimation(){
//System.out.println("startAnimation");
animate=true;
thread = new Thread(this);
thread.start();
}
public void updateLayout(int height, int width){
//System.out.println("updateLayout:height:"+height);
this.fieldHeight=height;
this.fieldWidth=width;
super.updateLayout();
}
public void stopAnimation(Bitmap bitmap){
//System.out.println("stopAnimation");
this.finalbitmap=bitmap;
animate=false;
}
public void stopAnimation(){
//System.out.println("stopAnimation");
animate=false;
}
public void run(){
while(animate){
//System.out.println("run:animate:"+animate);
try{ Thread.sleep(interval);}catch(Exception e){}
if ( index+1>=frameno )
index=0;
else
index++;
invalidate();
}
}
}
call from : //loading
Bitmap load_icon = Bitmap.getBitmapResource("loading.png");
AnimatedImageField spinner = new AnimatedImageField(Display.getWidth(), Display.getHeight(), load_icon,
12, 100, Field.FIELD_HCENTER | Field.FOCUSABLE
| Field.FIELD_VCENTER);
spinner.startAnimation();
add(spinner);
精彩评论