Nokia Asha App Development - Part 2


Published on

Nokia Developer Training for development on Asha Devices with JavaME language

  • Be the first to comment

Nokia Asha App Development - Part 2

  1. 1. App Development forNokia Asha Deviceswith Java ME Marlon Luz - INdT Nokia Developer Evangelist @marlonluz
  2. 2. High-Level UI API• GUI Components to create user interfaces• Portable among MIDP compatible Displayable devices • Same look and feel Screen Canvas • Small control on the look and feel Alert Form List TextBox GameCanvas• All components are Displayables and they are subclasses of the Screen class• Your app can create new instances of the components or extend them
  3. 3. Showing components and adding itensto the components • Get the Display of the mobile and put your component in the display Display display = Display.getDisplay(midlet); Form form = new Form(“MyForm”); display.setCurrent(form); • Create a List component and add items in the List List list = new List(“My List”, Choice.IMPLCIT); list.append(“first”, null); list.append(“second”, null); list.append(“third”, null); display.setCurrent(list);
  4. 4. Simple Screens • Screens to user interact Alert List Textbox
  5. 5. Alert• Notifications• Dialog box of modal type• Normally used to show error messages Alert alert = new Alert(“Alert”); alert.setType(AlertType.ERROR); alert.setString(“SOME ERROR”); display.setCurrent(alert);• Tip: Error description and any message must be clear enough
  6. 6. List• Mostrar escolhas ao usuário List list = new List(“Menu”, Choice.IMPLICIT); list.append(“New Game”, null); list.append(“High Scores”, null); list.append(“Help”, null); list.append(“About”, null); List.append(“Exit”, null); display.setCurrent(list);
  7. 7. TextBox• Entrada de Dados pelo usuário TextBox textBox = new TextBox(“Type a message”,””,100,TextField.ANY); display.setCurrent(textBox);
  8. 8. Form• Container for form items• Kind of items: • TextField • StringItem • DateField • ImageItem • Gauge • CustomItem • ChoiceGroup
  9. 9. Managing items in the form • Adding items Form form = new Form(“form”); StringItem item = new StringItem(“text”,”text”); form.append(item); • Removing items form.delete(0); // deletes the first item form.deleteAll(); // deletes all items
  10. 10. Form items - TextField• Use TextFields to the user input data TextField textField = new TextField(“TextField Label”, ”some text”,20,TextField.ANY); form.append(textField);• Input types: TextField.ANY - any char allowed TextField.EMAILADDR – email address chars allowed TextField.NUMERIC – integer number allowed TextField.PHONENUMBER – phone number chars allowed TextField.URL – URL chars allowed TextField.DECIMAL – decimal numbers allowed
  11. 11. Form items - TextField• Other types: TextField.PASSWORD TextField.UNEDITABLE TextField.SENSITIVE TextField.NON_PREDICTIVE TextField.INITAL_CAPS_WORD TextField.CAPS_SENTENCE• You can use the setConstraints() method to set the type after the item creation
  12. 12. Form items - StringItem• Shows a static textString str = "The game Shooter version 0.1 "+ "was developed by Marlon Luz. For supporting "+ "please send email for";StringItem stringItem = new StringItem("About",str);form.append(stringItem);
  13. 13. Form items - DateField• Use DateField to show dates or to the user input dates DateField dateField = new DateField(“Birth Date”, DateField.DATE); java.util.Date date = new java.util.Date(); dateField.setDate(date); form.append(dateField);
  14. 14. Form Items - Gauge• Useful to show progress screens Gauge gauge = new Gauge(“Volume”,true,100,70); form.append(gauge); Gauge gauge = new Gauge(“Volume”, false, 100,70); form.append(gauge);
  15. 15. Form Items - ImageItem• It shows a image in a FormImage image = Image.createImage("/foto.png");ImageItem imageItem = new ImageItem("Picture", image, ImageItem.LAYOUT_CENTER, "");form.append(imageItem);
  16. 16. Form Items - ChoiceGroup• It shows options to chooseChoiceGroup cgSex = new ChoiceGroup("Sex", Choice.EXCLUSIVE);cgSex.append("Male", null);cgSex.append("Female", null);form.append(cgSex);ChoiceGroup cgSkills = new ChoiceGroup("Skills", Choice.MULTIPLE);cgSkills.append("Java", null);cgSkills.append("C++", null);cgSkills.append("C#", null);form.append(cgSkills);
  17. 17. Form Items - Spacer• Space between items Spacer space = new Spacer(10,20); form.append(space);
  18. 18. Form Items - Tickers• Ticker is like CNN news or the marquee HTML tag Ticker ticker = new Ticker(“The ticker sample”); form.setTicker(ticker);
  19. 19. Commands• Commands can be applied in all Displayable components Command cmdExit = new Command("Exit", Command.EXIT, 1); Command cmdOk = new Command(“OK", Command.OK, 1); Command cmdList1 = new Command("List1", Command.ITEM, 1); Command cmdList2 = new Command("List2", Command.ITEM, 2); form.addCommand(cmdExit); form.addCommand(cmdOk); form.addCommand(cmdList1); form.addCommand(cmdList2);
  20. 20. Commands• You have to define a class to implement the CommandListener interface public class SampleApp extends MIDlet implements CommandListener{• You have to set the listener in the displayable component form.setCommandListener(this);
  21. 21. Commands • The commandAction() method must be implemented to handle the commands public void commandAction(Command c, Displayable d) { if (c == cmdExit) { notifyDestroyed(); } }
  22. 22. Obrigado! Marlon Luz @marlonluz