use of com.codename1.ui.Command in project CodenameOne by codenameone.
the class SMSShare method share.
/**
* {@inheritDoc}
*/
public void share(final String toShare) {
final Form currentForm = Display.getInstance().getCurrent();
final Form contactsForm = new Form("Contacts");
contactsForm.setScrollable(false);
contactsForm.setLayout(new BorderLayout());
contactsForm.addComponent(BorderLayout.CENTER, new Label("Please wait..."));
contactsForm.show();
Display.getInstance().startThread(new Runnable() {
public void run() {
String[] ids = ContactsManager.getAllContacts();
if (ids == null || ids.length == 0) {
Display.getInstance().callSerially(new Runnable() {
public void run() {
Dialog.show("Failed to Share", "No Contacts Found", "Ok", null);
currentForm.showBack();
}
});
return;
}
ContactsModel model = new ContactsModel(ids);
final List contacts = new List(model);
contacts.setRenderer(createListRenderer());
Display.getInstance().callSerially(new Runnable() {
public void run() {
contacts.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
final ShareForm[] f = new ShareForm[1];
final Hashtable contact = (Hashtable) contacts.getSelectedItem();
f[0] = new ShareForm(contactsForm, "Send SMS", (String) contact.get("phone"), toShare, new ActionListener() {
public void actionPerformed(ActionEvent evt) {
try {
Display.getInstance().sendSMS(f[0].getTo(), f[0].getMessage());
} catch (IOException ex) {
Log.e(ex);
System.out.println("failed to send sms to " + (String) contact.get("phone"));
}
finish();
}
});
f[0].show();
}
});
contactsForm.addComponent(BorderLayout.CENTER, contacts);
Command back = new Command("Back") {
public void actionPerformed(ActionEvent evt) {
currentForm.showBack();
}
};
contactsForm.addCommand(back);
contactsForm.setBackCommand(back);
contactsForm.revalidate();
}
});
}
}, "SMS Thread").start();
}
use of com.codename1.ui.Command in project CodenameOne by codenameone.
the class TestUtils method getToolbarCommands.
/**
* Returns all the command objects from the toolbar in the order of left, right, overflow & sidemenu
* @return the set of commands
*/
public static Command[] getToolbarCommands() {
Form f = Display.getInstance().getCurrent();
Toolbar tb = f.getToolbar();
ArrayList<Command> result = new ArrayList<Command>();
addAllCommands(tb.getLeftBarCommands(), result);
addAllCommands(tb.getRightBarCommands(), result);
addAllCommands(tb.getOverflowCommands(), result);
addAllCommands(tb.getSideMenuCommands(), result);
Command[] carr = new Command[result.size()];
result.toArray(carr);
return carr;
}
use of com.codename1.ui.Command in project CodenameOne by codenameone.
the class TestUtils method goBack.
/**
* 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);
}
use of com.codename1.ui.Command in project CodenameOne by codenameone.
the class LazyValueC method createForm.
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;
}
use of com.codename1.ui.Command in project CodenameOne by codenameone.
the class LazyValueC method showForm.
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);
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);
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);
f.show();
postShowImpl(f);
}
}
}
Aggregations