Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Session 3 J2ME Mobile Information Device Profile(MIDP) API


Published on

Session 3 Presentation in J2ME

Published in: Technology
  • Dating direct: ❤❤❤ ❤❤❤
    Are you sure you want to  Yes  No
    Your message goes here
  • Sex in your area is here: ❶❶❶ ❶❶❶
    Are you sure you want to  Yes  No
    Your message goes here
  • Be the first to like this

Session 3 J2ME Mobile Information Device Profile(MIDP) API

  1. 1. Session :3 (30-Mar-09) - outline <ul><li>>> MIDP Introduction </li></ul><ul><li>- Hardware and Software Requirements </li></ul><ul><li>- MID Profile Architecture </li></ul><ul><li>- MIDlet Suite </li></ul><ul><li>>> Basics of MIDlet </li></ul><ul><li>- MIDlet </li></ul><ul><li>-MIDlet StateChangeException </li></ul><ul><li>-Display </li></ul><ul><li>-Displayable </li></ul>
  2. 2. H/W and S/W Requirement <ul><li>>> H/W Requirement </li></ul><ul><li>-Screen size 96*54 pixels </li></ul><ul><li>-At least one type of user input(keyboard, touch screen) </li></ul><ul><li>-128 KB non-volatile memory for MID component. </li></ul><ul><li>-8KB non-volatile memory for storing persistence data. </li></ul><ul><li>-32 KB of volatile memory to running java. </li></ul><ul><li>-Wireless N/W connectivity </li></ul>
  3. 3. H/W an S/W Requirement <ul><li>>> S/W Requirement(OS S/W) </li></ul><ul><li>- Minimal scheduling, Exception handling and processing of interrupts software. </li></ul><ul><li>- support for displaying bitmapped graphics </li></ul><ul><li>- Must accept I/P and pass to JVM </li></ul><ul><li>- Data Persistence S/W. </li></ul><ul><li>- Software must be capability to read and write to/from non volatile memory. </li></ul><ul><li>- There must be access to the networking on the device. </li></ul>
  4. 4. MID Profile Architecture
  5. 5. MID Profile Architecture <ul><li>MID- To visually portrait the architecture of the application begin with the Hardware </li></ul><ul><li>Native OS – One step up running on the H/W is the Native OS. </li></ul><ul><li>Native apps - first reference to an application running on an MID. </li></ul><ul><li>- example are configuring application (i.e. Date,Time, Ring setting) </li></ul><ul><li>- Before J2ME only one type of apps will run in mobile that’s are native app. </li></ul>
  6. 6. MID Profile Architecture (Cont.,) <ul><li>CLDC installed on the native operating system and is the foundation for the for MIDP. </li></ul><ul><li>MIDP applications have access to both the libraries of CLDC and MIDP. </li></ul><ul><li>OEM-specific (original equipment manufacturer) classes are provided by the manufactory of the company </li></ul>
  7. 7. MIDlet Suite <ul><li>MIDlet is a java application designed to be run on a mobile device. </li></ul><ul><li>It has as its core java classes the CLDC and MIDP. </li></ul><ul><li>MIDlet suite consist of one or more MIDlet packaged together usings a JAR file. </li></ul>
  8. 8. MIDlet suite(Cont.,) <ul><li>>> Runtime environment and application manager </li></ul><ul><li>-- Application manager is the software on a mobile device that is responsible for installing, running and removing MIDlet suite. </li></ul><ul><li>-- Application manager is a device – dependent software(ie., designed and implemented by Manufacture of device). </li></ul><ul><li>When application manager start the MIDlet , It will make all the following available to the application: </li></ul><ul><li>-- Access to the CLDC and JVM </li></ul><ul><li>-- Access to the MIDP-define classes : user interfaces , persistence storage ,networking support using HTTP,timer and managing user interaction with the device. </li></ul><ul><li>-- Access to JAR file </li></ul><ul><li>-- Access to JAD (Java Application Descriptor) file </li></ul>
  9. 9. MIDlet Suite(Cont.,) <ul><li>>>Java Archive File (JAR) </li></ul><ul><li>-- Bundle all the information(Class file , images and application information) related to project into single entity known as a JAR file. </li></ul><ul><li>-- In addition to classes and resource file , a JAR contains a file known as a manifest. </li></ul><ul><li>-- manifest describe the content of the JAR file. </li></ul><ul><li>-- manifest file has the name and is stored as the part of JAR file itself. </li></ul>
  10. 10. MIDlet Suite(Cont.,) <ul><li>>> JAR Manifest Attributes </li></ul><ul><li>-- Manifest has totally nine attribute , no need to define all attribute. </li></ul><ul><li>--If the following six attribute are inside the manifest , the application manager will refuse to load the JAR: </li></ul><ul><ul><ul><li>MIDlet-Name </li></ul></ul></ul><ul><ul><ul><li>MIDlet-Version </li></ul></ul></ul><ul><ul><ul><li>MIDlet-Vendor </li></ul></ul></ul><ul><ul><ul><li>MIDlet-<n>(one entry for each MIDlet in the JAR file) </li></ul></ul></ul><ul><ul><ul><li>MicroEdition-Profile </li></ul></ul></ul><ul><ul><ul><li>MicroEdition-Configuration </li></ul></ul></ul>
  11. 11. MIDlet Suite(Cont.,) <ul><li>>> JAR –MIDlet Attribute </li></ul>
  12. 12. MIDlet suite(Cont.,) <ul><li>>> Sample manifest entry </li></ul><ul><ul><ul><li>MIDlet-Name: Todo List </li></ul></ul></ul><ul><ul><ul><li>MIDlet-Version: 1.0 </li></ul></ul></ul><ul><ul><ul><li>MIDlet-Vendor: Core J2ME </li></ul></ul></ul><ul><ul><ul><li>MIDlet-1: TodoList, /images/Todo.png, Todo.TodoMIDlet </li></ul></ul></ul><ul><ul><ul><li>MicroEdition-Profile: MIDP-1.0 </li></ul></ul></ul><ul><ul><ul><li>MicroEdition-Configuration: CLDC-1.0 </li></ul></ul></ul>
  13. 13. MIDlet Suite (Cont.,) <ul><li>>>> JAD(Java Application Descriptor) </li></ul><ul><li>>> JAD file may be available as part of the MIDlet suite to provide information about the MIDlet(s) within the JAR. </li></ul><ul><li>>> The rational behind including a JAD file is as follow. </li></ul><ul><li>1. To provide information to the application manager about the contents of a JAR. With this information, decisions can be made as to whether or not a MIDlet(s) is suitable for running on the device. </li></ul><ul><li>2. Provide a means for parameters to be passed to a MIDlets(s) without having to make changes to the JAR file. </li></ul>
  14. 14. MIDlet Suite(Cont.,) <ul><li>>> JAD Attribute </li></ul><ul><li>-- JAD have set pre-define attribute </li></ul><ul><li>-- You can also define your own attributes as you see necessary for your application. </li></ul><ul><li>-- Simply create names that do not start with &quot;MIDlet-&quot; and you are good to go </li></ul><ul><li>-- As with the manifest file, there is a required set of attributes that must be defined in the JAD file: </li></ul><ul><ul><li>MIDlet-Name </li></ul></ul><ul><ul><li>MIDlet-Version </li></ul></ul><ul><ul><li>MIDlet-Vendor </li></ul></ul><ul><ul><li>MIDlet-<n> for each MIDlet </li></ul></ul><ul><ul><li>MIDlet-Jar-URL </li></ul></ul>
  15. 15. MIDlet Suite(Cont.,)
  16. 16. MIDlet Suite(Cont.,) <ul><li>>> Simple JAD file </li></ul><ul><ul><li>MIDlet-Name: Todo List </li></ul></ul><ul><ul><li>MIDlet-Version: 1.0 </li></ul></ul><ul><ul><li>MIDlet-Vendor: Core J2ME </li></ul></ul><ul><ul><li>MIDlet-Jar-URL: </li></ul></ul><ul><ul><li>MIDlet-Jar-Size: 17043 </li></ul></ul><ul><ul><li>MIDlet-1: TodoList, /images/Todo.png, Todo.TodoMIDlet </li></ul></ul>
  17. 17. MIDlet <ul><li>MIDlet is the application that is build-upon the MIDlet Class. </li></ul><ul><li>The application manager communicates with a MIDlet through methods in this class. </li></ul><ul><li>This communication is a two-way street. </li></ul><ul><li>As an example, just as the application manager can pause a MIDlet (e.g., to allow a user to answer an incoming phone call), a MIDlet can make a request to be paused (and later restarted). </li></ul>
  18. 18. MIDlet LifeCycle <ul><li>MIDP applications are known as “MIDlets” </li></ul><ul><li>MIDlets move from state to state in the lifecycle, as indicated. </li></ul><ul><ul><li>Start – acquire resources and start executing </li></ul></ul><ul><ul><li>Pause – release resources and become quiescent (wait) </li></ul></ul><ul><ul><li>Destroy – release all resources, destroy threads, and end all activity </li></ul></ul>Pause Active Destroyed startApp destroyApp pauseApp destroyApp
  19. 19. MIDlet API Method Description Communication from application manager to MIDlet abstract void destroyApp (boolean unconditional) MIDlet is about to be shut down abstract void pauseApp() MIDlet is about to be placed into paused state abstract void startApp() MIDlet has been placed into active state Communication from MIDlet to application manager final void notifyDestroyed() MIDlet is requesting to be shut down final void notifyPaused() MIDlet is requesting to be paused final void resumeRequest() MIDlet is requesting to become active (after being paused) Attribute request from MIDlet to application manager final String getAppProperty (String key) Get attributes from JAR and/or JAD files
  20. 20. MIDlet StateChangeException <ul><li>During the course of a MIDlet's lifecycle, if an error occurs when changing states, this exception is thrown. </li></ul><ul><li>Two methods(startApp(), destoryApp()) in MIDlet class are throw this Exception </li></ul>
  21. 21. MIDlet StateChangeException API <ul><li>There are two constructors for creating this exception, one with and without a text message. </li></ul><ul><li>Eg. TestException </li></ul>Constructer Description MIDletStateChangeException() Create exception object with no text MIDletStateChangeException(String s) Create exception object with text
  22. 22. Display <ul><li>Each MIDlet has a reference to one Display object </li></ul><ul><li>Retrieve information about the current display (e.g., the range of colors supported) and includes methods for requesting that objects (Forms, TextBoxes, etc.) be displayed. </li></ul><ul><li>display controlling what is shown on the device and when </li></ul><ul><li>Note </li></ul><ul><li>- only one display object per MIDlet </li></ul>
  23. 23. Creating a Display object <ul><li>A Display object is made available to a MIDlet through a call to a static method declared inside the Display class. </li></ul><ul><li>Structure </li></ul><ul><li>public class DisplayStats extends MIDlet </li></ul><ul><li>{ </li></ul><ul><li>private Display display; // Reference to Display object </li></ul><ul><li>// MIDlet constructor </li></ul><ul><li>public DisplayStats() </li></ul><ul><li>{ </li></ul><ul><li>display = Display.getDisplay(this); </li></ul><ul><li>... </li></ul><ul><li>} </li></ul><ul><li>... </li></ul><ul><li>} </li></ul>
  24. 24. Display API <ul><li>Display Class: javax.microedition.lcdui.Display </li></ul>Method Description static Display getDisplay(MIDlet m) Get Display object for this MIDlet Displayable getCurrent() Displayable getCurrent() Get current Displayable object void setCurrent(Alert alert, Displayable nextDisplayable) Show an Alert followed by the specified Displayable object void setCurrent(Displayable nextDisplayable) Show a new Displayable object boolean isColor() Does the device support color? int numColors() How many colors (or shades of gray) are available? void callSerially(Runnable r) Request a runnable object be called after repainting
  25. 25. Displayable <ul><li>Display can show any number of Displayable objects. </li></ul><ul><li>a Displayable object can be viewed on a device </li></ul><ul><li>The MIDP includes two subclasses of Displayable: Screen and Canvas. </li></ul><ul><li>Screen object(Textbox, List, Form and Alert) are all high-level user interface components, as their implementation and presentation on the device are handled for you. </li></ul><ul><li>The Canvas object is used for custom graphics and low-level event handling , such as when writing games, and requires a little more finesse on your part to update the display. </li></ul>
  26. 26. Creating Displayable Object <ul><li>We don't create Displayable objects directly; instead, we reference subclasses of Displayable </li></ul><ul><li>Screen and Canvas extend the Displayable class </li></ul><ul><li>Using API </li></ul>Method Description void addCommand(Command cmd) Add Command to Displayable object void removeCommand(Command cmd) Remove Command from Displayable object void setCommandListener(CommandListener l) Add CommandListener to Displayable object boolean isShown() Is the Displayable object visible on the screen?
  27. 27. Event Handling <ul><li>Event Handling in Mobile device </li></ul><ul><li>Command Object </li></ul><ul><li>Item Object </li></ul><ul><li>Command and Command Listener </li></ul><ul><li>Item and Item Listener </li></ul>
  28. 28. Event Handling in Mobile Device <ul><li>event handling is nothing more than recognizing when an event occurs and taking an action based on that event. </li></ul><ul><li>there are three key steps to successfully managing an event. </li></ul><ul><li>- The hardware (the physical device itself) must recognize that something has occurred. </li></ul><ul><li>- The software on the device (the application manager) needs to be notified of the event </li></ul><ul><li>- A message from theapplication manager will be sent to the MIDlet. This message will contain information about the event so we can make decisions as to how to proceed </li></ul>
  29. 29. Command Object <ul><li>A Command is an object that holds information about an event. </li></ul><ul><li>The simplest way to think of a Command is as a &quot;button,&quot; something that you press or select </li></ul><ul><li>Processing events requires a little legwork up front. Here are the steps: </li></ul><ul><li>1. Create a Command object to hold information about an event. </li></ul><ul><li>2. Add the Command to a Form, Textbox, List or Canvas. </li></ul><ul><li>3. Add a &quot;listener&quot; to the above Form, Textbox, and so forth. </li></ul>
  30. 30. Command Object Creation <ul><li>private Form fmMain; // A Form </li></ul><ul><li>private Command cmExit; // A Command to exit the MIDlet </li></ul><ul><li>... </li></ul><ul><li>fmMain = new Form(&quot;Core J2ME&quot;); // Form object </li></ul><ul><li>cmExit = new Command(&quot;Exit&quot;, Command.EXIT, 1); // Command object </li></ul><ul><li>... </li></ul><ul><li>fmMain.addCommand(cmExit); // Add Command to Form </li></ul><ul><li>fmMain.setCommandListener(this); // Listen for Form events </li></ul><ul><li>... </li></ul><ul><li>public void commandAction(Command c, Displayable s) </li></ul><ul><li>{ </li></ul><ul><li>if (c == cmExit) </li></ul><ul><li>{ </li></ul><ul><li>destroyApp(true); </li></ul><ul><li>notifyDestroyed(); </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>
  31. 31. ItemObject <ul><li>An Item is any component that can be added to a Form. ChoiceGroup, DateField, Gauge and TextField are all subclasses of Item and each can process events. </li></ul><ul><li>Items are accessible only as part of a Form, whereas Commands areavailable on Forms, as well as a Textbox, List, or Canvas. </li></ul><ul><li>Once you add an Item to a Form, as with Commands, you must add a listener </li></ul><ul><li>Once there is a change to an Item (e.g., a Gauge has been incremented or a DateField has been changed), the listener object will be notified (sent a message). </li></ul>
  32. 32. Item Listener object creation <ul><li>private Form fmMain; // A Form </li></ul><ul><li>private DateField dfToday; // A DateField </li></ul><ul><li>... </li></ul><ul><li>fmMain = new Form(&quot;Core J2ME&quot;); // Form object </li></ul><ul><li>dfToday = new DateField(&quot;Today:&quot;, DateField.DATE); // DateField </li></ul><ul><li>... </li></ul><ul><li>fmMain.append(dfToday); // Add DateField to Form </li></ul><ul><li>fmMain.setItemStateListener(this); // Listen for events </li></ul><ul><li>... </li></ul><ul><li>public void itemStateChanged(Item item) </li></ul><ul><li>{ </li></ul><ul><li>// If the datefield initiated this event… </li></ul><ul><li>if (item == dfToday) </li></ul><ul><li>... </li></ul><ul><li>} </li></ul>