Java Code Examples for com.codename1.ui.events.ActionEvent

The following examples show how to use com.codename1.ui.events.ActionEvent. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: CodenameOne   Author: codenameone   File: Toolbar.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Shows the search bar manually which is useful for use cases of popping 
 * up search from code
 * 
 * @param callback gets the search string callbacks
 */
public void showSearchBar(final ActionListener callback) {        
    SearchBar s = new SearchBar(Toolbar.this, searchIconSize) {

        @Override
        public void onSearch(String text) {
            callback.actionPerformed(new ActionEvent(text));
        }

    };
    Form f = (Form) Toolbar.this.getComponentForm();
    setHidden(true);
    f.removeComponentFromForm(Toolbar.this);
    f.setToolbar(s);
    s.initSearchBar();
    if(f == Display.INSTANCE.getCurrent()) {
        f.animateLayout(100);
    }
}
 
Example #2
Source Project: parse4cn1   Author: sidiabale   File: StateMachine.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onMain_CheckBoxRawJsonAction(Component c, ActionEvent event) {
    CheckBox rawPushCheckbox = (CheckBox)c;
    if (rawPushCheckbox.isSelected()) {
        try {
            final String existing = findTextAreaPush().getText();
            JSONObject data = new JSONObject();
            data.put("alert", existing);
            findTextAreaPush().setText(data.toString());
        } catch (JSONException ex) {
            // Ignore error and initialize to default
            findTextAreaPush().setText("{\n"
                    + "  \"alert\":\"message\""
                    + "\n}");
        }
    } else {
        findTextAreaPush().setText("");
    }
}
 
Example #3
Source Project: CodenameOne   Author: codenameone   File: Sheet.java    License: GNU General Public License v2.0 6 votes vote down vote up
private void initUI() {
    setLayout(new BorderLayout());
    contentPane.setSafeArea(true);
    titleBar.setSafeArea(true);
    add(BorderLayout.NORTH, titleBar);
    if (parentSheet != null) {
        FontImage.setMaterialIcon(backButton, FontImage.MATERIAL_ARROW_BACK);
    }
    add(BorderLayout.CENTER, contentPane);
    backButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            back(DEFAULT_TRANSITION_DURATION);
        }
    });
    
}
 
Example #4
Source Project: codenameone-demos   Author: codenameone   File: PushDemo.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void start() {
    if(current != null){
        current.show();
        return;
    }
    s = new StateMachine("/theme");        
    
    Display.getInstance().addEdtErrorHandler(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            evt.consume();
            Log.p("Exception in AppName version " + Display.getInstance().getProperty("AppVersion", "Unknown"));
            Log.p("OS " + Display.getInstance().getPlatformName());
            Log.p("Error " + evt.getSource());
            Log.p("Current Form " + Display.getInstance().getCurrent().getName());
            Log.e((Throwable)evt.getSource());
            Log.sendLog();
        }
    });
}
 
Example #5
Source Project: codenameone-demos   Author: codenameone   File: PhotoShare.java    License: GNU General Public License v2.0 6 votes vote down vote up
Button createImageButton(final long imageId, final Container grid, final int offset) {
    final Button btn = new Button(URLImage.createToFileSystem(placeholder, FileSystemStorage.getInstance().getAppHomePath() + "/Thumb_" + imageId, THUMB_URL_PREFIX + imageId, URLImage.RESIZE_SCALE_TO_FILL));
    btn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            imageList.setSelectedIndex(offset);
            final Container viewerParent = new Container(new LayeredLayout());
            ImageViewer viewer = new ImageViewer(imageList.getItemAt(offset));
            viewerParent.addComponent(viewer);
            Container parent = new Container(new BorderLayout());
            viewerParent.addComponent(parent);
            parent.addComponent(BorderLayout.SOUTH, createToolbar(imageId));
            
            likeCount = new Label("");
            parent.addComponent(BorderLayout.NORTH, likeCount);
            
            
            viewer.setImageList(imageList);
            grid.getParent().replace(grid, viewerParent, CommonTransitions.createSlide(CommonTransitions.SLIDE_HORIZONTAL, false, 300));
            Display.getInstance().getCurrent().setBackCommand(createBackCommand(viewerParent, grid));
        }
    });
    return btn;
}
 
