use of com.codename1.ui.events.ActionEvent in project CodenameOne by codenameone.
the class FaceBookAccess method getPost.
/**
* Gets a Post from a postId
* This is a sync method it will block until a response it returned
* @param postId the post id
* @param needAuth if this object is public needAuth can be false and no
* authentication will be performed
* @return the Post requested
*/
public Post getPost(String postId, boolean needAuth) throws IOException {
final Post post = new Post();
final Vector err = new Vector();
addResponseCodeListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
NetworkEvent ne = (NetworkEvent) evt;
err.addElement(ne);
removeResponseCodeListener(this);
}
});
getFaceBookObject(postId, new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Vector v = (Vector) ((NetworkEvent) evt).getMetaData();
Hashtable t = (Hashtable) v.elementAt(0);
post.copy(t);
}
}, needAuth, false);
if (err.size() > 0) {
throw new IOException(((NetworkEvent) err.elementAt(0)).getResponseCode() + ": " + ((NetworkEvent) err.elementAt(0)).getMessage());
}
return post;
}
use of com.codename1.ui.events.ActionEvent in project CodenameOne by codenameone.
the class FaceBookAccess method getAlbum.
/**
* Gets a Album from a albumId
* This is a sync method it will block until a response it returned
* @param the albumId
* @param needAuth if this object is public needAuth can be false and no
* authentication will be performed
*
* @return the Album requested
*/
public Album getAlbum(String albumId, boolean needAuth) throws IOException {
final Album album = new Album();
final Vector err = new Vector();
addResponseCodeListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
NetworkEvent ne = (NetworkEvent) evt;
err.addElement(ne);
removeResponseCodeListener(this);
}
});
getFaceBookObject(albumId, new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Vector v = (Vector) ((NetworkEvent) evt).getMetaData();
Hashtable t = (Hashtable) v.elementAt(0);
album.copy(t);
}
}, needAuth, false);
if (err.size() > 0) {
throw new IOException(((NetworkEvent) err.elementAt(0)).getResponseCode() + ": " + ((NetworkEvent) err.elementAt(0)).getMessage());
}
return album;
}
use of com.codename1.ui.events.ActionEvent in project CodenameOne by codenameone.
the class FaceBookAccess method getPage.
/**
* Gets a Page from a pageId/name
* This is a sync method it will block until a response it returned
* @param pageId the pageId
* @return the Page requested
*/
public Page getPage(String pageId) throws IOException {
final Page page = new Page();
final Vector err = new Vector();
addResponseCodeListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
NetworkEvent ne = (NetworkEvent) evt;
err.addElement(ne);
removeResponseCodeListener(this);
}
});
getFaceBookObject(pageId, new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Vector v = (Vector) ((NetworkEvent) evt).getMetaData();
Hashtable t = (Hashtable) v.elementAt(0);
page.copy(t);
}
}, false, false);
if (err.size() > 0) {
throw new IOException(((NetworkEvent) err.elementAt(0)).getResponseCode() + ": " + ((NetworkEvent) err.elementAt(0)).getMessage());
}
return page;
}
use of com.codename1.ui.events.ActionEvent in project CodenameOne by codenameone.
the class CodenameOneActivity method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
super.onOptionsItemSelected(item);
final Form currentForm = Display.getInstance().getCurrent();
if (currentForm == null) {
return false;
}
Command cmd = null;
final boolean[] tmpProp = new boolean[1];
if (item.getItemId() == android.R.id.home) {
cmd = currentForm.getBackCommand();
if (cmd == null) {
return false;
}
cmd.putClientProperty("source", "ActionBar");
tmpProp[0] = true;
}
int commandIndex = item.getItemId();
if (cmd == null) {
cmd = currentForm.getCommand(commandIndex);
}
final Command command = cmd;
final ActionEvent actionEvent = new ActionEvent(command);
// stop edit if the keybaord is open
AndroidImplementation.stopEditing();
// Protect ourselves from commands that misbehave. A crash here will crash the entire application
Display.getInstance().callSerially(new Runnable() {
@Override
public void run() {
try {
currentForm.dispatchCommand(command, actionEvent);
// remove the temp source property
if (tmpProp[0]) {
command.putClientProperty("source", null);
}
} catch (Throwable e) {
Log.e("CodenameOneActivity.onOptionsItemSelected", e.toString() + Log.getStackTraceString(e));
}
}
});
return true;
}
use of com.codename1.ui.events.ActionEvent in project CodenameOne by codenameone.
the class ResetableTextWatcher method showVirtualKeyboard.
/**
* Show or hide the virtual keyboard if necessary
* @param show Show the keyboard if true, hide it otherwise
*/
private void showVirtualKeyboard(boolean show) {
Log.i(TAG, "showVirtualKeyboard show=" + show);
boolean result = false;
if (show) {
// If we're in landscape, Android will not show the soft
// keyboard unless SHOW_FORCED is requested
Configuration config = mResources.getConfiguration();
boolean isLandscape = (config.orientation == Configuration.ORIENTATION_LANDSCAPE);
int showFlags = isLandscape ? InputMethodManager.SHOW_FORCED : InputMethodManager.SHOW_IMPLICIT;
mInputManager.restartInput(mEditText);
result = mInputManager.showSoftInput(mEditText, showFlags, mResultReceiver);
} else {
if (mEditText == null) {
if (showVKB) {
mInputManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}
} else {
result = mInputManager.hideSoftInputFromWindow(mEditText.getWindowToken(), 0, mResultReceiver);
}
closedTime = System.currentTimeMillis();
}
showVKB = show;
final boolean showKeyboard = showVKB;
final ActionListener listener = Display.getInstance().getVirtualKeyboardListener();
if (listener != null) {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
// keyboard is opened or closed
try {
Thread.sleep(600);
} catch (InterruptedException ex) {
}
Display.getInstance().callSerially(new Runnable() {
@Override
public void run() {
ActionEvent evt = new ActionEvent(showKeyboard);
listener.actionPerformed(evt);
}
});
}
});
t.setUncaughtExceptionHandler(AndroidImplementation.exceptionHandler);
t.start();
}
Log.d(TAG, "InputMethodManager returned " + Boolean.toString(result).toUpperCase());
}
Aggregations