2009-03-13 22:11:42 +00:00
|
|
|
/*
|
2010-03-26 22:07:10 +00:00
|
|
|
* Copyright (C) 2008 The Android Open Source Project
|
2010-09-15 04:03:34 +00:00
|
|
|
*
|
2009-03-13 22:11:42 +00:00
|
|
|
* 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
|
2010-01-28 18:09:44 +00:00
|
|
|
*
|
2009-03-13 22:11:42 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2010-01-28 18:09:44 +00:00
|
|
|
*
|
2009-03-13 22:11:42 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package com.android.inputmethod.latin;
|
|
|
|
|
2011-03-17 02:37:51 +00:00
|
|
|
import com.android.inputmethod.compat.CompatUtils;
|
2011-03-24 06:18:49 +00:00
|
|
|
import com.android.inputmethod.compat.EditorInfoCompatUtils;
|
|
|
|
import com.android.inputmethod.compat.InputConnectionCompatUtils;
|
2011-03-18 05:49:06 +00:00
|
|
|
import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
|
2011-03-19 04:22:28 +00:00
|
|
|
import com.android.inputmethod.compat.InputMethodServiceCompatWrapper;
|
2011-03-25 06:28:29 +00:00
|
|
|
import com.android.inputmethod.compat.InputTypeCompatUtils;
|
2011-03-23 21:36:37 +00:00
|
|
|
import com.android.inputmethod.compat.VibratorCompatWrapper;
|
2011-04-08 10:57:13 +00:00
|
|
|
import com.android.inputmethod.deprecated.LanguageSwitcherProxy;
|
2011-03-25 06:28:29 +00:00
|
|
|
import com.android.inputmethod.deprecated.VoiceProxy;
|
2010-12-02 09:46:21 +00:00
|
|
|
import com.android.inputmethod.keyboard.Keyboard;
|
|
|
|
import com.android.inputmethod.keyboard.KeyboardActionListener;
|
2010-12-02 11:54:32 +00:00
|
|
|
import com.android.inputmethod.keyboard.KeyboardSwitcher;
|
2010-12-02 09:46:21 +00:00
|
|
|
import com.android.inputmethod.keyboard.KeyboardView;
|
2011-01-12 11:33:54 +00:00
|
|
|
import com.android.inputmethod.keyboard.LatinKeyboard;
|
2010-12-02 09:46:21 +00:00
|
|
|
import com.android.inputmethod.keyboard.LatinKeyboardView;
|
2010-01-15 21:43:50 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.app.AlertDialog;
|
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.DialogInterface;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.IntentFilter;
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.content.res.Configuration;
|
2009-10-12 20:48:35 +00:00
|
|
|
import android.content.res.Resources;
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.inputmethodservice.InputMethodService;
|
|
|
|
import android.media.AudioManager;
|
2011-01-26 14:13:18 +00:00
|
|
|
import android.net.ConnectivityManager;
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.os.Debug;
|
|
|
|
import android.os.Handler;
|
2011-03-01 22:20:27 +00:00
|
|
|
import android.os.IBinder;
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.os.Message;
|
|
|
|
import android.os.SystemClock;
|
2010-09-27 03:55:21 +00:00
|
|
|
import android.preference.PreferenceActivity;
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.preference.PreferenceManager;
|
2010-12-10 06:24:28 +00:00
|
|
|
import android.text.InputType;
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.text.TextUtils;
|
2010-08-20 05:35:02 +00:00
|
|
|
import android.util.DisplayMetrics;
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.util.Log;
|
|
|
|
import android.util.PrintWriterPrinter;
|
|
|
|
import android.util.Printer;
|
2010-02-11 01:45:35 +00:00
|
|
|
import android.view.HapticFeedbackConstants;
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.view.KeyEvent;
|
2010-12-06 12:26:38 +00:00
|
|
|
import android.view.LayoutInflater;
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.view.View;
|
2010-11-21 03:43:10 +00:00
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.view.ViewParent;
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.view.Window;
|
|
|
|
import android.view.WindowManager;
|
|
|
|
import android.view.inputmethod.CompletionInfo;
|
|
|
|
import android.view.inputmethod.EditorInfo;
|
2010-01-16 20:21:23 +00:00
|
|
|
import android.view.inputmethod.ExtractedText;
|
|
|
|
import android.view.inputmethod.ExtractedTextRequest;
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.view.inputmethod.InputConnection;
|
2010-09-01 08:54:12 +00:00
|
|
|
import android.widget.LinearLayout;
|
2009-03-13 22:11:42 +00:00
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
import java.io.FileDescriptor;
|
|
|
|
import java.io.PrintWriter;
|
|
|
|
import java.util.ArrayList;
|
2010-09-28 03:23:26 +00:00
|
|
|
import java.util.Arrays;
|
2010-01-16 20:21:23 +00:00
|
|
|
import java.util.Locale;
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
/**
|
|
|
|
* Input method implementation for Qwerty'ish keyboard.
|
|
|
|
*/
|
2011-03-19 04:22:28 +00:00
|
|
|
public class LatinIME extends InputMethodServiceCompatWrapper implements KeyboardActionListener {
|
2011-02-23 08:23:29 +00:00
|
|
|
private static final String TAG = LatinIME.class.getSimpleName();
|
2010-08-20 05:35:02 +00:00
|
|
|
private static final boolean PERF_DEBUG = false;
|
2010-11-21 01:36:37 +00:00
|
|
|
private static final boolean TRACE = false;
|
2011-01-22 20:46:30 +00:00
|
|
|
private static boolean DEBUG = LatinImeLogger.sDBG;
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2011-02-23 08:23:29 +00:00
|
|
|
/**
|
|
|
|
* The private IME option used to indicate that no microphone should be
|
|
|
|
* shown for a given text field. For instance, this is specified by the
|
|
|
|
* search dialog when the dialog is already showing a voice search button.
|
|
|
|
*
|
|
|
|
* @deprecated Use {@link LatinIME#IME_OPTION_NO_MICROPHONE} with package name prefixed.
|
|
|
|
*/
|
2011-03-19 04:22:28 +00:00
|
|
|
@SuppressWarnings("dep-ann")
|
2011-02-23 08:23:29 +00:00
|
|
|
public static final String IME_OPTION_NO_MICROPHONE_COMPAT = "nm";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The private IME option used to indicate that no microphone should be
|
|
|
|
* shown for a given text field. For instance, this is specified by the
|
|
|
|
* search dialog when the dialog is already showing a voice search button.
|
|
|
|
*/
|
2011-02-23 11:31:08 +00:00
|
|
|
public static final String IME_OPTION_NO_MICROPHONE = "noMicrophoneKey";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The private IME option used to indicate that no settings key should be
|
|
|
|
* shown for a given text field.
|
|
|
|
*/
|
|
|
|
public static final String IME_OPTION_NO_SETTINGS_KEY = "noSettingsKey";
|
2011-02-23 08:23:29 +00:00
|
|
|
|
2010-10-27 09:05:27 +00:00
|
|
|
private static final int DELAY_UPDATE_SUGGESTIONS = 180;
|
|
|
|
private static final int DELAY_UPDATE_OLD_SUGGESTIONS = 300;
|
2011-04-26 11:10:54 +00:00
|
|
|
private static final int DELAY_UPDATE_SHIFT_STATE = 100;
|
2011-01-21 10:04:00 +00:00
|
|
|
private static final int EXTENDED_TOUCHABLE_REGION_HEIGHT = 100;
|
2010-10-27 09:05:27 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
// How many continuous deletes at which to start deleting at a higher speed.
|
|
|
|
private static final int DELETE_ACCELERATE_AT = 20;
|
|
|
|
// Key events coming any faster than this are long-presses.
|
2009-07-28 23:33:36 +00:00
|
|
|
private static final int QUICK_PRESS = 200;
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2011-03-14 18:46:15 +00:00
|
|
|
/**
|
|
|
|
* The name of the scheme used by the Package Manager to warn of a new package installation,
|
|
|
|
* replacement or removal.
|
|
|
|
*/
|
|
|
|
private static final String SCHEME_PACKAGE = "package";
|
|
|
|
|
2010-11-13 10:09:30 +00:00
|
|
|
private int mSuggestionVisibility;
|
|
|
|
private static final int SUGGESTION_VISIBILILTY_SHOW_VALUE
|
|
|
|
= R.string.prefs_suggestion_visibility_show_value;
|
|
|
|
private static final int SUGGESTION_VISIBILILTY_SHOW_ONLY_PORTRAIT_VALUE
|
|
|
|
= R.string.prefs_suggestion_visibility_show_only_portrait_value;
|
|
|
|
private static final int SUGGESTION_VISIBILILTY_HIDE_VALUE
|
|
|
|
= R.string.prefs_suggestion_visibility_hide_value;
|
|
|
|
|
|
|
|
private static final int[] SUGGESTION_VISIBILITY_VALUE_ARRAY = new int[] {
|
|
|
|
SUGGESTION_VISIBILILTY_SHOW_VALUE,
|
|
|
|
SUGGESTION_VISIBILILTY_SHOW_ONLY_PORTRAIT_VALUE,
|
|
|
|
SUGGESTION_VISIBILILTY_HIDE_VALUE
|
|
|
|
};
|
|
|
|
|
2010-12-06 12:26:38 +00:00
|
|
|
private View mCandidateViewContainer;
|
2011-04-13 05:12:24 +00:00
|
|
|
private int mCandidateStripHeight;
|
2009-03-13 22:11:42 +00:00
|
|
|
private CandidateView mCandidateView;
|
|
|
|
private Suggest mSuggest;
|
2010-12-11 08:06:24 +00:00
|
|
|
private CompletionInfo[] mApplicationSpecifiedCompletions;
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
private AlertDialog mOptionsDialog;
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2011-03-18 05:49:06 +00:00
|
|
|
private InputMethodManagerCompatWrapper mImm;
|
2011-01-20 13:52:02 +00:00
|
|
|
private Resources mResources;
|
|
|
|
private SharedPreferences mPrefs;
|
|
|
|
private String mInputMethodId;
|
2010-11-13 08:46:45 +00:00
|
|
|
private KeyboardSwitcher mKeyboardSwitcher;
|
2010-11-17 07:35:35 +00:00
|
|
|
private SubtypeSwitcher mSubtypeSwitcher;
|
2011-03-25 00:42:09 +00:00
|
|
|
private VoiceProxy mVoiceProxy;
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
private UserDictionary mUserDictionary;
|
2010-08-20 05:35:02 +00:00
|
|
|
private UserBigramDictionary mUserBigramDictionary;
|
2009-07-28 23:48:47 +00:00
|
|
|
private ContactsDictionary mContactsDictionary;
|
2010-03-23 22:59:59 +00:00
|
|
|
private AutoDictionary mAutoDictionary;
|
2009-10-12 20:48:35 +00:00
|
|
|
|
2011-01-18 06:28:21 +00:00
|
|
|
// These variables are initialized according to the {@link EditorInfo#inputType}.
|
|
|
|
private boolean mAutoSpace;
|
|
|
|
private boolean mInputTypeNoAutoCorrect;
|
|
|
|
private boolean mIsSettingsSuggestionStripOn;
|
|
|
|
private boolean mApplicationSpecifiedCompletionOn;
|
|
|
|
|
2011-01-14 18:49:21 +00:00
|
|
|
private AccessibilityUtils mAccessibilityUtils;
|
|
|
|
|
2010-11-13 08:46:45 +00:00
|
|
|
private final StringBuilder mComposing = new StringBuilder();
|
2009-03-13 22:11:42 +00:00
|
|
|
private WordComposer mWord = new WordComposer();
|
|
|
|
private CharSequence mBestWord;
|
2010-12-19 08:32:26 +00:00
|
|
|
private boolean mHasValidSuggestions;
|
2009-12-18 21:39:18 +00:00
|
|
|
private boolean mHasDictionary;
|
2010-02-07 00:34:43 +00:00
|
|
|
private boolean mJustAddedAutoSpace;
|
2009-12-18 21:39:18 +00:00
|
|
|
private boolean mAutoCorrectEnabled;
|
2011-03-01 06:59:06 +00:00
|
|
|
private boolean mRecorrectionEnabled;
|
2011-04-22 04:08:35 +00:00
|
|
|
// Suggestion: use bigrams to adjust scores of suggestions obtained from unigram dictionary
|
2010-08-20 05:35:02 +00:00
|
|
|
private boolean mBigramSuggestionEnabled;
|
2011-04-22 04:08:35 +00:00
|
|
|
// Prediction: use bigrams to predict the next word when there is no input for it yet
|
|
|
|
private boolean mBigramPredictionEnabled;
|
2009-03-13 22:11:42 +00:00
|
|
|
private boolean mAutoCorrectOn;
|
|
|
|
private boolean mVibrateOn;
|
|
|
|
private boolean mSoundOn;
|
2010-08-20 05:35:02 +00:00
|
|
|
private boolean mPopupOn;
|
2009-03-13 22:11:42 +00:00
|
|
|
private boolean mAutoCap;
|
2009-03-26 00:39:38 +00:00
|
|
|
private boolean mQuickFixes;
|
2011-01-20 13:52:02 +00:00
|
|
|
private boolean mConfigEnableShowSubtypeSettings;
|
2010-12-23 03:24:27 +00:00
|
|
|
private boolean mConfigSwipeDownDismissKeyboardEnabled;
|
2011-01-12 11:33:54 +00:00
|
|
|
private int mConfigDelayBeforeFadeoutLanguageOnSpacebar;
|
|
|
|
private int mConfigDurationOfFadeoutLanguageOnSpacebar;
|
2011-01-17 14:47:52 +00:00
|
|
|
private float mConfigFinalFadeoutFactorOfLanguageOnSpacebar;
|
2011-03-02 07:40:10 +00:00
|
|
|
private long mConfigDoubleSpacesTurnIntoPeriodTimeout;
|
2010-11-21 01:36:37 +00:00
|
|
|
|
2010-11-25 00:20:28 +00:00
|
|
|
private int mCorrectionMode;
|
|
|
|
private int mCommittedLength;
|
|
|
|
private int mOrientation;
|
2010-08-20 05:35:02 +00:00
|
|
|
// Keep track of the last selection range to decide if we need to show word alternatives
|
2010-11-25 00:20:28 +00:00
|
|
|
private int mLastSelectionStart;
|
|
|
|
private int mLastSelectionEnd;
|
2010-12-10 11:50:30 +00:00
|
|
|
private SuggestedWords mSuggestPuncList;
|
2010-08-20 05:35:02 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
// Indicates whether the suggestion strip is to be on in landscape
|
|
|
|
private boolean mJustAccepted;
|
|
|
|
private int mDeleteCount;
|
|
|
|
private long mLastKeyTime;
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
private AudioManager mAudioManager;
|
2009-09-29 19:00:38 +00:00
|
|
|
// Align sound effect volume on music volume
|
2010-11-13 08:46:45 +00:00
|
|
|
private static final float FX_VOLUME = -1.0f;
|
2009-03-13 22:11:42 +00:00
|
|
|
private boolean mSilentMode;
|
|
|
|
|
2010-08-20 05:35:02 +00:00
|
|
|
/* package */ String mWordSeparators;
|
2009-03-13 22:11:42 +00:00
|
|
|
private String mSentenceSeparators;
|
2010-08-20 05:35:02 +00:00
|
|
|
private String mSuggestPuncs;
|
2011-03-25 00:42:09 +00:00
|
|
|
// TODO: Move this flag to VoiceProxy
|
2010-03-07 15:27:05 +00:00
|
|
|
private boolean mConfigurationChanging;
|
2010-01-16 20:21:23 +00:00
|
|
|
|
2011-03-14 18:46:15 +00:00
|
|
|
// Object for reacting to adding/removing a dictionary pack.
|
|
|
|
private BroadcastReceiver mDictionaryPackInstallReceiver =
|
|
|
|
new DictionaryPackInstallBroadcastReceiver(this);
|
|
|
|
|
2010-04-01 13:28:52 +00:00
|
|
|
// Keeps track of most recently inserted text (multi-character key) for reverting
|
|
|
|
private CharSequence mEnteredText;
|
|
|
|
|
2010-11-13 08:46:45 +00:00
|
|
|
private final ArrayList<WordAlternatives> mWordHistory = new ArrayList<WordAlternatives>();
|
2010-08-20 05:35:02 +00:00
|
|
|
|
2011-03-15 00:23:26 +00:00
|
|
|
public class WordAlternatives {
|
|
|
|
private final CharSequence mChosenWord;
|
|
|
|
private final WordComposer mWordComposer;
|
2010-03-04 14:34:21 +00:00
|
|
|
|
2011-03-15 00:23:26 +00:00
|
|
|
public WordAlternatives(CharSequence chosenWord, WordComposer wordComposer) {
|
2010-08-20 05:35:02 +00:00
|
|
|
mChosenWord = chosenWord;
|
2011-03-15 00:23:26 +00:00
|
|
|
mWordComposer = wordComposer;
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public CharSequence getChosenWord() {
|
|
|
|
return mChosenWord;
|
|
|
|
}
|
|
|
|
|
2011-03-15 00:23:26 +00:00
|
|
|
public CharSequence getOriginalWord() {
|
|
|
|
return mWordComposer.getTypedWord();
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|
|
|
|
|
2011-03-15 00:23:26 +00:00
|
|
|
public SuggestedWords.Builder getAlternatives() {
|
|
|
|
return getTypedSuggestions(mWordComposer);
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2011-03-15 00:23:26 +00:00
|
|
|
public int hashCode() {
|
|
|
|
return mChosenWord.hashCode();
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2011-03-15 00:23:26 +00:00
|
|
|
public boolean equals(Object o) {
|
|
|
|
return o instanceof CharSequence && TextUtils.equals(mChosenWord, (CharSequence)o);
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|
|
|
|
}
|
2009-10-12 20:48:35 +00:00
|
|
|
|
2010-12-02 11:54:32 +00:00
|
|
|
public final UIHandler mHandler = new UIHandler();
|
2010-11-16 09:07:06 +00:00
|
|
|
|
2010-11-21 01:36:37 +00:00
|
|
|
public class UIHandler extends Handler {
|
2010-11-16 09:07:06 +00:00
|
|
|
private static final int MSG_UPDATE_SUGGESTIONS = 0;
|
|
|
|
private static final int MSG_UPDATE_OLD_SUGGESTIONS = 1;
|
|
|
|
private static final int MSG_UPDATE_SHIFT_STATE = 2;
|
|
|
|
private static final int MSG_VOICE_RESULTS = 3;
|
2011-01-12 11:33:54 +00:00
|
|
|
private static final int MSG_FADEOUT_LANGUAGE_ON_SPACEBAR = 4;
|
|
|
|
private static final int MSG_DISMISS_LANGUAGE_ON_SPACEBAR = 5;
|
2011-03-02 07:40:10 +00:00
|
|
|
private static final int MSG_SPACE_TYPED = 6;
|
2011-04-22 07:16:30 +00:00
|
|
|
private static final int MSG_SET_BIGRAM_PREDICTIONS = 7;
|
2010-11-16 09:07:06 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
@Override
|
|
|
|
public void handleMessage(Message msg) {
|
2011-01-12 11:33:54 +00:00
|
|
|
final KeyboardSwitcher switcher = mKeyboardSwitcher;
|
|
|
|
final LatinKeyboardView inputView = switcher.getInputView();
|
2009-03-13 22:11:42 +00:00
|
|
|
switch (msg.what) {
|
2010-11-16 09:07:06 +00:00
|
|
|
case MSG_UPDATE_SUGGESTIONS:
|
|
|
|
updateSuggestions();
|
|
|
|
break;
|
|
|
|
case MSG_UPDATE_OLD_SUGGESTIONS:
|
|
|
|
setOldSuggestions();
|
|
|
|
break;
|
|
|
|
case MSG_UPDATE_SHIFT_STATE:
|
2011-01-12 11:33:54 +00:00
|
|
|
switcher.updateShiftState();
|
2010-11-16 09:07:06 +00:00
|
|
|
break;
|
2011-04-22 07:16:30 +00:00
|
|
|
case MSG_SET_BIGRAM_PREDICTIONS:
|
|
|
|
updateBigramPredictions();
|
2011-04-20 02:50:05 +00:00
|
|
|
break;
|
2010-11-16 09:07:06 +00:00
|
|
|
case MSG_VOICE_RESULTS:
|
2011-03-25 00:42:09 +00:00
|
|
|
mVoiceProxy.handleVoiceResults(preferCapitalization()
|
2011-01-12 11:33:54 +00:00
|
|
|
|| (switcher.isAlphabetMode() && switcher.isShiftedOrShiftLocked()));
|
|
|
|
break;
|
|
|
|
case MSG_FADEOUT_LANGUAGE_ON_SPACEBAR:
|
|
|
|
if (inputView != null)
|
2011-01-17 04:43:51 +00:00
|
|
|
inputView.setSpacebarTextFadeFactor(
|
2011-01-17 14:47:52 +00:00
|
|
|
(1.0f + mConfigFinalFadeoutFactorOfLanguageOnSpacebar) / 2,
|
2011-01-17 04:43:51 +00:00
|
|
|
(LatinKeyboard)msg.obj);
|
2011-01-12 11:33:54 +00:00
|
|
|
sendMessageDelayed(obtainMessage(MSG_DISMISS_LANGUAGE_ON_SPACEBAR, msg.obj),
|
|
|
|
mConfigDurationOfFadeoutLanguageOnSpacebar);
|
|
|
|
break;
|
|
|
|
case MSG_DISMISS_LANGUAGE_ON_SPACEBAR:
|
|
|
|
if (inputView != null)
|
2011-01-17 04:43:51 +00:00
|
|
|
inputView.setSpacebarTextFadeFactor(
|
2011-01-17 14:47:52 +00:00
|
|
|
mConfigFinalFadeoutFactorOfLanguageOnSpacebar, (LatinKeyboard)msg.obj);
|
2010-11-16 09:07:06 +00:00
|
|
|
break;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
}
|
2010-11-16 09:07:06 +00:00
|
|
|
|
|
|
|
public void postUpdateSuggestions() {
|
|
|
|
removeMessages(MSG_UPDATE_SUGGESTIONS);
|
|
|
|
sendMessageDelayed(obtainMessage(MSG_UPDATE_SUGGESTIONS), DELAY_UPDATE_SUGGESTIONS);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void cancelUpdateSuggestions() {
|
|
|
|
removeMessages(MSG_UPDATE_SUGGESTIONS);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasPendingUpdateSuggestions() {
|
|
|
|
return hasMessages(MSG_UPDATE_SUGGESTIONS);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void postUpdateOldSuggestions() {
|
|
|
|
removeMessages(MSG_UPDATE_OLD_SUGGESTIONS);
|
|
|
|
sendMessageDelayed(obtainMessage(MSG_UPDATE_OLD_SUGGESTIONS),
|
|
|
|
DELAY_UPDATE_OLD_SUGGESTIONS);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void cancelUpdateOldSuggestions() {
|
|
|
|
removeMessages(MSG_UPDATE_OLD_SUGGESTIONS);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void postUpdateShiftKeyState() {
|
|
|
|
removeMessages(MSG_UPDATE_SHIFT_STATE);
|
|
|
|
sendMessageDelayed(obtainMessage(MSG_UPDATE_SHIFT_STATE), DELAY_UPDATE_SHIFT_STATE);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void cancelUpdateShiftState() {
|
|
|
|
removeMessages(MSG_UPDATE_SHIFT_STATE);
|
|
|
|
}
|
|
|
|
|
2011-04-22 07:16:30 +00:00
|
|
|
public void postUpdateBigramPredictions() {
|
|
|
|
removeMessages(MSG_SET_BIGRAM_PREDICTIONS);
|
|
|
|
sendMessageDelayed(obtainMessage(MSG_SET_BIGRAM_PREDICTIONS), DELAY_UPDATE_SUGGESTIONS);
|
2011-04-20 02:50:05 +00:00
|
|
|
}
|
|
|
|
|
2011-04-22 07:16:30 +00:00
|
|
|
public void cancelUpdateBigramPredictions() {
|
|
|
|
removeMessages(MSG_SET_BIGRAM_PREDICTIONS);
|
2011-04-20 02:50:05 +00:00
|
|
|
}
|
|
|
|
|
2010-11-16 09:07:06 +00:00
|
|
|
public void updateVoiceResults() {
|
|
|
|
sendMessage(obtainMessage(MSG_VOICE_RESULTS));
|
|
|
|
}
|
2011-01-12 11:33:54 +00:00
|
|
|
|
2011-01-17 14:47:52 +00:00
|
|
|
public void startDisplayLanguageOnSpacebar(boolean localeChanged) {
|
2011-01-12 11:33:54 +00:00
|
|
|
removeMessages(MSG_FADEOUT_LANGUAGE_ON_SPACEBAR);
|
|
|
|
removeMessages(MSG_DISMISS_LANGUAGE_ON_SPACEBAR);
|
|
|
|
final LatinKeyboardView inputView = mKeyboardSwitcher.getInputView();
|
|
|
|
if (inputView != null) {
|
2011-02-20 12:12:51 +00:00
|
|
|
final LatinKeyboard keyboard = mKeyboardSwitcher.getLatinKeyboard();
|
2011-04-22 02:09:48 +00:00
|
|
|
// The language is always displayed when the delay is negative.
|
|
|
|
final boolean needsToDisplayLanguage = localeChanged
|
|
|
|
|| mConfigDelayBeforeFadeoutLanguageOnSpacebar < 0;
|
2011-01-12 11:33:54 +00:00
|
|
|
// The language is never displayed when the delay is zero.
|
|
|
|
if (mConfigDelayBeforeFadeoutLanguageOnSpacebar != 0)
|
2011-04-22 02:09:48 +00:00
|
|
|
inputView.setSpacebarTextFadeFactor(needsToDisplayLanguage ? 1.0f
|
2011-01-17 14:47:52 +00:00
|
|
|
: mConfigFinalFadeoutFactorOfLanguageOnSpacebar, keyboard);
|
2011-04-22 02:09:48 +00:00
|
|
|
// The fadeout animation will start when the delay is positive.
|
2011-01-17 14:47:52 +00:00
|
|
|
if (localeChanged && mConfigDelayBeforeFadeoutLanguageOnSpacebar > 0) {
|
2011-01-12 11:33:54 +00:00
|
|
|
sendMessageDelayed(obtainMessage(MSG_FADEOUT_LANGUAGE_ON_SPACEBAR, keyboard),
|
|
|
|
mConfigDelayBeforeFadeoutLanguageOnSpacebar);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-03-02 07:40:10 +00:00
|
|
|
|
|
|
|
public void startDoubleSpacesTimer() {
|
|
|
|
removeMessages(MSG_SPACE_TYPED);
|
|
|
|
sendMessageDelayed(obtainMessage(MSG_SPACE_TYPED),
|
|
|
|
mConfigDoubleSpacesTurnIntoPeriodTimeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void cancelDoubleSpacesTimer() {
|
|
|
|
removeMessages(MSG_SPACE_TYPED);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isAcceptingDoubleSpaces() {
|
|
|
|
return hasMessages(MSG_SPACE_TYPED);
|
|
|
|
}
|
2010-11-16 09:07:06 +00:00
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
|
2010-10-08 13:17:16 +00:00
|
|
|
@Override
|
|
|
|
public void onCreate() {
|
2010-11-26 04:08:36 +00:00
|
|
|
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
|
|
|
mPrefs = prefs;
|
|
|
|
LatinImeLogger.init(this, prefs);
|
2011-04-14 02:42:08 +00:00
|
|
|
LanguageSwitcherProxy.init(this, prefs);
|
2010-11-26 04:08:36 +00:00
|
|
|
SubtypeSwitcher.init(this, prefs);
|
|
|
|
KeyboardSwitcher.init(this, prefs);
|
2011-01-14 18:49:21 +00:00
|
|
|
AccessibilityUtils.init(this, prefs);
|
2010-12-23 03:24:27 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
super.onCreate();
|
2010-12-23 03:24:27 +00:00
|
|
|
|
2011-03-18 05:49:06 +00:00
|
|
|
mImm = InputMethodManagerCompatWrapper.getInstance(this);
|
2011-02-23 08:23:29 +00:00
|
|
|
mInputMethodId = Utils.getInputMethodId(mImm, getPackageName());
|
2010-11-17 07:35:35 +00:00
|
|
|
mSubtypeSwitcher = SubtypeSwitcher.getInstance();
|
|
|
|
mKeyboardSwitcher = KeyboardSwitcher.getInstance();
|
2011-01-14 18:49:21 +00:00
|
|
|
mAccessibilityUtils = AccessibilityUtils.getInstance();
|
2010-12-23 03:24:27 +00:00
|
|
|
|
|
|
|
final Resources res = getResources();
|
|
|
|
mResources = res;
|
2011-01-18 08:45:22 +00:00
|
|
|
|
|
|
|
// If the option should not be shown, do not read the recorrection preference
|
|
|
|
// but always use the default setting defined in the resources.
|
|
|
|
if (res.getBoolean(R.bool.config_enable_show_recorrection_option)) {
|
2011-03-01 06:59:06 +00:00
|
|
|
mRecorrectionEnabled = prefs.getBoolean(Settings.PREF_RECORRECTION_ENABLED,
|
2011-02-08 02:13:06 +00:00
|
|
|
res.getBoolean(R.bool.config_default_recorrection_enabled));
|
2011-01-18 08:45:22 +00:00
|
|
|
} else {
|
2011-03-01 06:59:06 +00:00
|
|
|
mRecorrectionEnabled = res.getBoolean(R.bool.config_default_recorrection_enabled);
|
2011-01-18 08:45:22 +00:00
|
|
|
}
|
|
|
|
|
2011-01-20 13:52:02 +00:00
|
|
|
mConfigEnableShowSubtypeSettings = res.getBoolean(
|
|
|
|
R.bool.config_enable_show_subtype_settings);
|
2010-12-23 03:24:27 +00:00
|
|
|
mConfigSwipeDownDismissKeyboardEnabled = res.getBoolean(
|
|
|
|
R.bool.config_swipe_down_dismiss_keyboard_enabled);
|
2011-01-12 11:33:54 +00:00
|
|
|
mConfigDelayBeforeFadeoutLanguageOnSpacebar = res.getInteger(
|
|
|
|
R.integer.config_delay_before_fadeout_language_on_spacebar);
|
|
|
|
mConfigDurationOfFadeoutLanguageOnSpacebar = res.getInteger(
|
|
|
|
R.integer.config_duration_of_fadeout_language_on_spacebar);
|
2011-01-17 14:47:52 +00:00
|
|
|
mConfigFinalFadeoutFactorOfLanguageOnSpacebar = res.getInteger(
|
2011-01-17 04:43:51 +00:00
|
|
|
R.integer.config_final_fadeout_percentage_of_language_on_spacebar) / 100.0f;
|
2011-03-02 07:40:10 +00:00
|
|
|
mConfigDoubleSpacesTurnIntoPeriodTimeout = res.getInteger(
|
|
|
|
R.integer.config_double_spaces_turn_into_period_timeout);
|
2010-08-20 05:35:02 +00:00
|
|
|
|
2010-12-09 12:06:26 +00:00
|
|
|
Utils.GCUtils.getInstance().reset();
|
2010-08-20 05:35:02 +00:00
|
|
|
boolean tryGC = true;
|
2010-12-09 12:06:26 +00:00
|
|
|
for (int i = 0; i < Utils.GCUtils.GC_TRY_LOOP_MAX && tryGC; ++i) {
|
2010-08-20 05:35:02 +00:00
|
|
|
try {
|
2010-11-17 07:35:35 +00:00
|
|
|
initSuggest();
|
2010-08-20 05:35:02 +00:00
|
|
|
tryGC = false;
|
|
|
|
} catch (OutOfMemoryError e) {
|
2010-12-09 12:06:26 +00:00
|
|
|
tryGC = Utils.GCUtils.getInstance().tryGCOrWait("InitSuggest", e);
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-23 03:24:27 +00:00
|
|
|
mOrientation = res.getConfiguration().orientation;
|
2010-02-03 23:35:49 +00:00
|
|
|
initSuggestPuncList();
|
2009-07-21 22:47:11 +00:00
|
|
|
|
2011-03-14 18:46:15 +00:00
|
|
|
// Register to receive ringer mode change and network state change.
|
|
|
|
// Also receive installation and removal of a dictionary pack.
|
2011-01-26 14:13:18 +00:00
|
|
|
final IntentFilter filter = new IntentFilter();
|
|
|
|
filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);
|
|
|
|
filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
|
2009-03-13 22:11:42 +00:00
|
|
|
registerReceiver(mReceiver, filter);
|
2011-03-25 00:42:09 +00:00
|
|
|
mVoiceProxy = VoiceProxy.init(this, prefs, mHandler);
|
2011-03-14 18:46:15 +00:00
|
|
|
|
|
|
|
final IntentFilter packageFilter = new IntentFilter();
|
|
|
|
packageFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
|
|
|
|
packageFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
|
|
|
|
packageFilter.addDataScheme(SCHEME_PACKAGE);
|
|
|
|
registerReceiver(mDictionaryPackInstallReceiver, packageFilter);
|
2011-04-14 11:45:47 +00:00
|
|
|
|
|
|
|
final IntentFilter newDictFilter = new IntentFilter();
|
|
|
|
newDictFilter.addAction(
|
|
|
|
DictionaryPackInstallBroadcastReceiver.NEW_DICTIONARY_INTENT_ACTION);
|
|
|
|
registerReceiver(mDictionaryPackInstallReceiver, newDictFilter);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2009-10-12 20:48:35 +00:00
|
|
|
|
2010-11-17 07:35:35 +00:00
|
|
|
private void initSuggest() {
|
2011-03-14 18:46:15 +00:00
|
|
|
final String localeStr = mSubtypeSwitcher.getInputLocaleStr();
|
|
|
|
final Locale keyboardLocale = new Locale(localeStr);
|
2009-10-12 20:48:35 +00:00
|
|
|
|
2011-03-14 18:46:15 +00:00
|
|
|
final Locale savedLocale = mSubtypeSwitcher.changeSystemLocale(keyboardLocale);
|
2009-10-12 20:48:35 +00:00
|
|
|
if (mSuggest != null) {
|
|
|
|
mSuggest.close();
|
|
|
|
}
|
2010-11-26 04:08:36 +00:00
|
|
|
final SharedPreferences prefs = mPrefs;
|
2011-01-19 08:44:39 +00:00
|
|
|
mQuickFixes = isQuickFixesEnabled(prefs);
|
2010-08-20 05:35:02 +00:00
|
|
|
|
2011-01-04 15:39:41 +00:00
|
|
|
final Resources res = mResources;
|
2011-02-23 08:23:29 +00:00
|
|
|
int mainDicResId = Utils.getMainDictionaryResourceId(res);
|
2011-03-14 18:46:15 +00:00
|
|
|
mSuggest = new Suggest(this, mainDicResId, keyboardLocale);
|
2010-12-11 08:06:24 +00:00
|
|
|
loadAndSetAutoCorrectionThreshold(prefs);
|
2011-02-24 07:18:24 +00:00
|
|
|
updateAutoTextEnabled();
|
2011-01-07 06:01:51 +00:00
|
|
|
|
2011-03-14 18:46:15 +00:00
|
|
|
mUserDictionary = new UserDictionary(this, localeStr);
|
2009-03-13 22:11:42 +00:00
|
|
|
mSuggest.setUserDictionary(mUserDictionary);
|
2011-01-07 06:01:51 +00:00
|
|
|
|
|
|
|
mContactsDictionary = new ContactsDictionary(this, Suggest.DIC_CONTACTS);
|
2009-07-28 23:48:47 +00:00
|
|
|
mSuggest.setContactsDictionary(mContactsDictionary);
|
2011-01-07 06:01:51 +00:00
|
|
|
|
2011-03-14 18:46:15 +00:00
|
|
|
mAutoDictionary = new AutoDictionary(this, this, localeStr, Suggest.DIC_AUTO);
|
2009-07-17 19:51:45 +00:00
|
|
|
mSuggest.setAutoDictionary(mAutoDictionary);
|
2011-01-07 06:01:51 +00:00
|
|
|
|
2011-03-14 18:46:15 +00:00
|
|
|
mUserBigramDictionary = new UserBigramDictionary(this, this, localeStr, Suggest.DIC_USER);
|
2011-01-07 06:01:51 +00:00
|
|
|
mSuggest.setUserBigramDictionary(mUserBigramDictionary);
|
|
|
|
|
2009-12-18 21:39:18 +00:00
|
|
|
updateCorrectionMode();
|
2011-01-04 15:39:41 +00:00
|
|
|
mWordSeparators = res.getString(R.string.word_separators);
|
|
|
|
mSentenceSeparators = res.getString(R.string.sentence_separators);
|
2009-10-12 20:48:35 +00:00
|
|
|
|
2010-11-17 07:35:35 +00:00
|
|
|
mSubtypeSwitcher.changeSystemLocale(savedLocale);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2009-10-12 20:48:35 +00:00
|
|
|
|
2011-03-14 18:46:15 +00:00
|
|
|
/* package private */ void resetSuggestMainDict() {
|
|
|
|
final String localeStr = mSubtypeSwitcher.getInputLocaleStr();
|
|
|
|
final Locale keyboardLocale = new Locale(localeStr);
|
|
|
|
int mainDicResId = Utils.getMainDictionaryResourceId(mResources);
|
|
|
|
mSuggest.resetMainDict(this, mainDicResId, keyboardLocale);
|
|
|
|
}
|
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
@Override
|
|
|
|
public void onDestroy() {
|
2011-01-07 06:01:51 +00:00
|
|
|
if (mSuggest != null) {
|
|
|
|
mSuggest.close();
|
|
|
|
mSuggest = null;
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
unregisterReceiver(mReceiver);
|
2011-03-14 18:46:15 +00:00
|
|
|
unregisterReceiver(mDictionaryPackInstallReceiver);
|
2011-03-25 00:42:09 +00:00
|
|
|
mVoiceProxy.destroy();
|
2010-08-20 05:35:02 +00:00
|
|
|
LatinImeLogger.commit();
|
|
|
|
LatinImeLogger.onDestroy();
|
2009-03-13 22:11:42 +00:00
|
|
|
super.onDestroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onConfigurationChanged(Configuration conf) {
|
2011-01-17 08:52:15 +00:00
|
|
|
mSubtypeSwitcher.onConfigurationChanged(conf);
|
2009-07-21 22:47:11 +00:00
|
|
|
// If orientation changed while predicting, commit the change
|
|
|
|
if (conf.orientation != mOrientation) {
|
2010-01-16 20:21:23 +00:00
|
|
|
InputConnection ic = getCurrentInputConnection();
|
|
|
|
commitTyped(ic);
|
|
|
|
if (ic != null) ic.finishComposingText(); // For voice input
|
2009-07-21 22:47:11 +00:00
|
|
|
mOrientation = conf.orientation;
|
2011-01-20 13:52:02 +00:00
|
|
|
if (isShowingOptionDialog())
|
|
|
|
mOptionsDialog.dismiss();
|
2009-07-21 22:47:11 +00:00
|
|
|
}
|
2010-11-11 07:03:19 +00:00
|
|
|
|
2010-03-07 15:27:05 +00:00
|
|
|
mConfigurationChanging = true;
|
2009-03-13 22:11:42 +00:00
|
|
|
super.onConfigurationChanged(conf);
|
2011-03-25 00:42:09 +00:00
|
|
|
mVoiceProxy.onConfigurationChanged(conf);
|
2010-03-07 15:27:05 +00:00
|
|
|
mConfigurationChanging = false;
|
2011-04-08 10:57:13 +00:00
|
|
|
|
|
|
|
// This will work only when the subtype is not supported.
|
|
|
|
LanguageSwitcherProxy.onConfigurationChanged(conf);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2009-07-21 22:47:11 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
@Override
|
|
|
|
public View onCreateInputView() {
|
2010-11-25 01:02:50 +00:00
|
|
|
return mKeyboardSwitcher.onCreateInputView();
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public View onCreateCandidatesView() {
|
2010-12-06 12:26:38 +00:00
|
|
|
LayoutInflater inflater = getLayoutInflater();
|
|
|
|
LinearLayout container = (LinearLayout)inflater.inflate(R.layout.candidates, null);
|
|
|
|
mCandidateViewContainer = container;
|
2011-04-13 05:12:24 +00:00
|
|
|
mCandidateStripHeight = (int)mResources.getDimension(R.dimen.candidate_strip_height);
|
2010-12-06 12:26:38 +00:00
|
|
|
mCandidateView = (CandidateView) container.findViewById(R.id.candidates);
|
2009-03-13 22:11:42 +00:00
|
|
|
mCandidateView.setService(this);
|
|
|
|
setCandidatesViewShown(true);
|
2010-12-06 12:26:38 +00:00
|
|
|
return container;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2010-01-28 18:09:44 +00:00
|
|
|
@Override
|
2009-03-13 22:11:42 +00:00
|
|
|
public void onStartInputView(EditorInfo attribute, boolean restarting) {
|
2010-11-12 23:49:56 +00:00
|
|
|
final KeyboardSwitcher switcher = mKeyboardSwitcher;
|
|
|
|
LatinKeyboardView inputView = switcher.getInputView();
|
2010-11-21 03:43:10 +00:00
|
|
|
|
2011-04-20 02:50:05 +00:00
|
|
|
if (DEBUG) {
|
2011-01-22 20:46:30 +00:00
|
|
|
Log.d(TAG, "onStartInputView: " + inputView);
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
// In landscape mode, this method gets called without the input view being created.
|
2010-08-20 05:35:02 +00:00
|
|
|
if (inputView == null) {
|
2009-03-13 22:11:42 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-11-25 01:02:50 +00:00
|
|
|
mSubtypeSwitcher.updateParametersOnStartInputView();
|
2010-11-18 00:55:23 +00:00
|
|
|
|
2011-03-03 01:02:06 +00:00
|
|
|
TextEntryState.reset();
|
2009-06-04 22:31:01 +00:00
|
|
|
|
2011-01-18 06:28:21 +00:00
|
|
|
// Most such things we decide below in initializeInputAttributesAndGetMode, but we need to
|
|
|
|
// know now whether this is a password text field, because we need to know now whether we
|
|
|
|
// want to enable the voice button.
|
2011-03-25 00:42:09 +00:00
|
|
|
final VoiceProxy voiceIme = mVoiceProxy;
|
2011-03-25 06:28:29 +00:00
|
|
|
voiceIme.resetVoiceStates(InputTypeCompatUtils.isPasswordInputType(attribute.inputType)
|
|
|
|
|| InputTypeCompatUtils.isVisiblePasswordInputType(attribute.inputType));
|
2011-01-18 06:28:21 +00:00
|
|
|
|
2011-02-20 13:04:50 +00:00
|
|
|
initializeInputAttributes(attribute);
|
2011-01-18 06:28:21 +00:00
|
|
|
|
|
|
|
inputView.closing();
|
|
|
|
mEnteredText = null;
|
|
|
|
mComposing.setLength(0);
|
|
|
|
mHasValidSuggestions = false;
|
|
|
|
mDeleteCount = 0;
|
|
|
|
mJustAddedAutoSpace = false;
|
|
|
|
|
|
|
|
loadSettings(attribute);
|
|
|
|
if (mSubtypeSwitcher.isKeyboardMode()) {
|
2011-02-20 13:04:50 +00:00
|
|
|
switcher.loadKeyboard(attribute,
|
2011-03-03 05:34:11 +00:00
|
|
|
mSubtypeSwitcher.isShortcutImeEnabled() && voiceIme.isVoiceButtonEnabled(),
|
|
|
|
voiceIme.isVoiceButtonOnPrimary());
|
2011-01-18 06:28:21 +00:00
|
|
|
switcher.updateShiftState();
|
|
|
|
}
|
|
|
|
|
2011-04-13 05:12:24 +00:00
|
|
|
setCandidatesViewShownInternal(isCandidateStripVisible(), false /* needsInputViewShown */ );
|
2011-01-18 06:28:21 +00:00
|
|
|
// Delay updating suggestions because keyboard input view may not be shown at this point.
|
|
|
|
mHandler.postUpdateSuggestions();
|
|
|
|
|
|
|
|
updateCorrectionMode();
|
|
|
|
|
2011-01-14 18:49:21 +00:00
|
|
|
final boolean accessibilityEnabled = mAccessibilityUtils.isAccessibilityEnabled();
|
|
|
|
|
2011-04-19 06:18:20 +00:00
|
|
|
inputView.setKeyPreviewEnabled(mPopupOn);
|
2011-01-18 06:28:21 +00:00
|
|
|
inputView.setProximityCorrectionEnabled(true);
|
2011-01-14 18:49:21 +00:00
|
|
|
inputView.setAccessibilityEnabled(accessibilityEnabled);
|
2011-01-18 06:28:21 +00:00
|
|
|
// If we just entered a text field, maybe it has some old text that requires correction
|
2011-03-01 06:59:06 +00:00
|
|
|
checkRecorrectionOnStart();
|
2011-01-18 06:28:21 +00:00
|
|
|
inputView.setForeground(true);
|
|
|
|
|
2011-03-03 05:34:11 +00:00
|
|
|
voiceIme.onStartInputView(inputView.getWindowToken());
|
2011-01-18 06:28:21 +00:00
|
|
|
|
|
|
|
if (TRACE) Debug.startMethodTracing("/data/trace/latinime");
|
|
|
|
}
|
|
|
|
|
2011-02-20 13:04:50 +00:00
|
|
|
private void initializeInputAttributes(EditorInfo attribute) {
|
|
|
|
if (attribute == null)
|
|
|
|
return;
|
2011-02-20 03:54:14 +00:00
|
|
|
final int inputType = attribute.inputType;
|
2011-01-18 06:28:21 +00:00
|
|
|
final int variation = inputType & InputType.TYPE_MASK_VARIATION;
|
|
|
|
mAutoSpace = false;
|
2009-12-18 21:39:18 +00:00
|
|
|
mInputTypeNoAutoCorrect = false;
|
2010-12-19 08:32:26 +00:00
|
|
|
mIsSettingsSuggestionStripOn = false;
|
2010-12-11 08:06:24 +00:00
|
|
|
mApplicationSpecifiedCompletionOn = false;
|
|
|
|
mApplicationSpecifiedCompletions = null;
|
2010-04-01 13:28:52 +00:00
|
|
|
|
2011-02-20 13:04:50 +00:00
|
|
|
if ((inputType & InputType.TYPE_MASK_CLASS) == InputType.TYPE_CLASS_TEXT) {
|
|
|
|
mIsSettingsSuggestionStripOn = true;
|
|
|
|
// Make sure that passwords are not displayed in candidate view
|
2011-03-25 06:28:29 +00:00
|
|
|
if (InputTypeCompatUtils.isPasswordInputType(inputType)
|
|
|
|
|| InputTypeCompatUtils.isVisiblePasswordInputType(inputType)) {
|
2011-02-20 13:04:50 +00:00
|
|
|
mIsSettingsSuggestionStripOn = false;
|
|
|
|
}
|
2011-03-25 06:28:29 +00:00
|
|
|
if (InputTypeCompatUtils.isEmailVariation(variation)
|
2011-02-20 13:04:50 +00:00
|
|
|
|| variation == InputType.TYPE_TEXT_VARIATION_PERSON_NAME) {
|
|
|
|
mAutoSpace = false;
|
|
|
|
} else {
|
|
|
|
mAutoSpace = true;
|
|
|
|
}
|
2011-03-25 06:28:29 +00:00
|
|
|
if (InputTypeCompatUtils.isEmailVariation(variation)) {
|
2011-02-20 13:04:50 +00:00
|
|
|
mIsSettingsSuggestionStripOn = false;
|
|
|
|
} else if (variation == InputType.TYPE_TEXT_VARIATION_URI) {
|
|
|
|
mIsSettingsSuggestionStripOn = false;
|
|
|
|
} else if (variation == InputType.TYPE_TEXT_VARIATION_FILTER) {
|
|
|
|
mIsSettingsSuggestionStripOn = false;
|
|
|
|
} else if (variation == InputType.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT) {
|
|
|
|
// If it's a browser edit field and auto correct is not ON explicitly, then
|
|
|
|
// disable auto correction, but keep suggestions on.
|
|
|
|
if ((inputType & InputType.TYPE_TEXT_FLAG_AUTO_CORRECT) == 0) {
|
2009-12-18 21:39:18 +00:00
|
|
|
mInputTypeNoAutoCorrect = true;
|
2009-09-17 18:08:16 +00:00
|
|
|
}
|
2011-02-20 13:04:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If NO_SUGGESTIONS is set, don't do prediction.
|
|
|
|
if ((inputType & InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS) != 0) {
|
|
|
|
mIsSettingsSuggestionStripOn = false;
|
|
|
|
mInputTypeNoAutoCorrect = true;
|
|
|
|
}
|
|
|
|
// If it's not multiline and the autoCorrect flag is not set, then don't correct
|
|
|
|
if ((inputType & InputType.TYPE_TEXT_FLAG_AUTO_CORRECT) == 0
|
|
|
|
&& (inputType & InputType.TYPE_TEXT_FLAG_MULTI_LINE) == 0) {
|
|
|
|
mInputTypeNoAutoCorrect = true;
|
|
|
|
}
|
|
|
|
if ((inputType & InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE) != 0) {
|
|
|
|
mIsSettingsSuggestionStripOn = false;
|
|
|
|
mApplicationSpecifiedCompletionOn = isFullscreenMode();
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-01 06:59:06 +00:00
|
|
|
private void checkRecorrectionOnStart() {
|
|
|
|
if (!mRecorrectionEnabled) return;
|
2010-12-03 10:40:31 +00:00
|
|
|
|
|
|
|
final InputConnection ic = getCurrentInputConnection();
|
|
|
|
if (ic == null) return;
|
|
|
|
// There could be a pending composing span. Clean it up first.
|
|
|
|
ic.finishComposingText();
|
|
|
|
|
2010-12-19 08:32:26 +00:00
|
|
|
if (isShowingSuggestionsStrip() && isSuggestionsRequested()) {
|
2010-09-28 23:35:29 +00:00
|
|
|
// First get the cursor position. This is required by setOldSuggestions(), so that
|
|
|
|
// it can pass the correct range to setComposingRegion(). At this point, we don't
|
2010-12-12 08:58:29 +00:00
|
|
|
// have valid values for mLastSelectionStart/End because onUpdateSelection() has
|
2010-09-28 23:35:29 +00:00
|
|
|
// not been called yet.
|
|
|
|
ExtractedTextRequest etr = new ExtractedTextRequest();
|
|
|
|
etr.token = 0; // anything is fine here
|
|
|
|
ExtractedText et = ic.getExtractedText(etr, 0);
|
|
|
|
if (et == null) return;
|
|
|
|
|
|
|
|
mLastSelectionStart = et.startOffset + et.selectionStart;
|
|
|
|
mLastSelectionEnd = et.startOffset + et.selectionEnd;
|
|
|
|
|
|
|
|
// Then look for possible corrections in a delayed fashion
|
2010-10-05 13:51:59 +00:00
|
|
|
if (!TextUtils.isEmpty(et.text) && isCursorTouchingWord()) {
|
2010-11-16 09:07:06 +00:00
|
|
|
mHandler.postUpdateOldSuggestions();
|
2010-10-05 13:51:59 +00:00
|
|
|
}
|
2010-09-28 23:35:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
@Override
|
|
|
|
public void onFinishInput() {
|
|
|
|
super.onFinishInput();
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-08-20 05:35:02 +00:00
|
|
|
LatinImeLogger.commit();
|
2010-12-11 08:06:24 +00:00
|
|
|
mKeyboardSwitcher.onAutoCorrectionStateChanged(false);
|
2010-08-20 05:35:02 +00:00
|
|
|
|
2011-03-25 00:42:09 +00:00
|
|
|
mVoiceProxy.flushVoiceInputLogs(mConfigurationChanging);
|
2010-11-21 01:36:37 +00:00
|
|
|
|
2010-12-02 09:46:21 +00:00
|
|
|
KeyboardView inputView = mKeyboardSwitcher.getInputView();
|
2010-12-03 10:40:31 +00:00
|
|
|
if (inputView != null) inputView.closing();
|
2010-03-23 22:59:59 +00:00
|
|
|
if (mAutoDictionary != null) mAutoDictionary.flushPendingWrites();
|
2010-08-20 05:35:02 +00:00
|
|
|
if (mUserBigramDictionary != null) mUserBigramDictionary.flushPendingWrites();
|
2010-01-16 20:21:23 +00:00
|
|
|
}
|
|
|
|
|
2010-10-06 09:39:47 +00:00
|
|
|
@Override
|
|
|
|
public void onFinishInputView(boolean finishingInput) {
|
|
|
|
super.onFinishInputView(finishingInput);
|
2010-12-02 09:46:21 +00:00
|
|
|
KeyboardView inputView = mKeyboardSwitcher.getInputView();
|
2010-12-03 10:40:31 +00:00
|
|
|
if (inputView != null) inputView.setForeground(false);
|
2010-11-16 09:07:06 +00:00
|
|
|
// Remove pending messages related to update suggestions
|
|
|
|
mHandler.cancelUpdateSuggestions();
|
|
|
|
mHandler.cancelUpdateOldSuggestions();
|
2010-10-06 09:39:47 +00:00
|
|
|
}
|
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
@Override
|
|
|
|
public void onUpdateExtractedText(int token, ExtractedText text) {
|
|
|
|
super.onUpdateExtractedText(token, text);
|
2011-03-25 00:42:09 +00:00
|
|
|
mVoiceProxy.showPunctuationHintIfNecessary();
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onUpdateSelection(int oldSelStart, int oldSelEnd,
|
|
|
|
int newSelStart, int newSelEnd,
|
|
|
|
int candidatesStart, int candidatesEnd) {
|
|
|
|
super.onUpdateSelection(oldSelStart, oldSelEnd, newSelStart, newSelEnd,
|
|
|
|
candidatesStart, candidatesEnd);
|
2010-01-16 20:21:23 +00:00
|
|
|
|
|
|
|
if (DEBUG) {
|
|
|
|
Log.i(TAG, "onUpdateSelection: oss=" + oldSelStart
|
|
|
|
+ ", ose=" + oldSelEnd
|
2011-02-25 09:11:18 +00:00
|
|
|
+ ", lss=" + mLastSelectionStart
|
|
|
|
+ ", lse=" + mLastSelectionEnd
|
2010-01-16 20:21:23 +00:00
|
|
|
+ ", nss=" + newSelStart
|
|
|
|
+ ", nse=" + newSelEnd
|
|
|
|
+ ", cs=" + candidatesStart
|
|
|
|
+ ", ce=" + candidatesEnd);
|
|
|
|
}
|
|
|
|
|
2011-03-25 00:42:09 +00:00
|
|
|
mVoiceProxy.setCursorAndSelection(newSelEnd, newSelStart);
|
2010-03-04 14:34:21 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
// If the current selection in the text view changes, we should
|
|
|
|
// clear whatever candidate text we have.
|
2011-02-25 09:11:18 +00:00
|
|
|
final boolean selectionChanged = (newSelStart != candidatesEnd
|
|
|
|
|| newSelEnd != candidatesEnd) && mLastSelectionStart != newSelStart;
|
|
|
|
final boolean candidatesCleared = candidatesStart == -1 && candidatesEnd == -1;
|
|
|
|
if (((mComposing.length() > 0 && mHasValidSuggestions)
|
2011-03-25 00:42:09 +00:00
|
|
|
|| mVoiceProxy.isVoiceInputHighlighted())
|
2011-02-25 09:11:18 +00:00
|
|
|
&& (selectionChanged || candidatesCleared)) {
|
|
|
|
if (candidatesCleared) {
|
|
|
|
// If the composing span has been cleared, save the typed word in the history for
|
|
|
|
// recorrection before we reset the candidate strip. Then, we'll be able to show
|
|
|
|
// suggestions for recorrection right away.
|
|
|
|
saveWordInHistory(mComposing);
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
mComposing.setLength(0);
|
2010-12-19 08:32:26 +00:00
|
|
|
mHasValidSuggestions = false;
|
2011-04-20 02:50:05 +00:00
|
|
|
if (isCursorTouchingWord()) {
|
2011-04-22 07:16:30 +00:00
|
|
|
mHandler.cancelUpdateBigramPredictions();
|
2011-04-20 02:50:05 +00:00
|
|
|
mHandler.postUpdateSuggestions();
|
|
|
|
} else {
|
|
|
|
setPunctuationSuggestions();
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
TextEntryState.reset();
|
|
|
|
InputConnection ic = getCurrentInputConnection();
|
|
|
|
if (ic != null) {
|
|
|
|
ic.finishComposingText();
|
|
|
|
}
|
2011-03-25 00:42:09 +00:00
|
|
|
mVoiceProxy.setVoiceInputHighlighted(false);
|
2010-12-19 08:32:26 +00:00
|
|
|
} else if (!mHasValidSuggestions && !mJustAccepted) {
|
2011-03-03 01:02:06 +00:00
|
|
|
if (TextEntryState.isAcceptedDefault() || TextEntryState.isSpaceAfterPicked()) {
|
|
|
|
if (TextEntryState.isAcceptedDefault())
|
|
|
|
TextEntryState.reset();
|
2010-12-10 06:24:28 +00:00
|
|
|
mJustAddedAutoSpace = false; // The user moved the cursor.
|
2010-02-07 00:34:43 +00:00
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
mJustAccepted = false;
|
2010-11-16 09:07:06 +00:00
|
|
|
mHandler.postUpdateShiftKeyState();
|
2010-01-16 20:21:23 +00:00
|
|
|
|
2010-08-20 05:35:02 +00:00
|
|
|
// Make a note of the cursor position
|
|
|
|
mLastSelectionStart = newSelStart;
|
|
|
|
mLastSelectionEnd = newSelEnd;
|
2010-01-16 20:21:23 +00:00
|
|
|
|
2011-03-01 06:59:06 +00:00
|
|
|
if (mRecorrectionEnabled && isShowingSuggestionsStrip()) {
|
2010-09-06 10:18:38 +00:00
|
|
|
// Don't look for corrections if the keyboard is not visible
|
2010-11-13 08:01:13 +00:00
|
|
|
if (mKeyboardSwitcher.isInputViewShown()) {
|
2010-09-06 10:18:38 +00:00
|
|
|
// Check if we should go in or out of correction mode.
|
2011-03-02 18:48:45 +00:00
|
|
|
if (isSuggestionsRequested()
|
2010-09-06 10:18:38 +00:00
|
|
|
&& (candidatesStart == candidatesEnd || newSelStart != oldSelStart
|
2011-03-01 06:59:06 +00:00
|
|
|
|| TextEntryState.isRecorrecting())
|
2010-12-19 08:32:26 +00:00
|
|
|
&& (newSelStart < newSelEnd - 1 || !mHasValidSuggestions)) {
|
2010-09-06 10:18:38 +00:00
|
|
|
if (isCursorTouchingWord() || mLastSelectionStart < mLastSelectionEnd) {
|
2011-04-22 07:16:30 +00:00
|
|
|
mHandler.cancelUpdateBigramPredictions();
|
2010-11-16 09:07:06 +00:00
|
|
|
mHandler.postUpdateOldSuggestions();
|
2010-09-06 10:18:38 +00:00
|
|
|
} else {
|
2011-03-01 06:59:06 +00:00
|
|
|
abortRecorrection(false);
|
2011-04-20 02:50:05 +00:00
|
|
|
// If showing the "touch again to save" hint, do not replace it. Else,
|
|
|
|
// show the bigrams if we are at the end of the text, punctuation otherwise.
|
|
|
|
if (mCandidateView != null
|
2010-11-13 10:09:30 +00:00
|
|
|
&& !mCandidateView.isShowingAddToDictionaryHint()) {
|
2011-04-20 02:50:05 +00:00
|
|
|
InputConnection ic = getCurrentInputConnection();
|
|
|
|
if (null == ic || !TextUtils.isEmpty(ic.getTextAfterCursor(1, 0))) {
|
|
|
|
if (!isShowingPunctuationList()) setPunctuationSuggestions();
|
|
|
|
} else {
|
2011-04-22 07:16:30 +00:00
|
|
|
mHandler.postUpdateBigramPredictions();
|
2011-04-20 02:50:05 +00:00
|
|
|
}
|
2010-10-05 13:51:59 +00:00
|
|
|
}
|
2010-09-06 10:18:38 +00:00
|
|
|
}
|
2010-08-26 19:22:58 +00:00
|
|
|
}
|
2010-01-16 20:21:23 +00:00
|
|
|
}
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2010-09-15 04:03:34 +00:00
|
|
|
/**
|
|
|
|
* This is called when the user has clicked on the extracted text view,
|
|
|
|
* when running in fullscreen mode. The default implementation hides
|
|
|
|
* the candidates view when this happens, but only if the extracted text
|
|
|
|
* editor has a vertical scroll bar because its text doesn't fit.
|
|
|
|
* Here we override the behavior due to the possibility that a re-correction could
|
|
|
|
* cause the candidate strip to disappear and re-appear.
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public void onExtractedTextClicked() {
|
2011-03-01 06:59:06 +00:00
|
|
|
if (mRecorrectionEnabled && isSuggestionsRequested()) return;
|
2010-09-15 04:03:34 +00:00
|
|
|
|
|
|
|
super.onExtractedTextClicked();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is called when the user has performed a cursor movement in the
|
|
|
|
* extracted text view, when it is running in fullscreen mode. The default
|
|
|
|
* implementation hides the candidates view when a vertical movement
|
|
|
|
* happens, but only if the extracted text editor has a vertical scroll bar
|
|
|
|
* because its text doesn't fit.
|
|
|
|
* Here we override the behavior due to the possibility that a re-correction could
|
|
|
|
* cause the candidate strip to disappear and re-appear.
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public void onExtractedCursorMovement(int dx, int dy) {
|
2011-03-01 06:59:06 +00:00
|
|
|
if (mRecorrectionEnabled && isSuggestionsRequested()) return;
|
2010-09-15 04:03:34 +00:00
|
|
|
|
|
|
|
super.onExtractedCursorMovement(dx, dy);
|
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
@Override
|
|
|
|
public void hideWindow() {
|
2010-08-20 05:35:02 +00:00
|
|
|
LatinImeLogger.commit();
|
2010-12-11 08:06:24 +00:00
|
|
|
mKeyboardSwitcher.onAutoCorrectionStateChanged(false);
|
2010-08-20 05:35:02 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
if (TRACE) Debug.stopMethodTracing();
|
2009-03-26 00:39:38 +00:00
|
|
|
if (mOptionsDialog != null && mOptionsDialog.isShowing()) {
|
|
|
|
mOptionsDialog.dismiss();
|
|
|
|
mOptionsDialog = null;
|
|
|
|
}
|
2011-03-25 00:42:09 +00:00
|
|
|
mVoiceProxy.hideVoiceWindow(mConfigurationChanging);
|
2010-08-20 05:35:02 +00:00
|
|
|
mWordHistory.clear();
|
2009-03-13 22:11:42 +00:00
|
|
|
super.hideWindow();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2010-12-11 08:06:24 +00:00
|
|
|
public void onDisplayCompletions(CompletionInfo[] applicationSpecifiedCompletions) {
|
2010-08-20 05:35:02 +00:00
|
|
|
if (DEBUG) {
|
2011-01-10 02:59:46 +00:00
|
|
|
Log.i(TAG, "Received completions:");
|
2011-03-04 07:56:10 +00:00
|
|
|
if (applicationSpecifiedCompletions != null) {
|
|
|
|
for (int i = 0; i < applicationSpecifiedCompletions.length; i++) {
|
|
|
|
Log.i(TAG, " #" + i + ": " + applicationSpecifiedCompletions[i]);
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
}
|
2010-12-11 08:06:24 +00:00
|
|
|
if (mApplicationSpecifiedCompletionOn) {
|
|
|
|
mApplicationSpecifiedCompletions = applicationSpecifiedCompletions;
|
|
|
|
if (applicationSpecifiedCompletions == null) {
|
2010-08-26 19:22:58 +00:00
|
|
|
clearSuggestions();
|
2009-03-13 22:11:42 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-12-10 11:50:30 +00:00
|
|
|
SuggestedWords.Builder builder = new SuggestedWords.Builder()
|
2010-12-11 08:06:24 +00:00
|
|
|
.setApplicationSpecifiedCompletions(applicationSpecifiedCompletions)
|
2010-12-10 11:50:30 +00:00
|
|
|
.setTypedWordValid(true)
|
|
|
|
.setHasMinimalSuggestion(true);
|
2010-08-20 05:35:02 +00:00
|
|
|
// When in fullscreen mode, show completions generated by the application
|
2010-12-10 11:50:30 +00:00
|
|
|
setSuggestions(builder.build());
|
2009-03-13 22:11:42 +00:00
|
|
|
mBestWord = null;
|
2010-08-31 09:00:09 +00:00
|
|
|
setCandidatesViewShown(true);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-31 09:00:09 +00:00
|
|
|
private void setCandidatesViewShownInternal(boolean shown, boolean needsInputViewShown) {
|
2011-04-13 05:12:24 +00:00
|
|
|
// TODO: Modify this if we support candidates with hard keyboard
|
2009-03-13 22:11:42 +00:00
|
|
|
if (onEvaluateInputViewShown()) {
|
2011-04-13 05:12:24 +00:00
|
|
|
final boolean shouldShowCandidates = shown
|
|
|
|
&& (needsInputViewShown ? mKeyboardSwitcher.isInputViewShown() : true);
|
|
|
|
if (isExtractViewShown()) {
|
|
|
|
// No need to have extra space to show the key preview.
|
|
|
|
mCandidateViewContainer.setMinimumHeight(0);
|
|
|
|
super.setCandidatesViewShown(shown);
|
|
|
|
} else {
|
|
|
|
// We must control the visibility of the suggestion strip in order to avoid clipped
|
|
|
|
// key previews, even when we don't show the suggestion strip.
|
|
|
|
mCandidateViewContainer.setVisibility(
|
|
|
|
shouldShowCandidates ? View.VISIBLE : View.INVISIBLE);
|
|
|
|
super.setCandidatesViewShown(true);
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-08-31 09:00:09 +00:00
|
|
|
@Override
|
|
|
|
public void setCandidatesViewShown(boolean shown) {
|
|
|
|
setCandidatesViewShownInternal(shown, true /* needsInputViewShown */ );
|
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
@Override
|
|
|
|
public void onComputeInsets(InputMethodService.Insets outInsets) {
|
|
|
|
super.onComputeInsets(outInsets);
|
2011-04-13 05:12:24 +00:00
|
|
|
final KeyboardView inputView = mKeyboardSwitcher.getInputView();
|
2011-04-21 05:51:53 +00:00
|
|
|
if (inputView == null)
|
|
|
|
return;
|
|
|
|
final int containerHeight = mCandidateViewContainer.getHeight();
|
|
|
|
int touchY = containerHeight;
|
2011-01-21 10:04:00 +00:00
|
|
|
// Need to set touchable region only if input view is being shown
|
2011-04-21 05:51:53 +00:00
|
|
|
if (mKeyboardSwitcher.isInputViewShown()) {
|
2011-04-13 05:12:24 +00:00
|
|
|
if (mCandidateViewContainer.getVisibility() == View.VISIBLE) {
|
|
|
|
touchY -= mCandidateStripHeight;
|
2011-01-21 10:04:00 +00:00
|
|
|
}
|
2011-04-13 05:12:24 +00:00
|
|
|
final int touchWidth = inputView.getWidth();
|
|
|
|
final int touchHeight = inputView.getHeight() + containerHeight
|
|
|
|
// Extend touchable region below the keyboard.
|
|
|
|
+ EXTENDED_TOUCHABLE_REGION_HEIGHT;
|
2011-01-21 10:04:00 +00:00
|
|
|
if (DEBUG) {
|
2011-04-13 05:12:24 +00:00
|
|
|
Log.d(TAG, "Touchable region: y=" + touchY + " width=" + touchWidth
|
|
|
|
+ " height=" + touchHeight);
|
2011-01-21 10:04:00 +00:00
|
|
|
}
|
2011-04-13 05:12:24 +00:00
|
|
|
setTouchableRegionCompat(outInsets, 0, touchY, touchWidth, touchHeight);
|
2011-01-21 10:04:00 +00:00
|
|
|
}
|
2011-04-21 05:51:53 +00:00
|
|
|
outInsets.contentTopInsets = touchY;
|
|
|
|
outInsets.visibleTopInsets = touchY;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-08-20 05:35:02 +00:00
|
|
|
@Override
|
|
|
|
public boolean onEvaluateFullscreenMode() {
|
2011-01-04 15:39:41 +00:00
|
|
|
final Resources res = mResources;
|
|
|
|
DisplayMetrics dm = res.getDisplayMetrics();
|
2010-08-20 05:35:02 +00:00
|
|
|
float displayHeight = dm.heightPixels;
|
|
|
|
// If the display is more than X inches high, don't go to fullscreen mode
|
2011-01-04 15:39:41 +00:00
|
|
|
float dimen = res.getDimension(R.dimen.max_height_for_fullscreen);
|
2010-08-20 05:35:02 +00:00
|
|
|
if (displayHeight > dimen) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return super.onEvaluateFullscreenMode();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
@Override
|
|
|
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
|
|
|
switch (keyCode) {
|
2010-12-10 06:24:28 +00:00
|
|
|
case KeyEvent.KEYCODE_BACK:
|
|
|
|
if (event.getRepeatCount() == 0 && mKeyboardSwitcher.getInputView() != null) {
|
|
|
|
if (mKeyboardSwitcher.getInputView().handleBack()) {
|
2009-03-26 00:39:38 +00:00
|
|
|
return true;
|
|
|
|
}
|
2010-12-10 06:24:28 +00:00
|
|
|
}
|
|
|
|
break;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
return super.onKeyDown(keyCode, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
|
|
|
switch (keyCode) {
|
2010-12-10 06:24:28 +00:00
|
|
|
case KeyEvent.KEYCODE_DPAD_DOWN:
|
|
|
|
case KeyEvent.KEYCODE_DPAD_UP:
|
|
|
|
case KeyEvent.KEYCODE_DPAD_LEFT:
|
|
|
|
case KeyEvent.KEYCODE_DPAD_RIGHT:
|
|
|
|
// Enable shift key and DPAD to do selections
|
|
|
|
if (mKeyboardSwitcher.isInputViewShown()
|
|
|
|
&& mKeyboardSwitcher.isShiftedOrShiftLocked()) {
|
|
|
|
KeyEvent newEvent = new KeyEvent(event.getDownTime(), event.getEventTime(),
|
|
|
|
event.getAction(), event.getKeyCode(), event.getRepeatCount(),
|
|
|
|
event.getDeviceId(), event.getScanCode(),
|
|
|
|
KeyEvent.META_SHIFT_LEFT_ON | KeyEvent.META_SHIFT_ON);
|
|
|
|
InputConnection ic = getCurrentInputConnection();
|
|
|
|
if (ic != null)
|
|
|
|
ic.sendKeyEvent(newEvent);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
return super.onKeyUp(keyCode, event);
|
|
|
|
}
|
|
|
|
|
2010-11-21 01:36:37 +00:00
|
|
|
public void commitTyped(InputConnection inputConnection) {
|
2010-12-19 08:32:26 +00:00
|
|
|
if (mHasValidSuggestions) {
|
|
|
|
mHasValidSuggestions = false;
|
2009-03-13 22:11:42 +00:00
|
|
|
if (mComposing.length() > 0) {
|
|
|
|
if (inputConnection != null) {
|
|
|
|
inputConnection.commitText(mComposing, 1);
|
|
|
|
}
|
|
|
|
mCommittedLength = mComposing.length();
|
|
|
|
TextEntryState.acceptedTyped(mComposing);
|
2011-03-04 07:56:10 +00:00
|
|
|
addToAutoAndUserBigramDictionaries(mComposing, AutoDictionary.FREQUENCY_FOR_TYPED);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
updateSuggestions();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-13 08:16:34 +00:00
|
|
|
public boolean getCurrentAutoCapsState() {
|
2009-03-13 22:11:42 +00:00
|
|
|
InputConnection ic = getCurrentInputConnection();
|
2010-01-24 15:34:07 +00:00
|
|
|
EditorInfo ei = getCurrentInputEditorInfo();
|
2010-12-10 06:24:28 +00:00
|
|
|
if (mAutoCap && ic != null && ei != null && ei.inputType != InputType.TYPE_NULL) {
|
2010-11-13 08:16:34 +00:00
|
|
|
return ic.getCursorCapsMode(ei.inputType) != 0;
|
2010-01-24 15:34:07 +00:00
|
|
|
}
|
2010-11-13 08:16:34 +00:00
|
|
|
return false;
|
2010-01-24 15:34:07 +00:00
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
private void swapPunctuationAndSpace() {
|
|
|
|
final InputConnection ic = getCurrentInputConnection();
|
|
|
|
if (ic == null) return;
|
|
|
|
CharSequence lastTwo = ic.getTextBeforeCursor(2, 0);
|
|
|
|
if (lastTwo != null && lastTwo.length() == 2
|
2010-12-02 11:54:32 +00:00
|
|
|
&& lastTwo.charAt(0) == Keyboard.CODE_SPACE
|
|
|
|
&& isSentenceSeparator(lastTwo.charAt(1))) {
|
2009-03-13 22:11:42 +00:00
|
|
|
ic.beginBatchEdit();
|
|
|
|
ic.deleteSurroundingText(2, 0);
|
|
|
|
ic.commitText(lastTwo.charAt(1) + " ", 1);
|
|
|
|
ic.endBatchEdit();
|
2010-11-13 08:16:34 +00:00
|
|
|
mKeyboardSwitcher.updateShiftState();
|
2010-02-07 00:34:43 +00:00
|
|
|
mJustAddedAutoSpace = true;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
}
|
2010-01-24 15:34:07 +00:00
|
|
|
|
2010-02-22 14:55:45 +00:00
|
|
|
private void reswapPeriodAndSpace() {
|
|
|
|
final InputConnection ic = getCurrentInputConnection();
|
|
|
|
if (ic == null) return;
|
|
|
|
CharSequence lastThree = ic.getTextBeforeCursor(3, 0);
|
|
|
|
if (lastThree != null && lastThree.length() == 3
|
2010-12-02 11:54:32 +00:00
|
|
|
&& lastThree.charAt(0) == Keyboard.CODE_PERIOD
|
|
|
|
&& lastThree.charAt(1) == Keyboard.CODE_SPACE
|
|
|
|
&& lastThree.charAt(2) == Keyboard.CODE_PERIOD) {
|
2010-02-22 14:55:45 +00:00
|
|
|
ic.beginBatchEdit();
|
|
|
|
ic.deleteSurroundingText(3, 0);
|
|
|
|
ic.commitText(" ..", 1);
|
|
|
|
ic.endBatchEdit();
|
2010-11-13 08:16:34 +00:00
|
|
|
mKeyboardSwitcher.updateShiftState();
|
2010-02-22 14:55:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
private void doubleSpace() {
|
|
|
|
if (mCorrectionMode == Suggest.CORRECTION_NONE) return;
|
|
|
|
final InputConnection ic = getCurrentInputConnection();
|
|
|
|
if (ic == null) return;
|
|
|
|
CharSequence lastThree = ic.getTextBeforeCursor(3, 0);
|
|
|
|
if (lastThree != null && lastThree.length() == 3
|
|
|
|
&& Character.isLetterOrDigit(lastThree.charAt(0))
|
2010-12-02 11:54:32 +00:00
|
|
|
&& lastThree.charAt(1) == Keyboard.CODE_SPACE
|
2011-03-02 07:40:10 +00:00
|
|
|
&& lastThree.charAt(2) == Keyboard.CODE_SPACE
|
|
|
|
&& mHandler.isAcceptingDoubleSpaces()) {
|
|
|
|
mHandler.cancelDoubleSpacesTimer();
|
2009-03-13 22:11:42 +00:00
|
|
|
ic.beginBatchEdit();
|
|
|
|
ic.deleteSurroundingText(2, 0);
|
|
|
|
ic.commitText(". ", 1);
|
|
|
|
ic.endBatchEdit();
|
2010-11-13 08:16:34 +00:00
|
|
|
mKeyboardSwitcher.updateShiftState();
|
2010-02-07 00:34:43 +00:00
|
|
|
mJustAddedAutoSpace = true;
|
2011-03-02 07:40:10 +00:00
|
|
|
} else {
|
|
|
|
mHandler.startDoubleSpacesTimer();
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-01-31 16:34:55 +00:00
|
|
|
private void maybeRemovePreviousPeriod(CharSequence text) {
|
|
|
|
final InputConnection ic = getCurrentInputConnection();
|
|
|
|
if (ic == null) return;
|
|
|
|
|
|
|
|
// When the text's first character is '.', remove the previous period
|
|
|
|
// if there is one.
|
|
|
|
CharSequence lastOne = ic.getTextBeforeCursor(1, 0);
|
2010-02-22 14:55:45 +00:00
|
|
|
if (lastOne != null && lastOne.length() == 1
|
2010-12-02 11:54:32 +00:00
|
|
|
&& lastOne.charAt(0) == Keyboard.CODE_PERIOD
|
|
|
|
&& text.charAt(0) == Keyboard.CODE_PERIOD) {
|
2010-01-31 16:34:55 +00:00
|
|
|
ic.deleteSurroundingText(1, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-07 00:34:43 +00:00
|
|
|
private void removeTrailingSpace() {
|
|
|
|
final InputConnection ic = getCurrentInputConnection();
|
|
|
|
if (ic == null) return;
|
|
|
|
|
|
|
|
CharSequence lastOne = ic.getTextBeforeCursor(1, 0);
|
|
|
|
if (lastOne != null && lastOne.length() == 1
|
2010-12-02 11:54:32 +00:00
|
|
|
&& lastOne.charAt(0) == Keyboard.CODE_SPACE) {
|
2010-02-07 00:34:43 +00:00
|
|
|
ic.deleteSurroundingText(1, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
public boolean addWordToDictionary(String word) {
|
|
|
|
mUserDictionary.addWord(word, 128);
|
2010-08-03 18:47:42 +00:00
|
|
|
// Suggestion strip should be updated after the operation of adding word to the
|
|
|
|
// user dictionary
|
2010-11-16 09:07:06 +00:00
|
|
|
mHandler.postUpdateSuggestions();
|
2009-03-13 22:11:42 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean isAlphabet(int code) {
|
|
|
|
if (Character.isLetter(code)) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-12-06 03:12:27 +00:00
|
|
|
private void onSettingsKeyPressed() {
|
2010-09-02 19:25:31 +00:00
|
|
|
if (!isShowingOptionDialog()) {
|
2011-01-20 13:52:02 +00:00
|
|
|
if (!mConfigEnableShowSubtypeSettings) {
|
|
|
|
showSubtypeSelectorAndSettings();
|
|
|
|
} else if (Utils.hasMultipleEnabledIMEsOrSubtypes(mImm)) {
|
2010-09-02 19:25:31 +00:00
|
|
|
showOptionsMenu();
|
|
|
|
} else {
|
|
|
|
launchSettings();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-06 03:12:27 +00:00
|
|
|
private void onSettingsKeyLongPressed() {
|
2010-09-02 19:25:31 +00:00
|
|
|
if (!isShowingOptionDialog()) {
|
2010-12-09 12:06:26 +00:00
|
|
|
if (Utils.hasMultipleEnabledIMEsOrSubtypes(mImm)) {
|
2010-11-25 00:20:28 +00:00
|
|
|
mImm.showInputMethodPicker();
|
2010-09-02 19:25:31 +00:00
|
|
|
} else {
|
|
|
|
launchSettings();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean isShowingOptionDialog() {
|
|
|
|
return mOptionsDialog != null && mOptionsDialog.isShowing();
|
|
|
|
}
|
|
|
|
|
2010-12-30 08:19:55 +00:00
|
|
|
// Implementation of {@link KeyboardActionListener}.
|
2010-12-02 09:46:21 +00:00
|
|
|
@Override
|
2010-12-20 07:13:57 +00:00
|
|
|
public void onCodeInput(int primaryCode, int[] keyCodes, int x, int y) {
|
2009-03-13 22:11:42 +00:00
|
|
|
long when = SystemClock.uptimeMillis();
|
2010-12-02 11:54:32 +00:00
|
|
|
if (primaryCode != Keyboard.CODE_DELETE || when > mLastKeyTime + QUICK_PRESS) {
|
2009-03-13 22:11:42 +00:00
|
|
|
mDeleteCount = 0;
|
|
|
|
}
|
|
|
|
mLastKeyTime = when;
|
2010-11-13 08:16:34 +00:00
|
|
|
KeyboardSwitcher switcher = mKeyboardSwitcher;
|
2011-01-14 18:49:21 +00:00
|
|
|
final boolean accessibilityEnabled = switcher.isAccessibilityEnabled();
|
2010-11-13 08:16:34 +00:00
|
|
|
final boolean distinctMultiTouch = switcher.hasDistinctMultitouch();
|
2009-03-13 22:11:42 +00:00
|
|
|
switch (primaryCode) {
|
2010-12-02 11:54:32 +00:00
|
|
|
case Keyboard.CODE_DELETE:
|
2010-10-22 10:35:23 +00:00
|
|
|
handleBackspace();
|
|
|
|
mDeleteCount++;
|
|
|
|
LatinImeLogger.logOnDelete();
|
|
|
|
break;
|
2010-12-02 11:54:32 +00:00
|
|
|
case Keyboard.CODE_SHIFT:
|
2010-10-22 10:35:23 +00:00
|
|
|
// Shift key is handled in onPress() when device has distinct multi-touch panel.
|
2011-01-14 18:49:21 +00:00
|
|
|
if (!distinctMultiTouch || accessibilityEnabled)
|
2010-11-13 08:16:34 +00:00
|
|
|
switcher.toggleShift();
|
2010-10-22 10:35:23 +00:00
|
|
|
break;
|
2010-12-06 03:12:27 +00:00
|
|
|
case Keyboard.CODE_SWITCH_ALPHA_SYMBOL:
|
2010-10-22 10:35:23 +00:00
|
|
|
// Symbol key is handled in onPress() when device has distinct multi-touch panel.
|
2011-01-14 18:49:21 +00:00
|
|
|
if (!distinctMultiTouch || accessibilityEnabled)
|
2010-11-13 08:16:34 +00:00
|
|
|
switcher.changeKeyboardMode();
|
2010-10-22 10:35:23 +00:00
|
|
|
break;
|
2010-12-02 11:54:32 +00:00
|
|
|
case Keyboard.CODE_CANCEL:
|
2010-10-22 10:35:23 +00:00
|
|
|
if (!isShowingOptionDialog()) {
|
|
|
|
handleClose();
|
|
|
|
}
|
|
|
|
break;
|
2010-12-06 03:12:27 +00:00
|
|
|
case Keyboard.CODE_SETTINGS:
|
|
|
|
onSettingsKeyPressed();
|
2010-10-22 10:35:23 +00:00
|
|
|
break;
|
2010-12-06 03:12:27 +00:00
|
|
|
case Keyboard.CODE_SETTINGS_LONGPRESS:
|
|
|
|
onSettingsKeyLongPressed();
|
2010-10-22 10:35:23 +00:00
|
|
|
break;
|
2011-04-21 10:43:20 +00:00
|
|
|
case LatinKeyboard.CODE_NEXT_LANGUAGE:
|
2011-04-08 10:57:13 +00:00
|
|
|
toggleLanguage(true);
|
2010-10-22 10:35:23 +00:00
|
|
|
break;
|
2011-04-21 10:43:20 +00:00
|
|
|
case LatinKeyboard.CODE_PREV_LANGUAGE:
|
2011-04-08 10:57:13 +00:00
|
|
|
toggleLanguage(false);
|
2010-10-22 10:35:23 +00:00
|
|
|
break;
|
2010-12-02 11:54:32 +00:00
|
|
|
case Keyboard.CODE_CAPSLOCK:
|
2010-11-13 08:16:34 +00:00
|
|
|
switcher.toggleCapsLock();
|
2010-10-22 10:35:23 +00:00
|
|
|
break;
|
2011-04-21 10:43:20 +00:00
|
|
|
case Keyboard.CODE_SHORTCUT:
|
2010-12-09 18:18:32 +00:00
|
|
|
mSubtypeSwitcher.switchToShortcutIME();
|
2010-10-22 10:35:23 +00:00
|
|
|
break;
|
2010-12-02 11:54:32 +00:00
|
|
|
case Keyboard.CODE_TAB:
|
2010-11-12 23:49:56 +00:00
|
|
|
handleTab();
|
2010-10-22 10:35:23 +00:00
|
|
|
break;
|
|
|
|
default:
|
2010-12-02 11:54:32 +00:00
|
|
|
if (primaryCode != Keyboard.CODE_ENTER) {
|
2010-10-22 10:35:23 +00:00
|
|
|
mJustAddedAutoSpace = false;
|
|
|
|
}
|
|
|
|
if (isWordSeparator(primaryCode)) {
|
2011-04-06 02:14:20 +00:00
|
|
|
handleSeparator(primaryCode, x, y);
|
2010-10-22 10:35:23 +00:00
|
|
|
} else {
|
2011-02-22 08:28:55 +00:00
|
|
|
handleCharacter(primaryCode, keyCodes, x, y);
|
2010-10-22 10:35:23 +00:00
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-11-13 08:16:34 +00:00
|
|
|
switcher.onKey(primaryCode);
|
2010-04-01 13:28:52 +00:00
|
|
|
// Reset after any single keystroke
|
|
|
|
mEnteredText = null;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-12-02 09:46:21 +00:00
|
|
|
@Override
|
2010-12-20 07:13:57 +00:00
|
|
|
public void onTextInput(CharSequence text) {
|
2011-03-25 00:42:09 +00:00
|
|
|
mVoiceProxy.commitVoiceInput();
|
2009-03-13 22:11:42 +00:00
|
|
|
InputConnection ic = getCurrentInputConnection();
|
|
|
|
if (ic == null) return;
|
2011-03-01 06:59:06 +00:00
|
|
|
abortRecorrection(false);
|
2009-03-13 22:11:42 +00:00
|
|
|
ic.beginBatchEdit();
|
2010-12-09 07:36:45 +00:00
|
|
|
commitTyped(ic);
|
2010-01-31 16:34:55 +00:00
|
|
|
maybeRemovePreviousPeriod(text);
|
2009-03-13 22:11:42 +00:00
|
|
|
ic.commitText(text, 1);
|
|
|
|
ic.endBatchEdit();
|
2010-11-13 08:16:34 +00:00
|
|
|
mKeyboardSwitcher.updateShiftState();
|
2010-12-30 08:19:55 +00:00
|
|
|
mKeyboardSwitcher.onKey(Keyboard.CODE_DUMMY);
|
2010-02-07 00:34:43 +00:00
|
|
|
mJustAddedAutoSpace = false;
|
2010-04-01 13:28:52 +00:00
|
|
|
mEnteredText = text;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2010-12-02 09:46:21 +00:00
|
|
|
@Override
|
2010-12-20 07:13:57 +00:00
|
|
|
public void onCancelInput() {
|
2010-09-07 06:37:59 +00:00
|
|
|
// User released a finger outside any key
|
2010-12-30 08:19:55 +00:00
|
|
|
mKeyboardSwitcher.onCancelInput();
|
2010-09-07 06:37:59 +00:00
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
private void handleBackspace() {
|
2011-03-25 00:42:09 +00:00
|
|
|
if (mVoiceProxy.logAndRevertVoiceInput()) return;
|
2010-03-04 14:34:21 +00:00
|
|
|
|
2011-01-13 08:14:27 +00:00
|
|
|
final InputConnection ic = getCurrentInputConnection();
|
|
|
|
if (ic == null) return;
|
2010-08-20 05:35:02 +00:00
|
|
|
ic.beginBatchEdit();
|
|
|
|
|
2011-03-25 00:42:09 +00:00
|
|
|
mVoiceProxy.handleBackspace();
|
2010-03-04 14:34:21 +00:00
|
|
|
|
2011-01-13 08:14:27 +00:00
|
|
|
boolean deleteChar = false;
|
2010-12-19 08:32:26 +00:00
|
|
|
if (mHasValidSuggestions) {
|
2009-03-13 22:11:42 +00:00
|
|
|
final int length = mComposing.length();
|
|
|
|
if (length > 0) {
|
|
|
|
mComposing.delete(length - 1, length);
|
|
|
|
mWord.deleteLast();
|
|
|
|
ic.setComposingText(mComposing, 1);
|
|
|
|
if (mComposing.length() == 0) {
|
2010-12-19 08:32:26 +00:00
|
|
|
mHasValidSuggestions = false;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2011-04-20 02:50:05 +00:00
|
|
|
if (1 == length) {
|
|
|
|
// 1 == length means we are about to erase the last character of the word,
|
|
|
|
// so we can show bigrams.
|
2011-04-22 07:16:30 +00:00
|
|
|
mHandler.postUpdateBigramPredictions();
|
2011-04-20 02:50:05 +00:00
|
|
|
} else {
|
|
|
|
// length > 1, so we still have letters to deduce a suggestion from.
|
|
|
|
mHandler.postUpdateSuggestions();
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
} else {
|
|
|
|
ic.deleteSurroundingText(1, 0);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
deleteChar = true;
|
|
|
|
}
|
2010-11-16 09:07:06 +00:00
|
|
|
mHandler.postUpdateShiftKeyState();
|
2011-01-13 08:14:27 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
TextEntryState.backspace();
|
2011-03-03 01:02:06 +00:00
|
|
|
if (TextEntryState.isUndoCommit()) {
|
2009-03-13 22:11:42 +00:00
|
|
|
revertLastWord(deleteChar);
|
2010-08-20 05:35:02 +00:00
|
|
|
ic.endBatchEdit();
|
2009-03-13 22:11:42 +00:00
|
|
|
return;
|
2011-01-13 08:14:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mEnteredText != null && sameAsTextBeforeCursor(ic, mEnteredText)) {
|
2010-04-01 13:28:52 +00:00
|
|
|
ic.deleteSurroundingText(mEnteredText.length(), 0);
|
2009-03-13 22:11:42 +00:00
|
|
|
} else if (deleteChar) {
|
2010-08-03 18:47:42 +00:00
|
|
|
if (mCandidateView != null && mCandidateView.dismissAddToDictionaryHint()) {
|
|
|
|
// Go back to the suggestion mode if the user canceled the
|
2010-10-05 13:51:59 +00:00
|
|
|
// "Touch again to save".
|
2010-08-03 18:47:42 +00:00
|
|
|
// NOTE: In gerenal, we don't revert the word when backspacing
|
|
|
|
// from a manual suggestion pick. We deliberately chose a
|
|
|
|
// different behavior only in the case of picking the first
|
|
|
|
// suggestion (typed word). It's intentional to have made this
|
|
|
|
// inconsistent with backspacing after selecting other suggestions.
|
|
|
|
revertLastWord(deleteChar);
|
|
|
|
} else {
|
2009-03-13 22:11:42 +00:00
|
|
|
sendDownUpKeyEvents(KeyEvent.KEYCODE_DEL);
|
2010-08-03 18:47:42 +00:00
|
|
|
if (mDeleteCount > DELETE_ACCELERATE_AT) {
|
|
|
|
sendDownUpKeyEvents(KeyEvent.KEYCODE_DEL);
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
ic.endBatchEdit();
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2010-11-12 23:49:56 +00:00
|
|
|
private void handleTab() {
|
|
|
|
final int imeOptions = getCurrentInputEditorInfo().imeOptions;
|
2011-03-24 06:18:49 +00:00
|
|
|
if (!EditorInfoCompatUtils.hasFlagNavigateNext(imeOptions)
|
|
|
|
&& !EditorInfoCompatUtils.hasFlagNavigatePrevious(imeOptions)) {
|
2010-11-12 23:49:56 +00:00
|
|
|
sendDownUpKeyEvents(KeyEvent.KEYCODE_TAB);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
final InputConnection ic = getCurrentInputConnection();
|
|
|
|
if (ic == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// True if keyboard is in either chording shift or manual temporary upper case mode.
|
|
|
|
final boolean isManualTemporaryUpperCase = mKeyboardSwitcher.isManualTemporaryUpperCase();
|
2011-03-24 06:18:49 +00:00
|
|
|
if (EditorInfoCompatUtils.hasFlagNavigateNext(imeOptions)
|
2010-11-12 23:49:56 +00:00
|
|
|
&& !isManualTemporaryUpperCase) {
|
2011-03-24 06:18:49 +00:00
|
|
|
EditorInfoCompatUtils.performEditorActionNext(ic);
|
2010-11-12 23:49:56 +00:00
|
|
|
ic.performEditorAction(EditorInfo.IME_ACTION_NEXT);
|
2011-03-24 06:18:49 +00:00
|
|
|
} else if (EditorInfoCompatUtils.hasFlagNavigatePrevious(imeOptions)
|
2010-11-12 23:49:56 +00:00
|
|
|
&& isManualTemporaryUpperCase) {
|
2011-03-24 06:18:49 +00:00
|
|
|
EditorInfoCompatUtils.performEditorActionPrevious(ic);
|
2010-11-12 23:49:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-01 06:59:06 +00:00
|
|
|
private void abortRecorrection(boolean force) {
|
|
|
|
if (force || TextEntryState.isRecorrecting()) {
|
|
|
|
TextEntryState.onAbortRecorrection();
|
2010-11-11 04:37:18 +00:00
|
|
|
setCandidatesViewShown(isCandidateStripVisible());
|
2010-08-20 05:35:02 +00:00
|
|
|
getCurrentInputConnection().finishComposingText();
|
2010-08-26 19:22:58 +00:00
|
|
|
clearSuggestions();
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2011-02-22 08:28:55 +00:00
|
|
|
private void handleCharacter(int primaryCode, int[] keyCodes, int x, int y) {
|
2011-03-25 00:42:09 +00:00
|
|
|
mVoiceProxy.handleCharacter();
|
2010-03-04 14:34:21 +00:00
|
|
|
|
2011-03-01 06:59:06 +00:00
|
|
|
if (mLastSelectionStart == mLastSelectionEnd && TextEntryState.isRecorrecting()) {
|
|
|
|
abortRecorrection(false);
|
2010-08-26 19:22:58 +00:00
|
|
|
}
|
2010-03-04 14:34:21 +00:00
|
|
|
|
2010-12-10 06:24:28 +00:00
|
|
|
int code = primaryCode;
|
2010-12-19 08:32:26 +00:00
|
|
|
if (isAlphabet(code) && isSuggestionsRequested() && !isCursorTouchingWord()) {
|
|
|
|
if (!mHasValidSuggestions) {
|
|
|
|
mHasValidSuggestions = true;
|
2009-03-13 22:11:42 +00:00
|
|
|
mComposing.setLength(0);
|
2010-08-20 05:35:02 +00:00
|
|
|
saveWordInHistory(mBestWord);
|
2009-03-13 22:11:42 +00:00
|
|
|
mWord.reset();
|
2011-03-02 06:56:17 +00:00
|
|
|
clearSuggestions();
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
}
|
2010-11-13 08:01:13 +00:00
|
|
|
KeyboardSwitcher switcher = mKeyboardSwitcher;
|
2010-11-13 08:16:34 +00:00
|
|
|
if (switcher.isShiftedOrShiftLocked()) {
|
2009-10-09 14:03:11 +00:00
|
|
|
if (keyCodes == null || keyCodes[0] < Character.MIN_CODE_POINT
|
|
|
|
|| keyCodes[0] > Character.MAX_CODE_POINT) {
|
|
|
|
return;
|
|
|
|
}
|
2010-12-10 06:24:28 +00:00
|
|
|
code = keyCodes[0];
|
|
|
|
if (switcher.isAlphabetMode() && Character.isLowerCase(code)) {
|
|
|
|
int upperCaseCode = Character.toUpperCase(code);
|
|
|
|
if (upperCaseCode != code) {
|
|
|
|
code = upperCaseCode;
|
2010-09-14 07:22:08 +00:00
|
|
|
} else {
|
|
|
|
// Some keys, such as [eszett], have upper case as multi-characters.
|
2010-12-10 06:24:28 +00:00
|
|
|
String upperCase = new String(new int[] {code}, 0, 1).toUpperCase();
|
2010-12-20 07:13:57 +00:00
|
|
|
onTextInput(upperCase);
|
2010-09-14 07:22:08 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-12-19 08:32:26 +00:00
|
|
|
if (mHasValidSuggestions) {
|
2010-11-13 08:16:34 +00:00
|
|
|
if (mComposing.length() == 0 && switcher.isAlphabetMode()
|
|
|
|
&& switcher.isShiftedOrShiftLocked()) {
|
2010-09-27 15:32:35 +00:00
|
|
|
mWord.setFirstCharCapitalized(true);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-12-10 06:24:28 +00:00
|
|
|
mComposing.append((char) code);
|
2011-02-22 08:28:55 +00:00
|
|
|
mWord.add(code, keyCodes, x, y);
|
2009-03-13 22:11:42 +00:00
|
|
|
InputConnection ic = getCurrentInputConnection();
|
|
|
|
if (ic != null) {
|
2010-01-24 15:34:07 +00:00
|
|
|
// If it's the first letter, make note of auto-caps state
|
|
|
|
if (mWord.size() == 1) {
|
2010-11-13 08:16:34 +00:00
|
|
|
mWord.setAutoCapitalized(getCurrentAutoCapsState());
|
2010-01-24 15:34:07 +00:00
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
ic.setComposingText(mComposing, 1);
|
|
|
|
}
|
2010-11-16 09:07:06 +00:00
|
|
|
mHandler.postUpdateSuggestions();
|
2009-03-13 22:11:42 +00:00
|
|
|
} else {
|
2010-12-10 06:24:28 +00:00
|
|
|
sendKeyChar((char)code);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-11-13 08:16:34 +00:00
|
|
|
switcher.updateShiftState();
|
2010-08-20 05:35:02 +00:00
|
|
|
if (LatinIME.PERF_DEBUG) measureCps();
|
2011-04-06 02:14:20 +00:00
|
|
|
TextEntryState.typedCharacter((char) code, isWordSeparator(code), x, y);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2011-04-06 02:14:20 +00:00
|
|
|
private void handleSeparator(int primaryCode, int x, int y) {
|
2011-03-25 00:42:09 +00:00
|
|
|
mVoiceProxy.handleSeparator();
|
2010-03-04 14:34:21 +00:00
|
|
|
|
2010-10-05 13:51:59 +00:00
|
|
|
// Should dismiss the "Touch again to save" message when handling separator
|
2010-08-03 18:47:42 +00:00
|
|
|
if (mCandidateView != null && mCandidateView.dismissAddToDictionaryHint()) {
|
2011-04-22 07:16:30 +00:00
|
|
|
mHandler.cancelUpdateBigramPredictions();
|
2010-11-16 09:07:06 +00:00
|
|
|
mHandler.postUpdateSuggestions();
|
2010-08-03 18:47:42 +00:00
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
boolean pickedDefault = false;
|
|
|
|
// Handle separator
|
2010-12-11 08:06:24 +00:00
|
|
|
final InputConnection ic = getCurrentInputConnection();
|
2009-03-13 22:11:42 +00:00
|
|
|
if (ic != null) {
|
|
|
|
ic.beginBatchEdit();
|
2011-03-01 06:59:06 +00:00
|
|
|
abortRecorrection(false);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-12-19 08:32:26 +00:00
|
|
|
if (mHasValidSuggestions) {
|
2009-03-13 22:11:42 +00:00
|
|
|
// In certain languages where single quote is a separator, it's better
|
2010-01-28 18:09:44 +00:00
|
|
|
// not to auto correct, but accept the typed word. For instance,
|
2009-03-13 22:11:42 +00:00
|
|
|
// in Italian dov' should not be expanded to dove' because the elision
|
|
|
|
// requires the last vowel to be removed.
|
2011-03-02 18:48:45 +00:00
|
|
|
if (mAutoCorrectOn && primaryCode != '\'') {
|
2011-04-06 02:14:20 +00:00
|
|
|
pickedDefault = pickDefaultSuggestion(primaryCode);
|
2010-02-07 00:34:43 +00:00
|
|
|
// Picked the suggestion by the space key. We consider this
|
|
|
|
// as "added an auto space".
|
2010-12-02 11:54:32 +00:00
|
|
|
if (primaryCode == Keyboard.CODE_SPACE) {
|
2010-02-07 00:34:43 +00:00
|
|
|
mJustAddedAutoSpace = true;
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
} else {
|
|
|
|
commitTyped(ic);
|
|
|
|
}
|
|
|
|
}
|
2010-12-02 11:54:32 +00:00
|
|
|
if (mJustAddedAutoSpace && primaryCode == Keyboard.CODE_ENTER) {
|
2010-02-07 00:34:43 +00:00
|
|
|
removeTrailingSpace();
|
|
|
|
mJustAddedAutoSpace = false;
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
sendKeyChar((char)primaryCode);
|
2010-02-22 14:55:45 +00:00
|
|
|
|
|
|
|
// Handle the case of ". ." -> " .." with auto-space if necessary
|
|
|
|
// before changing the TextEntryState.
|
2011-03-03 01:02:06 +00:00
|
|
|
if (TextEntryState.isPunctuationAfterAccepted() && primaryCode == Keyboard.CODE_PERIOD) {
|
2010-02-22 14:55:45 +00:00
|
|
|
reswapPeriodAndSpace();
|
|
|
|
}
|
|
|
|
|
2011-04-06 02:14:20 +00:00
|
|
|
TextEntryState.typedCharacter((char) primaryCode, true, x, y);
|
2011-04-20 02:50:05 +00:00
|
|
|
|
2011-03-03 01:02:06 +00:00
|
|
|
if (TextEntryState.isPunctuationAfterAccepted() && primaryCode != Keyboard.CODE_ENTER) {
|
2009-03-13 22:11:42 +00:00
|
|
|
swapPunctuationAndSpace();
|
2010-12-19 08:32:26 +00:00
|
|
|
} else if (isSuggestionsRequested() && primaryCode == Keyboard.CODE_SPACE) {
|
2009-03-13 22:11:42 +00:00
|
|
|
doubleSpace();
|
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
if (pickedDefault) {
|
2010-12-09 07:36:45 +00:00
|
|
|
CharSequence typedWord = mWord.getTypedWord();
|
|
|
|
TextEntryState.backToAcceptedDefault(typedWord);
|
|
|
|
if (!TextUtils.isEmpty(typedWord) && !typedWord.equals(mBestWord)) {
|
2011-03-24 06:18:49 +00:00
|
|
|
InputConnectionCompatUtils.commitCorrection(
|
2011-04-20 02:50:05 +00:00
|
|
|
ic, mLastSelectionEnd - typedWord.length(), typedWord, mBestWord);
|
2010-12-09 07:36:45 +00:00
|
|
|
if (mCandidateView != null)
|
|
|
|
mCandidateView.onAutoCorrectionInverted(mBestWord);
|
|
|
|
}
|
2011-04-20 02:50:05 +00:00
|
|
|
}
|
|
|
|
if (Keyboard.CODE_SPACE == primaryCode) {
|
|
|
|
if (!isCursorTouchingWord()) {
|
|
|
|
mHandler.cancelUpdateSuggestions();
|
|
|
|
mHandler.cancelUpdateOldSuggestions();
|
2011-04-22 07:16:30 +00:00
|
|
|
mHandler.postUpdateBigramPredictions();
|
2011-04-20 02:50:05 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Set punctuation right away. onUpdateSelection will fire but tests whether it is
|
|
|
|
// already displayed or not, so it's okay.
|
2010-12-09 07:36:45 +00:00
|
|
|
setPunctuationSuggestions();
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-11-13 08:16:34 +00:00
|
|
|
mKeyboardSwitcher.updateShiftState();
|
2009-03-13 22:11:42 +00:00
|
|
|
if (ic != null) {
|
|
|
|
ic.endBatchEdit();
|
|
|
|
}
|
|
|
|
}
|
2010-01-16 20:21:23 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
private void handleClose() {
|
|
|
|
commitTyped(getCurrentInputConnection());
|
2011-03-25 00:42:09 +00:00
|
|
|
mVoiceProxy.handleClose();
|
2009-03-13 22:11:42 +00:00
|
|
|
requestHideSelf(0);
|
2010-11-13 08:01:13 +00:00
|
|
|
LatinKeyboardView inputView = mKeyboardSwitcher.getInputView();
|
|
|
|
if (inputView != null)
|
|
|
|
inputView.closing();
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2010-08-20 05:35:02 +00:00
|
|
|
private void saveWordInHistory(CharSequence result) {
|
|
|
|
if (mWord.size() <= 1) {
|
|
|
|
return;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
// Skip if result is null. It happens in some edge case.
|
|
|
|
if (TextUtils.isEmpty(result)) {
|
|
|
|
return;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
|
|
|
|
// Make a copy of the CharSequence, since it is/could be a mutable CharSequence
|
|
|
|
final String resultCopy = result.toString();
|
2011-03-15 00:23:26 +00:00
|
|
|
WordAlternatives entry = new WordAlternatives(resultCopy,
|
2010-08-20 05:35:02 +00:00
|
|
|
new WordComposer(mWord));
|
|
|
|
mWordHistory.add(entry);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2010-12-19 08:32:26 +00:00
|
|
|
private boolean isSuggestionsRequested() {
|
2011-01-18 06:28:21 +00:00
|
|
|
return mIsSettingsSuggestionStripOn
|
|
|
|
&& (mCorrectionMode > 0 || isShowingSuggestionsStrip());
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-11-13 10:09:30 +00:00
|
|
|
private boolean isShowingPunctuationList() {
|
2010-12-10 11:50:30 +00:00
|
|
|
return mSuggestPuncList == mCandidateView.getSuggestions();
|
2010-11-13 10:09:30 +00:00
|
|
|
}
|
|
|
|
|
2010-12-19 08:32:26 +00:00
|
|
|
private boolean isShowingSuggestionsStrip() {
|
2010-11-13 10:09:30 +00:00
|
|
|
return (mSuggestionVisibility == SUGGESTION_VISIBILILTY_SHOW_VALUE)
|
|
|
|
|| (mSuggestionVisibility == SUGGESTION_VISIBILILTY_SHOW_ONLY_PORTRAIT_VALUE
|
|
|
|
&& mOrientation == Configuration.ORIENTATION_PORTRAIT);
|
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
private boolean isCandidateStripVisible() {
|
2011-01-26 16:33:02 +00:00
|
|
|
if (mCandidateView == null)
|
|
|
|
return false;
|
2011-03-01 06:59:06 +00:00
|
|
|
if (mCandidateView.isShowingAddToDictionaryHint() || TextEntryState.isRecorrecting())
|
2010-12-19 08:32:26 +00:00
|
|
|
return true;
|
|
|
|
if (!isShowingSuggestionsStrip())
|
|
|
|
return false;
|
|
|
|
if (mApplicationSpecifiedCompletionOn)
|
|
|
|
return true;
|
|
|
|
return isSuggestionsRequested();
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2010-11-21 01:36:37 +00:00
|
|
|
public void switchToKeyboardView() {
|
2011-02-17 08:45:46 +00:00
|
|
|
if (DEBUG) {
|
|
|
|
Log.d(TAG, "Switch to keyboard view.");
|
|
|
|
}
|
|
|
|
View v = mKeyboardSwitcher.getInputView();
|
|
|
|
if (v != null) {
|
|
|
|
// Confirms that the keyboard view doesn't have parent view.
|
|
|
|
ViewParent p = v.getParent();
|
|
|
|
if (p != null && p instanceof ViewGroup) {
|
|
|
|
((ViewGroup) p).removeView(v);
|
2010-12-02 09:46:21 +00:00
|
|
|
}
|
2011-02-17 08:45:46 +00:00
|
|
|
setInputView(v);
|
|
|
|
}
|
|
|
|
setCandidatesViewShown(isCandidateStripVisible());
|
|
|
|
updateInputViewShown();
|
|
|
|
mHandler.postUpdateSuggestions();
|
2010-01-16 20:21:23 +00:00
|
|
|
}
|
|
|
|
|
2010-11-21 01:36:37 +00:00
|
|
|
public void clearSuggestions() {
|
2010-12-10 11:50:30 +00:00
|
|
|
setSuggestions(SuggestedWords.EMPTY);
|
2010-01-16 20:21:23 +00:00
|
|
|
}
|
|
|
|
|
2010-12-10 11:50:30 +00:00
|
|
|
public void setSuggestions(SuggestedWords words) {
|
2011-03-25 00:42:09 +00:00
|
|
|
if (mVoiceProxy.getAndResetIsShowingHint()) {
|
2010-01-16 20:21:23 +00:00
|
|
|
setCandidatesView(mCandidateViewContainer);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mCandidateView != null) {
|
2010-12-10 11:50:30 +00:00
|
|
|
mCandidateView.setSuggestions(words);
|
2010-12-13 03:37:23 +00:00
|
|
|
if (mCandidateView.isConfigCandidateHighlightFontColorEnabled()) {
|
|
|
|
mKeyboardSwitcher.onAutoCorrectionStateChanged(
|
|
|
|
words.hasWordAboveAutoCorrectionScoreThreshold());
|
|
|
|
}
|
2010-01-16 20:21:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-21 01:36:37 +00:00
|
|
|
public void updateSuggestions() {
|
2009-03-13 22:11:42 +00:00
|
|
|
// Check if we have a suggestion engine attached.
|
2010-12-19 08:32:26 +00:00
|
|
|
if ((mSuggest == null || !isSuggestionsRequested())
|
2011-03-25 00:42:09 +00:00
|
|
|
&& !mVoiceProxy.isVoiceInputHighlighted()) {
|
2009-03-13 22:11:42 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-01-16 20:21:23 +00:00
|
|
|
|
2010-12-19 08:32:26 +00:00
|
|
|
if (!mHasValidSuggestions) {
|
2010-11-11 04:37:18 +00:00
|
|
|
setPunctuationSuggestions();
|
2009-03-13 22:11:42 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
showSuggestions(mWord);
|
|
|
|
}
|
|
|
|
|
2010-12-10 11:50:30 +00:00
|
|
|
private SuggestedWords.Builder getTypedSuggestions(WordComposer word) {
|
2010-12-13 03:37:23 +00:00
|
|
|
return mSuggest.getSuggestedWordBuilder(mKeyboardSwitcher.getInputView(), word, null);
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void showCorrections(WordAlternatives alternatives) {
|
2010-12-10 11:50:30 +00:00
|
|
|
SuggestedWords.Builder builder = alternatives.getAlternatives();
|
|
|
|
builder.setTypedWordValid(false).setHasMinimalSuggestion(false);
|
|
|
|
showSuggestions(builder.build(), alternatives.getOriginalWord());
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void showSuggestions(WordComposer word) {
|
2011-03-02 06:40:08 +00:00
|
|
|
// TODO: May need a better way of retrieving previous word
|
2010-12-10 06:24:28 +00:00
|
|
|
CharSequence prevWord = EditingUtils.getPreviousWord(getCurrentInputConnection(),
|
2010-08-20 05:35:02 +00:00
|
|
|
mWordSeparators);
|
2010-12-10 11:50:30 +00:00
|
|
|
SuggestedWords.Builder builder = mSuggest.getSuggestedWordBuilder(
|
2010-12-13 03:37:23 +00:00
|
|
|
mKeyboardSwitcher.getInputView(), word, prevWord);
|
2009-03-13 22:11:42 +00:00
|
|
|
|
2011-03-02 18:48:45 +00:00
|
|
|
boolean correctionAvailable = !mInputTypeNoAutoCorrect && mSuggest.hasAutoCorrection();
|
2011-01-10 02:59:46 +00:00
|
|
|
final CharSequence typedWord = word.getTypedWord();
|
2011-03-04 07:56:10 +00:00
|
|
|
// Here, we want to promote a whitelisted word if exists.
|
|
|
|
final boolean typedWordValid = AutoCorrection.isValidWordForAutoCorrection(
|
|
|
|
mSuggest.getUnigramDictionaries(), typedWord, preferCapitalization());
|
2010-08-20 05:35:02 +00:00
|
|
|
if (mCorrectionMode == Suggest.CORRECTION_FULL
|
|
|
|
|| mCorrectionMode == Suggest.CORRECTION_FULL_BIGRAM) {
|
2009-03-13 22:11:42 +00:00
|
|
|
correctionAvailable |= typedWordValid;
|
|
|
|
}
|
2009-07-23 19:17:48 +00:00
|
|
|
// Don't auto-correct words with multiple capital letter
|
2010-08-20 05:35:02 +00:00
|
|
|
correctionAvailable &= !word.isMostlyCaps();
|
2011-03-01 06:59:06 +00:00
|
|
|
correctionAvailable &= !TextEntryState.isRecorrecting();
|
2010-08-20 05:35:02 +00:00
|
|
|
|
2011-01-10 02:59:46 +00:00
|
|
|
// Basically, we update the suggestion strip only when suggestion count > 1. However,
|
|
|
|
// there is an exception: We update the suggestion strip whenever typed word's length
|
2011-01-21 06:03:09 +00:00
|
|
|
// is 1 or typed word is found in dictionary, regardless of suggestion count. Actually,
|
|
|
|
// in most cases, suggestion count is 1 when typed word's length is 1, but we do always
|
|
|
|
// need to clear the previous state when the user starts typing a word (i.e. typed word's
|
|
|
|
// length == 1).
|
|
|
|
if (builder.size() > 1 || typedWord.length() == 1 || typedWordValid
|
2011-01-10 02:59:46 +00:00
|
|
|
|| mCandidateView.isShowingAddToDictionaryHint()) {
|
2010-12-19 08:32:26 +00:00
|
|
|
builder.setTypedWordValid(typedWordValid).setHasMinimalSuggestion(correctionAvailable);
|
|
|
|
} else {
|
|
|
|
final SuggestedWords previousSuggestions = mCandidateView.getSuggestions();
|
|
|
|
if (previousSuggestions == mSuggestPuncList)
|
|
|
|
return;
|
|
|
|
builder.addTypedWordAndPreviousSuggestions(typedWord, previousSuggestions);
|
|
|
|
}
|
2010-12-10 11:50:30 +00:00
|
|
|
showSuggestions(builder.build(), typedWord);
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|
2009-07-23 19:17:48 +00:00
|
|
|
|
2010-12-10 11:50:30 +00:00
|
|
|
private void showSuggestions(SuggestedWords suggestedWords, CharSequence typedWord) {
|
|
|
|
setSuggestions(suggestedWords);
|
|
|
|
if (suggestedWords.size() > 0) {
|
2011-01-26 16:43:06 +00:00
|
|
|
if (Utils.shouldBlockedBySafetyNetForAutoCorrection(suggestedWords, mSuggest)) {
|
2011-01-18 08:22:01 +00:00
|
|
|
mBestWord = typedWord;
|
|
|
|
} else if (suggestedWords.hasAutoCorrectionWord()) {
|
2010-12-10 11:50:30 +00:00
|
|
|
mBestWord = suggestedWords.getWord(1);
|
2009-03-13 22:11:42 +00:00
|
|
|
} else {
|
|
|
|
mBestWord = typedWord;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mBestWord = null;
|
|
|
|
}
|
2010-11-11 04:37:18 +00:00
|
|
|
setCandidatesViewShown(isCandidateStripVisible());
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2011-04-06 02:14:20 +00:00
|
|
|
private boolean pickDefaultSuggestion(int separatorCode) {
|
2009-03-13 22:11:42 +00:00
|
|
|
// Complete any pending candidate query first
|
2010-11-16 09:07:06 +00:00
|
|
|
if (mHandler.hasPendingUpdateSuggestions()) {
|
|
|
|
mHandler.cancelUpdateSuggestions();
|
2009-03-13 22:11:42 +00:00
|
|
|
updateSuggestions();
|
|
|
|
}
|
2010-03-18 04:37:25 +00:00
|
|
|
if (mBestWord != null && mBestWord.length() > 0) {
|
2011-04-06 02:14:20 +00:00
|
|
|
TextEntryState.acceptedDefault(mWord.getTypedWord(), mBestWord, separatorCode);
|
2009-03-13 22:11:42 +00:00
|
|
|
mJustAccepted = true;
|
2010-12-09 07:36:45 +00:00
|
|
|
pickSuggestion(mBestWord);
|
2010-02-25 18:37:19 +00:00
|
|
|
// Add the word to the auto dictionary if it's not a known word
|
2011-03-04 07:56:10 +00:00
|
|
|
addToAutoAndUserBigramDictionaries(mBestWord, AutoDictionary.FREQUENCY_FOR_TYPED);
|
2010-08-20 05:35:02 +00:00
|
|
|
return true;
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
return false;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void pickSuggestionManually(int index, CharSequence suggestion) {
|
2010-12-10 11:50:30 +00:00
|
|
|
SuggestedWords suggestions = mCandidateView.getSuggestions();
|
2011-03-25 00:42:09 +00:00
|
|
|
mVoiceProxy.flushAndLogAllTextModificationCounters(index, suggestion, mWordSeparators);
|
2010-03-04 14:34:21 +00:00
|
|
|
|
2011-03-01 06:59:06 +00:00
|
|
|
final boolean recorrecting = TextEntryState.isRecorrecting();
|
2010-02-07 00:34:43 +00:00
|
|
|
InputConnection ic = getCurrentInputConnection();
|
|
|
|
if (ic != null) {
|
|
|
|
ic.beginBatchEdit();
|
|
|
|
}
|
2010-12-11 08:06:24 +00:00
|
|
|
if (mApplicationSpecifiedCompletionOn && mApplicationSpecifiedCompletions != null
|
|
|
|
&& index >= 0 && index < mApplicationSpecifiedCompletions.length) {
|
|
|
|
CompletionInfo ci = mApplicationSpecifiedCompletions[index];
|
2009-03-13 22:11:42 +00:00
|
|
|
if (ic != null) {
|
|
|
|
ic.commitCompletion(ci);
|
|
|
|
}
|
|
|
|
mCommittedLength = suggestion.length();
|
|
|
|
if (mCandidateView != null) {
|
|
|
|
mCandidateView.clear();
|
|
|
|
}
|
2010-11-13 08:16:34 +00:00
|
|
|
mKeyboardSwitcher.updateShiftState();
|
2010-02-07 00:34:43 +00:00
|
|
|
if (ic != null) {
|
|
|
|
ic.endBatchEdit();
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-02-03 23:35:49 +00:00
|
|
|
|
|
|
|
// If this is a punctuation, apply it through the normal key press
|
2010-08-20 05:35:02 +00:00
|
|
|
if (suggestion.length() == 1 && (isWordSeparator(suggestion.charAt(0))
|
|
|
|
|| isSuggestedPunctuation(suggestion.charAt(0)))) {
|
|
|
|
// Word separators are suggested before the user inputs something.
|
|
|
|
// So, LatinImeLogger logs "" as a user's input.
|
|
|
|
LatinImeLogger.logOnManualSuggestion(
|
2010-12-10 11:50:30 +00:00
|
|
|
"", suggestion.toString(), index, suggestions.mWords);
|
2010-10-05 13:51:59 +00:00
|
|
|
final char primaryCode = suggestion.charAt(0);
|
2010-12-30 16:35:24 +00:00
|
|
|
onCodeInput(primaryCode, new int[] { primaryCode },
|
|
|
|
KeyboardActionListener.NOT_A_TOUCH_COORDINATE,
|
|
|
|
KeyboardActionListener.NOT_A_TOUCH_COORDINATE);
|
2010-02-07 00:34:43 +00:00
|
|
|
if (ic != null) {
|
|
|
|
ic.endBatchEdit();
|
|
|
|
}
|
2010-02-03 23:35:49 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-04-20 02:50:05 +00:00
|
|
|
if (!mHasValidSuggestions) {
|
|
|
|
// If we are not composing a word, then it was a suggestion inferred from
|
|
|
|
// context - no user input. We should reset the word composer.
|
|
|
|
mWord.reset();
|
|
|
|
}
|
2010-02-07 00:34:43 +00:00
|
|
|
mJustAccepted = true;
|
2010-12-09 07:36:45 +00:00
|
|
|
pickSuggestion(suggestion);
|
2010-02-25 18:37:19 +00:00
|
|
|
// Add the word to the auto dictionary if it's not a known word
|
2010-03-24 23:44:31 +00:00
|
|
|
if (index == 0) {
|
2011-03-04 07:56:10 +00:00
|
|
|
addToAutoAndUserBigramDictionaries(suggestion, AutoDictionary.FREQUENCY_FOR_PICKED);
|
2010-08-20 05:35:02 +00:00
|
|
|
} else {
|
2011-03-04 07:56:10 +00:00
|
|
|
addToOnlyBigramDictionary(suggestion, 1);
|
2010-03-24 23:44:31 +00:00
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
LatinImeLogger.logOnManualSuggestion(mComposing.toString(), suggestion.toString(),
|
2010-12-10 11:50:30 +00:00
|
|
|
index, suggestions.mWords);
|
2009-03-13 22:11:42 +00:00
|
|
|
TextEntryState.acceptedSuggestion(mComposing.toString(), suggestion);
|
|
|
|
// Follow it with a space
|
2011-03-01 06:59:06 +00:00
|
|
|
if (mAutoSpace && !recorrecting) {
|
2009-03-13 22:11:42 +00:00
|
|
|
sendSpace();
|
2010-02-07 00:34:43 +00:00
|
|
|
mJustAddedAutoSpace = true;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
|
2011-02-23 13:04:47 +00:00
|
|
|
// We should show the hint if the user pressed the first entry AND either:
|
|
|
|
// - There is no dictionary (we know that because we tried to load it => null != mSuggest
|
|
|
|
// AND mHasDictionary is false)
|
|
|
|
// - There is a dictionary and the word is not in it
|
|
|
|
// Please note that if mSuggest is null, it means that everything is off: suggestion
|
|
|
|
// and correction, so we shouldn't try to show the hint
|
|
|
|
// We used to look at mCorrectionMode here, but showing the hint should have nothing
|
|
|
|
// to do with the autocorrection setting.
|
2011-03-04 07:56:10 +00:00
|
|
|
final boolean showingAddToDictionaryHint = index == 0 && mSuggest != null
|
|
|
|
// If there is no dictionary the hint should be shown.
|
|
|
|
&& (!mHasDictionary
|
|
|
|
// If "suggestion" is not in the dictionary, the hint should be shown.
|
|
|
|
|| !AutoCorrection.isValidWord(
|
|
|
|
mSuggest.getUnigramDictionaries(), suggestion, true));
|
2010-08-26 19:22:58 +00:00
|
|
|
|
2011-03-01 06:59:06 +00:00
|
|
|
if (!recorrecting) {
|
2010-08-26 19:22:58 +00:00
|
|
|
// Fool the state watcher so that a subsequent backspace will not do a revert, unless
|
|
|
|
// we just did a correction, in which case we need to stay in
|
|
|
|
// TextEntryState.State.PICKED_SUGGESTION state.
|
2011-04-06 02:14:20 +00:00
|
|
|
TextEntryState.typedCharacter((char) Keyboard.CODE_SPACE, true,
|
|
|
|
WordComposer.NOT_A_COORDINATE, WordComposer.NOT_A_COORDINATE);
|
2011-04-20 02:50:05 +00:00
|
|
|
// From there on onUpdateSelection() will fire so suggestions will be updated
|
2010-08-26 19:22:58 +00:00
|
|
|
} else if (!showingAddToDictionaryHint) {
|
2010-10-10 17:52:08 +00:00
|
|
|
// If we're not showing the "Touch again to save", then show corrections again.
|
2010-08-20 05:35:02 +00:00
|
|
|
// In case the cursor position doesn't change, make sure we show the suggestions again.
|
2010-08-26 19:22:58 +00:00
|
|
|
clearSuggestions();
|
2010-11-16 09:07:06 +00:00
|
|
|
mHandler.postUpdateOldSuggestions();
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|
2010-08-26 19:22:58 +00:00
|
|
|
if (showingAddToDictionaryHint) {
|
2010-02-11 01:45:35 +00:00
|
|
|
mCandidateView.showAddToDictionaryHint(suggestion);
|
|
|
|
}
|
2010-02-07 00:34:43 +00:00
|
|
|
if (ic != null) {
|
|
|
|
ic.endBatchEdit();
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-08-20 05:35:02 +00:00
|
|
|
/**
|
|
|
|
* Commits the chosen word to the text field and saves it for later
|
|
|
|
* retrieval.
|
|
|
|
* @param suggestion the suggestion picked by the user to be committed to
|
|
|
|
* the text field
|
|
|
|
*/
|
2010-12-09 07:36:45 +00:00
|
|
|
private void pickSuggestion(CharSequence suggestion) {
|
2010-11-13 08:16:34 +00:00
|
|
|
KeyboardSwitcher switcher = mKeyboardSwitcher;
|
|
|
|
if (!switcher.isKeyboardAvailable())
|
2010-11-13 08:01:13 +00:00
|
|
|
return;
|
2009-03-13 22:11:42 +00:00
|
|
|
InputConnection ic = getCurrentInputConnection();
|
|
|
|
if (ic != null) {
|
2011-03-25 00:42:09 +00:00
|
|
|
mVoiceProxy.rememberReplacedWord(suggestion, mWordSeparators);
|
2010-08-20 05:35:02 +00:00
|
|
|
ic.commitText(suggestion, 1);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
saveWordInHistory(suggestion);
|
2010-12-19 08:32:26 +00:00
|
|
|
mHasValidSuggestions = false;
|
2009-03-13 22:11:42 +00:00
|
|
|
mCommittedLength = suggestion.length();
|
|
|
|
}
|
|
|
|
|
2010-08-26 19:22:58 +00:00
|
|
|
/**
|
|
|
|
* Tries to apply any typed alternatives for the word if we have any cached alternatives,
|
|
|
|
* otherwise tries to find new corrections and completions for the word.
|
|
|
|
* @param touching The word that the cursor is touching, with position information
|
|
|
|
* @return true if an alternative was found, false otherwise.
|
|
|
|
*/
|
2010-12-10 06:24:28 +00:00
|
|
|
private boolean applyTypedAlternatives(EditingUtils.SelectedWord touching) {
|
2010-08-26 19:22:58 +00:00
|
|
|
// If we didn't find a match, search for result in typed word history
|
|
|
|
WordComposer foundWord = null;
|
|
|
|
WordAlternatives alternatives = null;
|
2011-03-04 07:56:10 +00:00
|
|
|
// Search old suggestions to suggest re-corrected suggestions.
|
2010-08-26 19:22:58 +00:00
|
|
|
for (WordAlternatives entry : mWordHistory) {
|
2010-12-10 06:24:28 +00:00
|
|
|
if (TextUtils.equals(entry.getChosenWord(), touching.mWord)) {
|
2011-03-15 00:23:26 +00:00
|
|
|
foundWord = entry.mWordComposer;
|
2010-08-26 19:22:58 +00:00
|
|
|
alternatives = entry;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-03-04 07:56:10 +00:00
|
|
|
// If we didn't find a match, at least suggest corrections as re-corrected suggestions.
|
2010-08-26 19:22:58 +00:00
|
|
|
if (foundWord == null
|
2011-03-04 07:56:10 +00:00
|
|
|
&& (AutoCorrection.isValidWord(
|
|
|
|
mSuggest.getUnigramDictionaries(), touching.mWord, true))) {
|
2010-08-26 19:22:58 +00:00
|
|
|
foundWord = new WordComposer();
|
2010-12-10 06:24:28 +00:00
|
|
|
for (int i = 0; i < touching.mWord.length(); i++) {
|
|
|
|
foundWord.add(touching.mWord.charAt(i), new int[] {
|
|
|
|
touching.mWord.charAt(i)
|
2011-02-22 08:28:55 +00:00
|
|
|
}, WordComposer.NOT_A_COORDINATE, WordComposer.NOT_A_COORDINATE);
|
2010-08-26 19:22:58 +00:00
|
|
|
}
|
2010-12-10 06:24:28 +00:00
|
|
|
foundWord.setFirstCharCapitalized(Character.isUpperCase(touching.mWord.charAt(0)));
|
2010-08-26 19:22:58 +00:00
|
|
|
}
|
|
|
|
// Found a match, show suggestions
|
|
|
|
if (foundWord != null || alternatives != null) {
|
|
|
|
if (alternatives == null) {
|
2011-03-15 00:23:26 +00:00
|
|
|
alternatives = new WordAlternatives(touching.mWord, foundWord);
|
2010-08-26 19:22:58 +00:00
|
|
|
}
|
|
|
|
showCorrections(alternatives);
|
|
|
|
if (foundWord != null) {
|
|
|
|
mWord = new WordComposer(foundWord);
|
|
|
|
} else {
|
|
|
|
mWord.reset();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-08-20 05:35:02 +00:00
|
|
|
private void setOldSuggestions() {
|
2011-03-29 01:45:49 +00:00
|
|
|
if (!InputConnectionCompatUtils.RECORRECTION_SUPPORTED) return;
|
2011-03-25 00:42:09 +00:00
|
|
|
mVoiceProxy.setShowingVoiceSuggestions(false);
|
2010-08-26 19:22:58 +00:00
|
|
|
if (mCandidateView != null && mCandidateView.isShowingAddToDictionaryHint()) {
|
|
|
|
return;
|
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
InputConnection ic = getCurrentInputConnection();
|
|
|
|
if (ic == null) return;
|
2010-12-19 08:32:26 +00:00
|
|
|
if (!mHasValidSuggestions) {
|
2010-08-26 19:22:58 +00:00
|
|
|
// Extract the selected or touching text
|
2010-12-10 06:24:28 +00:00
|
|
|
EditingUtils.SelectedWord touching = EditingUtils.getWordAtCursorOrSelection(ic,
|
2010-08-26 19:22:58 +00:00
|
|
|
mLastSelectionStart, mLastSelectionEnd, mWordSeparators);
|
2010-08-20 05:35:02 +00:00
|
|
|
|
2010-12-10 06:24:28 +00:00
|
|
|
if (touching != null && touching.mWord.length() > 1) {
|
2010-08-26 19:22:58 +00:00
|
|
|
ic.beginBatchEdit();
|
2010-08-20 05:35:02 +00:00
|
|
|
|
2011-03-25 00:42:09 +00:00
|
|
|
if (!mVoiceProxy.applyVoiceAlternatives(touching)
|
2010-11-21 01:36:37 +00:00
|
|
|
&& !applyTypedAlternatives(touching)) {
|
2011-03-01 06:59:06 +00:00
|
|
|
abortRecorrection(true);
|
2010-08-26 19:22:58 +00:00
|
|
|
} else {
|
2011-03-01 06:59:06 +00:00
|
|
|
TextEntryState.selectedForRecorrection();
|
2011-03-29 01:45:49 +00:00
|
|
|
InputConnectionCompatUtils.underlineWord(ic, touching);
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|
2010-08-26 19:22:58 +00:00
|
|
|
|
|
|
|
ic.endBatchEdit();
|
2010-08-20 05:35:02 +00:00
|
|
|
} else {
|
2011-03-01 06:59:06 +00:00
|
|
|
abortRecorrection(true);
|
2010-11-11 04:37:18 +00:00
|
|
|
setPunctuationSuggestions(); // Show the punctuation suggestions list
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|
|
|
|
} else {
|
2011-03-01 06:59:06 +00:00
|
|
|
abortRecorrection(true);
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-20 02:50:05 +00:00
|
|
|
private static final WordComposer sEmptyWordComposer = new WordComposer();
|
2011-04-22 07:16:30 +00:00
|
|
|
private void updateBigramPredictions() {
|
2011-04-20 02:50:05 +00:00
|
|
|
if (mSuggest == null || !isSuggestionsRequested())
|
|
|
|
return;
|
|
|
|
|
2011-04-22 07:16:30 +00:00
|
|
|
if (!mBigramPredictionEnabled) {
|
|
|
|
setPunctuationSuggestions();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-04-20 02:50:05 +00:00
|
|
|
final CharSequence prevWord = EditingUtils.getThisWord(getCurrentInputConnection(),
|
|
|
|
mWordSeparators);
|
|
|
|
SuggestedWords.Builder builder = mSuggest.getSuggestedWordBuilder(
|
|
|
|
mKeyboardSwitcher.getInputView(), sEmptyWordComposer, prevWord);
|
|
|
|
|
|
|
|
if (builder.size() > 0) {
|
|
|
|
// Explicitly supply an empty typed word (the no-second-arg version of
|
|
|
|
// showSuggestions will retrieve the word near the cursor, we don't want that here)
|
|
|
|
showSuggestions(builder.build(), "");
|
|
|
|
} else {
|
|
|
|
if (!isShowingPunctuationList()) setPunctuationSuggestions();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-11 04:37:18 +00:00
|
|
|
private void setPunctuationSuggestions() {
|
2010-12-10 11:50:30 +00:00
|
|
|
setSuggestions(mSuggestPuncList);
|
2010-12-19 08:32:26 +00:00
|
|
|
setCandidatesViewShown(isCandidateStripVisible());
|
2010-02-03 23:35:49 +00:00
|
|
|
}
|
|
|
|
|
2011-03-04 07:56:10 +00:00
|
|
|
private void addToAutoAndUserBigramDictionaries(CharSequence suggestion, int frequencyDelta) {
|
2010-08-20 05:35:02 +00:00
|
|
|
checkAddToDictionary(suggestion, frequencyDelta, false);
|
|
|
|
}
|
|
|
|
|
2011-03-04 07:56:10 +00:00
|
|
|
private void addToOnlyBigramDictionary(CharSequence suggestion, int frequencyDelta) {
|
2010-08-20 05:35:02 +00:00
|
|
|
checkAddToDictionary(suggestion, frequencyDelta, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds to the UserBigramDictionary and/or AutoDictionary
|
2011-03-04 07:56:10 +00:00
|
|
|
* @param selectedANotTypedWord true if it should be added to bigram dictionary if possible
|
2010-08-20 05:35:02 +00:00
|
|
|
*/
|
|
|
|
private void checkAddToDictionary(CharSequence suggestion, int frequencyDelta,
|
2011-03-04 07:56:10 +00:00
|
|
|
boolean selectedANotTypedWord) {
|
2010-08-20 05:35:02 +00:00
|
|
|
if (suggestion == null || suggestion.length() < 1) return;
|
2011-03-04 07:56:10 +00:00
|
|
|
|
2010-03-24 23:44:31 +00:00
|
|
|
// Only auto-add to dictionary if auto-correct is ON. Otherwise we'll be
|
|
|
|
// adding words in situations where the user or application really didn't
|
|
|
|
// want corrections enabled or learned.
|
2010-08-20 05:35:02 +00:00
|
|
|
if (!(mCorrectionMode == Suggest.CORRECTION_FULL
|
|
|
|
|| mCorrectionMode == Suggest.CORRECTION_FULL_BIGRAM)) {
|
|
|
|
return;
|
|
|
|
}
|
2011-03-04 07:56:10 +00:00
|
|
|
|
|
|
|
final boolean selectedATypedWordAndItsInAutoDic =
|
|
|
|
!selectedANotTypedWord && mAutoDictionary.isValidWord(suggestion);
|
|
|
|
final boolean isValidWord = AutoCorrection.isValidWord(
|
|
|
|
mSuggest.getUnigramDictionaries(), suggestion, true);
|
|
|
|
final boolean needsToAddToAutoDictionary = selectedATypedWordAndItsInAutoDic
|
|
|
|
|| !isValidWord;
|
|
|
|
if (needsToAddToAutoDictionary) {
|
2010-12-10 06:24:28 +00:00
|
|
|
mAutoDictionary.addWord(suggestion.toString(), frequencyDelta);
|
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
|
2010-12-10 06:24:28 +00:00
|
|
|
if (mUserBigramDictionary != null) {
|
|
|
|
CharSequence prevWord = EditingUtils.getPreviousWord(getCurrentInputConnection(),
|
|
|
|
mSentenceSeparators);
|
|
|
|
if (!TextUtils.isEmpty(prevWord)) {
|
|
|
|
mUserBigramDictionary.addBigrams(prevWord.toString(), suggestion.toString());
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|
2010-02-20 00:38:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
private boolean isCursorTouchingWord() {
|
|
|
|
InputConnection ic = getCurrentInputConnection();
|
|
|
|
if (ic == null) return false;
|
|
|
|
CharSequence toLeft = ic.getTextBeforeCursor(1, 0);
|
|
|
|
CharSequence toRight = ic.getTextAfterCursor(1, 0);
|
|
|
|
if (!TextUtils.isEmpty(toLeft)
|
2010-10-05 13:51:59 +00:00
|
|
|
&& !isWordSeparator(toLeft.charAt(0))
|
|
|
|
&& !isSuggestedPunctuation(toLeft.charAt(0))) {
|
2009-03-13 22:11:42 +00:00
|
|
|
return true;
|
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
if (!TextUtils.isEmpty(toRight)
|
2010-10-05 13:51:59 +00:00
|
|
|
&& !isWordSeparator(toRight.charAt(0))
|
|
|
|
&& !isSuggestedPunctuation(toRight.charAt(0))) {
|
2009-03-13 22:11:42 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-04-01 13:28:52 +00:00
|
|
|
private boolean sameAsTextBeforeCursor(InputConnection ic, CharSequence text) {
|
|
|
|
CharSequence beforeText = ic.getTextBeforeCursor(text.length(), 0);
|
|
|
|
return TextUtils.equals(text, beforeText);
|
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
public void revertLastWord(boolean deleteChar) {
|
|
|
|
final int length = mComposing.length();
|
2010-12-19 08:32:26 +00:00
|
|
|
if (!mHasValidSuggestions && length > 0) {
|
2009-03-13 22:11:42 +00:00
|
|
|
final InputConnection ic = getCurrentInputConnection();
|
2011-01-13 08:14:27 +00:00
|
|
|
final CharSequence punctuation = ic.getTextBeforeCursor(1, 0);
|
2009-03-13 22:11:42 +00:00
|
|
|
if (deleteChar) ic.deleteSurroundingText(1, 0);
|
|
|
|
int toDelete = mCommittedLength;
|
2011-01-13 08:14:27 +00:00
|
|
|
final CharSequence toTheLeft = ic.getTextBeforeCursor(mCommittedLength, 0);
|
|
|
|
if (!TextUtils.isEmpty(toTheLeft) && isWordSeparator(toTheLeft.charAt(0))) {
|
2009-03-13 22:11:42 +00:00
|
|
|
toDelete--;
|
|
|
|
}
|
|
|
|
ic.deleteSurroundingText(toDelete, 0);
|
2011-01-18 06:48:29 +00:00
|
|
|
// Re-insert punctuation only when the deleted character was word separator and the
|
|
|
|
// composing text wasn't equal to the auto-corrected text.
|
|
|
|
if (deleteChar
|
|
|
|
&& !TextUtils.isEmpty(punctuation) && isWordSeparator(punctuation.charAt(0))
|
|
|
|
&& !TextUtils.equals(mComposing, toTheLeft)) {
|
2011-01-13 08:14:27 +00:00
|
|
|
ic.commitText(mComposing, 1);
|
|
|
|
TextEntryState.acceptedTyped(mComposing);
|
2011-01-18 06:48:29 +00:00
|
|
|
ic.commitText(punctuation, 1);
|
2011-04-06 02:14:20 +00:00
|
|
|
TextEntryState.typedCharacter(punctuation.charAt(0), true,
|
|
|
|
WordComposer.NOT_A_COORDINATE, WordComposer.NOT_A_COORDINATE);
|
2011-01-18 06:48:29 +00:00
|
|
|
// Clear composing text
|
|
|
|
mComposing.setLength(0);
|
2011-01-13 08:14:27 +00:00
|
|
|
} else {
|
2011-01-18 06:48:29 +00:00
|
|
|
mHasValidSuggestions = true;
|
2011-01-13 08:14:27 +00:00
|
|
|
ic.setComposingText(mComposing, 1);
|
|
|
|
TextEntryState.backspace();
|
|
|
|
}
|
2011-04-22 07:16:30 +00:00
|
|
|
mHandler.cancelUpdateBigramPredictions();
|
2010-11-16 09:07:06 +00:00
|
|
|
mHandler.postUpdateSuggestions();
|
2009-03-13 22:11:42 +00:00
|
|
|
} else {
|
|
|
|
sendDownUpKeyEvents(KeyEvent.KEYCODE_DEL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected String getWordSeparators() {
|
|
|
|
return mWordSeparators;
|
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
public boolean isWordSeparator(int code) {
|
|
|
|
String separators = getWordSeparators();
|
|
|
|
return separators.contains(String.valueOf((char)code));
|
|
|
|
}
|
|
|
|
|
2010-08-20 05:35:02 +00:00
|
|
|
private boolean isSentenceSeparator(int code) {
|
2009-03-13 22:11:42 +00:00
|
|
|
return mSentenceSeparators.contains(String.valueOf((char)code));
|
|
|
|
}
|
|
|
|
|
|
|
|
private void sendSpace() {
|
2010-12-02 11:54:32 +00:00
|
|
|
sendKeyChar((char)Keyboard.CODE_SPACE);
|
2010-11-13 08:16:34 +00:00
|
|
|
mKeyboardSwitcher.updateShiftState();
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean preferCapitalization() {
|
2010-09-27 15:32:35 +00:00
|
|
|
return mWord.isFirstCharCapitalized();
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2011-04-08 10:57:13 +00:00
|
|
|
// Notify that language or mode have been changed and toggleLanguage will update KeyboardID
|
2011-01-18 06:28:21 +00:00
|
|
|
// according to new language or mode.
|
|
|
|
public void onRefreshKeyboard() {
|
2010-11-18 00:55:23 +00:00
|
|
|
// Reload keyboard because the current language has been changed.
|
2011-02-20 13:04:50 +00:00
|
|
|
mKeyboardSwitcher.loadKeyboard(getCurrentInputEditorInfo(),
|
2011-03-25 00:42:09 +00:00
|
|
|
mSubtypeSwitcher.isShortcutImeEnabled() && mVoiceProxy.isVoiceButtonEnabled(),
|
|
|
|
mVoiceProxy.isVoiceButtonOnPrimary());
|
2010-11-17 07:35:35 +00:00
|
|
|
initSuggest();
|
2011-02-20 03:54:14 +00:00
|
|
|
mKeyboardSwitcher.updateShiftState();
|
2009-10-12 20:48:35 +00:00
|
|
|
}
|
|
|
|
|
2011-04-08 10:57:13 +00:00
|
|
|
// "reset" and "next" are used only for USE_SPACEBAR_LANGUAGE_SWITCHER.
|
|
|
|
private void toggleLanguage(boolean next) {
|
|
|
|
if (mSubtypeSwitcher.useSpacebarLanguageSwitcher()) {
|
|
|
|
mSubtypeSwitcher.toggleLanguage(next);
|
|
|
|
}
|
|
|
|
onRefreshKeyboard();// no need??
|
|
|
|
}
|
|
|
|
|
2010-12-02 09:46:21 +00:00
|
|
|
@Override
|
2010-12-20 07:13:57 +00:00
|
|
|
public void onSwipeDown() {
|
2010-12-23 03:24:27 +00:00
|
|
|
if (mConfigSwipeDownDismissKeyboardEnabled)
|
|
|
|
handleClose();
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2010-12-02 09:46:21 +00:00
|
|
|
@Override
|
2011-03-02 19:43:13 +00:00
|
|
|
public void onPress(int primaryCode, boolean withSliding) {
|
2010-12-20 07:21:54 +00:00
|
|
|
if (mKeyboardSwitcher.isVibrateAndSoundFeedbackRequired()) {
|
|
|
|
vibrate();
|
|
|
|
playKeyClick(primaryCode);
|
|
|
|
}
|
2010-11-13 08:01:13 +00:00
|
|
|
KeyboardSwitcher switcher = mKeyboardSwitcher;
|
|
|
|
final boolean distinctMultiTouch = switcher.hasDistinctMultitouch();
|
2010-12-02 11:54:32 +00:00
|
|
|
if (distinctMultiTouch && primaryCode == Keyboard.CODE_SHIFT) {
|
2011-03-02 19:43:13 +00:00
|
|
|
switcher.onPressShift(withSliding);
|
2010-12-06 03:12:27 +00:00
|
|
|
} else if (distinctMultiTouch && primaryCode == Keyboard.CODE_SWITCH_ALPHA_SYMBOL) {
|
2010-11-16 08:28:50 +00:00
|
|
|
switcher.onPressSymbol();
|
2010-09-01 16:35:24 +00:00
|
|
|
} else {
|
2010-11-16 08:28:50 +00:00
|
|
|
switcher.onOtherKeyPressed();
|
2010-09-01 07:36:24 +00:00
|
|
|
}
|
2011-01-14 18:49:21 +00:00
|
|
|
mAccessibilityUtils.onPress(primaryCode, switcher);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2010-12-02 09:46:21 +00:00
|
|
|
@Override
|
2011-03-02 19:43:13 +00:00
|
|
|
public void onRelease(int primaryCode, boolean withSliding) {
|
2010-11-13 08:01:13 +00:00
|
|
|
KeyboardSwitcher switcher = mKeyboardSwitcher;
|
2010-01-30 04:09:49 +00:00
|
|
|
// Reset any drag flags in the keyboard
|
2010-11-13 08:01:13 +00:00
|
|
|
final boolean distinctMultiTouch = switcher.hasDistinctMultitouch();
|
2010-12-02 11:54:32 +00:00
|
|
|
if (distinctMultiTouch && primaryCode == Keyboard.CODE_SHIFT) {
|
2011-03-02 19:43:13 +00:00
|
|
|
switcher.onReleaseShift(withSliding);
|
2010-12-06 03:12:27 +00:00
|
|
|
} else if (distinctMultiTouch && primaryCode == Keyboard.CODE_SWITCH_ALPHA_SYMBOL) {
|
2010-11-16 08:28:50 +00:00
|
|
|
switcher.onReleaseSymbol();
|
2010-09-01 16:35:24 +00:00
|
|
|
}
|
2011-01-14 18:49:21 +00:00
|
|
|
mAccessibilityUtils.onRelease(primaryCode, switcher);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
|
|
|
|
2011-01-26 14:13:18 +00:00
|
|
|
// receive ringer mode change and network state change.
|
2009-03-13 22:11:42 +00:00
|
|
|
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
2011-01-26 14:13:18 +00:00
|
|
|
final String action = intent.getAction();
|
|
|
|
if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) {
|
|
|
|
updateRingerMode();
|
|
|
|
} else if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
|
|
|
|
mSubtypeSwitcher.onNetworkStateChanged(intent);
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// update flags for silent mode
|
|
|
|
private void updateRingerMode() {
|
|
|
|
if (mAudioManager == null) {
|
|
|
|
mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
|
|
|
|
}
|
|
|
|
if (mAudioManager != null) {
|
|
|
|
mSilentMode = (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) {
|
2010-08-20 05:35:02 +00:00
|
|
|
if (mKeyboardSwitcher.getInputView() != null) {
|
2009-03-13 22:11:42 +00:00
|
|
|
updateRingerMode();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mSoundOn && !mSilentMode) {
|
|
|
|
// FIXME: Volume and enable should come from UI settings
|
|
|
|
// FIXME: These should be triggered after auto-repeat logic
|
|
|
|
int sound = AudioManager.FX_KEYPRESS_STANDARD;
|
|
|
|
switch (primaryCode) {
|
2010-12-02 11:54:32 +00:00
|
|
|
case Keyboard.CODE_DELETE:
|
2009-03-13 22:11:42 +00:00
|
|
|
sound = AudioManager.FX_KEYPRESS_DELETE;
|
|
|
|
break;
|
2010-12-02 11:54:32 +00:00
|
|
|
case Keyboard.CODE_ENTER:
|
2009-03-13 22:11:42 +00:00
|
|
|
sound = AudioManager.FX_KEYPRESS_RETURN;
|
|
|
|
break;
|
2010-12-02 11:54:32 +00:00
|
|
|
case Keyboard.CODE_SPACE:
|
2009-03-13 22:11:42 +00:00
|
|
|
sound = AudioManager.FX_KEYPRESS_SPACEBAR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
mAudioManager.playSoundEffect(sound, FX_VOLUME);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-21 01:36:37 +00:00
|
|
|
public void vibrate() {
|
2009-03-13 22:11:42 +00:00
|
|
|
if (!mVibrateOn) {
|
|
|
|
return;
|
|
|
|
}
|
2010-11-13 08:01:13 +00:00
|
|
|
LatinKeyboardView inputView = mKeyboardSwitcher.getInputView();
|
|
|
|
if (inputView != null) {
|
|
|
|
inputView.performHapticFeedback(
|
2010-08-20 05:35:02 +00:00
|
|
|
HapticFeedbackConstants.KEYBOARD_TAP,
|
2010-02-11 01:45:35 +00:00
|
|
|
HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-13 08:46:45 +00:00
|
|
|
public void promoteToUserDictionary(String word, int frequency) {
|
2009-07-17 19:51:45 +00:00
|
|
|
if (mUserDictionary.isValidWord(word)) return;
|
|
|
|
mUserDictionary.addWord(word, frequency);
|
|
|
|
}
|
|
|
|
|
2010-11-13 08:46:45 +00:00
|
|
|
public WordComposer getCurrentWord() {
|
2010-02-24 03:01:43 +00:00
|
|
|
return mWord;
|
|
|
|
}
|
|
|
|
|
2010-11-13 08:46:45 +00:00
|
|
|
public boolean getPopupOn() {
|
2010-08-20 05:35:02 +00:00
|
|
|
return mPopupOn;
|
|
|
|
}
|
|
|
|
|
2009-12-18 21:39:18 +00:00
|
|
|
private void updateCorrectionMode() {
|
2011-03-02 06:40:08 +00:00
|
|
|
// TODO: cleanup messy flags
|
2009-12-18 21:39:18 +00:00
|
|
|
mHasDictionary = mSuggest != null ? mSuggest.hasMainDictionary() : false;
|
|
|
|
mAutoCorrectOn = (mAutoCorrectEnabled || mQuickFixes)
|
|
|
|
&& !mInputTypeNoAutoCorrect && mHasDictionary;
|
2010-02-20 00:38:58 +00:00
|
|
|
mCorrectionMode = (mAutoCorrectOn && mAutoCorrectEnabled)
|
2009-12-18 21:39:18 +00:00
|
|
|
? Suggest.CORRECTION_FULL
|
2010-02-20 00:38:58 +00:00
|
|
|
: (mAutoCorrectOn ? Suggest.CORRECTION_BASIC : Suggest.CORRECTION_NONE);
|
2010-08-20 05:35:02 +00:00
|
|
|
mCorrectionMode = (mBigramSuggestionEnabled && mAutoCorrectOn && mAutoCorrectEnabled)
|
|
|
|
? Suggest.CORRECTION_FULL_BIGRAM : mCorrectionMode;
|
2009-12-18 21:39:18 +00:00
|
|
|
if (mSuggest != null) {
|
|
|
|
mSuggest.setCorrectionMode(mCorrectionMode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-17 07:35:35 +00:00
|
|
|
private void updateAutoTextEnabled() {
|
2010-02-20 00:38:58 +00:00
|
|
|
if (mSuggest == null) return;
|
2011-02-07 11:40:34 +00:00
|
|
|
mSuggest.setQuickFixesEnabled(mQuickFixes
|
2010-11-18 00:55:23 +00:00
|
|
|
&& SubtypeSwitcher.getInstance().isSystemLanguageSameAsInputLanguage());
|
2010-02-20 00:38:58 +00:00
|
|
|
}
|
|
|
|
|
2010-11-13 10:09:30 +00:00
|
|
|
private void updateSuggestionVisibility(SharedPreferences prefs) {
|
2011-01-04 15:39:41 +00:00
|
|
|
final Resources res = mResources;
|
2010-11-13 10:09:30 +00:00
|
|
|
final String suggestionVisiblityStr = prefs.getString(
|
2010-12-09 12:06:26 +00:00
|
|
|
Settings.PREF_SHOW_SUGGESTIONS_SETTING,
|
2011-01-04 15:39:41 +00:00
|
|
|
res.getString(R.string.prefs_suggestion_visibility_default_value));
|
2010-11-13 10:09:30 +00:00
|
|
|
for (int visibility : SUGGESTION_VISIBILITY_VALUE_ARRAY) {
|
2011-01-04 15:39:41 +00:00
|
|
|
if (suggestionVisiblityStr.equals(res.getString(visibility))) {
|
2010-11-13 10:09:30 +00:00
|
|
|
mSuggestionVisibility = visibility;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
protected void launchSettings() {
|
2010-12-09 12:06:26 +00:00
|
|
|
launchSettings(Settings.class);
|
2010-01-16 20:21:23 +00:00
|
|
|
}
|
|
|
|
|
2010-09-27 03:55:21 +00:00
|
|
|
public void launchDebugSettings() {
|
2010-12-09 12:06:26 +00:00
|
|
|
launchSettings(DebugSettings.class);
|
2010-09-27 03:55:21 +00:00
|
|
|
}
|
|
|
|
|
2010-11-11 00:10:10 +00:00
|
|
|
protected void launchSettings(Class<? extends PreferenceActivity> settingsClass) {
|
2009-03-13 22:11:42 +00:00
|
|
|
handleClose();
|
|
|
|
Intent intent = new Intent();
|
2010-01-16 20:21:23 +00:00
|
|
|
intent.setClass(LatinIME.this, settingsClass);
|
2009-03-13 22:11:42 +00:00
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
startActivity(intent);
|
|
|
|
}
|
|
|
|
|
2010-11-11 00:10:10 +00:00
|
|
|
private void loadSettings(EditorInfo attribute) {
|
2009-03-13 22:11:42 +00:00
|
|
|
// Get the settings preferences
|
2010-11-26 04:08:36 +00:00
|
|
|
final SharedPreferences prefs = mPrefs;
|
2011-03-23 21:36:37 +00:00
|
|
|
final boolean hasVibrator = VibratorCompatWrapper.getInstance(this).hasVibrator();
|
|
|
|
mVibrateOn = hasVibrator && prefs.getBoolean(Settings.PREF_VIBRATE_ON, false);
|
2011-02-08 02:13:06 +00:00
|
|
|
mSoundOn = prefs.getBoolean(Settings.PREF_SOUND_ON,
|
|
|
|
mResources.getBoolean(R.bool.config_default_sound_enabled));
|
2011-01-31 06:31:20 +00:00
|
|
|
|
|
|
|
mPopupOn = isPopupEnabled(prefs);
|
2010-12-09 12:06:26 +00:00
|
|
|
mAutoCap = prefs.getBoolean(Settings.PREF_AUTO_CAP, true);
|
2011-01-19 08:44:39 +00:00
|
|
|
mQuickFixes = isQuickFixesEnabled(prefs);
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-11-26 04:08:36 +00:00
|
|
|
mAutoCorrectEnabled = isAutoCorrectEnabled(prefs);
|
|
|
|
mBigramSuggestionEnabled = mAutoCorrectEnabled && isBigramSuggestionEnabled(prefs);
|
2011-04-22 04:08:35 +00:00
|
|
|
mBigramPredictionEnabled = mBigramSuggestionEnabled && isBigramPredictionEnabled(prefs);
|
2010-12-11 08:06:24 +00:00
|
|
|
loadAndSetAutoCorrectionThreshold(prefs);
|
2010-01-16 20:21:23 +00:00
|
|
|
|
2011-03-25 00:42:09 +00:00
|
|
|
mVoiceProxy.loadSettings(attribute, prefs);
|
2010-11-21 01:36:37 +00:00
|
|
|
|
2009-12-18 21:39:18 +00:00
|
|
|
updateCorrectionMode();
|
2010-11-17 07:35:35 +00:00
|
|
|
updateAutoTextEnabled();
|
2010-11-26 04:08:36 +00:00
|
|
|
updateSuggestionVisibility(prefs);
|
2011-04-08 10:57:13 +00:00
|
|
|
|
|
|
|
// This will work only when the subtype is not supported.
|
|
|
|
LanguageSwitcherProxy.loadSettings();
|
2009-10-12 20:48:35 +00:00
|
|
|
}
|
|
|
|
|
2010-09-28 03:23:26 +00:00
|
|
|
/**
|
2010-12-11 08:06:24 +00:00
|
|
|
* Load Auto correction threshold from SharedPreferences, and modify mSuggest's threshold.
|
2010-09-28 03:23:26 +00:00
|
|
|
*/
|
2010-12-11 08:06:24 +00:00
|
|
|
private void loadAndSetAutoCorrectionThreshold(SharedPreferences sp) {
|
2010-09-28 03:23:26 +00:00
|
|
|
// When mSuggest is not initialized, cannnot modify mSuggest's threshold.
|
|
|
|
if (mSuggest == null) return;
|
2010-12-11 08:06:24 +00:00
|
|
|
// When auto correction setting is turned off, the threshold is ignored.
|
2010-09-28 03:23:26 +00:00
|
|
|
if (!isAutoCorrectEnabled(sp)) return;
|
|
|
|
|
2010-12-11 08:06:24 +00:00
|
|
|
final String currentAutoCorrectionSetting = sp.getString(
|
|
|
|
Settings.PREF_AUTO_CORRECTION_THRESHOLD,
|
2010-12-13 03:37:23 +00:00
|
|
|
mResources.getString(R.string.auto_correction_threshold_mode_index_modest));
|
2010-12-11 08:06:24 +00:00
|
|
|
final String[] autoCorrectionThresholdValues = mResources.getStringArray(
|
2010-12-13 03:37:23 +00:00
|
|
|
R.array.auto_correction_threshold_values);
|
2010-12-11 08:06:24 +00:00
|
|
|
// When autoCrrectionThreshold is greater than 1.0, auto correction is virtually turned off.
|
|
|
|
double autoCorrectionThreshold = Double.MAX_VALUE;
|
2010-09-28 03:23:26 +00:00
|
|
|
try {
|
2010-12-11 08:06:24 +00:00
|
|
|
final int arrayIndex = Integer.valueOf(currentAutoCorrectionSetting);
|
|
|
|
if (arrayIndex >= 0 && arrayIndex < autoCorrectionThresholdValues.length) {
|
|
|
|
autoCorrectionThreshold = Double.parseDouble(
|
|
|
|
autoCorrectionThresholdValues[arrayIndex]);
|
2010-09-28 03:23:26 +00:00
|
|
|
}
|
|
|
|
} catch (NumberFormatException e) {
|
2010-12-11 08:06:24 +00:00
|
|
|
// Whenever the threshold settings are correct, never come here.
|
|
|
|
autoCorrectionThreshold = Double.MAX_VALUE;
|
|
|
|
Log.w(TAG, "Cannot load auto correction threshold setting."
|
|
|
|
+ " currentAutoCorrectionSetting: " + currentAutoCorrectionSetting
|
|
|
|
+ ", autoCorrectionThresholdValues: "
|
|
|
|
+ Arrays.toString(autoCorrectionThresholdValues));
|
2010-09-28 03:23:26 +00:00
|
|
|
}
|
|
|
|
// TODO: This should be refactored :
|
2010-12-11 08:06:24 +00:00
|
|
|
// setAutoCorrectionThreshold should be called outside of this method.
|
|
|
|
mSuggest.setAutoCorrectionThreshold(autoCorrectionThreshold);
|
2010-09-28 03:23:26 +00:00
|
|
|
}
|
|
|
|
|
2011-01-31 06:31:20 +00:00
|
|
|
private boolean isPopupEnabled(SharedPreferences sp) {
|
|
|
|
final boolean showPopupOption = getResources().getBoolean(
|
|
|
|
R.bool.config_enable_show_popup_on_keypress_option);
|
|
|
|
if (!showPopupOption) return mResources.getBoolean(R.bool.config_default_popup_preview);
|
|
|
|
return sp.getBoolean(Settings.PREF_POPUP_ON,
|
|
|
|
mResources.getBoolean(R.bool.config_default_popup_preview));
|
|
|
|
}
|
|
|
|
|
2011-01-19 08:44:39 +00:00
|
|
|
private boolean isQuickFixesEnabled(SharedPreferences sp) {
|
|
|
|
final boolean showQuickFixesOption = mResources.getBoolean(
|
|
|
|
R.bool.config_enable_quick_fixes_option);
|
|
|
|
if (!showQuickFixesOption) {
|
|
|
|
return isAutoCorrectEnabled(sp);
|
|
|
|
}
|
|
|
|
return sp.getBoolean(Settings.PREF_QUICK_FIXES, mResources.getBoolean(
|
|
|
|
R.bool.config_default_quick_fixes));
|
|
|
|
}
|
|
|
|
|
2010-09-28 03:23:26 +00:00
|
|
|
private boolean isAutoCorrectEnabled(SharedPreferences sp) {
|
2010-12-11 08:06:24 +00:00
|
|
|
final String currentAutoCorrectionSetting = sp.getString(
|
|
|
|
Settings.PREF_AUTO_CORRECTION_THRESHOLD,
|
2010-12-13 03:37:23 +00:00
|
|
|
mResources.getString(R.string.auto_correction_threshold_mode_index_modest));
|
2010-12-11 08:06:24 +00:00
|
|
|
final String autoCorrectionOff = mResources.getString(
|
2010-12-13 03:37:23 +00:00
|
|
|
R.string.auto_correction_threshold_mode_index_off);
|
2010-12-11 08:06:24 +00:00
|
|
|
return !currentAutoCorrectionSetting.equals(autoCorrectionOff);
|
2010-09-28 03:23:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private boolean isBigramSuggestionEnabled(SharedPreferences sp) {
|
2011-01-19 08:44:39 +00:00
|
|
|
final boolean showBigramSuggestionsOption = mResources.getBoolean(
|
|
|
|
R.bool.config_enable_bigram_suggestions_option);
|
|
|
|
if (!showBigramSuggestionsOption) {
|
|
|
|
return isAutoCorrectEnabled(sp);
|
|
|
|
}
|
|
|
|
return sp.getBoolean(Settings.PREF_BIGRAM_SUGGESTIONS, mResources.getBoolean(
|
|
|
|
R.bool.config_default_bigram_suggestions));
|
2010-09-28 03:23:26 +00:00
|
|
|
}
|
|
|
|
|
2011-04-22 04:08:35 +00:00
|
|
|
private boolean isBigramPredictionEnabled(SharedPreferences sp) {
|
|
|
|
return sp.getBoolean(Settings.PREF_BIGRAM_PREDICTIONS, mResources.getBoolean(
|
|
|
|
R.bool.config_default_bigram_prediction));
|
|
|
|
}
|
|
|
|
|
2010-02-03 23:35:49 +00:00
|
|
|
private void initSuggestPuncList() {
|
2010-12-10 11:50:30 +00:00
|
|
|
if (mSuggestPuncs != null || mSuggestPuncList != null)
|
|
|
|
return;
|
|
|
|
SuggestedWords.Builder builder = new SuggestedWords.Builder();
|
|
|
|
String puncs = mResources.getString(R.string.suggested_punctuations);
|
|
|
|
if (puncs != null) {
|
|
|
|
for (int i = 0; i < puncs.length(); i++) {
|
|
|
|
builder.addWord(puncs.subSequence(i, i + 1));
|
2010-02-03 23:35:49 +00:00
|
|
|
}
|
|
|
|
}
|
2010-12-10 11:50:30 +00:00
|
|
|
mSuggestPuncList = builder.build();
|
|
|
|
mSuggestPuncs = puncs;
|
2010-02-03 23:35:49 +00:00
|
|
|
}
|
|
|
|
|
2010-08-20 05:35:02 +00:00
|
|
|
private boolean isSuggestedPunctuation(int code) {
|
|
|
|
return mSuggestPuncs.contains(String.valueOf((char)code));
|
|
|
|
}
|
|
|
|
|
2011-01-20 13:52:02 +00:00
|
|
|
private void showSubtypeSelectorAndSettings() {
|
2011-01-25 02:48:06 +00:00
|
|
|
final CharSequence title = getString(R.string.english_ime_input_options);
|
|
|
|
final CharSequence[] items = new CharSequence[] {
|
|
|
|
// TODO: Should use new string "Select active input modes".
|
|
|
|
getString(R.string.language_selection_title),
|
|
|
|
getString(R.string.english_ime_settings),
|
|
|
|
};
|
|
|
|
final DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
|
2011-01-20 13:52:02 +00:00
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface di, int position) {
|
|
|
|
di.dismiss();
|
|
|
|
switch (position) {
|
2011-01-25 02:48:06 +00:00
|
|
|
case 0:
|
2011-03-17 02:37:51 +00:00
|
|
|
Intent intent = CompatUtils.getInputLanguageSelectionIntent(
|
|
|
|
mInputMethodId, Intent.FLAG_ACTIVITY_NEW_TASK
|
2011-01-20 13:52:02 +00:00
|
|
|
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
|
|
|
|
| Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
|
|
startActivity(intent);
|
|
|
|
break;
|
2011-01-25 17:56:09 +00:00
|
|
|
case 1:
|
|
|
|
launchSettings();
|
|
|
|
break;
|
2011-01-20 13:52:02 +00:00
|
|
|
}
|
|
|
|
}
|
2011-01-25 02:48:06 +00:00
|
|
|
};
|
|
|
|
showOptionsMenuInternal(title, items, listener);
|
2011-01-20 13:52:02 +00:00
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
|
2011-01-20 13:52:02 +00:00
|
|
|
private void showOptionsMenu() {
|
2011-01-25 02:48:06 +00:00
|
|
|
final CharSequence title = getString(R.string.english_ime_input_options);
|
|
|
|
final CharSequence[] items = new CharSequence[] {
|
|
|
|
getString(R.string.selectInputMethod),
|
|
|
|
getString(R.string.english_ime_settings),
|
|
|
|
};
|
|
|
|
final DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
|
2010-12-02 09:46:21 +00:00
|
|
|
@Override
|
2009-03-13 22:11:42 +00:00
|
|
|
public void onClick(DialogInterface di, int position) {
|
|
|
|
di.dismiss();
|
|
|
|
switch (position) {
|
2011-01-25 02:48:06 +00:00
|
|
|
case 0:
|
2011-02-03 06:56:01 +00:00
|
|
|
mImm.showInputMethodPicker();
|
2011-01-20 13:52:02 +00:00
|
|
|
break;
|
2011-01-25 02:48:06 +00:00
|
|
|
case 1:
|
2011-02-03 06:56:01 +00:00
|
|
|
launchSettings();
|
2011-01-20 13:52:02 +00:00
|
|
|
break;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
}
|
2011-01-25 02:48:06 +00:00
|
|
|
};
|
|
|
|
showOptionsMenuInternal(title, items, listener);
|
2011-01-20 13:52:02 +00:00
|
|
|
}
|
|
|
|
|
2011-01-25 02:48:06 +00:00
|
|
|
private void showOptionsMenuInternal(CharSequence title, CharSequence[] items,
|
|
|
|
DialogInterface.OnClickListener listener) {
|
2011-03-01 22:20:27 +00:00
|
|
|
final IBinder windowToken = mKeyboardSwitcher.getInputView().getWindowToken();
|
|
|
|
if (windowToken == null) return;
|
2011-01-20 13:52:02 +00:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
|
builder.setCancelable(true);
|
|
|
|
builder.setIcon(R.drawable.ic_dialog_keyboard);
|
|
|
|
builder.setNegativeButton(android.R.string.cancel, null);
|
2011-01-25 02:48:06 +00:00
|
|
|
builder.setItems(items, listener);
|
|
|
|
builder.setTitle(title);
|
2009-03-13 22:11:42 +00:00
|
|
|
mOptionsDialog = builder.create();
|
2011-01-21 05:07:05 +00:00
|
|
|
mOptionsDialog.setCanceledOnTouchOutside(true);
|
2009-03-13 22:11:42 +00:00
|
|
|
Window window = mOptionsDialog.getWindow();
|
|
|
|
WindowManager.LayoutParams lp = window.getAttributes();
|
2011-03-01 22:20:27 +00:00
|
|
|
lp.token = windowToken;
|
2009-03-13 22:11:42 +00:00
|
|
|
lp.type = WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
|
|
|
|
window.setAttributes(lp);
|
|
|
|
window.addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
|
|
|
|
mOptionsDialog.show();
|
|
|
|
}
|
|
|
|
|
2010-10-08 13:17:16 +00:00
|
|
|
@Override
|
|
|
|
protected void dump(FileDescriptor fd, PrintWriter fout, String[] args) {
|
2009-03-13 22:11:42 +00:00
|
|
|
super.dump(fd, fout, args);
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
final Printer p = new PrintWriterPrinter(fout);
|
|
|
|
p.println("LatinIME state :");
|
|
|
|
p.println(" Keyboard mode = " + mKeyboardSwitcher.getKeyboardMode());
|
|
|
|
p.println(" mComposing=" + mComposing.toString());
|
2010-12-19 08:32:26 +00:00
|
|
|
p.println(" mIsSuggestionsRequested=" + mIsSettingsSuggestionStripOn);
|
2009-03-13 22:11:42 +00:00
|
|
|
p.println(" mCorrectionMode=" + mCorrectionMode);
|
2010-12-19 08:32:26 +00:00
|
|
|
p.println(" mHasValidSuggestions=" + mHasValidSuggestions);
|
2009-03-13 22:11:42 +00:00
|
|
|
p.println(" mAutoCorrectOn=" + mAutoCorrectOn);
|
|
|
|
p.println(" mAutoSpace=" + mAutoSpace);
|
2010-12-11 08:06:24 +00:00
|
|
|
p.println(" mApplicationSpecifiedCompletionOn=" + mApplicationSpecifiedCompletionOn);
|
2009-03-13 22:11:42 +00:00
|
|
|
p.println(" TextEntryState.state=" + TextEntryState.getState());
|
|
|
|
p.println(" mSoundOn=" + mSoundOn);
|
|
|
|
p.println(" mVibrateOn=" + mVibrateOn);
|
2010-08-20 05:35:02 +00:00
|
|
|
p.println(" mPopupOn=" + mPopupOn);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2009-03-26 00:39:38 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
// Characters per second measurement
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
private long mLastCpsTime;
|
|
|
|
private static final int CPS_BUFFER_SIZE = 16;
|
|
|
|
private long[] mCpsIntervals = new long[CPS_BUFFER_SIZE];
|
|
|
|
private int mCpsIndex;
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
private void measureCps() {
|
|
|
|
long now = System.currentTimeMillis();
|
|
|
|
if (mLastCpsTime == 0) mLastCpsTime = now - 100; // Initial
|
|
|
|
mCpsIntervals[mCpsIndex] = now - mLastCpsTime;
|
|
|
|
mLastCpsTime = now;
|
|
|
|
mCpsIndex = (mCpsIndex + 1) % CPS_BUFFER_SIZE;
|
|
|
|
long total = 0;
|
|
|
|
for (int i = 0; i < CPS_BUFFER_SIZE; i++) total += mCpsIntervals[i];
|
|
|
|
System.out.println("CPS = " + ((CPS_BUFFER_SIZE * 1000f) / total));
|
|
|
|
}
|
|
|
|
}
|