Merge "Tweak LatinIME's keypress vibration duration"

This commit is contained in:
Ken Wakasa 2011-09-19 19:29:09 -07:00 committed by Android (Google) Code Review
commit 8efe9bb15a
3 changed files with 62 additions and 7 deletions

View file

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
**
** Copyright 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.
*/
-->
<resources>
<string-array name="keypress_vibration_durations" translatable="false">
<!-- Build.HARDWARE,duration_in_milliseconds -->
<item>herring,4</item>
<item>tuna,5</item>
</string-array>
</resources>

View file

@ -44,4 +44,8 @@ public class VibratorCompatWrapper {
return false; return false;
return (Boolean) CompatUtils.invoke(mVibrator, true, METHOD_hasVibrator); return (Boolean) CompatUtils.invoke(mVibrator, true, METHOD_hasVibrator);
} }
public void vibrate(long milliseconds) {
mVibrator.vibrate(milliseconds);
}
} }

View file

@ -28,6 +28,7 @@ import android.content.res.Resources;
import android.inputmethodservice.InputMethodService; import android.inputmethodservice.InputMethodService;
import android.media.AudioManager; import android.media.AudioManager;
import android.net.ConnectivityManager; import android.net.ConnectivityManager;
import android.os.Build;
import android.os.Debug; import android.os.Debug;
import android.os.Message; import android.os.Message;
import android.os.SystemClock; 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.InputMethodServiceCompatWrapper;
import com.android.inputmethod.compat.InputTypeCompatUtils; import com.android.inputmethod.compat.InputTypeCompatUtils;
import com.android.inputmethod.compat.SuggestionSpanUtils; import com.android.inputmethod.compat.SuggestionSpanUtils;
import com.android.inputmethod.compat.VibratorCompatWrapper;
import com.android.inputmethod.deprecated.LanguageSwitcherProxy; import com.android.inputmethod.deprecated.LanguageSwitcherProxy;
import com.android.inputmethod.deprecated.VoiceProxy; import com.android.inputmethod.deprecated.VoiceProxy;
import com.android.inputmethod.deprecated.recorrection.Recorrection; 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 static float mFxVolume = -1.0f; // just a default value to be updated runtime
private boolean mSilentModeOn; // System-wide current configuration private boolean mSilentModeOn; // System-wide current configuration
private VibratorCompatWrapper mVibrator;
private long mKeypressVibrationDuration = -1;
// TODO: Move this flag to VoiceProxy // TODO: Move this flag to VoiceProxy
private boolean mConfigurationChanging; private boolean mConfigurationChanging;
@ -434,13 +439,14 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
mSubtypeSwitcher = SubtypeSwitcher.getInstance(); mSubtypeSwitcher = SubtypeSwitcher.getInstance();
mKeyboardSwitcher = KeyboardSwitcher.getInstance(); mKeyboardSwitcher = KeyboardSwitcher.getInstance();
mRecorrection = Recorrection.getInstance(); mRecorrection = Recorrection.getInstance();
mVibrator = VibratorCompatWrapper.getInstance(this);
DEBUG = LatinImeLogger.sDBG; DEBUG = LatinImeLogger.sDBG;
loadSettings();
final Resources res = getResources(); final Resources res = getResources();
mResources = res; mResources = res;
loadSettings();
Utils.GCUtils.getInstance().reset(); Utils.GCUtils.getInstance().reset();
boolean tryGC = true; boolean tryGC = true;
for (int i = 0; i < Utils.GCUtils.GC_TRY_LOOP_MAX && tryGC; ++i) { 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()); mSettingsValues = new Settings.Values(mPrefs, this, mSubtypeSwitcher.getInputLocaleStr());
resetContactsDictionary(null == mSuggest ? null : mSuggest.getContactsDictionary()); resetContactsDictionary(null == mSuggest ? null : mSuggest.getContactsDictionary());
updateSoundEffectVolume(); updateSoundEffectVolume();
updateKeypressVibrationDuration();
} }
private void initSuggest() { private void initSuggest() {
@ -2062,6 +2069,19 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
mSilentModeOn = (mAudioManager.getRingerMode() != AudioManager.RINGER_MODE_NORMAL); 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) { private void playKeyClick(int primaryCode) {
// if mAudioManager is null, we don't have the ringer state yet // if mAudioManager is null, we don't have the ringer state yet
// mAudioManager will be set by updateRingerMode // mAudioManager will be set by updateRingerMode
@ -2091,12 +2111,17 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
if (!mSettingsValues.mVibrateOn) { if (!mSettingsValues.mVibrateOn) {
return; return;
} }
if (mKeypressVibrationDuration < 0) {
// Go ahead with the system default
LatinKeyboardView inputView = mKeyboardSwitcher.getKeyboardView(); LatinKeyboardView inputView = mKeyboardSwitcher.getKeyboardView();
if (inputView != null) { if (inputView != null) {
inputView.performHapticFeedback( inputView.performHapticFeedback(
HapticFeedbackConstants.KEYBOARD_TAP, HapticFeedbackConstants.KEYBOARD_TAP,
HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING); HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
} }
} else if (mVibrator != null) {
mVibrator.vibrate(mKeypressVibrationDuration);
}
} }
public WordComposer getCurrentWord() { public WordComposer getCurrentWord() {