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));
}
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;
}
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;
}
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);
}
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();
}
Aggregations