You can create the instance of the ProgressBar and you can pass the time out and display messages to progressing bar.
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.Dialog;
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;
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);
}
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)
{
useful =false;
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
Dialog.alert("Successfully Completed");
System.exit(0);
}
});
iterations = 1;
}
gaugeField.setValue(iterations);
}
if (popup.isDisplayed())
{
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
UiApplication.getUiApplication().popScreen(popup);
}
});
}
}
public synchronized void remove()
{
useful = false;
}
}
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.Dialog;
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;
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);
}
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)
{
useful =false;
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
Dialog.alert("Successfully Completed");
System.exit(0);
}
});
iterations = 1;
}
gaugeField.setValue(iterations);
}
if (popup.isDisplayed())
{
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
UiApplication.getUiApplication().popScreen(popup);
}
});
}
}
public synchronized void remove()
{
useful = false;
}
}
Sourcecode is very interesting, I want to try it, thank you for this code.
ReplyDeleteWow, this post is pleasant, my sister is analyzing such things, therefore I am going
ReplyDeleteto inform her.
My webpage long hairstyles