TestFocusControl.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;
public class TestFocusControl extends TestControl {
public TestFocusControl(CameraMIDlet cm) {
super(cm);
super.optionsForm.setTitle("Focus Control Options");
createCameraForm(super.midlet.focuscontrol);
if (isSupported()) {
CreateOptionsForm();
}
}
public void CreateOptionsForm() {
focusModesCG = new ChoiceGroup("Focus Modes: ", 1);
macroCG = new ChoiceGroup("Macro Enabled: *NOT SUPPORTED*", 1);
macroCG.append("Enabled", null);
macroCG.append("Disabled", null);
manFocusTXT = new TextField("Manual Focus Distance", String.valueOf(super.focusControl.getFocus()), 10, 2);
if (!super.focusControl.isAutoFocusSupported()) {
focusModesCG.append("Auto Focus (not supported)", null);
}
else {
focusModesCG.append("Auto Focus", null);
}
if (!super.focusControl.isManualFocusSupported()) {
focusModesCG.append("Manual Focus (not supported)", null);
}
else {
focusModesCG.append("Manual Focus", null);
}
for (int i = 0; i < focusModesCG.size(); i++) {
focusModesCG.setFont(i, Font.getFont(0, 0, 8));
}
int focusmode = super.focusControl.getFocus();
if (focusmode != -1000) {
focusModesCG.setSelectedIndex(1, true);
}
super.optionsForm.append(focusModesCG);
if (super.focusControl.isManualFocusSupported()) {
super.optionsForm.append(manFocusTXT);
}
if (super.focusControl.isMacroSupported()) {
macroCG.setLabel("Macro Enabled:");
for (int i = 0; i < macroCG.size(); i++) {
macroCG.setFont(i, Font.getFont(0, 0, 8));
}
if (super.focusControl.getMacro()) {
macroCG.setSelectedIndex(0, true);
}
else {
macroCG.setSelectedIndex(1, true);
}
super.optionsForm.append(macroCG);
}
super.optionsForm.addCommand(super.cmdBack);
super.optionsForm.setCommandListener(this);
}
public void SaveOptions() {
try {
if (focusModesCG.getString(focusModesCG.getSelectedIndex()).equals("Auto Focus")) {
super.focusControl.setFocus(-1000);
}
else if (focusModesCG.getString(focusModesCG.getSelectedIndex()).equals("Manual Focus")) {
super.focusControl.setFocus(Integer.parseInt(manFocusTXT.getString()));
}
if (super.focusControl.isMacroSupported()) {
super.focusControl.setMacro(macroCG.getSelectedIndex() == 0);
}
super.midlet.showAlert("Options saved", "Options have been saved.", null);
}
catch (MediaException e) {
super.midlet.showAlert("MediaException", "Chosen mode not supported", null);
}
}
ChoiceGroup focusModesCG;
ChoiceGroup macroCG;
TextField manFocusTXT;
}