- Added back support for Cupcake by making the choice of preview callback conditional...
authordswitkin <dswitkin@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Thu, 22 Oct 2009 14:51:53 +0000 (14:51 +0000)
committerdswitkin <dswitkin@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Thu, 22 Oct 2009 14:51:53 +0000 (14:51 +0000)
- Fixed a number of non-dpi-aware resource dimensions.
- Bumped the version to 3.0 beta 3.

git-svn-id: http://zxing.googlecode.com/svn/trunk@1081 59b500cc-1b3d-0410-9834-0bbf25fbcc57

android/AndroidManifest.xml
android/res/layout-land/encode.xml
android/res/layout-land/share.xml
android/res/layout/bookmark_picker_list_item.xml
android/res/layout/capture.xml
android/res/layout/encode.xml
android/res/layout/help.xml
android/res/layout/search_book_contents_header.xml
android/res/layout/search_book_contents_list_item.xml
android/res/layout/share.xml
android/src/com/google/zxing/client/android/CameraManager.java

index a793e07..eec262a 100755 (executable)
@@ -20,10 +20,10 @@ version to be published. The next versionCode will be 7, regardless of whether t
 versionName is 2.31, 2.4, or 3.0. -->
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
           package="com.google.zxing.client.android"
-          android:versionName="3.0 beta2"
-          android:versionCode="36">
-  <!-- We require Donut (Android 1.6) or later. -->
-  <uses-sdk android:minSdkVersion="4"/>
+          android:versionName="3.0 beta3"
+          android:versionCode="37">
+  <!-- We require Cupcake (Android 1.5) or later. -->
+  <uses-sdk android:minSdkVersion="3"/>
   <!-- Donut-specific flags which allow us to run on large and high dpi screens. -->
   <supports-screens
     android:largeScreens="true"
index 409681b..e8ec884 100755 (executable)
@@ -35,7 +35,7 @@
             android:gravity="center"
             android:textColor="@color/contents_text"
             android:textSize="20.0sp"
-            android:paddingRight="8px"
-            android:paddingTop="8px"
-            android:paddingBottom="8px"/>
+            android:paddingRight="8dip"
+            android:paddingTop="8dip"
+            android:paddingBottom="8dip"/>
 </LinearLayout>
index 7144714..34c3cd3 100755 (executable)
@@ -20,7 +20,7 @@
               android:layout_height="fill_parent"
               android:background="@color/share_view"
               android:orientation="vertical"
-              android:padding="16px">
+              android:padding="16dip">
 
   <TextView
       android:layout_width="fill_parent"
@@ -29,7 +29,7 @@
       android:textColor="@color/share_text"
       android:textSize="18.0sp"
       android:text="@string/msg_share_explanation"
-      android:paddingBottom="32px"/>
+      android:paddingBottom="32dip"/>
 
   <LinearLayout
       android:layout_width="wrap_content"
@@ -43,7 +43,7 @@
         android:layout_height="wrap_content"
         android:scaleType="center"
         android:src="@drawable/share_via_barcode"
-        android:paddingRight="48px"/>
+        android:paddingRight="48dip"/>
 
     <LinearLayout
         android:layout_width="wrap_content"
index 3508635..6ff455d 100644 (file)
@@ -19,7 +19,7 @@
     android:orientation="vertical"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
-    android:padding="4px">
+    android:padding="4dip">
 
 
   <TextView android:id="@+id/bookmark_title"
index 192c533..3e39cde 100755 (executable)
@@ -35,7 +35,7 @@
                 android:layout_height="fill_parent"
                 android:background="@color/result_view"
                 android:visibility="gone"
-                android:padding="4px">
+                android:padding="4dip">
 
     <LinearLayout
         android:orientation="horizontal"
@@ -43,7 +43,7 @@
         android:layout_height="wrap_content"
         android:layout_weight="1"
         android:gravity="top"
-        android:padding="12px">
+        android:padding="12dip">
 
       <LinearLayout
           android:orientation="vertical"
@@ -54,7 +54,7 @@
         <ImageView android:id="@+id/barcode_image_view"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
-                   android:layout_marginBottom="4px"
+                   android:layout_marginBottom="4dip"
                    android:adjustViewBounds="true"
                    android:scaleType="centerInside"/>
 
@@ -88,7 +88,7 @@
                   android:text="@string/msg_default_contents"
                   android:textColor="@color/result_text"
                   android:textSize="22sp"
-                  android:paddingLeft="12px"
+                  android:paddingLeft="12dip"
                   android:autoLink="web"/>
 
       </ScrollView>
                   android:layout_weight="0"
                   android:background="@color/status_view"
                   android:baselineAligned="false"
-                  android:padding="4px">
+                  android:padding="4dip">
 
       <TextView android:id="@+id/status_text_view"
                 android:layout_width="wrap_content"
index 7597c6c..2de70dd 100755 (executable)
@@ -41,8 +41,8 @@
               android:gravity="center"
               android:textColor="@color/contents_text"
               android:textSize="20.0sp"
