Changeset 1469

Show
Ignore:
Timestamp:
11/15/08 08:45:38 (7 weeks ago)
Author:
czue
Message:

Adding an image sniffer that polls the contents of a directory and updates the chooser.

Location:
branches/dev/j2merosa/org.javarosa.media.image/src/org/javarosa/media/image
Files:
1 added
3 modified

Legend:

Unmodified
Added
Removed
  • branches/dev/j2merosa/org.javarosa.media.image/src/org/javarosa/media/image/activity/ImageCaptureActivity.java

    r1460 r1469  
    5555        private int width; 
    5656        private int height; 
     57        private String fullName; 
    5758         
    5859        public ImageCaptureActivity(IShell shell) { 
     
    6061                display = JavaRosaServiceProvider.instance().getDisplay(); 
    6162                dataModel = new FileRMSUtility("image_store"); 
    62                 width = 640; 
    63                 height = 480; 
     63                width = 960; 
     64                height = 720; 
    6465        } 
    6566 
     
    131132                // stick the picture in here.  
    132133                Hashtable table = new Hashtable(); 
    133                 BasicDataPointer p = new BasicDataPointer("Image", imageData); 
     134                FileDataPointer p = new FileDataPointer(fullName); 
     135                //BasicDataPointer p = new BasicDataPointer("Image", imageData); 
    134136                table.put(IMAGE_KEY, p); 
    135137                return table; 
     
    197199                        imageData = mVideoControl.getSnapshot("encoding=jpeg&quality=100&width=" + width + "&height=" + height); 
    198200                        //image = Image.createImage(jpg, 0, jpg.length); 
     201                        // Save to file no longer 
     202                        String fileName = "test" + System.currentTimeMillis(); 
     203                        fullName = saveFile(fileName + ".jpg", imageData); 
    199204                        doFinish(); 
    200                         // Save to file no longer 
    201                         //String fileName = "test" + System.currentTimeMillis(); 
    202                         //boolean saved = saveFile(fileName + ".jpg", jpg); 
     205                         
    203206                } catch (Exception me) { 
    204207                        handleException(me); 
     
    221224                        jpg = mVideoControl.getSnapshot("encoding=jpeg&quality=100&width=" + width + "&height=" + height); 
    222225                        String fileName = "test" + System.currentTimeMillis(); 
    223                         boolean saved = saveFile(fileName + ".jpg", jpg); 
     226                        boolean saved = saveFile(fileName + ".jpg", jpg) == ""; 
    224227                        if (saved) { 
    225228                                text += "Success!"; 
     
    247250        } 
    248251         
    249         private boolean saveFile(String filename, byte[] image) { 
     252        private String saveFile(String filename, byte[] image) { 
    250253                // TODO  
    251254                String rootName = FileUtility.getDefaultRoot(); 
     
    253256                FileUtility.createDirectory(restorepath); 
    254257                String fullName = restorepath + "/" + filename; 
    255                 System.out.println("Image saved."); 
    256                 return FileUtility.createFile(fullName, image); 
    257                 // not sure why this was being done twice 
     258                if (FileUtility.createFile(fullName, image)) { 
     259                        System.out.println("Image saved.");      
     260                        return fullName;         
     261                } else { 
     262                        return ""; 
     263                } 
     264                 
    258265        } 
    259266 
  • branches/dev/j2merosa/org.javarosa.media.image/src/org/javarosa/media/image/activity/ImageChooserActivity.java

    r1460 r1469  
    2020import org.javarosa.media.image.model.FileDataPointer; 
    2121import org.javarosa.media.image.storage.FileRMSUtility; 
     22import org.javarosa.media.image.utilities.ImageSniffer; 
    2223import org.javarosa.media.image.utilities.ImageUtility; 
    2324 
     
    4849        private Command markCommand; 
    4950        private String currentKey; 
     51        private Thread snifferThread; 
     52        private ImageSniffer sniffer; 
    5053 
    5154        public ImageChooserActivity(IShell shell) { 
     
    6770 
    6871        public void destroy() { 
    69                 // TODO Auto-generated method stub 
    70  
     72                sniffer.quit(); 
    7173        } 
    7274 
     
    8385                Object o = globalContext.getElement(currentKey); 
    8486                IDataPointer pointer = (IDataPointer) o; 
     87                addImageToUI(pointer); 
     88                updateView(); 
     89        } 
     90 
     91         
     92        private void updateView() { 
     93                display.setView(DisplayViewFactory.createView(mainForm)); 
     94        } 
     95 
     96        public void setShell(IShell shell) { 
     97                this.shell = shell; 
     98 
     99        } 
     100 
     101        public void start(Context context) { 
     102                this.context = context; 
     103                mainForm = new Form("Image Chooser"); 
     104                mainForm.addCommand(cancelCommand); 
     105                mainForm.addCommand(cameraCommand); 
     106                mainForm.addCommand(browseCommand); 
     107                mainForm.addCommand(returnCommand); 
     108                mainForm.addCommand(viewCommand); 
     109                mainForm.addCommand(markCommand); 
     110                mainForm.setCommandListener(this); 
     111 
     112                mainForm.append("Use the menu options to take pictures or browse."); 
     113               
     114                // also create the sniffer 
     115                sniffer = new ImageSniffer("file://localhost/root1/photos/", this); 
     116                snifferThread = new Thread(sniffer); 
     117                snifferThread.start(); 
     118                updateView(); 
     119        } 
     120         
     121        public synchronized void addImageToUI(IDataPointer pointer) { 
    85122                try { 
    86123                        if (pointer != null) {  
     
    95132                         
    96133                } 
    97                 display.setView(DisplayViewFactory.createView(mainForm)); 
    98         } 
    99  
    100         public void setShell(IShell shell) { 
    101                 this.shell = shell; 
    102  
    103         } 
    104  
    105         public void start(Context context) { 
    106                 this.context = context; 
    107                 mainForm = new Form("Image Chooser"); 
    108                 mainForm.addCommand(cancelCommand); 
    109                 mainForm.addCommand(cameraCommand); 
    110                 mainForm.addCommand(browseCommand); 
    111                 mainForm.addCommand(returnCommand); 
    112                 mainForm.addCommand(viewCommand); 
    113                 mainForm.addCommand(markCommand); 
    114                 mainForm.setCommandListener(this); 
    115  
    116                 display.setView(DisplayViewFactory.createView(mainForm)); 
    117  
    118         } 
     134        } 
     135 
    119136 
    120137        private FileDataPointer captureNewImage() { 
  • branches/dev/j2merosa/org.javarosa.media.image/src/org/javarosa/media/image/utilities/FileUtility.java

    r1460 r1469  
    6969        public static Enumeration listDirectory(String directoryPath) { 
    7070                FileConnection dir = null; 
     71                System.out.println("Listing the contents of: " + directoryPath); 
    7172                try { 
    7273                        dir = (FileConnection) Connector.open(directoryPath);