Implemented Paul's solution to the basic/regular build problem -- a sort of pseudo...
[zxing.git] / javame / src / com / google / zxing / client / j2me / DefaultMultimediaManager.java
1 /*
2  * Copyright 2007 ZXing authors
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package com.google.zxing.client.j2me;
18
19 import javax.microedition.media.Controllable;
20
21 /**
22  * <p>This class encapsulates optional multimedia-related operations that the device
23  * may support, like setting focus and zoom. This implementation itself will do nothing.
24  * It will attempt to dynamically instantiate {@link com.google.zxing.client.j2me.AdvancedMultimediaManager}
25  * which has methods that call JSR-234 APIs to actually set focus, zoom, etc. If successful,
26  * this class will delegate to that implementation. But if the phone does not support these
27  * APIs, instantiation will simply fail and this implementation will do nothing.</p>
28  *
29  * <p>Credit to Paul Hackenberger for the nice workaround</p>
30  *
31  * @author Sean Owen (srowen@google.com)
32  * @author Paul Hackenberger
33  */
34 class DefaultMultimediaManager implements MultimediaManager {
35
36   private MultimediaManager advancedMultimediaManager;
37
38   DefaultMultimediaManager() {
39     try {
40       advancedMultimediaManager = (MultimediaManager)
41           Class.forName("com.google.zxing.client.j2me.AdvancedMultimediaManager").newInstance();
42     } catch (ClassNotFoundException cnfe) {
43       // continue
44     } catch (IllegalAccessException iae) {
45       // continue
46     } catch (InstantiationException ie) {
47       // continue
48     }
49   }
50
51   public void setFocus(Controllable player) {
52     if (advancedMultimediaManager != null) {
53       advancedMultimediaManager.setFocus(player);
54     }
55   }
56
57   public void setZoom(Controllable player) {
58     if (advancedMultimediaManager != null) {
59       advancedMultimediaManager.setZoom(player);
60     }
61   }
62
63   public void setExposure(Controllable player) {
64     if (advancedMultimediaManager != null) {
65       advancedMultimediaManager.setExposure(player);
66     }
67   }
68
69 }