Another light hack attempt to work around Issue 70
authorsrowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Thu, 31 Jul 2008 19:21:34 +0000 (19:21 +0000)
committersrowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Thu, 31 Jul 2008 19:21:34 +0000 (19:21 +0000)
git-svn-id: http://zxing.googlecode.com/svn/trunk@541 59b500cc-1b3d-0410-9834-0bbf25fbcc57

javame/src/com/google/zxing/client/j2me/AdvancedMultimediaManager.java

index 4de04ca..3b5a0f3 100644 (file)
@@ -19,6 +19,7 @@ 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;
 
@@ -36,6 +37,21 @@ final class AdvancedMultimediaManager implements MultimediaManager {
   private static final long FOCUS_TIME_MS = 750L;
   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) {
     FocusControl focusControl = (FocusControl)
         player.getControl("javax.microedition.amms.control.camera.FocusControl");