Search in sources :

Example 11 with ActionEvent

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;
}
Also used : ActionListener(com.codename1.ui.events.ActionListener) ActionEvent(com.codename1.ui.events.ActionEvent) Hashtable(java.util.Hashtable) NetworkEvent(com.codename1.io.NetworkEvent) IOException(java.io.IOException) Vector(java.util.Vector)

Example 12 with ActionEvent

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;
}
Also used : ActionListener(com.codename1.ui.events.ActionListener) ActionEvent(com.codename1.ui.events.ActionEvent) Hashtable(java.util.Hashtable) NetworkEvent(com.codename1.io.NetworkEvent) IOException(java.io.IOException) Vector(java.util.Vector)

Example 13 with ActionEvent

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;
}
Also used : ActionListener(com.codename1.ui.events.ActionListener) ActionEvent(com.codename1.ui.events.ActionEvent) Hashtable(java.util.Hashtable) NetworkEvent(com.codename1.io.NetworkEvent) IOException(java.io.IOException) Vector(java.util.Vector)

Example 14 with ActionEvent

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;
}
Also used : Form(com.codename1.ui.Form) Command(com.codename1.ui.Command) ActionEvent(com.codename1.ui.events.ActionEvent)

Example 15 with ActionEvent

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());
}
Also used : Configuration(android.content.res.Configuration) ActionListener(com.codename1.ui.events.ActionListener) ActionEvent(com.codename1.ui.events.ActionEvent) Paint(android.graphics.Paint)

Aggregations

ActionEvent (com.codename1.ui.events.ActionEvent)98 ActionListener (com.codename1.ui.events.ActionListener)55 IOException (java.io.IOException)30 BorderLayout (com.codename1.ui.layouts.BorderLayout)28 Form (com.codename1.ui.Form)18 Hashtable (java.util.Hashtable)14 Vector (java.util.Vector)11 NetworkEvent (com.codename1.io.NetworkEvent)10 Container (com.codename1.ui.Container)9 ActionEvent (java.awt.event.ActionEvent)9 Command (com.codename1.ui.Command)8 ActionListener (java.awt.event.ActionListener)8 Button (com.codename1.ui.Button)7 Style (com.codename1.ui.plaf.Style)7 Rectangle (com.codename1.ui.geom.Rectangle)6 File (java.io.File)6 ConnectionNotFoundException (javax.microedition.io.ConnectionNotFoundException)6 MediaException (javax.microedition.media.MediaException)6 RecordStoreException (javax.microedition.rms.RecordStoreException)6 BufferedOutputStream (com.codename1.io.BufferedOutputStream)5