-              android:paddingBottom="8px"
-              android:paddingLeft="8px"
-              android:paddingRight="8px"/>
+              android:paddingBottom="8dip"
+              android:paddingLeft="8dip"
+              android:paddingRight="8dip"/>
   </LinearLayout>
 </ScrollView>
\ No newline at end of file
index 062ff68..d8613a5 100644 (file)
@@ -25,7 +25,7 @@
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:fadingEdge="vertical"
-           android:fadingEdgeLength="16dip"/>
+           android:fadingEdgeLength="12dip"/>
 
   <LinearLayout
       android:layout_width="fill_parent"
@@ -33,7 +33,7 @@
       android:layout_weight="0"
       android:orientation="horizontal"
       android:gravity="center"
-      android:padding="8px"
+      android:padding="6dip"
       android:weightSum="1"
       android:background="@color/help_button_view">
 
index f3399c0..1468015 100644 (file)
@@ -18,7 +18,8 @@
           android:layout_width="fill_parent"
           android:layout_height="wrap_content"
           android:background="@color/sbc_header_view"
-          android:paddingLeft="8px"
+          android:paddingLeft="8dip"
+          android:paddingBottom="4dip"
           android:enabled="false"
           android:textColor="@color/sbc_header_text"
           android:singleLine="true"
index a79f5a0..2cfaf07 100644 (file)
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:background="@color/sbc_list_item"
-    android:padding="8px">
+    android:padding="6dip">
 
   <TextView android:id="@+id/page_number_view"
-            android:layout_width="75px"
+            android:layout_width="75dip"
             android:layout_height="wrap_content"
             android:layout_gravity="left|top"
-            android:layout_marginRight="8px"
+            android:layout_marginRight="8dip"
             android:textColor="@color/sbc_page_number_text"
             android:singleLine="false"
             android:textSize="16sp"
index 8a68dd7..4125caa 100755 (executable)
@@ -20,7 +20,7 @@
               android:layout_height="fill_parent"
               android:background="@color/share_view"
               android:orientation="vertical"
-              android:padding="16px">
+              android:padding="16dip">
 
   <TextView
       android:layout_width="fill_parent"
@@ -29,7 +29,7 @@
       android:textColor="@color/share_text"
       android:textSize="18.0sp"
       android:text="@string/msg_share_explanation"
-      android:paddingBottom="32px"/>
+      android:paddingBottom="32dip"/>
 
   <LinearLayout
       android:layout_width="wrap_content"
@@ -43,7 +43,7 @@
         android:layout_height="wrap_content"
         android:scaleType="center"
         android:src="@drawable/share_via_barcode"
-        android:paddingBottom="32px"/>
+        android:paddingBottom="32dip"/>
 
     <Button android:id="@+id/contact_button"
             android:layout_width="fill_parent"
index 9ac5f47..fd4a366 100755 (executable)
@@ -23,6 +23,7 @@ import android.graphics.PixelFormat;
 import android.graphics.Point;
 import android.graphics.Rect;
 import android.hardware.Camera;
+import android.os.Build;
 import android.os.Handler;
 import android.os.Message;
 import android.util.Log;
@@ -60,6 +61,7 @@ final class CameraManager {
   private boolean previewing;
   private int previewFormat;
   private String previewFormatString;
+  private boolean useOneShotPreviewCallback;
 
   /**
    * Preview frames are delivered here, which we pass on to the registered handler. Make sure to
@@ -67,6 +69,9 @@ final class CameraManager {
    */
   private final Camera.PreviewCallback previewCallback = new Camera.PreviewCallback() {
     public void onPreviewFrame(byte[] data, Camera camera) {
+      if (!useOneShotPreviewCallback) {
+        camera.setPreviewCallback(null);
+      }
       if (previewHandler != null) {
         Message message = previewHandler.obtainMessage(previewMessage, cameraResolution.x,
             cameraResolution.y, data);
@@ -115,6 +120,16 @@ final class CameraManager {
     camera = null;
     initialized = false;
     previewing = false;
+
+    // Camera.setOneShotPreviewCallback() has a race condition in Cupcake, so we use the older
+    // Camera.setPreviewCallback() on 1.5 and earlier. For Donut and later, we need to use
+    // the more efficient one shot callback, as the older one can swamp the system and cause it
+    // to run out of memory.
+    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.CUPCAKE) {
+      useOneShotPreviewCallback = false;
+    } else {
+      useOneShotPreviewCallback = true;
+    }
   }
 
   /**
@@ -162,6 +177,9 @@ final class CameraManager {
    */
   public void stopPreview() {
     if (camera != null && previewing) {
+      if (!useOneShotPreviewCallback) {
+        camera.setPreviewCallback(null);
+      }
       camera.stopPreview();
       previewHandler = null;
       autoFocusHandler = null;
@@ -181,7 +199,11 @@ final class CameraManager {
     if (camera != null && previewing) {
       previewHandler = handler;
       previewMessage = message;
-      camera.setOneShotPreviewCallback(previewCallback);
+      if (useOneShotPreviewCallback) {
+        camera.setOneShotPreviewCallback(previewCallback);
+      } else {
+        camera.setPreviewCallback(previewCallback);
+      }
     }
   }