From 945b845a44ca7fd10c6da93f1a39d39e2c503934 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 6 Nov 2016 12:46:29 +0100 Subject: [PATCH] add a new max photo resolution limit of 2 mpx --- .../com/simplemobiletools/camera/Config.java | 18 +++++++++++++-- .../simplemobiletools/camera/Constants.java | 3 ++- .../com/simplemobiletools/camera/Preview.java | 14 +---------- .../camera/activities/SettingsActivity.kt | 23 +++++++++++++++++-- app/src/main/res/values/array.xml | 1 + 5 files changed, 41 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/com/simplemobiletools/camera/Config.java b/app/src/main/java/com/simplemobiletools/camera/Config.java index 63c25643..29b4d69e 100644 --- a/app/src/main/java/com/simplemobiletools/camera/Config.java +++ b/app/src/main/java/com/simplemobiletools/camera/Config.java @@ -48,12 +48,26 @@ public class Config { mPrefs.edit().putBoolean(Constants.FORCE_RATIO, enabled).apply(); } + // todo: delete this + public int getMaxResolution() { + return mPrefs.getInt(Constants.MAX_RESOLUTION, -1); + } + public int getMaxPhotoResolution() { - return mPrefs.getInt(Constants.MAX_RESOLUTION, 1); + return mPrefs.getInt(Constants.MAX_PHOTO_RESOLUTION, getOldDefaultResolution()); } public void setMaxPhotoResolution(int maxRes) { - mPrefs.edit().putInt(Constants.MAX_RESOLUTION, maxRes).apply(); + mPrefs.edit().putInt(Constants.MAX_PHOTO_RESOLUTION, maxRes).apply(); + } + + private int getOldDefaultResolution() { + final int index = getMaxResolution(); + switch (index) { + case 1: return 9000000; + case 2: return 0; + default: return 6000000; + } } public int getMaxVideoResolution() { diff --git a/app/src/main/java/com/simplemobiletools/camera/Constants.java b/app/src/main/java/com/simplemobiletools/camera/Constants.java index b70a4154..c484524e 100644 --- a/app/src/main/java/com/simplemobiletools/camera/Constants.java +++ b/app/src/main/java/com/simplemobiletools/camera/Constants.java @@ -14,8 +14,9 @@ public class Constants { public static final String SAVE_PHOTOS = "save_photos"; public static final String SOUND = "sound"; public static final String FORCE_RATIO = "force_ratio"; - public static final String MAX_RESOLUTION = "max_resolution"; + public static final String MAX_PHOTO_RESOLUTION = "max_photo_resolution"; public static final String MAX_VIDEO_RESOLUTION = "max_video_resolution"; + public static final String MAX_RESOLUTION = "max_resolution"; public static final String LAST_USED_CAMERA = "last_used_camera"; public static final String LAST_FLASHLIGHT_STATE = "last_flashlight_state"; } diff --git a/app/src/main/java/com/simplemobiletools/camera/Preview.java b/app/src/main/java/com/simplemobiletools/camera/Preview.java index 2790130c..c9bebe8d 100644 --- a/app/src/main/java/com/simplemobiletools/camera/Preview.java +++ b/app/src/main/java/com/simplemobiletools/camera/Preview.java @@ -318,7 +318,7 @@ public class Preview extends ViewGroup }; private Camera.Size getOptimalPictureSize() { - final int maxResolution = getMaxPhotoResolution(); + final int maxResolution = Config.newInstance(mContext).getMaxPhotoResolution(); final List sizes = mParameters.getSupportedPictureSizes(); Collections.sort(sizes, new SizesComparator()); Camera.Size maxSize = sizes.get(0); @@ -333,18 +333,6 @@ public class Preview extends ViewGroup return maxSize; } - private int getMaxPhotoResolution() { - final int maxRes = Config.newInstance(mContext).getMaxPhotoResolution(); - switch (maxRes) { - case 0: - return 6000000; - case 1: - return 9000000; - default: - return 0; - } - } - private boolean isProperResolution(Camera.Size size, int maxRes) { return maxRes == 0 || size.width * size.height < maxRes; } diff --git a/app/src/main/kotlin/com/simplemobiletools/camera/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/camera/activities/SettingsActivity.kt index f2158ee1..ff2e8cb8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/camera/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/camera/activities/SettingsActivity.kt @@ -127,17 +127,36 @@ class SettingsActivity : SimpleActivity() { } private fun setupMaxPhotoResolution() { - settings_max_photo_resolution.setSelection(mConfig.maxPhotoResolution) + settings_max_photo_resolution.setSelection(getMaxPhotoSelection()) settings_max_photo_resolution.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { override fun onNothingSelected(parent: AdapterView<*>?) { } override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) { - mConfig.maxPhotoResolution = settings_max_photo_resolution.selectedItemPosition + mConfig.maxPhotoResolution = getMaxPhotoPx(settings_max_photo_resolution.selectedItemPosition) } } } + private fun getMaxPhotoSelection(): Int { + val maxRes = mConfig.maxPhotoResolution + return when (maxRes) { + 3000000 -> 0 + 6000000 -> 1 + 9000000 -> 2 + else -> 3 + } + } + + private fun getMaxPhotoPx(index: Int): Int { + return when (index) { + 0 -> 3000000 + 1 -> 6000000 + 2 -> 9000000 + else -> 0 + } + } + private fun setupMaxVideoResolution() { settings_max_video_resolution.setSelection(mConfig.maxVideoResolution) settings_max_video_resolution.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { diff --git a/app/src/main/res/values/array.xml b/app/src/main/res/values/array.xml index 92d6e8fc..df996e54 100644 --- a/app/src/main/res/values/array.xml +++ b/app/src/main/res/values/array.xml @@ -1,6 +1,7 @@ + 2 MP 5 MP 8 MP @string/no_limit