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