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
New Developer
Posts: 2
Registered: ‎01-07-2010
My Device: Not Specified

Display hourglass or a processing dialog box

Hi

I am just starting development on BB and one of my first apps is simple gps program. I can not figure out how to display an hourglass or some sort of other message when the application is searching for sattelites.I know it should be something very simple.

 

Here is my code in case you need it.

 

package demo.gps;


import javax.microedition.location.Criteria;
import javax.microedition.location.Location;
import javax.microedition.location.LocationException;
import javax.microedition.location.LocationListener;
import javax.microedition.location.LocationProvider;
import javax.microedition.location.QualifiedCoordinates;



import net.rim.device.api.ui.UiApplication; 
import net.rim.device.api.ui.component.*; 
import net.rim.device.api.ui.container.MainScreen; 
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.autotext.AutoText; 
 
public class HelloGPS extends UiApplication 
{ 
        public static void main(String[] args) 
        { 
                HelloGPS theApp = new HelloGPS(); 
                theApp.enterEventDispatcher(); 
        } 
        public HelloGPS() 
        { 
                pushScreen(new HelloGPSScreen()); 
        } 
} 
 
final class HelloGPSScreen extends MainScreen 
{ 
	HorizontalFieldManager _fieldManagerInfo;
	HorizontalFieldManager _fieldManagerCheckbox;
	HorizontalFieldManager _fieldManagerOption;
	HorizontalFieldManager _fieldManagerGPS1;
	HorizontalFieldManager _fieldManagerGPS2;
	HorizontalFieldManager _fieldManagerGPS3;
	HorizontalFieldManager _fieldManagerGPS4;
	LabelField _gpsTF1;
	LabelField _gpsTF2;
	LabelField _gpsTF3;
	LabelField _gpsTF4;
	LocationProvider _locationProvider;
	
  public HelloGPSScreen() 
    { 
            super(); 
            _fieldManagerCheckbox = new HorizontalFieldManager();
            add(_fieldManagerCheckbox);
            
            _fieldManagerInfo = new HorizontalFieldManager();
            add(_fieldManagerInfo);
            
            _fieldManagerOption = new HorizontalFieldManager();
            add(_fieldManagerOption);
            
            _fieldManagerGPS1 = new HorizontalFieldManager();
            add(_fieldManagerGPS1);
            _fieldManagerGPS2 = new HorizontalFieldManager();
            add(_fieldManagerGPS2);
            _fieldManagerGPS3 = new HorizontalFieldManager();
            add(_fieldManagerGPS3);
            _fieldManagerGPS4 = new HorizontalFieldManager();
            add(_fieldManagerGPS4);
            LabelField title = new LabelField("HelloWorld Sample", 
                 LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH); 
            setTitle(title); 
     
            CheckboxField check1 = new CheckboxField("Type 1", false);
            CheckboxField check2 = new CheckboxField("Type 2", false);
            CheckboxField check3 = new CheckboxField("Type 3", false);
            _fieldManagerCheckbox.add(check1);
            _fieldManagerCheckbox.add(check2);
            _fieldManagerCheckbox.add(check3);
            
            AutoTextEditField infoT = new AutoTextEditField("Info: ", "");
            _fieldManagerInfo.add(infoT);
            
            String choiceItems[] = {"Option one","Option two","Option three"}; 
            ObjectChoiceField optionCF = new ObjectChoiceField("Options:",choiceItems);
            _fieldManagerOption.add(optionCF);
            
            _gpsTF1 = new LabelField("  Loc 1:");
            _gpsTF2 = new LabelField("  Loc 2:");
            _gpsTF3 = new LabelField("  Loc 3:");
            _gpsTF4 = new LabelField("  Loc 4:");
           
            FieldChangeListener listenerLoc1 = new FieldChangeListener() {
            	public void fieldChanged(Field field, int context) {
            		  markSpot(1);

                    
            	}
            	};

            FieldChangeListener listenerLoc2 = new FieldChangeListener() {
                	public void fieldChanged(Field field, int context) {
                		 markSpot(2);
                	}
                	};
                	
            FieldChangeListener listenerLoc3 = new FieldChangeListener() {
                    	public void fieldChanged(Field field, int context) {
                    		 markSpot(3);
                    	}
                    	};
                    	
            FieldChangeListener listenerLoc4 = new FieldChangeListener() {
                        	public void fieldChanged(Field field, int context) {
                        		 markSpot(4);
                        	}
                        	};
            ButtonField aquire1 = new ButtonField("Aquire");
            aquire1.setChangeListener(listenerLoc1);
            ButtonField aquire2 = new ButtonField("Aquire");
            aquire2.setChangeListener(listenerLoc2);
            ButtonField aquire3 = new ButtonField("Aquire");
            aquire3.setChangeListener(listenerLoc3);
            ButtonField aquire4 = new ButtonField("Aquire");
            aquire4.setChangeListener(listenerLoc4);
            

            
            _fieldManagerGPS1.add(aquire1);
            _fieldManagerGPS1.add(_gpsTF1);
            _fieldManagerGPS2.add(aquire2);
            _fieldManagerGPS2.add(_gpsTF2);
            _fieldManagerGPS3.add(aquire3);
            _fieldManagerGPS3.add(_gpsTF3);
            _fieldManagerGPS4.add(aquire4);
            _fieldManagerGPS4.add(_gpsTF4);
            
    } 
  public void setSpot(double lat, double lng, int num)
  {
  double spotLat = lat;
  double spotLong = lng;
  String latLong = new String(spotLat+", "+spotLong);
  setSpot(latLong, num);
  }
  
