Nokia Asha App Development - Part 2

Embed Size (px)

DESCRIPTION

Nokia Developer Training for development on Asha Devices with JavaME language

Citation preview

  • 1.App Development forNokia Asha Deviceswith Java ME Marlon Luz - INdT Nokia Developer Evangelist @marlonluz

2. High-Level UI API GUI Components to create userinterfaces Portable among MIDP compatible Displayabledevices Same look and feel ScreenCanvas Small control on the look and feel Alert Form List TextBox GameCanvas All components areDisplayables and they aresubclasses of the Screen class Your app can create newinstances of the components orextend them 3. Showing components and adding itensto the components Get the Display of the mobile and put your component inthe displayDisplay display = Display.getDisplay(midlet);Form form = new Form(MyForm);display.setCurrent(form); Create a List component and add items in the ListList list = new List(My List, Choice.IMPLCIT);list.append(first, null);list.append(second, null);list.append(third, null);display.setCurrent(list); 4. Simple Screens Screens to user interactAlertList Textbox 5. Alert Notifications Dialog box of modal type Normally used to show error messagesAlert alert = new Alert(Alert);alert.setType(AlertType.ERROR);alert.setString(SOME ERROR);display.setCurrent(alert); Tip: Error description and any messagemust be clear enough 6. List Mostrar escolhas ao usurioList 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. TextBox Entrada de Dados pelo usurioTextBox textBox = newTextBox(Type a message,,100,TextField.ANY);display.setCurrent(textBox); 8. Form Container for form items Kind of items: TextField StringItem DateField ImageItem Gauge CustomItem ChoiceGroup 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. 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. 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 toset the type after the item creation 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 [email protected]";StringItem stringItem = new StringItem("About",str);form.append(stringItem); 13. Form items - DateField Use DateField to show dates or to theuser input datesDateField dateField = new DateField(Birth Date, DateField.DATE);java.util.Date date = new java.util.Date();dateField.setDate(date);form.append(dateField); 14. Form Items - Gauge Useful to show progress screensGauge gauge = new Gauge(Volume,true,100,70);form.append(gauge);Gauge gauge = new Gauge(Volume, false, 100,70);form.append(gauge); 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. 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. Form Items - Spacer Space between itemsSpacer space = new Spacer(10,20);form.append(space); 18. Form Items - Tickers Ticker is like CNN news or the marquee HTML tagTicker ticker = new Ticker(The ticker sample);form.setTicker(ticker); 19. Commands Commands can be applied in all DisplayablecomponentsCommand 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. Commands You have to define a class to implement theCommandListener interfacepublic class SampleApp extends MIDlet implements CommandListener{ You have to set the listener in the displayable componentform.setCommandListener(this); 21. Commands The commandAction() method must be implemented to handle the commands public void commandAction(Command c, Displayable d) { if (c == cmdExit) { notifyDestroyed(); } } 22. Obrigado! Marlon Luz [email protected] @marlonluz