Added option to disable haptic feedback

This commit is contained in:
M66B 2023-11-09 12:01:27 +01:00
parent 02f31ffa4a
commit f56a98a4d8
6 changed files with 38 additions and 4 deletions

View File

@ -7241,7 +7241,7 @@ public class FragmentCompose extends FragmentBase {
getMainHandler().post(new RunnableEx("compose:toast") {
public void delegate() {
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED))
view.performHapticFeedback(HapticFeedbackConstants.CONFIRM);
Helper.performHapticFeedback(view, HapticFeedbackConstants.CONFIRM);
ToastEx.makeText(context, feedback, Toast.LENGTH_LONG).show();
}
});

View File

@ -10485,7 +10485,7 @@ public class FragmentMessages extends FragmentBase
@Override
protected void onExecuted(Bundle args, Void data) {
view.performHapticFeedback(HapticFeedbackConstants.CONFIRM);
Helper.performHapticFeedback(view, HapticFeedbackConstants.CONFIRM);
}
@Override

View File

@ -126,6 +126,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
private TextView tvClassMinDifference;
private SeekBar sbClassMinDifference;
private SwitchCompat swShowFiltered;
private SwitchCompat swHapticFeedback;
private ImageButton ibClassification;
private Spinner spLanguage;
private SwitchCompat swUpdates;
@ -296,7 +297,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
private final static String[] RESET_OPTIONS = new String[]{
"sort_answers", "shortcuts", "ical_tentative", "fts",
"classification", "class_min_probability", "class_min_difference",
"show_filtered",
"show_filtered", "haptic_feedback",
"language",
"lt_enabled", "lt_sentence", "lt_auto", "lt_picky", "lt_highlight", "lt_description", "lt_uri", "lt_user", "lt_key",
"deepl_enabled",
@ -397,6 +398,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
tvClassMinDifference = view.findViewById(R.id.tvClassMinDifference);
sbClassMinDifference = view.findViewById(R.id.sbClassMinDifference);
swShowFiltered = view.findViewById(R.id.swShowFiltered);
swHapticFeedback = view.findViewById(R.id.swHapticFeedback);
spLanguage = view.findViewById(R.id.spLanguage);
swUpdates = view.findViewById(R.id.swUpdates);
tvGithubPrivacy = view.findViewById(R.id.tvGithubPrivacy);
@ -740,6 +742,13 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
}
});
swHapticFeedback.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
prefs.edit().putBoolean("haptic_feedback", isChecked).apply();
}
});
spLanguage.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
@ -2639,6 +2648,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
sbClassMinDifference.setProgress(class_min_difference);
swShowFiltered.setChecked(prefs.getBoolean("show_filtered", false));
swHapticFeedback.setChecked(prefs.getBoolean("haptic_feedback", true));
int selected = -1;
String language = prefs.getString("language", null);

View File

@ -1926,6 +1926,17 @@ public class Helper {
}
}
static void performHapticFeedback(View view, int feedbackConstant) {
performHapticFeedback(view, feedbackConstant, 0);
}
static void performHapticFeedback(@NonNull View view, int feedbackConstant, int flags) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(view.getContext());
boolean haptic_feedback = prefs.getBoolean("haptic_feedback", true);
if (haptic_feedback)
view.performHapticFeedback(feedbackConstant);
}
// Graphics
static int dp2pixels(Context context, int dp) {

View File

@ -332,6 +332,18 @@
app:layout_constraintTop_toBottomOf="@id/sbClassMinDifference"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swHapticFeedback"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:checked="true"
android:text="@string/title_advanced_haptic_feedback"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swShowFiltered"
app:switchPadding="12dp" />
<TextView
android:id="@+id/tvLanguage"
android:layout_width="0dp"
@ -343,7 +355,7 @@
android:textColor="?android:attr/textColorPrimary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swShowFiltered" />
app:layout_constraintTop_toBottomOf="@id/swHapticFeedback" />
<Spinner
android:id="@+id/spLanguage"

View File

@ -829,6 +829,7 @@
<string name="title_advanced_class_min_chance">Minimum class probability: %1$s %%</string>
<string name="title_advanced_class_min_difference">Minimum class difference: %1$s %%</string>
<string name="title_advanced_show_filtered">Show a filter icon when rules were applied</string>
<string name="title_advanced_haptic_feedback">Haptic feedback on important actions</string>
<string name="title_advanced_language">Language</string>
<string name="title_advanced_language_system">System</string>
<string name="title_advanced_lt">LanguageTool integration</string>