Search in sources :

Example 16 with Command

use of com.codename1.ui.Command 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));
}
Also used : BorderLayout(com.codename1.ui.layouts.BorderLayout) Form(com.codename1.ui.Form) InfiniteProgress(com.codename1.components.InfiniteProgress) Command(com.codename1.ui.Command) Dialog(com.codename1.ui.Dialog) ActionEvent(com.codename1.ui.events.ActionEvent)

Example 17 with Command

use of com.codename1.ui.Command in project CodenameOne by codenameone.

the class CodenameOneActivity method onPrepareOptionsMenu.

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    menu.clear();
    try {
        Form currentForm = Display.getInstance().getCurrent();
        if (currentForm == null) {
            return false;
        }
        int numCommands = currentForm.getCommandCount();
        // If there are no commands, there's nothing to put in the menu
        if (numCommands == 0) {
            return false;
        }
        // Build menu items from commands
        for (int n = 0; n < numCommands; n++) {
            Command command = currentForm.getCommand(n);
            if (command != null) {
                String txt = currentForm.getUIManager().localize(command.getCommandName(), command.getCommandName());
                MenuItem item = menu.add(Menu.NONE, n, Menu.NONE, txt);
                Image icon = command.getIcon();
                if (icon != null) {
                    Bitmap b = (Bitmap) icon.getImage();
                    // Using BitmapDrawable with resources, to use device density (from 1.6 and above).
                    BitmapDrawable d = new BitmapDrawable(getResources(), b);
                    item.setIcon(d);
                }
                if (!command.isEnabled()) {
                    item.setEnabled(false);
                }
                if (android.os.Build.VERSION.SDK_INT >= 11 && command.getClientProperty("android:showAsAction") != null) {
                    String androidShowAsAction = command.getClientProperty("android:showAsAction").toString();
                    // "ifRoom" | "never" | "withText" | "always" | "collapseActionView"
                    if (androidShowAsAction.equalsIgnoreCase("ifRoom")) {
                        item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
                    } else if (androidShowAsAction.equalsIgnoreCase("never")) {
                        item.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
                    } else if (androidShowAsAction.equalsIgnoreCase("withText")) {
                        item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
                    } else if (androidShowAsAction.equalsIgnoreCase("always")) {
                        item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
                    } else if (android.os.Build.VERSION.SDK_INT >= 14 && androidShowAsAction.equalsIgnoreCase("collapseActionView")) {
                        // MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW
                        item.setShowAsAction(8);
                    }
                }
            }
        }
    } catch (Throwable t) {
    }
    return nativeMenu;
}
Also used : Bitmap(android.graphics.Bitmap) Form(com.codename1.ui.Form) Command(com.codename1.ui.Command) MenuItem(android.view.MenuItem) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Image(com.codename1.ui.Image)

Example 18 with Command

use of com.codename1.ui.Command 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 19 with Command

use of com.codename1.ui.Command in project CodenameOne by codenameone.

the class BlackBerryCanvas method getMenu.

public Menu getMenu(int val) {
    if (Display.getInstance().getCommandBehavior() == Display.COMMAND_BEHAVIOR_NATIVE) {
        m = new Menu();
        if (commands != null) {
            for (int iter = 0; iter < commands.size(); iter++) {
                final Command cmd = (Command) commands.elementAt(iter);
                String txt = UIManager.getInstance().localize(cmd.getCommandName(), cmd.getCommandName());
                MenuItem i = new MenuItem(txt, iter, iter) {

                    public void run() {
                        Display.getInstance().callSerially(new Runnable() {

                            public void run() {
                                impl.getCurrentForm().dispatchCommand(cmd, new ActionEvent(cmd));
                            }
                        });
                    }
                };
                m.add(i);
            }
        }
        return m;
    }
    return super.getMenu(val);
}
Also used : Command(com.codename1.ui.Command) ActionEvent(com.codename1.ui.events.ActionEvent) MenuItem(net.rim.device.api.ui.MenuItem) Menu(net.rim.device.api.ui.component.Menu)

Example 20 with Command

use of com.codename1.ui.Command in project CodenameOne by codenameone.

the class RSSReader method showRSSEntry.

/**
 * Shows a form containing the RSS entry
 *
 * @param h the parsed entry
 */
protected void showRSSEntry(Hashtable h) {
    Form newForm = null;
    if (targetContainer != null) {
        if (targetContainer instanceof Form) {
            newForm = (Form) targetContainer;
        } else {
            newForm = new Form((String) h.get("title"));
            newForm.setLayout(new BorderLayout());
            newForm.addComponent(BorderLayout.CENTER, targetContainer);
        }
        updateComponentValues(newForm, h);
    } else {
        newForm = new Form((String) h.get("title"));
        newForm.setScrollable(false);
        WebBrowser c = new WebBrowser();
        String s = (String) h.get("description");
        s = "<html><body>" + s + "</body></html>";
        c.setPage(s, null);
        newForm.setLayout(new BorderLayout());
        newForm.addComponent(BorderLayout.CENTER, c);
    }
    if (addBackToTaget) {
        final Form sourceForm = Display.getInstance().getCurrent();
        Command back = new BackCommand(sourceForm);
        newForm.addCommand(back);
        newForm.setBackCommand(back);
    }
    newForm.show();
}
Also used : BorderLayout(com.codename1.ui.layouts.BorderLayout) Form(com.codename1.ui.Form) Command(com.codename1.ui.Command)

Aggregations

BorderLayout (com.codename1.ui.layouts.BorderLayout)25 Command (com.codename1.ui.Command)24 ActionEvent (com.codename1.ui.events.ActionEvent)22 Form (com.codename1.ui.Form)20 Hashtable (java.util.Hashtable)13 UIManager (com.codename1.ui.plaf.UIManager)11 Container (com.codename1.ui.Container)10 ActionListener (com.codename1.ui.events.ActionListener)10 GridLayout (com.codename1.ui.layouts.GridLayout)9 Button (com.codename1.ui.Button)8 Style (com.codename1.ui.plaf.Style)8 IOException (java.io.IOException)7 Vector (java.util.Vector)7 Component (com.codename1.ui.Component)6 Dialog (com.codename1.ui.Dialog)6 BoxLayout (com.codename1.ui.layouts.BoxLayout)6 ArrayList (java.util.ArrayList)6 RadioButton (com.codename1.ui.RadioButton)5 LayeredLayout (com.codename1.ui.layouts.LayeredLayout)5 CheckBox (com.codename1.ui.CheckBox)4