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
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 public void setFocus(Controllable player) {
39 FocusControl focusControl = (FocusControl)
40 player.getControl("javax.microedition.amms.control.camera.FocusControl");
41 if (focusControl == null) {
42 focusControl = (FocusControl) player.getControl("FocusControl");
44 if (focusControl != null) {
46 if (focusControl.isMacroSupported() && !focusControl.getMacro()) {
47 focusControl.setMacro(true);
49 if (focusControl.isAutoFocusSupported()) {
50 focusControl.setFocus(FocusControl.AUTO);
52 Thread.sleep(FOCUS_TIME_MS); // let it focus...
53 } catch (InterruptedException ie) {
56 focusControl.setFocus(FocusControl.AUTO_LOCK);
58 } catch (MediaException me) {
64 public void setZoom(Controllable player) {
65 ZoomControl zoomControl = (ZoomControl) player.getControl("javax.microedition.amms.control.camera.ZoomControl");
66 if (zoomControl == null) {
67 zoomControl = (ZoomControl) player.getControl("ZoomControl");
69 if (zoomControl != null) {
70 // We zoom in if possible to encourage the viewer to take a snapshot from a greater distance.
71 // This is a crude way of dealing with the fact that many phone cameras will not focus at a
73 int maxZoom = zoomControl.getMaxOpticalZoom();
74 if (maxZoom > NO_ZOOM) {
75 zoomControl.setOpticalZoom(maxZoom > MAX_ZOOM ? MAX_ZOOM : maxZoom);
77 int maxDigitalZoom = zoomControl.getMaxDigitalZoom();
78 if (maxDigitalZoom > NO_ZOOM) {
79 zoomControl.setDigitalZoom(maxDigitalZoom > MAX_ZOOM ? MAX_ZOOM : maxDigitalZoom);
85 public void setExposure(Controllable player) {
86 ExposureControl exposureControl =
87 (ExposureControl) player.getControl("javax.microedition.amms.control.camera.ExposureControl");
88 if (exposureControl == null) {
89 exposureControl = (ExposureControl) player.getControl("ExposureControl");
91 if (exposureControl != null) {
93 int[] supportedISOs = exposureControl.getSupportedISOs();
94 if (supportedISOs != null && supportedISOs.length > 0) {
95 int maxISO = Integer.MIN_VALUE;
96 for (int i = 0; i < supportedISOs.length; i++) {
97 if (supportedISOs[i] > maxISO) {
98 maxISO = supportedISOs[i];
102 exposureControl.setISO(maxISO);
103 } catch (MediaException me) {
108 String[] supportedMeterings = exposureControl.getSupportedLightMeterings();
109 if (supportedMeterings != null) {
110 for (int i = 0; i < supportedMeterings.length; i++) {
111 if (DESIRED_METERING.equals(supportedMeterings[i])) {
112 exposureControl.setLightMetering(DESIRED_METERING);