当前位置: 首页>>代码示例>>Java>>正文


Java Form.getCommand方法代码示例

本文整理汇总了Java中com.codename1.ui.Form.getCommand方法的典型用法代码示例。如果您正苦于以下问题:Java Form.getCommand方法的具体用法?Java Form.getCommand怎么用?Java Form.getCommand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.codename1.ui.Form的用法示例。


在下文中一共展示了Form.getCommand方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: reloadForm

import com.codename1.ui.Form; //导入方法依赖的package包/类
/**
 * Useful tool to refresh the current state of a form shown using show form
 * without pushing another instance to the back stack
 */
public void reloadForm() {
    Form currentForm = Display.getInstance().getCurrent();
    Command backCommand = currentForm.getBackCommand(); 
    Form newForm = (Form)createContainer(fetchResourceFile(), currentForm.getName());

    if (backCommand != null) {
        setBackCommand(newForm, backCommand);

        // trigger listener creation if this is the only command in the form
        getFormListenerInstance(newForm, null);
        
        for(int iter = 0 ; iter < currentForm.getCommandCount() ; iter++) {
            if(backCommand == currentForm.getCommand(iter)) {
                newForm.addCommand(backCommand, newForm.getCommandCount());
                break;
            }
        }
    }
    
    beforeShow(newForm);
    Transition tin = newForm.getTransitionInAnimator();
    Transition tout = newForm.getTransitionOutAnimator();
    currentForm.setTransitionInAnimator(CommonTransitions.createEmpty());
    currentForm.setTransitionOutAnimator(CommonTransitions.createEmpty());
    newForm.setTransitionInAnimator(CommonTransitions.createEmpty());
    newForm.setTransitionOutAnimator(CommonTransitions.createEmpty());
    newForm.layoutContainer();
    newForm.show();
    postShowImpl(newForm);
    newForm.setTransitionInAnimator(tin);
    newForm.setTransitionOutAnimator(tout);
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:37,代码来源:UIBuilder.java

示例2: clickMenuItem

import com.codename1.ui.Form; //导入方法依赖的package包/类
/**
 * Executes a menu command with the given name
 * @param name the name of the command
 */
public static void clickMenuItem(String name) {
    if(verbose) {
        log("clickMenuItem(" + name + ")");
    }
    Form f = Display.getInstance().getCurrent();
    for(int iter = 0 ; iter < f.getCommandCount() ; iter++) {
        Command c = f.getCommand(iter);
        if(name.equals(c.getCommandName())) {
            f.dispatchCommand(c, new ActionEvent(c,ActionEvent.Type.Command));
            return;
        }
    }
    throw new RuntimeException("Command not found: " + name);
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:19,代码来源:TestUtils.java

示例3: onPrepareOptionsMenu

import com.codename1.ui.Form; //导入方法依赖的package包/类
@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();
                    // From https://developer.android.com/guide/topics/resources/menu-resource.html
                    // "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")) {
                        item.setShowAsAction(8); //MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW
                    }
                }
            }
        }
    } catch (Throwable t) {
    }

    return nativeMenu;
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:60,代码来源:CodenameOneActivity.java

示例4: onOptionsItemSelected

import com.codename1.ui.Form; //导入方法依赖的package包/类
@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;
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:47,代码来源:CodenameOneActivity.java


注:本文中的com.codename1.ui.Form.getCommand方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。