Added notes about how to comment out anything that might possibly lead to JSR-234...
[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     // Having issues with non-JSR-234 phones not accepting the build? then try commenting out from here:
40     try {
41       advancedMultimediaManager = (MultimediaManager)
42           Class.forName("com.google.zxing.client.j2me.AdvancedMultimediaManager").newInstance();
43     } catch (ClassNotFoundException cnfe) {
44       // continue
45     } catch (IllegalAccessException iae) {
46       // continue
47     } catch (InstantiationException ie) {
48       // continue
49     } catch (NoClassDefFoundError ncdfe) {
50       // continue
51     }
52     // to here. Then add this line:
53     // advancedMultimediaManager = null;
54     // You may also need to delete the class AdvancedMultimediaManager in this package to be completely free
55     // of JSR-234 references.
56   }
57
58   public void setFocus(Controllable player) {
59     if (advancedMultimediaManager != null) {
60       advancedMultimediaManager.setFocus(player);
61     }
62   }
63
64   public void setZoom(Controllable player) {
65     if (advancedMultimediaManager != null) {
66       advancedMultimediaManager.setZoom(player);
67     }
68   }
69
70   public void setExposure(Controllable player) {
71     if (advancedMultimediaManager != null) {
72       advancedMultimediaManager.setExposure(player);
73     }
74   }
75
76 }