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
subrat
Posts: 33
Registered: ‎11-23-2009
My Device: Not Specified
Accepted Solution

Custom Gauge Field

Hi All,

 

Is it possible to add any bitmap image with GaugeField for displaying  progress bar?

 

Regards

Subrat

Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Custom Gauge Field

no.

but implementing your own field is simple enough.

----------------------------------------------------------
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
New Developer
subrat
Posts: 33
Registered: ‎11-23-2009
My Device: Not Specified

Re: Custom Gauge Field

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.

Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Custom Gauge Field

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.

----------------------------------------------------------
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
New Developer
subrat
Posts: 33
Registered: ‎11-23-2009
My Device: Not Specified

Re: Custom Gauge Field

Code sample if any will be helpful.

Developer
zany
Posts: 222
Registered: ‎11-11-2009
My Device: Storm

Re: Custom Gauge Field

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

 

with regards,
Vignesh J

-------------------------------------------------------------------------------------------------------------------------------------------------------------------
Don't forget to mark your post as solved if you get the answer and dont forget to give kudos if the answer is useful for you.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
New Developer
subrat
Posts: 33
Registered: ‎11-23-2009
My Device: Not Specified

Re: Custom Gauge Field

Hey it Working thanks buddy.

New Contributor
chetansh
Posts: 7
Registered: ‎06-27-2010
My Device: None

Re: Custom Gauge Field

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

Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Custom Gauge Field

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)

----------------------------------------------------------
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