Example #6
Source Project: codenameone-demos   Author: codenameone   File: PhotoShare.java    License: GNU General Public License v2.0 6 votes vote down vote up
ActionListener createDetailsButtonActionListener(final long imageId) {
    return new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                InfiniteProgress ip = new InfiniteProgress();
                Dialog dlg = ip.showInifiniteBlocking();
                try {
                    String[] data = WebServiceProxy.getPhotoDetails(imageId);
                    String s = "";
                    for(String d : data) {
                        s += d;
                        s += "\n";
                    }
                    dlg.dispose();
                    Dialog.show("Data", s, "OK", null);
                } catch(IOException err) {
                    dlg.dispose();
                    Dialog.show("Error", "Error connecting to server", "OK", null);
                }
            }
        };
}
 
Example #7
Source Project: CodenameOne   Author: codenameone   File: Button.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Allows subclasses to override action event behavior 
 * {@inheritDoc}
 * 
 * @param x the x position of the click if applicable (can be 0 or -1 otherwise)
 * @param y the y position of the click if applicable (can be 0 or -1 otherwise)
 */
protected void fireActionEvent(int x, int y){
    super.fireActionEvent();
    if(cmd != null) {
        ActionEvent ev = new ActionEvent(cmd, this, x, y);
        dispatcher.fireActionEvent(ev);
        if(!ev.isConsumed()) {
            Form f = getComponentForm();
            if(f != null) {
                f.actionCommandImplNoRecurseComponent(cmd, ev);
            }
        }
    } else {
        dispatcher.fireActionEvent(new ActionEvent(this, ActionEvent.Type.PointerPressed,x, y));
    }
    Display d = Display.getInstance();
    if(d.isBuiltinSoundsEnabled()) {
        d.playBuiltinSound(Display.SOUND_TYPE_BUTTON_PRESS);
    }
}
 
Example #8
Source Project: CodenameOne   Author: codenameone   File: TextComponentPassword.java    License: GNU General Public License v2.0 6 votes vote down vote up
public TextComponentPassword() {
    super();
    field.setConstraint(TextArea.PASSWORD);
    action(FontImage.MATERIAL_VISIBILITY_OFF).
        actionClick(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (field.getConstraint() == TextArea.PASSWORD) {
                    field.setConstraint(TextField.NON_PREDICTIVE);
                    action(FontImage.MATERIAL_VISIBILITY_OFF);
                } else {
                    field.setConstraint(TextField.PASSWORD);
                    action(FontImage.MATERIAL_VISIBILITY);
                }
                if (field.isEditing()) {
                    field.stopEditing();
                    field.startEditingAsync();
                } else {
                    field.getParent().revalidate();
                }
            }
        });
}
 
Example #9
Source Project: codenameone-demos   Author: codenameone   File: FBDemo.java    License: GNU General Public License v2.0 6 votes vote down vote up
private Component showMyFriends() {
    final Container c = new Container(new BorderLayout());
    c.setScrollable(false);
    BorderLayout bl = new BorderLayout();
    bl.setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE);
    Container p = new Container(bl);
    p.addComponent(BorderLayout.CENTER, new InfiniteProgress());

    c.addComponent(BorderLayout.CENTER, p);
    final List myFriends = new List();
    myFriends.setRenderer(new FriendsRenderer());
    try {
        FaceBookAccess.getInstance().getUserFriends("me", (DefaultListModel) myFriends.getModel(), new ActionListener() {

            public void actionPerformed(ActionEvent evt) {
                c.removeAll();
                c.addComponent(BorderLayout.CENTER, myFriends);
                c.revalidate();
            }
        });
    } catch (IOException ex) {
        ex.printStackTrace();
    }
    return c;
}
 
