aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/LatinIME.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/latin/LatinIME.java')
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java138
1 files changed, 33 insertions, 105 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 1858db949..273593dfb 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -40,12 +40,11 @@ import android.text.TextUtils;
import android.util.Log;
import android.util.PrintWriterPrinter;
import android.util.Printer;
-import android.view.HapticFeedbackConstants;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
-import android.view.ViewParent;
import android.view.ViewGroup.LayoutParams;
+import android.view.ViewParent;
import android.view.inputmethod.CompletionInfo;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.ExtractedText;
@@ -61,7 +60,6 @@ import com.android.inputmethod.compat.InputMethodServiceCompatWrapper;
import com.android.inputmethod.compat.InputMethodSubtypeCompatWrapper;
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.keyboard.Keyboard;
@@ -223,10 +221,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
private int mDeleteCount;
private long mLastKeyTime;
- private AudioManager mAudioManager;
- private boolean mSilentModeOn; // System-wide current configuration
-
- private VibratorCompatWrapper mVibrator;
+ private AudioAndHapticFeedbackManager mFeedbackManager;
// Member variables for remembering the current device orientation.
private int mDisplayOrientation;
@@ -238,8 +233,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
// Keeps track of most recently inserted text (multi-character key) for reverting
private CharSequence mEnteredText;
- private final ComposingStateManager mComposingStateManager =
- ComposingStateManager.getInstance();
+ private boolean mIsAutoCorrectionIndicatorOn;
public final UIHandler mHandler = new UIHandler(this);
@@ -511,7 +505,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
super.onCreate();
mImm = InputMethodManagerCompatWrapper.getInstance();
- mVibrator = VibratorCompatWrapper.getInstance(this);
mHandler.onCreate();
DEBUG = LatinImeLogger.sDBG;
@@ -538,11 +531,14 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
// Register to receive ringer mode change and network state change.
// Also receive installation and removal of a dictionary pack.
final IntentFilter filter = new IntentFilter();
- filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);
filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
registerReceiver(mReceiver, filter);
mVoiceProxy = VoiceProxy.init(this, prefs, mHandler);
+ final IntentFilter ringerModeFilter = new IntentFilter();
+ ringerModeFilter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);
+ registerReceiver(mFeedbackManager, ringerModeFilter);
+
final IntentFilter packageFilter = new IntentFilter();
packageFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
packageFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
@@ -559,6 +555,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);
resetContactsDictionary(null == mSuggest ? null : mSuggest.getContactsDictionary());
}
@@ -576,7 +573,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
oldContactsDictionary = null;
}
- int mainDicResId = Utils.getMainDictionaryResourceId(res);
+ int mainDicResId = DictionaryFactory.getMainDictionaryResourceId(res);
mSuggest = new Suggest(this, mainDicResId, keyboardLocale);
if (mSettingsValues.mAutoCorrectEnabled) {
mSuggest.setAutoCorrectionThreshold(mSettingsValues.mAutoCorrectionThreshold);
@@ -636,7 +633,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
/* package private */ void resetSuggestMainDict() {
final String localeStr = mSubtypeSwitcher.getInputLocaleStr();
final Locale keyboardLocale = LocaleUtils.constructLocaleFromString(localeStr);
- int mainDicResId = Utils.getMainDictionaryResourceId(mResources);
+ int mainDicResId = DictionaryFactory.getMainDictionaryResourceId(mResources);
mSuggest.resetMainDict(this, mainDicResId, keyboardLocale);
}
@@ -647,6 +644,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
mSuggest = null;
}
unregisterReceiver(mReceiver);
+ unregisterReceiver(mFeedbackManager);
unregisterReceiver(mDictionaryPackInstallReceiver);
mVoiceProxy.destroy();
LatinImeLogger.commit();
@@ -657,7 +655,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
@Override
public void onConfigurationChanged(Configuration conf) {
mSubtypeSwitcher.onConfigurationChanged(conf);
- mComposingStateManager.onFinishComposingText();
// If orientation changed while predicting, commit the change
if (mDisplayOrientation != conf.orientation) {
mDisplayOrientation = conf.orientation;
@@ -745,12 +742,12 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
+ String.format("inputType=0x%08x imeOptions=0x%08x",
editorInfo.inputType, editorInfo.imeOptions));
}
- if (Utils.inPrivateImeOptions(null, IME_OPTION_NO_MICROPHONE_COMPAT, editorInfo)) {
+ if (StringUtils.inPrivateImeOptions(null, IME_OPTION_NO_MICROPHONE_COMPAT, editorInfo)) {
Log.w(TAG, "Deprecated private IME option specified: "
+ editorInfo.privateImeOptions);
Log.w(TAG, "Use " + getPackageName() + "." + IME_OPTION_NO_MICROPHONE + " instead");
}
- if (Utils.inPrivateImeOptions(getPackageName(), IME_OPTION_FORCE_ASCII, editorInfo)) {
+ if (StringUtils.inPrivateImeOptions(getPackageName(), IME_OPTION_FORCE_ASCII, editorInfo)) {
Log.w(TAG, "Deprecated private IME option specified: "
+ editorInfo.privateImeOptions);
Log.w(TAG, "Use EditorInfo.IME_FLAG_FORCE_ASCII flag instead");
@@ -1148,7 +1145,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
// and the composingStateManager about it.
private void resetEntireInputState() {
resetComposingState(true /* alsoResetLastComposedWord */);
- mComposingStateManager.onFinishComposingText();
updateSuggestions();
final InputConnection ic = getCurrentInputConnection();
if (ic != null) {
@@ -1207,7 +1203,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
if (ic == null) return false;
final CharSequence lastThree = ic.getTextBeforeCursor(3, 0);
if (lastThree != null && lastThree.length() == 3
- && Utils.canBeFollowedByPeriod(lastThree.charAt(0))
+ && StringUtils.canBeFollowedByPeriod(lastThree.charAt(0))
&& lastThree.charAt(1) == Keyboard.CODE_SPACE
&& lastThree.charAt(2) == Keyboard.CODE_SPACE
&& mHandler.isAcceptingDoubleSpaces()) {
@@ -1247,7 +1243,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
if (isShowingOptionDialog()) return;
if (InputMethodServiceCompatWrapper.CAN_HANDLE_ON_CURRENT_INPUT_METHOD_SUBTYPE_CHANGED) {
showSubtypeSelectorAndSettings();
- } else if (Utils.hasMultipleEnabledIMEsOrSubtypes(false /* exclude aux subtypes */)) {
+ } else if (SubtypeUtils.hasMultipleEnabledIMEsOrSubtypes(
+ false /* exclude aux subtypes */)) {
showOptionsMenu();
} else {
launchSettings();
@@ -1263,7 +1260,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
if (isShowingOptionDialog()) return false;
switch (requestCode) {
case CODE_SHOW_INPUT_METHOD_PICKER:
- if (Utils.hasMultipleEnabledIMEsOrSubtypes(true /* include aux subtypes */)) {
+ if (SubtypeUtils.hasMultipleEnabledIMEsOrSubtypes(true /* include aux subtypes */)) {
mImm.showInputMethodPicker();
return true;
}
@@ -1295,7 +1292,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
final IBinder token = getWindow().getWindow().getAttributes().token;
if (mShouldSwitchToLastSubtype) {
final InputMethodSubtypeCompatWrapper lastSubtype = mImm.getLastInputMethodSubtype();
- final boolean lastSubtypeBelongsToThisIme = Utils.checkIfSubtypeBelongsToThisIme(
+ final boolean lastSubtypeBelongsToThisIme = SubtypeUtils.checkIfSubtypeBelongsToThisIme(
this, lastSubtype);
if ((includesOtherImes || lastSubtypeBelongsToThisIme)
&& mImm.switchToLastInputMethod(token)) {
@@ -1339,6 +1336,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
// all inputs that do not result in a special state. Each character handling is then
// free to override the state as they see fit.
final int spaceState = mSpaceState;
+ if (!mWordComposer.isComposingWord()) mIsAutoCorrectionIndicatorOn = false;
// TODO: Consolidate the double space timer, mLastKeyTime, and the space state.
if (primaryCode != Keyboard.CODE_SPACE) {
@@ -1588,7 +1586,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
// it entirely and resume suggestions on the previous word, we'd like to still
// have touch coordinates for it.
resetComposingState(false /* alsoResetLastComposedWord */);
- mComposingStateManager.onFinishComposingText();
clearSuggestions();
}
}
@@ -1599,7 +1596,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
// If it's the first letter, make note of auto-caps state
if (mWordComposer.size() == 1) {
mWordComposer.setAutoCapitalized(getCurrentAutoCapsState());
- mComposingStateManager.onStartComposingText();
}
ic.setComposingText(getTextWithUnderline(mWordComposer.getTypedWord()), 1);
}
@@ -1631,7 +1627,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
private boolean handleSeparator(final int primaryCode, final int x, final int y,
final int spaceState) {
mVoiceProxy.handleSeparator();
- mComposingStateManager.onFinishComposingText();
// Should dismiss the "Touch again to save" message when handling separator
if (mSuggestionsView != null && mSuggestionsView.dismissAddToDictionaryHint()) {
@@ -1711,7 +1706,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
}
private CharSequence getTextWithUnderline(final CharSequence text) {
- return mComposingStateManager.isAutoCorrectionIndicatorOn()
+ return mIsAutoCorrectionIndicatorOn
? SuggestionSpanUtils.getTextWithAutoCorrectionIndicatorUnderline(this, text)
: text;
}
@@ -1787,15 +1782,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
// Put a blue underline to a word in TextView which will be auto-corrected.
final InputConnection ic = getCurrentInputConnection();
if (ic != null) {
- final boolean oldAutoCorrectionIndicator =
- mComposingStateManager.isAutoCorrectionIndicatorOn();
- if (oldAutoCorrectionIndicator != newAutoCorrectionIndicator) {
- mComposingStateManager.setAutoCorrectionIndicatorOn(newAutoCorrectionIndicator);
- if (DEBUG) {
- Log.d(TAG, "Flip the indicator. " + oldAutoCorrectionIndicator
- + " -> " + newAutoCorrectionIndicator);
- }
+ if (mIsAutoCorrectionIndicatorOn != newAutoCorrectionIndicator) {
if (mWordComposer.isComposingWord()) {
+ mIsAutoCorrectionIndicatorOn = newAutoCorrectionIndicator;
final CharSequence textWithUnderline =
getTextWithUnderline(mWordComposer.getTypedWord());
ic.setComposingText(textWithUnderline, 1);
@@ -1884,7 +1873,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
builder.addTypedWordAndPreviousSuggestions(typedWord, previousSuggestions);
}
}
- if (Utils.shouldBlockAutoCorrectionBySafetyNet(builder, mSuggest)) {
+ if (Suggest.shouldBlockAutoCorrectionBySafetyNet(builder, mSuggest)) {
builder.setShouldBlockAutoCorrectionBySafetyNet();
}
showSuggestions(builder.build(), typedWord);
@@ -1941,7 +1930,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
@Override
public void pickSuggestionManually(final int index, final CharSequence suggestion) {
- mComposingStateManager.onFinishComposingText();
final SuggestedWords suggestedWords = mSuggestionsView.getSuggestions();
mVoiceProxy.flushAndLogAllTextModificationCounters(index, suggestion,
mSettingsValues.mWordSeparators);
@@ -2144,14 +2132,12 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
public boolean isCursorTouchingWord() {
final InputConnection ic = getCurrentInputConnection();
if (ic == null) return false;
- CharSequence toLeft = ic.getTextBeforeCursor(1, 0);
- CharSequence toRight = ic.getTextAfterCursor(1, 0);
- if (!TextUtils.isEmpty(toLeft)
- && !mSettingsValues.isWordSeparator(toLeft.charAt(0))) {
+ CharSequence before = ic.getTextBeforeCursor(1, 0);
+ CharSequence after = ic.getTextAfterCursor(1, 0);
+ if (!TextUtils.isEmpty(before) && !mSettingsValues.isWordSeparator(before.charAt(0))) {
return true;
}
- if (!TextUtils.isEmpty(toRight)
- && !mSettingsValues.isWordSeparator(toRight.charAt(0))) {
+ if (!TextUtils.isEmpty(after) && !mSettingsValues.isWordSeparator(after.charAt(0))) {
return true;
}
return false;
@@ -2212,7 +2198,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
private void restartSuggestionsOnWordBeforeCursor(final InputConnection ic,
final CharSequence word) {
mWordComposer.setComposingWord(word, mKeyboardSwitcher.getKeyboard());
- mComposingStateManager.onStartComposingText();
ic.deleteSurroundingText(word.length(), 0);
ic.setComposingText(word, 1);
mHandler.postUpdateSuggestions();
@@ -2244,7 +2229,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
// This is the case when we cancel a manual pick.
// We should restart suggestion on the word right away.
mWordComposer.resumeSuggestionOnLastComposedWord(mLastComposedWord);
- mComposingStateManager.onStartComposingText();
ic.setComposingText(originallyTypedWord, 1);
} else {
ic.commitText(originallyTypedWord, 1);
@@ -2335,9 +2319,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
}
}
- public void hapticAndAudioFeedback(int primaryCode) {
- vibrate();
- playKeyClick(primaryCode);
+ public void hapticAndAudioFeedback(final int primaryCode) {
+ mFeedbackManager.hapticAndAudioFeedback(primaryCode, mKeyboardSwitcher.getKeyboardView());
}
@Override
@@ -2367,76 +2350,21 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
@Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
- if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) {
- updateRingerMode();
- } else if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
+ if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
mSubtypeSwitcher.onNetworkStateChanged(intent);
}
}
};
- // update flags for silent mode
- private void updateRingerMode() {
- if (mAudioManager == null) {
- mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
- if (mAudioManager == null) return;
- }
- mSilentModeOn = (mAudioManager.getRingerMode() != AudioManager.RINGER_MODE_NORMAL);
- }
-
- private void playKeyClick(int primaryCode) {
- // if mAudioManager is null, we don't have the ringer state yet
- // mAudioManager will be set by updateRingerMode
- if (mAudioManager == null) {
- if (mKeyboardSwitcher.getKeyboardView() != null) {
- updateRingerMode();
- }
- }
- if (isSoundOn()) {
- final int sound;
- switch (primaryCode) {
- case Keyboard.CODE_DELETE:
- sound = AudioManager.FX_KEYPRESS_DELETE;
- break;
- case Keyboard.CODE_ENTER:
- sound = AudioManager.FX_KEYPRESS_RETURN;
- break;
- case Keyboard.CODE_SPACE:
- sound = AudioManager.FX_KEYPRESS_SPACEBAR;
- break;
- default:
- sound = AudioManager.FX_KEYPRESS_STANDARD;
- break;
- }
- mAudioManager.playSoundEffect(sound, mSettingsValues.mFxVolume);
- }
- }
-
+ // TODO: remove this method when VoiceProxy has been removed
public void vibrate() {
- if (!mSettingsValues.mVibrateOn) {
- return;
- }
- if (mSettingsValues.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(mSettingsValues.mKeypressVibrationDuration);
- }
+ mFeedbackManager.vibrate(mKeyboardSwitcher.getKeyboardView());
}
public boolean isAutoCapitalized() {
return mWordComposer.isAutoCapitalized();
}
- boolean isSoundOn() {
- return mSettingsValues.mSoundOn && !mSilentModeOn;
- }
-
private void updateCorrectionMode() {
// TODO: cleanup messy flags
final boolean shouldAutoCorrect = mSettingsValues.mAutoCorrectEnabled
@@ -2486,7 +2414,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
switch (position) {
case 0:
Intent intent = CompatUtils.getInputLanguageSelectionIntent(
- Utils.getInputMethodId(getPackageName()),
+ SubtypeUtils.getInputMethodId(getPackageName()),
Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
| Intent.FLAG_ACTIVITY_CLEAR_TOP);