Classes sorted by package:

core.comms
BaseMessaging

core.threads
BaseThread

core.ui
MainUIMidlet

core.ui.controller
AbstractController
AlbumController
BaseController
ControllerInterface
PhotoController
PhotoListController
PhotoViewController
ScreenSingleton

core.ui.datamodel
AlbumData
ImageAccessor
ImageData

core.ui.screens
AddPhotoToAlbum
AlbumListScreen
NewLabelScreen
PhotoListScreen
PhotoViewScreen
SplashScreen

core.util
Constants
ImageUtil

sms
NetworkScreen
SmsMessaging
SmsReceiverController
SmsReceiverThread
SmsSenderController
SmsSenderThread
  1 /*
  2  * Lancaster University
  3  * Computing Department
  4  
  5  * Created by Eduardo Figueiredo
  6  * Date: 22 Jul 2007
  7  
  8  */
  9 package ubc.midp.mobilephoto.core.ui.controller;
 10 
 11 import javax.microedition.lcdui.Alert;
 12 import javax.microedition.lcdui.AlertType;
 13 import javax.microedition.lcdui.Command;
 14 import javax.microedition.lcdui.Display;
 15 
 16 import javax.microedition.rms.RecordStoreFullException;
 17 
 18 import lancs.midp.mobilephoto.lib.exceptions.ImageNotFoundException;
 19 import lancs.midp.mobilephoto.lib.exceptions.ImagePathNotValidException;
 20 import lancs.midp.mobilephoto.lib.exceptions.InvalidImageDataException;
 21 import lancs.midp.mobilephoto.lib.exceptions.NullAlbumDataReference;
 22 import lancs.midp.mobilephoto.lib.exceptions.PersistenceMechanismException;
 23 import ubc.midp.mobilephoto.core.ui.MainUIMidlet;
 24 import ubc.midp.mobilephoto.core.ui.datamodel.AlbumData;
 25 import ubc.midp.mobilephoto.core.ui.datamodel.ImageAccessor;
 26 import ubc.midp.mobilephoto.core.ui.datamodel.ImageData;
 27 import ubc.midp.mobilephoto.core.ui.screens.AddPhotoToAlbum;
 28 import ubc.midp.mobilephoto.core.ui.screens.AlbumListScreen;
 29 import ubc.midp.mobilephoto.core.util.Constants;
 30 
 31 import ubc.midp.mobilephoto.core.ui.screens.PhotoViewScreen;
 32 import javax.microedition.lcdui.Image;
 33 /**
 34  @author Eduardo Figueiredo
 35  */
 36 public class PhotoViewController extends AbstractController {
 37 
 38   String imageName = "";
 39   
 40   /**
 41    @param midlet
 42    @param nextController
 43    @param albumData
 44    @param albumListScreen
 45    @param currentScreenName
 46    */
 47   public PhotoViewController(MainUIMidlet midlet, AlbumData albumData, AlbumListScreen albumListScreen, String imageName) {
 48     super(midlet, albumData, albumListScreen);
 49     this.imageName = imageName;
 50   }
 51 
 52   /* (non-Javadoc)
 53    * @see ubc.midp.mobilephoto.core.ui.controller.ControllerInterface#handleCommand(javax.microedition.lcdui.Command, javax.microedition.lcdui.Displayable)
 54    */
 55   public boolean handleCommand(Command c) {
 56     String label = c.getLabel();
 57     System.out.println"<* PhotoViewController.handleCommand() *> " + label);
 58 
 59     /** Case: Copy photo to a different album */
 60     if (label.equals("Copy")) {
 61       AddPhotoToAlbum copyPhotoToAlbum = new AddPhotoToAlbum("Copy Photo to Album");
 62       copyPhotoToAlbum.setPhotoName(imageName);
 63       copyPhotoToAlbum.setLabePhotoPath("Copy to Album:");
 64       copyPhotoToAlbum.setCommandListener(this);
 65 
 66       if (((PhotoViewScreen)this.getCurrentScreen()).isFromSMS())
 67         {copyPhotoToAlbum.setImage(((PhotoViewScreen)this.getCurrentScreen()).getImage());}
 68       
 69           Display.getDisplay(midlet).setCurrent(copyPhotoToAlbum);
 70       
 71       return true;
 72     }
 73     
 74     /** Case: Save a copy in a new album */
 75     else if (label.equals("Save Photo")) {
 76       try {
 77         ImageData imageData = null;  
 78         Image img = ((AddPhotoToAlbum)this.getCurrentScreen()).getImage();
 79         
 80         if (img == null)
 81         {
 82           try {
 83             imageData = getAlbumData().getImageAccessor().getImageInfo(imageName);
 84           catch (ImageNotFoundException e) {
 85             Alert alert = new Alert("Error""The selected photo was not found in the mobile device", null, AlertType.ERROR);
 86             Display.getDisplay(midlet).setCurrent(alert, Display.getDisplay(midlet).getCurrent());
 87           catch (NullAlbumDataReference e) {
 88             this.setAlbumDatanew 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           }
 92         }
 93         
 94         
 95         String photoname = ((AddPhotoToAlbumgetCurrentScreen()).getPhotoName();
 96         String albumname = ((AddPhotoToAlbumgetCurrentScreen()).getPath();
 97         ImageAccessor imageAccessor = getAlbumData().getImageAccessor();
 98         
 99         if (img != null)
100           imageAccessor.addImageData(photoname, img, albumname);
101         
102         if (img == null)
103           
104         imageAccessor.addImageData(photoname, imageData, albumname)
105         
106       
107         
108       catch (InvalidImageDataException e) {
109         Alert alert = null;
110         if (instanceof ImagePathNotValidException)
111           alert = new Alert("Error""The path is not valid", null, AlertType.ERROR);
112         else
113           alert = new Alert("Error""The image file format is not valid", null, AlertType.ERROR);
114         Display.getDisplay(midlet).setCurrent(alert, Display.getDisplay(midlet).getCurrent());
115         return true;
116         // alert.setTimeout(5000);
117       catch (PersistenceMechanismException e) {
118         Alert alert = null;
119         if (e.getCause() instanceof RecordStoreFullException)
120           alert = new Alert("Error""The mobile database is full", null, AlertType.ERROR);
121         else
122           alert = new Alert("Error""The mobile database can not add a new photo", null, AlertType.ERROR);
123         Display.getDisplay(midlet).setCurrent(alert, Display.getDisplay(midlet).getCurrent());
124       }
125       //((PhotoController)this.getNextController()).showImageList(ScreenSingleton.getInstance().getCurrentStoreName(), false, false);
126         //ScreenSingleton.getInstance().setCurrentScreenName(Constants.IMAGELIST_SCREEN);
127         getAlbumListScreen().repaintListAlbum(getAlbumData().getAlbumNames());
128       setCurrentScreengetAlbumListScreen() );
129       ScreenSingleton.getInstance().setCurrentScreenName(Constants.ALBUMLIST_SCREEN);
130       return true;
131     }else if ((label.equals("Cancel")) || (label.equals("Back"))){
132       getAlbumListScreen().repaintListAlbum(getAlbumData().getAlbumNames());
133       setCurrentScreengetAlbumListScreen() );
134       ScreenSingleton.getInstance().setCurrentScreenName(Constants.ALBUMLIST_SCREEN);
135       return true;
136     }
137     
138     return false;
139   }
140 }