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
Contributor
Posts: 11
Registered: ‎05-21-2012
My Device: multi-device (developer)
My Carrier: multi-provider (developer)

Problem refreshing the main display when overriding the paint(Graphics) method

Hello

I have an application displaying a BrowserField in a VerticalFieldManager. I override the MainScreen's paint method to show a animated loader when the BrowserField is loading the page, and the content of the BrowserField when the  loading is finished.

Most of the time this setting works fine, but on rare occasions, while the web page is rendered by the BrowserField, the animated loader is still visible behind the page display. The web page is shown on the foreground, but scrolling with the trackpad scrolls the animated loader up and down in the background.

Would this a double buffer problem? Is there something missing, or eventually a better way to paint on the screen while letting the BrowserField load the page in background.


The application code in the MainScreen class looks like this:

<code>
    private boolean isLoading;
    //override Mainscreen#paint(Graphics)
    public void paint(Graphics g){
        if(isLoading){
            graphics.clear();
                /*
        paint animation
        */
        }else{
              /* let the screen paint itself */
                super.paint(g);
        }
        return;
    }
    
    //switch the loading animation on/off
    public void showLoader(boolean show){
        isLoading = show;
        synchronized (UiApplication.getEventLock()) {
            this.updateDisplay();
        }
    }
</code>

The above showLoader method is called from the BrowserField listener:
<code>
class MyBrowserHandler extends BrowserFieldListener {

    MyMainScreen parent;
    public MyBrowserHandler(BrowserScreen parent) {
        this.parent = parent;
    }

    public void documentLoaded(BrowserField browserField, Document document) throws Exception {
        parent.showLoader(false);
    }
}
</code>

Thanks!

Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Problem refreshing the main display when overriding the paint(Graphics) method

Have you tried a simple invalidate() instead of

        synchronized (UiApplication.getEventLock()) {
            this.updateDisplay();
        }

(which is a bad idea anyway - invokeLater is much safer than synchronizing on the event lock)?

 

Invalidate will schedule a repaint in the cleanest way possible...

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Contributor
Posts: 11
Registered: ‎05-21-2012
My Device: multi-device (developer)
My Carrier: multi-provider (developer)

Re: Problem refreshing the main display when overriding the paint(Graphics) method

Thanks for your reply !

I tried switching to an invalidate() call instead. It doesn't seem to affect to problem (it doesn't make it worse either, I'll take your advice and use invalidate here).

The problem seems to be on the graphics context and it's use, but I don't have any idea on what to try about it.

Developer
Posts: 19,633
Registered: ‎07-14-2008
My Device: Not Specified

Re: Problem refreshing the main display when overriding the paint(Graphics) method

Is the problem here that rthe BrowserField has not told the Mainscreen to stop displaying the animation?

Contributor
Posts: 11
Registered: ‎05-21-2012
My Device: multi-device (developer)
My Carrier: multi-provider (developer)

Re: Problem refreshing the main display when overriding the paint(Graphics) method

I am not sure about it. As the drawing process in the Mainscreen switches from the loader to the BrowserField by checking the isLoading boolean, I suppose the two shouldn't happen at the same time.

The loader animation is not handled by a component added to the Mainscreen's manager, but through pure graphics drawing inside the Mainscreen's paint method (that's the reason why I had to override the paint method, it has to do with keeping drawing the loader during layout changes), so it can't ask to be displayed by itself.

 

So I'd guess  if the BrowserField never asks the mainscreen to stop the animation, the loader should be displayed all the time and the web page never shown.

New Developer
Posts: 14
Registered: ‎04-01-2012
My Device: 9630
My Carrier: MTN

Re: Problem refreshing the main display when overriding the paint(Graphics) method

is there any resolution to this issue?

Contributor
Posts: 11
Registered: ‎05-21-2012
My Device: multi-device (developer)
My Carrier: multi-provider (developer)

Re: Problem refreshing the main display when overriding the paint(Graphics) method

Hi

 

I tweaked my app to avoid the most visible effects, but didn't get any definitive solution.

Avoiding this use case from the start seems to be the best strategy: don't touch the low level paint() method, and use a status dialog or switch UI elements by adding/removing or hiding them away as  needed, and it should be OK.