Move AudioAndHapticFeedbackManager from LatinIME to KeyboardSwitcher

Bug: 7313372
Change-Id: I9bd3275f57ed3f5c2c4a95768443af505513ee97
main
Tadashi G. Takaoka 2012-10-15 13:59:35 -07:00 committed by Android (Google) Code Review
parent b0f6b70d44
commit 8e360c68f1
3 changed files with 23 additions and 23 deletions

View File

@ -29,6 +29,7 @@ import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy;
import com.android.inputmethod.keyboard.KeyboardLayoutSet.KeyboardLayoutSetException;
import com.android.inputmethod.keyboard.PointerTracker.TimerProxy;
import com.android.inputmethod.keyboard.internal.KeyboardState;
import com.android.inputmethod.latin.AudioAndHapticFeedbackManager;
import com.android.inputmethod.latin.DebugSettings;
import com.android.inputmethod.latin.ImfUtils;
import com.android.inputmethod.latin.InputView;
@ -65,6 +66,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
new KeyboardTheme(5, R.style.KeyboardTheme_IceCreamSandwich),
};
private AudioAndHapticFeedbackManager mFeedbackManager;
private SubtypeSwitcher mSubtypeSwitcher;
private SharedPreferences mPrefs;
private boolean mForceNonDistinctMultitouch;
@ -102,6 +104,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
private void initInternal(LatinIME latinIme, SharedPreferences prefs) {
mLatinIME = latinIme;
mResources = latinIme.getResources();
mFeedbackManager = new AudioAndHapticFeedbackManager(latinIme);
mPrefs = prefs;
mSubtypeSwitcher = SubtypeSwitcher.getInstance();
mState = new KeyboardState(this);
@ -147,6 +150,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
mKeyboardLayoutSet = builder.build();
try {
mState.onLoadKeyboard(mResources.getString(R.string.layout_switch_back_symbols));
mFeedbackManager.onSettingsChanged(settingsValues);
} catch (KeyboardLayoutSetException e) {
Log.w(TAG, "loading keyboard failed: " + e.mKeyboardId, e.getCause());
LatinImeLogger.logOnException(e.mKeyboardId.toString(), e.getCause());
@ -154,6 +158,10 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
}
}
public void onRingerModeChanged() {
mFeedbackManager.onRingerModeChanged();
}
public void saveKeyboardState() {
if (getKeyboard() != null) {
mState.onSaveKeyboardState();
@ -202,7 +210,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
public void onPressKey(int code) {
if (isVibrateAndSoundFeedbackRequired()) {
mLatinIME.hapticAndAudioFeedback(code);
mFeedbackManager.hapticAndAudioFeedback(code, mKeyboardView);
}
mState.onPressKey(code, isSinglePointer(), mLatinIME.getCurrentAutoCapsState());
}
@ -314,7 +322,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
// Implements {@link KeyboardState.SwitchActions}.
@Override
public void hapticAndAudioFeedback(int code) {
mLatinIME.hapticAndAudioFeedback(code);
mFeedbackManager.hapticAndAudioFeedback(code, mKeyboardView);
}
public void onLongPressTimeout(int code) {

View File

@ -31,17 +31,15 @@ import com.android.inputmethod.latin.VibratorUtils;
* complexity of settings and the like.
*/
public final class AudioAndHapticFeedbackManager {
final private SettingsValues mSettingsValues;
final private AudioManager mAudioManager;
final private VibratorUtils mVibratorUtils;
private final AudioManager mAudioManager;
private final VibratorUtils mVibratorUtils;
private SettingsValues mSettingsValues;
private boolean mSoundOn;
public AudioAndHapticFeedbackManager(final LatinIME latinIme,
final SettingsValues settingsValues) {
mSettingsValues = settingsValues;
public AudioAndHapticFeedbackManager(final LatinIME latinIme) {
mVibratorUtils = VibratorUtils.getInstance(latinIme);
mAudioManager = (AudioManager) latinIme.getSystemService(Context.AUDIO_SERVICE);
mSoundOn = reevaluateIfSoundIsOn();
}
public void hapticAndAudioFeedback(final int primaryCode,
@ -51,7 +49,7 @@ public final class AudioAndHapticFeedbackManager {
}
private boolean reevaluateIfSoundIsOn() {
if (!mSettingsValues.mSoundOn || mAudioManager == null) {
if (mSettingsValues == null || !mSettingsValues.mSoundOn || mAudioManager == null) {
return false;
} else {
return mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_NORMAL;
@ -81,8 +79,7 @@ public final class AudioAndHapticFeedbackManager {
}
}
// TODO: make this private when LatinIME does not call it any more
public void vibrate(final View viewToPerformHapticFeedbackOn) {
private void vibrate(final View viewToPerformHapticFeedbackOn) {
if (!mSettingsValues.mVibrateOn) {
return;
}
@ -98,6 +95,11 @@ public final class AudioAndHapticFeedbackManager {
}
}
public void onSettingsChanged(final SettingsValues settingsValues) {
mSettingsValues = settingsValues;
mSoundOn = reevaluateIfSoundIsOn();
}
public void onRingerModeChanged() {
mSoundOn = reevaluateIfSoundIsOn();
}

View File

@ -163,8 +163,6 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
private int mDeleteCount;
private long mLastKeyTime;
private AudioAndHapticFeedbackManager mFeedbackManager;
// Member variables for remembering the current device orientation.
private int mDisplayOrientation;
@ -438,7 +436,6 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
}
};
mCurrentSettings = job.runInLocale(mResources, mSubtypeSwitcher.getCurrentSubtypeLocale());
mFeedbackManager = new AudioAndHapticFeedbackManager(this, mCurrentSettings);
resetContactsDictionary(null == mSuggest ? null : mSuggest.getContactsDictionary());
}
@ -2251,13 +2248,6 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
mHandler.postUpdateSuggestionStrip();
}
// TODO: Remove this method from {@link LatinIME} and move {@link FeedbackManager} to
// {@link KeyboardSwitcher}. Called from KeyboardSwitcher
public void hapticAndAudioFeedback(final int primaryCode) {
mFeedbackManager.hapticAndAudioFeedback(
primaryCode, mKeyboardSwitcher.getMainKeyboardView());
}
// Callback called by PointerTracker through the KeyboardActionListener. This is called when a
// key is depressed; release matching call is onReleaseKey below.
@Override
@ -2303,7 +2293,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
mSubtypeSwitcher.onNetworkStateChanged(intent);
} else if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) {
mFeedbackManager.onRingerModeChanged();
mKeyboardSwitcher.onRingerModeChanged();
}
}
};