- Fixed a crash on first launch after install on some hardware.
authordswitkin <dswitkin@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Tue, 20 Oct 2009 18:09:40 +0000 (18:09 +0000)
committerdswitkin <dswitkin@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Tue, 20 Oct 2009 18:09:40 +0000 (18:09 +0000)
- Moved the beep sound to the music stream and made the volume keys work.
- Bumped the version to 3.0 beta 2.

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

android/AndroidManifest.xml
android/src/com/google/zxing/client/android/CameraManager.java
android/src/com/google/zxing/client/android/CaptureActivity.java
android/src/com/google/zxing/client/android/ViewfinderView.java

index 3feca9b..a793e07 100755 (executable)
@@ -20,8 +20,8 @@ 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 beta1"
-          android:versionCode="35">
+          android:versionName="3.0 beta2"
+          android:versionCode="36">
   <!-- We require Donut (Android 1.6) or later. -->
   <uses-sdk android:minSdkVersion="4"/>
   <!-- Donut-specific flags which allow us to run on large and high dpi screens. -->
index 330b045..9ac5f47 100755 (executable)
@@ -208,6 +208,9 @@ final class CameraManager {
    */
   public Rect getFramingRect() {
     if (framingRect == null) {
+      if (camera == null) {
+        return null;
+      }
       int width = cameraResolution.x * 3 / 4;
       if (width < MIN_FRAME_WIDTH) {
         width = MIN_FRAME_WIDTH;
index d95abb8..7ff6ad0 100755 (executable)
@@ -131,7 +131,6 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
 
   @Override
   public void onCreate(Bundle icicle) {
-    Log.i(TAG, "Creating CaptureActivity");
     super.onCreate(icicle);
 
     Window window = getWindow();
@@ -244,7 +243,8 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
   public boolean onCreateOptionsMenu(Menu menu) {
     super.onCreateOptionsMenu(menu);
     menu.add(0, SHARE_ID, 0, R.string.menu_share).setIcon(R.drawable.share_menu_item);
-    menu.add(0, HISTORY_ID, 0, R.string.menu_history).setIcon(android.R.drawable.ic_menu_recent_history);
+    menu.add(0, HISTORY_ID, 0, R.string.menu_history)
+        .setIcon(android.R.drawable.ic_menu_recent_history);
     menu.add(0, SETTINGS_ID, 0, R.string.menu_settings)
         .setIcon(android.R.drawable.ic_menu_preferences);
     menu.add(0, HELP_ID, 0, R.string.menu_help)
@@ -479,7 +479,7 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
    * run. The easiest way to do this is to check android:versionCode from the manifest, and compare
    * it to a value stored as a preference.
    */
-  private void showHelpOnFirstLaunch() {
+  private boolean showHelpOnFirstLaunch() {
     try {
       PackageInfo info = getPackageManager().getPackageInfo(PACKAGE_NAME, 0);
       int currentVersion = info.versionCode;
@@ -493,10 +493,12 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
         Intent intent = new Intent(Intent.ACTION_VIEW);
         intent.setClassName(this, HelpActivity.class.getName());
         startActivity(intent);
+        return true;
       }
     } catch (PackageManager.NameNotFoundException e) {
       Log.w(TAG, e);
     }
+    return false;
   }
 
   /**
@@ -505,8 +507,11 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
    */
   private void initBeepSound() {
     if (playBeep && mediaPlayer == null) {
+      // The volume on STREAM_SYSTEM is not adjustable, and users found it too loud,
+      // so we now play on the music stream.
+      setVolumeControlStream(AudioManager.STREAM_MUSIC);
       mediaPlayer = new MediaPlayer();
-      mediaPlayer.setAudioStreamType(AudioManager.STREAM_SYSTEM);
+      mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
       mediaPlayer.setOnCompletionListener(beepListener);
 
       AssetFileDescriptor file = getResources().openRawResourceFd(R.raw.beep);
index 0937056..3b73753 100755 (executable)
@@ -62,6 +62,9 @@ public final class ViewfinderView extends View {
   @Override
   public void onDraw(Canvas canvas) {
     Rect frame = CameraManager.get().getFramingRect();
+    if (frame == null) {
+      return;
+    }
     int width = canvas.getWidth();
     int height = canvas.getHeight();