Mobile Application Development. MIDP & GUI Programmierung



Similar documents
Mobile application development J2ME U N I T I I

Introduction to Mobile Phone. Programming in Java Me

APPLICATION PROGRAMMING - MOBILE COMPUTING Mobile Computing

Development of Java ME

Tutorial: Development of Interactive Applications for Mobile Devices

Mobile Software Application Development. Tutorial. Caesar Ogole. April 2006

MIDlet development with J2ME and MIDP

The Software Engineering of Mobile Application Development

Mobile Information Device Profile - Java Programs in the Phone

Mobile App Design and Development

core. Volume I - Fundamentals Seventh Edition Sun Microsystems Press A Prentice Hall Title ULB Darmstadt

5. More on app development

1 Mobile and Ubiquitous User Interfaces

Fundamentals of Java Programming

CaptainCasa. CaptainCasa Enterprise Client. CaptainCasa Enterprise Client. Feature Overview

GUIs with Swing. Principles of Software Construction: Objects, Design, and Concurrency. Jonathan Aldrich and Charlie Garrod Fall 2012

Mobility Introduction Android. Duration 16 Working days Start Date 1 st Oct 2013

TUTORIAL 4 Building a Navigation Bar with Fireworks

Specialized Android APP Development Program with Java (SAADPJ) Duration 2 months

Bangla Text Input and Rendering Support for Short Message Service on Mobile Devices

private byte[] encryptcommand = {(byte)0xa0, (byte)0xc1, (byte)0x00, (byte)0x00, (byte) 0x00};

::. Contenuti della lezione *+ ') $ &,!!!$!-,.../- ' % + &

Java is commonly used for deploying applications across a network. Compiled Java code

Java Platform, Micro Edition (Java ME) Mokoena F.R. The 7046 Team

ios 9 Accessibility Switch Control - The Missing User Guide Updated 09/15/15

The Basic Java Applet and JApplet

einstruction CPS (Clicker) Instructions

INTRODUCTION TO COMPUTER CONCEPTS CSIT 100 LAB: MICROSOFT POWERPOINT

DESIGNING SHIFT CALENDAR FOR MOBILE PHONE

Swing. A Quick Tutorial on Programming Swing Applications

Automated Integration Tests for Mobile Applications in Java 2 Micro Edition

INSTALL NOTES Elements Environments Windows 95 Users

CORSAIR GAMING KEYBOARD SOFTWARE USER MANUAL

Game Center Programming Guide

Hildon User Interface Style Guide Summary

Eclipse 4 RCP application Development COURSE OUTLINE

Mass Announcement Service Operation

Implementação. Interfaces Pessoa Máquina 2010/ Salvador Abreu baseado em material Alan Dix. Thursday, June 2, 2011

Tutorial Reference Manual. Java WireFusion 4.1

Practice Fusion API Client Installation Guide for Windows

Field Manager Mobile Worker User Guide for RIM BlackBerry 1

Microsoft Migrating to Word 2010 from Word 2003

Computing Concepts with Java Essentials

Using WebEx Player. Playing a recording. Installing WebEx Player. System requirements for listening to audio in a recording

Interacting with Users

5. Tutorial. Starting FlashCut CNC

Introduction To Microsoft Office PowerPoint Bob Booth July 2008 AP-PPT5

DVR GUIDE. Using your DVR/Multi-Room DVR WAVE-123 wavebroadband.com

ANDROID PROGRAMMING - INTRODUCTION. Roberto Beraldi

DATASTREAM CHARTING ADVANCED FEATURES

Migrating to Excel 2010 from Excel Excel - Microsoft Office 1 of 1

Generating Automated Test Scripts for AltioLive using QF Test

Microsoft PowerPoint 2010

5.17 GUI. Xiaoyi Jiang Informatik I Grundlagen der Programmierung

BCA 421- Java. Tilak Maharashtra University. Bachelor of Computer Applications (BCA) 1. The Genesis of Java

This guide describes features that are common to most models. Some features may not be available on your tablet.

Kaldeera Workflow Designer 2010 User's Guide

How to Develop Accessible Linux Applications

How to create and personalize a PDF portfolio

Using WINK to create custom animated tutorials

Event processing in Java: what happens when you click?

About the HealthStream Learning Center

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

Mobile Application Development

Introduction to Word 2007

Windows XP Pro: Basics 1

Inteset Secure Lockdown ver. 2.0

USER MANUAL (PRO-CURO LITE, PRO & ENT) [SUPPLIED FOR VERSION 3]

Microsoft PowerPoint 2011

EMC Documentum Webtop

WHAT S NEW IN WORD 2010 & HOW TO CUSTOMIZE IT

Beginning BlackBerry 7

COMMANDtrack. Service Bulletin 2.7 Release Date: September 13, New Functionality. Application CR Description

Access Tutorial 13: Event-Driven Programming Using Macros

SCORPION. micron security products

Admin. Mobile Software Development Framework: Android Activity, View/ViewGroup, External Resources. Recap: TinyOS. Recap: J2ME Framework

My home Mobile phone application

Microsoft Migrating to PowerPoint 2010 from PowerPoint 2003

To begin, visit this URL:

CSC 551: Web Programming. Spring 2004

Using the Content Distribution Manager GUI

PLAY VIDEO. Close- Closes the file you are working on and takes you back to MicroStation V8i Open File dialog.

Polycom SoundPoint IP 650

A Short Introduction to Android

Android Development Exercises Version Hands On Exercises for. Android Development. v

Nero MediaStreaming for MCE Manual

Movie Maker 2 Beginning

GUI Event-Driven Programming

Microsoft Excel 2010 Part 3: Advanced Excel

HP Mobile Remote Control (Select Models Only) User Guide

Citrix GoToAssist Corporate Representative User Guide

There are several ways of creating a PDF file using PDFCreator.

IBM Tivoli Software. Document Version 8. Maximo Asset Management Version 7.5 Releases. QBR (Ad Hoc) Reporting and Report Object Structures

KEYBOARD SHORTCUTS. Note: Keyboard shortcuts may be different for the same icon depending upon the SAP screen you are in.

Developing In Eclipse, with ADT

Automated Dispatch System Query Tool


Transcription:

J2ME MIDlets Mobile Application Development MIDP & GUI Programmierung Christoph Denzler Fachhochschule Nordwestschweiz Institut für Mobile und Verteilte Systeme Lernziele Sie wissen wie ein MIDlet kontrolliert wird. kennen die GUI Komponenten des lcdui Packages können ein GUI konzipieren und planen können eine MVC Architektur entwerfen und implementieren. haben Erfahrungen gesammelt bei der Programmierung von einfachen GUIs mit MIDP. 2 1

Heute Was ist ein MIDlet? Entwurf des GUIs der Fallstudie GUI Komponenten in MIDP Entwurf einer MVC Architektur für die Fallstudie 3 Heute Was ist ein MIDlet? Überblick Applikationsmodell HelloWorld Beispiel Entwurf des GUIs der Fallstudie GUI Komponenten in MIDP Entwurf einer MVC Architektur für die Fallstudie 4 2

What is a MIDlet MIDP applications are called MIDlets The class javax.microedition.midlet.midlet allows the platform to control a MIDP application. MIDP does not support the running of traditional applications that use a static main method as their entry point. Its entry point is a class that extends the javax.microedition.midlet.midlet class. MIDP defines an application lifecycle model similar to the applet model. 5 What is a MIDlet Suite One or more MIDlets are packaged together into what is referred to as a MIDlet suite. A MIDlet suite is basically a standard JAR (Java archive) file and Class files Resource files (e.g. icons, image files, string resources) A manifest describing the JAR contents a separate file called an application descriptor (JAD). Midlets in a suite share Runtime object heap Persistent storage 6 3

Heute Was ist ein MIDlet? Überblick Applikationsmodell HelloWorld Beispiel Entwurf des GUIs der Fallstudie GUI Komponenten in MIDP Entwurf einer MVC Architektur für die Fallstudie 7 Application Management Software The Application Management Software (AMS) manages the MIDlets. The AMS is a part of the device's operating environment and guides the MIDlets through their various states during the execution process. 8 4

MIDP State Management The MIDlet Life Cycle new Midlet() startapp Paused destroyapp pauseapp Active destroyapp Destroyed 9 MIDP State Management State transitions initiated by application management software protected void startapp() Midlet is (re)-started May be called several times use flag to decide whether first call or not Midlet initialization is usually done in the constructor protected void pauseapp() Midlet should release as many resources as possible Midlet can still receive asynchronous events (e.g. timer) protected void destroyapp(boolean unconditional) Normal way to terminate a midlet. If unconditional == false the midlet may throw a MIDletStateChangeException to signal that it would like to stay alive Midlet should release its resources and save any persistent data 10 5

MIDP State Management State transitions initiated by MIDlet notifydestroyed() Informs manager that midlet released its resources and saved data. destroyapp() will NOT be called Rule: call destroyapp() to perform cleanup before notifydestroyed(). notifypaused() Informs manager that midlet entered the paused state. pauseapp() will NOT be called In the future, startapp() or destroyapp() will be called. resumerequest() Request to become active again (e.g. after a timer event) 11 The MIDlet Class abstract class MIDlet { // called by the platform abstract void startapp(); abstract void pauseapp(); abstract void destroyapp(); } // can be called by the subclass void notifypaused(); void notifydestroyed(); // plus various property accessors 12 6

Heute Was ist ein MIDlet? Überblick Applikationsmodell HelloWorld Beispiel Entwurf des GUIs der Fallstudie GUI Komponenten in MIDP Entwurf einer MVC Architektur für die Fallstudie 13 Simple HelloWorld Midlet package hello; import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class HelloWorld extends MIDlet implements CommandListener { private Command cmdexit; // the exit command private TextBox tb; public HelloWorld() { cmdexit = new Command("Exit", Command.SCREEN, 2); tb = new TextBox("Hello MIDlet", "Hello World", 256, TextField.ANY); tb.addcommand(cmdexit); tb.setcommandlistener(this); } 14 7

Simple HelloWorld Midlet (cont.) } public void startapp() { Display.getDisplay(this).setCurrent(tb); } public void pauseapp() { } public void destroyapp(boolean unconditional) { cleanup(); } public void commandaction(command c, Displayable s) { if (c == cmdexit) { destroyapp(true); notifydestroyed(); } } 15 Heute Was ist ein MIDlet? Entwurf des GUIs der Fallstudie GUI Komponenten in MIDP Entwurf einer MVC Architektur für die Fallstudie 16 8

User Interface Design Use a Screen Map Split the application into views Make the application structure simple Define a main screen for the application Clarify the interactions between each view Consider the navigation throughout the application Ensure that the users can always return to where they started 17 User Interface Design (cont) Take different screen sizes into account Do not use hard coded UI coordinates UI size Get screen size Use getheight() and getwidth() methods of the Canvas class to get the size of the Canvas. Note Set canvas in full screen mode Use the setfullscreenmode(true) method Plan for localization 18 9

Key Handling Be Aware that keypad layouts vary a lot key mappings may differ from device to device Key Handling Design separate the control code from the application logic enables the changing of the control handlers without modifying the application use the key codes and game actions defined by the MIDP specification public void keypressed( int keycode ) { int gameaction = getgameaction( keycode ); switch( gameaction ) { case Canvas.DOWN: // move down break; case Canvas.LEFT: // move left break;.. } 19 Modular Architecture Separate View from Logic Apply MVC Pattern Separate application specifics from generic components e.g. by designing an abstract interface Separate device specific from application e.g. by designing an abstract interface Separate localization resources from code Save in external text files 20 10

Heute Was ist ein MIDlet? Entwurf des GUIs der Fallstudie GUI Komponenten in MIDP Übersicht High-Level GUI Komponenten List, Alert, TestBox Form & Items Low-Level GUI Komponenten Entwurf einer MVC Architektur für die Fallstudie 21 The MIDP User Interface Library Display Model Commands The High-Level API Screens Form, TextBox, List, Alert, Item The Low-Level API Canvas, Graphics, CustomItem Located in javax.microedition.lcdui 22 11

MIDP User Interface Requirements Not too many short-lived objects Usable without pointer device / touch screen Compatibility with native phone applications => neither AWT nor Swing (nor SWT) were an option! Display Types High-level API, only abstract description of UI Look-and-feel matches the device Forms, Menus, Commands, Lists, Alerts Low-level API ("Gaming") Canvas, native drawing primitives 23 MIDP UI Class Hierarchy Display 0..1 * Displayable * * * Command Ticker 0..1 0..1 CommandListener Screen Canvas List Alert TextBox Form 1 * Item CustomItem ChoiceGroup Gauge DateField TextField ImageItem StringItem 24 12

MIDP User Interface Screen Model Each MIDlet consists of several screens (Displayable) On the display one Screen is displayed at each point of time The application sets and resets the current screen Display Commands Abstract Commands Specified by a type and a priority Can be implemented as buttons, menus, Have to be added to each screen Are handled in a command listener (also associated with a screen) 0..1 Displayable * * * Command 0..1 CommandListener 25 Display Setting Displayable Objects Displayable getcurrent(); Returns the current displayable object void setcurrent(displayable d) makes next displayable object visible (may be delayed) void setcurrent(alert alert, Displayable next) shows the alert and after its dismiss the displayable d (may be delayed) void setcurrentitem(item item) makes form which contains item as next displayable Display Access static Display getdisplay(midlet m) 26 13

Display (cont.) setcurrent change will typically not take effect immediately Change of display occurs between event delivering calls (not guaranteed before next event) Consequences Call to getcurrent after a setcurrent is unlikely to return the set displayable, getcurrent returns the visible displayable Calls to setcurrent are not queued isshown on a Displayable may return false although it has been set with setcurrent If after a call to setcurrent the thread is busy in a blocking operation, then it may be that the UI is not actualized => Blocking Operations should be executed in a separate thread! A Canvas offers methods shownotify and hidenotify 27 Display (cont.) Screen Parameters boolean iscolor() int numcolors() Number of colors or graylevels int numalphalevels() Number of alpha levels (transparency of colors) int getcolor(int colorspecifier) Returns information about foreground/background colors int getbestimagewidth/height(int imagetype) Returns best image width&height for list/choice/alert images boolean vibrate(int millis) Returns whether vibrator can be controlled int getborderstyle(boolean highlighted) boolean flashbacklight(int duration) 28 14

Displayable Commands void addcommand(command cmd) void removecommand(command cmd) CommandListener void setcommandlistener(commandlistener l) replaces previous installed listeners the same listener may be installed in several displayable objects Visibility boolean isshown() Checks if the Displayable is actually visible on the display (e.g. MIDlet running, Displayable installed, no system screens) Title void settitle(string title) String gettitle() Ticker void setticker(ticker t) setticker(null) clears the ticker Ticker getticker Ticker ticker = new Ticker("Select an item"); disp.setticker(ticker); disp.addcommand(exitcommand); disp.addcommand(nextcommand); 29 Command Label String representation, may be ignored (except for SCREEN commands) Type SCREEN application defined command, pertained to current screen BACK previous screen, may be mapped on a back button OK confirm data and proceed CANCEL discarding of current screen Nothing is done automatically by these EXIT exit request commands!!! HELP on-line help request STOP stop a process visible on the current screen ITEM specific to a particular item on the screen Priority: >= 1; low = high priority 30 15

CommandListener Interface void commandaction(command c, Displayable d) Indicates that a command event has occurred on displayable d Command c may be one which has been added or an implicit List.SELECT_COMMAND of a list. Implementation Provided by the application, implemented e.g. as inner class Should return immediately (not necessarily called in a separate thread) otherwise, application could block 31 Heute Was ist ein MIDlet? Entwurf des GUIs der Fallstudie GUI Komponenten in MIDP Übersicht High-Level GUI Komponenten List, Alert, TestBox Form & Items Low-Level GUI Komponenten Entwurf einer MVC Architektur für die Fallstudie 32 16

High-Level LCDUI Ensure highest portability Provide a set of standard controls Make GUI development easy Offers high level widgets Standard controls like lists, textbox, etc. Look-And-Feel is determined by LCDUI implementation application automatically adapts to runtime environment i.e. application may look different on different devices Simple user interactions are taken care of by system E.g. scrolling in a large dialog No direct access to input devices data exchange through listeners Limited capabilities 33 MIDP UI High-Level API Screen List Alert TextBox Form 1 * Item ChoiceGroup Gauge DateField Spacer TextField ImageItem StringItem 34 17

Screen Screen Common abstract base class of all high-level user interface classes No further methods (since MIDP 2.0) 35 List Functionality list of choices (string [+ icon]), insert/append/delete scrolling handled by system (no events) selection using select / go button Types IMPLICIT menu list (=> List.SELECT_COMMAND) EXCLUSIVE radio buttons, getselectedindex() no events! MULTIPLE check boxes, isselected(int) new List("Title", List.IMPLICIT, new String[]{"one","two","three"}, null); 36 18

TextBox Functionality Screen to enter and edit text Application sets max chars and input constraints TextBox must have an associated command! Types ANY (0) EMAILADDR (1) NUMERIC (2) PHONENUMBER (3) URL (4) DECIMAL (5) Modifier PASSWORD UNEDITABLE SENSITIVE NON_PREDICTABLE INITIAL_CAPS_WORD INITIAL_CAPS_SENTENCE new TextBox("Enter ID", "", 10, TextField.NUMERIC); 37 Alert Functionality Message screen (optional with image), used for errors / exceptions Default Command: Alert.DISMISS_COMMAND (may be replaced) gettimeout() / settimeout(int) [Alert.FOREVER => modal] Types ERROR INFO WARNING ALARM (e.g. reminder, wakeup call) CONFIRMATION Alert a = new Alert("Oops"); a.setstring("something went wrong"); a.settype(alerttype.confirmation); a.settimeout(alert.forever); 38 19

Form Functionality Combination of different items (images, textfields, gauges, choice groups) Each item has a label (setlabel / getlabel) An item may be contained in at most one form Scrolling performed by device, no events Methods append(item item) / append(image image) / append(string str) set(int n, Item item) / insert(int n, Item item) size() / delete(int n) / get(int n) setitemstatelistener(itemstatelistener listener) void itemstatechanged(item item) Called, when an item changes (e.g. text input) 39 Items StringItem ImageItem different layouts: center, left, right, newline before, newline after TextField similar to text box; with max size & constraints DateField types date, time, date_time; setdate / getdate ChoiceGroup only exclusive and multiple Gauge graphical value display, may be editable Gauge(String label, boolean interactive, int max, int initial) Spacer CustomItem 40 20

Heute Was ist ein MIDlet? Entwurf des GUIs der Fallstudie GUI Komponenten in MIDP Übersicht High-Level GUI Komponenten List, Alert, TestBox Form & Items Low-Level GUI Komponenten Entwurf einer MVC Architektur für die Fallstudie 41 MIDP Low-Level Interface Low level abstraction Gives control about positioning of elements Exact pixel positioning Control over look-and-feel of UI elements Direct access to keyboard and input devices Capturing low-level keyboard events key pressed key released Access to device specific properties Display resolution Color depth Available keys May limit portability Typical application domain are games 42 21

MIDP Low-Level API Canvas Graphics Form 1 * Item CustomItem 43 Canvas Drawing full control, but code must adapt itself to available features (color, size,..) redrawing requested by system with paint(graphics g) redrawing can be requested by application with repaint Events Key Events keypressed, keyreleased, keyrepeated Pointer Events pointerpressed, pointerreleased, pointerdragged Visibility shownotify, hidenotify 44 22

Canvas Drawing full control, but code must adapt itself to available features (color, size,..) redrawing requested by system with paint(graphics g) redrawing can be requested by application with repaint Events Key Events keypressed, keyreleased, keyrepeated Pointer Events pointerpressed, pointerreleased, pointerdragged Visibility shownotify, hidenotify 45 Canvas (cont) Canvas Properties Screen getwidth, getheight, isdoublebuffered Events haspointerevents, haspointermotionevents, hasrepeatevents Key Codes Game Actions: UP, DOWN, LEFT, RIGHT, FIRE, GAME_A, GAME_B, GAME_C, GAME_D Key Codes: KEY_NUM0,, KEY_NUM9, KEY_POUND (#), KEY_STAR (*) Support getkeycode(action) <-> getgameaction(key) getkeyname(key) => "press F1 to continue" 46 23

Graphics Drawing drawline, drawrect, drawroundrect, drawarc, drawstring, drawimage fillrect, fillroundrect, fillarc Drawing State setcolor / setgrayscale setstrokestyle (SOLID / DOTTED) setfont Clipping setclip(x, y, w, h), getclipx / getclipy, getclipwidth, getclipheight 47 Graphics (cont) Image getwidth() / getheight() immutable: createimage(string resource) createimage(byte[] data, int offset, int len) createimage(image src) mutable createimage(int w, int h) => getgraphics() Font Font.getFont(face, style, size) FACE_MONOSPACE, FACE_PROPORTIONAL, FACE_SYSTEM SIZE_LARGE, SIZE_MEDIUM, SIZE_SMALL STYLE_BOLD, STYLE_ITALIC, STYLE_PLAIN, STYLE_UNDERLINED 48 24

CustomItem Purpose Allow user to develop her own item controls Although derived from Item this is a low-level class API very similar to Canvas class 49 Heute Was ist ein MIDlet? Entwurf des GUIs der Fallstudie GUI Komponenten in MIDP Entwurf einer MVC Architektur für die Fallstudie 50 25