example.photoalbum
Class PhotoAlbum

java.lang.Object
  extended by javax.microedition.midlet.MIDlet
      extended by example.photoalbum.PhotoAlbum
All Implemented Interfaces:
java.lang.Runnable, javax.microedition.lcdui.CommandListener, javax.microedition.lcdui.ItemStateListener

public class PhotoAlbum
extends javax.microedition.midlet.MIDlet
implements javax.microedition.lcdui.CommandListener, javax.microedition.lcdui.ItemStateListener, java.lang.Runnable

The PhotoAlbum MIDlet provides the commands and screens that implement a simple photograph and animation album. The images and animations to be displayed are configured in the descriptor file with attributes.

Options are provided to to vary the speed of display and the frame style.


Constructor Summary
PhotoAlbum()
          Construct a new PhotoAlbum MIDlet and initialize the base options and main PhotoFrame to be used when the MIDlet is started.
 
Method Summary
(package private)  void closeOptions()
          Close the options store.
 void commandAction(javax.microedition.lcdui.Command c, javax.microedition.lcdui.Displayable s)
          Respond to commands.
protected  void destroyApp(boolean unconditional)
          Destroy must cleanup everything not handled by the garbage collector.
 void itemStateChanged(javax.microedition.lcdui.Item item)
          Listener for changes to options.
(package private)  void openOptions()
          Open the store that holds the saved options.
protected  void pauseApp()
          Pause is used to release the memory used by Image.
(package private)  void restoreOptions()
          Restore the options from persistent storage.
 void run()
          The Run method is used to load the images.
(package private)  void saveOptions()
          Save the options to persistent storage.
protected  void startApp()
          Start up the Hello MIDlet by setting the PhotoFrame and loading the initial images.
 
Methods inherited from class javax.microedition.midlet.MIDlet
checkPermission, getAppProperty, notifyDestroyed, notifyPaused, platformRequest, resumeRequest
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PhotoAlbum

public PhotoAlbum()
Construct a new PhotoAlbum MIDlet and initialize the base options and main PhotoFrame to be used when the MIDlet is started.

Method Detail

startApp

protected void startApp()
Start up the Hello MIDlet by setting the PhotoFrame and loading the initial images.

Specified by:
startApp in class javax.microedition.midlet.MIDlet

pauseApp

protected void pauseApp()
Pause is used to release the memory used by Image. When restarted the images will be re-created. Save the options for the next restart.

Specified by:
pauseApp in class javax.microedition.midlet.MIDlet

destroyApp

protected void destroyApp(boolean unconditional)
Destroy must cleanup everything not handled by the garbage collector. In this case there is nothing to cleanup. Save the options for the next restart.

Specified by:
destroyApp in class javax.microedition.midlet.MIDlet
Parameters:
unconditional - true if this MIDlet should always cleanup

commandAction

public void commandAction(javax.microedition.lcdui.Command c,
                          javax.microedition.lcdui.Displayable s)
Respond to commands. Commands are added to each screen as they are created. Each screen uses the PhotoAlbum MIDlet as the CommandListener. All commands are handled here:

Specified by:
commandAction in interface javax.microedition.lcdui.CommandListener
Parameters:
c - the command that triggered this callback
s - the screen that contained the command

itemStateChanged

public void itemStateChanged(javax.microedition.lcdui.Item item)
Listener for changes to options. The new values are set in the PhotoFrame.

Specified by:
itemStateChanged in interface javax.microedition.lcdui.ItemStateListener
Parameters:
item - - the item whose value has changed.

run

public void run()
The Run method is used to load the images. A form is used to report the progress of loading images and when the loading is complete they are displayed. Any errors that occur are reported using an Alert. Images previously loaded into the PhotoFrame are discarded before loading.

Load images from resource files using Image.createImage. Images may be in resource files or accessed using http: The first image is loaded to determine whether it is a single image or a sequence of images and to make sure it exists. If the name given is the complete name of the image then it is a singleton. Otherwise it is assumed to be a sequence of images with the name as a prefix. Sequence numbers (n) are 0, 1, 2, 3, .... The full resource name is the concatenation of name + n + ".png".

If an OutOfMemoryError occurs the sequence of images is truncated and an alert is used to inform the user. The images loaded are displayed. see createImage

Specified by:
run in interface java.lang.Runnable

openOptions

void openOptions()
Open the store that holds the saved options. If an error occurs, put up an Alert.


saveOptions

void saveOptions()
Save the options to persistent storage. The options are retrieved ChoiceGroups and stored in Record 1 of the store which is reserved for it. The two options are stored in bytes 0 and 1 of the record.


restoreOptions

void restoreOptions()
Restore the options from persistent storage. The options are read from record 1 and set in the frame and if the optionsForm has been created in the respective ChoiceGroups.


closeOptions

void closeOptions()
Close the options store.