use of com.codename1.ui.events.ActionListener 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.ui.events.ActionListener in project CodenameOne by codenameone.
the class Oauth2 method showAuthentication.
/**
* This method shows an authentication for login form
*
* @param al a listener that will receive at its source either a token for
* the service or an exception in case of a failure
* @return a component that should be displayed to the user in order to
* perform the authentication
*/
public void showAuthentication(ActionListener al) {
final Form old = Display.getInstance().getCurrent();
InfiniteProgress inf = new InfiniteProgress();
final Dialog progress = inf.showInifiniteBlocking();
Form authenticationForm = new Form("Login");
authenticationForm.setScrollable(false);
if (old != null) {
Command cancel = new Command("Cancel") {
public void actionPerformed(ActionEvent ev) {
if (Display.getInstance().getCurrent() == progress) {
progress.dispose();
}
old.showBack();
}
};
if (authenticationForm.getToolbar() != null) {
authenticationForm.getToolbar().addCommandToLeftBar(cancel);
} else {
authenticationForm.addCommand(cancel);
}
authenticationForm.setBackCommand(cancel);
}
authenticationForm.setLayout(new BorderLayout());
authenticationForm.addComponent(BorderLayout.CENTER, createLoginComponent(al, authenticationForm, old, progress));
}
use of com.codename1.ui.events.ActionListener in project CodenameOne by codenameone.
the class Oauth2 method createLoginComponent.
private Component createLoginComponent(final ActionListener al, final Form frm, final Form backToForm, final Dialog progress) {
String URL = oauth2URL + "?client_id=" + clientId + "&redirect_uri=" + Util.encodeUrl(redirectURI);
if (scope != null) {
URL += "&scope=" + scope;
}
if (clientSecret != null) {
URL += "&response_type=code";
} else {
URL += "&response_type=token";
}
if (additionalParams != null) {
Enumeration e = additionalParams.keys();
while (e.hasMoreElements()) {
String key = (String) e.nextElement();
String val = additionalParams.get(key).toString();
URL += "&" + key + "=" + val;
}
}
DocumentInfo.setDefaultEncoding(DocumentInfo.ENCODING_UTF8);
final WebBrowser[] web = new WebBrowser[1];
web[0] = new WebBrowser() {
@Override
public void onLoad(String url) {
handleURL(url, this, al, frm, backToForm, progress);
}
public void onStart(String url) {
}
};
web[0].setURL(URL);
return web[0];
}
use of com.codename1.ui.events.ActionListener 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.ui.events.ActionListener 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