mirror of
https://github.com/SimpleMobileTools/Simple-Camera.git
synced 2025-02-12 01:10:42 +01:00
allow setting max video resolution, closes #7
This commit is contained in:
parent
5a87bed1bb
commit
2d4174c23e
@ -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);
|
||||
}
|
||||
|
@ -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";
|
||||
}
|
||||
|
@ -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<Camera.Size> 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<Camera.Size> 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;
|
||||
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<Camera.Size> previewSizes = mParameters.getSupportedPreviewSizes();
|
||||
Collections.sort(previewSizes, new SizesComparator());
|
||||
|
@ -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() {
|
||||
|
@ -143,7 +143,7 @@
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/settings_max_resolution_holder"
|
||||
android:id="@+id/settings_max_photo_resolution_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/settings_padding"
|
||||
@ -153,19 +153,46 @@
|
||||
android:paddingTop="@dimen/activity_margin">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/settings_max_resolution_label"
|
||||
android:id="@+id/settings_max_photo_resolution_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:paddingLeft="@dimen/settings_padding"
|
||||
android:text="@string/max_size"/>
|
||||
android:text="@string/max_photo_size"/>
|
||||
|
||||
<android.support.v7.widget.AppCompatSpinner
|
||||
android:id="@+id/settings_max_resolution"
|
||||
android:id="@+id/settings_max_photo_resolution"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:entries="@array/max_resolutions"/>
|
||||
android:entries="@array/max_photo_resolutions"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/settings_max_video_resolution_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/settings_padding"
|
||||
android:paddingBottom="@dimen/activity_margin"
|
||||
android:paddingLeft="@dimen/activity_margin"
|
||||
android:paddingRight="@dimen/settings_padding"
|
||||
android:paddingTop="@dimen/activity_margin">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/settings_max_video_resolution_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:paddingLeft="@dimen/settings_padding"
|
||||
android:text="@string/max_video_size"/>
|
||||
|
||||
<android.support.v7.widget.AppCompatSpinner
|
||||
android:id="@+id/settings_max_video_resolution"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:entries="@array/max_video_resolutions"/>
|
||||
|
||||
</RelativeLayout>
|
||||
</LinearLayout>
|
||||
|
@ -12,6 +12,7 @@
|
||||
<string name="no_permissions">Non c\'è molto da fare senza l\'accesso alla fotocamera e all\'archiviazione</string>
|
||||
<string name="no_audio_permissions">È necessario l\'accesso al microfono per registrare i video</string>
|
||||
<string name="no_gallery_app_available">Nessuna app galleria disponibile</string>
|
||||
<string name="no_valid_resolution_found">No valid resolution with selected aspect ratio found, using max resolution</string>
|
||||
|
||||
<!-- Settings -->
|
||||
<string name="settings">Impostazioni</string>
|
||||
@ -19,7 +20,8 @@
|
||||
<string name="long_tap_capture">Tocco prolungato per la cattura</string>
|
||||
<string name="focus_before_capture">Messa a fuoco prima della cattura</string>
|
||||
<string name="force_ratio">Forza proporzione 16:9</string>
|
||||
<string name="max_size">Limite risoluzione foto</string>
|
||||
<string name="max_photo_size">Limite risoluzione foto</string>
|
||||
<string name="max_video_size">Video resolution limit</string>
|
||||
<string name="no_limit">nessuno</string>
|
||||
<string name="shutter_sound">Suono otturatore</string>
|
||||
|
||||
|
@ -12,6 +12,7 @@
|
||||
<string name="no_permissions">お使いのカメラやストレージにアクセスしないと、ほとんど行うことはありません</string>
|
||||
<string name="no_audio_permissions">ビデオを記録するためにオーディオのアクセス許可が必要です</string>
|
||||
<string name="no_gallery_app_available">利用可能なギャラリーアプリがありません</string>
|
||||
<string name="no_valid_resolution_found">No valid resolution with selected aspect ratio found, using max resolution</string>
|
||||
|
||||
<!-- Settings -->
|
||||
<string name="settings">設定</string>
|
||||
@ -19,7 +20,8 @@
|
||||
<string name="long_tap_capture">長押ししてキャプチャする</string>
|
||||
<string name="focus_before_capture">キャプチャ前に再度焦点を合わせる</string>
|
||||
<string name="force_ratio">強制的に 16:9 レシオにする</string>
|
||||
<string name="max_size">写真解像度の限度</string>
|
||||
<string name="max_photo_size">写真解像度の限度</string>
|
||||
<string name="max_video_size">Video resolution limit</string>
|
||||
<string name="no_limit">なし</string>
|
||||
<string name="shutter_sound">シャッター音</string>
|
||||
|
||||
|
@ -12,6 +12,7 @@
|
||||
<string name="no_permissions">Не так много можно сделать без доступа к камере и хранилищу</string>
|
||||
<string name="no_audio_permissions">Нам нужно аудио разрешение для записи видео</string>
|
||||
<string name="no_gallery_app_available">Нет доступного приложения-галереи</string>
|
||||
<string name="no_valid_resolution_found">No valid resolution with selected aspect ratio found, using max resolution</string>
|
||||
|
||||
<!-- Settings -->
|
||||
<string name="settings">Настройки</string>
|
||||
@ -19,7 +20,8 @@
|
||||
<string name="long_tap_capture">Длинное нажатие для захвата</string>
|
||||
<string name="focus_before_capture">Перефокусировка перед захватом</string>
|
||||
<string name="force_ratio">Принудительное соотношение сторон 16:9</string>
|
||||
<string name="max_size">Лимит разрешения фото</string>
|
||||
<string name="max_photo_size">Лимит разрешения фото</string>
|
||||
<string name="max_video_size">Video resolution limit</string>
|
||||
<string name="no_limit">нет</string>
|
||||
<string name="shutter_sound">Звук затвора</string>
|
||||
|
||||
|
@ -12,6 +12,7 @@
|
||||
<string name="no_permissions">Inte mycket att göra utan tillgång till din kamera och lagring</string>
|
||||
<string name="no_audio_permissions">För att spela in video krävs ljudrättigheter</string>
|
||||
<string name="no_gallery_app_available">Ingen galleri-app finns tillgänglig</string>
|
||||
<string name="no_valid_resolution_found">No valid resolution with selected aspect ratio found, using max resolution</string>
|
||||
|
||||
<!-- Settings -->
|
||||
<string name="settings">Inställningar</string>
|
||||
@ -19,7 +20,8 @@
|
||||
<string name="long_tap_capture">Långtryck för bildtagning</string>
|
||||
<string name="focus_before_capture">Fokusera om innan bildtagning</string>
|
||||
<string name="force_ratio">Tvinga 16:9-förhållande</string>
|
||||
<string name="max_size">Bildupplösningsgräns</string>
|
||||
<string name="max_photo_size">Bildupplösningsgräns</string>
|
||||
<string name="max_video_size">Video resolution limit</string>
|
||||
<string name="no_limit">inga</string>
|
||||
<string name="shutter_sound">Slutarljud</string>
|
||||
|
||||
|
@ -1,8 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string-array name="max_resolutions" translatable="false">
|
||||
<string-array name="max_photo_resolutions" translatable="false">
|
||||
<item>5 MP</item>
|
||||
<item>8 MP</item>
|
||||
<item>@string/no_limit</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="max_video_resolutions" translatable="false">
|
||||
<item>480p</item>
|
||||
<item>720p</item>
|
||||
<item>1080p</item>
|
||||
<item>@string/no_limit</item>
|
||||
</string-array>
|
||||
</resources>
|
||||
|
@ -12,6 +12,7 @@
|
||||
<string name="no_permissions">Not much to do without accessing your camera and storage</string>
|
||||
<string name="no_audio_permissions">We need the audio permission for recording videos</string>
|
||||
<string name="no_gallery_app_available">No gallery app available</string>
|
||||
<string name="no_valid_resolution_found">No valid resolution with selected aspect ratio found, using max resolution</string>
|
||||
|
||||
<!-- Settings -->
|
||||
<string name="settings">Settings</string>
|
||||
@ -19,7 +20,8 @@
|
||||
<string name="long_tap_capture">Long tap to capture</string>
|
||||
<string name="focus_before_capture">Refocus before capture</string>
|
||||
<string name="force_ratio">Force 16:9 ratio</string>
|
||||
<string name="max_size">Photo resolution limit</string>
|
||||
<string name="max_photo_size">Photo resolution limit</string>
|
||||
<string name="max_video_size">Video resolution limit</string>
|
||||
<string name="no_limit">none</string>
|
||||
<string name="shutter_sound">Shutter sound</string>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user