add the option to disable Shutter sound

This commit is contained in:
tibbi 2016-07-09 20:42:36 +02:00
parent 17b771a649
commit b33ecdcc20
6 changed files with 51 additions and 1 deletions

View File

@ -53,4 +53,12 @@ public class Config {
public void setMaxResolution(int maxRes) {
mPrefs.edit().putInt(Constants.MAX_RESOLUTION, maxRes).apply();
}
public boolean getIsSoundEnabled() {
return mPrefs.getBoolean(Constants.SOUND, true);
}
public void setIsSoundEnabled(boolean enabled) {
mPrefs.edit().putBoolean(Constants.SOUND, enabled).apply();
}
}

View File

@ -10,6 +10,7 @@ public class Constants {
public static final String IS_FIRST_RUN = "is_first_run";
public static final String LONG_TAP = "long_tap";
public static final String FOCUS_BEFORE_CAPTURE = "focus_before_capture";
public static final String SOUND = "sound";
public static final String FORCE_RATIO = "force_ratio";
public static final String MAX_RESOLUTION = "max_resolution";
}

View File

@ -223,7 +223,9 @@ public class Preview extends ViewGroup implements SurfaceHolder.Callback, View.O
mParameters.setPictureSize(maxSize.width, maxSize.height);
mParameters.setRotation(rotation % 360);
MediaPlayer.create(getContext(), R.raw.camera_shutter).start();
if (Config.newInstance(getContext()).getIsSoundEnabled())
MediaPlayer.create(getContext(), R.raw.camera_shutter).start();
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
mCamera.enableShutterSound(false);
}

View File

@ -16,6 +16,7 @@ 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_sound) SwitchCompat mSoundSwitch;
@BindView(R.id.settings_force_ratio) SwitchCompat mForceRatioSwitch;
@BindView(R.id.settings_max_resolution) AppCompatSpinner mMaxResolutionSpinner;
@ -30,6 +31,7 @@ public class SettingsActivity extends AppCompatActivity {
setupLongTap();
setupFocusBeforeCapture();
setupSound();
setupForceRatio();
setupMaxResolution();
}
@ -42,6 +44,10 @@ public class SettingsActivity extends AppCompatActivity {
mFocusBeforeCaptureSwitch.setChecked(mConfig.getFocusBeforeCaptureEnabled());
}
private void setupSound() {
mSoundSwitch.setChecked(mConfig.getIsSoundEnabled());
}
private void setupForceRatio() {
mForceRatioSwitch.setChecked(mConfig.getForceRatioEnabled());
}
@ -62,6 +68,12 @@ public class SettingsActivity extends AppCompatActivity {
mConfig.setFocusBeforeCaptureEnabled(mFocusBeforeCaptureSwitch.isChecked());
}
@OnClick(R.id.settings_sound_holder)
public void handleSound() {
mSoundSwitch.setChecked(!mSoundSwitch.isChecked());
mConfig.setIsSoundEnabled(mSoundSwitch.isChecked());
}
@OnClick(R.id.settings_force_ratio_holder)
public void handleForceRatio() {
mForceRatioSwitch.setChecked(!mForceRatioSwitch.isChecked());

View File

@ -58,6 +58,32 @@
</RelativeLayout>
<RelativeLayout
android:id="@+id/settings_sound_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_sound_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:paddingLeft="@dimen/settings_padding"
android:text="@string/shutter_sound"/>
<android.support.v7.widget.SwitchCompat
android:id="@+id/settings_sound"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="@null"
android:clickable="false"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/settings_force_ratio_holder"
android:layout_width="match_parent"

View File

@ -19,6 +19,7 @@
<string name="force_ratio">Force 16:9 ratio</string>
<string name="max_size">Photo resolution limit</string>
<string name="no_limit">none</string>
<string name="shutter_sound">Shutter sound</string>
<!-- About -->
<string name="about">About</string>