Merge "Get the view for haptic feedback as a parameter (A6)"

This commit is contained in:
Jean Chalard 2012-03-08 02:32:39 -08:00 committed by Android (Google) Code Review
commit 663aabca0c
2 changed files with 11 additions and 15 deletions

View File

@ -21,11 +21,10 @@ import android.content.Context;
import android.content.Intent;
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.keyboard.KeyboardSwitcher;
import com.android.inputmethod.keyboard.LatinKeyboardView;
/**
* This class gathers audio feedback and haptic feedback functions.
@ -35,22 +34,21 @@ import com.android.inputmethod.keyboard.LatinKeyboardView;
*/
public class AudioAndHapticFeedbackManager extends BroadcastReceiver {
final private SettingsValues mSettingsValues;
final private KeyboardSwitcher mKeyboardSwitcher;
final private AudioManager mAudioManager;
final private VibratorCompatWrapper mVibrator;
private boolean mSoundOn;
public AudioAndHapticFeedbackManager(final LatinIME latinIme,
final SettingsValues settingsValues, final KeyboardSwitcher keyboardSwitcher) {
final SettingsValues settingsValues) {
mSettingsValues = settingsValues;
mKeyboardSwitcher = keyboardSwitcher;
mVibrator = VibratorCompatWrapper.getInstance(latinIme);
mAudioManager = (AudioManager) latinIme.getSystemService(Context.AUDIO_SERVICE);
mSoundOn = reevaluateIfSoundIsOn();
}
public void hapticAndAudioFeedback(final int primaryCode) {
vibrate();
public void hapticAndAudioFeedback(final int primaryCode,
final View viewToPerformHapticFeedbackOn) {
vibrate(viewToPerformHapticFeedbackOn);
playKeyClick(primaryCode);
}
@ -86,15 +84,14 @@ public class AudioAndHapticFeedbackManager extends BroadcastReceiver {
}
// TODO: make this private when LatinIME does not call it any more
public void vibrate() {
public void vibrate(final View viewToPerformHapticFeedbackOn) {
if (!mSettingsValues.mVibrateOn) {
return;
}
if (mSettingsValues.mKeypressVibrationDuration < 0) {
// Go ahead with the system default
LatinKeyboardView inputView = mKeyboardSwitcher.getKeyboardView();
if (inputView != null) {
inputView.performHapticFeedback(
if (viewToPerformHapticFeedbackOn != null) {
viewToPerformHapticFeedbackOn.performHapticFeedback(
HapticFeedbackConstants.KEYBOARD_TAP,
HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
}

View File

@ -557,8 +557,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
/* package */ void loadSettings() {
if (null == mPrefs) mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
mSettingsValues = new SettingsValues(mPrefs, this, mSubtypeSwitcher.getInputLocaleStr());
mFeedbackManager = new AudioAndHapticFeedbackManager(this, mSettingsValues,
mKeyboardSwitcher);
mFeedbackManager = new AudioAndHapticFeedbackManager(this, mSettingsValues);
resetContactsDictionary(null == mSuggest ? null : mSuggest.getContactsDictionary());
}
@ -2322,7 +2321,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
}
public void hapticAndAudioFeedback(final int primaryCode) {
mFeedbackManager.hapticAndAudioFeedback(primaryCode);
mFeedbackManager.hapticAndAudioFeedback(primaryCode, mKeyboardSwitcher.getKeyboardView());
}
@Override
@ -2360,7 +2359,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
// TODO: remove this method when VoiceProxy has been removed
public void vibrate() {
mFeedbackManager.vibrate();
mFeedbackManager.vibrate(mKeyboardSwitcher.getKeyboardView());
}
public boolean isAutoCapitalized() {