Your module (as do all modules) extends KrollModule which extends KrollProxy, which handles events. Your Handler class does not have access to this object so it cannot fire the event itself, however you are already passing that reference (new Handler(this)
) so just use it!
import ext.ResponseHandler;
public class Handler implements ResponseHandler {
private KrollModule proxy; // Hold onto this reference
public Handler(KrollModule proxy) {
this.proxy = proxy;
}
public void OnConnected(String arg0, String arg1) {
// Fire event if anyone is listening
if (proxy.hasListeners("colorChange")) {
HashMap<String, Object> event = new HashMap<String, Object>();
event.put("u1", arg0);
event.put("u2", arg1);
proxy.fireEvent("colorChange", hm);
}
}
}
This is the general idea, pass the proxy to fire an event to the class itself, an alternative would be to inline an anonymous implementation of ResponseHandler
inside your module instead. I'm not sure if you are implementing ResponseHandler right, or if OnConnected
is even firing, you need to check that first.