BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 10-25-2007, 08:53 PM   #1 (permalink)
New Member
 
BBPsy's Avatar
 
Join Date: Sep 2007
Model: 7520
PIN: N/A
Carrier: Globe
Posts: 5
Post Thanks: 0
Thanked 0 Times in 0 Posts
Question Using GaugeField/ProgressBar

Please Login to Remove!

Hi guys,

I am new with BlackBerry JDE, and need your help in using GaugeField to update the value of progress bar using the value of i in the for statementthat loops so I could see if the value increases from 0 until it reaches 100...

Could anyone please help me... I have my code below... Please help and Thanks in advance.

Code:
import java.util.Vector;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.EditField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.SeparatorField;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.PopupScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.component.GaugeField;
import java.util.Timer;
import java.util.TimerTask;




/**
 * 
 */
  public class NEWProg extends UiApplication {
    
    
    public static void main(String args[]){
       
    NEWProg npr = new NEWProg();
    npr.enterEventDispatcher();
   
  
        
    }
    
    
    
    
    NEWProg() {
      
       pushScreen(new ProgressScreen());
       
        }
} 

//create a new screen that extends MainScreen, which provides
//default standard behavior for BlackBerry applications
class ProgressScreen extends PopupScreen
{
        private HorizontalFieldManager hfldmgr1;
        private GaugeField percentGauge;
        private LabelField ltitle;
      
      
    
    
    
        public ProgressScreen()
        {

         //invoke the MainScreen constructor
        
       
                
                
       super(new VerticalFieldManager(),Field.FOCUSABLE);
       
       Font defaultfont = Font.getDefault();
       Font boldfont = defaultfont.derive(Font.BOLD);
      
       
       hfldmgr1 =  new HorizontalFieldManager();
       percentGauge = new GaugeField(null, 0, 100,50, GaugeField.PERCENT);
       
       Timer timer;
       TimerTask task;
      
        for(int i= 0; i<=100; i++){
            percentGauge.setValue(i);
               
       }
       
       ltitle= new LabelField("Downloading ",Field.FIELD_HCENTER);
       ltitle.setFont(boldfont);
        
                
        hfldmgr1.add(percentGauge);
              
        add(ltitle);
        add(new SeparatorField());
        add(hfldmgr1);
       
         
                
        }
        
   
        //override the onClose() method to display a dialog box to the user
        //with "Goodbye!" when the application is closed
        public boolean onClose()
        {
            //display a dialog box with "Goodbye!"
            //...
            
             Dialog.alert("Goodbye!");
            
            System.exit(0);
            return true;
        }
     }
__________________
---------------------------
Regards,
BBPsy
Offline  
Old 10-26-2007, 03:08 AM   #2 (permalink)
Thumbs Must Hurt
 
Join Date: May 2007
Location: Bulgaria
Model: none
PIN: N/A
Carrier: Mtel
Posts: 150
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

You should use doPaint() method to update visually the progress bar.
Offline  
Old 10-26-2007, 03:39 AM   #3 (permalink)
New Member
 
BBPsy's Avatar
 
Join Date: Sep 2007
Model: 7520
PIN: N/A
Carrier: Globe
Posts: 5
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi pa4o85,

Thanks for your info.

Do you have any sample code... I have no idea on using doPaint() since I am just starting to learn.

Thanks in advance.
__________________
---------------------------
Regards,
BBPsy
Offline  
Old 10-26-2007, 04:16 AM   #4 (permalink)
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

i don't think you need doPaint() as the GaugeField delivers the functionality you need.
Without trying your code i see two obscure things:
- your comment (seems to be a sample) mentions to extend mainscreen, you extend popupscreen.
- you create a timer but you don't use it.

Code:
int i=0;
progressTask = new TimerTask() {
   public void run() {
      percentGauge.setValue(i);
      i++;
   }
};

Timer progressTimer = new Timer();
progressTimer.scheduleAtFixedRate(progressTask, 100, 10000);
this would update the gauge field every 100ms with a 1% progress. didn't test it though
__________________
java developer, Devinto, hamburg/germany
Offline  
Old 10-26-2007, 05:05 AM   #5 (permalink)
Thumbs Must Hurt
 
Join Date: May 2007
Location: Bulgaria
Model: none
PIN: N/A
Carrier: Mtel
Posts: 150
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

I use a class ProgressBar like this. It works for me, perfectly:
Code:
public class ProgressBar {
  private PopupScreen popup;
  private GaugeField gaugeField;
  private LabelField label;
  private CustomButtonField cancelButton;
  
  private ProgressStatus monitor;
  private boolean isCanceled = false;

  /**
   * Object constructor
   * 
   * @param monitor - ProgressStatus, that shows the percents of the progress and
   *        the database that is synchronizing at the current moment
   * @param title - Text to display on popup area
   * @see GaugeField
   * @see PopupScreen
   */
  public ProgressBar(ProgressStatus monitor, String title) {
    this.monitor = monitor;
    monitor.setMessage(title);
    
    FontFamily fontFamily[] = FontFamily.getFontFamilies();
    Font font = fontFamily[3].getFont(FontFamily.SCALABLE_FONT, 12);
    
    DialogFieldManager manager = new DialogFieldManager();
    popup = new PopupScreen(manager);
    label = new LabelField(title);
    gaugeField = new GaugeField(null, 0, 100, 20, GaugeField.PERCENT);
    synchronized (UiApplication.getEventLock()) {
      cancelButton = new CustomButtonField("Cancel", font, 30, 20) {
        public boolean trackwheelClick(int status, int time) {
          //Dialog.alert("here");
          isCanceled = true;
          return true;
        }
      };
    }
    manager.addCustomField(label);
    manager.addCustomField(gaugeField);
    manager.addCustomField(cancelButton);
  }
  
  public void open() {
     UiApplication.getUiApplication().pushScreen(popup);
     popup.doPaint();
  }
  
  public void update() {
    int percents = monitor.getPercents();
    if (gaugeField.getValue() <= percents) {
      label.setText(monitor.getMessage());
      gaugeField.setValue(percents);
    }
    popup.doPaint();
  }
  
  public void close() {
    UiApplication.getUiApplication().invokeLater(new Runnable() {
      public void run() {
        if (popup.isDisplayed()) {
          UiApplication.getUiApplication().popScreen(popup);
        }
      }
    });
  }

  public boolean isCanceled() {
    return isCanceled;
  }

  public void setCanceled(boolean isCanceled) {
    this.isCanceled = isCanceled;
  }
  
}
Offline  
Old 10-26-2007, 05:11 AM   #6 (permalink)
Thumbs Must Hurt
 
Join Date: May 2007
Location: Bulgaria
Model: none
PIN: N/A
Carrier: Mtel
Posts: 150
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by simon.hain View Post
i don't think you need doPaint() as the GaugeField delivers the functionality you need.
I mean Screen.doPaint() method as it is a part of the functionality of GaugeField as it extends it. I think without doPaint() i can not see the progress itself and the new-setted values.
Offline  
Old 10-30-2007, 10:02 PM   #7 (permalink)
New Member
 
BBPsy's Avatar
 
Join Date: Sep 2007
Model: 7520
PIN: N/A
Carrier: Globe
Posts: 5
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi guys

Thanks for the help...
__________________
---------------------------
Regards,
BBPsy
Offline  




Copyright 2004-2016 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.