diff options
author | 2011-09-19 14:51:31 +0900 | |
---|---|---|
committer | 2011-09-20 11:23:30 +0900 | |
commit | 28f36d68afe8d323d1032d0e03fe3013449e21fe (patch) | |
tree | e62fb770c92e4291db2787970a9d63ca592f17b6 /java/src | |
parent | a35ea4cba88868a8c45b4d132d0c49b128f76927 (diff) | |
download | latinime-28f36d68afe8d323d1032d0e03fe3013449e21fe.tar.gz latinime-28f36d68afe8d323d1032d0e03fe3013449e21fe.tar.xz latinime-28f36d68afe8d323d1032d0e03fe3013449e21fe.zip |
Tweak LatinIME's keypress vibration duration
bug: 5337363
Change-Id: If6e6de587cbcddf26710d8f0b237c4bc393589b6
Diffstat (limited to 'java/src')
-rw-r--r-- | java/src/com/android/inputmethod/compat/VibratorCompatWrapper.java | 4 | ||||
-rw-r--r-- | java/src/com/android/inputmethod/latin/LatinIME.java | 39 |
2 files changed, 36 insertions, 7 deletions
diff --git a/java/src/com/android/inputmethod/compat/VibratorCompatWrapper.java b/java/src/com/android/inputmethod/compat/VibratorCompatWrapper.java index a6304d877..2fb8b8710 100644 --- a/java/src/com/android/inputmethod/compat/VibratorCompatWrapper.java +++ b/java/src/com/android/inputmethod/compat/VibratorCompatWrapper.java @@ -44,4 +44,8 @@ public class VibratorCompatWrapper { return false; return (Boolean) CompatUtils.invoke(mVibrator, true, METHOD_hasVibrator); } + + public void vibrate(long milliseconds) { + mVibrator.vibrate(milliseconds); + } } diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index fdf58f6ef..d788d70df 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -28,6 +28,7 @@ import android.content.res.Resources; import android.inputmethodservice.InputMethodService; import android.media.AudioManager; import android.net.ConnectivityManager; +import android.os.Build; import android.os.Debug; import android.os.Message; import android.os.SystemClock; @@ -56,6 +57,7 @@ import com.android.inputmethod.compat.InputMethodManagerCompatWrapper; import com.android.inputmethod.compat.InputMethodServiceCompatWrapper; import com.android.inputmethod.compat.InputTypeCompatUtils; import com.android.inputmethod.compat.SuggestionSpanUtils; +import com.android.inputmethod.compat.VibratorCompatWrapper; import com.android.inputmethod.deprecated.LanguageSwitcherProxy; import com.android.inputmethod.deprecated.VoiceProxy; import com.android.inputmethod.deprecated.recorrection.Recorrection; @@ -211,6 +213,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar private static float mFxVolume = -1.0f; // just a default value to be updated runtime private boolean mSilentModeOn; // System-wide current configuration + private VibratorCompatWrapper mVibrator; + private long mKeypressVibrationDuration = -1; + // TODO: Move this flag to VoiceProxy private boolean mConfigurationChanging; @@ -434,13 +439,14 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar mSubtypeSwitcher = SubtypeSwitcher.getInstance(); mKeyboardSwitcher = KeyboardSwitcher.getInstance(); mRecorrection = Recorrection.getInstance(); + mVibrator = VibratorCompatWrapper.getInstance(this); DEBUG = LatinImeLogger.sDBG; - loadSettings(); - final Resources res = getResources(); mResources = res; + loadSettings(); + Utils.GCUtils.getInstance().reset(); boolean tryGC = true; for (int i = 0; i < Utils.GCUtils.GC_TRY_LOOP_MAX && tryGC; ++i) { @@ -481,6 +487,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar mSettingsValues = new Settings.Values(mPrefs, this, mSubtypeSwitcher.getInputLocaleStr()); resetContactsDictionary(null == mSuggest ? null : mSuggest.getContactsDictionary()); updateSoundEffectVolume(); + updateKeypressVibrationDuration(); } private void initSuggest() { @@ -2062,6 +2069,19 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar mSilentModeOn = (mAudioManager.getRingerMode() != AudioManager.RINGER_MODE_NORMAL); } + private void updateKeypressVibrationDuration() { + final String[] durationPerHardwareList = mResources.getStringArray( + R.array.keypress_vibration_durations); + final String hardwarePrefix = Build.HARDWARE + ","; + for (final String element : durationPerHardwareList) { + if (element.startsWith(hardwarePrefix)) { + mKeypressVibrationDuration = + Long.parseLong(element.substring(element.lastIndexOf(',') + 1)); + break; + } + } + } + private void playKeyClick(int primaryCode) { // if mAudioManager is null, we don't have the ringer state yet // mAudioManager will be set by updateRingerMode @@ -2091,11 +2111,16 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar if (!mSettingsValues.mVibrateOn) { return; } - LatinKeyboardView inputView = mKeyboardSwitcher.getKeyboardView(); - if (inputView != null) { - inputView.performHapticFeedback( - HapticFeedbackConstants.KEYBOARD_TAP, - HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING); + if (mKeypressVibrationDuration < 0) { + // Go ahead with the system default + LatinKeyboardView inputView = mKeyboardSwitcher.getKeyboardView(); + if (inputView != null) { + inputView.performHapticFeedback( + HapticFeedbackConstants.KEYBOARD_TAP, + HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING); + } + } else if (mVibrator != null) { + mVibrator.vibrate(mKeypressVibrationDuration); } } |