BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 01-18-2007, 01:16 AM   #1
sanjayt
New Member
 
Join Date: Jan 2007
Model: 8100
Posts: 3
Default Progress Bar

Please Login to Remove!

Can any one please tell me, how to code for progress bar in blackberry, which will update contunuously depends on the input?

Last edited by sanjayt; 01-18-2007 at 01:19 AM..
Offline  
Old 01-18-2007, 01:19 AM   #2
John Clark
BBF Moderator
 
John Clark's Avatar
 
Join Date: Jun 2005
Model: Z30
OS: 10.2.1.x
PIN: s & needles
Carrier: AT&T
Posts: 34,720
Default

*** moved to Developer Forum ***
Offline  
Old 01-18-2007, 04:08 AM   #3
halon
New Member
 
Join Date: Jan 2007
Model: none
Posts: 3
Default

Well, I haven't done it myself, but I'm guessing what you could do is make a custom control which extends "Field", override layout(int width, int height) using setExtent() to provide boundaries, also override paint(net.rim.device.api.ui.Graphics g) in which to draw rectangles and fill them according to the 'percentage' variable in the class.

Then what you can do is give it some sort of function like UpdateProgress(int percentage) and have it update the variable inside the class, then manually call the paint() function - not sure where you would call that.

Is that any of any use to you? I'll give you more details if you want, but perhaps there's someone else on the forums who've done it before.
Offline  
Old 01-18-2007, 04:27 AM   #4
jfisher
CrackBerry Addict
 
Join Date: Jun 2005
Location: Manchester, UK
Model: BOLD
Carrier: t-mobile
Posts: 714
Default

i made this, needs two image files, one for the background and another for the progress bar itself. you pass the class a string which gets displayed as a message:

import java.util.Timer;
import java.util.TimerTask;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Characters;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.container.PopupScreen;
import net.rim.device.api.ui.container.VerticalFieldManag er;
/*
* popupWaitingScreen.java
*
* Created on June 19, 2006, 5:01 PM
*
* @author jfisher
*/
public class popupWaitingScreen extends PopupScreen {
BitmapField myBitmapField = new BitmapField();
Bitmap backdrop = Bitmap.getBitmapResource("waitingbackground.png");
Bitmap progress = Bitmap.getBitmapResource("greysquare.png");
Timer timer = new Timer();
TimerTask updateTask;
int xval = 14;
Bitmap myBitmap = new Bitmap(165, 95);
BitmapField waitingField = new BitmapField(myBitmap);
Graphics myGraphics = new Graphics(myBitmap);
/** Creates a new instance of popupWaitingScreen */
public popupWaitingScreen(String value) {
super(new VerticalFieldManager(),Field.FOCUSABLE);


if(value.length()>26){
value = value.substring(0,23) + "...";
}

final String message = value;
updateTask = new TimerTask() {
public void run() {
myGraphics.drawBitmap(0,0,165,95,backdrop, 0,0);
myGraphics.drawBitmap(xval,79,7,7,progress, 0,0);
myGraphics.drawText(message, 10,10);
xval = xval+3;
if(xval>140){
xval = 14;
}
waitingField.setBitmap(myBitmap);
}
};
add(waitingField);
timer.scheduleAtFixedRate(updateTask, 40, 80);
}

public boolean keyChar(char key, int status, int time) {
boolean retval = false;
switch (key) {
case Characters.ESCAPE:
int response = Dialog.ask(Dialog.D_YES_NO, "Are you sure you want to cancel this process and exit the application?");
if (Dialog.YES == response){
System.exit(1);
}else{
return true;
}
retval = true;
break;
default:
retval = super.keyChar(key, status, time);
}
return retval;
}
}
__________________
new job doesn't allow a public profile - please do not contact this user with questions, you will not get a response. good luck!
Offline  
Old 01-19-2007, 10:01 AM   #5
fbrimm
Thumbs Must Hurt
 
Join Date: Aug 2005
Model: 8830
Carrier: Verizon
Posts: 144
Thumbs up

jfisher

Nice code! I hope you don't mind if I put it to use.

How do you remove the popup screen when what your waiting on completes?

Thanks.

fbrimm
Offline  
Old 01-19-2007, 11:22 AM   #6
jfisher
CrackBerry Addict
 
Join Date: Jun 2005
Location: Manchester, UK
Model: BOLD
Carrier: t-mobile
Posts: 714
Default

