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());
}
}

View File

@ -3,7 +3,31 @@
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_margin="@dimen/activity_margin">
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/settings_long_tap_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_long_tap_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:paddingLeft="@dimen/settings_padding"
android:text="@string/long_tap_capture"/>
<android.support.v7.widget.SwitchCompat
android:id="@+id/settings_long_tap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="@null"
android:clickable="false"/>
</RelativeLayout>
</RelativeLayout>

View File

@ -3,4 +3,5 @@
<dimen name="preview_btn_margin">32dp</dimen>
<dimen name="side_icon_padding">12dp</dimen>
<dimen name="icon_size">56dp</dimen>
<dimen name="settings_padding">8dp</dimen>
</resources>

View File

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