  public void markSpot(int num)
  {
	  
	  try
	   {
	   LocationProvider lPvd = LocationProvider.getInstance(new Criteria());
	   lPvd.setLocationListener(new MyLocationListener(this,true,num), 1, 1, 1);
	   }
	   catch (Exception e)
	   {
	   
	   }
  }

public void setSpot(final String locStr, final int num)
  {
	final LabelField lf[] = {_gpsTF1, _gpsTF2, _gpsTF3, _gpsTF4};
  UiApplication.getUiApplication().invokeLater (new Runnable() {
  public void run()
  {
  lf[num-1].setText(locStr);
  }});
  }

  public boolean onClose() 
    { 
        Dialog.alert("Goodbye!"); 
        System.exit(0); 
        return true; 
    } 
  

  private class MyLocationListener implements LocationListener {

	  HelloGPSScreen hg;
	    boolean onceOnly;
	    int num;

	  public MyLocationListener(HelloGPSScreen hg, boolean onceOnly,int num)
	    {
	     this.hg = hg;
	     this.onceOnly = onceOnly;
	     this.num = num;
	    }

	  public void locationUpdated(LocationProvider provider,
	     Location location)
	    {
	     QualifiedCoordinates qc = location.getQualifiedCoordinates();
	     if (onceOnly)
	     {
	     hg.setSpot(qc.getLatitude(),qc.getLongitude(),num);
	     provider.reset();
	     provider.setLocationListener(null, 0, 0, 0);
	     }
	     else
	     {
	     

	  }
	    }

	  public void providerStateChanged(LocationProvider provider,
	     int newState)
	    {

	  }
  }
  }

 

 

Developer
Posts: 212
Registered: ‎07-18-2008
My Device: Storm 9550

Re: Display hourglass or a processing dialog box

the hourglass is for garbage collector only, you could and should not use it.

 

bring up a PopupScreen with a GaugeField in it:

http://www.blackberry.com/developers/docs/5.0.0api/net/rim/device/api/ui/component/GaugeField.html

 

If your problem was solved, please mark answer as "Accepted solution"
If your want to thank, click the "kudo" symbol
___________
visit me: http://mobilejavadevelopment.blogspot.com/
visit the Berlin BlackBerry Developer Group: http://berlinblackberrydevelopers.blogspot.com/
Developer
Posts: 168
Registered: ‎11-22-2009
My Device: 9000 Bold, 8300 Curve

Re: Display hourglass or a processing dialog box

Using the status bar is good practice in many cases. Display "Connecting to GPS satellites" at first and then change the status to whatever message you want after you have a lock.