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