TestSnapshotControl.java

/*
 * Copyright © 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.*;

public class TestSnapshotControl extends TestControl {

    public TestSnapshotControl(CameraMIDlet cm) {
        super(cm);
        maxshots = 10;
        super.optionsForm.setTitle("Snapshot Control File Options");
        createCameraForm(super.midlet.snapshotcontrol);
        if (isSupported()) {
            CreateOptionsForm();
        }
    }

    public void CreateOptionsForm() {
        maxTF = new TextField("Max Shots (burst shoot only):", String.valueOf(maxshots), 4, 2);
        dirTF = new TextField("Directory:", super.snapControl.getDirectory(), 100, 0x80000);
        prefixTF = new TextField("Prefix: ", super.snapControl.getFilePrefix(), 100, 0x80000);
        suffixTF = new TextField("Suffix: ", super.snapControl.getFileSuffix(), 100, 0x80000);
        burstShootCG = new ChoiceGroup("Type of snapshots:", 1);
        burstShootCG.append("Burst shoot", null);
        burstShootCG.append("Freeze & Confirm", null);
        if (burstShooting) {
            burstShootCG.setSelectedIndex(0, true);
        }
        burstShootCG.setFont(0, Font.getFont(0, 0, 8));
        burstShootCG.setFont(1, Font.getFont(0, 0, 8));
        super.optionsForm.append(burstShootCG);
        super.optionsForm.append(maxTF);
        super.optionsForm.append(dirTF);
        super.optionsForm.append(prefixTF);
        super.optionsForm.append(suffixTF);
        super.optionsForm.addCommand(super.cmdBack);
        super.optionsForm.setCommandListener(this);
    }

    public void SaveOptions() {
        burstShooting = burstShootCG.getSelectedIndex() == 0;
        if (burstShooting) {
            maxshots = Integer.parseInt(maxTF.getString());
            setSnapshotNbr(maxshots);
        }
        try {
            super.snapControl.setDirectory(dirTF.getString());
        }
        catch (IllegalArgumentException e) {
            super.midlet.showAlert("IllegalArgumentException", "Chosen directory not supported", null);
        }
        try {
            super.snapControl.setFilePrefix(prefixTF.getString());
        }
        catch (IllegalArgumentException e) {
            super.midlet.showAlert("IllegalArgumentException", "Chosen prefix not supported", null);
        }
        try {
            super.snapControl.setFileSuffix(suffixTF.getString());
        }
        catch (IllegalArgumentException e) {
            super.midlet.showAlert("IllegalArgumentException", "Chosen suffix not supported", null);
        }
    }

    public boolean captureImage() {
        try {
            super.snapControl.start(super.snaps);
        }
        catch (SecurityException secExc) {
            midlet.showAlert("Security error", secExc.getMessage(), canvas);
            return false;
        }
        catch (Exception e) {
            midlet.showAlert("Error", e.getMessage(), canvas);
            return false;
        }
        return true;
    }

    public boolean showCapturedImageAfterCapture() {
        return false;
    }
    TextField prefixTF;
    TextField suffixTF;
    TextField dirTF;
    TextField maxTF;
    ChoiceGroup burstShootCG;
    boolean burstShooting;
    int maxshots;
}