From 856b582cfb1eb8f6e683c7520d9cdb85ef9f2186 Mon Sep 17 00:00:00 2001 From: Ken Wakasa Date: Wed, 20 Jul 2011 16:51:05 +0900 Subject: Vibrator.hasVibrator() takes no parameter. bug: 5038842 Change-Id: I239a2f35488a1f18ecdb019abc50e72e3e9da297 --- java/src/com/android/inputmethod/compat/VibratorCompatWrapper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'java/src/com/android/inputmethod/compat/VibratorCompatWrapper.java') diff --git a/java/src/com/android/inputmethod/compat/VibratorCompatWrapper.java b/java/src/com/android/inputmethod/compat/VibratorCompatWrapper.java index 8e2a2e0b8..a6304d877 100644 --- a/java/src/com/android/inputmethod/compat/VibratorCompatWrapper.java +++ b/java/src/com/android/inputmethod/compat/VibratorCompatWrapper.java @@ -23,7 +23,7 @@ import java.lang.reflect.Method; public class VibratorCompatWrapper { private static final Method METHOD_hasVibrator = CompatUtils.getMethod(Vibrator.class, - "hasVibrator", int.class); + "hasVibrator"); private static final VibratorCompatWrapper sInstance = new VibratorCompatWrapper(); private Vibrator mVibrator; -- cgit v1.2.3-83-g751a From 28f36d68afe8d323d1032d0e03fe3013449e21fe Mon Sep 17 00:00:00 2001 From: Ken Wakasa Date: Mon, 19 Sep 2011 14:51:31 +0900 Subject: Tweak LatinIME's keypress vibration duration bug: 5337363 Change-Id: If6e6de587cbcddf26710d8f0b237c4bc393589b6 --- java/res/values/keypress-vibration-durations.xml | 26 +++++++++++++++ .../inputmethod/compat/VibratorCompatWrapper.java | 4 +++ .../com/android/inputmethod/latin/LatinIME.java | 39 ++++++++++++++++++---- 3 files changed, 62 insertions(+), 7 deletions(-) create mode 100644 java/res/values/keypress-vibration-durations.xml (limited to 'java/src/com/android/inputmethod/compat/VibratorCompatWrapper.java') diff --git a/java/res/values/keypress-vibration-durations.xml b/java/res/values/keypress-vibration-durations.xml new file mode 100644 index 000000000..d50986629 --- /dev/null +++ b/java/res/values/keypress-vibration-durations.xml @@ -0,0 +1,26 @@ + + + + + + herring,4 + tuna,5 + + 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); } } -- cgit v1.2.3-83-g751a From 376eb52450ffdc3d4580b405fc049144395c407f Mon Sep 17 00:00:00 2001 From: Ken Wakasa Date: Fri, 30 Mar 2012 18:47:24 +0900 Subject: Move VibratorCompatWrapper to VibratorUtils. bug: 6129704 Change-Id: Ib63f1ed2d610e27e14957cf8805ef884cae6adf6 --- .../inputmethod/compat/VibratorCompatWrapper.java | 51 ---------------------- .../latin/AudioAndHapticFeedbackManager.java | 10 ++--- .../com/android/inputmethod/latin/Settings.java | 8 ++-- .../android/inputmethod/latin/SettingsValues.java | 4 +- .../android/inputmethod/latin/VibratorUtils.java | 50 +++++++++++++++++++++ 5 files changed, 61 insertions(+), 62 deletions(-) delete mode 100644 java/src/com/android/inputmethod/compat/VibratorCompatWrapper.java create mode 100644 java/src/com/android/inputmethod/latin/VibratorUtils.java (limited to 'java/src/com/android/inputmethod/compat/VibratorCompatWrapper.java') diff --git a/java/src/com/android/inputmethod/compat/VibratorCompatWrapper.java b/java/src/com/android/inputmethod/compat/VibratorCompatWrapper.java deleted file mode 100644 index 2fb8b8710..000000000 --- a/java/src/com/android/inputmethod/compat/VibratorCompatWrapper.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2011 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.inputmethod.compat; - -import android.content.Context; -import android.os.Vibrator; - -import java.lang.reflect.Method; - -public class VibratorCompatWrapper { - private static final Method METHOD_hasVibrator = CompatUtils.getMethod(Vibrator.class, - "hasVibrator"); - - private static final VibratorCompatWrapper sInstance = new VibratorCompatWrapper(); - private Vibrator mVibrator; - - private VibratorCompatWrapper() { - } - - public static VibratorCompatWrapper getInstance(Context context) { - if (sInstance.mVibrator == null) { - sInstance.mVibrator = - (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); - } - return sInstance; - } - - public boolean hasVibrator() { - if (mVibrator == null) - 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/AudioAndHapticFeedbackManager.java b/java/src/com/android/inputmethod/latin/AudioAndHapticFeedbackManager.java index 9c5ccc76b..55664d411 100644 --- a/java/src/com/android/inputmethod/latin/AudioAndHapticFeedbackManager.java +++ b/java/src/com/android/inputmethod/latin/AudioAndHapticFeedbackManager.java @@ -21,8 +21,8 @@ import android.media.AudioManager; import android.view.HapticFeedbackConstants; import android.view.View; -import com.android.inputmethod.compat.VibratorCompatWrapper; import com.android.inputmethod.keyboard.Keyboard; +import com.android.inputmethod.latin.VibratorUtils; /** * This class gathers audio feedback and haptic feedback functions. @@ -33,13 +33,13 @@ import com.android.inputmethod.keyboard.Keyboard; public class AudioAndHapticFeedbackManager { final private SettingsValues mSettingsValues; final private AudioManager mAudioManager; - final private VibratorCompatWrapper mVibrator; + final private VibratorUtils mVibratorUtils; private boolean mSoundOn; public AudioAndHapticFeedbackManager(final LatinIME latinIme, final SettingsValues settingsValues) { mSettingsValues = settingsValues; - mVibrator = VibratorCompatWrapper.getInstance(latinIme); + mVibratorUtils = VibratorUtils.getInstance(latinIme); mAudioManager = (AudioManager) latinIme.getSystemService(Context.AUDIO_SERVICE); mSoundOn = reevaluateIfSoundIsOn(); } @@ -93,8 +93,8 @@ public class AudioAndHapticFeedbackManager { HapticFeedbackConstants.KEYBOARD_TAP, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING); } - } else if (mVibrator != null) { - mVibrator.vibrate(mSettingsValues.mKeypressVibrationDuration); + } else if (mVibratorUtils != null) { + mVibratorUtils.vibrate(mSettingsValues.mKeypressVibrationDuration); } } diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java index 650dcdc68..fd61292df 100644 --- a/java/src/com/android/inputmethod/latin/Settings.java +++ b/java/src/com/android/inputmethod/latin/Settings.java @@ -44,7 +44,7 @@ import android.widget.TextView; import com.android.inputmethod.compat.CompatUtils; import com.android.inputmethod.compat.InputMethodServiceCompatWrapper; -import com.android.inputmethod.compat.VibratorCompatWrapper; +import com.android.inputmethod.latin.VibratorUtils; import com.android.inputmethod.latin.define.ProductionFlag; import com.android.inputmethodcommon.InputMethodSettingsActivity; @@ -179,7 +179,7 @@ public class Settings extends InputMethodSettingsActivity generalSettings.removePreference(mVoicePreference); } - if (!VibratorCompatWrapper.getInstance(context).hasVibrator()) { + if (!VibratorUtils.getInstance(context).hasVibrator()) { generalSettings.removePreference(findPreference(PREF_VIBRATE_ON)); } @@ -358,7 +358,7 @@ public class Settings extends InputMethodSettingsActivity private void refreshEnablingsOfKeypressSoundAndVibrationSettings( SharedPreferences sp, Resources res) { if (mKeypressVibrationDurationSettingsPref != null) { - final boolean hasVibrator = VibratorCompatWrapper.getInstance(this).hasVibrator(); + final boolean hasVibrator = VibratorUtils.getInstance(this).hasVibrator(); final boolean vibrateOn = hasVibrator && sp.getBoolean(Settings.PREF_VIBRATE_ON, res.getBoolean(R.bool.config_default_vibration_enabled)); mKeypressVibrationDurationSettingsPref.setEnabled(vibrateOn); @@ -421,7 +421,7 @@ public class Settings extends InputMethodSettingsActivity @Override public void onStopTrackingTouch(SeekBar arg0) { final int tempMs = arg0.getProgress(); - VibratorCompatWrapper.getInstance(context).vibrate(tempMs); + VibratorUtils.getInstance(context).vibrate(tempMs); } }); sb.setProgress(currentMs); diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index c1335fdfe..0ad685bdb 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -23,8 +23,8 @@ import android.util.Log; import android.view.inputmethod.EditorInfo; import com.android.inputmethod.compat.InputTypeCompatUtils; -import com.android.inputmethod.compat.VibratorCompatWrapper; import com.android.inputmethod.keyboard.internal.KeySpecParser; +import com.android.inputmethod.latin.VibratorUtils; import java.util.ArrayList; import java.util.Arrays; @@ -187,7 +187,7 @@ public class SettingsValues { private static boolean isVibrateOn(final Context context, final SharedPreferences prefs, final Resources res) { - final boolean hasVibrator = VibratorCompatWrapper.getInstance(context).hasVibrator(); + final boolean hasVibrator = VibratorUtils.getInstance(context).hasVibrator(); return hasVibrator && prefs.getBoolean(Settings.PREF_VIBRATE_ON, res.getBoolean(R.bool.config_default_vibration_enabled)); } diff --git a/java/src/com/android/inputmethod/latin/VibratorUtils.java b/java/src/com/android/inputmethod/latin/VibratorUtils.java new file mode 100644 index 000000000..33ffdd9c9 --- /dev/null +++ b/java/src/com/android/inputmethod/latin/VibratorUtils.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.inputmethod.latin; + +import android.content.Context; +import android.os.Vibrator; + +public class VibratorUtils { + private static final VibratorUtils sInstance = new VibratorUtils(); + private Vibrator mVibrator; + + private VibratorUtils() { + // This utility class is not publicly instantiable. + } + + public static VibratorUtils getInstance(Context context) { + if (sInstance.mVibrator == null) { + sInstance.mVibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); + } + return sInstance; + } + + public boolean hasVibrator() { + if (mVibrator == null) { + return false; + } + return mVibrator.hasVibrator(); + } + + public void vibrate(long milliseconds) { + if (mVibrator == null) { + return; + } + mVibrator.vibrate(milliseconds); + } +} -- cgit v1.2.3-83-g751a