make Focus Before Capture optional, disabled by default

This commit is contained in:
tibbi 2016-06-18 20:17:15 +02:00
parent 5265edf5fe
commit 6aa66155d4
6 changed files with 61 additions and 4 deletions

View File

@ -21,4 +21,12 @@ public class Config {
public void setLongTapEnabled(boolean enabled) {
prefs.edit().putBoolean(Constants.LONG_TAP, enabled).apply();
}
public boolean getFocusBeforeCaptureEnabled() {
return prefs.getBoolean(Constants.FOCUS_BEFORE_CAPTURE, false);
}
public void setFocusBeforeCaptureEnabled(boolean enabled) {
prefs.edit().putBoolean(Constants.FOCUS_BEFORE_CAPTURE, enabled).apply();
}
}

View File

@ -8,4 +8,5 @@ public class Constants {
// Shared preferences
public static final String PREFS_KEY = "Camera";
public static final String LONG_TAP = "long_tap";
public static final String FOCUS_BEFORE_CAPTURE = "focus_before_capture";
}

View File

@ -48,6 +48,7 @@ public class Preview extends ViewGroup implements SurfaceHolder.Callback, View.O
private static boolean isSurfaceCreated;
private static boolean switchToVideoAsap;
private static boolean isVideoCaptureIntent;
private static boolean focusBeforeCapture;
private boolean setupPreviewAfterMeasure;
private static String curVideoPath;
private static int lastClickX;
@ -145,6 +146,8 @@ public class Preview extends ViewGroup implements SurfaceHolder.Callback, View.O
final boolean isLongTapEnabled = Config.newInstance(getContext()).getLongTapEnabled();
surfaceView.setOnLongClickListener(isLongTapEnabled ? this : null);
focusBeforeCapture = Config.newInstance(getContext()).getFocusBeforeCaptureEnabled();
return true;
}
@ -194,7 +197,11 @@ public class Preview extends ViewGroup implements SurfaceHolder.Callback, View.O
}
public void tryTakePicture() {
focusArea(true);
if (focusBeforeCapture) {
focusArea(true);
} else {
takePicture();
}
}
private void takePicture() {

View File

@ -10,6 +10,7 @@ import butterknife.OnClick;
public class SettingsActivity extends AppCompatActivity {
@BindView(R.id.settings_long_tap) SwitchCompat longTapSwitch;
@BindView(R.id.settings_focus_before_capture) SwitchCompat focusBeforeCaptureSwitch;
private static Config mConfig;
@ -19,16 +20,28 @@ public class SettingsActivity extends AppCompatActivity {
setContentView(R.layout.activity_settings);
mConfig = Config.newInstance(getApplicationContext());
ButterKnife.bind(this);
setupLongTap();
setupFocusBeforeCapture();
}
private void setupLongTap() {
longTapSwitch.setChecked(mConfig.getLongTapEnabled());
}
private void setupFocusBeforeCapture() {
focusBeforeCaptureSwitch.setChecked(mConfig.getFocusBeforeCaptureEnabled());
}
@OnClick(R.id.settings_long_tap_holder)
public void handleLongTapToTrigger() {
longTapSwitch.setChecked(!longTapSwitch.isChecked());
mConfig.setLongTapEnabled(longTapSwitch.isChecked());
}
@OnClick(R.id.settings_focus_before_capture_holder)
public void handleFocusBeforeCapture() {
focusBeforeCaptureSwitch.setChecked(!focusBeforeCaptureSwitch.isChecked());
mConfig.setFocusBeforeCaptureEnabled(focusBeforeCaptureSwitch.isChecked());
}
}

View File

@ -1,9 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
<LinearLayout
android:id="@+id/settings_holder"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/settings_long_tap_holder"
@ -30,4 +31,30 @@
android:clickable="false"/>
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:id="@+id/settings_focus_before_capture_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/settings_padding"
android:background="?android:attr/selectableItemBackground"
android:padding="@dimen/activity_margin">
<TextView
android:id="@+id/settings_focus_before_capture_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:paddingLeft="@dimen/settings_padding"
android:text="@string/focus_before_capture"/>
<android.support.v7.widget.SwitchCompat
android:id="@+id/settings_focus_before_capture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="@null"
android:clickable="false"/>
</RelativeLayout>
</LinearLayout>

View File

@ -15,6 +15,7 @@
<!-- Settings -->
<string name="settings">Settings</string>
<string name="long_tap_capture">Long tap to capture</string>
<string name="focus_before_capture">Focus before capture</string>
<!-- About -->
<string name="about">About</string>