Changeset 1567 for bundle


Ignore:
Timestamp:
03/29/07 17:24:43 (13 years ago)
Author:
laszlo
Message:

refs #1144 spent 96h
Without video recording support.

Location:
bundle/LeMidlet/src/org/lemill/lemidlet
Files:
8 added
2 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • bundle/LeMidlet/src/org/lemill/lemidlet/LeMidlet.java

    r1168 r1567  
    55 
    66import org.lemill.lemidlet.configure.ConfiguratorForm; 
     7import org.lemill.lemidlet.filesending.FileBrowserList; 
    78import org.lemill.lemidlet.imagecapture.CameraCanvas; 
    89import org.lemill.lemidlet.imagecapture.ImageCanvas; 
    9 import org.lemill.lemidlet.imagecapture.ImagePropertiesForm; 
    10 import org.lemill.lemidlet.imagecapture.ImageSenderForm; 
     10import org.lemill.lemidlet.soundrecording.AudioCanvas; 
     11import org.lemill.lemidlet.utils.CapabilityDetector; 
    1112import org.lemill.lemidlet.utils.ControlFlowManager; 
     13import org.lemill.lemidlet.utils.HTTPSenderForm; 
     14import org.lemill.lemidlet.utils.MessageBox; 
    1215import org.lemill.lemidlet.utils.NullStateListener; 
    13  
     16import org.lemill.lemidlet.utils.PropertiesForm; 
    1417 
    1518public class LeMidlet extends MIDlet implements NullStateListener { 
     
    2124    private CameraCanvas cameraCanvas; 
    2225    private ImageCanvas imageCanvas;     
    23     private ImagePropertiesForm imageProperties; 
    24     private ImageSenderForm imageSender; 
     26    private PropertiesForm imageProperties; 
     27    private HTTPSenderForm imageSender; 
     28    private FileBrowserList fileBrowser; 
     29    private PropertiesForm fileProperties; 
     30    private HTTPSenderForm fileSender; 
     31 
     32    private AudioCanvas audioCanvas; 
     33 
     34    private PropertiesForm audioProperties; 
     35 
     36    private HTTPSenderForm audioSender; 
    2537     
    2638    public LeMidlet() { 
    2739        flowManager = new ControlFlowManager(this, this); 
    28         mainList = new MainList(flowManager); 
    29         configurator = new ConfiguratorForm(this, flowManager); 
    30         imageCanvas = new ImageCanvas(flowManager); 
    31         cameraCanvas = new CameraCanvas(this, flowManager, imageCanvas); 
    32         imageProperties = new ImagePropertiesForm(flowManager); 
    33         imageSender = new ImageSenderForm(this, flowManager, configurator, imageCanvas, imageProperties); 
    34         setupControlFlow(); 
     40        if(CapabilityDetector.getInstance().getMMAPIVersion() == null) { 
     41            MessageBox.ShowError(this, flowManager, "Your device dose not support MMAPI, which is required by LeMidlet!"); 
     42            return; 
     43        }  
     44        if( 
     45                CapabilityDetector.getInstance().getSupporterdImageEncodings().isEmpty() && 
     46                CapabilityDetector.getInstance().getAvailableAudioFormats().isEmpty() && 
     47                CapabilityDetector.getInstance().getAvailableVideoFormats().isEmpty() && 
     48                CapabilityDetector.getInstance().getFCAPIVersion() == null 
     49        ) { 
     50            MessageBox.ShowError(this, flowManager, "Your device dose not support any feature of LeMidlet!"); 
     51            return;          
     52        } 
     53        setupControlFlow();              
    3554    } 
    3655     
    3756    private void setupControlFlow() { 
     57         
     58        // MAIN LIST 
     59         
     60        mainList = new MainList(this, flowManager); 
    3861        flowManager.setNextItem(null, mainList, ""); 
     62        flowManager.setNextItem(mainList, null, "VOICE"); 
    3963        flowManager.setNextItem(mainList, null, "EXIT"); 
    40         flowManager.setNextItem(mainList, cameraCanvas, "PICTURE"); 
    41         flowManager.setNextItem(mainList, null, "VOICE"); 
     64 
     65        // CONFIGURATOR 
     66         
     67        configurator = new ConfiguratorForm(this, flowManager);      
    4268        flowManager.setNextItem(mainList, configurator, "OPTIONS"); 
    4369        flowManager.setNextItem(configurator, mainList, "OK"); 
    4470        flowManager.setNextItem(configurator, mainList, "EXIT");     
    45         flowManager.setNextItem(cameraCanvas, imageCanvas, "SNAPSHOT"); 
    46         flowManager.setNextItem(cameraCanvas, mainList, "EXIT"); 
    47         flowManager.setNextItem(imageCanvas, imageProperties, "OK"); 
    48         flowManager.setNextItem(imageProperties, imageSender, "OK"); 
    49         flowManager.setNextItem(imageSender, cameraCanvas, "FINISHED"); 
     71     
     72        // CAPTURE IMAGE 
     73         
     74        if(!CapabilityDetector.getInstance().getSupporterdImageEncodings().isEmpty()) { 
     75            imageCanvas = new ImageCanvas(flowManager); 
     76            cameraCanvas = new CameraCanvas(this, flowManager, imageCanvas); 
     77            imageProperties = new PropertiesForm(flowManager); 
     78            imageSender = new HTTPSenderForm(this, flowManager, configurator, imageCanvas, imageProperties); 
     79            flowManager.setNextItem(mainList, cameraCanvas, "PICTURE"); 
     80            flowManager.setNextItem(cameraCanvas, imageCanvas, "SNAPSHOT"); 
     81            flowManager.setNextItem(cameraCanvas, mainList, "EXIT"); 
     82            flowManager.setNextItem(imageCanvas, imageProperties, "OK"); 
     83            flowManager.setNextItem(imageProperties, imageSender, "OK"); 
     84            flowManager.setNextItem(imageSender, cameraCanvas, "FINISHED"); 
     85        } 
     86         
     87        // SEND FILE 
     88         
     89        if(CapabilityDetector.getInstance().getFCAPIVersion() != null) { 
     90            fileBrowser = new FileBrowserList(this, flowManager); 
     91            fileProperties = new PropertiesForm(flowManager);        
     92            fileSender = new HTTPSenderForm(this, flowManager, configurator, fileBrowser, fileProperties); 
     93            flowManager.setNextItem(mainList, fileBrowser, "SEND_FILE"); 
     94            flowManager.setNextItem(fileBrowser, fileProperties, "OK"); 
     95            flowManager.setNextItem(fileProperties, fileSender, "OK"); 
     96            flowManager.setNextItem(fileSender, fileBrowser, "FINISHED"); 
     97            flowManager.setNextItem(fileBrowser, mainList, "EXIT"); 
     98        } 
     99         
     100        // CAPTURE AUDIO 
     101         
     102        if(!CapabilityDetector.getInstance().getAvailableAudioFormats().isEmpty()) { 
     103            audioCanvas = new AudioCanvas(this, flowManager); 
     104            audioProperties = new PropertiesForm(flowManager);       
     105            audioSender = new HTTPSenderForm(this, flowManager, configurator, audioCanvas, audioProperties); 
     106            flowManager.setNextItem(mainList, audioCanvas, "RECORD_AUDIO"); 
     107            flowManager.setNextItem(audioCanvas, audioProperties, "OK"); 
     108            flowManager.setNextItem(audioProperties, audioSender, "OK"); 
     109            flowManager.setNextItem(audioSender, audioCanvas, "FINISHED"); 
     110            flowManager.setNextItem(audioCanvas, mainList, "EXIT"); 
     111        } 
     112     
    50113    } 
    51114     
  • bundle/LeMidlet/src/org/lemill/lemidlet/MainList.java

    r1168 r1567  
    11package org.lemill.lemidlet; 
     2 
     3import java.util.Hashtable; 
    24 
    35import javax.microedition.lcdui.Command; 
     
    57import javax.microedition.lcdui.Displayable; 
    68import javax.microedition.lcdui.List; 
     9import javax.microedition.midlet.MIDlet; 
    710 
     11import org.lemill.lemidlet.utils.CapabilityDetector; 
    812import org.lemill.lemidlet.utils.ControlFlowManager; 
    913 
     
    1317     
    1418    private ControlFlowManager flowManager;  
    15          
    16     public MainList(ControlFlowManager flowManager) { 
    17         super("LeMidlet", List.IMPLICIT, new String[]{"Take picture", /*"Record audio",*/ "Configure..."}, null); 
     19     
     20    private Hashtable menuActions = new Hashtable(); 
     21     
     22    public MainList(MIDlet midlet, ControlFlowManager flowManager) { 
     23        super("LeMidlet", List.IMPLICIT, new String[]{}, null); 
    1824        this.flowManager = flowManager; 
     25        buildMenu(); 
    1926        addCommand(ExitCommand); 
    2027        setCommandListener(this); 
    2128    } 
    2229 
     30    public void buildMenu() { 
     31        int i=0; 
     32        if(!CapabilityDetector.getInstance().getSupporterdImageEncodings().isEmpty()) { 
     33            this.append("Take picture", null); 
     34            menuActions.put(new Integer(i), "PICTURE"); 
     35            i++; 
     36        } 
     37        if(!CapabilityDetector.getInstance().getAvailableAudioFormats().isEmpty()) { 
     38            this.append("Record audio", null); 
     39            menuActions.put(new Integer(i), "RECORD_AUDIO"); 
     40            i++; 
     41        } 
     42        /* 
     43        if(!CapabilityDetector.getInstance().getAvailableVideoFormats().isEmpty()) { 
     44            this.append("Record video", null); 
     45            menuActions.put(new Integer(i), "RECORD_VIDEO"); 
     46            i++; 
     47        } 
     48        */ 
     49        if(CapabilityDetector.getInstance().getFCAPIVersion() != null) { 
     50            this.append("Send file", null); 
     51            menuActions.put(new Integer(i), "SEND_FILE"); 
     52            i++; 
     53        } 
     54        this.append("Configure...", null); 
     55        menuActions.put(new Integer(i), "OPTIONS"); 
     56    } 
     57     
    2358    public void commandAction(Command command, Displayable item) { 
    2459        if(command == ExitCommand) 
    2560            flowManager.gotoNextItem(this, "EXIT"); 
    2661        if(command == SELECT_COMMAND) { 
    27             if(getSelectedIndex() == 0) 
    28                 flowManager.gotoNextItem(this, "PICTURE"); 
    29             //if(getSelectedIndex() == 1) 
    30             //  flowManager.gotoNextItem(this, "VOICE"); 
    31             if(getSelectedIndex() == 1) 
    32                 flowManager.gotoNextItem(this, "OPTIONS"); 
     62            String action = (String)menuActions.get(new Integer(getSelectedIndex())); 
     63            flowManager.gotoNextItem(this, action);          
    3364        } 
    3465    } 
  • bundle/LeMidlet/src/org/lemill/lemidlet/configure/ConfiguratorForm.java

    r1168 r1567  
    1515public class ConfiguratorForm extends Form implements CommandListener { 
    1616 
    17     private TextField urlField = new TextField("Server: ", "195.111.2.146", 128, TextField.URL); 
    18     private TextField baseField = new TextField("LeMill base: ", "lemill", 128, TextField.URL); 
     17    private TextField urlField = new TextField("URL: ", "lemill.net", 128, TextField.URL); 
    1918    private TextField userField = new TextField("User name: ", "", 64, TextField.ANY); 
    2019    private TextField passwordField = new TextField("Password: ", "", 64, TextField.PASSWORD); 
     
    4140        } 
    4241        append(urlField); 
    43         append(baseField); 
    4442        append(userField); 
    4543        append(passwordField); 
     
    5351            String[] fields = recordStoreManager.load(); 
    5452            urlField.setString(fields[0]); 
    55             baseField.setString(fields[1]); 
    56             userField.setString(fields[2]); 
    57             passwordField.setString(fields[3]); 
     53            userField.setString(fields[1]); 
     54            passwordField.setString(fields[2]); 
    5855        } catch (Exception e) { 
    5956            MessageBox.Show(midlet, "Error", e.getMessage(), AlertType.ERROR); 
     
    6360     
    6461    private void saveFields() { 
    65         String[] fields = new String[4]; 
     62        String[] fields = new String[3]; 
    6663        fields[0] = urlField.getString(); 
    67         fields[1] = baseField.getString(); 
    68         fields[2] = userField.getString(); 
    69         fields[3] = passwordField.getString();           
     64        fields[1] = userField.getString(); 
     65        fields[2] = passwordField.getString();           
    7066        try { 
    7167            recordStoreManager.save(fields); 
     
    8682        return passwordField.getString(); 
    8783    } 
    88      
    89     public String getServerBase() { 
    90         return baseField.getString(); 
    91     } 
    92      
     84         
    9385    public void commandAction(Command command, Displayable item) { 
    9486        if(command == OKCommand) { 
  • bundle/LeMidlet/src/org/lemill/lemidlet/imagecapture/CameraCanvas.java

    r1168 r1567  
    6464            } 
    6565            player.realize(); 
    66             videoControl = (VideoControl) (player.getControl("VideoControl")); 
     66            videoControl = (VideoControl) (player.getControl("VideoControl"));           
    6767            if (videoControl == null) { 
    6868                destroyPlayer(); 
     
    135135    } 
    136136 
    137     private void snapshotTaken(byte[] imageData, String snapshotImageType) { 
    138         imageCanvas.setImage(imageData, snapshotImageType); 
     137    private void snapshotTaken(byte[] imageData, String snapshotImageType, String contentType) { 
     138        imageCanvas.setImage(imageData, snapshotImageType, contentType); 
    139139        flowManager.gotoNextItem(this, "SNAPSHOT"); 
    140140    } 
     
    151151                        if (JPEGSupported) { 
    152152                            snapshotTaken(videoControl 
    153                                     .getSnapshot("encoding=jpeg"), "jpeg"); 
     153                                    .getSnapshot("encoding=jpeg"), "jpeg", "image/jpeg"); 
    154154                        } else { 
    155155                            snapshotTaken(videoControl 
    156                                     .getSnapshot("encoding=png"), "png"); 
     156                                    .getSnapshot("encoding=png"), "png", "image/png"); 
    157157                        }    
    158158                    } catch (MediaException e) { 
  • bundle/LeMidlet/src/org/lemill/lemidlet/imagecapture/ImageCanvas.java

    r1168 r1567  
    1010import javax.microedition.lcdui.Image; 
    1111 
     12import org.lemill.lemidlet.utils.Content; 
    1213import org.lemill.lemidlet.utils.ControlFlowManager; 
    1314 
    14 public class ImageCanvas extends Canvas implements CommandListener { 
     15public class ImageCanvas extends Canvas implements CommandListener, Content { 
    1516 
    1617    private Image image; 
    1718    private byte[] imageData; 
    1819    private String imageType; 
     20    private String contentType; 
    1921    private ControlFlowManager flowManager; 
    20  
    21     //private Command sendCommand = new Command("Send", Command.OK, 1); 
    2222     
    2323    private Command okCommand = new Command("OK", Command.OK, 1); 
     
    2929    } 
    3030     
    31     public void setImage(byte[] imageData, String imageType) { 
     31    public void setImage(byte[] imageData, String imageType, String contentType) { 
    3232        this.image = Image.createImage(imageData, 0, imageData.length); 
    3333        this.imageData = imageData; 
    3434        this.imageType = imageType; 
     35        this.contentType = contentType; 
    3536    } 
    3637     
     
    4849        g.drawImage(image, x, y, Graphics.TOP | Graphics.LEFT); 
    4950    } 
    50  
    51     public String getImageType() { 
    52         return imageType; 
    53     } 
    54      
    55     public byte[] getImageData() { 
    56         return imageData; 
    57     } 
    58      
     51         
    5952    public void commandAction(Command command, Displayable item) { 
    60         /* 
    61         if(command == sendCommand) { 
    62             //new HTTPSender(midlet).sendFile("http://elibrary.hu/upload.php", this.imageData, "test." + this.imageType, "test", "test"); 
    63             HTTPSenderForm sender = new HTTPSenderForm("Send Image", midlet); 
    64             Display.getDisplay(midlet).setCurrent(sender); 
    65             sender.sendFile("http://elibrary.hu/upload.php", this.imageData, "test." + this.imageType, "test", "test", flowManager, this, "FINISHED"); 
    66         } 
    67         */ 
    6853        if(command == okCommand) { 
    6954            flowManager.gotoNextItem(this, "OK"); 
     
    7156    } 
    7257 
     58    public String getContentType() { 
     59        return contentType; 
     60    } 
     61 
     62    public byte[] getData() { 
     63        return imageData;    
     64    } 
     65 
     66    public String getFileExt() { 
     67        return imageType; 
     68    } 
     69 
    7370} 
  • bundle/LeMidlet/src/org/lemill/lemidlet/utils/ControlFlowManager.java

    r1168 r1567  
    5959    } 
    6060     
     61    public void exit() { 
     62        nsListener.onNullState(); 
     63    } 
    6164} 
  • bundle/LeMidlet/src/org/lemill/lemidlet/utils/MessageBox.java

    r1168 r1567  
    33import javax.microedition.lcdui.Alert; 
    44import javax.microedition.lcdui.AlertType; 
     5import javax.microedition.lcdui.Command; 
     6import javax.microedition.lcdui.CommandListener; 
    57import javax.microedition.lcdui.Display; 
     8import javax.microedition.lcdui.Displayable; 
     9import javax.microedition.lcdui.Form; 
     10import javax.microedition.lcdui.StringItem; 
    611import javax.microedition.midlet.MIDlet; 
    712 
     
    1217        Alert alert = new Alert(title, msg, null, type); 
    1318        alert.setTimeout(Alert.FOREVER); 
    14         Display.getDisplay(midlet).setCurrent(alert); 
     19        Display.getDisplay(midlet).setCurrent(alert); 
     20    } 
     21     
     22    public static void ShowError(MIDlet midlet, final ControlFlowManager flowManager, String msg) { 
     23        Form alert = new Form("Error"); 
     24        alert.append(new StringItem("Error: ", msg)); 
     25        alert.addCommand(new Command("Exit", Command.EXIT, 1)); 
     26        alert.setCommandListener(new CommandListener() { 
     27            public void commandAction(Command command, Displayable item) { 
     28                flowManager.exit(); 
     29            } 
     30        }); 
     31        Display.getDisplay(midlet).setCurrent(alert);        
    1532    } 
    1633     
  • bundle/LeMidlet/src/org/lemill/lemidlet/utils/RecordStoreManager.java

    r1168 r1567  
    3333        int i; 
    3434        for(i=1; i<=store.getNumRecords(); i++) { 
    35             System.out.println("readed: " + i); 
    3635            byte[] dataBytes = store.getRecord(i); 
    3736            if(dataBytes == null) 
Note: See TracChangeset for help on using the changeset viewer.