Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Start recognition when autofocus completes (used when continuous autofocus is disabled)
- private Camera.AutoFocusCallback startRecognitionCameraAutoFocusCallback = new Camera.AutoFocusCallback() {
- @Override
- public void onAutoFocus( boolean success, Camera camera )
- {
- startRecognition();
- }
- };
- // Enable 'Start' button when autofocus completes (used when continuous autofocus is disabled)
- private Camera.AutoFocusCallback enableStartButtonCameraAutoFocusCallback = new Camera.AutoFocusCallback() {
- @Override
- public void onAutoFocus( boolean success, Camera camera )
- {
- startButton.setText( BUTTON_TEXT_START );
- startButton.setEnabled( true );
- }
- };
- // Start autofocus (used when continuous autofocus is disabled)
- private void autoFocus( Camera.AutoFocusCallback callback )
- {
- if( camera != null ) {
- try {
- camera.autoFocus( callback );
- } catch( Exception e ) {
- Log.e( getString( R.string.app_name ), "Error: " + e.getMessage() );
- }
- }
- }
- // Choosing autofocus or continuous focus and whether to start recognition immediately or after autofocus or manually
- if( disableContinuousAutofocus ||
- !parameters.getSupportedFocusModes().contains( Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO ) ) {
- // No continuous focus
- if( startRecognitionWhenReady ) {
- // Start recognition (if you look inside onStartButtonClick it is actually delayed
- // till autofocus completes
- onStartButtonClick( startButton );
- startRecognitionWhenReady = false;
- } else {
- // Just focus and enable 'Start' button
- autoFocus( enableStartButtonCameraAutoFocusCallback );
- }
- } else {
- // Continuous focus. Have to use some Magic. Some devices expect preview to actually
- // start before enabling continuous focus has any effect. So we wait for the camera to
- // actually start preview
- handler.postDelayed( new Runnable() {
- public void run()
- {
- Camera _camera = MainActivity.this.camera;
- Camera.Parameters parameters = _camera.getParameters();
- parameters.setFocusMode( Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO );
- _camera.setParameters( parameters );
- if( startRecognitionWhenReady ) {
- // Give some time for the camera to focus and start recognition
- handler.postDelayed( new Runnable() {
- public void run()
- {
- onStartButtonClick( startButton );
- }
- }, 300 );
- startRecognitionWhenReady = false;
- } else {
- // Just enable 'Start' button
- startButton.setEnabled( true );
- startButton.setText( BUTTON_TEXT_START );
- }
- }
- }, 300 );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement