Move AudioAndHapticFeedbackManager from LatinIME to KeyboardSwitcher
Bug: 7313372 Change-Id: I9bd3275f57ed3f5c2c4a95768443af505513ee97main
parent
b0f6b70d44
commit
8e360c68f1
|
@ -29,6 +29,7 @@ import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy;
|
||||||
import com.android.inputmethod.keyboard.KeyboardLayoutSet.KeyboardLayoutSetException;
|
import com.android.inputmethod.keyboard.KeyboardLayoutSet.KeyboardLayoutSetException;
|
||||||
import com.android.inputmethod.keyboard.PointerTracker.TimerProxy;
|
import com.android.inputmethod.keyboard.PointerTracker.TimerProxy;
|
||||||
import com.android.inputmethod.keyboard.internal.KeyboardState;
|
import com.android.inputmethod.keyboard.internal.KeyboardState;
|
||||||
|
import com.android.inputmethod.latin.AudioAndHapticFeedbackManager;
|
||||||
import com.android.inputmethod.latin.DebugSettings;
|
import com.android.inputmethod.latin.DebugSettings;
|
||||||
import com.android.inputmethod.latin.ImfUtils;
|
import com.android.inputmethod.latin.ImfUtils;
|
||||||
import com.android.inputmethod.latin.InputView;
|
import com.android.inputmethod.latin.InputView;
|
||||||
|
@ -65,6 +66,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
|
||||||
new KeyboardTheme(5, R.style.KeyboardTheme_IceCreamSandwich),
|
new KeyboardTheme(5, R.style.KeyboardTheme_IceCreamSandwich),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private AudioAndHapticFeedbackManager mFeedbackManager;
|
||||||
private SubtypeSwitcher mSubtypeSwitcher;
|
private SubtypeSwitcher mSubtypeSwitcher;
|
||||||
private SharedPreferences mPrefs;
|
private SharedPreferences mPrefs;
|
||||||
private boolean mForceNonDistinctMultitouch;
|
private boolean mForceNonDistinctMultitouch;
|
||||||
|
@ -102,6 +104,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
|
||||||
private void initInternal(LatinIME latinIme, SharedPreferences prefs) {
|
private void initInternal(LatinIME latinIme, SharedPreferences prefs) {
|
||||||
mLatinIME = latinIme;
|
mLatinIME = latinIme;
|
||||||
mResources = latinIme.getResources();
|
mResources = latinIme.getResources();
|
||||||
|
mFeedbackManager = new AudioAndHapticFeedbackManager(latinIme);
|
||||||
mPrefs = prefs;
|
mPrefs = prefs;
|
||||||
mSubtypeSwitcher = SubtypeSwitcher.getInstance();
|
mSubtypeSwitcher = SubtypeSwitcher.getInstance();
|
||||||
mState = new KeyboardState(this);
|
mState = new KeyboardState(this);
|
||||||
|
@ -147,6 +150,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
|
||||||
mKeyboardLayoutSet = builder.build();
|
mKeyboardLayoutSet = builder.build();
|
||||||
try {
|
try {
|
||||||
mState.onLoadKeyboard(mResources.getString(R.string.layout_switch_back_symbols));
|
mState.onLoadKeyboard(mResources.getString(R.string.layout_switch_back_symbols));
|
||||||
|
mFeedbackManager.onSettingsChanged(settingsValues);
|
||||||
} catch (KeyboardLayoutSetException e) {
|
} catch (KeyboardLayoutSetException e) {
|
||||||
Log.w(TAG, "loading keyboard failed: " + e.mKeyboardId, e.getCause());
|
Log.w(TAG, "loading keyboard failed: " + e.mKeyboardId, e.getCause());
|
||||||
LatinImeLogger.logOnException(e.mKeyboardId.toString(), 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() {
|
public void saveKeyboardState() {
|
||||||
if (getKeyboard() != null) {
|
if (getKeyboard() != null) {
|
||||||
mState.onSaveKeyboardState();
|
mState.onSaveKeyboardState();
|
||||||
|
@ -202,7 +210,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
|
||||||
|
|
||||||
public void onPressKey(int code) {
|
public void onPressKey(int code) {
|
||||||
if (isVibrateAndSoundFeedbackRequired()) {
|
if (isVibrateAndSoundFeedbackRequired()) {
|
||||||
mLatinIME.hapticAndAudioFeedback(code);
|
mFeedbackManager.hapticAndAudioFeedback(code, mKeyboardView);
|
||||||
}
|
}
|
||||||
mState.onPressKey(code, isSinglePointer(), mLatinIME.getCurrentAutoCapsState());
|
mState.onPressKey(code, isSinglePointer(), mLatinIME.getCurrentAutoCapsState());
|
||||||
}
|
}
|
||||||
|
@ -314,7 +322,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
|
||||||
// Implements {@link KeyboardState.SwitchActions}.
|
// Implements {@link KeyboardState.SwitchActions}.
|
||||||
@Override
|
@Override
|
||||||
public void hapticAndAudioFeedback(int code) {
|
public void hapticAndAudioFeedback(int code) {
|
||||||
mLatinIME.hapticAndAudioFeedback(code);
|
mFeedbackManager.hapticAndAudioFeedback(code, mKeyboardView);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onLongPressTimeout(int code) {
|
public void onLongPressTimeout(int code) {
|
||||||
|
|
|
@ -31,17 +31,15 @@ import com.android.inputmethod.latin.VibratorUtils;
|
||||||
* complexity of settings and the like.
|
* complexity of settings and the like.
|
||||||
*/
|
*/
|
||||||
public final class AudioAndHapticFeedbackManager {
|
public final class AudioAndHapticFeedbackManager {
|
||||||
final private SettingsValues mSettingsValues;
|
private final AudioManager mAudioManager;
|
||||||
final private AudioManager mAudioManager;
|
private final VibratorUtils mVibratorUtils;
|
||||||
final private VibratorUtils mVibratorUtils;
|
|
||||||
|
private SettingsValues mSettingsValues;
|
||||||
private boolean mSoundOn;
|
private boolean mSoundOn;
|
||||||
|
|
||||||
public AudioAndHapticFeedbackManager(final LatinIME latinIme,
|
public AudioAndHapticFeedbackManager(final LatinIME latinIme) {
|
||||||
final SettingsValues settingsValues) {
|
|
||||||
mSettingsValues = settingsValues;
|
|
||||||
mVibratorUtils = VibratorUtils.getInstance(latinIme);
|
mVibratorUtils = VibratorUtils.getInstance(latinIme);
|
||||||
mAudioManager = (AudioManager) latinIme.getSystemService(Context.AUDIO_SERVICE);
|
mAudioManager = (AudioManager) latinIme.getSystemService(Context.AUDIO_SERVICE);
|
||||||
mSoundOn = reevaluateIfSoundIsOn();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void hapticAndAudioFeedback(final int primaryCode,
|
public void hapticAndAudioFeedback(final int primaryCode,
|
||||||
|
@ -51,7 +49,7 @@ public final class AudioAndHapticFeedbackManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean reevaluateIfSoundIsOn() {
|
private boolean reevaluateIfSoundIsOn() {
|
||||||
if (!mSettingsValues.mSoundOn || mAudioManager == null) {
|
if (mSettingsValues == null || !mSettingsValues.mSoundOn || mAudioManager == null) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
return mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_NORMAL;
|
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
|
private void vibrate(final View viewToPerformHapticFeedbackOn) {
|
||||||
public void vibrate(final View viewToPerformHapticFeedbackOn) {
|
|
||||||
if (!mSettingsValues.mVibrateOn) {
|
if (!mSettingsValues.mVibrateOn) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -98,6 +95,11 @@ public final class AudioAndHapticFeedbackManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onSettingsChanged(final SettingsValues settingsValues) {
|
||||||
|
mSettingsValues = settingsValues;
|
||||||
|
mSoundOn = reevaluateIfSoundIsOn();
|
||||||
|
}
|
||||||
|
|
||||||
public void onRingerModeChanged() {
|
public void onRingerModeChanged() {
|
||||||
mSoundOn = reevaluateIfSoundIsOn();
|
mSoundOn = reevaluateIfSoundIsOn();
|
||||||
}
|
}
|
||||||
|
|
|
@ -163,8 +163,6 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
|
||||||
private int mDeleteCount;
|
private int mDeleteCount;
|
||||||
private long mLastKeyTime;
|
private long mLastKeyTime;
|
||||||
|
|
||||||
private AudioAndHapticFeedbackManager mFeedbackManager;
|
|
||||||
|
|
||||||
// Member variables for remembering the current device orientation.
|
// Member variables for remembering the current device orientation.
|
||||||
private int mDisplayOrientation;
|
private int mDisplayOrientation;
|
||||||
|
|
||||||
|
@ -438,7 +436,6 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
mCurrentSettings = job.runInLocale(mResources, mSubtypeSwitcher.getCurrentSubtypeLocale());
|
mCurrentSettings = job.runInLocale(mResources, mSubtypeSwitcher.getCurrentSubtypeLocale());
|
||||||
mFeedbackManager = new AudioAndHapticFeedbackManager(this, mCurrentSettings);
|
|
||||||
resetContactsDictionary(null == mSuggest ? null : mSuggest.getContactsDictionary());
|
resetContactsDictionary(null == mSuggest ? null : mSuggest.getContactsDictionary());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2251,13 +2248,6 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
|
||||||
mHandler.postUpdateSuggestionStrip();
|
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
|
// Callback called by PointerTracker through the KeyboardActionListener. This is called when a
|
||||||
// key is depressed; release matching call is onReleaseKey below.
|
// key is depressed; release matching call is onReleaseKey below.
|
||||||
@Override
|
@Override
|
||||||
|
@ -2303,7 +2293,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
|
||||||
if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
|
if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
|
||||||
mSubtypeSwitcher.onNetworkStateChanged(intent);
|
mSubtypeSwitcher.onNetworkStateChanged(intent);
|
||||||
} else if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) {
|
} else if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) {
|
||||||
mFeedbackManager.onRingerModeChanged();
|
mKeyboardSwitcher.onRingerModeChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue