html5-img
1 / 17

Programming of Handheld and Mobile Devices

Programming of Handheld and Mobile Devices. Lecture 7 J2ME Rob Pooley rjp@macs.hw.ac.uk. Java 2 Platform, Micro Edition (J2ME).

helen
Télécharger la présentation

Programming of Handheld and Mobile Devices

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Programming of Handheld and Mobile Devices Lecture 7 J2ME Rob Pooley rjp@macs.hw.ac.uk Programming Handheld and Mobile devices

  2. Java 2 Platform, Micro Edition (J2ME) • The Java 2 Platform, Micro Edition (J2ME) provides a flexible environment for applications running on consumer devices, such as mobile phones, PDAs, and TV set-top boxes, as well as a broad range of embedded devices. • J2ME includes Java virtual machines and a set of standard Java APIs • It includes flexible user interfaces, a robust security model, a broad range of built-in network protocols, and extensive support for networked and offline applications Programming Handheld and Mobile devices

  3. The J2ME Architecture • The J2ME architecture comprises a variety of configurations, profiles, and optional packages that implementers and developers can choose from Programming Handheld and Mobile devices

  4. Configurations • Configurations comprise a virtual machine and a minimal set of class libraries. • They provide the base functionality for a particular range of devices that share similar characteristics, such as network connectivity and memory footprint. • Currently, there are two J2ME configurations: • the Connected Limited Device Configuration (CLDC) and • the Connected Device Configuration (CDC). Programming Handheld and Mobile devices

  5. Profiles • To provide a complete runtime environment for a specific device category a configuration must be combined with a profile • This is a set of higher-level APIs that further define the application life-cycle model, the user interface, and access to device-specific properties. • A profile supports a narrower category of devices within the framework of a chosen configuration. • A widely adopted example is to combine CLDC with the Mobile Information Device Profile (MIDP) to provide a complete Java application environment for cell phones and other devices with similar capabilities Programming Handheld and Mobile devices

  6. Optional Packages • The J2ME platform can be extended by adding various optional packages to a technology stack that includes either CLDC or CDC and an associated profile. • Optional packages offer standard APIs for using both existing and emerging technologies such as database connectivity, wireless messaging, multimedia, Bluetooth, and web services. • Because optional packages are modular, developers can avoid carrying the overhead of unnecessary functionality by including only the packages an application actually needs. Programming Handheld and Mobile devices

  7. Programming Handheld and Mobile devices

  8. AppHandleEvent() static Boolean AppHandleEvent(EventType* pEvent) { uint16_t formId; FormType* pForm; if (pEvent->eType == frmLoadEvent) { // Load the form resource. formId = pEvent->data.frmLoad.formID; // OS6NEW: FrmInitForm() needs app db ptr as first argument pForm = FrmInitForm(gAppDB, formId); FrmSetActiveForm(pForm); // Set the event handler for the form. The handler of the currently active form is called by FrmHandleEvent each time // is receives an event. switch (formId) { case MainForm: FrmSetEventHandler(pForm, MainFormHandleEvent); FrmInitLayout(pForm, gMainFormLayout); break; case Form2Form: FrmSetEventHandler(pForm, Form2FormHandleEvent); FrmInitLayout(pForm, gForm2FormLayout); break; default: ErrFatalDisplay("Invalid Form Load Event"); break; } return true; } return false; } Programming Handheld and Mobile devices

  9. ## -------------------------------------- # Palm OS Generic Protein Makefile for # Eclipse v1.0.0 # # Fill in this file to specify your # project and the source that you want # to build, and the settings involved in # the build. The makefile-engine.mk # will then do the hard work of the # makefile and dependency handling. # # After starting a new project, please # remember the following steps... # 1. Add all sources and resources in # SOURCES and RESOURCES # 2. Review the other settings as needed. # SHELL = /bin/sh ## conditionally include an # auto-generated.mk for dynamic definitions -include auto-generated.mk ## -------------------------------------- # Set up the artifact name. # The database name and other file names are # based on the application name ## -------------------------------------- ARTIFACT_NAME = BasicApp EMPTY = SPACE =$(EMPTY) $(EMPTY) ESCAPED_ARTIFACT_NAME = $(subst $(SPACE),\ ,$(ARTIFACT_NAME)) PROJECT_NAME = BasicApp PRC_NAME = BasicApp.prc The makefile Programming Handheld and Mobile devices

  10. # Sources and Resources and Definition files # List all the sources (.c/.cpp), resources # (.xrd), and definition file (.sld) # in your project. Use project relative path # names with forward slashes # (src/code.cpp). Please do not use spaces in # directory or file names. # # A note about XRD resource files: If you have # existing .rsrc or .rcp files, # refer to the documentation for the GenerateXRD # tool to convert them into # XRD files for use with all Palm OS SDKs. ## ------------------------------------- # TODO: Update all sources and resources SOURCES = Src/AppMain.c RESOURCES = Rsc/BasicApp.xrd Rsc/Version.xrd DEFS_FILE = Src/BasicApp.def SLD_FILE = Src/BasicApp.sld ## -------------------------------------- # Review Database information # Register Creator ID at: http://dev.palmos.com/creatorid/ ## ----------------------------------- CREATOR_ID = bapp DB_TYPE = appl DATABASE_RESET = DATABASE_BACKUP = -b DATABASE_HIDDEN = DATABASE_PROTECT = DATABASE_VERSION = 1 LOCALE = enUS DATABASE_NAME = $(APP_NAME) The makefile 2 Programming Handheld and Mobile devices

  11. # Choose SDK # Supported values: # sdk-6 ## ------------------------------------------ SDK_VERSION = sdk-6 ifeq ($(SDK_LOCATION),) SDK_LOCATION=../../ endif ## ------------------------------------------ # Build Settings # Review the following for your needs. # The default settings build with debug information # and no optimization and # a target platform of an actual device. ## ----------------------------------------- # # Set Debug or Release configuration for this project # via the project properties # (right-click on the project and select Properties). # DEBUG_OR_RELEASE=Debug # # Set the target platform for the build; # either Device or Simulator # Use Device as a target for emulator builds. # TARGET_PLATFORM=Simulator # Specify the level of optimization that you want: # NONE, SOME, FULL, INTRAPROCEDURAL, INTERPROCEDURAL, INLINING. # Leave blank to select FULL for release builds, and NONE # for debug builds. # INTRAPROCEDURAL, INTERPROCEDURAL, INLINING are applicable # to device builds only; simulator builds will translate # those levels to FULL. OPTIMIZE_LEVEL = NONE # Specify warning level # NONE = suppress all warnings # ALL = enable all warnings # <undefined> = default warnings WARNING_LEVEL = # Specify exception handling support # true = enable it # false = don't enable it ENABLE_EXCEPTION_HANDLING=true # List additional libraries to link with # (Full or project relative path) ADDITIONAL_LINK_LIBRARIES = ADDITIONAL_SIM_LINK_LIBRARIES = The makefile 3 Programming Handheld and Mobile devices

  12. # Additional paths to look for #include "header" # (Source file directories are automatically included) # Please note that both local and system include paths # should either use "cygwin" syntax or if in Windows # syntax they should # be quoted. ie: ../MyLibrary/headers # or "C:\Source\MyLibrary\headers" # Additionally, you must explicly specify the "-I" # prior to each path included in this variable. Spaces # are used to separate each path from each other. LOCAL_INCLUDE_PATHS = -Irsc LOCAL_SIM_INCLUDE_PATHS = -Irsc # Additional paths to look for #include <header> # (Palm OS SDK directories are automatically included) # Additionally, you must explicly specify the "-I" # prior to each path included in this variable. Spaces # are used to separate each path from each other. SYSTEM_INCLUDE_PATHS = SYSTEM_SIM_INCLUDE_PATHS = # Specify any needed preprocessor symbols. # If you set DEFINES to "ASSERTLEVEL=1", the # compiler will see "-DASSERTLEVEL=1" # (separate individual entries with spaces) DEFINES = SIM_DEFINES = # Specify additional compiler flags for all files ADDITIONAL_COMPILER_FLAGS = ADDITIONAL_SIM_COMPILER_FLAGS = # Specify additional linker flags ADDITIONAL_LINKER_FLAGS = ADDITIONAL_SIM_LINKER_FLAGS = # Specify additional archival flags (for static # libraries) ADDITIONAL_AR_FLAGS = ADDITIONAL_SIM_AR_FLAGS = # Tools Directory # Normally you wouldn't want to override this # since the necessary tools # are in the PATH. But if you experimenting with # other tools, then reset the directory here # If overridden, end with a trailing '/' ifeq ($(TOOLS_DIR), ) TOOLS_DIR = ../../../PalmOSTools/ endif The makefile 4 Programming Handheld and Mobile devices

  13. ## --------------------------------------------- # Resource Settings ## ------------------------------------------- # Specify the target text encoding # LATIN, JAPANESE, SIMPLIFIED_CHINESE TEXTENCODING = LATIN # Specify error levels for locale and text encoding # NOCHECK # STRICT # <default> LOCALE_CHECKING = # Specific if encoding should be checked # FALSE, TRUE STRICT_ENCODING = FALSE ## ----------------------------------------------- # Output Settings ## ---------------------------------------------- # Modify if you want object and output files to be in # different locations # (However, please note that all three object # directories must be different # for the makefile engine to properly operate.) # OUTPUT_DIR is the "main" output directory, where # all linked and binary objects # will be put. DEBUG_DEVICE_OUTPUT_DIR := DebugDevice RELEASE_DEVICE_OUTPUT_DIR := ReleaseDevice DEBUG_SIMULATOR_OUTPUT_DIR := DebugSim RELEASE_SIMULATOR_OUTPUT_DIR := ReleaseSim RSC_OBJ_DIR := ResourceObjs ## ----------------------------------------------- # Makefiles ## ----------------------------------------------- ## include the makefile engine include makefile-engine.mk ## conditionally include your own custom.mk for ## your specific overrides or definitions ## this is useful if you don't want to use the ## auto-generated.mk values ## for some reason -include custom.mk The makefile 5 Programming Handheld and Mobile devices

  14. Another simple example UInt32 PilotMain(UInt16 launchCode, MemPtr launchParameters, UInt16 launchFlags) { #pragma unused(launchParameters) Err error; switch (launchCode) { case sysAppLaunchCmdNormalLaunch: error = RomVersionCompatible (kOurMinVersion, launchFlags); if (error) return error; error = AppStart(); if (error) return error; FrmGotoForm(MainForm); AppEventLoop(); AppStop(); break; default: break; } return errNone; } Programming Handheld and Mobile devices

  15. Second AppStart() and AppStop() static Err AppStart(void) { return errNone; } static void AppStop(void) { FrmCloseAllForms(); } Programming Handheld and Mobile devices

  16. The event loop static void AppEventLoop(void) { Err error; EventType event; do { EvtGetEvent(&event, evtWaitForever); if (! SysHandleEvent(&event)) if (! MenuHandleEvent(0, &event, &error)) if (! AppHandleEvent(&event)) FrmDispatchEvent(&event); } while (event.eType != appStopEvent); } Programming Handheld and Mobile devices

  17. Application events static Boolean AppHandleEvent(EventPtr event) { UInt16 formId; FormPtr form; if (event->eType == frmLoadEvent) { // Load the form resource. formId = event->data.frmLoad.formID; form = FrmInitForm(formId); ErrFatalDisplayIf(!form, "Can't initialize form"); FrmSetActiveForm(form); // Set the event handler for the form. The handler of the currently // active form is called by FrmHandleEvent each time it receives an // event. switch (formId) { case MainForm: FrmSetEventHandler(form, MainFormHandleEvent); break; case SecondForm: FrmSetEventHandler(form, SecondFormHandleEvent); break; default: ErrFatalDisplay("Invalid Form Load Event"); break; } return true; } else return false; } Programming Handheld and Mobile devices

More Related