VideoCanvas.java
/**
* Copyright (c) 2012 Nokia Corporation. All rights reserved.
* Nokia and Nokia Connecting People are registered trademarks of Nokia Corporation.
* Oracle and Java are trademarks or registered trademarks of Oracle and/or its
* affiliates. Other product and company names mentioned herein may be trademarks
* or trade names of their respective owners.
* See LICENSE.TXT for license information.
*/
package com.nokia.example.ammscamera;
import javax.microedition.lcdui.*;
import javax.microedition.media.MediaException;
import javax.microedition.media.control.VideoControl;
public class VideoCanvas extends Canvas
implements CommandListener {
public VideoCanvas(TestControl tc, VideoControl vc, int key) {
setFullScreenMode(false);
testControl = tc;
videoControl = vc;
captureCmd = new Command("Capture", Command.OK, 0);
optionsCmd = new Command("Options", Command.SCREEN, 0);
backCmd = new Command("Back", Command.BACK, 1);
addCommand(captureCmd);
addCommand(optionsCmd);
addCommand(backCmd);
setCommandListener(this);
id = key;
update = false;
try {
videoControl.initDisplayMode(1, this);
videoControl.setDisplayFullScreen(true);
}
catch (IllegalArgumentException e) {
testControl.midlet.showAlert("Illegal Argument Exception", e.getMessage(), this);
}
catch (Exception e) {
testControl.midlet.showAlert("Exception", e.getMessage(), this);
}
videoControl.setVisible(true);
}
public void setDisplay() {
if (id != testControl.midlet.zoomcontrol) {
setFullScreenMode(false);
try {
videoControl.setDisplayFullScreen(true);
}
catch (MediaException e) {
e.printStackTrace();
}
}
}
protected void paint(Graphics g) {
if (videoControl != null) {
update = false;
}
}
protected void pointerPressed(int x, int y) {
capture();
}
public void commandAction(Command c, Displayable d) {
if (c.equals(backCmd)) {
exitVideoCanvas();
}
else if (c.equals(captureCmd)) {
capture();
}
else if (c.equals(optionsCmd)) {
showOptions();
}
}
protected void exitVideoCanvas() {
if (testControl.player != null) {
testControl.player.close();
}
CameraMIDlet.getDisplay().setCurrent(testControl.midlet.openMenu);
}
protected void capture() {
if (testControl.captureImage() && testControl.showCapturedImageAfterCapture()) {
testControl.showCapturedImage();
}
}
protected void showOptions() {
CameraMIDlet.getDisplay().setCurrent(testControl.optionsForm);
}
protected void zoomIn() {
testControl.zoomIn();
repaint();
}
protected void zoomOut() {
testControl.zoomOut();
repaint();
}
TestControl testControl;
VideoControl videoControl;
int id;
boolean update;
Command captureCmd;
Command optionsCmd;
Command backCmd;
}