Example #10
Source Project: CodenameOne   Author: codenameone   File: AutoCompleteTextField.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void actionPerformed(ActionEvent evt) {
    pressInBounds = false;
    final Form f = getComponentForm();
    Container layered = f.getLayeredPane(AutoCompleteTextField.this.getClass(), true);

    boolean canOpenPopup = true;

    for (int i = 0; i < layered.getComponentCount(); i++) {
        Container wrap = (Container) layered.getComponentAt(i);
        Component pop = wrap.getComponentAt(0);
        if(pop.isVisible()){
            if(!pop.contains(evt.getX(), evt.getY())){

            }else{
                pressInBounds = true;
            }
        }
    }
}
 
Example #11
Source Project: CodenameOne   Author: codenameone   File: BlackBerryCanvas.java    License: GNU General Public License v2.0 6 votes vote down vote up
protected boolean keyControl(char c, int status, int time) {
    if(c == Characters.CONTROL_VOLUME_UP || c == Characters.CONTROL_VOLUME_DOWN) {
        int i = MMAPIPlayer.getGlobalVolume();
        if(i == -1) {
            i = 70;
        }
        if(c == Characters.CONTROL_VOLUME_UP) {
            MMAPIPlayer.setGlobalVolume(Math.min(100, i + 4));
        } else {
            MMAPIPlayer.setGlobalVolume(Math.max(0, i - 4));
        }
        if(BlackBerryImplementation.getVolumeListener() != null) {
            BlackBerryImplementation.getVolumeListener().fireActionEvent(new ActionEvent(this, c));
            return true;
        }
    }
    return super.keyControl(c, status, time);
}
 
Example #12
Source Project: CodenameOne   Author: codenameone   File: HTMLImageMap.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void actionPerformed(ActionEvent evt) {
    if (mapData!=null) {
        int x=evt.getX();
        int y=evt.getY();
        if ((mapData.areas!=null) && (x!=-1)) {
            for(Enumeration e=mapData.areas.keys();e.hasMoreElements();) {
                Rectangle rect = (Rectangle)e.nextElement();
                if (rect.contains(x-getAbsoluteX(), y-getAbsoluteY())) {
                    String link=(String)mapData.areas.get(rect);
                    if (link!=null) {
                        HTMLLink.processLink(htmlC, link);
                    }
                    return;
                }
            }
        }
        if (mapData.defaultLink!=null) {
            HTMLLink.processLink(htmlC, mapData.defaultLink);
        }
    }

}
 
Example #13
Source Project: CodenameOne   Author: codenameone   File: Form.java    License: GNU General Public License v2.0 6 votes vote down vote up
private boolean fireReleaseListeners(int x, int y) {
    if (pointerReleasedListeners != null && pointerReleasedListeners.hasListeners()) {
        ActionEvent ev = new ActionEvent(this, ActionEvent.Type.PointerReleased, x, y);
        pointerReleasedListeners.fireActionEvent(ev);
        if(ev.isConsumed()) {
            if (dragged != null) {
                if (dragged.isDragAndDropInitialized()) {
                    LeadUtil.dragFinished(dragged, x, y);

                }
                dragged = null;
            }
            return true;
        }
    }
    return false;
}
 
Example #14
Source Project: CodenameOne   Author: codenameone   File: Log.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Binds pro based crash protection logic that will send out an email in case of an exception thrown on the EDT
 * 
 * @param consumeError true will hide the error from the user, false will leave the builtin logic that defaults to
 * showing an error dialog to the user
 */
public static void bindCrashProtection(final boolean consumeError) {
    if(Display.getInstance().isSimulator()) {
        return;
    }
    Display.getInstance().addEdtErrorHandler(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            if(consumeError) {
                evt.consume();
            }
            p("Exception in " + Display.getInstance().getProperty("AppName", "app") + " version " + Display.getInstance().getProperty("AppVersion", "Unknown"));
            p("OS " + Display.getInstance().getPlatformName());
            p("Error " + evt.getSource());
            if(Display.getInstance().getCurrent() != null) {
                p("Current Form " + Display.getInstance().getCurrent().getName());
            } else {
                p("Before the first form!");
            }
            e((Throwable)evt.getSource());
            if(getUniqueDeviceKey() != null) {
                sendLog();
            }
        }
    });
    crashBound = true;
}
 
