Implemented Paul's solution to the basic/regular build problem -- a sort of pseudo...
authorsrowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Thu, 26 Jun 2008 15:35:39 +0000 (15:35 +0000)
committersrowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Thu, 26 Jun 2008 15:35:39 +0000 (15:35 +0000)
git-svn-id: http://zxing.googlecode.com/svn/trunk@481 59b500cc-1b3d-0410-9834-0bbf25fbcc57

AUTHORS
build.xml
javame/build.xml
javame/src-basic/com/google/zxing/client/j2me/AdvancedMultimediaManager.java [deleted file]
javame/src/com/google/zxing/client/j2me/AdvancedMultimediaManager.java
javame/src/com/google/zxing/client/j2me/DefaultMultimediaManager.java [new file with mode: 0644]
javame/src/com/google/zxing/client/j2me/MultimediaManager.java [new file with mode: 0644]
javame/src/com/google/zxing/client/j2me/SnapshotThread.java
javame/src/com/google/zxing/client/j2me/ZXingMIDlet.java

diff --git a/AUTHORS b/AUTHORS
index 040e6fd..93a7370 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -9,5 +9,6 @@ Daniel Switkin (Google)
 David Albert (Bug Labs)
 John Connolly (Bug Labs)
 Matthew Schulkind (Google)
+Paul Hackenberger
 Sean Owen (Google)
 Vince Francis
\ No newline at end of file
index 6d98501..79daf24 100644 (file)
--- a/build.xml
+++ b/build.xml
@@ -26,7 +26,6 @@
     <ant dir="javame" target="build"/>
     <ant dir="javase" target="build"/>
     <ant dir="android" target="package"/>
-    <ant dir="javame" target="build-basic"/>
     <ant dir="rim" target="build"/>
     <ant dir="zxingorg" target="build"/>
   </target>
index 78b7d47..7eeda6d 100644 (file)
@@ -65,7 +65,7 @@
     </fail>
   </target>
 
-  <target name="compile" depends="init">
+  <target name="build" depends="init">
     <mkdir dir="build"/>
     <javac srcdir="src"
            destdir="build"
       <classpath refid="wtk-build-path"/>
     </javac>
     <jar jarfile="javame.jar" basedir="build"/>
-  </target>
 
-  <target name="compile-basic" depends="init">
-    <mkdir dir="build"/>
-    <!-- For an explanation of this odd build command, see javadoc in
-         src/com/google/zxing/client/j2me/AdvancedMultimediaManager.java -->
-    <javac srcdir="src-basic"
-           destdir="build"
-           source="1.2"
-           target="1.2"
-           bootclasspath="${javame-compile-bootclasspath-path}"
-           optimize="true"
-           debug="true"
-           deprecation="true"
-           fork="true">
-      <classpath refid="wtk-build-path"/>
-    </javac>
-    <javac srcdir="src"
-           destdir="build"
-           source="1.2"
-           target="1.2"
-           bootclasspath="${javame-compile-bootclasspath-path}"
-           optimize="true"
-           debug="true"
-           deprecation="true"
-           fork="true">
-      <classpath refid="wtk-build-path"/>
-      <exclude name="com/google/zxing/client/j2me/AdvancedMultimediaManager.java"/>
-    </javac>
-    <jar jarfile="javame-basic.jar" basedir="build"/>
-  </target>
-
-  <target name="package">
     <unzip src="../core/core.jar" dest="build"/>
 
     <mkdir dir="build-j2me"/>
     <copy file="src/com/google/zxing/client/j2me/MANIFEST.MF.template"
           tofile="src/com/google/zxing/client/j2me/MANIFEST.MF" overwrite="true">
       <filterset>
-        <filter token="APP_NAME" value="${jar-name}"/>
+        <filter token="APP_NAME" value="BarcodeReader"/>
         <filter token="VERSION" value="${version}"/>
       </filterset>
     </copy>
 
-    <jar jarfile="${jar-name}.jar" basedir="build-j2me" manifest="src/com/google/zxing/client/j2me/MANIFEST.MF"/>
+    <jar jarfile="BarcodeReader.jar" basedir="build-j2me" manifest="src/com/google/zxing/client/j2me/MANIFEST.MF"/>
 
-    <move file="${jar-name}.jar" tofile="temp.jar"/>
+    <move file="BarcodeReader.jar" tofile="temp.jar"/>
     <java jar="${WTK-home}/bin/proguard.jar" fork="true" failonerror="true">
       <jvmarg value="-Dmaximum.inlined.code.length=32"/>
       <arg value="-injars temp.jar"/>
