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. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
New Developer
zookie
Posts: 54
Registered: ‎01-24-2009

Did RIM give us this or do we have to code ourself?

I have run over some of the hundreds of posts on this subject, but I'm after a specific result and just need some direction.

 

My MainScreen calls a function which starts a thread, connects to a web server, retrieves data, and then displays in a RichTextField.

 

I would like to display a box exactly like Figure two in the following link.

 

http://docs.blackberry.com/en/developers/deliverables/6625/Progress_indicators_2_0_514034_11.jsp

 

I want to show this box just before I start the thread that connects to the web server.  Then, I would like to get rid of the box just before the returned data (from web server) is sent to RichTextField.

 

Was RIM kind enough to give us an easy way to make this "Please Wait..." progress indicator?

 

If not, can someone give me some direction here to recreate?  I'd like it to look exactly like that Please Wait indicator so as to keep the Blackberry "feel".  I've read about Dialog and GuageField.  Not quite clicking for me yet.  Is that Please Wait shown in the above link just a GuageField?  Or is it a screen or DialogFieldManager?  I don't want to cover the entire screen with another screen, just want that popup exactly like in the link.

 

 

 

Please use plain text.
Developer
BBDeveloper
Posts: 3,951
Registered: ‎07-15-2008

Re: Did RIM give us this or do we have to code ourself?

Implementing a callback mechanism where it tells you about the status of the thread connecting to web and using this information updtae your UI.


Use Search. "Accept Solution" If the problem is resolved.
Please use plain text.
New Developer
zookie
Posts: 54
Registered: ‎01-24-2009

Re: Did RIM give us this or do we have to code ourself?

I kind of know when the network thread is done.

 

When my function that calls the network thread starts, that's when I would like to display the progress indicator.  I have another function that is called from the network thread that receives the results and inserts them into a RichTextField.  So, just before that RichTextField.setText() call, I would like to close the progress indicator.

 

The bigger question is more on creating a progress indicator that looks exactly like the second image in that link.  The "Please wait.." screen.

Please use plain text.
Developer
zany
Posts: 222
Registered: ‎11-11-2009

Re: Did RIM give us this or do we have to code ourself?

i think this sample code will solve your problem

 

 

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.*;

class FloatingScreenMain extends UiApplication {
    private CustomPopupScreen _popup;

    public static void main( String[] args ) {
        FloatingScreenMain app = new FloatingScreenMain();
        app.enterEventDispatcher();
    }

    FloatingScreenMain() {   
        _popup = new CustomPopupScreen(this);
        UiApplication.getUiApplication().invokeLater( new Runnable() {
            public void run() {
                MyScreen screen = new MyScreen();
                pushScreen (screen);
                pushScreen ( _popup );
            }
        });
    }

    public void closeScreen()
    {
        UiApplication.getUiApplication().invokeLater( new Runnable() {
            public void run() {
                popScreen ( _popup );
            }
        });
    }
}

class MyScreen extends MainScreen{
    public MyScreen()
    {
        super();
    }

    protected void paint (Graphics g)
    {
        super.paint (g);
        g.setColor(Color.ROYALBLUE);
        g.fillRect( 0, 0, Display.getWidth(), Display.getHeight());
    }
}

class CustomPopupScreen extends Screen {

    private final static int _CUSTOM_WIDTH   = 250;
    private final static int _CUSTOM_HEIGHT   = 60;
    private final static int _Y             = ( Display.getHeight() - _CUSTOM_HEIGHT ) / 2;
    private FloatingScreenMain _parent;

    CustomPopupScreen (FloatingScreenMain parent) {
        super (new VerticalFieldManager (Manager.NO_VERTICAL_SCROLL | Manager.NO_VERTICAL_SCROLLBAR));
        _parent = parent;
    }

    protected void sublayout( int width, int height ) {
        setExtent( _CUSTOM_WIDTH, _CUSTOM_HEIGHT );
        setPosition( 25, _Y );
        layoutDelegate( _CUSTOM_WIDTH, _CUSTOM_HEIGHT );
    }

    public int getPreferredWidth()
    {
        return _CUSTOM_WIDTH;
    }

    public int getPreferredHeight()
    {
        return _CUSTOM_HEIGHT;
    }

    protected void paintBackground( Graphics g ) {
        g.setColor( Color.BLACK );
        g.fillRect( 0, 0, getPreferredWidth(), getPreferredHeight());
        g.setColor( Color.WHITE );
        g.drawBitmap(10, 15, 31, 29, Bitmap.getBitmapResource("image.png"), 0, 0);
        g.drawText("Please wait...", 50, 20);
    }

    protected boolean touchEvent (TouchEvent message)
    {
        switch (message.getEvent() )
        {
            case TouchEvent.CLICK:
                _parent.closeScreen();
                return true;
        }

        return false;
    }
}

with regards,
Vignesh J

-------------------------------------------------------------------------------------------------------------------------------------------------------------------
Don't forget to mark your post as solved if you get the answer and dont forget to give kudos if the answer is useful for you.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
Please use plain text.
New Developer
zookie
Posts: 54
Registered: ‎01-24-2009

Re: Did RIM give us this or do we have to code ourself?

zany,

 

This looks like it coud be what I need.  I'm having a problem calling this class though.  I created a new class, then copy and pasted this code.

 

I typically would do the following:

FloatingScreenMain fsmScreen = new FloatingScreenMain();

UiApplication.getUiApplication().pushScreen(fsmScreen);

 

But this gives me an error on the .pushScreen saying cannot find symbol.  I'm assuming this is because FloatingScreenMain extends UiApplication.

 

Do you know how I can call this?

 

Thank you very much for the code!

Please use plain text.
New Developer
zookie
Posts: 54
Registered: ‎01-24-2009

Re: Did RIM give us this or do we have to code ourself?

nevermind.  It's pretty late here and I didn't read the code close enough.  The constructor that extends MainScreen is actually called MyScreen instead of FloatingScreenMain.

 

I'll have to tweak this code, but you definitely got a great start for me.  Thank you again!

Please use plain text.