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 0000000000000000000000000000000000000000..bf98703a7739a0ad879b7b83c40a9d3d42bd9d61 --- /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 cf2f527a7a874c8ea740b218fdd6dccf350151ea..efff30f8fa0f523ac84ebac263d0eb3372fc31d4 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 a4ad149c6dd714f3416226063c5332796cd8758f..116646c3b2f4b7ba67e604ff90bf2d2a41c3b19c 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");