1 /*
2 * Created on 12-Apr-2005
3 *
4 */
5 // #if includeSmsFeature
6
7 package ubc.midp.mobilephoto.sms;
8
9 import javax.microedition.lcdui.Alert;
10 import javax.microedition.lcdui.AlertType;
11 import javax.microedition.lcdui.Command;
12 import javax.microedition.lcdui.Display;
13
14 import lancs.midp.mobilephoto.lib.exceptions.ImageNotFoundException;
15 import lancs.midp.mobilephoto.lib.exceptions.NullAlbumDataReference;
16 import lancs.midp.mobilephoto.lib.exceptions.PersistenceMechanismException;
17 import ubc.midp.mobilephoto.core.ui.MainUIMidlet;
18 import ubc.midp.mobilephoto.core.ui.controller.AbstractController;
19 import ubc.midp.mobilephoto.core.ui.datamodel.AlbumData;
20 import ubc.midp.mobilephoto.core.ui.datamodel.ImageData;
21 import ubc.midp.mobilephoto.core.ui.screens.AlbumListScreen;
22
23 /**
24 * @author trevor
25 *
26 * This class extends the BaseController to provide functionality specific to
27 * the SMS (Short Message Service) photo messaging feature. It contains command
28 * handlers for this feature and methods that are only required by this feature.
29 * All non-SMS commands (ie. general ones) are passed on to the parent class (BaseController)
30 * for handling.
31 *
32 */
33 public class SmsSenderController extends AbstractController {
34
35 String selectedImageName = "null";
36 String imageName = "";
37 NetworkScreen networkScreen;
38
39 /**
40 * @param midlet
41 */
42
43
44 /**
45 * @param midlet
46 * @param nextController
47 * @param albumData
48 * @param albumListScreen
49 * @param currentScreenName
50 */
51 public SmsSenderController(MainUIMidlet midlet, AlbumData albumData, AlbumListScreen albumListScreen, String imageName) {
52 super(midlet, albumData, albumListScreen);
53 this.imageName = imageName;
54 }
55
56 /**
57 * Handle SMS specific events.
58 * If we are given a standard command that is handled by the BaseController, pass
59 * the handling off to our super class with the else clause
60 */
61
62 public boolean handleCommand(Command c) {
63
64
65 String label = c.getLabel();
66 System.out.println("SmsSenderController::handleCommand: " + label);
67
68 /** Case: ... **/
69 if (label.equals("Send Photo by SMS")) {
70
71 networkScreen = new NetworkScreen("Reciever Details");
72 selectedImageName = imageName;
73 networkScreen.setCommandListener(this);
74 this.setCurrentScreen(networkScreen);
75 return true;
76
77 } else if (label.equals("Send Now")) {
78
79 //Get the data from the currently selected image
80 ImageData ii = null;
81 byte[] imageBytes = null;
82 try {
83 ii = getAlbumData().getImageAccessor().getImageInfo(selectedImageName);
84 imageBytes = getAlbumData().getImageAccessor().loadImageBytesFromRMS(ii.getParentAlbumName(), ii.getImageLabel(), ii.getForeignRecordId());
85 } catch (ImageNotFoundException e) {
86 Alert alert = new Alert( "Error", "The selected image can not be found", null, AlertType.ERROR);
87 alert.setTimeout(5000);
88 } catch (NullAlbumDataReference e) {
89 this.setAlbumData( new AlbumData() );
90 Alert alert = new Alert( "Error", "The operation is not available. Try again later !", null, AlertType.ERROR);
91 Display.getDisplay(midlet).setCurrent(alert, Display.getDisplay(midlet).getCurrent());
92 } catch (PersistenceMechanismException e) {
93 Alert alert = new Alert( "Error", "It was not possible to recovery the selected image", null, AlertType.ERROR);
94 alert.setTimeout(5000);
95 }
96
97
98 System.out.println("SmsController::handleCommand - Sending bytes for image " + ii.getImageLabel() + " with length: " + imageBytes.length);
99
100 //Get the destination info - set some defaults just in case
101 String smsPort = "1000";
102 String destinationAddress = "5550001";
103 String messageText = "Binary Message (No Text)";
104
105 smsPort = networkScreen.getRecPort();
106 destinationAddress = networkScreen.getRecPhoneNum();
107
108 System.out.println("SmsController:handleCommand() - Info from Network Screen is: " + smsPort + " and " + destinationAddress);
109
110 SmsSenderThread smsS = new SmsSenderThread(smsPort,destinationAddress,messageText);
111 smsS.setBinaryData(imageBytes);
112 new Thread(smsS).start();
113 return true;
114
115
116 } else if (label.equals("Cancel Send")) {
117
118 //TODO: If they want to cancel sending the SMS message, send them back to main screen
119 System.out.println("Cancel sending of SMS message");
120 return true;
121
122 }
123
124 return false;
125 }
126 }
127 //#endif
|