Example #15
Source Project: CodenameOne   Author: codenameone   File: UIBuilder.java    License: GNU General Public License v2.0 6 votes vote down vote up
private void processCommandImpl(ActionEvent ev, Command cmd) {
    processCommand(ev, cmd);
    if(ev.isConsumed()) {
        return;
    }
    if(globalCommandListeners != null) {
        globalCommandListeners.fireActionEvent(ev);
        if(ev.isConsumed()) {
            return;
        }
    }

    if(localCommandListeners != null) {
        Form f = Display.getInstance().getCurrent();
        EventDispatcher e = (EventDispatcher)localCommandListeners.get(f.getName());
        if(e != null) {
            e.fireActionEvent(ev);
        }
    }
}
 
Example #16
Source Project: CodenameOne   Author: codenameone   File: FaceBookAccess.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Gest a post from a post Id
 *
 * @param postId the postId
 * @param post an Object to fill with the data
 * @param callback the callback that should be updated when the data arrives
 */
public void getPost(String postId, final Post post, final ActionListener callback) throws IOException {
    getFaceBookObject(postId, new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            Vector v = (Vector) ((NetworkEvent) evt).getMetaData();
            Hashtable t = (Hashtable) v.elementAt(0);
            if (post != null) {
                post.copy(t);
            }
            if (callback != null) {
                callback.actionPerformed(evt);
            }
        }
    });
}
 
Example #17
Source Project: CodenameOne   Author: codenameone   File: FaceBookAccess.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Gest an album from an albumId
 *
 * @param albumId the albumId
 * @param album an Object to fill with the data
 * @param callback the callback that should be updated when the data arrives
 */
public void getAlbum(String albumId, final Album album, final ActionListener callback) throws IOException {
    getFaceBookObject(albumId, new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            Vector v = (Vector) ((NetworkEvent) evt).getMetaData();
            Hashtable t = (Hashtable) v.elementAt(0);
            if (album != null) {
                album.copy(t);
            }
            if (callback != null) {
                callback.actionPerformed(evt);
            }
        }
    });
}
 
Example #18
Source Project: CodenameOne   Author: codenameone   File: LikeButton.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void actionPerformed(ActionEvent evt) {
    if(!FaceBookAccess.getInstance().isAuthenticated()) {
        FaceBookAccess.setClientId(appId);
        FaceBookAccess.setRedirectURI(redirectURI);
        FaceBookAccess.setClientSecret(clientSecret);
        if(permissions != null) {
            FaceBookAccess.setPermissions(permissions);            
        }
        FaceBookAccess.getInstance().showAuthentication(this);
        return;
    }
    if(evt.getSource() instanceof Exception) {
        return;
    }
    try {
        FaceBookAccess.getInstance().postLike(getPostId());
    } catch (IOException ex) {
        Log.e(ex);
    }
}
 
Example #19
Source Project: CodenameOne   Author: codenameone   File: ClearableTextField.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Wraps the given text field with a UI that will allow us to clear it
 * @param tf the text field
 * @param iconSize size in millimeters for the clear icon, -1 for default size
 * @return a Container that should be added to the UI instead of the actual text field
 */
public static ClearableTextField wrap(final TextArea tf, float iconSize) {
    ClearableTextField cf = new ClearableTextField();
    Button b = new Button("", tf.getUIID());
    if(iconSize > 0) {
        FontImage.setMaterialIcon(b, FontImage.MATERIAL_CLEAR, iconSize);
    } else {
        FontImage.setMaterialIcon(b, FontImage.MATERIAL_CLEAR);
    }
    removeCmpBackground(tf);
    removeCmpBackground(b);
    cf.setUIID(tf.getUIID());
    cf.add(BorderLayout.CENTER, tf);
    cf.add(BorderLayout.EAST, b);
    b.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            tf.stopEditing();
            tf.setText("");
            tf.startEditingAsync();
        }
    });
    return cf;        
}
 
Example #20
Source Project: CodenameOne   Author: codenameone   File: AdsService.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
protected void readResponse(InputStream input) throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    byte[] buffer = new byte[256];
    int len;
    while ((len = input.read(buffer)) > 0) {
        out.write(buffer, 0, len);
    }

    int size = out.toByteArray().length;
    if (size > 0) {
        String s = new String(out.toByteArray(), 0, size, "UTF-8");
        currentAd = s;
        fireResponseListener(new ActionEvent(currentAd,ActionEvent.Type.Response));
    }
}
 
