Changeset 1455
- Timestamp:
- 11/07/08 17:03:58 (2 months ago)
- Location:
- branches/dev/j2merosa/org.javarosa.media.image/src/org/javarosa/media/image
- Files:
-
- 1 added
- 5 modified
- 1 moved
-
activity/FileBrowseActivity.java (moved) (moved from branches/dev/j2merosa/org.javarosa.media.image/src/org/javarosa/media/image/utilities/FileBrowseActivity.java) (9 diffs)
-
activity/ImageCaptureActivity.java (modified) (9 diffs)
-
activity/ImageChooserActivity.java (modified) (7 diffs)
-
midlet/SnapperMIDlet.java (modified) (2 diffs)
-
utilities/FileUtility.java (modified) (4 diffs)
-
utilities/ImageUtility.java (added)
-
view/CameraCanvas.java (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/dev/j2merosa/org.javarosa.media.image/src/org/javarosa/media/image/activity/FileBrowseActivity.java
r1445 r1455 1 package org.javarosa.media.image. utilities;1 package org.javarosa.media.image.activity; 2 2 3 3 import java.io.IOException; … … 6 6 7 7 import javax.microedition.io.Connector; 8 import javax.microedition.io.file.FileConnection;9 import javax.microedition.io.file.FileSystemRegistry;10 8 import javax.microedition.lcdui.Alert; 11 9 import javax.microedition.lcdui.AlertType; … … 20 18 import org.javarosa.core.Context; 21 19 import org.javarosa.core.JavaRosaServiceProvider; 20 import org.javarosa.core.api.Constants; 22 21 import org.javarosa.core.api.IActivity; 23 22 import org.javarosa.core.api.IDisplay; 24 23 import org.javarosa.core.api.IShell; 25 24 import org.javarosa.j2me.view.DisplayViewFactory; 25 import org.javarosa.media.image.utilities.FileUtility; 26 26 27 27 public class FileBrowseActivity implements IActivity, CommandListener { … … 29 29 private String currDirName; 30 30 31 private Command view = new Command("View", Command.ITEM, 1);31 private Command selectCommand = new Command("Select", Command.OK, 1); 32 32 private Command back = new Command("Back", Command.BACK, 2); 33 private Command exit = new Command("Exit", Command.EXIT, 3);33 private Command cancel = new Command("Cancel", Command.CANCEL, 3); 34 34 35 35 private IShell shell; … … 54 54 55 55 public void destroy() { 56 shell.returnFromActivity(this, "Success!", null); 57 56 58 57 } 59 58 … … 101 100 public void commandAction(Command c, Displayable d) { 102 101 System.out.println("updir:" + UP_DIRECTORY); 103 if (c == view) {102 if (c == selectCommand ) { 104 103 List curr = (List) d; 105 104 final String currFile = curr.getString(curr.getSelectedIndex()); 106 System.out.println("currFile:" + currFile); 107 105 108 106 new Thread(new Runnable() { 109 107 public void run() { 110 108 if (currFile.endsWith(SEP_STR) 111 109 || currFile.equals(UP_DIRECTORY)) { 112 System.out.println("h7");113 114 110 traverseDirectory(currFile); 115 111 } else { 116 showFile(currFile);112 returnFile(currFile); 117 113 } 118 114 } … … 120 116 } else if (c == back) { 121 117 showCurrDir(); 122 } else if (c == exit) {123 destroy();118 } else if (c == cancel) { 119 shell.returnFromActivity(this, Constants.ACTIVITY_CANCEL, null); 124 120 } 125 121 } … … 127 123 void showCurrDir() { 128 124 Enumeration e; 129 FileConnection currDir = null;130 125 List browser; 131 try { 132 System.out.println("In showCurrDir"); 133 System.out.println("mega_root:" + MEGA_ROOT + "cur_dir:" 134 + currDirName); 135 if (MEGA_ROOT.equals(currDirName)) { 136 e = FileSystemRegistry.listRoots(); 137 browser = new List(currDirName, List.IMPLICIT); 138 System.out.println("here"); 139 } else { 140 System.out.println("connector"); 141 currDir = (FileConnection) Connector.open("file://localhost/" 142 + currDirName); 143 System.out.println("curr_dir:" + currDir); 144 // currDir = 145 // (FileConnection)Connector.open("http://localhost:8080/" + 146 // currDirName); 147 e = currDir.list(); 148 browser = new List(currDirName, List.IMPLICIT); 149 browser.append(UP_DIRECTORY, null); 126 System.out.println("In showCurrDir"); 127 System.out.println("mega_root:" + MEGA_ROOT + "cur_dir:" 128 + currDirName); 129 if (MEGA_ROOT.equals(currDirName)) { 130 e = FileUtility.getRootNames(); 131 browser = new List(currDirName, List.IMPLICIT); 132 System.out.println("here"); 133 } else { 134 String fullPath = "file://localhost/" + currDirName; 135 e = FileUtility.listDirectory(fullPath); 136 browser = new List(currDirName, List.IMPLICIT); 137 browser.append(UP_DIRECTORY, null); 138 } 139 while (e.hasMoreElements()) { 140 String fileName = (String) e.nextElement(); 141 if (fileName.charAt(fileName.length() - 1) == SEP) { 142 browser.append(fileName, null); 150 143 } 151 while (e.hasMoreElements()) { 152 System.out.println("h2"); 153 String fileName = (String) e.nextElement(); 154 System.out.println("fileName:" + fileName + " char_at:" 155 + fileName.charAt(fileName.length() - 1)); 144 // if((fileName.charAt(fileName.length()-1))).equals("g"))){} 145 else { 146 System.out.println("h4"); 147 // Image image = Image.createImage(fileName); 148 browser.append(fileName, null); 149 // Form form = new Form("Image here"); 156 150 157 if (fileName.charAt(fileName.length() - 1) == SEP) { 158 browser.append(fileName, null); 159 160 } 161 // if((fileName.charAt(fileName.length()-1))).equals("g"))){} 162 else { 163 System.out.println("h4"); 164 // Image image = Image.createImage(fileName); 165 browser.append(fileName, null); 166 // Form form = new Form("Image here"); 167 168 // form.append(image); 169 } 151 // form.append(image); 170 152 } 171 browser.setSelectCommand(view);172 browser.addCommand(exit);173 browser.setCommandListener(this);174 if (currDir != null) {175 currDir.close();176 }177 display.setView(DisplayViewFactory.createView(browser));178 } catch (IOException ioe) {179 //System.out.println(ioe);180 153 } 154 browser.setSelectCommand(selectCommand ); 155 browser.addCommand(cancel); 156 browser.setCommandListener(this); 157 display.setView(DisplayViewFactory.createView(browser)); 181 158 } 182 159 … … 206 183 } 207 184 208 void showFile(String fileName) {185 void returnFile(String fileName) { 209 186 try { 210 FileConnection fc = (FileConnection) Connector 211 .open("file://localhost/" + currDirName + fileName); 212 if (!fc.exists()) { 213 throw new IOException("File does not exists"); 214 } 215 InputStream fis = fc.openInputStream(); 216 byte[] b = new byte[1024]; 217 int length = fis.read(b, 0, 1024); 218 fis.close(); 219 fc.close(); 220 221 TextBox tb = new TextBox("View File: " + fileName, null, 1024, 222 TextField.ANY | TextField.UNEDITABLE); 223 224 tb.addCommand(back); 225 tb.addCommand(exit); 226 tb.setCommandListener(this); 227 228 if (length > 0) { 229 tb.setString(new String(b, 0, length)); 230 } 231 display.setView(DisplayViewFactory.createView(tb)); 187 // todo 232 188 } catch (Exception e) { 233 189 } -
branches/dev/j2merosa/org.javarosa.media.image/src/org/javarosa/media/image/activity/ImageCaptureActivity.java
r1445 r1455 44 44 { 45 45 46 public static final String IMAGE_KEY = "IMAGE_KEY"; 46 47 private Context context; 47 48 private IShell shell; … … 56 57 private IDisplay display; 57 58 private ImageRMSUtility dataModel; 58 59 private Image image; 60 59 61 public ImageCaptureActivity(IShell shell) { 60 62 this.shell = shell; … … 69 71 70 72 public void destroy() { 71 shell.returnFromActivity(this, "Success!", null); 73 mPlayer.close(); 74 mPlayer = null; 75 mVideoControl = null; 72 76 } 73 77 74 78 public Context getActivityContext() { 75 // TODO Auto-generated method stub 76 return null; 79 return context; 77 80 } 78 81 … … 96 99 this.context = context; 97 100 showCamera(); 98 99 101 } 100 102 … … 112 114 * Other images are deleted? 113 115 */ 114 private void finish() {116 private void doFinish() { 115 117 Hashtable args = buildReturnArgs(); 116 shell.returnFromActivity(this, "Success!", args); 117 118 shell.returnFromActivity(this, Constants.ACTIVITY_COMPLETE, args); 119 } 120 121 private void doError() { 122 shell.returnFromActivity(this, Constants.ACTIVITY_ERROR, null); 118 123 } 119 124 120 125 private Hashtable buildReturnArgs() { 121 126 // stick the picture in here. 122 return null; 127 Hashtable table = new Hashtable(); 128 table.put(IMAGE_KEY, image); 129 return table; 123 130 } 124 131 private void showCamera() { … … 129 136 mVideoControl = (VideoControl) mPlayer.getControl("VideoControl"); 130 137 131 //Command mExitCommand = new Command("Exit", Command.EXIT, 0);132 //Command mCameraCommand = new Command("Camera", Command.SCREEN, 0);138 // Command mExitCommand = new Command("Exit", Command.EXIT, 0); 139 // Command mCameraCommand = new Command("Camera", Command.SCREEN, 0); 133 140 mBackCommand = new Command("Back", Command.BACK, 0); 134 141 mCaptureCommand = new Command("Capture", Command.SCREEN, 0); … … 153 160 // JavaRosaServiceProvider.instance().getDisplay().setCurrent(a); 154 161 // throw new RuntimeException(e.getMessage()); 162 System.out.println(e.getMessage()); 163 e.printStackTrace(); 155 164 String toLog = e.getMessage(); 156 165 toLog += e.toString(); 157 166 saveFile("log" + System.currentTimeMillis() + ".txt", toLog.getBytes()); 158 167 159 } 160 168 doError(); 169 } 170 171 161 172 public void commandAction(Command cmd, Displayable display) { 162 // TODO Auto-generated method stub163 173 if (cmd.equals(this.mBackCommand)) { 164 174 goBack(); … … 166 176 else if (cmd.equals(this.mCaptureCommand)) { 167 177 doCapture(); 168 System.out.println("Click!");178 //doCaptureLoop(); 169 179 } 170 180 } 171 181 172 182 private void goBack() { 173 // TODO174 System.out.println("Back Again!");175 183 this.shell.returnFromActivity(this, Constants.ACTIVITY_CANCEL, null); 176 184 … … 178 186 179 187 private void doCapture() { 180 byte[] jpg; 181 int width = 1360;182 int height = 1020;188 byte[] jpg; 189 int width = 640; 190 int height = 480; 183 191 try { 184 192 // Get the image. 185 193 jpg = mVideoControl.getSnapshot("encoding=jpeg&quality=100&width=" + width + "&height=" + height); 186 // Save to file 187 String fileName = "test" + System.currentTimeMillis(); 188 boolean saved = saveFile(fileName + ".jpg", jpg); 189 } catch (MediaException me) { 194 image = Image.createImage(jpg, 0, jpg.length); 195 doFinish(); 196 // Save to file no longer 197 //String fileName = "test" + System.currentTimeMillis(); 198 //boolean saved = saveFile(fileName + ".jpg", jpg); 199 } catch (Exception me) { 190 200 handleException(me); 191 201 } -
branches/dev/j2merosa/org.javarosa.media.image/src/org/javarosa/media/image/activity/ImageChooserActivity.java
r1445 r1455 3 3 import java.util.Hashtable; 4 4 5 import javax.microedition.lcdui.Command; 6 import javax.microedition.lcdui.CommandListener; 5 7 import javax.microedition.lcdui.Display; 8 import javax.microedition.lcdui.Displayable; 9 import javax.microedition.lcdui.Form; 10 import javax.microedition.lcdui.Image; 6 11 7 12 import org.javarosa.core.Context; 8 13 import org.javarosa.core.JavaRosaServiceProvider; 14 import org.javarosa.core.api.Constants; 9 15 import org.javarosa.core.api.IActivity; 10 16 import org.javarosa.core.api.IDisplay; 11 17 import org.javarosa.core.api.IShell; 18 import org.javarosa.j2me.view.DisplayViewFactory; 12 19 import org.javarosa.media.image.model.FileDataPointer; 13 20 import org.javarosa.media.image.storage.ImageRMSUtility; 21 import org.javarosa.media.image.utilities.ImageUtility; 14 22 15 23 /** … … 21 29 * 22 30 */ 23 public class ImageChooserActivity implements IActivity 31 public class ImageChooserActivity implements IActivity, CommandListener 24 32 { 33 public static final String ACTIVITY_KEY = "ACTIVITY_KEY"; 25 34 // this should map images (IDataPointers) to bool true/false whether selected or not 26 35 private Hashtable allImages; … … 29 38 private IDisplay display; 30 39 private ImageRMSUtility dataModel; 40 private Form mainForm; 41 private Command cancelCommand; 42 private Command cameraCommand; 43 private Command browseCommand; 44 private Command returnCommand; 45 private Command viewCommand; 46 private Command markCommand; 47 private String currentKey; 48 31 49 32 50 public ImageChooserActivity(IShell shell) { … … 34 52 display = JavaRosaServiceProvider.instance().getDisplay(); 35 53 dataModel = new ImageRMSUtility("image_store"); 54 55 cancelCommand = new Command("Cancel", Command.CANCEL, 0); 56 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); 36 61 } 37 62 … … 47 72 48 73 public Context getActivityContext() { 49 // TODO Auto-generated method stub 50 return null; 74 return context; 51 75 } 52 76 … … 57 81 58 82 public void resume(Context globalContext) { 59 // TODO Auto-generated method stub 83 Image img = (Image) globalContext.getElement(currentKey); 84 if (img != null) { 85 Image thumbnail = ImageUtility.createThumbnail(img); 86 mainForm.append(thumbnail); 87 } 88 display.setView(DisplayViewFactory.createView(mainForm)); 60 89 61 90 } 62 91 63 92 public void setShell(IShell shell) { 64 // TODO Auto-generated method stub93 this.shell = shell; 65 94 66 95 } 67 96 68 97 public void start(Context context) { 69 // The start method should complete all initialization that was not performed in the 70 // constructor, including all GUI initialization. The context object parameter is 71 // likely a subclass of the global context object. The context should contain required 72 // and optional parameters for running the Activity. It is preferred to pass all this 73 // information through the context rather than call separate initialize(...) methods, 74 // because this way the activity's current 'configuration' can be accessed and passed 75 // around generically. 76 77 // When start() is called, the Activity should initialize itself and then take control 78 // of the application, for instance by setting the Display. Activities shouldn't touch 79 // the device's Display object directly, but rather call the shell's setDisplay() method. 80 // This allows the Shell to mediate requests for the Display, thus preventing confused 81 // Activities from breaking the Application's workflow. 82 83 // In this method you should generally save off a reference to the activity's parent Shell. 84 98 this.context = context; 99 mainForm = new Form("Image Chooser"); 100 mainForm.addCommand(cancelCommand); 101 mainForm.addCommand(cameraCommand); 102 mainForm.addCommand(browseCommand); 103 mainForm.addCommand(returnCommand); 104 mainForm.addCommand(viewCommand); 105 mainForm.addCommand(markCommand); 106 mainForm.setCommandListener(this); 107 108 display.setView(DisplayViewFactory.createView(mainForm)); 85 109 86 110 } … … 118 142 } 119 143 144 public void commandAction(Command command, Displayable display) { 145 if (command.equals(cameraCommand)) { 146 processCamera(); 147 } else if (command.equals(browseCommand)) { 148 processBrowser(); 149 } else if (command.equals(viewCommand)) { 150 processView(); 151 } else if (command.equals(cancelCommand)) { 152 processCancel(); 153 } else if (command.equals(returnCommand)) { 154 processReturn(); 155 } else if (command.equals(markCommand)) { 156 processMark(); 157 } 158 } 159 160 private void processReturn() { 161 shell.returnFromActivity(this, Constants.ACTIVITY_COMPLETE, null); 162 } 163 164 private void processMark() { 165 // TODO Auto-generated method stub 166 167 } 168 169 private void processCancel() { 170 shell.returnFromActivity(this, Constants.ACTIVITY_CANCEL, null); 171 } 172 173 private void processView() { 174 // TODO Auto-generated method stub 175 176 } 177 178 private void processBrowser() { 179 returnFromActivity(new FileBrowseActivity(shell)); 180 } 181 182 private void processCamera() 183 { 184 currentKey = ImageCaptureActivity.IMAGE_KEY; 185 returnFromActivity(new ImageCaptureActivity(shell)); 186 } 187 188 private void returnFromActivity(IActivity activity) { 189 Hashtable returnArgs = buildReturnArgsFromActivity(activity); 190 shell.returnFromActivity(this, Constants.ACTIVITY_NEEDS_RESOLUTION, returnArgs); 191 } 192 193 private Hashtable buildReturnArgsFromActivity(IActivity activity) { 194 Hashtable table = new Hashtable(); 195 table.put(ACTIVITY_KEY, activity); 196 return table; 197 } 198 120 199 121 200 -
branches/dev/j2merosa/org.javarosa.media.image/src/org/javarosa/media/image/midlet/SnapperMIDlet.java
r1434 r1455 1 1 /* License 2 * Modifications by Andres Monroy-Hernandez, 20083 2 * 4 3 * Copyright 1994-2004 Sun Microsystems, Inc. All Rights Reserved. … … 38 37 package org.javarosa.media.image.midlet; 39 38 40 import java.io.DataInputStream; 39 41 40 import java.io.IOException; 42 import java.io.InputStream;43 import java.io.OutputStream;44 import java.util.Calendar;45 import java.util.Date;46 import java.util.Enumeration;47 41 48 import javax.microedition.io.Connector; 49 import javax.microedition.io.HttpConnection; 50 import javax.microedition.io.file.FileConnection; 51 import javax.microedition.io.file.FileSystemRegistry; 52 import javax.microedition.lcdui.Alert; 53 import javax.microedition.lcdui.AlertType; 54 import javax.microedition.lcdui.Canvas; 55 import javax.microedition.lcdui.Choice; 56 import javax.microedition.lcdui.ChoiceGroup; 57 import javax.microedition.lcdui.Command; 58 import javax.microedition.lcdui.CommandListener; 59 import javax.microedition.lcdui.DateField; 60 import javax.microedition.lcdui.Display; 61
