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
misty83
Posts: 745
Registered: ‎01-04-2009
My Device: 8300, 8800, 8700f, 9000
Accepted Solution

blinking spots

hi, i've got such a problem.

When my application connects to server, theres is an information for the user (textField) "Connecting, please wait"

and what i need to do is three blining spots at the end. i mean-till connection is sucessfull i need one spot to appear every second. when there are 3 spots, they should dissapear, and again one spot, second, third..

 

i tried to add Timer which will add one spot every second to the TextField. i add this Timer in the constructor of TextField. but it does not work at all..

 

 

is there more simply way to do that?

 

kind regards

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

Re: blinking spots

Try something like this. Please note this is just example.

import net.rim.device.api.ui.container.MainScreen; import java.util.*; import net.rim.device.api.ui.component.RichTextField; class mainScreen extends MainScreen { Timer timer; RichTextField rtf; public mainScreen() { rtf = new RichTextField("Waiting"); add(rtf); timer = new Timer(); timer.schedule(new RemindTask(),1000,1000); } int i =0; class RemindTask extends TimerTask { public void run() { i += 1; rtf.setText("Waiting"+"....".substring(0,i%4)); } } }

 


Use Search. "Accept Solution" If the problem is resolved.
Please use plain text.
Developer
simon_hain
Posts: 15,806
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: blinking spots

don't forget to synchronize on the eventlock or use invokelater, a timertask does not run on the main event thread.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
Rajat_10Sep
Posts: 696
Registered: ‎12-02-2008
My Device: Not Specified

Re: blinking spots

Hi,

 

I am providing some code below , I use this code to generally implement Splash in my application ,I think you can use this code to show your "Wait Message"

 

-------------------------------------------------------------------------------------------------------------------class ProgressBar extends Thread{
    private int maximum, timeout;
    private boolean useful;
    private PopupScreen popup;
    private GaugeField gaugeField;
    DataClass objData = null;
    ProgressBar(int maximum, int timeout){
        objData = new DataClass();
       
              objData.initializeData();
          
           this.maximum = maximum;
           this.timeout = timeout;
          
          /* DialogFieldManager manager = new DialogFieldManager(){
               public void paint(Graphics g)
               {
                    g.setBackgroundColor(Color.TOMATO);
                    g.clear();
                    super.paint(g);
               }
               };

           popup = new PopupScreen(manager);
          
           gaugeField = new GaugeField("Loading...", 1, maximum, 1, GaugeField.PERCENT);
        
           manager.addCustomField(gaugeField);*/
    }

     /**
     * run() method for starting thread
     */

   public void run()
   {
        useful = true;

        UiApplication.getUiApplication().invokeLater(new Runnable(){
            public void run(){
                //UiApplication.getUiApplication().pushScreen(popup);
            }
         });

           int iterations = 0;

         while (useful){
            try{
                Thread.sleep(timeout);
            }catch (Exception e){
            }
           
            if (++iterations > maximum)
                remove();
            /*if(useful){
                //gaugeField.setValue(iterations);
            } */  

       }
       
        System.out.println("exiting....");
        // if (popup.isDisplayed())
         //{
            System.out.println("exiting....");
           
            UiApplication.getUiApplication().invokeLater(new Runnable()
            {               
                public void run()
                {
                   // UiApplication.getUiApplication().popScreen(popup);
                    //UiApplication.getUiApplication().pushScreen(new PizzaNameScreen());
                    UiApplication.getUiApplication().pushScreen(new StartingScreen(objData));
                   
                    //UiApplication.getUiApplication().pushScreen(new AlertScreen());
                }
            });
        // }
  }

     /**
     * Method to shutdown the thread and remove the popup screen
    * 
    */

public synchronized void remove()
   {
            useful = false;
   }
}

 

-----------------------------------------------------------------------------------------------------------

 

Comment out the code which you do not require.

 

Please let me kow if you have any query.

 

Regards,

Rajat Gupta.

___________________________________________________________________________________________________

If your issue solved, please resolve this thread. Set "Solution" mark on the post which contains the answer to your question. Thanks. Please If I successfully help you with an issue, thank you for clicking "kudos" in my post

 

Regards,
Rajat Gupta.
--------------------------------------------------------------------------------
If your problem was get solved then please mark the thread as "Accepted solution" and kudos - your wish
Please use plain text.
Developer
mreed
Posts: 1,041
Registered: ‎07-16-2008
My Device: ಠ_ಠ

Re: blinking spots

I would go with what BBDeveloper suggested, along with simon's comment, plus remember to cancel and clear the timer task once you are done with it.
Please use plain text.
Developer
misty83
Posts: 745
Registered: ‎01-04-2009
My Device: 8300, 8800, 8700f, 9000

Re: blinking spots

ok, i know that i can synchronize thread like this:

 

synchronized(_thread){

_thread.start()

}

 

but how can i synchronize TimerTask?

 

 

Please use plain text.
Developer
misty83
Posts: 745
Registered: ‎01-04-2009
My Device: 8300, 8800, 8700f, 9000

Re: blinking spots

cause the spots works as i wanted, but now it is blocking the rest of my application..
Please use plain text.
Developer
misty83
Posts: 745
Registered: ‎01-04-2009
My Device: 8300, 8800, 8700f, 9000

Re: blinking spots

i tried:

 

public
void run(){

 

Object _eventLock =
new Object();

synchronized(_eventLock){

_i += 1; _textField.setText("Wait"....".substring(0, _i%4));

}

 

}//end of run

 

and also:

 

public void run(){

 

 

synchronized(Application.getEventLock()){

_i += 1; _textField.setText(" "+_string+"....".substring(0, _i%4));

}

 

}//end of run

 

 

but it won't work. i mean-spots appear, but my application is frozen :/

Please use plain text.
Developer
peter_strange
Posts: 19,595
Registered: ‎07-14-2008
My Device: Not Specified

Re: blinking spots

[ Edited ]

Simon said "synchronize on the eventlock"

 

This means, in the section of code when you update the UI Component, you need to make sure that it is only you updating it, so you put that bit of code in a sychronized block using the event lock, for example:

 

synchronized(Application.getEventLock())  {

....

}

 

The alternative is to use invokeLater or invokeAndWait, which have higher overhead especially when you are only updating one Field.

 

Edit: Apologies, I see that is what you have tried.  Ignore the above, I will need to look at this a bit more.

Message Edited by peter_strange on 03-04-2009 09:36 AM
Please use plain text.
Developer
misty83
Posts: 745
Registered: ‎01-04-2009
My Device: 8300, 8800, 8700f, 9000

Re: blinking spots

but i tried this (see my previous post)
Please use plain text.