mirror of
https://github.com/SimpleMobileTools/Simple-Camera.git
synced 2025-02-16 19:30:40 +01:00
limit max resolution as set in Settings
This commit is contained in:
parent
040a4965fa
commit
8bbd93183b
@ -37,4 +37,12 @@ public class Config {
|
||||
public void setForceRatioEnabled(boolean enabled) {
|
||||
mPrefs.edit().putBoolean(Constants.FORCE_RATIO, enabled).apply();
|
||||
}
|
||||
|
||||
public int getMaxResolution() {
|
||||
return mPrefs.getInt(Constants.MAX_RESOLUTION, 1);
|
||||
}
|
||||
|
||||
public void setMaxResolution(int maxRes) {
|
||||
mPrefs.edit().putInt(Constants.MAX_RESOLUTION, maxRes).apply();
|
||||
}
|
||||
}
|
||||
|
@ -10,4 +10,5 @@ public class Constants {
|
||||
public static final String LONG_TAP = "long_tap";
|
||||
public static final String FOCUS_BEFORE_CAPTURE = "focus_before_capture";
|
||||
public static final String FORCE_RATIO = "force_ratio";
|
||||
public static final String MAX_RESOLUTION = "max_resolution";
|
||||
}
|
||||
|
@ -256,12 +256,13 @@ public class Preview extends ViewGroup implements SurfaceHolder.Callback, View.O
|
||||
};
|
||||
|
||||
private Camera.Size getOptimalPictureSize() {
|
||||
final int maxResolution = getMaxResolution();
|
||||
final List<Camera.Size> sizes = mParameters.getSupportedPictureSizes();
|
||||
Camera.Size maxSize = sizes.get(0);
|
||||
for (Camera.Size size : sizes) {
|
||||
final boolean isEightMegapixelsMax = isEightMegapixelsMax(size);
|
||||
final boolean isProperRatio = isProperRatio(size);
|
||||
if (isEightMegapixelsMax && isProperRatio) {
|
||||
final boolean isProperResolution = isProperResolution(size, maxResolution);
|
||||
if (isProperResolution && isProperRatio) {
|
||||
maxSize = size;
|
||||
break;
|
||||
}
|
||||
@ -269,8 +270,20 @@ public class Preview extends ViewGroup implements SurfaceHolder.Callback, View.O
|
||||
return maxSize;
|
||||
}
|
||||
|
||||
private boolean isEightMegapixelsMax(Camera.Size size) {
|
||||
return size.width * size.height < 9000000;
|
||||
private int getMaxResolution() {
|
||||
final int maxRes = Config.newInstance(getContext()).getMaxResolution();
|
||||
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;
|
||||
}
|
||||
|
||||
private boolean isProperRatio(Camera.Size size) {
|
||||
|
@ -2,6 +2,7 @@ package com.simplemobiletools.camera.activities;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.AppCompatSpinner;
|
||||
import android.support.v7.widget.SwitchCompat;
|
||||
|
||||
import com.simplemobiletools.camera.Config;
|
||||
@ -10,11 +11,13 @@ import com.simplemobiletools.camera.R;
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
import butterknife.OnItemSelected;
|
||||
|
||||
public class SettingsActivity extends AppCompatActivity {
|
||||
@BindView(R.id.settings_long_tap) SwitchCompat mLongTapSwitch;
|
||||
@BindView(R.id.settings_focus_before_capture) SwitchCompat mFocusBeforeCaptureSwitch;
|
||||
@BindView(R.id.settings_force_ratio) SwitchCompat mForceRatioSwitch;
|
||||
@BindView(R.id.settings_max_resolution) AppCompatSpinner mMaxResolutionSpinner;
|
||||
|
||||
private static Config mConfig;
|
||||
|
||||
@ -28,6 +31,7 @@ public class SettingsActivity extends AppCompatActivity {
|
||||
setupLongTap();
|
||||
setupFocusBeforeCapture();
|
||||
setupForceRatio();
|
||||
setupMaxResolution();
|
||||
}
|
||||
|
||||
private void setupLongTap() {
|
||||
@ -42,6 +46,10 @@ public class SettingsActivity extends AppCompatActivity {
|
||||
mForceRatioSwitch.setChecked(mConfig.getForceRatioEnabled());
|
||||
}
|
||||
|
||||
private void setupMaxResolution() {
|
||||
mMaxResolutionSpinner.setSelection(mConfig.getMaxResolution());
|
||||
}
|
||||
|
||||
@OnClick(R.id.settings_long_tap_holder)
|
||||
public void handleLongTapToTrigger() {
|
||||
mLongTapSwitch.setChecked(!mLongTapSwitch.isChecked());
|
||||
@ -59,4 +67,9 @@ public class SettingsActivity extends AppCompatActivity {
|
||||
mForceRatioSwitch.setChecked(!mForceRatioSwitch.isChecked());
|
||||
mConfig.setForceRatioEnabled(mForceRatioSwitch.isChecked());
|
||||
}
|
||||
|
||||
@OnItemSelected(R.id.settings_max_resolution)
|
||||
public void handleMaxResolution() {
|
||||
mConfig.setMaxResolution(mMaxResolutionSpinner.getSelectedItemPosition());
|
||||
}
|
||||
}
|
||||
|
@ -85,7 +85,7 @@
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/settings_max_size_holder"
|
||||
android:id="@+id/settings_max_resolution_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/settings_padding"
|
||||
@ -93,7 +93,7 @@
|
||||
android:padding="@dimen/activity_margin">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/settings_max_size_label"
|
||||
android:id="@+id/settings_max_resolution_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
@ -101,11 +101,11 @@
|
||||
android:text="@string/max_size"/>
|
||||
|
||||
<android.support.v7.widget.AppCompatSpinner
|
||||
android:id="@+id/settings_max_size"
|
||||
android:id="@+id/settings_max_resolution"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:entries="@array/max_sizes"/>
|
||||
android:entries="@array/max_resolutions"/>
|
||||
|
||||
</RelativeLayout>
|
||||
</LinearLayout>
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string-array name="max_sizes">
|
||||
<string-array name="max_resolutions">
|
||||
<item>5 MP</item>
|
||||
<item>8 MP</item>
|
||||
<item>@string/no_limit</item>
|
||||
|
Loading…
x
Reference in New Issue
Block a user