BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 08-20-2009, 11:27 AM   #1 (permalink)
New Member
 
Join Date: Jul 2009
Model: 8830
PIN: N/A
Carrier: T-Mobile
Posts: 6
Post Thanks: 0
Thanked 0 Times in 0 Posts
Exclamation progress bar when http requesting

Please Login to Remove!

I am confused by the progress bar, when i call the http request.

I just want to implement a kind of progress bar, such as the popupscreen or anything else, when i am getting the date via http, the progress bar would be displaying animately (any kind of GaugeField or Thread).

But i cannot make the progress bar moving during the http requesting, can any one give me some suggestion how to implement this?

Thank you in advance, urgently!!
Offline  
Old 08-20-2009, 11:53 AM   #2 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
Default

Not really enough info here to tell you what you are doing wrong.

How are you updating the Guagefield?

Are you making the HTTP connection within the UI thread?
Offline  
Old 08-20-2009, 08:22 PM   #3 (permalink)
New Member
 
Join Date: Jul 2009
Model: 8830
PIN: N/A
Carrier: T-Mobile
Posts: 6
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

So far, i put the Http connection in the main thread, and before Http connection, i create the progress bar class, in which contain the thread for counting the value of Guagefield (0~100 and then 0~100 again).

Is it doable?
Offline  
Old 08-20-2009, 08:30 PM   #4 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
Default

Can't do that. HTTP blocks the main thread - this will a) cause the problem you are seeing, and b) cause your event queue to overflow, resulting in a very rude "App not responsive" exception along with a stack trace.

You put the HTTP in a separate thread, and arrange a listener or callback mechanism to notify the UI thread on progress.
Offline  
Old 08-24-2009, 03:06 AM   #5 (permalink)
New Member
 
Join Date: Jul 2009
Model: 8830
PIN: N/A
Carrier: T-Mobile
Posts: 6
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you, Dougsg38p.

My codes are like this:

The main thread:

such as MainScreen.java
=====================
...

some processes...

// Before Http connection

InProgressWaitingScreen progressbar = new InProgressWaitingScreen( "Downloading..." );
progressbar.open();

// Http connection
...
// Http connection complete

progressbar.close();

=========================


File: InProgressWaitingScreen.java
==========================

public final class InProgressWaitingScreen
{
public PopupScreen popup;
public GaugeField gaugeField;
private CustomizeFontLabelField label;
private boolean useful;
private int timeout = 1;
ProgressBarThread progressBarThread;

public InProgressWaitingScreen( String title )
{
DialogFieldManager manager = new DialogFieldManager();
popup = new PopupScreen(manager);
label = new CustomizeFontLabelField(title);
gaugeField = new GaugeField( "Progressing...", 0, 100, 50, GaugeField.LABEL_AS_PROGRESS);
manager.addCustomField(label);
manager.addCustomField(gaugeField);

progressBarThread = new ProgressBarThread(this);
progressBarThread.start();
}

public void open()
{
UiApplication.getUiApplication().pushScreen(popup) ;
popup.doPaint();
}

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

private class ProgressBarThread extends Thread
{
private InProgressWaitingScreen progressScreen;

public ProgressBarThread( InProgressWaitingScreen screen )
{
progressScreen = screen;
}

public synchronized void stop()
{
useful = false;
}

public void run()
{
useful = true;
int iterations = 0;

while (useful)
{
try
{
Thread.sleep(timeout);
}
catch (Exception e)
{

}

if (++iterations > 100)
iterations = 1;

progressScreen.gaugeField.setValue(iterations);
// but i can NOT call doPaint here, so that the progress bar can not be refreshed!!!! invalidate() doesnt make effect
//popup.doPaint();
progressScreen.popup.invalidate();
//******** I can print out this log in the while loop
System.out.println( "invalidate(" + iterations + ")");
}
}
}


}

===============================

Could any one help me to point out the reason why the progress bar can not be refreshed in this way?
I can complete the http connection, just the progress bar can not be updated.

If use popup.doPaint();, that make the app exception.

Thank you.

Last edited by argus2012 : 08-24-2009 at 03:13 AM.
Offline  
Old 08-25-2009, 02:24 AM   #6 (permalink)
New Member
 
Join Date: Jul 2009
Model: 8830
PIN: N/A
Carrier: T-Mobile
Posts: 6
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

any idea about this?
Offline  
Old 08-25-2009, 09:25 AM   #7 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
Default

The UI components can only be accessed from the event thread. In order to do what you are trying to do, you would have to place this UI operation in a Runnable, and pass this to UiApplication.invokeLater().

Having said that, I don't see the benefit in having this timer thread arbitrarily updating the progress bar.

Also, I have never called "doPaint" in 1 million lines of Blackberry code - not sure what you are trying to do here.

Why not do something a little simpler?

1. Put the HTTP in a sep. thread
2. Arrange a callback mechanism so the thread can call back to your Screen class
3. Push a modal dialog, "Downloading...please wait"
4. In your callback, use InvokeLater to pop this modal dialog. (remember, this IS NOT the UI thread)

Now, your next line of code after the modal dialog push will execute once the HTTP request is complete.

Last edited by Dougsg38p : 08-25-2009 at 09:27 AM.
Offline  
Old 09-01-2009, 10:32 AM   #8 (permalink)
New Member
 
Join Date: Sep 2009
Model: 9000
PIN: N/A
Carrier: Verizon
Posts: 1
Post Thanks: 0
Thanked 0 Times in 0 Posts
Smile progress bar when http requesting call

Doug,

Thank you for your suggestion. Do you have an example of a callback function? I'm fairly new to Java development on the blackberry and although my HTTP call is in a separate thread and I have my progress bar in a popup screen I'm just not sure when to call it. Thanks in advance for your help!
Offline  
Closed Thread


Thread Tools

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





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