Changeset 1460
- Timestamp:
- 11/10/08 04:26:07 (2 months ago)
- Location:
- branches/dev/j2merosa/org.javarosa.media.image/src/org/javarosa/media/image
- Files:
-
- 5 modified
- 2 moved
-
activity/FileBrowseActivity.java (modified) (5 diffs)
-
activity/ImageCaptureActivity.java (modified) (7 diffs)
-
activity/ImageChooserActivity.java (modified) (12 diffs)
-
model/FileDataPointer.java (modified) (2 diffs)
-
storage/FileMetaData.java (moved) (moved from branches/dev/j2merosa/org.javarosa.media.image/src/org/javarosa/media/image/storage/ImageMetaData.java) (1 diff)
-
storage/FileRMSUtility.java (moved) (moved from branches/dev/j2merosa/org.javarosa.media.image/src/org/javarosa/media/image/storage/ImageRMSUtility.java) (2 diffs)
-
utilities/FileUtility.java (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/dev/j2merosa/org.javarosa.media.image/src/org/javarosa/media/image/activity/FileBrowseActivity.java
r1455 r1460 4 4 import java.io.InputStream; 5 5 import java.util.Enumeration; 6 import java.util.Hashtable; 6 7 7 8 import javax.microedition.io.Connector; … … 23 24 import org.javarosa.core.api.IShell; 24 25 import org.javarosa.j2me.view.DisplayViewFactory; 26 import org.javarosa.media.image.model.FileDataPointer; 25 27 import org.javarosa.media.image.utilities.FileUtility; 26 28 … … 41 43 private final static String SEP_STR = "/"; 42 44 private final static char SEP = '/'; 45 46 public static final String FILE_POINTER = "FILE_POINTER"; 43 47 44 48 public FileBrowseActivity(IShell shell) { … … 103 107 List curr = (List) d; 104 108 final String currFile = curr.getString(curr.getSelectedIndex()); 105 106 109 new Thread(new Runnable() { 107 110 public void run() { … … 184 187 185 188 void returnFile(String fileName) { 186 try { 187 // todo 188 } catch (Exception e) { 189 } 189 String fullName = "file:///" + currDirName + fileName; 190 FileDataPointer fdp = new FileDataPointer(fullName); 191 Hashtable returnArgs = new Hashtable(); 192 returnArgs.put(FILE_POINTER, fdp); 193 shell.returnFromActivity(this, Constants.ACTIVITY_COMPLETE, returnArgs); 190 194 } 191 195 -
branches/dev/j2merosa/org.javarosa.media.image/src/org/javarosa/media/image/activity/ImageCaptureActivity.java
r1455 r1460 2 2 3 3 import java.io.IOException; 4 import java.io.OutputStream;5 import java.util.Enumeration;6 4 import java.util.Hashtable; 7 5 8 import javax.microedition.io.Connector;9 import javax.microedition.io.file.FileConnection;10 import javax.microedition.io.file.FileSystemRegistry;11 6 import javax.microedition.lcdui.Alert; 12 7 import javax.microedition.lcdui.AlertType; … … 14 9 import javax.microedition.lcdui.Command; 15 10 import javax.microedition.lcdui.CommandListener; 16 import javax.microedition.lcdui.Display;17 11 import javax.microedition.lcdui.Displayable; 18 12 import javax.microedition.lcdui.Image; … … 28 22 import org.javarosa.core.api.IDisplay; 29 23 import org.javarosa.core.api.IShell; 24 import org.javarosa.core.model.data.BasicDataPointer; 30 25 import org.javarosa.j2me.view.DisplayViewFactory; 31 26 import org.javarosa.media.image.model.FileDataPointer; 32 import org.javarosa.media.image.storage. ImageRMSUtility;27 import org.javarosa.media.image.storage.FileRMSUtility; 33 28 import org.javarosa.media.image.utilities.FileUtility; 34 29 import org.javarosa.media.image.view.CameraCanvas; … … 56 51 private Command mCaptureCommand; 57 52 private IDisplay display; 58 private ImageRMSUtility dataModel; 59 private Image image; 53 private FileRMSUtility dataModel; 54 private byte[] imageData; 55 private int width; 56 private int height; 60 57 61 58 public ImageCaptureActivity(IShell shell) { 62 59 this.shell = shell; 63 60 display = JavaRosaServiceProvider.instance().getDisplay(); 64 dataModel = new ImageRMSUtility("image_store"); 65 } 66 61 dataModel = new FileRMSUtility("image_store"); 62 width = 640; 63 height = 480; 64 } 65 66 67 67 public void contextChanged(Context globalContext) { 68 68 // TODO Auto-generated method stub … … 101 101 } 102 102 103 public void setResolition(int width, int height) { 104 this.width = width; 105 this.height = height; 106 107 } 103 108 /** 104 109 * Actually capture an image … … 126 131 // stick the picture in here. 127 132 Hashtable table = new Hashtable(); 128 table.put(IMAGE_KEY, image); 133 BasicDataPointer p = new BasicDataPointer("Image", imageData); 134 table.put(IMAGE_KEY, p); 129 135 return table; 130 136 } 137 131 138 private void showCamera() { 132 139 try { … … 186 193 187 194 private void doCapture() { 188 byte[] jpg;189 int width = 640;190 int height = 480;191 195 try { 192 196 // Get the image. 193 jpg= mVideoControl.getSnapshot("encoding=jpeg&quality=100&width=" + width + "&height=" + height);194 image = Image.createImage(jpg, 0, jpg.length);197 imageData = mVideoControl.getSnapshot("encoding=jpeg&quality=100&width=" + width + "&height=" + height); 198 //image = Image.createImage(jpg, 0, jpg.length); 195 199 doFinish(); 196 200 // Save to file no longer -
branches/dev/j2merosa/org.javarosa.media.image/src/org/javarosa/media/image/activity/ImageChooserActivity.java
r1455 r1460 16 16 import org.javarosa.core.api.IDisplay; 17 17 import org.javarosa.core.api.IShell; 18 import org.javarosa.core.model.data.IDataPointer; 18 19 import org.javarosa.j2me.view.DisplayViewFactory; 19 20 import org.javarosa.media.image.model.FileDataPointer; 20 import org.javarosa.media.image.storage. ImageRMSUtility;21 import org.javarosa.media.image.storage.FileRMSUtility; 21 22 import org.javarosa.media.image.utilities.ImageUtility; 22 23 23 24 /** 24 * An Activity that represents the selection of zero or more images. 25 * This will launch a UI that supports displaying a list of images, marking 26 * some subset of them and returning those images. New images can also 27 * be added via an ImageCaptureActivity. 25 * An Activity that represents the selection of zero or more images. This will 26 * launch a UI that supports displaying a list of images, marking some subset of 27 * them and returning those images. New images can also be added via an 28 * ImageCaptureActivity. 29 * 28 30 * @author Cory Zue 29 * 31 * 30 32 */ 31 public class ImageChooserActivity implements IActivity, CommandListener 32 { 33 public class ImageChooserActivity implements IActivity, CommandListener { 33 34 public static final String ACTIVITY_KEY = "ACTIVITY_KEY"; 34 // this should map images (IDataPointers) to bool true/false whether selected or not 35 // this should map images (IDataPointers) to bool true/false whether 36 // selected or not 35 37 private Hashtable allImages; 36 38 private Context context; 37 39 private IShell shell; 38 40 private IDisplay display; 39 private ImageRMSUtility dataModel;41 private FileRMSUtility dataModel; 40 42 private Form mainForm; 41 43 private Command cancelCommand; … … 46 48 private Command markCommand; 47 49 private String currentKey; 48 49 50 50 51 public ImageChooserActivity(IShell shell) { 51 52 this.shell = shell; 52 53 display = JavaRosaServiceProvider.instance().getDisplay(); 53 dataModel = new ImageRMSUtility("image_store");54 54 dataModel = new FileRMSUtility("image_store"); 55 55 56 cancelCommand = new Command("Cancel", Command.CANCEL, 0); 56 57 returnCommand = new Command("Return", Command.OK, 0); 57 cameraCommand = new Command("Camera", Command.SCREEN, 0);58 browseCommand = new Command("Browse", Command.SCREEN, 0);59 viewCommand = new Command("View", Command.SCREEN, 0);60 markCommand = new Command("Mark/Unmark", Command.SCREEN, 0);58 cameraCommand = new Command("Camera", Command.SCREEN, 0); 59 browseCommand = new Command("Browse", Command.SCREEN, 0); 60 viewCommand = new Command("View", Command.SCREEN, 0); 61 markCommand = new Command("Mark/Unmark", Command.SCREEN, 0); 61 62 } 62 63 63 64 public void contextChanged(Context globalContext) { 64 65 65 66 66 } 67 67 68 68 public void destroy() { 69 69 // TODO Auto-generated method stub 70 70 71 71 } 72 72 … … 77 77 public void halt() { 78 78 // TODO Auto-generated method stub 79 79 80 80 } 81 81 82 82 public void resume(Context globalContext) { 83 Image img = (Image) globalContext.getElement(currentKey); 84 if (img != null) { 85 Image thumbnail = ImageUtility.createThumbnail(img); 86 mainForm.append(thumbnail); 83 Object o = globalContext.getElement(currentKey); 84 IDataPointer pointer = (IDataPointer) o; 85 try { 86 if (pointer != null) { 87 byte[] data = pointer.getData(); 88 Image img = Image.createImage(data, 0, data.length); 89 Image thumbNail = ImageUtility.createThumbnail(img); 90 mainForm.append(thumbNail); 91 } 92 } catch (Exception ex) { 93 System.out.println(ex.getMessage()); 94 System.out.println(ex); 95 87 96 } 88 97 display.setView(DisplayViewFactory.createView(mainForm)); 89 90 98 } 91 99 92 100 public void setShell(IShell shell) { 93 101 this.shell = shell; 94 102 95 103 } 96 104 … … 98 106 this.context = context; 99 107 mainForm = new Form("Image Chooser"); 100 mainForm.addCommand(cancelCommand);108 mainForm.addCommand(cancelCommand); 101 109 mainForm.addCommand(cameraCommand); 102 110 mainForm.addCommand(browseCommand); … … 104 112 mainForm.addCommand(viewCommand); 105 113 mainForm.addCommand(markCommand); 106 mainForm.setCommandListener(this);107 108 display.setView(DisplayViewFactory.createView(mainForm));109 110 } 111 114 mainForm.setCommandListener(this); 115 116 display.setView(DisplayViewFactory.createView(mainForm)); 117 118 } 119 112 120 private FileDataPointer captureNewImage() { 113 // TODO: I have a feeling this is going to actually be some sort of back and forth chicannery 121 // TODO: I have a feeling this is going to actually be some sort of back 122 // and forth chicannery 114 123 // with the shell 115 124 return null; 116 125 } 117 126 118 127 /** 119 * Selects an image 128 * Selects an image 129 * 120 130 * @param image 121 131 */ … … 123 133 // TODO: impl; 124 134 } 125 135 126 136 /** 127 * Deselects an image 137 * Deselects an image 138 * 128 139 * @param image 129 140 */ … … 131 142 // TODO: impl; 132 143 } 133 144 134 145 /** 135 146 * Picks the selected images and returns them (and control) to the shell … … 137 148 */ 138 149 private void finish() { 139 Hashtable args = null; // buildReturnArgs();150 Hashtable args = null; // buildReturnArgs(); 140 151 shell.returnFromActivity(this, "Success!", args); 141 152 … … 155 166 } else if (command.equals(markCommand)) { 156 167 processMark(); 157 } 168 } 158 169 } 159 170 … … 164 175 private void processMark() { 165 176 // TODO Auto-generated method stub 166 177 167 178 } 168 179 169 180 private void processCancel() { 170 shell.returnFromActivity(this, Constants.ACTIVITY_CANCEL, null); 181 shell.returnFromActivity(this, Constants.ACTIVITY_CANCEL, null); 171 182 } 172 183 173 184 private void processView() { 174 185 // TODO Auto-generated method stub 175 186 176 187 } 177 188 178 189 private void processBrowser() { 190 currentKey = FileBrowseActivity.FILE_POINTER; 179 191 returnFromActivity(new FileBrowseActivity(shell)); 180 192 } 181 193 182 private void processCamera() 183 { 194 private void processCamera() { 184 195 currentKey = ImageCaptureActivity.IMAGE_KEY; 185 196 returnFromActivity(new ImageCaptureActivity(shell)); … … 188 199 private void returnFromActivity(IActivity activity) { 189 200 Hashtable returnArgs = buildReturnArgsFromActivity(activity); 190 shell.returnFromActivity(this, Constants.ACTIVITY_NEEDS_RESOLUTION, returnArgs); 201 shell.returnFromActivity(this, Constants.ACTIVITY_NEEDS_RESOLUTION, 202 returnArgs); 191 203 } 192 204 … … 197 209 } 198 210 199 200 201 211 } -
branches/dev/j2merosa/org.javarosa.media.image/src/org/javarosa/media/image/model/FileDataPointer.java
r1419 r1460 2 2 3 3 import org.javarosa.core.model.data.IDataPointer; 4 import org.javarosa.media.image.utilities.FileUtility; 4 5 5 6 /** … … 18 19 19 20 public byte[] getData() { 20 // TODO read the file from memory 21 return null; 21 return FileUtility.getFileData(fileName); 22 22 } 23 23 -
branches/dev/j2merosa/org.javarosa.media.image/src/org/javarosa/media/image/storage/FileMetaData.java
r1434 r1460 8 8 * 9 9 */ 10 public class ImageMetaData extends MetaDataObject {10 public class FileMetaData extends MetaDataObject { 11 11 12 12 -
branches/dev/j2merosa/org.javarosa.media.image/src/org/javarosa/media/image/storage/FileRMSUtility.java
r1434 r1460 7 7 8 8 /** 9 * A (potentially temporary) class for writing a n imageto RMS9 * A (potentially temporary) class for writing a basic byte[] to RMS 10 10 * @author Cory Zue 11 11 * 12 12 */ 13 public class ImageRMSUtility extends RMSUtility {13 public class FileRMSUtility extends RMSUtility { 14 14 15 15 private Hashtable images; 16 16 17 public ImageRMSUtility(String name) {17 public FileRMSUtility(String name) { 18 18 super(name, RMSUtility.RMS_TYPE_STANDARD); 19 images = new Hashtable(); 19 images = new Hashtable(); 20 20 } 21 21 … … 33 33 public void saveImage(String fileName, byte[] data) { 34 34 35 ImageMetaData md = new ImageMetaData();35 FileMetaData md = new FileMetaData(); 36 36 md.setFileName(fileName); 37 37 this.writeBytesToRMS(data, md); -
branches/dev/j2merosa/org.javarosa.media.image/src/org/javarosa/media/image/utilities/FileUtility.java
r1455 r1460 2 2 3 3 import java.io.IOException; 4 import java.io.InputStream; 4 5 import java.io.OutputStream; 5 6 import java.util.Enumeration; … … 116 117 } 117 118 119 120 /** 121 * Gets file data from the OS 122 * @param fileName 123 * @return 124 */ 125 public static byte[] getFileData(String fileName) { 126 InputStream fis = null; 127 FileConnection file = null; 128 boolean isSaved = false; 129 try { 130 file = (FileConnection) Connector.open(fileName); 131 int bytesToRead = (int) file.fileSize(); 132 byte[] toReturn = new byte[bytesToRead]; 133 fis = file.openInputStream(); 134 int bytesRead = 0; 135 int blockSize = 1024; 136 while (bytesToRead > bytesRead) { 137 int thisBlock = blockSize; 138 if (bytesToRead - bytesRead < blockSize) { 139 thisBlock = bytesToRead-bytesRead; 140 } 141 fis.read(toReturn, bytesRead, thisBlock); 142 bytesRead += blockSize; 143 } 144 return toReturn; 145 } catch (Exception ex) { 146 handleException(ex); 147 } 148 finally { 149 close(fis); 150 close(file); 151 } 152 return null; 153 } 154 private static void close(InputStream stream) { 155 try { 156 if (stream != null) { 157 stream.close(); 158 } 159 } catch (Exception e) { 160 } 161 } 162 163 118 164 private static void close(OutputStream stream) { 119 165 try { … … 140 186 141 187 188 189 142 190 }
