Going back to old approach of using JSR-234 directly, then compiling with different code to produce a non-JSR-234 version. This approach isn't working on some phones -- including JSR-234 phones.

git-svn-id: https://zxing.googlecode.com/svn/trunk@641 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen 2008-10-26 13:29:46 +00:00
parent de419268b8
commit a1deb27f46
3 changed files with 7 additions and 55 deletions

View file

@ -19,14 +19,12 @@ package com.google.zxing.client.j2me;
import javax.microedition.amms.control.camera.ExposureControl;
import javax.microedition.amms.control.camera.FocusControl;
import javax.microedition.amms.control.camera.ZoomControl;
import javax.microedition.media.Control;
import javax.microedition.media.Controllable;
import javax.microedition.media.MediaException;
/**
* <p>See {@link DefaultMultimediaManager} documentation for details.</p>
*
* <p>This class should never be directly imported or reference in the code.</p>
* <p>Implementation suitable for JSR-234 phones which takes advantage of advanced camera
* capability.</p>
*
* @author Sean Owen (srowen@google.com)
*/
@ -38,18 +36,6 @@ final class AdvancedMultimediaManager implements MultimediaManager {
private static final String DESIRED_METERING = "center-weighted";
AdvancedMultimediaManager() {
// Another try at fixing Issue 70. Seems like FocusControl et al. are sometimes not
// loaded until first use in the setFocus() method. This is too late for our
// mechanism to handle, since it is trying to detect this API is not available
// at the time this class is instantiated. We can't move the player.getControl() calls
// into here since we don't have a Controllable to call on, since we can't pass an
// arg into the constructor, since we can't do that in J2ME when instantiating via
// newInstance(). So we just try writing some dead code here to induce the VM to
// definitely load the classes now:
Control dummy = null;
ExposureControl dummy1 = (ExposureControl) dummy;
FocusControl dummy2 = (FocusControl) dummy;
ZoomControl dummy3 = (ZoomControl) dummy;
}
public void setFocus(Controllable player) {

View file

@ -19,58 +19,22 @@ package com.google.zxing.client.j2me;
import javax.microedition.media.Controllable;
/**
* <p>This class encapsulates optional multimedia-related operations that the device
* may support, like setting focus and zoom. This implementation itself will do nothing.
* It will attempt to dynamically instantiate {@link com.google.zxing.client.j2me.AdvancedMultimediaManager}
* which has methods that call JSR-234 APIs to actually set focus, zoom, etc. If successful,
* this class will delegate to that implementation. But if the phone does not support these
* APIs, instantiation will simply fail and this implementation will do nothing.</p>
*
* <p>Credit to Paul Hackenberger for the nice workaround</p>
* <p>Dummy implemenation which does nothing. This is suitable for non-JSR-234 phones.</p>
*
* @author Sean Owen (srowen@google.com)
* @author Paul Hackenberger
*/
class DefaultMultimediaManager implements MultimediaManager {
private MultimediaManager advancedMultimediaManager;
final class DefaultMultimediaManager implements MultimediaManager {
DefaultMultimediaManager() {
// Having issues with non-JSR-234 phones not accepting the build? then try commenting out from here:
try {
advancedMultimediaManager = (MultimediaManager)
Class.forName("com.google.zxing.client.j2me.AdvancedMultimediaManager").newInstance();
} catch (ClassNotFoundException cnfe) {
// continue
} catch (IllegalAccessException iae) {
// continue
} catch (InstantiationException ie) {
// continue
} catch (NoClassDefFoundError ncdfe) {
// continue
}
// to here. Then add this line:
// advancedMultimediaManager = null;
// You may also need to delete the class AdvancedMultimediaManager in this package to be completely free
// of JSR-234 references.
}
public void setFocus(Controllable player) {
if (advancedMultimediaManager != null) {
advancedMultimediaManager.setFocus(player);
}
}
public void setZoom(Controllable player) {
if (advancedMultimediaManager != null) {
advancedMultimediaManager.setZoom(player);
}
}
public void setExposure(Controllable player) {
if (advancedMultimediaManager != null) {
advancedMultimediaManager.setExposure(player);
}
}
}

View file

@ -69,7 +69,9 @@ public final class ZXingMIDlet extends MIDlet {
try {
player = createPlayer();
player.realize();
MultimediaManager multimediaManager = new DefaultMultimediaManager();
MultimediaManager multimediaManager = new AdvancedMultimediaManager();
// Comment line above / uncomment below to make the basic version
//MultimediaManager multimediaManager = new DefaultMultimediaManager();
multimediaManager.setZoom(player);
multimediaManager.setExposure(player);
videoControl = (VideoControl) player.getControl("VideoControl");