From 2d4174c23ee59e324079c24758957cef7d871761 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 26 Jul 2016 20:14:01 +0200 Subject: [PATCH] allow setting max video resolution, closes #7 --- .../com/simplemobiletools/camera/Config.java | 12 +++++- .../simplemobiletools/camera/Constants.java | 1 + .../com/simplemobiletools/camera/Preview.java | 41 +++++++++++++++---- .../camera/activities/SettingsActivity.java | 25 +++++++---- app/src/main/res/layout/activity_settings.xml | 37 ++++++++++++++--- app/src/main/res/values-it/strings.xml | 4 +- app/src/main/res/values-ja/strings.xml | 4 +- app/src/main/res/values-ru/strings.xml | 4 +- app/src/main/res/values-sv/strings.xml | 4 +- app/src/main/res/values/array.xml | 9 +++- app/src/main/res/values/strings.xml | 4 +- 11 files changed, 117 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/com/simplemobiletools/camera/Config.java b/app/src/main/java/com/simplemobiletools/camera/Config.java index a72bbfa6..200d8c19 100644 --- a/app/src/main/java/com/simplemobiletools/camera/Config.java +++ b/app/src/main/java/com/simplemobiletools/camera/Config.java @@ -54,14 +54,22 @@ public class Config { mPrefs.edit().putBoolean(Constants.FORCE_RATIO, enabled).apply(); } - public int getMaxResolution() { + public int getMaxPhotoResolution() { return mPrefs.getInt(Constants.MAX_RESOLUTION, 1); } - public void setMaxResolution(int maxRes) { + public void setMaxPhotoResolution(int maxRes) { mPrefs.edit().putInt(Constants.MAX_RESOLUTION, maxRes).apply(); } + public int getMaxVideoResolution() { + return mPrefs.getInt(Constants.MAX_VIDEO_RESOLUTION, 1); + } + + public void setMaxVideoResolution(int maxRes) { + mPrefs.edit().putInt(Constants.MAX_VIDEO_RESOLUTION, maxRes).apply(); + } + public boolean getIsSoundEnabled() { return mPrefs.getBoolean(Constants.SOUND, true); } diff --git a/app/src/main/java/com/simplemobiletools/camera/Constants.java b/app/src/main/java/com/simplemobiletools/camera/Constants.java index 8bbe8992..86ac9fb7 100644 --- a/app/src/main/java/com/simplemobiletools/camera/Constants.java +++ b/app/src/main/java/com/simplemobiletools/camera/Constants.java @@ -14,4 +14,5 @@ public class Constants { 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_VIDEO_RESOLUTION = "max_video_resolution"; } diff --git a/app/src/main/java/com/simplemobiletools/camera/Preview.java b/app/src/main/java/com/simplemobiletools/camera/Preview.java index ae92f30d..427ca70e 100644 --- a/app/src/main/java/com/simplemobiletools/camera/Preview.java +++ b/app/src/main/java/com/simplemobiletools/camera/Preview.java @@ -260,12 +260,12 @@ public class Preview extends ViewGroup implements SurfaceHolder.Callback, View.O }; private Camera.Size getOptimalPictureSize() { - final int maxResolution = getMaxResolution(); + final int maxResolution = getMaxPhotoResolution(); final List sizes = mParameters.getSupportedPictureSizes(); Collections.sort(sizes, new SizesComparator()); Camera.Size maxSize = sizes.get(0); for (Camera.Size size : sizes) { - final boolean isProperRatio = isProperRatio(size); + final boolean isProperRatio = !mForceAspectRatio || isProperRatio(size); final boolean isProperResolution = isProperResolution(size, maxResolution); if (isProperResolution && isProperRatio) { maxSize = size; @@ -275,8 +275,8 @@ public class Preview extends ViewGroup implements SurfaceHolder.Callback, View.O return maxSize; } - private int getMaxResolution() { - final int maxRes = Config.newInstance(getContext()).getMaxResolution(); + private int getMaxPhotoResolution() { + final int maxRes = Config.newInstance(getContext()).getMaxPhotoResolution(); switch (maxRes) { case 0: return 6000000; @@ -291,6 +291,20 @@ public class Preview extends ViewGroup implements SurfaceHolder.Callback, View.O return maxRes == 0 || size.width * size.height < maxRes; } + private int getMaxVideoResolution() { + final int maxRes = Config.newInstance(getContext()).getMaxVideoResolution(); + switch (maxRes) { + case 0: + return 400000; + case 1: + return 1000000; + case 2: + return 2100000; + default: + return 0; + } + } + private boolean isProperRatio(Camera.Size size) { final float currRatio = (float) size.height / size.width; float wantedRatio = (float) 3 / 4; @@ -301,15 +315,23 @@ public class Preview extends ViewGroup implements SurfaceHolder.Callback, View.O } private Camera.Size getOptimalVideoSize() { + final int maxResolution = getMaxVideoResolution(); final List sizes = getSupportedVideoSizes(); Collections.sort(sizes, new SizesComparator()); Camera.Size maxSize = sizes.get(0); - for (Camera.Size size : sizes) { - final boolean isProperRatio = isProperRatio(size); - if (isProperRatio) { + final int cnt = sizes.size(); + for (int i = 0; i < cnt; i++) { + Camera.Size size = sizes.get(i); + final boolean isProperRatio = !mForceAspectRatio || isProperRatio(size); + final boolean isProperResolution = isProperResolution(size, maxResolution); + if (isProperResolution && isProperRatio) { maxSize = size; break; } + + if (i == cnt - 1) { + Utils.showToast(getContext(), R.string.no_valid_resolution_found); + } } return maxSize; } @@ -508,7 +530,9 @@ public class Preview extends ViewGroup implements SurfaceHolder.Callback, View.O if (mSetupPreviewAfterMeasure) { mSetupPreviewAfterMeasure = false; - mCamera.stopPreview(); + if (mCamera != null) + mCamera.stopPreview(); + setupPreview(); } } @@ -559,6 +583,7 @@ public class Preview extends ViewGroup implements SurfaceHolder.Callback, View.O mSwitchToVideoAsap = false; Camera.Size preferred = mParameters.getPreferredPreviewSizeForVideo(); + if (preferred == null) { final List previewSizes = mParameters.getSupportedPreviewSizes(); Collections.sort(previewSizes, new SizesComparator()); diff --git a/app/src/main/java/com/simplemobiletools/camera/activities/SettingsActivity.java b/app/src/main/java/com/simplemobiletools/camera/activities/SettingsActivity.java index 5119eda8..3762e7be 100644 --- a/app/src/main/java/com/simplemobiletools/camera/activities/SettingsActivity.java +++ b/app/src/main/java/com/simplemobiletools/camera/activities/SettingsActivity.java @@ -19,7 +19,8 @@ public class SettingsActivity extends SimpleActivity { @BindView(R.id.settings_focus_before_capture) SwitchCompat mFocusBeforeCaptureSwitch; @BindView(R.id.settings_sound) SwitchCompat mSoundSwitch; @BindView(R.id.settings_force_ratio) SwitchCompat mForceRatioSwitch; - @BindView(R.id.settings_max_resolution) AppCompatSpinner mMaxResolutionSpinner; + @BindView(R.id.settings_max_photo_resolution) AppCompatSpinner mMaxPhotoResolutionSpinner; + @BindView(R.id.settings_max_video_resolution) AppCompatSpinner mMaxVideoResolutionSpinner; private static Config mConfig; @@ -35,7 +36,8 @@ public class SettingsActivity extends SimpleActivity { setupFocusBeforeCapture(); setupSound(); setupForceRatio(); - setupMaxResolution(); + setupMaxPhotoResolution(); + setupMaxVideoResolution(); } private void setupDarkTheme() { @@ -58,8 +60,12 @@ public class SettingsActivity extends SimpleActivity { mForceRatioSwitch.setChecked(mConfig.getForceRatioEnabled()); } - private void setupMaxResolution() { - mMaxResolutionSpinner.setSelection(mConfig.getMaxResolution()); + private void setupMaxPhotoResolution() { + mMaxPhotoResolutionSpinner.setSelection(mConfig.getMaxPhotoResolution()); + } + + private void setupMaxVideoResolution() { + mMaxVideoResolutionSpinner.setSelection(mConfig.getMaxVideoResolution()); } @OnClick(R.id.settings_dark_theme_holder) @@ -93,9 +99,14 @@ public class SettingsActivity extends SimpleActivity { mConfig.setForceRatioEnabled(mForceRatioSwitch.isChecked()); } - @OnItemSelected(R.id.settings_max_resolution) - public void handleMaxResolution() { - mConfig.setMaxResolution(mMaxResolutionSpinner.getSelectedItemPosition()); + @OnItemSelected(R.id.settings_max_photo_resolution) + public void handleMaxPhotoResolution() { + mConfig.setMaxPhotoResolution(mMaxPhotoResolutionSpinner.getSelectedItemPosition()); + } + + @OnItemSelected(R.id.settings_max_video_resolution) + public void handleMaxVideoResolution() { + mConfig.setMaxVideoResolution(mMaxVideoResolutionSpinner.getSelectedItemPosition()); } private void restartActivity() { diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index e4470604..d7de5950 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -143,7 +143,7 @@ + android:text="@string/max_photo_size"/> + android:entries="@array/max_photo_resolutions"/> + + + + + + + + diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 1003bd0c..be6232b8 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -12,6 +12,7 @@ Non c\'è molto da fare senza l\'accesso alla fotocamera e all\'archiviazione È necessario l\'accesso al microfono per registrare i video Nessuna app galleria disponibile + No valid resolution with selected aspect ratio found, using max resolution Impostazioni @@ -19,7 +20,8 @@ Tocco prolungato per la cattura Messa a fuoco prima della cattura Forza proporzione 16:9 - Limite risoluzione foto + Limite risoluzione foto + Video resolution limit nessuno Suono otturatore diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index 4cadf74c..bc020fbb 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -12,6 +12,7 @@ お使いのカメラやストレージにアクセスしないと、ほとんど行うことはありません ビデオを記録するためにオーディオのアクセス許可が必要です 利用可能なギャラリーアプリがありません + No valid resolution with selected aspect ratio found, using max resolution 設定 @@ -19,7 +20,8 @@ 長押ししてキャプチャする キャプチャ前に再度焦点を合わせる 強制的に 16:9 レシオにする - 写真解像度の限度 + 写真解像度の限度 + Video resolution limit なし シャッター音 diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 7559924b..2e46ba6b 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -12,6 +12,7 @@ Не так много можно сделать без доступа к камере и хранилищу Нам нужно аудио разрешение для записи видео Нет доступного приложения-галереи + No valid resolution with selected aspect ratio found, using max resolution Настройки @@ -19,7 +20,8 @@ Длинное нажатие для захвата Перефокусировка перед захватом Принудительное соотношение сторон 16:9 - Лимит разрешения фото + Лимит разрешения фото + Video resolution limit нет Звук затвора diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index d9651e64..74f07a0b 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -12,6 +12,7 @@ Inte mycket att göra utan tillgång till din kamera och lagring För att spela in video krävs ljudrättigheter Ingen galleri-app finns tillgänglig + No valid resolution with selected aspect ratio found, using max resolution Inställningar @@ -19,7 +20,8 @@ Långtryck för bildtagning Fokusera om innan bildtagning Tvinga 16:9-förhållande - Bildupplösningsgräns + Bildupplösningsgräns + Video resolution limit inga Slutarljud diff --git a/app/src/main/res/values/array.xml b/app/src/main/res/values/array.xml index 25e80ade..92d6e8fc 100644 --- a/app/src/main/res/values/array.xml +++ b/app/src/main/res/values/array.xml @@ -1,8 +1,15 @@ - + 5 MP 8 MP @string/no_limit + + + 480p + 720p + 1080p + @string/no_limit + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 09d210d4..bcc6788e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -12,6 +12,7 @@ Not much to do without accessing your camera and storage We need the audio permission for recording videos No gallery app available + No valid resolution with selected aspect ratio found, using max resolution Settings @@ -19,7 +20,8 @@ Long tap to capture Refocus before capture Force 16:9 ratio - Photo resolution limit + Photo resolution limit + Video resolution limit none Shutter sound