Example #21
Source Project: CodenameOne   Author: codenameone   File: TestUtils.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Executes the back command for the current form, similarly to pressing the back button
 */
public static void goBack() {
    if(verbose) {
        log("goBack()");
    }
    Form f = Display.getInstance().getCurrent();
    Command c = f.getBackCommand();
    assertBool(c != null, "The current form doesn't have a back command at this moment! for form name " + f.getName());
    f.dispatchCommand(c, new ActionEvent(c,ActionEvent.Type.Command));
    waitFor(20);
}
 
Example #22
Source Project: parse4cn1   Author: sidiabale   File: StateMachine.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void onMain_ButtonAction(Component c, ActionEvent event) {
    try {
        Logger.getInstance().showLog();
    } catch (ParseException ex) {
        Dialog.show("Error", 
                "Showing log failed:\n\n" + ex.getMessage(), 
                Dialog.TYPE_ERROR, null, "OK", null);
    }
}
 
Example #23
Source Project: parse4cn1   Author: sidiabale   File: StateMachine.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void onMain_ButtonClearBadgeAction(Component c, ActionEvent event) {
    if (Parse.getPlatform() != Parse.EPlatform.IOS) {
        Dialog.show("Info", "Badging the app icon is only supported on iOS", "OK", null);
    } else {
        try {
            ParseInstallation.getCurrentInstallation().setBadge(0);
        } catch (ParseException ex) {
            Dialog.show("Error", 
                "Clearing badge failed:\n\n" + ex.getMessage(), 
                Dialog.TYPE_ERROR, null, "OK", null);
        }
    }
}
 
Example #24
Source Project: codenameone-demos   Author: codenameone   File: PropertyCross.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Shows the favorites screen 
 */
void showFavs() {
    final Form favsForm = new Form("Favourites");
    addBackToHome(favsForm);
    favsForm.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
    if(favoritesList.size() == 0) {
        favsForm.addComponent(new SpanLabel("You have not added any properties to your favourites"));
    } else {
        // this is really trivial we just take the favorites and show them as a set of buttons
        for(Map<String, Object> c : favoritesList) {
            MultiButton mb = new MultiButton();
            final Map<String, Object> currentListing = c;
            String thumb_url = (String)currentListing.get("thumb_url");
            String guid = (String)currentListing.get("guid");
            String price_formatted = (String)currentListing.get("price_formatted");
            String summary = (String)currentListing.get("summary");
            mb.setIcon(URLImage.createToStorage(placeholder, guid, thumb_url, URLImage.RESIZE_SCALE_TO_FILL));
            mb.setTextLine1(price_formatted);
            mb.setTextLine2(summary);
            mb.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    showPropertyDetails(favsForm, currentListing);
                }
            });
            favsForm.addComponent(mb);
        }
    }
    favsForm.show();
}
 
Example #25
Source Project: codenameone-demos   Author: codenameone   File: Poker.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * A blocking method that creates the card deal animation and binds the drop logic when cards are dropped on the deck
 */
private void dealCard(Component deck, final Container destination, Image cardImage, Card currentCard) {
    final Button card = new Button();
    card.setUIID("Label");
    card.setIcon(cardImage);
    
    // Components are normally placed by layout managers so setX/Y/Width/Height shouldn't be invoked. However,
    // in this case we want the layout animation to deal from a specific location. Notice that we use absoluteX/Y
    // since the default X/Y are relative to their parent container.
    card.setX(deck.getAbsoluteX());
    int deckAbsY = deck.getAbsoluteY();
    if(destination.getY() > deckAbsY) {
        card.setY(deckAbsY - destination.getAbsoluteY());
    } else {
        card.setY(deckAbsY);
    }
    card.setWidth(deck.getWidth());
    card.setHeight(deck.getHeight());
    destination.addComponent(card);
    
    // we save the model data directly into the component so we don't need to keep track of it. Later when we
    // need to check the card type a user touched we can just use getClientProperty
    card.putClientProperty("card", currentCard);
    destination.getParent().animateHierarchyAndWait(400);
    card.setDraggable(true);
    
    // when the user drops a card on a drop target (currently only the deck) we remove it and animate it out
    card.addDropListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            evt.consume();
            card.getParent().removeComponent(card);
            destination.animateLayout(300);
        }
    });
}
 
