2 * Copyright 2007 ZXing authors
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.google.zxing.client.j2me;
19 import javax.microedition.amms.control.camera.ExposureControl;
20 import javax.microedition.amms.control.camera.FocusControl;
21 import javax.microedition.amms.control.camera.ZoomControl;
22 import javax.microedition.media.Controllable;
23 import javax.microedition.media.MediaException;
26 * <p>See {@link DefaultMultimediaManager} documentation for details.</p>
28 * <p>This class should never be directly imported or reference in the code.</p>
30 * @author Sean Owen (srowen@google.com)
32 final class AdvancedMultimediaManager implements MultimediaManager {
34 private static final int NO_ZOOM = 100;
35 private static final int MAX_ZOOM = 200;
36 private static final long FOCUS_TIME_MS = 750L;
37 private static final String DESIRED_METERING = "center-weighted";
39 public void setFocus(Controllable player) {
40 FocusControl focusControl = (FocusControl)
41 player.getControl("javax.microedition.amms.control.camera.FocusControl");
42 if (focusControl != null) {
44 if (focusControl.isMacroSupported() && !focusControl.getMacro()) {
45 focusControl.setMacro(true);
47 if (focusControl.isAutoFocusSupported()) {
48 focusControl.setFocus(FocusControl.AUTO);
50 Thread.sleep(FOCUS_TIME_MS); // let it focus...
51 } catch (InterruptedException ie) {
54 focusControl.setFocus(FocusControl.AUTO_LOCK);
56 } catch (MediaException me) {
62 public void setZoom(Controllable player) {
63 ZoomControl zoomControl = (ZoomControl) player.getControl("javax.microedition.amms.control.camera.ZoomControl");
64 if (zoomControl != null) {
65 // We zoom in if possible to encourage the viewer to take a snapshot from a greater distance.
66 // This is a crude way of dealing with the fact that many phone cameras will not focus at a
68 int maxZoom = zoomControl.getMaxOpticalZoom();
69 if (maxZoom > NO_ZOOM) {
70 zoomControl.setOpticalZoom(maxZoom > MAX_ZOOM ? MAX_ZOOM : maxZoom);
72 int maxDigitalZoom = zoomControl.getMaxDigitalZoom();
73 if (maxDigitalZoom > NO_ZOOM) {
74 zoomControl.setDigitalZoom(maxDigitalZoom > MAX_ZOOM ? MAX_ZOOM : maxDigitalZoom);
80 public void setExposure(Controllable player) {
81 ExposureControl exposureControl =
82 (ExposureControl) player.getControl("javax.microedition.amms.control.camera.ExposureControl");
83 if (exposureControl != null) {
85 int[] supportedISOs = exposureControl.getSupportedISOs();
86 if (supportedISOs != null && supportedISOs.length > 0) {
87 int maxISO = Integer.MIN_VALUE;
88 for (int i = 0; i < supportedISOs.length; i++) {
89 if (supportedISOs[i] > maxISO) {
90 maxISO = supportedISOs[i];
94 exposureControl.setISO(maxISO);
95 } catch (MediaException me) {
100 String[] supportedMeterings = exposureControl.getSupportedLightMeterings();
101 if (supportedMeterings != null) {
102 for (int i = 0; i < supportedMeterings.length; i++) {
103 if (DESIRED_METERING.equals(supportedMeterings[i])) {
104 exposureControl.setLightMetering(DESIRED_METERING);