From 0f3adeef4629685e6a82f0fa5e05472d7cd54adf Mon Sep 17 00:00:00 2001 From: althafvly Date: Fri, 14 Oct 2022 09:34:44 +0530 Subject: [PATCH] Camera: Use alternative flash default on xiaomi, fairphone and gigaset - Fixes https://gitlab.e.foundation/e/backlog/-/issues/5818 Change-Id: Id2c1f9f5cc647017fc0469ff3009cb0f9acbe6ca --- .../opencamera/DeviceSettings.java | 34 +++++++++++++++++++ .../sourceforge/opencamera/MainActivity.java | 9 ++++- .../opencamera/MyPreferenceFragment.java | 12 +++++++ 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/net/sourceforge/opencamera/DeviceSettings.java diff --git a/app/src/main/java/net/sourceforge/opencamera/DeviceSettings.java b/app/src/main/java/net/sourceforge/opencamera/DeviceSettings.java new file mode 100644 index 000000000..bf98703a7 --- /dev/null +++ b/app/src/main/java/net/sourceforge/opencamera/DeviceSettings.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2022 E FOUNDATION + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.sourceforge.opencamera; + +import android.os.Build; + +import java.util.Locale; + +public class DeviceSettings { + + /** Returns whether the the device uses fake flash in Camera API2. + * Some older device have issues in low light. + */ + public static boolean deviceUsingFakeFlash() { + final boolean is_xiaomi = Build.MANUFACTURER.toLowerCase(Locale.US).contains("xiaomi"); + final boolean is_fairphone = Build.MANUFACTURER.toLowerCase(Locale.US).contains("fairphone"); + final boolean is_GS290 = Build.DEVICE != null && Build.DEVICE.equals("GS290"); + return is_fairphone || is_xiaomi || is_GS290; + } +} diff --git a/app/src/main/java/net/sourceforge/opencamera/MainActivity.java b/app/src/main/java/net/sourceforge/opencamera/MainActivity.java index cf2f527a7..efff30f8f 100644 --- a/app/src/main/java/net/sourceforge/opencamera/MainActivity.java +++ b/app/src/main/java/net/sourceforge/opencamera/MainActivity.java @@ -863,7 +863,7 @@ public class MainActivity extends AppCompatActivity { void setDeviceDefaults() { if( MyDebug.LOG ) Log.d(TAG, "setDeviceDefaults"); - //SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); + final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); //boolean is_samsung = Build.MANUFACTURER.toLowerCase(Locale.US).contains("samsung"); //boolean is_oneplus = Build.MANUFACTURER.toLowerCase(Locale.US).contains("oneplus"); //boolean is_nexus = Build.MODEL.toLowerCase(Locale.US).contains("nexus"); @@ -878,6 +878,13 @@ public class MainActivity extends AppCompatActivity { //Log.d(TAG, "is_pixel_phone? " + is_pixel_phone); //Log.d(TAG, "is_pixel_xl_phone? " + is_pixel_xl_phone); }*/ + if ( DeviceSettings.deviceUsingFakeFlash() ) { + if( MyDebug.LOG ) + Log.d(TAG, "set fake flash for camera2"); + final SharedPreferences.Editor editor = sharedPreferences.edit(); + editor.putBoolean(PreferenceKeys.Camera2FakeFlashPreferenceKey, true); + editor.apply(); + } /*if( is_samsung || is_oneplus ) { // The problems we used to have on Samsung Galaxy devices are now fixed, by setting // TEMPLATE_PREVIEW for the precaptureBuilder in CameraController2. This also fixes the diff --git a/app/src/main/java/net/sourceforge/opencamera/MyPreferenceFragment.java b/app/src/main/java/net/sourceforge/opencamera/MyPreferenceFragment.java index a4ad149c6..116646c3b 100644 --- a/app/src/main/java/net/sourceforge/opencamera/MyPreferenceFragment.java +++ b/app/src/main/java/net/sourceforge/opencamera/MyPreferenceFragment.java @@ -211,6 +211,18 @@ public class MyPreferenceFragment extends PreferenceFragment implements OnShared pg.removePreference(pref); } + if ( DeviceSettings.deviceUsingFakeFlash() ) { + if( MyDebug.LOG ) + Log.d(TAG, "set fake flash for camera2"); + Preference pref = findPreference(PreferenceKeys.Camera2FakeFlashPreferenceKey); + pref.setDefaultValue(true); + pref.setEnabled(false); + + final SharedPreferences.Editor editor = sharedPreferences.edit(); + editor.putBoolean(PreferenceKeys.Camera2FakeFlashPreferenceKey, true); + editor.apply(); + } + if( Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2 ) { // BluetoothLeService requires Android 4.3+ Preference pref = findPreference("preference_screen_remote_control"); -- GitLab