Skip to content

Commit 8bbd931

Browse files
committed
limit max resolution as set in Settings
1 parent 040a496 commit 8bbd931

6 files changed

Lines changed: 44 additions & 9 deletions

File tree

app/src/main/java/com/simplemobiletools/camera/Config.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,12 @@ public boolean getForceRatioEnabled() {
3737
public void setForceRatioEnabled(boolean enabled) {
3838
mPrefs.edit().putBoolean(Constants.FORCE_RATIO, enabled).apply();
3939
}
40+
41+
public int getMaxResolution() {
42+
return mPrefs.getInt(Constants.MAX_RESOLUTION, 1);
43+
}
44+
45+
public void setMaxResolution(int maxRes) {
46+
mPrefs.edit().putInt(Constants.MAX_RESOLUTION, maxRes).apply();
47+
}
4048
}

app/src/main/java/com/simplemobiletools/camera/Constants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ public class Constants {
1010
public static final String LONG_TAP = "long_tap";
1111
public static final String FOCUS_BEFORE_CAPTURE = "focus_before_capture";
1212
public static final String FORCE_RATIO = "force_ratio";
13+
public static final String MAX_RESOLUTION = "max_resolution";
1314
}

app/src/main/java/com/simplemobiletools/camera/Preview.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,21 +256,34 @@ public void run() {
256256
};
257257

258258
private Camera.Size getOptimalPictureSize() {
259+
final int maxResolution = getMaxResolution();
259260
final List<Camera.Size> sizes = mParameters.getSupportedPictureSizes();
260261
Camera.Size maxSize = sizes.get(0);
261262
for (Camera.Size size : sizes) {
262-
final boolean isEightMegapixelsMax = isEightMegapixelsMax(size);
263263
final boolean isProperRatio = isProperRatio(size);
264-
if (isEightMegapixelsMax && isProperRatio) {
264+
final boolean isProperResolution = isProperResolution(size, maxResolution);
265+
if (isProperResolution && isProperRatio) {
265266
maxSize = size;
266267
break;
267268
}
268269
}
269270
return maxSize;
270271
}
271272

272-
private boolean isEightMegapixelsMax(Camera.Size size) {
273-
return size.width * size.height < 9000000;
273+
private int getMaxResolution() {
274+
final int maxRes = Config.newInstance(getContext()).getMaxResolution();
275+
switch (maxRes) {
276+
case 0:
277+
return 6000000;
278+
case 1:
279+
return 9000000;
280+
default:
281+
return 0;
282+
}
283+
}
284+
285+
private boolean isProperResolution(Camera.Size size, int maxRes) {
286+
return maxRes == 0 || size.width * size.height < maxRes;
274287
}
275288

276289
private boolean isProperRatio(Camera.Size size) {

app/src/main/java/com/simplemobiletools/camera/activities/SettingsActivity.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.os.Bundle;
44
import android.support.v7.app.AppCompatActivity;
5+
import android.support.v7.widget.AppCompatSpinner;
56
import android.support.v7.widget.SwitchCompat;
67

78
import com.simplemobiletools.camera.Config;
@@ -10,11 +11,13 @@
1011
import butterknife.BindView;
1112
import butterknife.ButterKnife;
1213
import butterknife.OnClick;
14+
import butterknife.OnItemSelected;
1315

1416
public class SettingsActivity extends AppCompatActivity {
1517
@BindView(R.id.settings_long_tap) SwitchCompat mLongTapSwitch;
1618
@BindView(R.id.settings_focus_before_capture) SwitchCompat mFocusBeforeCaptureSwitch;
1719
@BindView(R.id.settings_force_ratio) SwitchCompat mForceRatioSwitch;
20+
@BindView(R.id.settings_max_resolution) AppCompatSpinner mMaxResolutionSpinner;
1821

1922
private static Config mConfig;
2023

@@ -28,6 +31,7 @@ protected void onCreate(Bundle savedInstanceState) {
2831
setupLongTap();
2932
setupFocusBeforeCapture();
3033
setupForceRatio();
34+
setupMaxResolution();
3135
}
3236

3337
private void setupLongTap() {
@@ -42,6 +46,10 @@ private void setupForceRatio() {
4246
mForceRatioSwitch.setChecked(mConfig.getForceRatioEnabled());
4347
}
4448

49+
private void setupMaxResolution() {
50+
mMaxResolutionSpinner.setSelection(mConfig.getMaxResolution());
51+
}
52+
4553
@OnClick(R.id.settings_long_tap_holder)
4654
public void handleLongTapToTrigger() {
4755
mLongTapSwitch.setChecked(!mLongTapSwitch.isChecked());
@@ -59,4 +67,9 @@ public void handleForceRatio() {
5967
mForceRatioSwitch.setChecked(!mForceRatioSwitch.isChecked());
6068
mConfig.setForceRatioEnabled(mForceRatioSwitch.isChecked());
6169
}
70+
71+
@OnItemSelected(R.id.settings_max_resolution)
72+
public void handleMaxResolution() {
73+
mConfig.setMaxResolution(mMaxResolutionSpinner.getSelectedItemPosition());
74+
}
6275
}

app/src/main/res/layout/activity_settings.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,27 +85,27 @@
8585
</RelativeLayout>
8686

8787
<RelativeLayout
88-
android:id="@+id/settings_max_size_holder"
88+
android:id="@+id/settings_max_resolution_holder"
8989
android:layout_width="match_parent"
9090
android:layout_height="wrap_content"
9191
android:layout_marginTop="@dimen/settings_padding"
9292
android:background="?android:attr/selectableItemBackground"
9393
android:padding="@dimen/activity_margin">
9494

9595
<TextView
96-
android:id="@+id/settings_max_size_label"
96+
android:id="@+id/settings_max_resolution_label"
9797
android:layout_width="wrap_content"
9898
android:layout_height="wrap_content"
9999
android:layout_centerVertical="true"
100100
android:paddingLeft="@dimen/settings_padding"
101101
android:text="@string/max_size"/>
102102

103103
<android.support.v7.widget.AppCompatSpinner
104-
android:id="@+id/settings_max_size"
104+
android:id="@+id/settings_max_resolution"
105105
android:layout_width="wrap_content"
106106
android:layout_height="wrap_content"
107107
android:layout_alignParentRight="true"
108-
android:entries="@array/max_sizes"/>
108+
android:entries="@array/max_resolutions"/>
109109

110110
</RelativeLayout>
111111
</LinearLayout>

app/src/main/res/values/array.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
3-
<string-array name="max_sizes">
3+
<string-array name="max_resolutions">
44
<item>5 MP</item>
55
<item>8 MP</item>
66
<item>@string/no_limit</item>

0 commit comments

Comments
 (0)