From b9e5da0c9c248f767697b89ee619855f0dd9ee49 Mon Sep 17 00:00:00 2001 From: Marc K Date: Fri, 25 Sep 2020 23:45:10 +0200 Subject: [PATCH] Fix continuous auto-focus When autoFocus is called in continuous modes, the camera focuses only once and continuous focus does not work until auto focus is cancelled. This could help with #9 and definietly fixes focusing only once in continuous mode. --- app/src/main/java/de/visorapp/visor/VisorActivity.java | 2 +- app/src/main/java/de/visorapp/visor/VisorSurface.java | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/de/visorapp/visor/VisorActivity.java b/app/src/main/java/de/visorapp/visor/VisorActivity.java index 75179d2..aebdede 100644 --- a/app/src/main/java/de/visorapp/visor/VisorActivity.java +++ b/app/src/main/java/de/visorapp/visor/VisorActivity.java @@ -229,7 +229,7 @@ public void onStartTrackingTouch(SeekBar seekBar) { @Override public void onStopTrackingTouch(SeekBar seekBar) { - + mVisorView.autoFocusCamera(); // will not be applied in continuous modes } }; /** diff --git a/app/src/main/java/de/visorapp/visor/VisorSurface.java b/app/src/main/java/de/visorapp/visor/VisorSurface.java index caaf964..f353f4d 100644 --- a/app/src/main/java/de/visorapp/visor/VisorSurface.java +++ b/app/src/main/java/de/visorapp/visor/VisorSurface.java @@ -610,7 +610,6 @@ public void enableCamera() { toggleCameraPreview(); } - autoFocusCamera(); if (mSharedPreferences.getBoolean(getResources().getString(R.string.key_preference_auto_torch), false)) { turnFlashlightOn(); } @@ -712,7 +711,7 @@ public void playActionSoundShutter() { * It will autofocus just a single time. */ public void autoFocusCamera() { - if (mState != STATE_PREVIEW) return; + if (mState != STATE_PREVIEW || mCamera.getParameters().getFocusMode().contains("continuous")) return; try { mCamera.cancelAutoFocus(); @@ -790,6 +789,8 @@ public void toggleAutoFocusMode() { if (currentMode.equals(FOCUS_MODE_AUTO)) { Toast.makeText(VisorSurface.this.getContext(), R.string.text_autofocus_enabled, Toast.LENGTH_SHORT).show(); cameraParameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE); + // make sure that no focusing is in progress or CONTINUOUS mode will not work + mCamera.cancelAutoFocus(); } else { Toast.makeText(VisorSurface.this.getContext(), R.string.text_autofocus_disabled, Toast.LENGTH_SHORT).show(); cameraParameters.setFocusMode(FOCUS_MODE_AUTO);