From a7a7f4e00277b2d3c1c38d2b6fe558e177e1e8d2 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Thu, 10 Jan 2013 12:06:00 +0900 Subject: [PATCH] Add default button to vibration/volume settings dialog Change-Id: I7beb4517314efdefeb47d91b14a6b02c3075c19f --- java/res/values/strings.xml | 3 ++ .../android/inputmethod/latin/Settings.java | 16 +++++---- .../inputmethod/latin/SettingsFragment.java | 36 +++++++++++++++---- .../inputmethod/latin/SettingsValues.java | 2 +- 4 files changed, 43 insertions(+), 14 deletions(-) diff --git a/java/res/values/strings.xml b/java/res/values/strings.xml index 5c5442708..fd7aac49f 100644 --- a/java/res/values/strings.xml +++ b/java/res/values/strings.xml @@ -376,4 +376,7 @@ Keypress vibration duration settings Keypress sound volume settings + + + Default diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java index f592a2515..a720203ae 100644 --- a/java/src/com/android/inputmethod/latin/Settings.java +++ b/java/src/com/android/inputmethod/latin/Settings.java @@ -168,19 +168,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)); } diff --git a/java/src/com/android/inputmethod/latin/SettingsFragment.java b/java/src/com/android/inputmethod/latin/SettingsFragment.java index a4f0d9902..6a4371835 100644 --- a/java/src/com/android/inputmethod/latin/SettingsFragment.java +++ b/java/src/com/android/inputmethod/latin/SettingsFragment.java @@ -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) diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index fac85a8cc..0d3feaa26 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -139,7 +139,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,