mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
Merge "Add default button to vibration/volume settings dialog"
This commit is contained in:
commit
40c59727cf
@ -376,4 +376,7 @@
|
||||
<string name="prefs_keypress_vibration_duration_settings">Keypress vibration duration settings</string>
|
||||
<!-- Title of the settings for keypress sound volume -->
|
||||
<string name="prefs_keypress_sound_volume_settings">Keypress sound volume settings</string>
|
||||
|
||||
<!-- Title of the button to revert to the default value of the device in the settings dialog [CHAR LIMIT=15] -->
|
||||
<string name="button_default">Default</string>
|
||||
</resources>
|
||||
|
@ -167,19 +167,21 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
|
||||
public static float readKeypressSoundVolume(final SharedPreferences prefs,
|
||||
final Resources res) {
|
||||
final float volume = prefs.getFloat(PREF_KEYPRESS_SOUND_VOLUME, -1.0f);
|
||||
if (volume >= 0) {
|
||||
return volume;
|
||||
}
|
||||
return (volume >= 0) ? volume : readDefaultKeypressSoundVolume(res);
|
||||
}
|
||||
|
||||
public static float readDefaultKeypressSoundVolume(final Resources res) {
|
||||
return Float.parseFloat(
|
||||
ResourceUtils.getDeviceOverrideValue(res, R.array.keypress_volumes));
|
||||
}
|
||||
|
||||
public static int readVibrationDuration(final SharedPreferences prefs,
|
||||
public static int readKeypressVibrationDuration(final SharedPreferences prefs,
|
||||
final Resources res) {
|
||||
final int ms = prefs.getInt(PREF_VIBRATION_DURATION_SETTINGS, -1);
|
||||
if (ms >= 0) {
|
||||
return ms;
|
||||
}
|
||||
return (ms >= 0) ? ms : readDefaultKeypressVibrationDuration(res);
|
||||
}
|
||||
|
||||
public static int readDefaultKeypressVibrationDuration(final Resources res) {
|
||||
return Integer.parseInt(
|
||||
ResourceUtils.getDeviceOverrideValue(res, R.array.keypress_vibration_durations));
|
||||
}
|
||||
|
@ -180,7 +180,7 @@ public final class SettingsFragment extends InputMethodSettingsFragment
|
||||
});
|
||||
mKeypressVibrationDurationSettingsPref.setSummary(
|
||||
res.getString(R.string.settings_keypress_vibration_duration,
|
||||
Settings.readVibrationDuration(prefs, res)));
|
||||
Settings.readKeypressVibrationDuration(prefs, res)));
|
||||
}
|
||||
|
||||
mKeypressSoundVolumeSettingsPref =
|
||||
@ -312,11 +312,23 @@ public final class SettingsFragment extends InputMethodSettingsFragment
|
||||
sp.edit().putInt(Settings.PREF_VIBRATION_DURATION_SETTINGS, value).apply();
|
||||
}
|
||||
|
||||
private void feedbackSettingsValue(final int value) {
|
||||
AudioAndHapticFeedbackManager.getInstance().vibrate(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPositiveButtonClick(final SeekBarDialog dialog) {
|
||||
writePreference(sp, dialog.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeutralButtonClick(final SeekBarDialog dialog) {
|
||||
final int defaultValue =
|
||||
Settings.readDefaultKeypressVibrationDuration(context.getResources());
|
||||
dialog.setValue(defaultValue, false /* fromUser */);
|
||||
writePreference(sp, defaultValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDismiss(final SeekBarDialog dialog) {
|
||||
if (settingsPref != null) {
|
||||
@ -326,13 +338,13 @@ public final class SettingsFragment extends InputMethodSettingsFragment
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(final SeekBarDialog dialog) {
|
||||
final int ms = dialog.getValue();
|
||||
AudioAndHapticFeedbackManager.getInstance().vibrate(ms);
|
||||
feedbackSettingsValue(dialog.getValue());
|
||||
}
|
||||
};
|
||||
final int currentMs = Settings.readVibrationDuration(sp, getResources());
|
||||
final int currentMs = Settings.readKeypressVibrationDuration(sp, getResources());
|
||||
final SeekBarDialog.Builder builder = new SeekBarDialog.Builder(context);
|
||||
builder.setTitle(R.string.prefs_keypress_vibration_duration_settings)
|
||||
.setNeutralButtonText(R.string.button_default)
|
||||
.setListener(listener)
|
||||
.setMaxValue(AudioAndHapticFeedbackManager.MAX_KEYPRESS_VIBRATION_DURATION)
|
||||
.setValueFromat(R.string.settings_keypress_vibration_duration)
|
||||
@ -359,11 +371,23 @@ public final class SettingsFragment extends InputMethodSettingsFragment
|
||||
sp.edit().putFloat(Settings.PREF_KEYPRESS_SOUND_VOLUME, value).apply();
|
||||
}
|
||||
|
||||
private void feedbackSettingsValue(final float value) {
|
||||
am.playSoundEffect(AudioManager.FX_KEYPRESS_STANDARD, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPositiveButtonClick(final SeekBarDialog dialog) {
|
||||
writePreference(sp, dialog.getValue() / PERCENT_FLOAT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeutralButtonClick(final SeekBarDialog dialog) {
|
||||
final float defaultValue =
|
||||
Settings.readDefaultKeypressSoundVolume(context.getResources());
|
||||
dialog.setValue((int)(defaultValue * PERCENT_INT), false /* fromUser */);
|
||||
writePreference(sp, defaultValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDismiss(final SeekBarDialog dialog) {
|
||||
if (settingsPref != null) {
|
||||
@ -373,13 +397,13 @@ public final class SettingsFragment extends InputMethodSettingsFragment
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(final SeekBarDialog dialog) {
|
||||
final float volume = dialog.getValue() / PERCENT_FLOAT;
|
||||
am.playSoundEffect(AudioManager.FX_KEYPRESS_STANDARD, volume);
|
||||
feedbackSettingsValue(dialog.getValue() / PERCENT_FLOAT);
|
||||
}
|
||||
};
|
||||
final SeekBarDialog.Builder builder = new SeekBarDialog.Builder(context);
|
||||
final int currentVolumeInt = getCurrentKeyPressSoundVolumePercent(sp, getResources());
|
||||
builder.setTitle(R.string.prefs_keypress_sound_volume_settings)
|
||||
.setNeutralButtonText(R.string.button_default)
|
||||
.setListener(listener)
|
||||
.setMaxValue(PERCENT_INT)
|
||||
.setValue(currentVolumeInt)
|
||||
|
@ -128,7 +128,7 @@ public final class SettingsValues {
|
||||
mBigramPredictionEnabled = readBigramPredictionEnabled(prefs, res);
|
||||
|
||||
// Compute other readable settings
|
||||
mKeypressVibrationDuration = Settings.readVibrationDuration(prefs, res);
|
||||
mKeypressVibrationDuration = Settings.readKeypressVibrationDuration(prefs, res);
|
||||
mKeypressSoundVolume = Settings.readKeypressSoundVolume(prefs, res);
|
||||
mKeyPreviewPopupDismissDelay = Settings.readKeyPreviewPopupDismissDelay(prefs, res);
|
||||
mAutoCorrectionThreshold = readAutoCorrectionThreshold(res,
|
||||
|
Loading…
Reference in New Issue
Block a user