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>Implementation suitable for JSR-234 phones which takes advantage of advanced camera
29 * @author Sean Owen (srowen@google.com)
31 final class AdvancedMultimediaManager implements MultimediaManager {
33 private static final int NO_ZOOM = 100;
34 private static final int MAX_ZOOM = 200;
35 private static final long FOCUS_TIME_MS = 750L;
36 private static final String DESIRED_METERING = "center-weighted";
38 AdvancedMultimediaManager() {
41 public void setFocus(Controllable player) {
42 FocusControl focusControl = (FocusControl)
43 player.getControl("javax.microedition.amms.control.camera.FocusControl");
44 if (focusControl == null) {
45 focusControl = (FocusControl) player.getControl("FocusControl");
47 if (focusControl != null) {
49 if (focusControl.isMacroSupported() && !focusControl.getMacro()) {
50 focusControl.setMacro(true);
52 if (focusControl.isAutoFocusSupported()) {
53 focusControl.setFocus(FocusControl.AUTO);
55 Thread.sleep(FOCUS_TIME_MS); // let it focus...
56 } catch (InterruptedException ie) {
59 focusControl.setFocus(FocusControl.AUTO_LOCK);
61 } catch (MediaException me) {
67 public void setZoom(Controllable player) {
68 ZoomControl zoomControl = (ZoomControl) player.getControl("javax.microedition.amms.control.camera.ZoomControl");
69 if (zoomControl == null) {
70 zoomControl = (ZoomControl) player.getControl("ZoomControl");
72 if (zoomControl != null) {
73 // We zoom in if possible to encourage the viewer to take a snapshot from a greater distance.
74 // This is a crude way of dealing with the fact that many phone cameras will not focus at a
76 int maxZoom = zoomControl.getMaxOpticalZoom();
77 if (maxZoom > NO_ZOOM) {
78 zoomControl.setOpticalZoom(maxZoom > MAX_ZOOM ? MAX_ZOOM : maxZoom);
80 int maxDigitalZoom = zoomControl.getMaxDigitalZoom();
81 if (maxDigitalZoom > NO_ZOOM) {
82 zoomControl.setDigitalZoom(maxDigitalZoom > MAX_ZOOM ? MAX_ZOOM : maxDigitalZoom);
88 public void setExposure(Controllable player) {
89 ExposureControl exposureControl =
90 (ExposureControl) player.getControl("javax.microedition.amms.control.camera.ExposureControl");
91 if (exposureControl == null) {
92 exposureControl = (ExposureControl) player.getControl("ExposureControl");
94 if (exposureControl != null) {
96 int[] supportedISOs = exposureControl.getSupportedISOs();
97 if (supportedISOs != null && supportedISOs.length > 0) {
98 int maxISO = Integer.MIN_VALUE;
99 for (int i = 0; i < supportedISOs.length; i++) {
100 if (supportedISOs[i] > maxISO) {
101 maxISO = supportedISOs[i];
105 exposureControl.setISO(maxISO);
106 } catch (MediaException me) {
111 String[] supportedMeterings = exposureControl.getSupportedLightMeterings();
112 if (supportedMeterings != null) {
113 for (int i = 0; i < supportedMeterings.length; i++) {
114 if (DESIRED_METERING.equals(supportedMeterings[i])) {
115 exposureControl.setLightMetering(DESIRED_METERING);