diff options
Diffstat (limited to 'java/src/com/android/inputmethod/latin/LatinIME.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/LatinIME.java | 77 |
1 files changed, 53 insertions, 24 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 61b2e93cc..91a784124 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; @@ -207,9 +209,12 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar private long mLastKeyTime; private AudioManager mAudioManager; - private static float mFxVolume = -1.0f; // just a default value to be updated runtime + private float mFxVolume = -1.0f; // default volume private boolean mSilentModeOn; // System-wide current configuration + private VibratorCompatWrapper mVibrator; + private long mKeypressVibrationDuration = -1; + // TODO: Move this flag to VoiceProxy private boolean mConfigurationChanging; @@ -433,13 +438,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) { @@ -480,6 +486,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() { @@ -2043,13 +2050,14 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar // update sound effect volume private void updateSoundEffectVolume() { - if (mAudioManager == null) { - mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); - if (mAudioManager == null) return; + final String[] volumePerHardwareList = mResources.getStringArray(R.array.keypress_volumes); + final String hardwarePrefix = Build.HARDWARE + ","; + for (final String element : volumePerHardwareList) { + if (element.startsWith(hardwarePrefix)) { + mFxVolume = Float.parseFloat(element.substring(element.lastIndexOf(',') + 1)); + break; + } } - // This aligns with the current media volume minus 6dB - mFxVolume = (float) mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC) - / (float) mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC) / 4.0f; } // update flags for silent mode @@ -2061,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 @@ -2070,17 +2091,20 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar } } if (isSoundOn()) { - int sound = AudioManager.FX_KEYPRESS_STANDARD; + final int sound; switch (primaryCode) { - case Keyboard.CODE_DELETE: - sound = AudioManager.FX_KEYPRESS_DELETE; - break; - case Keyboard.CODE_ENTER: - sound = AudioManager.FX_KEYPRESS_RETURN; - break; - case Keyboard.CODE_SPACE: - sound = AudioManager.FX_KEYPRESS_SPACEBAR; - break; + case Keyboard.CODE_DELETE: + sound = AudioManager.FX_KEYPRESS_DELETE; + break; + case Keyboard.CODE_ENTER: + sound = AudioManager.FX_KEYPRESS_RETURN; + break; + case Keyboard.CODE_SPACE: + sound = AudioManager.FX_KEYPRESS_SPACEBAR; + break; + default: + sound = AudioManager.FX_KEYPRESS_STANDARD; + break; } mAudioManager.playSoundEffect(sound, mFxVolume); } @@ -2090,11 +2114,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); } } |