add a new max photo resolution limit of 2 mpx

This commit is contained in:
tibbi 2016-11-06 12:46:29 +01:00
parent 0bdfb7802f
commit 945b845a44
5 changed files with 41 additions and 18 deletions

View File

@ -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() {

View File

@ -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";
}

View File

@ -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<Camera.Size> 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;
}

View File

@ -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 {

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="max_photo_resolutions" translatable="false">
<item>2 MP</item>
<item>5 MP</item>
<item>8 MP</item>
<item>@string/no_limit</item>