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

Commit 3f1330dd authored by Mohammed Althaf T's avatar Mohammed Althaf T 😊
Browse files

Merge branch '6465-master-slow_focus' into 'master'

camera: Camera improvements

See merge request !63
parents 691b1bd3 6186e83d
Loading
Loading
Loading
Loading
Loading
+15 −12
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@ apply plugin: 'com.android.application'
apply plugin: 'org.jetbrains.kotlin.android'

android {
    compileSdkVersion 31
    compileSdkVersion 33
    compileOptions.encoding = 'UTF-8'

    compileOptions {
@@ -23,7 +23,7 @@ android {
    defaultConfig {
        applicationId "foundation.e.camera"
        minSdkVersion 25
        targetSdkVersion 31
        targetSdkVersion 33

        renderscriptTargetApi 21
        //renderscriptSupportModeEnabled true // don't use support library as it bloats the APK, and we don't need pre-4.4 support
@@ -56,28 +56,31 @@ android {
        abortOnError false
        checkReleaseBuilds false
    }
    buildFeatures {
        renderScript true
        buildConfig true
    }
    namespace 'foundation.e.camera'
    //useLibrary 'android.test.mock'

}

dependencies {
    //noinspection GradleCompatible
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation "androidx.constraintlayout:constraintlayout:2.1.3"
    implementation "androidx.constraintlayout:constraintlayout:2.1.4"
    implementation "org.greenrobot:eventbus:3.3.1"
    implementation 'androidx.core:core-ktx:1.8.0'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'

    // appcompat version must be 1.4.0 or later to satisfy emoji policy!
    implementation 'androidx.appcompat:appcompat:1.4.1'
    implementation 'androidx.appcompat:appcompat:1.6.1'

    implementation 'androidx.exifinterface:exifinterface:1.3.3'
    implementation 'androidx.exifinterface:exifinterface:1.3.7'
    implementation 'foundation.e:elib:0.0.1-alpha11'

    testImplementation 'junit:junit:4.13.1'
    testImplementation 'junit:junit:4.13.2'

    // newer AndroidJUnit4 InstrumentedTest
    androidTestImplementation "androidx.test:runner:1.4.0"
    androidTestImplementation "androidx.test:rules:1.4.0"
    androidTestImplementation "androidx.test.espresso:espresso-core:3.4.0"
    androidTestImplementation "androidx.test:runner:1.5.2"
    androidTestImplementation "androidx.test:rules:1.5.0"
    androidTestImplementation "androidx.test.espresso:espresso-core:3.5.1"
}
+1 −1
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="foundation.e.camera"
    android:versionCode="87"
    android:versionName="1.51.1"
    android:installLocation="auto"
@@ -40,6 +39,7 @@
        android:name="net.sourceforge.opencamera.OpenCameraApplication"
        android:theme="@style/AppTheme"
        android:largeHeap="true"
        android:hardwareAccelerated="true"
        android:requestLegacyExternalStorage="true"
        >
        <!-- should not change the android:name, including moving to a subpackage - see http://android-developers.blogspot.co.uk/2011/06/things-that-cannot-change.html -->
+1 −1
Original line number Diff line number Diff line
@@ -2435,7 +2435,7 @@ public class MyApplicationInterface extends BasicApplicationInterface {
                try {
                    retriever.release();
                }
                catch(RuntimeException ex) {
                catch(RuntimeException | IOException ex) {
                    // ignore
                }
                try {
+7 −11
Original line number Diff line number Diff line
@@ -814,18 +814,14 @@ public class MyPreferenceFragment extends PreferenceFragment implements OnShared

        {
            final Preference pref = findPreference("preference_privacy_policy");
            pref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(Preference arg0) {
            pref.setOnPreferenceClickListener(arg0 -> {
                if( pref.getKey().equals("preference_privacy_policy") ) {
                    if( MyDebug.LOG )
                        Log.d(TAG, "user clicked privacy policy");
                    MainActivity main_activity = (MainActivity)MyPreferenceFragment.this.getActivity();
                    main_activity.launchOnlinePrivacyPolicy();
                        return false;
                }
                return false;
                }
            });
        }

+31 −9
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ import android.view.Display;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.TextureView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
@@ -65,6 +66,8 @@ import java.util.Locale;
import java.util.Queue;
import java.util.concurrent.Executor;

import foundation.e.camera.R;

/** Provides support using Android 5's Camera 2 API
 *  android.hardware.camera2.*.
 */
@@ -100,6 +103,8 @@ public class CameraController2 extends CameraController {
    private long min_exposure_time;
    private long max_exposure_time;

    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,
@@ -180,7 +185,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 = 1000; // 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;
@@ -265,8 +270,8 @@ public class CameraController2 extends CameraController {
    private static final int STATE_WAITING_FAKE_PRECAPTURE_DONE = 5;
    private int state = STATE_NORMAL;
    private long precapture_state_change_time_ms = -1; // time we changed state for precapture modes
    private static final long precapture_start_timeout_c = 2000;
    private static final long precapture_done_timeout_c = 3000;
    private static final long precapture_start_timeout_c = 500;
    private static final long precapture_done_timeout_c = 1000;

    private boolean use_fake_precapture; // see CameraController.setUseCamera2FakeFlash() for details - this is the user/application setting, see use_fake_precapture_mode for whether fake precapture is enabled (as we may do this for other purposes, e.g., front screen flash)
    private boolean use_fake_precapture_mode; // true if either use_fake_precapture is true, or we're temporarily using fake precapture mode (e.g., for front screen flash or exposure bracketing)
@@ -8195,15 +8200,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++;
                        }
@@ -8255,10 +8263,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;
@@ -8448,6 +8458,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 ) {
Loading