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. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Web and WebWorks Development

Reply
Trusted Contributor
chicoxml
Posts: 224
Registered: ‎09-03-2010
Accepted Solution

Extensión problem screen

Hello,

I am trying to make an extension to make a screen of load, Everything works very well, I can show the screen, but I cannot close it by means of a method automatically.

 

This it is the code of the extension:

Extensions.java

 

package AppExt;

import org.w3c.dom.Document;

import net.rim.device.api.browser.field2.BrowserField;
import net.rim.device.api.script.ScriptEngine;
import net.rim.device.api.web.WidgetConfig;
import net.rim.device.api.web.WidgetExtension;

public final class Extensions implements WidgetExtension {

	public String[] getFeatureList() {
		// TODO Auto-generated method stub
		String[] result = new String[1];
		result[0] = "AppExt.box";
		return result;
	}

	public void loadFeature(String feature, String version,
			Document doc, ScriptEngine scriptEngine) throws Exception {
		
		if (feature == "AppExt.box") {
	         scriptEngine.addExtension("AppExt.box", new BoxNamespace());
	      }
		// TODO Auto-generated method stub

	}

	public void register(WidgetConfig arg0, BrowserField arg1) {
		// TODO Auto-generated method stub

	}

	public void unloadFeatures(Document arg0) {
		// TODO Auto-generated method stub

	}

}

 

 

BoxNamespace.java

package AppExt;

import net.rim.device.api.script.ScriptableFunction;

public final class BoxNamespace extends ScriptableFunction {

	public static final String FIELD_SHOW = "show";
	public static final String FIELD_HTML = "html";
	public static final String FIELD_CLOSE = "close";

	private   String _html = "";
	private BoxFunction Boxfn;

	public BoxNamespace() {
		this.Boxfn = new BoxFunction(this);
	}

	// The getField() function is called when the
	// dot '.' extender is used on your JavaScript object.
	public Object getField(String name) throws Exception {

		if (name.equals(FIELD_SHOW)) {
			return this.Boxfn;
		} else if (name.equals(FIELD_HTML)) {
			return new String(_html);
		}else if(name.equals(FIELD_CLOSE)){
		
			 this.Boxfn.vbox.close();
		
		}
		return super.getField(name);
	}
	
	public boolean putField(String name, Object value) throws Exception {
		
		if (name.equals(FIELD_HTML)) {
			if (value != null && value != UNDEFINED) {
				this._html = (String)value;
				return true;
			}
		}
		return false;
	}
	
	public String getHtml() {
		return this._html;
	}
}

 BoxFunction.java

package AppExt;

import net.rim.device.api.script.ScriptableFunction;
import net.rim.device.api.ui.UiApplication;

public final class BoxFunction extends ScriptableFunction  {
	private  BoxNamespace _boxNspace =null; 
	public 	popup vbox ;
	public BoxFunction(BoxNamespace boxNamespace) {
		_boxNspace =boxNamespace;
	}
	public Object invoke(Object obj, Object[] args) throws Exception {
		
		final UiApplication uiApp = UiApplication.getUiApplication();
	  	uiApp.invokeLater (new Runnable() {
		    public void run()
		    {
		    	vbox = new popup( _boxNspace.getHtml()); //
		    	uiApp.pushModalScreen(vbox);
		    }
		});	
		return UNDEFINED;
	}
	
	public ScriptableFunction closewindow = new ScriptableFunction() 
	{
	   public Object invoke(Object obj, Object[] args) throws Exception
	   {
		   vbox.close();
	      return UNDEFINED;
	   }
	};  
	
}

 popup.java

package AppExt;

import net.rim.device.api.browser.field2.BrowserField;
import net.rim.device.api.browser.field2.BrowserFieldConfig;
import net.rim.device.api.ui.container.PopupScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;

public class popup extends PopupScreen {

	public popup(String html) {
		super(new VerticalFieldManager());
		BrowserFieldConfig config = new BrowserFieldConfig();
		config.setProperty(BrowserFieldConfig.NAVIGATION_MODE, BrowserFieldConfig.NAVIGATION_MODE_CARET);
		config.setProperty("Content-Type", "text/plain; charset=utf-8"); 
		config.setProperty(BrowserFieldConfig.JAVASCRIPT_ENABLED, Boolean.TRUE);
		BrowserField bw = new BrowserField(config);
		bw.displayContent(html, "http://localhost/");
		add(bw);
		// TODO Auto-generated constructor stub
	}

}

 

in javascript:

 

loading();

function loading()
		{
			AppExt.box.html ="<h4>loading..</h4>";
			AppExt.box.show();
			 setTimeout(function(){
				   
					AppExt.box.close();
					 alert("closing");
		     }, 3000)	

			
		}

 

 

I am supposing that the problem this in this line, but that I am making bad.

AppExt.box.close();

 

 

Please use plain text.
Trusted Contributor
chicoxml
Posts: 224
Registered: ‎09-03-2010

Re: Extensión problem screen

[ Edited ]

java.lang.illegalStateException: UI engine accessed without holding the event lock

 

 

library.xml

<?xml version="1.0" encoding="UTF-8"?>
<library>
    <extension>
        <entryClass>AppExt.Extensions</entryClass>
    </extension>
    <features>
        <feature id="AppExt.box" version="1.0.0" ></feature>
    </features>
</library>

 

Please use plain text.
Developer
ibarrera
Posts: 588
Registered: ‎05-29-2009

Re: Extensión problem screen

I think you should catch the event lock when you close your screen... so instead of only vbox.close() try this...

 

final UiApplication uiApp = UiApplication.getUiApplication();
	  	uiApp.invokeLater (new Runnable() {
		    public void run() {
		    	 vbox.close();
		    }
		});	



Please use plain text.