use of com.codename1.io.NetworkEvent in project CodenameOne by codenameone.
the class ConnectionRequest method addResponseListener.
/**
* Adds a listener that would be notified on the CodenameOne thread of a response from the server.
* This event is specific to the connection request type and its firing will change based on
* how the connection request is read/processed
*
* @param a listener
*/
public void addResponseListener(ActionListener<NetworkEvent> a) {
if (actionListeners == null) {
actionListeners = new EventDispatcher();
actionListeners.setBlocking(false);
}
actionListeners.addListener(a);
}
use of com.codename1.io.NetworkEvent in project CodenameOne by codenameone.
the class ConnectionRequest method addExceptionListener.
/**
* Adds a listener that would be notified on the CodenameOne thread of an exception
* in this connection request
*
* @param a listener
*/
public void addExceptionListener(ActionListener<NetworkEvent> a) {
if (exceptionListeners == null) {
exceptionListeners = new EventDispatcher();
exceptionListeners.setBlocking(false);
}
exceptionListeners.addListener(a);
}
use of com.codename1.io.NetworkEvent in project CodenameOne by codenameone.
the class NetworkManager method addProgressListener.
/**
* Adds a listener to be notified when progress updates
*
* @param al action listener
*/
public void addProgressListener(ActionListener<NetworkEvent> al) {
if (progressListeners == null) {
progressListeners = new EventDispatcher();
progressListeners.setBlocking(false);
}
progressListeners.addListener(al);
}
use of com.codename1.io.NetworkEvent in project CodenameOne by codenameone.
the class RequestBuilder method getAsBytesAsync.
/**
* Executes the request asynchronously and writes the response to the provided
* Callback
* @param callback writes the response to this callback
*/
public void getAsBytesAsync(final Callback<Response<byte[]>> callback) {
ConnectionRequest request = createRequest(false);
request.addResponseListener(new ActionListener<NetworkEvent>() {
@Override
public void actionPerformed(NetworkEvent evt) {
Response res = null;
res = new Response(evt.getResponseCode(), evt.getConnectionRequest().getResponseData(), evt.getMessage());
callback.onSucess(res);
}
});
CN.addToQueue(request);
}
use of com.codename1.io.NetworkEvent in project CodenameOne by codenameone.
the class RequestBuilder method getAsJsonMap.
/**
* Executes the request asynchronously and writes the response to the provided
* Callback
* @param callback writes the response to this callback
* @param onError the error callback
* @return returns the Connection Request object so it can be killed if necessary
*/
public ConnectionRequest getAsJsonMap(final SuccessCallback<Response<Map>> callback, final FailureCallback<? extends Object> onError) {
ConnectionRequest request = createRequest(true);
request.addResponseListener(new ActionListener<NetworkEvent>() {
@Override
public void actionPerformed(NetworkEvent evt) {
if (onError != null) {
// this is an error response code and should be handled as an error
if (evt.getResponseCode() > 310) {
return;
}
}
Response res = null;
Map response = (Map) evt.getMetaData();
res = new Response(evt.getResponseCode(), response, evt.getMessage());
callback.onSucess(res);
}
});
bindOnError(request, onError);
CN.addToQueue(request);
return request;
}
Aggregations