📄 filetransfer.java.svn-base
字号:
public void commandAction(Command c, Displayable d) { if (JimmUI.isControlActive(tlWebAsk) && (c == JimmUI.cmdSelect)) { int index = tlWebAsk.getCurrTextIndex(); switch (index) { case WEB_ASK_RESULT_NO: case WEB_ASK_RESULT_YES: Options.setInt(Options.OPTION_FT_MODE, (index == WEB_ASK_RESULT_NO) ? Options.FS_MODE_NET : Options.FS_MODE_WEB); Options.setBoolean(Options.OPTION_ASK_FOR_WEB_FT, false); Options.safeSave(); startFtInternal(); return; default: return; } } else if ((alert != null) && (d == alert)) { JimmUI.backToLastScreen(); } else if ((fileSystem != null) && fileSystem.isActive()) { if (c == JimmUI.cmdOk) { curMode = MODE_CHECK_FILE_LEN; fileName = fileSystem.getValue(); new Thread(this).start(); } else { free(); JimmUI.backToLastScreen(); } } else { if (c == this.okCommand) { if (d == this.name_Desc) { switch (Options.getInt(Options.OPTION_FT_MODE)) { case Options.FS_MODE_NET: this.initFT(this.fileNameField.getString(), this.descriptionField.getString()); break; case Options.FS_MODE_WEB: JimmUI.backToLastScreen(); // SplashCanvas.setProgress(0);// SplashCanvas.setMessage(ResourceBundle.getString("init_ft"));// SplashCanvas.removeCmd(SplashCanvas.cancelCommand);// SplashCanvas.setCmdListener(this);// SplashCanvas.show(); fileName = this.fileNameField.getString(); description = this.descriptionField.getString(); String[] fnItems = Util.explode(fileName, '/'); shortFileName = (fnItems.length == 0) ? fileName : fnItems[fnItems.length-1]; curMode = MODE_SEND_THROUGH_WEB; new Thread(this).start(); break; } } } else if (c == this.backCommand || c == SplashCanvas.cancelCommand) { free(); JimmUI.backToLastScreen(); } } } private void free() { //#sijapp cond.if target isnot "MOTOROLA" # vf = null; //#sijapp cond.end # try { if (fis != null) fis.close(); } catch (Exception e) {} // Do nothing try { if (fileSystem != null) fileSystem.close(); } catch (Exception e) {} // Do nothing fileSystem = null; fis = null; name_Desc = null; fileNameField = null; descriptionField = null; System.gc(); } /** ************************************************************************* */ /** ************************************************************************* */ /** ************************************************************************* */ //#sijapp cond.if target isnot "MOTOROLA" # // Class for viewfinder public class ViewFinder extends Canvas implements CommandListener { // Variables private Player p = null; private VideoControl vc = null; private boolean active = false; private boolean viewfinder = true; private Image img; private byte[] data; private int sourceWidth = 0; private int sourceHeight = 0; private String encoding = null; private String extension = "jpeg"; // Commands private Command backCommand; private Command okCommand; public ViewFinder() { backCommand = new Command(ResourceBundle.getString("back"), Jimm.cmdBack, 2); okCommand = new Command(ResourceBundle.getString("ok"), Command.SCREEN, 1); this.addCommand(backCommand); this.addCommand(okCommand); this.setCommandListener(this); } private void reset() { img = null; if (vc != null) { vc.setVisible(false); vc = null; } if (p != null) { try { if (p.getState() == Player.STARTED) p.stop(); p.deallocate(); p.close(); } catch (Exception e) { } p = null; } System.gc(); } // paint method, inherid form Canvas protected void paint(Graphics g) { g.setColor(0xffffffff); g.fillRect(0, 0, this.getWidth(), this.getHeight()); if (!viewfinder && (img != null)) { g.drawImage(img, getWidth() / 2, getHeight() / 2, Graphics.VCENTER | Graphics.HCENTER); // System.out.println("drawedImage"); } g.setColor(0x00000000); if (viewfinder) g.drawString(ResourceBundle.getString("viewfinder") + " " + (getWidth()-2) + "x" + (getHeight()-2), 1, 1, Graphics.TOP | Graphics.LEFT); else g.drawString(ResourceBundle.getString("send_img") + "? " + sourceWidth + "x" + sourceHeight, 1, 1, Graphics.TOP | Graphics.LEFT); } // start the viewfinder public synchronized void start() { reset(); if (!active) { try { //#sijapp cond.if modules_DEBUGLOG is "true" # String contentTypes[]=Manager.getSupportedContentTypes("capture"); DebugLog.addText(">>" + "capture" + "<<"); for (int i = 0; i < contentTypes.length; i++) DebugLog.addText(contentTypes[i]); //#sijapp cond.end# String cam_dev = "capture://image"; try { p = Manager.createPlayer(cam_dev); } catch (Exception mxe) { cam_dev = "capture://video"; p = Manager.createPlayer(cam_dev); } p.realize(); int curRes = Options.getInt(Options.OPTION_CAMERA_RES); int curEnc = Options.getInt(Options.OPTION_CAMERA_ENCODING); encoding = null; int key1 = 0; int key2 = 0; String[] imageTypes = Util.explode(System.getProperty("video.snapshot.encodings"), ' '); String tmp = ""; String[] params; String[] values; String width; String height; for (int i = 0; i < imageTypes.length; i++) { params = Util.explode(imageTypes[i], '&'); width = null; height = null; for (int j = 0; j < params.length; j++) { values = Util.explode(params[j], '='); if (values[0].equals("encoding")) { if (Util.strCountOccur(tmp, values[1]) == 0){ if (key1 == curEnc) { encoding = "encoding="+values[1]; extension = values[1]; } tmp += values[1]; key1++; } } else if (values[0].equals("width")) { width = values[1]; } else if (values[0].equals("height")) { height = values[1]; } } if ((width != null) && (height != null)) { if (key2 == curRes) { encoding += "&" + "width=" + width + "&" + "height=" + height; break; } key2++; } } // Get the video control vc = (VideoControl) p.getControl("VideoControl"); if (vc != null) { vc.initDisplayMode(VideoControl.USE_DIRECT_VIDEO, this); int canvasWidth = this.getWidth(); int canvasHeight = this.getHeight(); try { vc.setDisplayLocation(2, 2); vc.setDisplaySize(canvasWidth - 4, canvasHeight - 4); } catch (MediaException me) { try { vc.setDisplayFullScreen(true); } catch (MediaException me2) {} } vc.setVisible(true); p.start(); active = true; } else { JimmException.handleException(new JimmException(180, 0, true)); } } catch (IOException ioe) { reset(); JimmException.handleException(new JimmException(181, 0, true)); } catch (MediaException me) { reset(); JimmException.handleException(new JimmException(181, 1, true)); } catch (SecurityException se) { reset(); JimmException.handleException(new JimmException(181, 2, true)); } } } private byte[] getSnapshot(String type) { byte[] data; try { data = vc.getSnapshot(type); } catch (Exception e) { return null; } return data; } // take a snapshot form the viewfinder public void takeSnapshot() { if (p != null) { //#sijapp cond.if modules_DEBUGLOG is "true" # DebugLog.addText (encoding); //#sijapp cond.end# data = getSnapshot(encoding); if (data == null) data = getSnapshot("JPEG"); if (data == null) data = getSnapshot(null); if (data == null) JimmException.handleException(new JimmException(183, 0, true)); img = Image.createImage(data, 0, data.length); sourceWidth = img.getWidth(); sourceHeight = img.getHeight(); img = Util.createThumbnail(img, this.getWidth(), this.getHeight()); viewfinder = false; vc.setVisible(false); repaint(); } } // stop the viewfinder public synchronized void stop() { if (active) { try { vc.setVisible(false); p.stop(); } catch (Exception e) { reset(); } active = false; } } // action listener public void commandAction(Command c, Displayable d) { if (c == this.okCommand) { if (!viewfinder) { this.stop(); this.reset(); FileTransfer.this.setData(new ByteArrayInputStream(data), data.length); FileTransfer.this.askForNameDesc("jimm_cam_" + Util.getDateString(false,Util.createCurrentDate(true)) + "_" + Util.getCounter() + "." + extension, ""); } else this.takeSnapshot(); } else if (c == this.backCommand) { if (!viewfinder) { viewfinder = true; active = false; start(); } else { this.stop(); this.reset(); JimmUI.backToLastScreen(); FileTransfer.this.vf = null; } } } // Key pressed public void keyPressed(int keyCode) { if (getGameAction(keyCode) == FIRE) if (!viewfinder) { this.stop(); this.reset(); FileTransfer.this.setData(new ByteArrayInputStream(data), data.length); FileTransfer.this.askForNameDesc("jimm_cam_" + Util.getDateString(false,Util.createCurrentDate(true)) + "_" + Util.getCounter() + ".jpeg", ""); } else { this.takeSnapshot(); } } } //#sijapp cond.end #}//#sijapp cond.end#
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -