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

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

camera: Improve camera UX for murena two

parent 064005b8
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@
            android:name="net.sourceforge.opencamera.MainActivity"
            android:configChanges="orientation|screenSize|keyboardHidden"
            android:theme="@style/AppTheme"
            android:launchMode="singleInstance"
            android:clearTaskOnLaunch="true"
            android:exported="true"
            >
+4 −0
Original line number Diff line number Diff line
@@ -38,4 +38,8 @@ public class DeviceSettings {
        final boolean isOne = Build.DEVICE.equals("one") || Build.DEVICE.equals("X2");
        return isMurena && isOne;
    }

    public static boolean isMurenaTwo() {
        return Build.DEVICE.toLowerCase(Locale.US).contains("two");
    }
}
+28 −0
Original line number Diff line number Diff line
@@ -105,6 +105,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
@@ -185,6 +186,11 @@ public class MainActivity extends AppCompatActivity {
    public static volatile boolean test_preview_want_no_limits; // test flag, if set to true then instead use test_preview_want_no_limits_value; needs to be static, as it needs to be set before activity is created to take effect
    public static volatile boolean test_preview_want_no_limits_value;

    private boolean murenaTwoHwKill = false;

    private Handler handler;
    private Runnable retryRunnable = null;

    // whether this is a multi-camera device (note, this isn't simply having more than 1 camera, but also having more than one with the same facing)
    // note that in most cases, code should check the MultiCamButtonPreferenceKey preference as well as the is_multi_cam flag,
    // this can be done via isMultiCamEnabled().
@@ -358,6 +364,8 @@ public class MainActivity extends AppCompatActivity {
        magneticSensor = new MagneticSensor(this);
        //speechControl = new SpeechControl(this);

        handler = new Handler();

        // determine whether we support Camera2 API
        // must be done before setDeviceDefaults()
        initCamera2Support();
@@ -1594,6 +1602,26 @@ public class MainActivity extends AppCompatActivity {
        else {
            mainUI.onKeyUp(keyCode, event);
        }

        if (!camera_in_background && keyCode == 131 && DeviceSettings.isMurenaTwo()) {
            String cameraState = Utils.getProperty("persist.sys.hwswitch.state", null);
            if (cameraState == null) return super.onKeyUp(keyCode, event);

            if (retryRunnable != null) {
                handler.removeCallbacks(retryRunnable);
            }

            murenaTwoHwKill = Objects.equals(cameraState, "1");
            retryRunnable = () -> {
                if (!murenaTwoHwKill) {
                    preview.retryOpenCamera();
                } else {
                    restartOpenCamera();
                }
            };
            handler.postDelayed(retryRunnable, murenaTwoHwKill ? 200 : 5000);
        }

        return super.onKeyUp(keyCode, event);
    }

+1 −0
Original line number Diff line number Diff line
@@ -2633,6 +2633,7 @@ public class MyApplicationInterface extends BasicApplicationInterface {

    @Override
    public void onCameraError() {
        if (DeviceSettings.isMurenaTwo()) return;
        main_activity.getPreview().showToast(null, R.string.camera_error);
    }

+19 −0
Original line number Diff line number Diff line
package net.sourceforge.opencamera;

import android.os.Build;

import java.lang.reflect.Method;
import java.util.Locale;

public class Utils {
    public static String getProperty(String key, String defaultValue) {
        try {
            Class<?> systemProperties = Class.forName("android.os.SystemProperties");
            Method get = systemProperties.getMethod("get", String.class, String.class);
            return (String) get.invoke(null, key, defaultValue);
        } catch (Exception e) {
            e.printStackTrace();
            return defaultValue;
        }
    }
}
Loading