package com.box.ui;
import javax.microedition.lcdui.*;
import javax.microedition.media.Manager;
import javax.microedition.media.MediaException;
import javax.microedition.media.Player;
import javax.microedition.media.control.VideoControl;
import com.box.MIDlet.MainWindow;
public class UpUI extends Canvas implements CommandListener {
private Display display;
private MainWindow m;
private Command backCommand = new Command(boxtext.back,Command.BACK,1);
private Command okCommand = new Command(boxtext.ok,Command.OK,1);
private Alert alert = null;
private boolean error = false;
public VideoControl videoControl = null;
public Player capturePlayer = null;
private byte[] data = null;
private Image image = null;
public UpUI(MainWindow p,Display d) {
m = p;
display = d;
//Player capturePlayer = null;
this.addCommand(backCommand);
this.addCommand(okCommand);
this.setCommandListener(this);
try {
capturePlayer = Manager.createPlayer("capture://video");
capturePlayer.realize();
// now create the canvas
} catch(Exception e) {
error(e);
}
try {
capturePlayer.start();
} catch(Exception e) { error(e); }
videoControl =
(VideoControl)capturePlayer.getControl(
"javax.microedition.media.control.VideoControl");
// if not present, throw error
// init display mode to use direct video and this canvas
videoControl.initDisplayMode(VideoControl.USE_DIRECT_VIDEO, this);
try { // try and set to full screen
videoControl.setDisplayFullScreen(true);
} catch(MediaException me) {
// but some devices may not support full screen mode
videoControl.setDisplayLocation(5, 5);
try {
videoControl.setDisplaySize(getWidth() - 10, getHeight() - 10);
} catch(Exception e) {}
}
// and make the video control visible
videoControl.setVisible(true);
videoControl.setDisplayLocation(5, 18);
}
void error(Exception e) {
alert.setString(e.getMessage());
alert.setTitle("Error");
display.setCurrent(alert);
e.printStackTrace();
error = true;
}
public void commandAction(Command cmd,Displayable displayable){
if(cmd == backCommand){
try {
capturePlayer.stop();
} catch (MediaException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
videoControl = null;
capturePlayer.close();
AppCanvas app = new AppCanvas(display,m);
display.setCurrent(app);
}
if(cmd == okCommand){
try {
capturePlayer.stop();
data = videoControl.getSnapshot(null);
videoControl = null;
capturePlayer.close();
} catch (MediaException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
sendPhoto send = new sendPhoto(m,display,data);
display.setCurrent(send);
// HttpThread thread = new HttpThread();
// thread.setData(videoControl);
// thread.start();
}
}
// public void keyPressed(int keyCode) {
// try {
// capturePlayer.stop();
//
// } catch(Exception e) { error(e); }
HttpThread thread = new HttpThread();
thread.setData(videoControl);
thread.start();
//
// }
protected void paint(Graphics g) {
// TODO Auto-generated method stub
g.setColor(0xffffff);
g.fillRect(0, 0, getWidth(), getHeight());
// and draw a rectangle with a different color
g.setColor(0x44ff66);
g.drawRect(0, 0, getWidth() - 10, getHeight() - 10);
}
}