2 * Copyright 2007 Google Inc.
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.FocusControl;
20 import javax.microedition.amms.control.camera.ZoomControl;
21 import javax.microedition.media.Controllable;
22 import javax.microedition.media.MediaException;
25 * <p>This odd class encapsulates all access to functionality exposed by JSR-234,
26 * which provides access to things like focus and zoom. Not all phones support this though.
27 * Normally we might handle loading of code like this via reflection but this is
28 * not available to us in Java ME. So, we create two implementations of the same class --
29 * this one, and another found under source root "src-basic". This one actually calls
30 * JSR-234 methods. The other does nothing. The build script creates two build products then
31 * one compiled with this class and one with other, to create both the JSR-234 version
32 * and the "basic" non-JSR-234 version.</p>
34 * @author Sean Owen (srowen@google.com)
36 final class AdvancedMultimediaManager {
38 private static final int NO_ZOOM = 100;
39 private static final int MAX_ZOOM = 200;
40 private static final long FOCUS_TIME_MS = 750L;
42 private AdvancedMultimediaManager() {
46 static void setFocus(Controllable player) throws MediaException {
47 FocusControl focusControl = (FocusControl)
48 player.getControl("javax.microedition.amms.control.camera.FocusControl");
49 if (focusControl != null) {
50 if (focusControl.isMacroSupported() && !focusControl.getMacro()) {
51 focusControl.setMacro(true);
53 if (focusControl.isAutoFocusSupported()) {
54 focusControl.setFocus(FocusControl.AUTO);
56 Thread.sleep(FOCUS_TIME_MS); // let it focus...
57 } catch (InterruptedException ie) {
61 focusControl.setFocus(FocusControl.AUTO_LOCK);
62 } catch (MediaException me) {
63 // continue; some phones like the SE K850 don't support this?
69 static void setZoom(Controllable player) {
70 ZoomControl zoomControl = (ZoomControl) player.getControl("javax.microedition.amms.control.camera.ZoomControl");
71 if (zoomControl != null) {
72 // We zoom in if possible to encourage the viewer to take a snapshot from a greater distance.
73 // This is a crude way of dealing with the fact that many phone cameras will not focus at a
75 int maxZoom = zoomControl.getMaxOpticalZoom();
76 if (maxZoom > NO_ZOOM) {
77 zoomControl.setOpticalZoom(maxZoom > MAX_ZOOM ? MAX_ZOOM : maxZoom);
79 int maxDigitalZoom = zoomControl.getMaxDigitalZoom();
80 if (maxDigitalZoom > NO_ZOOM) {
81 zoomControl.setDigitalZoom(maxDigitalZoom > MAX_ZOOM ? MAX_ZOOM : maxDigitalZoom);