From c25e4f9f889880ca42b6668406bd873d4896c31f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Gillsj=C3=B6?= Date: Tue, 27 Oct 2020 12:02:38 +0100 Subject: [PATCH] Fixed index error when previous video size no longer is a valid option. --- .../math/videoimucapture/CameraSettingsManager.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/android_app/app/src/main/java/se/lth/math/videoimucapture/CameraSettingsManager.java b/android_app/app/src/main/java/se/lth/math/videoimucapture/CameraSettingsManager.java index 075ce5b..ba64984 100644 --- a/android_app/app/src/main/java/se/lth/math/videoimucapture/CameraSettingsManager.java +++ b/android_app/app/src/main/java/se/lth/math/videoimucapture/CameraSettingsManager.java @@ -32,7 +32,6 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.stream.Collectors; @@ -321,6 +320,16 @@ private void updatePreferenceList(ListPreference listPreference, boolean useSens String[] stringSizes = validSizes.stream().map(Object::toString).toArray(String[]::new); int defaultIndex = validSizes.indexOf(getSize()); + // The previous choice was from the full list, this size is not present in the sensor aspect ratio list. + if (defaultIndex == -1) { + Size closestSize = CameraUtils.chooseOptimalSize( + validSizes.toArray(new Size[0]), + getSize().getWidth(), + getSize().getHeight(), + new Size(mArraySensorSize.width(), mArraySensorSize.height())); + defaultIndex = validSizes.indexOf(closestSize); + } + listPreference.setEntryValues(stringSizes); listPreference.setEntries(stringSizes); listPreference.setValueIndex(defaultIndex);