TestZoomControl.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 TestZoomControl extends TestControl {
public TestZoomControl(CameraMIDlet cm) {
super(cm);
super.optionsForm.setTitle("Zoom Control Options");
createCameraForm(super.midlet.zoomcontrol);
if (isSupported()) {
CreateOptionsForm();
}
}
public void CreateOptionsForm() {
String zoomDigSuppModes[] = new String[super.zoomControl.getDigitalZoomLevels()];
int zoomDigModesInt[] = new int[super.zoomControl.getDigitalZoomLevels()];
super.zoomControl.setDigitalZoom(100);
for (int i = 0; i < zoomDigSuppModes.length; i++) {
zoomDigModesInt[i] = super.zoomControl.getDigitalZoom();
zoomDigSuppModes[i] = ZoomToStr(zoomDigModesInt[i]);
super.zoomControl.setDigitalZoom(-1001);
}
super.zoomControl.setDigitalZoom(100);
digZoomCG = new ChoiceGroup("Digital Zoom Level", 1);
for (int i = 0; i < zoomDigSuppModes.length; i++) {
if (zoomDigModesInt[i] % 100 == 0) {
digZoomCG.append(zoomDigSuppModes[i], null);
}
}
String zoomOptSuppModes[] = new String[super.zoomControl.getOpticalZoomLevels()];
int zoomOptModesInt[] = new int[zoomOptSuppModes.length];
super.zoomControl.setOpticalZoom(100);
for (int i = 0; i < zoomOptSuppModes.length; i++) {
zoomOptModesInt[i] = super.zoomControl.getOpticalZoom();
zoomOptSuppModes[i] = ZoomToStr(zoomOptModesInt[i]);
super.zoomControl.setOpticalZoom(-1001);
}
optZoomCG = new ChoiceGroup("Optical Zoom ", 1, zoomOptSuppModes, null);
String note = "***\n To zoom in and out between dig. zoom levels while in camera mode, press the left and right soft keys \n***";
super.optionsForm.append(digZoomCG);
super.optionsForm.append(optZoomCG);
super.optionsForm.addCommand(super.cmdBack);
super.optionsForm.append(note);
super.optionsForm.setCommandListener(this);
}
public String ZoomToStr(int z) {
String ret = String.valueOf(z);
if (z % 100 == 0) {
ret = String.valueOf(z / 100) + "x";
}
else {
ret = String.valueOf(z / 100) + "." + String.valueOf(z % 100) + "x";
}
return ret;
}
public int ZoomToInt(String str) {
int tmp = str.indexOf("x");
return Integer.parseInt(str.substring(0, tmp)) * 100;
}
public void SaveOptions() {
try {
if (digZoomCG.size() > 0) {
super.zoomControl.setDigitalZoom(ZoomToInt(digZoomCG.getString(digZoomCG.getSelectedIndex())));
}
if (optZoomCG.size() > 0) {
super.zoomControl.setOpticalZoom(ZoomToInt(optZoomCG.getString(optZoomCG.getSelectedIndex())));
}
super.midlet.showAlert("Options saved", "Options have been saved.", super.canvas);
}
catch (IllegalArgumentException e) {
super.midlet.showAlert("IllegalArgumentException", "Chosen mode not supported", super.optionsForm);
}
}
ChoiceGroup digZoomCG;
ChoiceGroup optZoomCG;
}