• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Intro to MIDP Development
 

Intro to MIDP Development

on

  • 2,003 views

 

Statistics

Views

Total Views
2,003
Views on SlideShare
1,870
Embed Views
133

Actions

Likes
1
Downloads
49
Comments
0

1 Embed 133

http://php.tpu.fi 133

Accessibility

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Intro to MIDP Development Intro to MIDP Development Presentation Transcript

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