Example #26
Source Project: codenameone-demos   Author: codenameone   File: PhotoShare.java    License: GNU General Public License v2.0 5 votes vote down vote up
private void showLoginForm() {
    Form login = new Form("Login");
    BorderLayout bl = new BorderLayout();
    bl.setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE);
    ComponentGroup loginDetails = new ComponentGroup();
    
    TextField displayName = new TextField();
    displayName.setHint("Display Name");
    loginDetails.addComponent(displayName);

    final TextField email = new TextField();
    email.setHint("E-Mail");
    loginDetails.addComponent(email);

    Button send = new Button("Send Verification");
    loginDetails.addComponent(send);
    
    send.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            onSendAction(email);
        }
    });
    
    login.setLayout(bl);
    login.addComponent(BorderLayout.CENTER, loginDetails);
    login.show();
}
 
Example #27
Source Project: codenameone-demos   Author: codenameone   File: PhotoShare.java    License: GNU General Public License v2.0 5 votes vote down vote up
private Command createPictureCommand(final Container grid) {
    return new Command("Take Picture") {
        public void actionPerformed(ActionEvent ev) {
            String picture = Capture.capturePhoto(1024, -1);
            if(picture == null) {
                return;
            }
            MultipartRequest mp = new MultipartRequest() {
                private long key;
                @Override
                protected void readResponse(InputStream input) throws IOException {
                    DataInputStream di = new DataInputStream(input);
                    key = di.readLong();
                }

                @Override
                protected void postResponse() {
                    final Button btn = createImageButton(key, grid, imageList.getSize());
                    imageList.addImageId(key);
                    grid.addComponent(0, btn);
                    if(!animating) {
                        animating = true;
                        grid.animateLayoutAndWait(400);
                        animating = false;
                    }
                }
            };
            mp.setUrl(UPLOAD_URL);
            try {
                mp.addData("i", picture, "image/jpeg");
                mp.addArgument("p", "Data;More data");
                NetworkManager.getInstance().addToQueue(mp);
            } catch(IOException err) {
                err.printStackTrace();
            }
        }
    };
}
 
Example #28
Source Project: codenameone-demos   Author: codenameone   File: PhotoShare.java    License: GNU General Public License v2.0 5 votes vote down vote up
ActionListener createLikeAction(final long imageId) {
    return new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                try {
                    WebServiceProxy.likePhoto(imageId, Preferences.get("key", ""));
                } catch(IOException err) {
                    err.printStackTrace();
                }
            }
        };
}
 
Example #29
Source Project: CodenameOne   Author: codenameone   File: WebSocketsSample.java    License: GNU General Public License v2.0 5 votes vote down vote up
void showChat() {
    Form f= new Form("Chat");
    f.setLayout(new BorderLayout());
    
    Container south = new Container();
    final TextField tf = new TextField();
    Button send = new Button(new Command("Send") {

        @Override
        public void actionPerformed(ActionEvent evt) {
            if (sock.getReadyState() == WebSocketState.OPEN) {
                sock.send(tf.getText());
                tf.setText("");
            } else {
                Dialog.show("", "The socket is not open", "OK", null);
                showLogin();
            }
            
        }
         
    });
    
    chatContainer = new Container();
    chatContainer.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
    
    south.addComponent(tf);
    south.addComponent(send);
    f.addComponent(BorderLayout.SOUTH, south);
    f.addComponent(BorderLayout.CENTER, chatContainer);
    f.setFormBottomPaddingEditingMode(true);
    f.show();
    
}
 
Example #30
Source Project: CodenameOne   Author: codenameone   File: HTMLForm.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void actionPerformed(ActionEvent evt) {
    super.actionPerformed(evt);
    if (isSubmit) {
        htmlForm.submit(key,value);
    } else {
        htmlForm.reset();
    }
}