1 package ubc.midp.mobilephoto.core.ui;
2
3 import javax.microedition.midlet.MIDlet;
4 import javax.microedition.midlet.MIDletStateChangeException;
5
6 import ubc.midp.mobilephoto.core.ui.controller.AlbumController;
7 import ubc.midp.mobilephoto.core.ui.controller.BaseController;
8 import ubc.midp.mobilephoto.core.ui.controller.PhotoListController;
9 import ubc.midp.mobilephoto.core.ui.datamodel.AlbumData;
10 import ubc.midp.mobilephoto.core.ui.screens.AlbumListScreen;
11
12 //#ifdef includeSmsFeature
13 import ubc.midp.mobilephoto.sms.SmsReceiverController;
14 import ubc.midp.mobilephoto.sms.SmsReceiverThread;
15 //#endif
16
17 //Following are pre-processor statements to include the required
18 //classes for device specific features. They must be commented out
19 //if they aren't used, otherwise it will throw exceptions trying to
20 //load classes that aren't available for a given platform.
21
22
23 /*
24 * @author trevor
25 *
26 * This is the main Midlet class for the core J2ME application
27 * It contains all the basic functionality that should be executable
28 * in any standard J2ME device that supports MIDP 1.0 or higher.
29 * Any additional J2ME features for this application that are dependent
30 * upon a particular device (ie. optional or proprietary library) are
31 * de-coupled from the core application so they can be conditionally included
32 * depending on the target platform
33 *
34 * This Application provides a basic Photo Album interface that allows a user to view
35 * images on their mobile device.
36 * */
37 public class MainUIMidlet extends MIDlet {
38
39 //(m v C) Controller
40 private BaseController rootController;
41
42 //Model (M v c)
43 private AlbumData model;
44
45 /**
46 * Constructor -
47 */
48 public MainUIMidlet() {
49 //do nothing
50 }
51
52 /**
53 * Start the MIDlet by creating new model and controller classes, and
54 * initialize them as necessary
55 */
56 public void startApp() throws MIDletStateChangeException {
57 model = new AlbumData();
58 AlbumListScreen album = new AlbumListScreen();
59 rootController = new BaseController(this, model, album);
60
61 // [EF] initialize sub-controllers
62 PhotoListController photoListController = new PhotoListController(this, model, album);
63 photoListController.setNextController(rootController);
64
65 AlbumController albumController = new AlbumController(this, model, album);
66 albumController.setNextController(photoListController);
67 album.setCommandListener(albumController);
68
69
70
71 //#ifdef includeSmsFeature
72 SmsReceiverController controller = new SmsReceiverController(this, model, album);
73 controller.setNextController(albumController);
74 SmsReceiverThread smsR = new SmsReceiverThread(this, model, album, controller);
75 System.out.println("SmsController::Starting SMSReceiver Thread");
76 new Thread(smsR).start();
77 //#endif
78
79
80 //Only the first (last?) controller needs to be initialized (?)
81 rootController.init(model);
82 }
83
84 /**
85 * Pause the MIDlet
86 * This method does nothing at the moment.
87 */
88 public void pauseApp() {
89 //do nothing
90 }
91
92 /**
93 * Destroy the MIDlet
94 */
95 public void destroyApp(boolean unconditional) {
96 notifyDestroyed();
97 }
98 }
|