allow disabling the Long tap tp capture feature

This commit is contained in:
tibbi
2016-06-18 18:16:43 +02:00
parent 68e7a8de1e
commit 4fdfa9b157
7 changed files with 77 additions and 3 deletions

View File

@@ -0,0 +1,24 @@
package com.simplemobiletools.camera;
import android.content.Context;
import android.content.SharedPreferences;
public class Config {
private SharedPreferences prefs;
public static Config newInstance(Context context) {
return new Config(context);
}
public Config(Context context) {
prefs = context.getSharedPreferences(Constants.PREFS_KEY, Context.MODE_PRIVATE);
}
public boolean getLongTapEnabled() {
return prefs.getBoolean(Constants.LONG_TAP, true);
}
public void setLongTapEnabled(boolean enabled) {
prefs.edit().putBoolean(Constants.LONG_TAP, enabled).apply();
}
}

View File

@@ -4,4 +4,8 @@ public class Constants {
public static final int ORIENT_PORTRAIT = 0;
public static final int ORIENT_LANDSCAPE_LEFT = 1;
public static final int ORIENT_LANDSCAPE_RIGHT = 2;
// Shared preferences
public static final String PREFS_KEY = "Camera";
public static final String LONG_TAP = "long_tap";
}

View File

@@ -72,7 +72,6 @@ public class Preview extends ViewGroup implements SurfaceHolder.Callback, View.O
canTakePicture = false;
surfaceView.setOnTouchListener(this);
surfaceView.setOnClickListener(this);
surfaceView.setOnLongClickListener(this);
isFlashEnabled = false;
isVideoMode = false;
isSurfaceCreated = false;
@@ -143,6 +142,9 @@ public class Preview extends ViewGroup implements SurfaceHolder.Callback, View.O
initRecorder();
}
final boolean isLongTapEnabled = Config.newInstance(getContext()).getLongTapEnabled();
surfaceView.setOnLongClickListener(isLongTapEnabled ? this : null);
return true;
}

View File

@@ -2,15 +2,33 @@ package com.simplemobiletools.camera;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.SwitchCompat;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
public class SettingsActivity extends AppCompatActivity {
@BindView(R.id.settings_long_tap) SwitchCompat longTapSwitch;
private static Config mConfig;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
mConfig = Config.newInstance(getApplicationContext());
ButterKnife.bind(this);
setupLongTap();
}
private void setupLongTap() {
longTapSwitch.setChecked(mConfig.getLongTapEnabled());
}
@OnClick(R.id.settings_long_tap_holder)
public void handleLongTapToTrigger() {
longTapSwitch.setChecked(!longTapSwitch.isChecked());
mConfig.setLongTapEnabled(longTapSwitch.isChecked());
}
}