Intro to MIDP Development


Published on

Published in: Technology, Art & Photos
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Intro to MIDP Development

  1. 1. MIDP Development Jussi Pohjolainen TAMK University of Applied Sciences
  2. 2. Class Diagram of MIDP app + int checkPermission(String) # abstract void destroyApp(boolean) + String getAppProperty(String) + void notifyDestroyed() # abstract pauseApp() + boolean platformRequest(String) + void resumeRequest() # abstract void startApp(); abstract class MIDlet abstract class MyMIDlet
  3. 3. Code <ul><li>import javax.microedition.midlet.MIDlet; </li></ul><ul><li>import javax.microedition.lcdui.*; </li></ul><ul><li>public class MyMIDlet extends MIDlet { </li></ul><ul><li>public MyMIDlet() {} </li></ul><ul><li>public void startApp() {} </li></ul><ul><li>public void destroyApp(boolean unconditional) {} </li></ul><ul><li>public void pauseApp() {} </li></ul><ul><li>} </li></ul>
  4. 4. MIDlet’s Life Cycle Paused Active Destroyed Constructor startApp() pauseApp() destroyApp()
  5. 5. Application Manager <ul><li>Application Manager controls all the methods in the previous slide </li></ul><ul><li>You can try to change the state by using methods like: </li></ul><ul><ul><li>void notifyDestroyed() </li></ul></ul><ul><ul><li>notifyPaused() </li></ul></ul><ul><ul><li>resumeRequest() </li></ul></ul>
  6. 6. Intro to MIDP GUI
  7. 7. Intro to GUI <ul><li>Problem: Mobile Devices are totally different from each other </li></ul><ul><ul><li>Screen size, Resolution? </li></ul></ul><ul><ul><li>Color Depth? </li></ul></ul><ul><ul><li>Input Devices? </li></ul></ul><ul><li>Two solutions </li></ul><ul><ul><li>Abstraction: Let MIDP take care of the practical implementation </li></ul></ul><ul><ul><li>Discover: Sniff the features of the current phone and act according to them </li></ul></ul>
  8. 8. Abstraction vs. Discover <ul><li>Abstraction: Use high-level API </li></ul><ul><ul><li>Portability key issue </li></ul></ul><ul><ul><li>Very easy to use </li></ul></ul><ul><ul><li>Little control over look and feel </li></ul></ul><ul><li>Discover: Use low-level API </li></ul><ul><ul><li>Full control over graphics </li></ul></ul><ul><ul><li>Classes like Canvas, Graphics, Image, Font </li></ul></ul><ul><ul><li>Time consuming, but you can control the look and feel </li></ul></ul>
  9. 9. Display <ul><li>MIDP GUI could be seen as a deck of cards </li></ul><ul><li>No multiple windows </li></ul><ul><li>Display is a class that represents the screen display </li></ul><ul><li>Display has a single GUI-element whose content is controlled by one app at any time </li></ul><ul><li>The main task of the Display-class is to take care of what is visible at the screen </li></ul>
  10. 10. Using Display – class in Code <ul><li>import javax.microedition.midlet.*; </li></ul><ul><li>import javax.microedition.lcdui.*; </li></ul><ul><li>public class MyMIDlet extends MIDlet </li></ul><ul><li>{ </li></ul><ul><li>public MyMIDlet() {} </li></ul><ul><li>public void pauseApp() {} </li></ul><ul><li>public void destroyApp(boolean ignore) {} </li></ul><ul><li>public void startApp() </li></ul><ul><li>{ </li></ul><ul><li>Display d = Display.getDisplay(this); </li></ul><ul><li>d.setCurrent(…); </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>
  11. 11. Using Display <ul><li>You ask reference to the client device's display: </li></ul><ul><ul><li>public void startApp(){ </li></ul></ul><ul><ul><li>Display d = Display.getDisplay(this) </li></ul></ul><ul><ul><li>} </li></ul></ul><ul><li>Specification says that this is done in startApp -method </li></ul><ul><li>After getting the reference, you can use Display-classes methods: </li></ul><ul><ul><li>public void setCurrent(Displayable next) </li></ul></ul><ul><ul><li>public void setCurrent(Alert alert, Displayable nestDisplayable) </li></ul></ul>
  12. 12. Display’s methods <ul><li>boolean flashBacklight(int d) </li></ul><ul><li>boolean isColor() </li></ul><ul><li>int numColors() </li></ul><ul><li>boolean vibrate(int duration) </li></ul>
  13. 13. Displayable <ul><li>Display is responsible for changing GUI – elements on the screen </li></ul><ul><li>These GUI-elements are Displayable – objects. </li></ul><ul><li>Displayable is a abstract class that has couple concrete classes </li></ul>
  14. 14. Class Hierarchy
  15. 15. Examples of Displayable objects
  16. 16. Delegation Event Handling
  17. 17. Delegation Event Handling <ul><li>MIDlet's event handling system is the same as in Java SE </li></ul><ul><li>Delegation Event Model: </li></ul><ul><ul><li>Simple and easy to learn </li></ul></ul><ul><ul><li>Support a clean separation between application and GUI code </li></ul></ul><ul><ul><li>Facilitate the creation of robust event handling code which is less error-prone (strong compile-time checking) </li></ul></ul><ul><ul><li>Flexible enough to enable varied application models for event flow and propagation </li></ul></ul><ul><ul><li>For visual tool builders, enable run-time discovery of both events that a component generates as well as the events it may observe </li></ul></ul><ul><ul><li>Support backward binary compatibility with the old model </li></ul></ul>
  18. 18. Separation of GUI and BL Source Listener Registration
  19. 19. Delegation Event Model and MIDlets <ul><li>In MIDP, event source is usually Displayable-object </li></ul><ul><li>Registration is done with </li></ul><ul><ul><li>setCommandListener(CommandListener l) </li></ul></ul><ul><li>Listener can be any object, which class has implemented the CommandListener interface </li></ul>
  20. 20. Example <ul><li>Event source </li></ul><ul><ul><li>TextBox textbox = new TextBox(....); </li></ul></ul><ul><li>Event Listener </li></ul><ul><ul><li>Cat listener = new Cat(); </li></ul></ul><ul><li>Registration </li></ul><ul><ul><li>textbox.setCommandListener(listener); </li></ul></ul><ul><li>The Cat-class must implement the CommandListener-class. </li></ul><ul><li>It is wise to add some commands to the Textbox-screen: </li></ul><ul><ul><li>Command exitcommand = new Command(..); </li></ul></ul><ul><ul><li>textbox.addCommand(exitcommand); </li></ul></ul>
  21. 21. Listener <ul><li>Listener can be any class that implements the given interface. </li></ul><ul><li>In this case, Listener is a class called “Cat” </li></ul><ul><ul><li>class Cat implements CommandListener{ </li></ul></ul><ul><ul><li>public void commandAction(Command c, </li></ul></ul><ul><ul><li>Displayable d){ </li></ul></ul><ul><ul><li>// This will be called </li></ul></ul><ul><ul><li>} </li></ul></ul><ul><ul><li>} </li></ul></ul>
  22. 22. BL and GUI in the same class <ul><li>In small programs it is usual that the GUI - and the application code is implemented in the same class. </li></ul><ul><li>No the listener is the same class: </li></ul><ul><ul><li>class OmaMIDlet extends MIDlet implements CommandListener </li></ul></ul><ul><li>And registration: </li></ul><ul><ul><li>textbox.setCommandListener(this); </li></ul></ul>