12-04-2009 04:09 AM
Hi All,
Is it possible to add any bitmap image with GaugeField for displaying progress bar?
Regards
Subrat
Solved! Go to Solution.
12-04-2009 04:14 AM
no.
but implementing your own field is simple enough.
12-04-2009 04:18 AM
Ok adding Image is not possible .
Implementing own field means what?
Actually I am able to draw a progress bar using GaugeField but it has default look and feel of BlackBerry.
12-04-2009 04:23 AM
you can draw whatever you want if you use low-level access, read the paint method or another graphics context.
you can create a graphics object yourself, from a background bitmap for example, and paint on it.
i would suggest a timertask or a thread to paint your progress bitmap to the correct place.
12-04-2009 04:55 AM
Code sample if any will be helpful.
12-04-2009 08:22 AM
Hi,
This is just a sample code, which will do what you need
class ProgressField extends GaugeField {
private int _progress;
public ProgressField()
{
super();
_progress = 10;
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
try {
startProgress();
}
catch (final Exception e) {
System.out.println(e.toString());
}
}
}, 100, true);
}
private void startProgress()
{
if (_progress > 100)
return;
moveProgress();
}
private void moveProgress()
{
_progress++;
invalidate();
}
public int getPreferredHeight()
{
return 75;
}
protected void paint (Graphics g)
{
g.drawBitmap(0, 0, 100, 75, Bitmap.getBitmapResource("image.png"), 0, 0);
g.setBackgroundColor(Color.BLACK);
int xPos = 0;
for (int i = 0; i < _progress; i += 10)
{
g.fillRect(xPos, 45, 8, 10);
xPos += 10;
}
}
protected void layout(int width, int height) {
super.layout(width, height);
setExtent (width, 75);
}
}
Note: you can modify this code based on your need to make it perfect and proper
12-07-2009 12:25 AM
Hey it Working thanks buddy.
06-30-2010 09:37 AM
Hello,
I have used this code to extend it further.
Inside the invokeLater method I am calling another thread that is doing my ProgressBar background process. I am trying to tie my background process with the each step in the Progress Bar.
The code's like something like this.
ret=UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
try {
init();
ThreadClass c1 = new ThreadClass();
c1.start();
startProgress();
synchronized (c1) {
c1.wait();
}
}
catch (final Exception e) {
System.out.println(e.toString());
}
}
}, 300, true);
I wanted to know is this allowed as I get following error from time to time:
Application XXXXXX(182) is not responding; process terminated
and I feel its this threads that's doing the problem.
KIndly share your views.
Regards,
ChetanSH
06-30-2010 09:56 AM
you are blocking the event thread, this terminates your app.
to submit results from a thread to the UI you could use a callback pattern (google it if you don't know the word)