-      <arg value="-outjars ${jar-name}.jar"/>
+      <arg value="-outjars BarcodeReader.jar"/>
       <arg value="-libraryjars ${WTK-home}/lib/cldcapi11.jar"/>
       <arg value="-libraryjars ${WTK-home}/lib/midpapi20.jar"/>
       <arg value="-libraryjars ${WTK-home}/lib/mmapi.jar"/>
       <arg value="-libraryjars ${WTK-home}/lib/jsr234.jar"/>
       <arg value="-microedition"/>
       <arg value="-keep public class com.google.zxing.client.j2me.ZXingMIDlet"/>
+      <arg value="-keep class com.google.zxing.client.j2me.AdvancedMultimediaManager"/>
+      <arg value="-keep class com.google.zxing.client.j2me.DefaultMultimediaManager"/>
+      <arg value="-keep class com.google.zxing.client.j2me.MultimediaManager"/>      
       <arg value="-optimizationpasses 7"/>
       <arg value="-overloadaggressively"/>
       <arg value="-allowaccessmodification"/>
     <delete file="temp.jar"/>
 
     <!-- get .jar size to include it in the .jad file -->
-    <length file="${jar-name}.jar" property="jar-size"/>
+    <length file="BarcodeReader.jar" property="jar-size"/>
 
-    <copy file="BarcodeReader.jad.template" tofile="${jar-name}.jad" overwrite="true">
+    <copy file="BarcodeReader.jad.template" tofile="BarcodeReader.jad" overwrite="true">
       <filterset>
         <filter token="JAR_SIZE" value="${jar-size}"/>
-        <filter token="APP_NAME" value="${jar-name}"/>
+        <filter token="APP_NAME" value="BarcodeReader"/>
         <filter token="VERSION" value="${version}"/>
       </filterset>
     </copy>
 
   </target>
 
-  <target name="build">
-    <description>Builds the main reader .jar file</description>
-    <property name="jar-name" value="BarcodeReader"/>
-    <antcall target="clean"/>
-    <antcall target="compile"/>
-    <antcall target="package"/>
-  </target>
-
-  <target name="build-basic">
-    <description>Builds the basic reader .jar file</description>
-    <property name="jar-name" value="BarcodeReaderBasic"/>
-    <antcall target="clean"/>
-    <antcall target="compile-basic"/>
-    <antcall target="package"/>
-  </target>
-
   <target name="dump">
     <java jar="${WTK-home}/bin/proguard.jar" fork="true">
       <arg value="-injars BarcodeReader.jar"/>
diff --git a/javame/src-basic/com/google/zxing/client/j2me/AdvancedMultimediaManager.java b/javame/src-basic/com/google/zxing/client/j2me/AdvancedMultimediaManager.java
deleted file mode 100644 (file)
index 7394c26..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright 2007 ZXing authors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.zxing.client.j2me;
-
-import javax.microedition.media.Controllable;
-
-/**
- * <p>See this exact same class under the "src" source root for a full explanation.
- * This is a "no-op" version of the class that gets built into the .jar file
- * which is suitable for non-JSR-234 devices.</p>
- * 
- * @author Sean Owen (srowen@google.com)
- */
-final class AdvancedMultimediaManager {
-
-  private AdvancedMultimediaManager() {
-    // do nothing
-  }
-
-  // These signatures must match those in the other class exactly
-
-  static void setFocus(Controllable player) {
-    // do nothing
-  }
-
-  static void setZoom(Controllable player) {
-    // do nothing
-  }
-
-  static void setExposure(Controllable player) {
-    // do nothing
-  }
-
-}
\ No newline at end of file
index c8adc97..3657372 100644 (file)
@@ -23,29 +23,20 @@ import javax.microedition.media.Controllable;
 import javax.microedition.media.MediaException;
 
 /**
- * <p>This odd class encapsulates all access to functionality exposed by JSR-234,
- * which provides access to things like focus and zoom. Not all phones support this though.
- * Normally we might handle loading of code like this via reflection but this is
- * not available to us in Java ME. So, we create two implementations of the same class --
- * this one, and another found under source root "src-basic". This one actually calls
- * JSR-234 methods. The other does nothing. The build script creates two build products then
- * one compiled with this class and one with other, to create both the JSR-234 version
- * and the "basic" non-JSR-234 version.</p>
+ * <p>See {@link DefaultMultimediaManager} documentation for details.</p>
+ *
+ * <p>This class should never be directly imported or reference in the code.</p>
  *
  * @author Sean Owen (srowen@google.com)
  */
