TestFlashControl.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.*;
public class TestFlashControl extends TestControl {
public TestFlashControl(CameraMIDlet cm) {
super(cm);
super.optionsForm.setTitle("Flash Control Options");
createCameraForm(super.midlet.flashcontrol);
if (isSupported()) {
CreateOptionsForm();
}
}
public void CreateOptionsForm() {
try {
flashModesCG = new ChoiceGroup("Flash Modes: ", 1);
int flashstr[] = super.flashControl.getSupportedModes();
int mode = super.flashControl.getMode();
String str = "";
for (int i = 0; i < flashstr.length; i++) {
switch (flashstr[i]) {
case 1: // '\001'
str = "OFF";
flashModesCG.append(str, null);
break;
case 5: // '\005'
str = "FORCE_WITH_REDEYEREDUCE";
flashModesCG.append(str, null);
break;
case 4: // '\004'
str = "FORCE";
flashModesCG.append(str, null);
break;
case 6: // '\006'
str = "FILLIN";
flashModesCG.append(str, null);
break;
case 3: // '\003'
str = "AUTO_WITH_REDEYEREDUCE";
flashModesCG.append(str, null);
break;
case 2: // '\002'
str = "AUTO";
flashModesCG.append(str, null);
break;
}
flashModesCG.setFont(i, Font.getFont(0, 0, 8));
flashModesCG.set(i, str, null);
if (mode == flashstr[i]) {
flashModesCG.setSelectedIndex(i, true);
}
}
super.optionsForm.append(flashModesCG);
super.optionsForm.addCommand(super.cmdBack);
super.optionsForm.setCommandListener(this);
}
catch (NullPointerException e) {
super.midlet.showAlert("Flash not supported", "Phone does not support AMMS flash", null);
}
}
public void SaveOptions() {
try {
super.midlet.showAlert("Options saved", "Options have been saved.", super.canvas);
String tmp = flashModesCG.getString(flashModesCG.getSelectedIndex());
if (tmp.equals("OFF")) {
super.flashControl.setMode(1);
}
else if (tmp.equals("AUTO")) {
super.flashControl.setMode(2);
}
else if (tmp.equals("AUTO_WITH_REDEYEREDUCE")) {
super.flashControl.setMode(3);
}
else if (tmp.equals("FORCE")) {
super.flashControl.setMode(4);
}
else if (tmp.equals("FORCE_WITH_REDEYEREDUCE")) {
super.flashControl.setMode(5);
}
else if (tmp.equals("FILLIN")) {
super.flashControl.setMode(6);
}
}
catch (IllegalArgumentException e) {
super.midlet.showAlert("IllegalArgumentException", "Chosen mode not supported", null);
}
}
ChoiceGroup flashModesCG;
}