Skip to content

Commit

Permalink
Take picture only on valid focus. Workaround for issue # 61394
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalduggal committed Apr 16, 2014
1 parent 3f3818e commit 0fd8a0e
Showing 1 changed file with 18 additions and 1 deletion.
Expand Up @@ -36,6 +36,7 @@
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
Expand Down Expand Up @@ -494,7 +495,11 @@ static public void takePicture()
public void onAutoFocus(boolean success, Camera camera)
{
// Take the picture when the camera auto focus completes.
camera.takePicture(shutterCallback, null, jpegCallback);
if (success) {
camera.takePicture(shutterCallback, null, jpegCallback);
} else {
Log.d(TAG, "Unable to focus. Ignoring call to take picture");
}
}
};
camera.autoFocus(focusCallback);
Expand Down Expand Up @@ -676,4 +681,16 @@ public void onBackPressed()
}
super.onBackPressed();
}

@Override
public boolean onKeyDown (int keyCode, KeyEvent event)
{
if (keyCode == KeyEvent.KEYCODE_MENU) {
//Workaround for http://code.google.com/p/android/issues/detail?id=61394
//Exists atleast till version 19.1 of support library
return true;
}

return super.onKeyDown(keyCode, event);
}
}

1 comment on commit 0fd8a0e

@danpe
Copy link

@danpe danpe commented on 0fd8a0e May 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm on Nexus 5, trying to take picture.
Picture looks 100% focused and my call to Ti.Media.takePicture(); failed silently.

Took me more than 30 minutes to understand the some how I received the "Unable to focus" message.

I think there are 2 options of solving this.

  1. Always take picture even if focus didn't succeed and just log on focus failure
  2. Add a property that sais "Throw on focus failure" so it will throw an error that we can catch on the JavaScript and show the user.

Please sign in to comment.