Java Code Examples for com.codename1.ui.Command#putClientProperty()
The following examples show how to use
com.codename1.ui.Command#putClientProperty() .
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 File: UIBuilder.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
private void initBackForm(Form f) { Vector formNavigationStack = baseFormNavigationStack; if(formNavigationStack != null && formNavigationStack.size() > 0) { setFormState(f, (Hashtable)formNavigationStack.elementAt(formNavigationStack.size() - 1)); formNavigationStack.removeElementAt(formNavigationStack.size() - 1); if(formNavigationStack.size() > 0) { Hashtable previous = (Hashtable)formNavigationStack.elementAt(formNavigationStack.size() - 1); String commandAction = (String)previous.get(FORM_STATE_KEY_NAME); Command backCommand = createCommandImpl(getBackCommandText((String)previous.get(FORM_STATE_KEY_TITLE)), null, BACK_COMMAND_ID, commandAction, true, ""); setBackCommand(f, backCommand); // trigger listener creation if this is the only command in the form getFormListenerInstance(f, null); backCommand.putClientProperty(COMMAND_ARGUMENTS, ""); backCommand.putClientProperty(COMMAND_ACTION, commandAction); } } }
Example 2
Source File: UIBuilder.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
private Object[] readObjectArrayForListModel(DataInputStream in, Resources res) throws IOException { Object[] elements = new Object[in.readInt()]; int elen = elements.length; for(int iter = 0 ; iter < elen ; iter++) { switch(in.readByte()) { case 1: // String elements[iter] = in.readUTF(); break; case 2: // hashtable of Strings int hashSize = in.readInt(); Hashtable val = new Hashtable(); elements[iter] = val; for(int i = 0 ; i < hashSize ; i++) { int type = in.readInt(); if(type == 1) { // String String key = in.readUTF(); Object value = in.readUTF(); if(key.equals("$navigation")) { Command cmd = createCommandImpl((String)value, null, -1, (String)value, false, ""); cmd.putClientProperty(COMMAND_ACTION, (String)value); value = cmd; } val.put(key, value); } else { val.put(in.readUTF(), res.getImage(in.readUTF())); } } break; } } return elements; }
Example 3
Source File: UIBuilder.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
private void initBackContainer(Container cnt, Form destForm, Vector formNavigationStack) { setContainerState(cnt, (Hashtable)formNavigationStack.elementAt(formNavigationStack.size() - 1)); formNavigationStack.removeElementAt(formNavigationStack.size() - 1); if(formNavigationStack.size() > 0) { Hashtable previous = (Hashtable)formNavigationStack.elementAt(formNavigationStack.size() - 1); String commandAction = (String)previous.get(FORM_STATE_KEY_NAME); Command backCommand = createCommandImpl(getBackCommandText((String)previous.get(FORM_STATE_KEY_TITLE)), null, BACK_COMMAND_ID, commandAction, true, ""); setBackCommand(destForm, backCommand); backCommand.putClientProperty(COMMAND_ARGUMENTS, ""); backCommand.putClientProperty(COMMAND_ACTION, commandAction); } }
Example 4
Source File: CodenameOneActivity.java From CodenameOne with GNU General Public License v2.0 | 4 votes |
@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; }
Example 5
Source File: UIBuilder.java From CodenameOne with GNU General Public License v2.0 | 4 votes |
Form createForm(Form f) { Form currentForm = Display.getInstance().getCurrent(); if(currentForm != null && currentForm instanceof Dialog) { ((Dialog)Display.getInstance().getCurrent()).dispose(); currentForm = Display.getInstance().getCurrent(); } Vector formNavigationStack = baseFormNavigationStack; if(formNavigationStack != null && !(f instanceof Dialog) && !f.getName().equals(homeForm)) { if(currentForm != null) { String nextForm = (String)f.getClientProperty("%next_form%"); // we are in the sidemenu view we should really be using the parent form SideMenuBar b = (SideMenuBar)currentForm.getClientProperty("cn1$sideMenuParent"); if(b != null) { currentForm = b.getParentForm(); } // don't add back commands to transitional forms if(nextForm == null) { String commandAction = currentForm.getName(); if(allowBackTo(commandAction) && f.getBackCommand() == null) { Command backCommand; if(isSameBackDestination(currentForm, f)) { backCommand = currentForm.getBackCommand(); } else { backCommand = createCommandImpl(getBackCommandText(currentForm.getTitle()), null, BACK_COMMAND_ID, commandAction, true, ""); backCommand.putClientProperty(COMMAND_ARGUMENTS, ""); backCommand.putClientProperty(COMMAND_ACTION, commandAction); } if(backCommand != null) { setBackCommand(f, backCommand); } // trigger listener creation if this is the only command in the form getFormListenerInstance(f, null); formNavigationStack.addElement(getFormState(currentForm)); } } } } return f; }
Example 6
Source File: UIBuilder.java From CodenameOne with GNU General Public License v2.0 | 4 votes |
private void showForm(Form f, Command sourceCommand, Component sourceComponent) { Form currentForm = Display.getInstance().getCurrent(); if(currentForm != null && currentForm instanceof Dialog) { ((Dialog)Display.getInstance().getCurrent()).dispose(); currentForm = Display.getInstance().getCurrent(); } Vector formNavigationStack = baseFormNavigationStack; if(sourceCommand != null && currentForm != null && currentForm.getBackCommand() == sourceCommand) { if(currentForm != null) { exitForm(currentForm); } if(formNavigationStack != null && formNavigationStack.size() > 0) { String name = f.getName(); if(name != null && name.equals(homeForm)) { if(formNavigationStack.size() > 0) { setFormState(f, (Hashtable)formNavigationStack.elementAt(formNavigationStack.size() - 1)); } formNavigationStack.clear(); } else { initBackForm(f); } } onBackNavigation(); beforeShow(f, sourceCommand); f.showBack(); postShowImpl(f); } else { if(currentForm != null) { exitForm(currentForm); } if(formNavigationStack != null && !(f instanceof Dialog) && !f.getName().equals(homeForm)) { if(currentForm != null) { String nextForm = (String)f.getClientProperty("%next_form%"); // we are in the sidemenu view we should really be using the parent form SideMenuBar b = (SideMenuBar)currentForm.getClientProperty("cn1$sideMenuParent"); if(b != null) { currentForm = b.getParentForm(); } // don't add back commands to transitional forms if(nextForm == null) { String commandAction = currentForm.getName(); if(allowBackTo(commandAction) && f.getBackCommand() == null) { Command backCommand; if(isSameBackDestination(currentForm, f)) { backCommand = currentForm.getBackCommand(); } else { backCommand = createCommandImpl(getBackCommandText(currentForm.getTitle()), null, BACK_COMMAND_ID, commandAction, true, ""); backCommand.putClientProperty(COMMAND_ARGUMENTS, ""); backCommand.putClientProperty(COMMAND_ACTION, commandAction); } if(backCommand != null) { setBackCommand(f, backCommand); } // trigger listener creation if this is the only command in the form getFormListenerInstance(f, null); formNavigationStack.addElement(getFormState(currentForm)); } } } } if(f instanceof Dialog) { beforeShow(f, sourceCommand); if(sourceComponent != null) { // we are cheating with the post show here since we are using a modal // dialog to prevent the "double clicking button" problem by using // a modal dialog sourceComponent.setEnabled(false); postShowImpl(f); f.show(); sourceComponent.setEnabled(true); exitForm(f); } else { ((Dialog)f).showModeless(); postShowImpl(f); } } else { beforeShow(f, sourceCommand); f.show(); postShowImpl(f); } } }