-final class AdvancedMultimediaManager {
+final class AdvancedMultimediaManager implements MultimediaManager {
 
   private static final int NO_ZOOM = 100;
   private static final int MAX_ZOOM = 200;
   private static final long FOCUS_TIME_MS = 750L;
   private static final String DESIRED_METERING = "center-weighted";
 
-  private AdvancedMultimediaManager() {
-    // do nothing
-  }
-
-  static void setFocus(Controllable player) {
+  public void setFocus(Controllable player) {
     FocusControl focusControl = (FocusControl)
         player.getControl("javax.microedition.amms.control.camera.FocusControl");
     if (focusControl != null) {
@@ -68,7 +59,7 @@ final class AdvancedMultimediaManager {
     }
   }
 
-  static void setZoom(Controllable player) {
+  public void setZoom(Controllable player) {
     ZoomControl zoomControl = (ZoomControl) player.getControl("javax.microedition.amms.control.camera.ZoomControl");
     if (zoomControl != null) {
       // We zoom in if possible to encourage the viewer to take a snapshot from a greater distance.
@@ -86,7 +77,7 @@ final class AdvancedMultimediaManager {
     }
   }
 
-  static void setExposure(Controllable player) {
+  public void setExposure(Controllable player) {
     ExposureControl exposureControl =
         (ExposureControl) player.getControl("javax.microedition.amms.control.camera.ExposureControl");
     if (exposureControl != null) {
diff --git a/javame/src/com/google/zxing/client/j2me/DefaultMultimediaManager.java b/javame/src/com/google/zxing/client/j2me/DefaultMultimediaManager.java
new file mode 100644 (file)
index 0000000..c73abcc
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2007 ZXing authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+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>
+ *
+ * @author Sean Owen (srowen@google.com)
+ * @author Paul Hackenberger
+ */
+class DefaultMultimediaManager implements MultimediaManager {
+
+  private MultimediaManager advancedMultimediaManager;
+
+  DefaultMultimediaManager() {
+    try {
+      advancedMultimediaManager = (MultimediaManager)
+          Class.forName("com.google.zxing.client.j2me.AdvancedMultimediaManager").newInstance();
+    } catch (ClassNotFoundException cnfe) {
+      // continue
+    } catch (IllegalAccessException iae) {
+      // continue
+    } catch (InstantiationException ie) {
+      // continue
+    }
+  }
+
+  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);
+    }
+  }
+
+}
\ No newline at end of file
diff --git a/javame/src/com/google/zxing/client/j2me/MultimediaManager.java b/javame/src/com/google/zxing/client/j2me/MultimediaManager.java
new file mode 100644 (file)
index 0000000..6643608
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2008 ZXing authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.google.zxing.client.j2me;
+
+import javax.microedition.media.Controllable;
+
+/**
+ * <p>Implemented by {@link com.google.zxing.client.j2me.DefaultMultimediaManager} and
+ * {@link com.google.zxing.client.j2me.AdvancedMultimediaManager} in order to dynamically
+ * load support for JSR-234 APIs where possible.</p>
+ *
+ * @author Sean Owen (srowen@google.com)
+ * @author Paul Hackenberger
+ */
+interface MultimediaManager {
+
+  void setFocus(Controllable player);
+
+  void setZoom(Controllable player);
+
+  void setExposure(Controllable player);
+
+}
\ No newline at end of file
index 99322dc..b6c3e39 100644 (file)
@@ -37,11 +37,13 @@ final class SnapshotThread implements Runnable {
   private final ZXingMIDlet zXingMIDlet;
   private final Object waitLock;
   private boolean done;
+  private final MultimediaManager multimediaManager;
 
   SnapshotThread(ZXingMIDlet zXingMIDlet) {
     this.zXingMIDlet = zXingMIDlet;
     waitLock = new Object();
     done = false;
+    multimediaManager = new DefaultMultimediaManager();
   }
 
   void continueRun() {
@@ -70,7 +72,7 @@ final class SnapshotThread implements Runnable {
     do {
       waitForSignal();
       try {
-        AdvancedMultimediaManager.setFocus(player);
+        multimediaManager.setFocus(player);
         byte[] snapshot = takeSnapshot();
         Image capturedImage = Image.createImage(snapshot, 0, snapshot.length);
         MonochromeBitmapSource source = new LCDUIImageMonochromeBitmapSource(capturedImage);
index 9f633d4..9941814 100644 (file)
@@ -72,8 +72,9 @@ public final class ZXingMIDlet extends MIDlet {
     try {
       player = createPlayer();
       player.realize();
-      AdvancedMultimediaManager.setZoom(player);
-      AdvancedMultimediaManager.setExposure(player);
+      MultimediaManager multimediaManager = new DefaultMultimediaManager();
+      multimediaManager.setZoom(player);
+      multimediaManager.setExposure(player);
       videoControl = (VideoControl) player.getControl("VideoControl");
       canvas = new VideoCanvas(this);
       canvas.setFullScreenMode(true);