Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2f2fb5dd authored by Mohammed Althaf T's avatar Mohammed Althaf T 😊
Browse files

camera: alert user if camera is unable to focus

parent 4c123e2a
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -993,6 +993,7 @@ public class MainActivity extends AppCompatActivity implements PreferenceFragmen

        String[] defaultResolutions = getResources().getStringArray(
                R.array.config_e_os_camera_default_resolution_lens);
        SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
        SharedPreferences.Editor editor = sharedPreferences.edit();

        for (String entry : defaultResolutions) {
+28 −7
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@ package net.sourceforge.opencamera.cameracontroller;
import net.sourceforge.opencamera.ContinuousBurstImageRunningAction;
import net.sourceforge.opencamera.HDRProcessor;
import net.sourceforge.opencamera.MyDebug;
import net.sourceforge.opencamera.R;

import java.nio.ByteBuffer;
import java.util.ArrayList;
@@ -70,6 +71,7 @@ import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.TextureView;
import android.view.WindowMetrics;
import android.widget.Toast;

import org.greenrobot.eventbus.EventBus;

@@ -116,6 +118,8 @@ public class CameraController2 extends CameraController {
    //private boolean supports_low_light_boost;

    private boolean supports_tonemap_preset_curve;
    private int toastCounter = 0;

    private final static int tonemap_log_max_curve_points_c = 64;
    private final static float [] jtvideo_values_base = new float[] {
            0.00f,    0.00f,
@@ -196,7 +200,7 @@ public class CameraController2 extends CameraController {
    private boolean previewIsVideoMode;
    private AutoFocusCallback autofocus_cb;
    private long autofocus_time_ms = -1; // time we set autofocus_cb to non-null
    private static final long autofocus_timeout_c = 250; // timeout for calling autofocus_cb (applies for both auto and continuous focus)
    private static final long autofocus_timeout_c = 500; // timeout for calling autofocus_cb (applies for both auto and continuous focus)
    private boolean capture_follows_autofocus_hint;
    private boolean ready_for_capture;
    private FaceDetectionListener face_detection_listener;
@@ -8879,15 +8883,18 @@ public class CameraController2 extends CameraController {
                        // need to check af_state != null, I received Google Play crash in 1.33 where it was null
                        boolean focus_success = af_state != null && ( af_state == CaptureResult.CONTROL_AF_STATE_FOCUSED_LOCKED || af_state == CaptureResult.CONTROL_AF_STATE_PASSIVE_FOCUSED );
                        if( MyDebug.LOG ) {
                            if( focus_success )
                            if( focus_success ) {
                                Log.d(TAG, "autofocus success");
                            else
                            } else {
                                Log.d(TAG, "autofocus failed");
                            if( af_state == null )
                                onFocusFailed();
                            }
                            if( af_state == null ) {
                                Log.e(TAG, "continuous focus mode but af_state is null");
                            else
                            } else {
                                Log.d(TAG, "af_state: " + af_state);
                            }
                        }
                        if( af_state == null ) {
                            test_af_state_null_focus++;
                        }
@@ -8939,10 +8946,12 @@ public class CameraController2 extends CameraController {
                    ) {
                        boolean focus_success = af_state == CaptureResult.CONTROL_AF_STATE_FOCUSED_LOCKED || af_state == CaptureResult.CONTROL_AF_STATE_PASSIVE_FOCUSED;
                        if( MyDebug.LOG ) {
                            if( focus_success )
                            if( focus_success ) {
                                Log.d(TAG, "onCaptureCompleted: autofocus success");
                            else
                            } else {
                                Log.d(TAG, "onCaptureCompleted: autofocus failed");
                                onFocusFailed();
                            }
                            Log.d(TAG, "af_state: " + af_state);
                        }
                        state = STATE_NORMAL;
@@ -9122,6 +9131,18 @@ public class CameraController2 extends CameraController {
            }
        }

        private void onFocusFailed() {
            // Show only if focus failed twice.
            if (toastCounter == 1) {
                Toast.makeText(context,
                        R.string.preference_failed_focus_mode_message,
                        Toast.LENGTH_SHORT).show();
                toastCounter = 0;
            } else {
                toastCounter++;
            }
        }

        private void handleContinuousFocusMove(CaptureResult result) {
            Integer af_state = result.get(CaptureResult.CONTROL_AF_STATE);
            if( af_state != null && af_state == CaptureResult.CONTROL_AF_STATE_PASSIVE_SCAN && af_state != last_af_state ) {
+1 −0
Original line number Diff line number Diff line
@@ -783,6 +783,7 @@
    <string name="exposure_unlock">Unlock exposure</string>

    <string name="preference_nr_mode_low_light_message">Low light mode: please hold the camera steady</string>
    <string name="preference_failed_focus_mode_message">Please hold the camera steady for better photos.</string>

    <string name="photo_mode_panorama">Pano</string> <!-- keep short, as this shows in the popup menu; probably shouldn't be translated? -->
    <string name="photo_mode_panorama_full">Panorama</string>