Я хочу отображать ход загрузки веб-страницы.Я использую BrowserFieldListener для расчета прогресса на веб-странице.Но на экране ничего не отображается.Как я могу рассчитать процент этого прогресса?
Класс BrowserFieldDemoScreen расширяет MainScreen {
public BrowserFieldDemoScreen()
{
BrowserFieldConfig myBrowserFieldConfig = new BrowserFieldConfig();
myBrowserFieldConfig.setProperty(BrowserFieldConfig
.NAVIGATION_MODE,BrowserFieldConfig.NAVIGATION_MODE_POINTER);
BrowserField browserField = new BrowserField();
browserField.requestContent("http://www.blackberry.com");
browserField.addListener(new BrowserFieldListener() {
public void documentAborted(BrowserField browserField, Document document) throws Exception
{
if ((browserField != null) && (document != null))
{
String title = browserField.getDocumentTitle();
String url = document.getBaseURI();
browserField.getErrorHandler().displayContentError(url, "Aborted loading document '" + title + "'");
}
super.documentAborted(browserField, document);
}
public void documentCreated(BrowserField browserField, ScriptEngine scriptEngine, Document document) throws Exception
{
if ((browserField != null) && (document != null))
{
String title = browserField.getDocumentTitle();
String url = document.getBaseURI();
System.out.println("[" + this.getClass().getName() + "] Document '" + title + "' created for URL " + url);
}
super.documentCreated(browserField, scriptEngine, document);
}
/**
*
* @param browserField - The BrowserField to which the document belongs
* @param document - The document for which this event belongs.
*/
public void documentError(BrowserField browserField, Document document) throws Exception
{
if ((browserField != null) && (document != null))
{
String title = browserField.getDocumentTitle();
String url = document.getBaseURI();
browserField.getErrorHandler().displayContentError(url, "Error loading document '" + title + "'");
}
super.documentError(browserField, document);
}
public void documentLoaded(BrowserField browserField, Document document) throws Exception
{
if ((browserField != null) && (document != null))
{
String title = browserField.getDocumentTitle();
System.out.println("[" + this.getClass().getName() + "] Document '" + title + "' loaded");
}
super.documentLoaded(browserField, document);
}
public void documentUnloading(BrowserField browserField, Document document) throws Exception
{
if ((browserField != null) && (document != null))
{
String title = browserField.getDocumentTitle();
System.out.println("[" + this.getClass().getName() + "] Document '" + title + "' unloading");
}
super.documentUnloading(browserField, document);
}
public void downloadProgress(BrowserField browserField, ContentReadEvent event) throws Exception
{
if ((browserField != null) && (event != null))
{
String title = browserField.getDocumentTitle();
double amtComplete = event.getItemsRead() / event.getItemsToRead();
System.out.println("[" + this.getClass().getName() + "] Document '" + title + "' loading " + String.valueOf(amtComplete) + "% complete");
}
super.downloadProgress(browserField, event);
}});
}
}