feel free - i'll add the code to my blog next week with some more detailed instructions, i've been using it for a few months now with no problems.

i use invokelater from my background thread to get rid of the popup, pushing the new screen - this is a little naughty as it leaves the timer process running:

UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
UiApplication.getUiApplication().popScreen(UiAppli cation.getUiApplication().getActiveScreen());
UiApplication.getUiApplication().pushScreen(new myScreen());
}
});

- but it's performed fine for what i need, you could add some code using Screen.onExposed and/or Screen.onObscured() inside the progress class to check when the new screen has been pushed from the background thread so it can cancel the timer operations, alternatively you could have a boolean in a logic class it routinely checks to see if it still needs to be active - this isn't the most elegant/proper way of doing it - but it works.

in action:
__________________
new job doesn't allow a public profile - please do not contact this user with questions, you will not get a response. good luck!

Last edited by jfisher; 01-19-2007 at 11:35 AM..
Offline  
Old 02-26-2007, 05:24 PM   #7
markat2k
New Member
 
Join Date: Feb 2007
Model: 8830
Carrier: Sprint
Posts: 3
Default Another progress bar

This is pretty simple. Might be better to use TimerTask somehow than extend Thread.

Code:
/**
 * Defines ProgressBar object. Creates popup screen with title, and perpetually updating
 * progress gauge. Instantiate and run as thread to start progress update. Call
 * remove() method when finished to remove popup screen and shutdown thread.
 */
package mrm.util;

import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.GaugeField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.DialogFieldManager;
import net.rim.device.api.ui.container.PopupScreen;

public class ProgressBar extends Thread {

	private int maximum, timeout;

	private boolean useful;

	private PopupScreen popup;

	private GaugeField gaugeField;

	/**
	 * Object constructor
	 * 
	 * @param title
	 *           Text to display on popup area
	 * @param maximum
	 *           Range / width of the gauge field of progress bar
	 * @param timeout
	 *           Milliseconds to pause between updates to progress bar
	 * @see GaugeField
	 * @see Thread
	 * @see PopupScreen
	 */

	public ProgressBar(String title, int maximum, int timeout) {
		this.maximum = maximum;
		this.timeout = timeout;

		DialogFieldManager manager = new DialogFieldManager();

		popup = new PopupScreen(manager);
		gaugeField = new GaugeField(null, 1, maximum, 1, GaugeField.NO_TEXT);

		manager.addCustomField(new LabelField(title));
		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)
				iterations = 1;

			gaugeField.setValue(iterations);
		}

		if (popup.isDisplayed()) {
			UiApplication.getUiApplication().invokeLater(new Runnable() {
				public void run() {
					UiApplication.getUiApplication().popScreen(popup);
				}
			});
		}
	}

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

	public synchronized void remove() {
		useful = false;
	}
}
Offline  
Old 03-24-2007, 07:48 PM   #8
whickie
Knows Where the Search Button Is
 
whickie's Avatar
 
Join Date: Sep 2006
Location: Ottawa, Canada
Model: Pearl
Carrier: Rogers
Posts: 19
Default The Pearl

Anyone having problems with PopupScreen on the Pearl?

I get ControlledAccessException if I try to push a PopupScreen.
Offline  
Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


National Instruments Mainframe Chassis - NI-PXIe-1071 w/Warranty picture

National Instruments Mainframe Chassis - NI-PXIe-1071 w/Warranty

$650.00



Tektronix TM502A Two Slot Mainframe - Tested and Working picture

Tektronix TM502A Two Slot Mainframe - Tested and Working

$100.00



Chroma 6312A DC Electronic Load Mainframe **FOR PARTS ONLY, POWERS ON** picture

Chroma 6312A DC Electronic Load Mainframe **FOR PARTS ONLY, POWERS ON**

$150.00



Fluke Networks Versiv Modular Mainframe AS IS picture

Fluke Networks Versiv Modular Mainframe AS IS

$1900.00



Chroma 6312 DC Electronic Load Mainframe  picture

Chroma 6312 DC Electronic Load Mainframe

$254.96



SHC SYSTEM 6 MAINFRAME + Mixed Modules 6-562,6-201,6-402. picture

SHC SYSTEM 6 MAINFRAME + Mixed Modules 6-562,6-201,6-402.

$99.99







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