diff --git a/app/src/main/java/net/sourceforge/opencamera/MainActivity.java b/app/src/main/java/net/sourceforge/opencamera/MainActivity.java index de596e2655468af4d1bda138eed292696159383e..d237c74dcbecd03deec3cb74687fa77664756010 100644 --- a/app/src/main/java/net/sourceforge/opencamera/MainActivity.java +++ b/app/src/main/java/net/sourceforge/opencamera/MainActivity.java @@ -998,22 +998,7 @@ public class MainActivity extends AppCompatActivity { } } - String[] defaultResolutions = getResources().getStringArray( - R.array.config_e_os_camera_default_resolution_lens); - SharedPreferences.Editor editor = sharedPreferences.edit(); - - for (String entry : defaultResolutions) { - if (!entry.matches("\\d+:\\d+x\\d+")) continue; - - String[] mainParts = entry.split(":"); - String[] resParts = mainParts[1].split("x"); - int cameraId = Integer.parseInt(mainParts[0]); - String resolution = resParts[0] + " " + resParts[1]; - - editor.putString(PreferenceKeys.getResolutionPreferenceKey(cameraId), resolution); - } - - editor.apply(); + updateCameraResolution(); } /** Switches modes if required, if called from a relevant intent/tile. @@ -3044,6 +3029,10 @@ public class MainActivity extends AppCompatActivity { if( preview.getCurrentPictureSize() != null ) { bundle.putInt("resolution_width", preview.getCurrentPictureSize().width); bundle.putInt("resolution_height", preview.getCurrentPictureSize().height); + SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this); + if (pref.getBoolean("isFirstTimeResolution_" + preview.getCameraId(), true)) { + updateCameraResolution(); + } } //List video_quality = this.preview.getVideoQualityHander().getSupportedVideoQuality(); @@ -3155,6 +3144,38 @@ public class MainActivity extends AppCompatActivity { getFragmentManager().beginTransaction().add(android.R.id.content, fragment, "PREFERENCE_FRAGMENT").addToBackStack(null).commitAllowingStateLoss(); } + private void updateCameraResolution() { + SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this); + SharedPreferences.Editor editor = pref.edit(); + String[] defaultResolutions = getResources().getStringArray( + R.array.config_e_os_camera_default_resolution_lens); + for (String entry : defaultResolutions) { + if (!entry.matches("\\d+:\\d+x\\d+")) continue; + + String[] mainParts = entry.split(":"); + String[] resParts = mainParts[1].split("x"); + int cameraId = Integer.parseInt(mainParts[0]); + String resolution = resParts[0] + " " + resParts[1]; + + boolean existing = true; + if (preview != null && preview.getSupportedPictureSizes(false) != null) { + List supportedResolutions = + preview.getSupportedPictureSizes(false); + String highestResolution = supportedResolutions.get(0).width + " " + + supportedResolutions.get(0).height; + String currentResolution = pref.getString( + PreferenceKeys.getResolutionPreferenceKey(cameraId), ""); + existing = highestResolution.equals(currentResolution) && cameraId == preview.getCameraId(); + } + if (existing) { + editor.putString(PreferenceKeys.getResolutionPreferenceKey(cameraId), resolution); + editor.putBoolean("isFirstTimeResolution_" + cameraId, false); + } + } + + editor.apply(); + } + public void updateForSettings(boolean update_camera) { updateForSettings(update_camera, null); }