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;
|
|
|
|
|
2010-02-09 10:29:10 +00:00
|
|
|
import com.android.inputmethod.voice.FieldContext;
|
|
|
|
import com.android.inputmethod.voice.SettingsUtil;
|
|
|
|
import com.android.inputmethod.voice.VoiceInput;
|
2010-01-15 21:43:50 +00:00
|
|
|
|
2010-08-20 05:35:02 +00:00
|
|
|
import org.xmlpull.v1.XmlPullParserException;
|
|
|
|
|
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;
|
2010-08-20 05:35:02 +00:00
|
|
|
import android.content.res.XmlResourceParser;
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.inputmethodservice.InputMethodService;
|
|
|
|
import android.inputmethodservice.Keyboard;
|
|
|
|
import android.media.AudioManager;
|
|
|
|
import android.os.Debug;
|
|
|
|
import android.os.Handler;
|
|
|
|
import android.os.Message;
|
|
|
|
import android.os.SystemClock;
|
|
|
|
import android.preference.PreferenceManager;
|
2010-03-30 17:05:53 +00:00
|
|
|
import android.speech.SpeechRecognizer;
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.text.ClipboardManager;
|
|
|
|
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-01-16 20:21:23 +00:00
|
|
|
import android.view.LayoutInflater;
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.view.View;
|
2010-03-07 15:27:05 +00:00
|
|
|
import android.view.ViewGroup;
|
2010-08-20 05:35:02 +00:00
|
|
|
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;
|
|
|
|
import android.view.inputmethod.InputMethodManager;
|
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;
|
2010-08-20 05:35:02 +00:00
|
|
|
import java.io.IOException;
|
2010-01-16 20:21:23 +00:00
|
|
|
import java.io.PrintWriter;
|
|
|
|
import java.util.ArrayList;
|
2010-02-17 22:42:51 +00:00
|
|
|
import java.util.Collections;
|
2010-01-16 20:21:23 +00:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Locale;
|
|
|
|
import java.util.Map;
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
/**
|
|
|
|
* Input method implementation for Qwerty'ish keyboard.
|
|
|
|
*/
|
2010-01-16 20:21:23 +00:00
|
|
|
public class LatinIME extends InputMethodService
|
2010-08-20 05:35:02 +00:00
|
|
|
implements LatinKeyboardBaseView.OnKeyboardActionListener,
|
2010-01-16 20:21:23 +00:00
|
|
|
VoiceInput.UiListener,
|
|
|
|
SharedPreferences.OnSharedPreferenceChangeListener {
|
|
|
|
private static final String TAG = "LatinIME";
|
2010-08-20 05:35:02 +00:00
|
|
|
private static final boolean PERF_DEBUG = false;
|
2009-03-13 22:11:42 +00:00
|
|
|
static final boolean DEBUG = false;
|
|
|
|
static final boolean TRACE = false;
|
2010-01-16 20:21:23 +00:00
|
|
|
static final boolean VOICE_INSTALLED = true;
|
|
|
|
static final boolean ENABLE_VOICE_BUTTON = true;
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
private static final String PREF_VIBRATE_ON = "vibrate_on";
|
|
|
|
private static final String PREF_SOUND_ON = "sound_on";
|
2010-08-20 05:35:02 +00:00
|
|
|
private static final String PREF_POPUP_ON = "popup_on";
|
2009-03-13 22:11:42 +00:00
|
|
|
private static final String PREF_AUTO_CAP = "auto_cap";
|
2009-03-26 00:39:38 +00:00
|
|
|
private static final String PREF_QUICK_FIXES = "quick_fixes";
|
|
|
|
private static final String PREF_SHOW_SUGGESTIONS = "show_suggestions";
|
|
|
|
private static final String PREF_AUTO_COMPLETE = "auto_complete";
|
2010-08-20 05:35:02 +00:00
|
|
|
private static final String PREF_BIGRAM_SUGGESTIONS = "bigram_suggestion";
|
2010-02-09 22:17:30 +00:00
|
|
|
private static final String PREF_VOICE_MODE = "voice_mode";
|
2010-01-28 15:33:27 +00:00
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
// Whether or not the user has used voice input before (and thus, whether to show the
|
2010-01-28 18:09:44 +00:00
|
|
|
// first-run warning dialog or not).
|
2010-01-16 20:21:23 +00:00
|
|
|
private static final String PREF_HAS_USED_VOICE_INPUT = "has_used_voice_input";
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
// Whether or not the user has used voice input from an unsupported locale UI before.
|
|
|
|
// For example, the user has a Chinese UI but activates voice input.
|
|
|
|
private static final String PREF_HAS_USED_VOICE_INPUT_UNSUPPORTED_LOCALE =
|
|
|
|
"has_used_voice_input_unsupported_locale";
|
|
|
|
|
|
|
|
// A list of locales which are supported by default for voice input, unless we get a
|
|
|
|
// different list from Gservices.
|
|
|
|
public static final String DEFAULT_VOICE_INPUT_SUPPORTED_LOCALES =
|
|
|
|
"en " +
|
|
|
|
"en_US " +
|
|
|
|
"en_GB " +
|
|
|
|
"en_AU " +
|
|
|
|
"en_CA " +
|
|
|
|
"en_IE " +
|
|
|
|
"en_IN " +
|
|
|
|
"en_NZ " +
|
|
|
|
"en_SG " +
|
|
|
|
"en_ZA ";
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-01-16 20:21:23 +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.
|
|
|
|
private static final String IME_OPTION_NO_MICROPHONE = "nm";
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2009-10-12 20:48:35 +00:00
|
|
|
public static final String PREF_SELECTED_LANGUAGES = "selected_languages";
|
|
|
|
public static final String PREF_INPUT_LANGUAGE = "input_language";
|
2010-09-06 10:18:38 +00:00
|
|
|
private static final String PREF_RECORRECTION_ENABLED = "recorrection_enabled";
|
2009-03-13 22:11:42 +00:00
|
|
|
|
|
|
|
private static final int MSG_UPDATE_SUGGESTIONS = 0;
|
2009-03-26 00:39:38 +00:00
|
|
|
private static final int MSG_START_TUTORIAL = 1;
|
2009-07-23 19:17:48 +00:00
|
|
|
private static final int MSG_UPDATE_SHIFT_STATE = 2;
|
2010-01-16 20:21:23 +00:00
|
|
|
private static final int MSG_VOICE_RESULTS = 3;
|
|
|
|
private static final int MSG_START_LISTENING_AFTER_SWIPE = 4;
|
2010-08-20 05:35:02 +00:00
|
|
|
private static final int MSG_UPDATE_OLD_SUGGESTIONS = 5;
|
2010-01-16 20:21:23 +00:00
|
|
|
|
|
|
|
// If we detect a swipe gesture within N ms of typing, then swipe is
|
|
|
|
// ignored, since it may in fact be two key presses in quick succession.
|
|
|
|
private static final long MIN_MILLIS_AFTER_TYPING_BEFORE_SWIPE = 1000;
|
|
|
|
|
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
|
|
|
|
2009-07-28 23:33:36 +00:00
|
|
|
static final int KEYCODE_ENTER = '\n';
|
|
|
|
static final int KEYCODE_SPACE = ' ';
|
2010-02-22 14:55:45 +00:00
|
|
|
static final int KEYCODE_PERIOD = '.';
|
2009-03-13 22:11:42 +00:00
|
|
|
|
|
|
|
// Contextual menu positions
|
2010-09-07 11:22:50 +00:00
|
|
|
private static final int POS_METHOD = 0;
|
|
|
|
private static final int POS_SETTINGS = 1;
|
2010-01-16 20:21:23 +00:00
|
|
|
|
2010-08-20 05:35:02 +00:00
|
|
|
//private LatinKeyboardView mInputView;
|
2010-09-01 08:54:12 +00:00
|
|
|
private LinearLayout mCandidateViewContainer;
|
2009-03-13 22:11:42 +00:00
|
|
|
private CandidateView mCandidateView;
|
|
|
|
private Suggest mSuggest;
|
|
|
|
private CompletionInfo[] mCompletions;
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
private AlertDialog mOptionsDialog;
|
2010-01-16 20:21:23 +00:00
|
|
|
private AlertDialog mVoiceWarningDialog;
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2009-03-26 00:39:38 +00:00
|
|
|
KeyboardSwitcher mKeyboardSwitcher;
|
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
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
private Hints mHints;
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2009-10-12 20:48:35 +00:00
|
|
|
Resources mResources;
|
|
|
|
|
2010-03-13 01:25:42 +00:00
|
|
|
private String mInputLocale;
|
|
|
|
private String mSystemLocale;
|
2010-01-30 04:09:49 +00:00
|
|
|
private LanguageSwitcher mLanguageSwitcher;
|
2009-03-13 22:11:42 +00:00
|
|
|
|
|
|
|
private StringBuilder mComposing = new StringBuilder();
|
|
|
|
private WordComposer mWord = new WordComposer();
|
|
|
|
private int mCommittedLength;
|
|
|
|
private boolean mPredicting;
|
2010-01-16 20:21:23 +00:00
|
|
|
private boolean mRecognizing;
|
|
|
|
private boolean mAfterVoiceInput;
|
|
|
|
private boolean mImmediatelyAfterVoiceInput;
|
|
|
|
private boolean mShowingVoiceSuggestions;
|
|
|
|
private boolean mVoiceInputHighlighted;
|
|
|
|
private boolean mEnableVoiceButton;
|
2009-03-13 22:11:42 +00:00
|
|
|
private CharSequence mBestWord;
|
|
|
|
private boolean mPredictionOn;
|
|
|
|
private boolean mCompletionOn;
|
2009-12-18 21:39:18 +00:00
|
|
|
private boolean mHasDictionary;
|
2009-03-13 22:11:42 +00:00
|
|
|
private boolean mAutoSpace;
|
2010-02-07 00:34:43 +00:00
|
|
|
private boolean mJustAddedAutoSpace;
|
2009-12-18 21:39:18 +00:00
|
|
|
private boolean mAutoCorrectEnabled;
|
2010-09-06 10:18:38 +00:00
|
|
|
private boolean mReCorrectionEnabled;
|
2010-08-20 05:35:02 +00:00
|
|
|
private boolean mBigramSuggestionEnabled;
|
2009-03-13 22:11:42 +00:00
|
|
|
private boolean mAutoCorrectOn;
|
2010-08-20 05:35:02 +00:00
|
|
|
// TODO move this state variable outside LatinIME
|
2009-03-13 22:11:42 +00:00
|
|
|
private boolean mCapsLock;
|
2010-01-16 20:21:23 +00:00
|
|
|
private boolean mPasswordText;
|
2009-03-13 22:11:42 +00:00
|
|
|
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;
|
2010-01-16 20:21:23 +00:00
|
|
|
private boolean mHasUsedVoiceInput;
|
|
|
|
private boolean mHasUsedVoiceInputUnsupportedLocale;
|
|
|
|
private boolean mLocaleSupportedForVoiceInput;
|
2009-03-26 00:39:38 +00:00
|
|
|
private boolean mShowSuggestions;
|
2010-01-16 20:21:23 +00:00
|
|
|
private boolean mIsShowingHint;
|
2009-03-26 00:39:38 +00:00
|
|
|
private int mCorrectionMode;
|
2010-01-16 20:21:23 +00:00
|
|
|
private boolean mEnableVoice = true;
|
2010-01-28 15:33:27 +00:00
|
|
|
private boolean mVoiceOnPrimary;
|
2009-07-21 22:47:11 +00:00
|
|
|
private int mOrientation;
|
2010-02-03 23:35:49 +00:00
|
|
|
private List<CharSequence> mSuggestPuncList;
|
2010-08-20 05:35:02 +00:00
|
|
|
// Keep track of the last selection range to decide if we need to show word alternatives
|
|
|
|
private int mLastSelectionStart;
|
|
|
|
private int mLastSelectionEnd;
|
|
|
|
|
|
|
|
// Input type is such that we should not auto-correct
|
|
|
|
private boolean mInputTypeNoAutoCorrect;
|
2010-01-28 18:09:44 +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 CharSequence mJustRevertedSeparator;
|
|
|
|
private int mDeleteCount;
|
|
|
|
private long mLastKeyTime;
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-09-09 05:43:17 +00:00
|
|
|
// Modifier keys state
|
2010-09-01 16:35:24 +00:00
|
|
|
private ModifierKeyState mShiftKeyState = new ModifierKeyState();
|
2010-09-09 05:43:17 +00:00
|
|
|
private ModifierKeyState mSymbolKeyState = new ModifierKeyState();
|
2010-09-01 16:35:24 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
private Tutorial mTutorial;
|
|
|
|
|
|
|
|
private AudioManager mAudioManager;
|
2009-09-29 19:00:38 +00:00
|
|
|
// Align sound effect volume on music volume
|
|
|
|
private 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;
|
2010-01-16 20:21:23 +00:00
|
|
|
private VoiceInput mVoiceInput;
|
|
|
|
private VoiceResults mVoiceResults = new VoiceResults();
|
|
|
|
private long mSwipeTriggerTimeMillis;
|
2010-03-07 15:27:05 +00:00
|
|
|
private boolean mConfigurationChanging;
|
2010-01-16 20:21:23 +00:00
|
|
|
|
2010-04-01 13:28:52 +00:00
|
|
|
// Keeps track of most recently inserted text (multi-character key) for reverting
|
|
|
|
private CharSequence mEnteredText;
|
2010-08-20 05:35:02 +00:00
|
|
|
private boolean mRefreshKeyboardRequired;
|
2010-04-01 13:28:52 +00:00
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
// For each word, a list of potential replacements, usually from voice.
|
2010-02-11 01:45:35 +00:00
|
|
|
private Map<String, List<CharSequence>> mWordToSuggestions =
|
|
|
|
new HashMap<String, List<CharSequence>>();
|
2010-01-16 20:21:23 +00:00
|
|
|
|
2010-08-20 05:35:02 +00:00
|
|
|
private ArrayList<WordAlternatives> mWordHistory = new ArrayList<WordAlternatives>();
|
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
private class VoiceResults {
|
|
|
|
List<String> candidates;
|
|
|
|
Map<String, List<CharSequence>> alternatives;
|
|
|
|
}
|
2010-09-15 04:03:34 +00:00
|
|
|
|
2010-08-20 05:35:02 +00:00
|
|
|
public abstract static class WordAlternatives {
|
|
|
|
protected CharSequence mChosenWord;
|
2010-03-04 14:34:21 +00:00
|
|
|
|
2010-08-20 05:35:02 +00:00
|
|
|
public WordAlternatives() {
|
|
|
|
// Nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
public WordAlternatives(CharSequence chosenWord) {
|
|
|
|
mChosenWord = chosenWord;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int hashCode() {
|
|
|
|
return mChosenWord.hashCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
public abstract CharSequence getOriginalWord();
|
|
|
|
|
|
|
|
public CharSequence getChosenWord() {
|
|
|
|
return mChosenWord;
|
|
|
|
}
|
|
|
|
|
|
|
|
public abstract List<CharSequence> getAlternatives();
|
|
|
|
}
|
|
|
|
|
|
|
|
public class TypedWordAlternatives extends WordAlternatives {
|
|
|
|
private WordComposer word;
|
|
|
|
|
|
|
|
public TypedWordAlternatives() {
|
|
|
|
// Nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
public TypedWordAlternatives(CharSequence chosenWord, WordComposer wordComposer) {
|
|
|
|
super(chosenWord);
|
|
|
|
word = wordComposer;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public CharSequence getOriginalWord() {
|
|
|
|
return word.getTypedWord();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<CharSequence> getAlternatives() {
|
|
|
|
return getTypedSuggestions(word);
|
|
|
|
}
|
|
|
|
}
|
2009-10-12 20:48:35 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
Handler mHandler = new Handler() {
|
|
|
|
@Override
|
|
|
|
public void handleMessage(Message msg) {
|
|
|
|
switch (msg.what) {
|
|
|
|
case MSG_UPDATE_SUGGESTIONS:
|
|
|
|
updateSuggestions();
|
|
|
|
break;
|
2010-08-20 05:35:02 +00:00
|
|
|
case MSG_UPDATE_OLD_SUGGESTIONS:
|
|
|
|
setOldSuggestions();
|
|
|
|
break;
|
2009-03-26 00:39:38 +00:00
|
|
|
case MSG_START_TUTORIAL:
|
|
|
|
if (mTutorial == null) {
|
2010-08-20 05:35:02 +00:00
|
|
|
if (mKeyboardSwitcher.getInputView().isShown()) {
|
|
|
|
mTutorial = new Tutorial(
|
|
|
|
LatinIME.this, mKeyboardSwitcher.getInputView());
|
2009-03-26 00:39:38 +00:00
|
|
|
mTutorial.start();
|
|
|
|
} else {
|
|
|
|
// Try again soon if the view is not yet showing
|
|
|
|
sendMessageDelayed(obtainMessage(MSG_START_TUTORIAL), 100);
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
break;
|
2009-07-23 19:17:48 +00:00
|
|
|
case MSG_UPDATE_SHIFT_STATE:
|
|
|
|
updateShiftKeyState(getCurrentInputEditorInfo());
|
|
|
|
break;
|
2010-01-16 20:21:23 +00:00
|
|
|
case MSG_VOICE_RESULTS:
|
|
|
|
handleVoiceResults();
|
|
|
|
break;
|
|
|
|
case MSG_START_LISTENING_AFTER_SWIPE:
|
|
|
|
if (mLastKeyTime < mSwipeTriggerTimeMillis) {
|
|
|
|
startListening(true);
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
@Override public void onCreate() {
|
2010-08-20 05:35:02 +00:00
|
|
|
LatinImeLogger.init(this);
|
2009-03-13 22:11:42 +00:00
|
|
|
super.onCreate();
|
|
|
|
//setStatusIcon(R.drawable.ime_qwerty);
|
2009-10-12 20:48:35 +00:00
|
|
|
mResources = getResources();
|
|
|
|
final Configuration conf = mResources.getConfiguration();
|
2010-01-30 04:09:49 +00:00
|
|
|
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
|
|
|
mLanguageSwitcher = new LanguageSwitcher(this);
|
|
|
|
mLanguageSwitcher.loadLocales(prefs);
|
|
|
|
mKeyboardSwitcher = new KeyboardSwitcher(this, this);
|
|
|
|
mKeyboardSwitcher.setLanguageSwitcher(mLanguageSwitcher);
|
2010-03-13 01:25:42 +00:00
|
|
|
mSystemLocale = conf.locale.toString();
|
2010-05-03 18:14:31 +00:00
|
|
|
mLanguageSwitcher.setSystemLocale(conf.locale);
|
2010-01-30 04:09:49 +00:00
|
|
|
String inputLanguage = mLanguageSwitcher.getInputLanguage();
|
|
|
|
if (inputLanguage == null) {
|
|
|
|
inputLanguage = conf.locale.toString();
|
|
|
|
}
|
2010-09-06 10:18:38 +00:00
|
|
|
mReCorrectionEnabled = prefs.getBoolean(PREF_RECORRECTION_ENABLED,
|
|
|
|
getResources().getBoolean(R.bool.default_recorrection_enabled));
|
2010-08-20 05:35:02 +00:00
|
|
|
|
|
|
|
LatinIMEUtil.GCUtils.getInstance().reset();
|
|
|
|
boolean tryGC = true;
|
|
|
|
for (int i = 0; i < LatinIMEUtil.GCUtils.GC_TRY_LOOP_MAX && tryGC; ++i) {
|
|
|
|
try {
|
|
|
|
initSuggest(inputLanguage);
|
|
|
|
tryGC = false;
|
|
|
|
} catch (OutOfMemoryError e) {
|
|
|
|
tryGC = LatinIMEUtil.GCUtils.getInstance().tryGCOrWait(inputLanguage, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-21 22:47:11 +00:00
|
|
|
mOrientation = conf.orientation;
|
2010-02-03 23:35:49 +00:00
|
|
|
initSuggestPuncList();
|
2009-07-21 22:47:11 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
// register to receive ringer mode changes for silent mode
|
|
|
|
IntentFilter filter = new IntentFilter(AudioManager.RINGER_MODE_CHANGED_ACTION);
|
|
|
|
registerReceiver(mReceiver, filter);
|
2010-01-16 20:21:23 +00:00
|
|
|
if (VOICE_INSTALLED) {
|
|
|
|
mVoiceInput = new VoiceInput(this, this);
|
|
|
|
mHints = new Hints(this, new Hints.Display() {
|
|
|
|
public void showHint(int viewResource) {
|
|
|
|
LayoutInflater inflater = (LayoutInflater) getSystemService(
|
|
|
|
Context.LAYOUT_INFLATER_SERVICE);
|
|
|
|
View view = inflater.inflate(viewResource, null);
|
|
|
|
setCandidatesView(view);
|
|
|
|
setCandidatesViewShown(true);
|
|
|
|
mIsShowingHint = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2010-01-30 04:09:49 +00:00
|
|
|
prefs.registerOnSharedPreferenceChangeListener(this);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2009-10-12 20:48:35 +00:00
|
|
|
|
2010-08-20 05:35:02 +00:00
|
|
|
/**
|
|
|
|
* Loads a dictionary or multiple separated dictionary
|
|
|
|
* @return returns array of dictionary resource ids
|
|
|
|
*/
|
|
|
|
static int[] getDictionary(Resources res) {
|
|
|
|
String packageName = LatinIME.class.getPackage().getName();
|
|
|
|
XmlResourceParser xrp = res.getXml(R.xml.dictionary);
|
|
|
|
ArrayList<Integer> dictionaries = new ArrayList<Integer>();
|
|
|
|
|
|
|
|
try {
|
|
|
|
int current = xrp.getEventType();
|
|
|
|
while (current != XmlResourceParser.END_DOCUMENT) {
|
|
|
|
if (current == XmlResourceParser.START_TAG) {
|
|
|
|
String tag = xrp.getName();
|
|
|
|
if (tag != null) {
|
|
|
|
if (tag.equals("part")) {
|
|
|
|
String dictFileName = xrp.getAttributeValue(null, "name");
|
|
|
|
dictionaries.add(res.getIdentifier(dictFileName, "raw", packageName));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
xrp.next();
|
|
|
|
current = xrp.getEventType();
|
|
|
|
}
|
|
|
|
} catch (XmlPullParserException e) {
|
|
|
|
Log.e(TAG, "Dictionary XML parsing failure");
|
|
|
|
} catch (IOException e) {
|
|
|
|
Log.e(TAG, "Dictionary XML IOException");
|
|
|
|
}
|
|
|
|
|
|
|
|
int count = dictionaries.size();
|
|
|
|
int[] dict = new int[count];
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
dict[i] = dictionaries.get(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
return dict;
|
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
private void initSuggest(String locale) {
|
2010-03-13 01:25:42 +00:00
|
|
|
mInputLocale = locale;
|
2009-10-12 20:48:35 +00:00
|
|
|
|
|
|
|
Resources orig = getResources();
|
|
|
|
Configuration conf = orig.getConfiguration();
|
|
|
|
Locale saveLocale = conf.locale;
|
|
|
|
conf.locale = new Locale(locale);
|
|
|
|
orig.updateConfiguration(conf, orig.getDisplayMetrics());
|
|
|
|
if (mSuggest != null) {
|
|
|
|
mSuggest.close();
|
|
|
|
}
|
2010-02-20 00:38:58 +00:00
|
|
|
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
|
|
|
|
mQuickFixes = sp.getBoolean(PREF_QUICK_FIXES, true);
|
2010-08-20 05:35:02 +00:00
|
|
|
|
|
|
|
int[] dictionaries = getDictionary(orig);
|
|
|
|
mSuggest = new Suggest(this, dictionaries);
|
2010-02-20 00:38:58 +00:00
|
|
|
updateAutoTextEnabled(saveLocale);
|
2010-01-17 21:55:56 +00:00
|
|
|
if (mUserDictionary != null) mUserDictionary.close();
|
2010-03-13 01:25:42 +00:00
|
|
|
mUserDictionary = new UserDictionary(this, mInputLocale);
|
2009-10-12 20:48:35 +00:00
|
|
|
if (mContactsDictionary == null) {
|
2010-08-20 05:35:02 +00:00
|
|
|
mContactsDictionary = new ContactsDictionary(this, Suggest.DIC_CONTACTS);
|
2009-10-12 20:48:35 +00:00
|
|
|
}
|
2010-02-24 03:01:43 +00:00
|
|
|
if (mAutoDictionary != null) {
|
|
|
|
mAutoDictionary.close();
|
2009-10-12 20:48:35 +00:00
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
mAutoDictionary = new AutoDictionary(this, this, mInputLocale, Suggest.DIC_AUTO);
|
|
|
|
if (mUserBigramDictionary != null) {
|
|
|
|
mUserBigramDictionary.close();
|
|
|
|
}
|
|
|
|
mUserBigramDictionary = new UserBigramDictionary(this, this, mInputLocale,
|
|
|
|
Suggest.DIC_USER);
|
|
|
|
mSuggest.setUserBigramDictionary(mUserBigramDictionary);
|
2009-03-13 22:11:42 +00:00
|
|
|
mSuggest.setUserDictionary(mUserDictionary);
|
2009-07-28 23:48:47 +00:00
|
|
|
mSuggest.setContactsDictionary(mContactsDictionary);
|
2009-07-17 19:51:45 +00:00
|
|
|
mSuggest.setAutoDictionary(mAutoDictionary);
|
2009-12-18 21:39:18 +00:00
|
|
|
updateCorrectionMode();
|
2009-10-12 20:48:35 +00:00
|
|
|
mWordSeparators = mResources.getString(R.string.word_separators);
|
|
|
|
mSentenceSeparators = mResources.getString(R.string.sentence_separators);
|
|
|
|
|
|
|
|
conf.locale = saveLocale;
|
|
|
|
orig.updateConfiguration(conf, orig.getDisplayMetrics());
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2009-10-12 20:48:35 +00:00
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
@Override
|
|
|
|
public void onDestroy() {
|
2010-08-20 05:35:02 +00:00
|
|
|
if (mUserDictionary != null) {
|
|
|
|
mUserDictionary.close();
|
|
|
|
}
|
|
|
|
if (mContactsDictionary != null) {
|
|
|
|
mContactsDictionary.close();
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
unregisterReceiver(mReceiver);
|
2010-08-20 05:35:02 +00:00
|
|
|
if (VOICE_INSTALLED && mVoiceInput != null) {
|
2010-01-16 20:21:23 +00:00
|
|
|
mVoiceInput.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) {
|
2010-02-21 23:59:15 +00:00
|
|
|
// If the system locale changes and is different from the saved
|
2010-03-13 01:25:42 +00:00
|
|
|
// locale (mSystemLocale), then reload the input locale list from the
|
2010-02-21 23:59:15 +00:00
|
|
|
// latin ime settings (shared prefs) and reset the input locale
|
|
|
|
// to the first one.
|
2010-03-13 01:25:42 +00:00
|
|
|
final String systemLocale = conf.locale.toString();
|
|
|
|
if (!TextUtils.equals(systemLocale, mSystemLocale)) {
|
|
|
|
mSystemLocale = systemLocale;
|
2010-02-21 23:59:15 +00:00
|
|
|
if (mLanguageSwitcher != null) {
|
|
|
|
mLanguageSwitcher.loadLocales(
|
|
|
|
PreferenceManager.getDefaultSharedPreferences(this));
|
2010-05-03 18:14:31 +00:00
|
|
|
mLanguageSwitcher.setSystemLocale(conf.locale);
|
2010-02-21 23:59:15 +00:00
|
|
|
toggleLanguage(true, true);
|
|
|
|
} else {
|
|
|
|
reloadKeyboards();
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
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;
|
2010-02-21 23:59:15 +00:00
|
|
|
reloadKeyboards();
|
2009-07-21 22:47:11 +00:00
|
|
|
}
|
2010-03-07 15:27:05 +00:00
|
|
|
mConfigurationChanging = true;
|
2009-03-13 22:11:42 +00:00
|
|
|
super.onConfigurationChanged(conf);
|
2010-03-07 15:27:05 +00:00
|
|
|
if (mRecognizing) {
|
|
|
|
switchToRecognitionStatusView();
|
|
|
|
}
|
|
|
|
mConfigurationChanging = false;
|
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-08-20 05:35:02 +00:00
|
|
|
mKeyboardSwitcher.recreateInputView();
|
2009-10-01 04:15:47 +00:00
|
|
|
mKeyboardSwitcher.makeKeyboards(true);
|
2010-01-16 20:21:23 +00:00
|
|
|
mKeyboardSwitcher.setKeyboardMode(
|
|
|
|
KeyboardSwitcher.MODE_TEXT, 0,
|
|
|
|
shouldShowVoiceButton(makeFieldContext(), getCurrentInputEditorInfo()));
|
2010-08-20 05:35:02 +00:00
|
|
|
return mKeyboardSwitcher.getInputView();
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public View onCreateCandidatesView() {
|
2009-10-01 04:15:47 +00:00
|
|
|
mKeyboardSwitcher.makeKeyboards(true);
|
2010-09-01 08:54:12 +00:00
|
|
|
mCandidateViewContainer = (LinearLayout) getLayoutInflater().inflate(
|
2009-03-13 22:11:42 +00:00
|
|
|
R.layout.candidates, null);
|
|
|
|
mCandidateView = (CandidateView) mCandidateViewContainer.findViewById(R.id.candidates);
|
|
|
|
mCandidateView.setService(this);
|
|
|
|
setCandidatesViewShown(true);
|
|
|
|
return mCandidateViewContainer;
|
|
|
|
}
|
|
|
|
|
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-08-20 05:35:02 +00:00
|
|
|
LatinKeyboardView inputView = mKeyboardSwitcher.getInputView();
|
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;
|
|
|
|
}
|
|
|
|
|
2009-10-12 20:48:35 +00:00
|
|
|
if (mRefreshKeyboardRequired) {
|
|
|
|
mRefreshKeyboardRequired = false;
|
2010-01-30 04:09:49 +00:00
|
|
|
toggleLanguage(true, true);
|
2009-10-12 20:48:35 +00:00
|
|
|
}
|
|
|
|
|
2009-10-01 04:15:47 +00:00
|
|
|
mKeyboardSwitcher.makeKeyboards(false);
|
2009-06-04 22:31:01 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
TextEntryState.newSession(this);
|
2009-06-04 22:31:01 +00:00
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
// Most such things we decide below in the switch statement, but we need to know
|
|
|
|
// now whether this is a password text field, because we need to know now (before
|
|
|
|
// the switch statement) whether we want to enable the voice button.
|
|
|
|
mPasswordText = false;
|
|
|
|
int variation = attribute.inputType & EditorInfo.TYPE_MASK_VARIATION;
|
|
|
|
if (variation == EditorInfo.TYPE_TEXT_VARIATION_PASSWORD ||
|
|
|
|
variation == EditorInfo.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD) {
|
|
|
|
mPasswordText = true;
|
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
mEnableVoiceButton = shouldShowVoiceButton(makeFieldContext(), attribute);
|
2010-01-28 15:33:27 +00:00
|
|
|
final boolean enableVoiceButton = mEnableVoiceButton && mEnableVoice;
|
2010-01-16 20:21:23 +00:00
|
|
|
|
|
|
|
mAfterVoiceInput = false;
|
|
|
|
mImmediatelyAfterVoiceInput = false;
|
|
|
|
mShowingVoiceSuggestions = false;
|
|
|
|
mVoiceInputHighlighted = false;
|
2009-12-18 21:39:18 +00:00
|
|
|
mInputTypeNoAutoCorrect = false;
|
2009-03-13 22:11:42 +00:00
|
|
|
mPredictionOn = false;
|
|
|
|
mCompletionOn = false;
|
|
|
|
mCompletions = null;
|
|
|
|
mCapsLock = false;
|
2010-04-01 13:28:52 +00:00
|
|
|
mEnteredText = null;
|
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
switch (attribute.inputType & EditorInfo.TYPE_MASK_CLASS) {
|
2009-03-13 22:11:42 +00:00
|
|
|
case EditorInfo.TYPE_CLASS_NUMBER:
|
|
|
|
case EditorInfo.TYPE_CLASS_DATETIME:
|
2009-09-01 21:05:19 +00:00
|
|
|
mKeyboardSwitcher.setKeyboardMode(KeyboardSwitcher.MODE_SYMBOLS,
|
2010-01-28 15:33:27 +00:00
|
|
|
attribute.imeOptions, enableVoiceButton);
|
2009-03-13 22:11:42 +00:00
|
|
|
break;
|
|
|
|
case EditorInfo.TYPE_CLASS_PHONE:
|
|
|
|
mKeyboardSwitcher.setKeyboardMode(KeyboardSwitcher.MODE_PHONE,
|
2010-01-28 15:33:27 +00:00
|
|
|
attribute.imeOptions, enableVoiceButton);
|
2009-03-13 22:11:42 +00:00
|
|
|
break;
|
|
|
|
case EditorInfo.TYPE_CLASS_TEXT:
|
|
|
|
mKeyboardSwitcher.setKeyboardMode(KeyboardSwitcher.MODE_TEXT,
|
2010-01-28 15:33:27 +00:00
|
|
|
attribute.imeOptions, enableVoiceButton);
|
2009-03-13 22:11:42 +00:00
|
|
|
//startPrediction();
|
|
|
|
mPredictionOn = true;
|
|
|
|
// Make sure that passwords are not displayed in candidate view
|
|
|
|
if (variation == EditorInfo.TYPE_TEXT_VARIATION_PASSWORD ||
|
|
|
|
variation == EditorInfo.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD ) {
|
|
|
|
mPredictionOn = false;
|
|
|
|
}
|
|
|
|
if (variation == EditorInfo.TYPE_TEXT_VARIATION_EMAIL_ADDRESS
|
|
|
|
|| variation == EditorInfo.TYPE_TEXT_VARIATION_PERSON_NAME) {
|
|
|
|
mAutoSpace = false;
|
|
|
|
} else {
|
|
|
|
mAutoSpace = true;
|
|
|
|
}
|
|
|
|
if (variation == EditorInfo.TYPE_TEXT_VARIATION_EMAIL_ADDRESS) {
|
|
|
|
mPredictionOn = false;
|
|
|
|
mKeyboardSwitcher.setKeyboardMode(KeyboardSwitcher.MODE_EMAIL,
|
2010-01-28 15:33:27 +00:00
|
|
|
attribute.imeOptions, enableVoiceButton);
|
2009-03-13 22:11:42 +00:00
|
|
|
} else if (variation == EditorInfo.TYPE_TEXT_VARIATION_URI) {
|
|
|
|
mPredictionOn = false;
|
|
|
|
mKeyboardSwitcher.setKeyboardMode(KeyboardSwitcher.MODE_URL,
|
2010-01-28 15:33:27 +00:00
|
|
|
attribute.imeOptions, enableVoiceButton);
|
2009-03-13 22:11:42 +00:00
|
|
|
} else if (variation == EditorInfo.TYPE_TEXT_VARIATION_SHORT_MESSAGE) {
|
|
|
|
mKeyboardSwitcher.setKeyboardMode(KeyboardSwitcher.MODE_IM,
|
2010-01-28 15:33:27 +00:00
|
|
|
attribute.imeOptions, enableVoiceButton);
|
2009-03-13 22:11:42 +00:00
|
|
|
} else if (variation == EditorInfo.TYPE_TEXT_VARIATION_FILTER) {
|
|
|
|
mPredictionOn = false;
|
2009-06-04 22:31:01 +00:00
|
|
|
} else if (variation == EditorInfo.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT) {
|
2010-01-27 05:25:29 +00:00
|
|
|
mKeyboardSwitcher.setKeyboardMode(KeyboardSwitcher.MODE_WEB,
|
2010-01-28 15:33:27 +00:00
|
|
|
attribute.imeOptions, enableVoiceButton);
|
2009-06-04 22:31:01 +00:00
|
|
|
// If it's a browser edit field and auto correct is not ON explicitly, then
|
|
|
|
// disable auto correction, but keep suggestions on.
|
|
|
|
if ((attribute.inputType & EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT) == 0) {
|
2009-12-18 21:39:18 +00:00
|
|
|
mInputTypeNoAutoCorrect = true;
|
2009-06-04 22:31:01 +00:00
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2009-09-17 18:08:16 +00:00
|
|
|
|
|
|
|
// If NO_SUGGESTIONS is set, don't do prediction.
|
|
|
|
if ((attribute.inputType & EditorInfo.TYPE_TEXT_FLAG_NO_SUGGESTIONS) != 0) {
|
|
|
|
mPredictionOn = false;
|
2009-12-18 21:39:18 +00:00
|
|
|
mInputTypeNoAutoCorrect = true;
|
2009-09-17 18:08:16 +00:00
|
|
|
}
|
|
|
|
// If it's not multiline and the autoCorrect flag is not set, then don't correct
|
|
|
|
if ((attribute.inputType & EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT) == 0 &&
|
|
|
|
(attribute.inputType & EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE) == 0) {
|
2009-12-18 21:39:18 +00:00
|
|
|
mInputTypeNoAutoCorrect = true;
|
2009-09-17 18:08:16 +00:00
|
|
|
}
|
2010-08-31 09:00:09 +00:00
|
|
|
if ((attribute.inputType & EditorInfo.TYPE_TEXT_FLAG_AUTO_COMPLETE) != 0) {
|
2009-03-13 22:11:42 +00:00
|
|
|
mPredictionOn = false;
|
2010-08-31 09:00:09 +00:00
|
|
|
mCompletionOn = isFullscreenMode();
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
mKeyboardSwitcher.setKeyboardMode(KeyboardSwitcher.MODE_TEXT,
|
2010-01-28 15:33:27 +00:00
|
|
|
attribute.imeOptions, enableVoiceButton);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
inputView.closing();
|
2009-03-13 22:11:42 +00:00
|
|
|
mComposing.setLength(0);
|
|
|
|
mPredicting = false;
|
|
|
|
mDeleteCount = 0;
|
2010-02-07 00:34:43 +00:00
|
|
|
mJustAddedAutoSpace = false;
|
2009-03-13 22:11:42 +00:00
|
|
|
loadSettings();
|
2010-03-02 07:18:48 +00:00
|
|
|
updateShiftKeyState(attribute);
|
2009-12-18 21:39:18 +00:00
|
|
|
|
2010-08-31 09:00:09 +00:00
|
|
|
setCandidatesViewShownInternal(isCandidateStripVisible() || mCompletionOn,
|
|
|
|
false /* needsInputViewShown */ );
|
|
|
|
updateSuggestions();
|
2010-01-16 20:21:23 +00:00
|
|
|
|
2009-12-18 21:39:18 +00:00
|
|
|
// If the dictionary is not big enough, don't auto correct
|
|
|
|
mHasDictionary = mSuggest.hasMainDictionary();
|
|
|
|
|
|
|
|
updateCorrectionMode();
|
|
|
|
|
2010-08-20 05:35:02 +00:00
|
|
|
inputView.setPreviewEnabled(mPopupOn);
|
|
|
|
inputView.setProximityCorrectionEnabled(true);
|
2010-02-20 00:38:58 +00:00
|
|
|
mPredictionOn = mPredictionOn && (mCorrectionMode > 0 || mShowSuggestions);
|
2009-03-26 00:39:38 +00:00
|
|
|
checkTutorial(attribute.privateImeOptions);
|
2009-07-23 19:17:48 +00:00
|
|
|
if (TRACE) Debug.startMethodTracing("/data/trace/latinime");
|
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-09-03 10:05:23 +00:00
|
|
|
onAutoCompletionStateChanged(false);
|
2010-08-20 05:35:02 +00:00
|
|
|
|
2010-03-07 15:27:05 +00:00
|
|
|
if (VOICE_INSTALLED && !mConfigurationChanging) {
|
|
|
|
if (mAfterVoiceInput) {
|
2010-03-04 14:34:21 +00:00
|
|
|
mVoiceInput.flushAllTextModificationCounters();
|
2010-03-07 15:27:05 +00:00
|
|
|
mVoiceInput.logInputEnded();
|
|
|
|
}
|
2010-02-05 12:11:59 +00:00
|
|
|
mVoiceInput.flushLogs();
|
2010-03-07 15:27:05 +00:00
|
|
|
mVoiceInput.cancel();
|
2010-02-05 12:11:59 +00:00
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
if (mKeyboardSwitcher.getInputView() != null) {
|
|
|
|
mKeyboardSwitcher.getInputView().closing();
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onUpdateExtractedText(int token, ExtractedText text) {
|
|
|
|
super.onUpdateExtractedText(token, text);
|
|
|
|
InputConnection ic = getCurrentInputConnection();
|
|
|
|
if (!mImmediatelyAfterVoiceInput && mAfterVoiceInput && ic != null) {
|
|
|
|
if (mHints.showPunctuationHintIfNecessary(ic)) {
|
|
|
|
mVoiceInput.logPunctuationHintDisplayed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mImmediatelyAfterVoiceInput = false;
|
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
|
|
|
|
+ ", nss=" + newSelStart
|
|
|
|
+ ", nse=" + newSelEnd
|
|
|
|
+ ", cs=" + candidatesStart
|
|
|
|
+ ", ce=" + candidatesEnd);
|
|
|
|
}
|
|
|
|
|
2010-03-04 14:34:21 +00:00
|
|
|
if (mAfterVoiceInput) {
|
|
|
|
mVoiceInput.setCursorPos(newSelEnd);
|
|
|
|
mVoiceInput.setSelectionSpan(newSelEnd - newSelStart);
|
|
|
|
}
|
|
|
|
|
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.
|
2010-01-16 20:21:23 +00:00
|
|
|
if ((((mComposing.length() > 0 && mPredicting) || mVoiceInputHighlighted)
|
|
|
|
&& (newSelStart != candidatesEnd
|
2010-08-20 05:35:02 +00:00
|
|
|
|| newSelEnd != candidatesEnd)
|
|
|
|
&& mLastSelectionStart != newSelStart)) {
|
2009-03-13 22:11:42 +00:00
|
|
|
mComposing.setLength(0);
|
|
|
|
mPredicting = false;
|
2010-08-20 05:35:02 +00:00
|
|
|
postUpdateSuggestions();
|
2009-03-13 22:11:42 +00:00
|
|
|
TextEntryState.reset();
|
|
|
|
InputConnection ic = getCurrentInputConnection();
|
|
|
|
if (ic != null) {
|
|
|
|
ic.finishComposingText();
|
|
|
|
}
|
2010-01-16 20:21:23 +00:00
|
|
|
mVoiceInputHighlighted = false;
|
2010-02-07 00:34:43 +00:00
|
|
|
} else if (!mPredicting && !mJustAccepted) {
|
|
|
|
switch (TextEntryState.getState()) {
|
2010-08-20 05:35:02 +00:00
|
|
|
case ACCEPTED_DEFAULT:
|
2010-02-07 00:34:43 +00:00
|
|
|
TextEntryState.reset();
|
|
|
|
// fall through
|
2010-08-20 05:35:02 +00:00
|
|
|
case SPACE_AFTER_PICKED:
|
2010-02-07 00:34:43 +00:00
|
|
|
mJustAddedAutoSpace = false; // The user moved the cursor.
|
|
|
|
break;
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
mJustAccepted = false;
|
2009-08-08 02:46:55 +00:00
|
|
|
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
|
|
|
|
2010-09-06 10:18:38 +00:00
|
|
|
if (mReCorrectionEnabled) {
|
|
|
|
// Don't look for corrections if the keyboard is not visible
|
|
|
|
if (mKeyboardSwitcher != null && mKeyboardSwitcher.getInputView() != null
|
|
|
|
&& mKeyboardSwitcher.getInputView().isShown()) {
|
|
|
|
// Check if we should go in or out of correction mode.
|
|
|
|
if (isPredictionOn()
|
|
|
|
&& mJustRevertedSeparator == null
|
|
|
|
&& (candidatesStart == candidatesEnd || newSelStart != oldSelStart
|
|
|
|
|| TextEntryState.isCorrecting())
|
|
|
|
&& (newSelStart < newSelEnd - 1 || (!mPredicting))
|
|
|
|
&& !mVoiceInputHighlighted) {
|
|
|
|
if (isCursorTouchingWord() || mLastSelectionStart < mLastSelectionEnd) {
|
|
|
|
postUpdateOldSuggestions();
|
|
|
|
} else {
|
|
|
|
abortCorrection(false);
|
|
|
|
}
|
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() {
|
|
|
|
if (mReCorrectionEnabled && isPredictionOn()) return;
|
|
|
|
|
|
|
|
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) {
|
|
|
|
if (mReCorrectionEnabled && isPredictionOn()) return;
|
|
|
|
|
|
|
|
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-09-03 10:05:23 +00:00
|
|
|
onAutoCompletionStateChanged(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;
|
|
|
|
}
|
2010-03-07 15:27:05 +00:00
|
|
|
if (!mConfigurationChanging) {
|
|
|
|
if (mAfterVoiceInput) mVoiceInput.logInputEnded();
|
|
|
|
if (mVoiceWarningDialog != null && mVoiceWarningDialog.isShowing()) {
|
|
|
|
mVoiceInput.logKeyboardWarningDialogDismissed();
|
|
|
|
mVoiceWarningDialog.dismiss();
|
|
|
|
mVoiceWarningDialog = null;
|
|
|
|
}
|
|
|
|
if (VOICE_INSTALLED & mRecognizing) {
|
|
|
|
mVoiceInput.cancel();
|
|
|
|
}
|
2010-01-16 20:21:23 +00:00
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
mWordToSuggestions.clear();
|
|
|
|
mWordHistory.clear();
|
2009-03-13 22:11:42 +00:00
|
|
|
super.hideWindow();
|
|
|
|
TextEntryState.endSession();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDisplayCompletions(CompletionInfo[] completions) {
|
2010-08-20 05:35:02 +00:00
|
|
|
if (DEBUG) {
|
2009-03-13 22:11:42 +00:00
|
|
|
Log.i("foo", "Received completions:");
|
|
|
|
for (int i=0; i<(completions != null ? completions.length : 0); i++) {
|
|
|
|
Log.i("foo", " #" + i + ": " + completions[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mCompletionOn) {
|
|
|
|
mCompletions = completions;
|
|
|
|
if (completions == 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
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
List<CharSequence> stringList = new ArrayList<CharSequence>();
|
|
|
|
for (int i=0; i<(completions != null ? completions.length : 0); i++) {
|
|
|
|
CompletionInfo ci = completions[i];
|
|
|
|
if (ci != null) stringList.add(ci.getText());
|
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
// When in fullscreen mode, show completions generated by the application
|
2010-01-16 20:21:23 +00:00
|
|
|
setSuggestions(stringList, true, true, true);
|
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) {
|
2009-03-13 22:11:42 +00:00
|
|
|
// TODO: Remove this if we support candidates with hard keyboard
|
|
|
|
if (onEvaluateInputViewShown()) {
|
2010-08-20 05:35:02 +00:00
|
|
|
super.setCandidatesViewShown(shown && mKeyboardSwitcher.getInputView() != null
|
2010-08-31 09:00:09 +00:00
|
|
|
&& (needsInputViewShown ? mKeyboardSwitcher.getInputView().isShown() : 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);
|
2009-03-19 00:39:49 +00:00
|
|
|
if (!isFullscreenMode()) {
|
|
|
|
outInsets.contentTopInsets = outInsets.visibleTopInsets;
|
|
|
|
}
|
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() {
|
|
|
|
DisplayMetrics dm = getResources().getDisplayMetrics();
|
|
|
|
float displayHeight = dm.heightPixels;
|
|
|
|
// If the display is more than X inches high, don't go to fullscreen mode
|
|
|
|
float dimen = getResources().getDimension(R.dimen.max_height_for_fullscreen);
|
|
|
|
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) {
|
|
|
|
case KeyEvent.KEYCODE_BACK:
|
2010-08-20 05:35:02 +00:00
|
|
|
if (event.getRepeatCount() == 0 && mKeyboardSwitcher.getInputView() != null) {
|
|
|
|
if (mKeyboardSwitcher.getInputView().handleBack()) {
|
2009-03-13 22:11:42 +00:00
|
|
|
return true;
|
2009-03-26 00:39:38 +00:00
|
|
|
} else if (mTutorial != null) {
|
|
|
|
mTutorial.close();
|
|
|
|
mTutorial = null;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2009-03-26 00:39:38 +00:00
|
|
|
case KeyEvent.KEYCODE_DPAD_DOWN:
|
|
|
|
case KeyEvent.KEYCODE_DPAD_UP:
|
|
|
|
case KeyEvent.KEYCODE_DPAD_LEFT:
|
|
|
|
case KeyEvent.KEYCODE_DPAD_RIGHT:
|
|
|
|
// If tutorial is visible, don't allow dpad to work
|
|
|
|
if (mTutorial != null) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
return super.onKeyDown(keyCode, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
|
|
|
switch (keyCode) {
|
|
|
|
case KeyEvent.KEYCODE_DPAD_DOWN:
|
|
|
|
case KeyEvent.KEYCODE_DPAD_UP:
|
|
|
|
case KeyEvent.KEYCODE_DPAD_LEFT:
|
|
|
|
case KeyEvent.KEYCODE_DPAD_RIGHT:
|
2009-03-26 00:39:38 +00:00
|
|
|
// If tutorial is visible, don't allow dpad to work
|
|
|
|
if (mTutorial != null) {
|
|
|
|
return true;
|
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
LatinKeyboardView inputView = mKeyboardSwitcher.getInputView();
|
2009-03-13 22:11:42 +00:00
|
|
|
// Enable shift key and DPAD to do selections
|
2010-08-20 05:35:02 +00:00
|
|
|
if (inputView != null && inputView.isShown()
|
|
|
|
&& inputView.isShifted()) {
|
2010-01-28 18:09:44 +00:00
|
|
|
event = new KeyEvent(event.getDownTime(), event.getEventTime(),
|
2009-03-13 22:11:42 +00:00
|
|
|
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(event);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return super.onKeyUp(keyCode, event);
|
|
|
|
}
|
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
private void revertVoiceInput() {
|
|
|
|
InputConnection ic = getCurrentInputConnection();
|
|
|
|
if (ic != null) ic.commitText("", 1);
|
|
|
|
updateSuggestions();
|
|
|
|
mVoiceInputHighlighted = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void commitVoiceInput() {
|
|
|
|
InputConnection ic = getCurrentInputConnection();
|
|
|
|
if (ic != null) ic.finishComposingText();
|
|
|
|
updateSuggestions();
|
|
|
|
mVoiceInputHighlighted = false;
|
|
|
|
}
|
|
|
|
|
2009-10-12 20:48:35 +00:00
|
|
|
private void reloadKeyboards() {
|
|
|
|
if (mKeyboardSwitcher == null) {
|
|
|
|
mKeyboardSwitcher = new KeyboardSwitcher(this, this);
|
|
|
|
}
|
2010-01-30 04:09:49 +00:00
|
|
|
mKeyboardSwitcher.setLanguageSwitcher(mLanguageSwitcher);
|
2010-08-20 05:35:02 +00:00
|
|
|
if (mKeyboardSwitcher.getInputView() != null
|
|
|
|
&& mKeyboardSwitcher.getKeyboardMode() != KeyboardSwitcher.MODE_NONE) {
|
2010-02-26 19:47:05 +00:00
|
|
|
mKeyboardSwitcher.setVoiceMode(mEnableVoice && mEnableVoiceButton, mVoiceOnPrimary);
|
2010-01-28 20:34:01 +00:00
|
|
|
}
|
2009-10-12 20:48:35 +00:00
|
|
|
mKeyboardSwitcher.makeKeyboards(true);
|
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
private void commitTyped(InputConnection inputConnection) {
|
|
|
|
if (mPredicting) {
|
|
|
|
mPredicting = false;
|
|
|
|
if (mComposing.length() > 0) {
|
|
|
|
if (inputConnection != null) {
|
|
|
|
inputConnection.commitText(mComposing, 1);
|
|
|
|
}
|
|
|
|
mCommittedLength = mComposing.length();
|
|
|
|
TextEntryState.acceptedTyped(mComposing);
|
2010-08-20 05:35:02 +00:00
|
|
|
addToDictionaries(mComposing, AutoDictionary.FREQUENCY_FOR_TYPED);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
updateSuggestions();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-08 02:46:55 +00:00
|
|
|
private void postUpdateShiftKeyState() {
|
|
|
|
mHandler.removeMessages(MSG_UPDATE_SHIFT_STATE);
|
2010-09-01 07:36:24 +00:00
|
|
|
// TODO: Should remove this 300ms delay?
|
2009-08-08 02:46:55 +00:00
|
|
|
mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_UPDATE_SHIFT_STATE), 300);
|
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
public void updateShiftKeyState(EditorInfo attr) {
|
|
|
|
InputConnection ic = getCurrentInputConnection();
|
2010-08-20 09:28:22 +00:00
|
|
|
if (ic != null && attr != null && mKeyboardSwitcher.isAlphabetMode()) {
|
2010-09-01 16:35:24 +00:00
|
|
|
mKeyboardSwitcher.setShifted(mShiftKeyState.isMomentary() || mCapsLock
|
|
|
|
|| getCursorCapsMode(ic, attr) != 0);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
}
|
2010-01-24 15:34:07 +00:00
|
|
|
|
|
|
|
private int getCursorCapsMode(InputConnection ic, EditorInfo attr) {
|
|
|
|
int caps = 0;
|
|
|
|
EditorInfo ei = getCurrentInputEditorInfo();
|
|
|
|
if (mAutoCap && ei != null && ei.inputType != EditorInfo.TYPE_NULL) {
|
|
|
|
caps = ic.getCursorCapsMode(attr.inputType);
|
|
|
|
}
|
|
|
|
return caps;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
&& lastTwo.charAt(0) == KEYCODE_SPACE && isSentenceSeparator(lastTwo.charAt(1))) {
|
|
|
|
ic.beginBatchEdit();
|
|
|
|
ic.deleteSurroundingText(2, 0);
|
|
|
|
ic.commitText(lastTwo.charAt(1) + " ", 1);
|
|
|
|
ic.endBatchEdit();
|
|
|
|
updateShiftKeyState(getCurrentInputEditorInfo());
|
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
|
|
|
|
&& lastThree.charAt(0) == KEYCODE_PERIOD
|
|
|
|
&& lastThree.charAt(1) == KEYCODE_SPACE
|
|
|
|
&& lastThree.charAt(2) == KEYCODE_PERIOD) {
|
|
|
|
ic.beginBatchEdit();
|
|
|
|
ic.deleteSurroundingText(3, 0);
|
|
|
|
ic.commitText(" ..", 1);
|
|
|
|
ic.endBatchEdit();
|
|
|
|
updateShiftKeyState(getCurrentInputEditorInfo());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
private void doubleSpace() {
|
|
|
|
//if (!mAutoPunctuate) return;
|
|
|
|
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))
|
|
|
|
&& lastThree.charAt(1) == KEYCODE_SPACE && lastThree.charAt(2) == KEYCODE_SPACE) {
|
|
|
|
ic.beginBatchEdit();
|
|
|
|
ic.deleteSurroundingText(2, 0);
|
|
|
|
ic.commitText(". ", 1);
|
|
|
|
ic.endBatchEdit();
|
|
|
|
updateShiftKeyState(getCurrentInputEditorInfo());
|
2010-02-07 00:34:43 +00:00
|
|
|
mJustAddedAutoSpace = true;
|
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
|
|
|
|
&& lastOne.charAt(0) == KEYCODE_PERIOD
|
|
|
|
&& text.charAt(0) == KEYCODE_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
|
|
|
|
&& lastOne.charAt(0) == KEYCODE_SPACE) {
|
|
|
|
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
|
|
|
|
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-09-02 19:25:31 +00:00
|
|
|
private boolean hasMultipleEnabledIMEs() {
|
|
|
|
return ((InputMethodManager) getSystemService(
|
|
|
|
INPUT_METHOD_SERVICE)).getEnabledInputMethodList().size() > 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void showInputMethodPicker() {
|
|
|
|
((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE))
|
|
|
|
.showInputMethodPicker();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void onOptionKeyPressed() {
|
|
|
|
if (!isShowingOptionDialog()) {
|
|
|
|
if (hasMultipleEnabledIMEs()) {
|
|
|
|
showOptionsMenu();
|
|
|
|
} else {
|
|
|
|
launchSettings();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void onOptionKeyLongPressed() {
|
|
|
|
if (!isShowingOptionDialog()) {
|
|
|
|
if (hasMultipleEnabledIMEs()) {
|
|
|
|
showInputMethodPicker();
|
|
|
|
} else {
|
|
|
|
launchSettings();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean isShowingOptionDialog() {
|
|
|
|
return mOptionsDialog != null && mOptionsDialog.isShowing();
|
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
// Implementation of KeyboardViewListener
|
|
|
|
|
2010-08-25 12:27:13 +00:00
|
|
|
public void onKey(int primaryCode, int[] keyCodes, int x, int y) {
|
2009-03-13 22:11:42 +00:00
|
|
|
long when = SystemClock.uptimeMillis();
|
2010-01-28 18:09:44 +00:00
|
|
|
if (primaryCode != Keyboard.KEYCODE_DELETE ||
|
2009-03-13 22:11:42 +00:00
|
|
|
when > mLastKeyTime + QUICK_PRESS) {
|
|
|
|
mDeleteCount = 0;
|
|
|
|
}
|
|
|
|
mLastKeyTime = when;
|
2010-09-09 05:43:17 +00:00
|
|
|
final boolean distinctMultiTouch = mKeyboardSwitcher.hasDistinctMultitouch();
|
2009-03-13 22:11:42 +00:00
|
|
|
switch (primaryCode) {
|
|
|
|
case Keyboard.KEYCODE_DELETE:
|
|
|
|
handleBackspace();
|
|
|
|
mDeleteCount++;
|
2010-08-20 05:35:02 +00:00
|
|
|
LatinImeLogger.logOnDelete();
|
2009-03-13 22:11:42 +00:00
|
|
|
break;
|
|
|
|
case Keyboard.KEYCODE_SHIFT:
|
2010-09-06 05:26:46 +00:00
|
|
|
// Shift key is handled in onPress() when device has distinct multi-touch panel.
|
2010-09-09 05:43:17 +00:00
|
|
|
if (!distinctMultiTouch)
|
2010-09-06 05:26:46 +00:00
|
|
|
handleShift();
|
2009-03-13 22:11:42 +00:00
|
|
|
break;
|
2010-09-09 05:43:17 +00:00
|
|
|
case Keyboard.KEYCODE_MODE_CHANGE:
|
|
|
|
// Symbol key is handled in onPress() when device has distinct multi-touch panel.
|
|
|
|
if (!distinctMultiTouch)
|
|
|
|
changeKeyboardMode();
|
|
|
|
break;
|
2009-03-13 22:11:42 +00:00
|
|
|
case Keyboard.KEYCODE_CANCEL:
|
2010-09-02 19:25:31 +00:00
|
|
|
if (!isShowingOptionDialog()) {
|
2009-03-13 22:11:42 +00:00
|
|
|
handleClose();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LatinKeyboardView.KEYCODE_OPTIONS:
|
2010-09-02 19:25:31 +00:00
|
|
|
onOptionKeyPressed();
|
|
|
|
break;
|
|
|
|
case LatinKeyboardView.KEYCODE_OPTIONS_LONGPRESS:
|
|
|
|
onOptionKeyLongPressed();
|
2009-03-13 22:11:42 +00:00
|
|
|
break;
|
2010-01-22 21:57:20 +00:00
|
|
|
case LatinKeyboardView.KEYCODE_NEXT_LANGUAGE:
|
2010-01-30 04:09:49 +00:00
|
|
|
toggleLanguage(false, true);
|
|
|
|
break;
|
|
|
|
case LatinKeyboardView.KEYCODE_PREV_LANGUAGE:
|
|
|
|
toggleLanguage(false, false);
|
2009-10-12 20:48:35 +00:00
|
|
|
break;
|
2010-01-16 20:21:23 +00:00
|
|
|
case LatinKeyboardView.KEYCODE_VOICE:
|
|
|
|
if (VOICE_INSTALLED) {
|
|
|
|
startListening(false /* was a button press, was not a swipe */);
|
|
|
|
}
|
|
|
|
break;
|
2010-01-27 05:25:29 +00:00
|
|
|
case 9 /*Tab*/:
|
2010-02-08 15:34:58 +00:00
|
|
|
sendDownUpKeyEvents(KeyEvent.KEYCODE_TAB);
|
2010-01-27 05:25:29 +00:00
|
|
|
break;
|
2009-03-13 22:11:42 +00:00
|
|
|
default:
|
2010-02-07 00:34:43 +00:00
|
|
|
if (primaryCode != KEYCODE_ENTER) {
|
|
|
|
mJustAddedAutoSpace = false;
|
|
|
|
}
|
2010-08-25 12:27:13 +00:00
|
|
|
LatinImeLogger.logOnInputChar((char)primaryCode, x, y);
|
2009-03-13 22:11:42 +00:00
|
|
|
if (isWordSeparator(primaryCode)) {
|
|
|
|
handleSeparator(primaryCode);
|
|
|
|
} else {
|
|
|
|
handleCharacter(primaryCode, keyCodes);
|
|
|
|
}
|
|
|
|
// Cancel the just reverted state
|
|
|
|
mJustRevertedSeparator = null;
|
|
|
|
}
|
2009-07-21 22:47:11 +00:00
|
|
|
if (mKeyboardSwitcher.onKey(primaryCode)) {
|
|
|
|
changeKeyboardMode();
|
|
|
|
}
|
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
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
public void onText(CharSequence text) {
|
2010-02-21 22:22:25 +00:00
|
|
|
if (VOICE_INSTALLED && mVoiceInputHighlighted) {
|
|
|
|
commitVoiceInput();
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
InputConnection ic = getCurrentInputConnection();
|
|
|
|
if (ic == null) return;
|
2010-08-20 05:35:02 +00:00
|
|
|
abortCorrection(false);
|
2009-03-13 22:11:42 +00:00
|
|
|
ic.beginBatchEdit();
|
|
|
|
if (mPredicting) {
|
|
|
|
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();
|
|
|
|
updateShiftKeyState(getCurrentInputEditorInfo());
|
|
|
|
mJustRevertedSeparator = null;
|
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-09-07 06:37:59 +00:00
|
|
|
public void onCancel() {
|
|
|
|
// User released a finger outside any key
|
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
private void handleBackspace() {
|
2010-01-16 20:21:23 +00:00
|
|
|
if (VOICE_INSTALLED && mVoiceInputHighlighted) {
|
2010-03-04 14:34:21 +00:00
|
|
|
mVoiceInput.incrementTextModificationDeleteCount(
|
|
|
|
mVoiceResults.candidates.get(0).toString().length());
|
2010-01-16 20:21:23 +00:00
|
|
|
revertVoiceInput();
|
|
|
|
return;
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
boolean deleteChar = false;
|
|
|
|
InputConnection ic = getCurrentInputConnection();
|
|
|
|
if (ic == null) return;
|
2010-03-04 14:34:21 +00:00
|
|
|
|
2010-08-20 05:35:02 +00:00
|
|
|
ic.beginBatchEdit();
|
|
|
|
|
2010-03-04 14:34:21 +00:00
|
|
|
if (mAfterVoiceInput) {
|
|
|
|
// Don't log delete if the user is pressing delete at
|
|
|
|
// the beginning of the text box (hence not deleting anything)
|
|
|
|
if (mVoiceInput.getCursorPos() > 0) {
|
|
|
|
// If anything was selected before the delete was pressed, increment the
|
|
|
|
// delete count by the length of the selection
|
|
|
|
int deleteLen = mVoiceInput.getSelectionSpan() > 0 ?
|
|
|
|
mVoiceInput.getSelectionSpan() : 1;
|
|
|
|
mVoiceInput.incrementTextModificationDeleteCount(deleteLen);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
if (mPredicting) {
|
|
|
|
final int length = mComposing.length();
|
|
|
|
if (length > 0) {
|
|
|
|
mComposing.delete(length - 1, length);
|
|
|
|
mWord.deleteLast();
|
|
|
|
ic.setComposingText(mComposing, 1);
|
|
|
|
if (mComposing.length() == 0) {
|
|
|
|
mPredicting = false;
|
|
|
|
}
|
|
|
|
postUpdateSuggestions();
|
|
|
|
} else {
|
|
|
|
ic.deleteSurroundingText(1, 0);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
deleteChar = true;
|
|
|
|
}
|
2009-08-08 02:46:55 +00:00
|
|
|
postUpdateShiftKeyState();
|
2009-03-13 22:11:42 +00:00
|
|
|
TextEntryState.backspace();
|
2010-08-20 05:35:02 +00:00
|
|
|
if (TextEntryState.getState() == TextEntryState.State.UNDO_COMMIT) {
|
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;
|
2010-04-01 13:28:52 +00:00
|
|
|
} else if (mEnteredText != null && sameAsTextBeforeCursor(ic, mEnteredText)) {
|
|
|
|
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
|
|
|
|
// "Tap again to save".
|
|
|
|
// 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
|
|
|
}
|
|
|
|
}
|
|
|
|
mJustRevertedSeparator = null;
|
2010-08-20 05:35:02 +00:00
|
|
|
ic.endBatchEdit();
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2010-09-01 16:35:24 +00:00
|
|
|
private void resetShift() {
|
|
|
|
handleShiftInternal(true);
|
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
private void handleShift() {
|
2010-09-01 16:35:24 +00:00
|
|
|
handleShiftInternal(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handleShiftInternal(boolean forceNormal) {
|
2009-12-04 19:58:57 +00:00
|
|
|
mHandler.removeMessages(MSG_UPDATE_SHIFT_STATE);
|
2010-08-20 05:35:02 +00:00
|
|
|
KeyboardSwitcher switcher = mKeyboardSwitcher;
|
|
|
|
LatinKeyboardView inputView = switcher.getInputView();
|
|
|
|
if (switcher.isAlphabetMode()) {
|
2010-09-01 16:35:24 +00:00
|
|
|
if (mCapsLock || forceNormal) {
|
2010-08-20 05:35:02 +00:00
|
|
|
mCapsLock = false;
|
|
|
|
switcher.setShifted(false);
|
|
|
|
} else if (inputView != null) {
|
|
|
|
if (inputView.isShifted()) {
|
|
|
|
mCapsLock = true;
|
|
|
|
switcher.setShiftLocked(true);
|
|
|
|
} else {
|
|
|
|
switcher.setShifted(true);
|
|
|
|
}
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
} else {
|
2010-08-20 05:35:02 +00:00
|
|
|
switcher.toggleShift();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void abortCorrection(boolean force) {
|
|
|
|
if (force || TextEntryState.isCorrecting()) {
|
|
|
|
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
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
private void handleCharacter(int primaryCode, int[] keyCodes) {
|
2010-01-16 20:21:23 +00:00
|
|
|
if (VOICE_INSTALLED && mVoiceInputHighlighted) {
|
|
|
|
commitVoiceInput();
|
|
|
|
}
|
2010-03-04 14:34:21 +00:00
|
|
|
|
|
|
|
if (mAfterVoiceInput) {
|
|
|
|
// Assume input length is 1. This assumption fails for smiley face insertions.
|
|
|
|
mVoiceInput.incrementTextModificationInsertCount(1);
|
|
|
|
}
|
2010-08-26 19:22:58 +00:00
|
|
|
if (mLastSelectionStart == mLastSelectionEnd && TextEntryState.isCorrecting()) {
|
|
|
|
abortCorrection(false);
|
|
|
|
}
|
2010-03-04 14:34:21 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
if (isAlphabet(primaryCode) && isPredictionOn() && !isCursorTouchingWord()) {
|
|
|
|
if (!mPredicting) {
|
|
|
|
mPredicting = true;
|
|
|
|
mComposing.setLength(0);
|
2010-08-20 05:35:02 +00:00
|
|
|
saveWordInHistory(mBestWord);
|
2009-03-13 22:11:42 +00:00
|
|
|
mWord.reset();
|
|
|
|
}
|
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
if (mKeyboardSwitcher.getInputView().isShifted()) {
|
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-08-20 05:35:02 +00:00
|
|
|
primaryCode = keyCodes[0];
|
2010-09-14 07:22:08 +00:00
|
|
|
if (mKeyboardSwitcher.isAlphabetMode() && Character.isLowerCase(primaryCode)) {
|
|
|
|
int upperCaseCode = Character.toUpperCase(primaryCode);
|
|
|
|
if (upperCaseCode != primaryCode) {
|
|
|
|
primaryCode = upperCaseCode;
|
|
|
|
} else {
|
|
|
|
// Some keys, such as [eszett], have upper case as multi-characters.
|
|
|
|
String upperCase = new String(new int[] {primaryCode}, 0, 1).toUpperCase();
|
|
|
|
onText(upperCase);
|
|
|
|
return;
|
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
if (mPredicting) {
|
2010-08-20 05:35:02 +00:00
|
|
|
if (mKeyboardSwitcher.getInputView().isShifted()
|
|
|
|
&& mKeyboardSwitcher.isAlphabetMode()
|
|
|
|
&& mComposing.length() == 0) {
|
2009-03-13 22:11:42 +00:00
|
|
|
mWord.setCapitalized(true);
|
|
|
|
}
|
|
|
|
mComposing.append((char) primaryCode);
|
|
|
|
mWord.add(primaryCode, keyCodes);
|
|
|
|
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) {
|
|
|
|
mWord.setAutoCapitalized(
|
|
|
|
getCursorCapsMode(ic, getCurrentInputEditorInfo()) != 0);
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
ic.setComposingText(mComposing, 1);
|
|
|
|
}
|
|
|
|
postUpdateSuggestions();
|
|
|
|
} else {
|
|
|
|
sendKeyChar((char)primaryCode);
|
|
|
|
}
|
2009-10-12 19:59:34 +00:00
|
|
|
updateShiftKeyState(getCurrentInputEditorInfo());
|
2010-08-20 05:35:02 +00:00
|
|
|
if (LatinIME.PERF_DEBUG) measureCps();
|
2009-03-13 22:11:42 +00:00
|
|
|
TextEntryState.typedCharacter((char) primaryCode, isWordSeparator(primaryCode));
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handleSeparator(int primaryCode) {
|
2010-01-16 20:21:23 +00:00
|
|
|
if (VOICE_INSTALLED && mVoiceInputHighlighted) {
|
|
|
|
commitVoiceInput();
|
|
|
|
}
|
2010-03-04 14:34:21 +00:00
|
|
|
|
|
|
|
if (mAfterVoiceInput){
|
|
|
|
// Assume input length is 1. This assumption fails for smiley face insertions.
|
|
|
|
mVoiceInput.incrementTextModificationInsertPunctuationCount(1);
|
|
|
|
}
|
|
|
|
|
2010-08-03 18:47:42 +00:00
|
|
|
// Should dismiss the "Tap again to save" message when handling separator
|
|
|
|
if (mCandidateView != null && mCandidateView.dismissAddToDictionaryHint()) {
|
|
|
|
postUpdateSuggestions();
|
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
boolean pickedDefault = false;
|
|
|
|
// Handle separator
|
|
|
|
InputConnection ic = getCurrentInputConnection();
|
|
|
|
if (ic != null) {
|
|
|
|
ic.beginBatchEdit();
|
2010-08-20 05:35:02 +00:00
|
|
|
abortCorrection(false);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
if (mPredicting) {
|
|
|
|
// 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.
|
2010-01-28 18:09:44 +00:00
|
|
|
if (mAutoCorrectOn && primaryCode != '\'' &&
|
|
|
|
(mJustRevertedSeparator == null
|
|
|
|
|| mJustRevertedSeparator.length() == 0
|
2009-03-13 22:11:42 +00:00
|
|
|
|| mJustRevertedSeparator.charAt(0) != primaryCode)) {
|
2010-08-20 05:35:02 +00:00
|
|
|
pickedDefault = pickDefaultSuggestion();
|
2010-02-07 00:34:43 +00:00
|
|
|
// Picked the suggestion by the space key. We consider this
|
|
|
|
// as "added an auto space".
|
|
|
|
if (primaryCode == KEYCODE_SPACE) {
|
|
|
|
mJustAddedAutoSpace = true;
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
} else {
|
|
|
|
commitTyped(ic);
|
|
|
|
}
|
|
|
|
}
|
2010-02-07 00:34:43 +00:00
|
|
|
if (mJustAddedAutoSpace && primaryCode == KEYCODE_ENTER) {
|
|
|
|
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.
|
2010-08-20 05:35:02 +00:00
|
|
|
if (TextEntryState.getState() == TextEntryState.State.PUNCTUATION_AFTER_ACCEPTED
|
2010-02-22 14:55:45 +00:00
|
|
|
&& primaryCode == KEYCODE_PERIOD) {
|
|
|
|
reswapPeriodAndSpace();
|
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
TextEntryState.typedCharacter((char) primaryCode, true);
|
2010-08-20 05:35:02 +00:00
|
|
|
if (TextEntryState.getState() == TextEntryState.State.PUNCTUATION_AFTER_ACCEPTED
|
2009-03-13 22:11:42 +00:00
|
|
|
&& primaryCode != KEYCODE_ENTER) {
|
|
|
|
swapPunctuationAndSpace();
|
2010-02-07 00:34:43 +00:00
|
|
|
} else if (isPredictionOn() && primaryCode == KEYCODE_SPACE) {
|
2009-03-13 22:11:42 +00:00
|
|
|
doubleSpace();
|
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
if (pickedDefault) {
|
|
|
|
TextEntryState.backToAcceptedDefault(mWord.getTypedWord());
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
updateShiftKeyState(getCurrentInputEditorInfo());
|
|
|
|
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());
|
2010-01-16 20:21:23 +00:00
|
|
|
if (VOICE_INSTALLED & mRecognizing) {
|
|
|
|
mVoiceInput.cancel();
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
requestHideSelf(0);
|
2010-08-20 05:35:02 +00:00
|
|
|
mKeyboardSwitcher.getInputView().closing();
|
2009-03-13 22:11:42 +00:00
|
|
|
TextEntryState.endSession();
|
|
|
|
}
|
|
|
|
|
2010-08-20 05:35:02 +00:00
|
|
|
private void saveWordInHistory(CharSequence result) {
|
|
|
|
if (mWord.size() <= 1) {
|
|
|
|
mWord.reset();
|
|
|
|
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();
|
|
|
|
TypedWordAlternatives entry = new TypedWordAlternatives(resultCopy,
|
|
|
|
new WordComposer(mWord));
|
|
|
|
mWordHistory.add(entry);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void postUpdateSuggestions() {
|
|
|
|
mHandler.removeMessages(MSG_UPDATE_SUGGESTIONS);
|
|
|
|
mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_UPDATE_SUGGESTIONS), 100);
|
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-08-20 05:35:02 +00:00
|
|
|
private void postUpdateOldSuggestions() {
|
|
|
|
mHandler.removeMessages(MSG_UPDATE_OLD_SUGGESTIONS);
|
|
|
|
mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_UPDATE_OLD_SUGGESTIONS), 300);
|
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
private boolean isPredictionOn() {
|
2010-08-31 09:00:09 +00:00
|
|
|
return mPredictionOn;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
private boolean isCandidateStripVisible() {
|
2009-03-26 00:39:38 +00:00
|
|
|
return isPredictionOn() && mShowSuggestions;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
public void onCancelVoice() {
|
|
|
|
if (mRecognizing) {
|
|
|
|
switchToKeyboardView();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void switchToKeyboardView() {
|
|
|
|
mHandler.post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
mRecognizing = false;
|
2010-08-20 05:35:02 +00:00
|
|
|
if (mKeyboardSwitcher.getInputView() != null) {
|
|
|
|
setInputView(mKeyboardSwitcher.getInputView());
|
2010-01-16 20:21:23 +00:00
|
|
|
}
|
|
|
|
updateInputViewShown();
|
|
|
|
}});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void switchToRecognitionStatusView() {
|
2010-03-07 15:27:05 +00:00
|
|
|
final boolean configChanged = mConfigurationChanging;
|
|
|
|
mHandler.post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
mRecognizing = true;
|
|
|
|
View v = mVoiceInput.getView();
|
|
|
|
ViewParent p = v.getParent();
|
|
|
|
if (p != null && p instanceof ViewGroup) {
|
|
|
|
((ViewGroup)v.getParent()).removeView(v);
|
|
|
|
}
|
|
|
|
setInputView(v);
|
|
|
|
updateInputViewShown();
|
|
|
|
if (configChanged) {
|
|
|
|
mVoiceInput.onConfigurationChanged();
|
|
|
|
}
|
|
|
|
}});
|
2010-01-16 20:21:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void startListening(boolean swipe) {
|
|
|
|
if (!mHasUsedVoiceInput ||
|
|
|
|
(!mLocaleSupportedForVoiceInput && !mHasUsedVoiceInputUnsupportedLocale)) {
|
|
|
|
// Calls reallyStartListening if user clicks OK, does nothing if user clicks Cancel.
|
|
|
|
showVoiceWarningDialog(swipe);
|
|
|
|
} else {
|
|
|
|
reallyStartListening(swipe);
|
|
|
|
}
|
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
private void reallyStartListening(boolean swipe) {
|
|
|
|
if (!mHasUsedVoiceInput) {
|
|
|
|
// The user has started a voice input, so remember that in the
|
|
|
|
// future (so we don't show the warning dialog after the first run).
|
|
|
|
SharedPreferences.Editor editor =
|
|
|
|
PreferenceManager.getDefaultSharedPreferences(this).edit();
|
|
|
|
editor.putBoolean(PREF_HAS_USED_VOICE_INPUT, true);
|
2010-09-12 12:05:25 +00:00
|
|
|
SharedPreferencesCompat.apply(editor);
|
2010-01-16 20:21:23 +00:00
|
|
|
mHasUsedVoiceInput = true;
|
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
if (!mLocaleSupportedForVoiceInput && !mHasUsedVoiceInputUnsupportedLocale) {
|
|
|
|
// The user has started a voice input from an unsupported locale, so remember that
|
|
|
|
// in the future (so we don't show the warning dialog the next time they do this).
|
|
|
|
SharedPreferences.Editor editor =
|
|
|
|
PreferenceManager.getDefaultSharedPreferences(this).edit();
|
|
|
|
editor.putBoolean(PREF_HAS_USED_VOICE_INPUT_UNSUPPORTED_LOCALE, true);
|
2010-09-12 12:05:25 +00:00
|
|
|
SharedPreferencesCompat.apply(editor);
|
2010-01-16 20:21:23 +00:00
|
|
|
mHasUsedVoiceInputUnsupportedLocale = true;
|
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
// Clear N-best suggestions
|
2010-08-26 19:22:58 +00:00
|
|
|
clearSuggestions();
|
2010-01-16 20:21:23 +00:00
|
|
|
|
|
|
|
FieldContext context = new FieldContext(
|
2010-02-05 02:31:40 +00:00
|
|
|
getCurrentInputConnection(),
|
|
|
|
getCurrentInputEditorInfo(),
|
|
|
|
mLanguageSwitcher.getInputLanguage(),
|
|
|
|
mLanguageSwitcher.getEnabledLanguages());
|
2010-01-16 20:21:23 +00:00
|
|
|
mVoiceInput.startListening(context, swipe);
|
|
|
|
switchToRecognitionStatusView();
|
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
private void showVoiceWarningDialog(final boolean swipe) {
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
|
builder.setCancelable(true);
|
|
|
|
builder.setIcon(R.drawable.ic_mic_dialog);
|
|
|
|
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
|
|
|
public void onClick(DialogInterface dialog, int whichButton) {
|
|
|
|
mVoiceInput.logKeyboardWarningDialogOk();
|
|
|
|
reallyStartListening(swipe);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
|
|
|
|
public void onClick(DialogInterface dialog, int whichButton) {
|
|
|
|
mVoiceInput.logKeyboardWarningDialogCancel();
|
|
|
|
}
|
|
|
|
});
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
if (mLocaleSupportedForVoiceInput) {
|
|
|
|
String message = getString(R.string.voice_warning_may_not_understand) + "\n\n" +
|
|
|
|
getString(R.string.voice_warning_how_to_turn_off);
|
|
|
|
builder.setMessage(message);
|
|
|
|
} else {
|
|
|
|
String message = getString(R.string.voice_warning_locale_not_supported) + "\n\n" +
|
|
|
|
getString(R.string.voice_warning_may_not_understand) + "\n\n" +
|
|
|
|
getString(R.string.voice_warning_how_to_turn_off);
|
|
|
|
builder.setMessage(message);
|
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
builder.setTitle(R.string.voice_warning_title);
|
|
|
|
mVoiceWarningDialog = builder.create();
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
Window window = mVoiceWarningDialog.getWindow();
|
|
|
|
WindowManager.LayoutParams lp = window.getAttributes();
|
2010-08-20 05:35:02 +00:00
|
|
|
lp.token = mKeyboardSwitcher.getInputView().getWindowToken();
|
2010-01-16 20:21:23 +00:00
|
|
|
lp.type = WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
|
|
|
|
window.setAttributes(lp);
|
|
|
|
window.addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
|
|
|
|
mVoiceInput.logKeyboardWarningDialogShown();
|
|
|
|
mVoiceWarningDialog.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onVoiceResults(List<String> candidates,
|
|
|
|
Map<String, List<CharSequence>> alternatives) {
|
|
|
|
if (!mRecognizing) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mVoiceResults.candidates = candidates;
|
|
|
|
mVoiceResults.alternatives = alternatives;
|
|
|
|
mHandler.sendMessage(mHandler.obtainMessage(MSG_VOICE_RESULTS));
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handleVoiceResults() {
|
|
|
|
mAfterVoiceInput = true;
|
|
|
|
mImmediatelyAfterVoiceInput = true;
|
|
|
|
|
|
|
|
InputConnection ic = getCurrentInputConnection();
|
|
|
|
if (!isFullscreenMode()) {
|
|
|
|
// Start listening for updates to the text from typing, etc.
|
|
|
|
if (ic != null) {
|
|
|
|
ExtractedTextRequest req = new ExtractedTextRequest();
|
|
|
|
ic.getExtractedText(req, InputConnection.GET_EXTRACTED_TEXT_MONITOR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
vibrate();
|
|
|
|
switchToKeyboardView();
|
|
|
|
|
|
|
|
final List<CharSequence> nBest = new ArrayList<CharSequence>();
|
|
|
|
boolean capitalizeFirstWord = preferCapitalization()
|
2010-08-20 05:35:02 +00:00
|
|
|
|| (mKeyboardSwitcher.isAlphabetMode()
|
|
|
|
&& mKeyboardSwitcher.getInputView().isShifted());
|
2010-01-16 20:21:23 +00:00
|
|
|
for (String c : mVoiceResults.candidates) {
|
|
|
|
if (capitalizeFirstWord) {
|
|
|
|
c = Character.toUpperCase(c.charAt(0)) + c.substring(1, c.length());
|
|
|
|
}
|
|
|
|
nBest.add(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nBest.size() == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
String bestResult = nBest.get(0).toString();
|
|
|
|
|
2010-03-04 14:34:21 +00:00
|
|
|
mVoiceInput.logVoiceInputDelivered(bestResult.length());
|
2010-01-16 20:21:23 +00:00
|
|
|
|
|
|
|
mHints.registerVoiceResult(bestResult);
|
|
|
|
|
|
|
|
if (ic != null) ic.beginBatchEdit(); // To avoid extra updates on committing older text
|
|
|
|
|
|
|
|
commitTyped(ic);
|
|
|
|
EditingUtil.appendText(ic, bestResult);
|
|
|
|
|
|
|
|
if (ic != null) ic.endBatchEdit();
|
|
|
|
|
|
|
|
mVoiceInputHighlighted = true;
|
|
|
|
mWordToSuggestions.putAll(mVoiceResults.alternatives);
|
2010-08-26 19:22:58 +00:00
|
|
|
}
|
2010-01-16 20:21:23 +00:00
|
|
|
|
2010-08-26 19:22:58 +00:00
|
|
|
private void clearSuggestions() {
|
|
|
|
setSuggestions(null, false, false, false);
|
2010-01-16 20:21:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void setSuggestions(
|
|
|
|
List<CharSequence> suggestions,
|
|
|
|
boolean completions,
|
|
|
|
boolean typedWordValid,
|
|
|
|
boolean haveMinimalSuggestion) {
|
|
|
|
|
|
|
|
if (mIsShowingHint) {
|
|
|
|
setCandidatesView(mCandidateViewContainer);
|
|
|
|
mIsShowingHint = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mCandidateView != null) {
|
|
|
|
mCandidateView.setSuggestions(
|
|
|
|
suggestions, completions, typedWordValid, haveMinimalSuggestion);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
private void updateSuggestions() {
|
2010-08-20 05:35:02 +00:00
|
|
|
LatinKeyboardView inputView = mKeyboardSwitcher.getInputView();
|
|
|
|
((LatinKeyboard) inputView.getKeyboard()).setPreferredLetters(null);
|
2010-02-05 22:07:04 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
// Check if we have a suggestion engine attached.
|
2010-01-16 20:21:23 +00:00
|
|
|
if ((mSuggest == null || !isPredictionOn()) && !mVoiceInputHighlighted) {
|
2009-03-13 22:11:42 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-01-16 20:21:23 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
if (!mPredicting) {
|
2010-02-03 23:35:49 +00:00
|
|
|
setNextSuggestions();
|
2009-03-13 22:11:42 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
showSuggestions(mWord);
|
|
|
|
}
|
|
|
|
|
|
|
|
private List<CharSequence> getTypedSuggestions(WordComposer word) {
|
|
|
|
List<CharSequence> stringList = mSuggest.getSuggestions(
|
|
|
|
mKeyboardSwitcher.getInputView(), word, false, null);
|
|
|
|
return stringList;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void showCorrections(WordAlternatives alternatives) {
|
|
|
|
List<CharSequence> stringList = alternatives.getAlternatives();
|
|
|
|
((LatinKeyboard) mKeyboardSwitcher.getInputView().getKeyboard()).setPreferredLetters(null);
|
|
|
|
showSuggestions(stringList, alternatives.getOriginalWord(), false, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void showSuggestions(WordComposer word) {
|
2010-08-26 19:22:58 +00:00
|
|
|
// long startTime = System.currentTimeMillis(); // TIME MEASUREMENT!
|
2010-08-20 05:35:02 +00:00
|
|
|
// TODO Maybe need better way of retrieving previous word
|
|
|
|
CharSequence prevWord = EditingUtil.getPreviousWord(getCurrentInputConnection(),
|
|
|
|
mWordSeparators);
|
|
|
|
List<CharSequence> stringList = mSuggest.getSuggestions(
|
2010-08-26 19:22:58 +00:00
|
|
|
mKeyboardSwitcher.getInputView(), word, false, prevWord);
|
|
|
|
// long stopTime = System.currentTimeMillis(); // TIME MEASUREMENT!
|
|
|
|
// Log.d("LatinIME","Suggest Total Time - " + (stopTime - startTime));
|
2009-03-13 22:11:42 +00:00
|
|
|
|
2010-02-05 22:07:04 +00:00
|
|
|
int[] nextLettersFrequencies = mSuggest.getNextLettersFrequencies();
|
|
|
|
|
2010-08-20 05:35:02 +00:00
|
|
|
((LatinKeyboard) mKeyboardSwitcher.getInputView().getKeyboard()).setPreferredLetters(
|
|
|
|
nextLettersFrequencies);
|
2010-02-05 22:07:04 +00:00
|
|
|
|
2010-03-24 23:44:31 +00:00
|
|
|
boolean correctionAvailable = !mInputTypeNoAutoCorrect && mSuggest.hasMinimalCorrection();
|
2009-03-13 22:11:42 +00:00
|
|
|
//|| mCorrectionMode == mSuggest.CORRECTION_FULL;
|
2010-08-20 05:35:02 +00:00
|
|
|
CharSequence typedWord = word.getTypedWord();
|
2009-03-13 22:11:42 +00:00
|
|
|
// If we're in basic correct
|
2009-12-01 19:44:22 +00:00
|
|
|
boolean typedWordValid = mSuggest.isValidWord(typedWord) ||
|
2010-08-20 05:35:02 +00:00
|
|
|
(preferCapitalization()
|
|
|
|
&& mSuggest.isValidWord(typedWord.toString().toLowerCase()));
|
|
|
|
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();
|
|
|
|
correctionAvailable &= !TextEntryState.isCorrecting();
|
|
|
|
|
|
|
|
showSuggestions(stringList, typedWord, typedWordValid, correctionAvailable);
|
|
|
|
}
|
2009-07-23 19:17:48 +00:00
|
|
|
|
2010-08-20 05:35:02 +00:00
|
|
|
private void showSuggestions(List<CharSequence> stringList, CharSequence typedWord,
|
|
|
|
boolean typedWordValid, boolean correctionAvailable) {
|
2010-01-16 20:21:23 +00:00
|
|
|
setSuggestions(stringList, false, typedWordValid, correctionAvailable);
|
2009-03-13 22:11:42 +00:00
|
|
|
if (stringList.size() > 0) {
|
|
|
|
if (correctionAvailable && !typedWordValid && stringList.size() > 1) {
|
|
|
|
mBestWord = stringList.get(1);
|
|
|
|
} else {
|
|
|
|
mBestWord = typedWord;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mBestWord = null;
|
|
|
|
}
|
|
|
|
setCandidatesViewShown(isCandidateStripVisible() || mCompletionOn);
|
|
|
|
}
|
|
|
|
|
2010-08-20 05:35:02 +00:00
|
|
|
private boolean pickDefaultSuggestion() {
|
2009-03-13 22:11:42 +00:00
|
|
|
// Complete any pending candidate query first
|
|
|
|
if (mHandler.hasMessages(MSG_UPDATE_SUGGESTIONS)) {
|
|
|
|
mHandler.removeMessages(MSG_UPDATE_SUGGESTIONS);
|
|
|
|
updateSuggestions();
|
|
|
|
}
|
2010-03-18 04:37:25 +00:00
|
|
|
if (mBestWord != null && mBestWord.length() > 0) {
|
2009-03-13 22:11:42 +00:00
|
|
|
TextEntryState.acceptedDefault(mWord.getTypedWord(), mBestWord);
|
|
|
|
mJustAccepted = true;
|
2010-08-20 05:35:02 +00:00
|
|
|
pickSuggestion(mBestWord, false);
|
2010-02-25 18:37:19 +00:00
|
|
|
// Add the word to the auto dictionary if it's not a known word
|
2010-08-20 05:35:02 +00:00
|
|
|
addToDictionaries(mBestWord, AutoDictionary.FREQUENCY_FOR_TYPED);
|
|
|
|
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-08-20 05:35:02 +00:00
|
|
|
List<CharSequence> suggestions = mCandidateView.getSuggestions();
|
2010-08-26 20:31:54 +00:00
|
|
|
if (mAfterVoiceInput && mShowingVoiceSuggestions) {
|
2010-03-04 14:34:21 +00:00
|
|
|
mVoiceInput.flushAllTextModificationCounters();
|
|
|
|
// send this intent AFTER logging any prior aggregated edits.
|
2010-08-26 20:31:54 +00:00
|
|
|
mVoiceInput.logTextModifiedByChooseSuggestion(suggestion.toString(), index,
|
|
|
|
mWordSeparators,
|
|
|
|
getCurrentInputConnection());
|
2010-03-04 14:34:21 +00:00
|
|
|
}
|
|
|
|
|
2010-08-20 05:35:02 +00:00
|
|
|
final boolean correcting = TextEntryState.isCorrecting();
|
2010-02-07 00:34:43 +00:00
|
|
|
InputConnection ic = getCurrentInputConnection();
|
|
|
|
if (ic != null) {
|
|
|
|
ic.beginBatchEdit();
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
if (mCompletionOn && mCompletions != null && index >= 0
|
|
|
|
&& index < mCompletions.length) {
|
|
|
|
CompletionInfo ci = mCompletions[index];
|
|
|
|
if (ic != null) {
|
|
|
|
ic.commitCompletion(ci);
|
|
|
|
}
|
|
|
|
mCommittedLength = suggestion.length();
|
|
|
|
if (mCandidateView != null) {
|
|
|
|
mCandidateView.clear();
|
|
|
|
}
|
|
|
|
updateShiftKeyState(getCurrentInputEditorInfo());
|
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(
|
|
|
|
"", suggestion.toString(), index, suggestions);
|
2010-08-25 12:27:13 +00:00
|
|
|
onKey(suggestion.charAt(0), null, LatinKeyboardBaseView.NOT_A_TOUCH_COORDINATE,
|
|
|
|
LatinKeyboardBaseView.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;
|
|
|
|
}
|
2010-02-07 00:34:43 +00:00
|
|
|
mJustAccepted = true;
|
2010-08-20 05:35:02 +00:00
|
|
|
pickSuggestion(suggestion, correcting);
|
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) {
|
2010-08-20 05:35:02 +00:00
|
|
|
addToDictionaries(suggestion, AutoDictionary.FREQUENCY_FOR_PICKED);
|
|
|
|
} else {
|
|
|
|
addToBigramDictionary(suggestion, 1);
|
2010-03-24 23:44:31 +00:00
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
LatinImeLogger.logOnManualSuggestion(mComposing.toString(), suggestion.toString(),
|
|
|
|
index, suggestions);
|
2009-03-13 22:11:42 +00:00
|
|
|
TextEntryState.acceptedSuggestion(mComposing.toString(), suggestion);
|
|
|
|
// Follow it with a space
|
2010-08-20 05:35:02 +00:00
|
|
|
if (mAutoSpace && !correcting) {
|
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
|
|
|
|
2010-08-26 19:22:58 +00:00
|
|
|
final boolean showingAddToDictionaryHint = index == 0 && mCorrectionMode > 0
|
|
|
|
&& !mSuggest.isValidWord(suggestion)
|
|
|
|
&& !mSuggest.isValidWord(suggestion.toString().toLowerCase());
|
|
|
|
|
2010-08-20 05:35:02 +00:00
|
|
|
if (!correcting) {
|
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.
|
2010-08-20 05:35:02 +00:00
|
|
|
TextEntryState.typedCharacter((char) KEYCODE_SPACE, true);
|
|
|
|
setNextSuggestions();
|
2010-08-26 19:22:58 +00:00
|
|
|
} else if (!showingAddToDictionaryHint) {
|
|
|
|
// If we're not showing the "Tap again to save hint", 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-08-20 05:35:02 +00:00
|
|
|
postUpdateOldSuggestions();
|
|
|
|
}
|
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
|
|
|
private void rememberReplacedWord(CharSequence suggestion) {
|
|
|
|
if (mShowingVoiceSuggestions) {
|
|
|
|
// Retain the replaced word in the alternatives array.
|
|
|
|
EditingUtil.Range range = new EditingUtil.Range();
|
|
|
|
String wordToBeReplaced = EditingUtil.getWordAtCursor(getCurrentInputConnection(),
|
|
|
|
mWordSeparators, range);
|
|
|
|
if (!mWordToSuggestions.containsKey(wordToBeReplaced)) {
|
|
|
|
wordToBeReplaced = wordToBeReplaced.toLowerCase();
|
|
|
|
}
|
|
|
|
if (mWordToSuggestions.containsKey(wordToBeReplaced)) {
|
|
|
|
List<CharSequence> suggestions = mWordToSuggestions.get(wordToBeReplaced);
|
|
|
|
if (suggestions.contains(suggestion)) {
|
|
|
|
suggestions.remove(suggestion);
|
|
|
|
}
|
|
|
|
suggestions.add(wordToBeReplaced);
|
|
|
|
mWordToSuggestions.remove(wordToBeReplaced);
|
|
|
|
mWordToSuggestions.put(suggestion.toString(), suggestions);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
* @param correcting whether this is due to a correction of an existing
|
|
|
|
* word.
|
|
|
|
*/
|
|
|
|
private void pickSuggestion(CharSequence suggestion, boolean correcting) {
|
|
|
|
LatinKeyboardView inputView = mKeyboardSwitcher.getInputView();
|
2009-03-13 22:11:42 +00:00
|
|
|
if (mCapsLock) {
|
|
|
|
suggestion = suggestion.toString().toUpperCase();
|
2010-01-28 18:09:44 +00:00
|
|
|
} else if (preferCapitalization()
|
2010-08-20 05:35:02 +00:00
|
|
|
|| (mKeyboardSwitcher.isAlphabetMode()
|
|
|
|
&& inputView.isShifted())) {
|
2009-08-04 01:16:19 +00:00
|
|
|
suggestion = suggestion.toString().toUpperCase().charAt(0)
|
2009-03-13 22:11:42 +00:00
|
|
|
+ suggestion.subSequence(1, suggestion.length()).toString();
|
|
|
|
}
|
|
|
|
InputConnection ic = getCurrentInputConnection();
|
|
|
|
if (ic != null) {
|
2010-08-20 05:35:02 +00:00
|
|
|
rememberReplacedWord(suggestion);
|
|
|
|
ic.commitText(suggestion, 1);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
saveWordInHistory(suggestion);
|
2009-03-13 22:11:42 +00:00
|
|
|
mPredicting = false;
|
|
|
|
mCommittedLength = suggestion.length();
|
2010-08-20 05:35:02 +00:00
|
|
|
((LatinKeyboard) inputView.getKeyboard()).setPreferredLetters(null);
|
|
|
|
// If we just corrected a word, then don't show punctuations
|
|
|
|
if (!correcting) {
|
|
|
|
setNextSuggestions();
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
updateShiftKeyState(getCurrentInputEditorInfo());
|
|
|
|
}
|
|
|
|
|
2010-08-26 19:22:58 +00:00
|
|
|
/**
|
|
|
|
* Tries to apply any voice alternatives for the word if this was a spoken word and
|
|
|
|
* there are voice alternatives.
|
|
|
|
* @param touching The word that the cursor is touching, with position information
|
|
|
|
* @return true if an alternative was found, false otherwise.
|
|
|
|
*/
|
|
|
|
private boolean applyVoiceAlternatives(EditingUtil.SelectedWord touching) {
|
|
|
|
// Search for result in spoken word alternatives
|
|
|
|
String selectedWord = touching.word.toString().trim();
|
|
|
|
if (!mWordToSuggestions.containsKey(selectedWord)) {
|
|
|
|
selectedWord = selectedWord.toLowerCase();
|
|
|
|
}
|
|
|
|
if (mWordToSuggestions.containsKey(selectedWord)) {
|
|
|
|
mShowingVoiceSuggestions = true;
|
|
|
|
List<CharSequence> suggestions = mWordToSuggestions.get(selectedWord);
|
|
|
|
// If the first letter of touching is capitalized, make all the suggestions
|
|
|
|
// start with a capital letter.
|
2010-09-06 05:26:46 +00:00
|
|
|
if (Character.isUpperCase(touching.word.charAt(0))) {
|
2010-08-26 19:22:58 +00:00
|
|
|
for (int i = 0; i < suggestions.size(); i++) {
|
|
|
|
String origSugg = (String) suggestions.get(i);
|
|
|
|
String capsSugg = origSugg.toUpperCase().charAt(0)
|
|
|
|
+ origSugg.subSequence(1, origSugg.length()).toString();
|
|
|
|
suggestions.set(i, capsSugg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setSuggestions(suggestions, false, true, true);
|
|
|
|
setCandidatesViewShown(true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
private boolean applyTypedAlternatives(EditingUtil.SelectedWord touching) {
|
|
|
|
// If we didn't find a match, search for result in typed word history
|
|
|
|
WordComposer foundWord = null;
|
|
|
|
WordAlternatives alternatives = null;
|
|
|
|
for (WordAlternatives entry : mWordHistory) {
|
|
|
|
if (TextUtils.equals(entry.getChosenWord(), touching.word)) {
|
|
|
|
if (entry instanceof TypedWordAlternatives) {
|
|
|
|
foundWord = ((TypedWordAlternatives) entry).word;
|
|
|
|
}
|
|
|
|
alternatives = entry;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// If we didn't find a match, at least suggest completions
|
|
|
|
if (foundWord == null
|
|
|
|
&& (mSuggest.isValidWord(touching.word)
|
|
|
|
|| mSuggest.isValidWord(touching.word.toString().toLowerCase()))) {
|
|
|
|
foundWord = new WordComposer();
|
|
|
|
for (int i = 0; i < touching.word.length(); i++) {
|
|
|
|
foundWord.add(touching.word.charAt(i), new int[] {
|
|
|
|
touching.word.charAt(i)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
foundWord.setCapitalized(Character.isUpperCase(touching.word.charAt(0)));
|
|
|
|
}
|
|
|
|
// Found a match, show suggestions
|
|
|
|
if (foundWord != null || alternatives != null) {
|
|
|
|
if (alternatives == null) {
|
|
|
|
alternatives = new TypedWordAlternatives(touching.word, foundWord);
|
|
|
|
}
|
|
|
|
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() {
|
|
|
|
mShowingVoiceSuggestions = 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-08-26 19:22:58 +00:00
|
|
|
if (!mPredicting) {
|
|
|
|
// Extract the selected or touching text
|
|
|
|
EditingUtil.SelectedWord touching = EditingUtil.getWordAtCursorOrSelection(ic,
|
|
|
|
mLastSelectionStart, mLastSelectionEnd, mWordSeparators);
|
2010-08-20 05:35:02 +00:00
|
|
|
|
2010-08-26 19:22:58 +00:00
|
|
|
if (touching != null && touching.word.length() > 1) {
|
|
|
|
ic.beginBatchEdit();
|
2010-08-20 05:35:02 +00:00
|
|
|
|
2010-08-26 19:22:58 +00:00
|
|
|
if (!applyVoiceAlternatives(touching) && !applyTypedAlternatives(touching)) {
|
|
|
|
abortCorrection(true);
|
|
|
|
} else {
|
2010-08-20 05:35:02 +00:00
|
|
|
TextEntryState.selectedForCorrection();
|
2010-08-26 19:22:58 +00:00
|
|
|
EditingUtil.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 {
|
|
|
|
abortCorrection(true);
|
|
|
|
setNextSuggestions();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
abortCorrection(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-03 23:35:49 +00:00
|
|
|
private void setNextSuggestions() {
|
|
|
|
setSuggestions(mSuggestPuncList, false, false, false);
|
|
|
|
}
|
|
|
|
|
2010-08-20 05:35:02 +00:00
|
|
|
private void addToDictionaries(CharSequence suggestion, int frequencyDelta) {
|
|
|
|
checkAddToDictionary(suggestion, frequencyDelta, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void addToBigramDictionary(CharSequence suggestion, int frequencyDelta) {
|
|
|
|
checkAddToDictionary(suggestion, frequencyDelta, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds to the UserBigramDictionary and/or AutoDictionary
|
|
|
|
* @param addToBigramDictionary true if it should be added to bigram dictionary if possible
|
|
|
|
*/
|
|
|
|
private void checkAddToDictionary(CharSequence suggestion, int frequencyDelta,
|
|
|
|
boolean addToBigramDictionary) {
|
|
|
|
if (suggestion == null || suggestion.length() < 1) return;
|
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;
|
|
|
|
}
|
|
|
|
if (suggestion != null) {
|
|
|
|
if (!addToBigramDictionary && mAutoDictionary.isValidWord(suggestion)
|
|
|
|
|| (!mSuggest.isValidWord(suggestion.toString())
|
2010-03-24 23:44:31 +00:00
|
|
|
&& !mSuggest.isValidWord(suggestion.toString().toLowerCase()))) {
|
2010-08-20 05:35:02 +00:00
|
|
|
mAutoDictionary.addWord(suggestion.toString(), frequencyDelta);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mUserBigramDictionary != null) {
|
|
|
|
CharSequence prevWord = EditingUtil.getPreviousWord(getCurrentInputConnection(),
|
|
|
|
mSentenceSeparators);
|
|
|
|
if (!TextUtils.isEmpty(prevWord)) {
|
|
|
|
mUserBigramDictionary.addBigrams(prevWord.toString(), suggestion.toString());
|
|
|
|
}
|
|
|
|
}
|
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)
|
|
|
|
&& !isWordSeparator(toLeft.charAt(0))) {
|
|
|
|
return true;
|
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
if (!TextUtils.isEmpty(toRight)
|
2009-03-13 22:11:42 +00:00
|
|
|
&& !isWordSeparator(toRight.charAt(0))) {
|
|
|
|
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();
|
|
|
|
if (!mPredicting && length > 0) {
|
|
|
|
final InputConnection ic = getCurrentInputConnection();
|
|
|
|
mPredicting = true;
|
|
|
|
mJustRevertedSeparator = ic.getTextBeforeCursor(1, 0);
|
|
|
|
if (deleteChar) ic.deleteSurroundingText(1, 0);
|
|
|
|
int toDelete = mCommittedLength;
|
|
|
|
CharSequence toTheLeft = ic.getTextBeforeCursor(mCommittedLength, 0);
|
2010-01-28 18:09:44 +00:00
|
|
|
if (toTheLeft != null && toTheLeft.length() > 0
|
2009-03-13 22:11:42 +00:00
|
|
|
&& isWordSeparator(toTheLeft.charAt(0))) {
|
|
|
|
toDelete--;
|
|
|
|
}
|
|
|
|
ic.deleteSurroundingText(toDelete, 0);
|
|
|
|
ic.setComposingText(mComposing, 1);
|
|
|
|
TextEntryState.backspace();
|
|
|
|
postUpdateSuggestions();
|
|
|
|
} else {
|
|
|
|
sendDownUpKeyEvents(KeyEvent.KEYCODE_DEL);
|
|
|
|
mJustRevertedSeparator = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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() {
|
|
|
|
sendKeyChar((char)KEYCODE_SPACE);
|
|
|
|
updateShiftKeyState(getCurrentInputEditorInfo());
|
|
|
|
//onKey(KEY_SPACE[0], KEY_SPACE);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean preferCapitalization() {
|
|
|
|
return mWord.isCapitalized();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void swipeRight() {
|
2010-01-16 20:21:23 +00:00
|
|
|
if (userHasNotTypedRecently() && VOICE_INSTALLED && mEnableVoice &&
|
|
|
|
fieldCanDoVoice(makeFieldContext())) {
|
|
|
|
startListening(true /* was a swipe */);
|
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
if (LatinKeyboardView.DEBUG_AUTO_PLAY) {
|
|
|
|
ClipboardManager cm = ((ClipboardManager)getSystemService(CLIPBOARD_SERVICE));
|
|
|
|
CharSequence text = cm.getText();
|
|
|
|
if (!TextUtils.isEmpty(text)) {
|
2010-08-20 05:35:02 +00:00
|
|
|
mKeyboardSwitcher.getInputView().startPlaying(text.toString());
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-10-12 20:48:35 +00:00
|
|
|
|
2010-01-30 04:09:49 +00:00
|
|
|
private void toggleLanguage(boolean reset, boolean next) {
|
|
|
|
if (reset) {
|
|
|
|
mLanguageSwitcher.reset();
|
|
|
|
} else {
|
|
|
|
if (next) {
|
|
|
|
mLanguageSwitcher.next();
|
|
|
|
} else {
|
|
|
|
mLanguageSwitcher.prev();
|
|
|
|
}
|
|
|
|
}
|
2009-10-12 20:48:35 +00:00
|
|
|
int currentKeyboardMode = mKeyboardSwitcher.getKeyboardMode();
|
|
|
|
reloadKeyboards();
|
|
|
|
mKeyboardSwitcher.makeKeyboards(true);
|
2010-01-28 15:33:27 +00:00
|
|
|
mKeyboardSwitcher.setKeyboardMode(currentKeyboardMode, 0,
|
|
|
|
mEnableVoiceButton && mEnableVoice);
|
2010-01-30 04:09:49 +00:00
|
|
|
initSuggest(mLanguageSwitcher.getInputLanguage());
|
|
|
|
mLanguageSwitcher.persist();
|
2009-10-12 20:48:35 +00:00
|
|
|
updateShiftKeyState(getCurrentInputEditorInfo());
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
|
|
|
|
String key) {
|
|
|
|
if (PREF_SELECTED_LANGUAGES.equals(key)) {
|
2010-01-30 04:09:49 +00:00
|
|
|
mLanguageSwitcher.loadLocales(sharedPreferences);
|
2009-10-12 20:48:35 +00:00
|
|
|
mRefreshKeyboardRequired = true;
|
2010-09-06 10:18:38 +00:00
|
|
|
} else if (PREF_RECORRECTION_ENABLED.equals(key)) {
|
|
|
|
mReCorrectionEnabled = sharedPreferences.getBoolean(PREF_RECORRECTION_ENABLED,
|
|
|
|
getResources().getBoolean(R.bool.default_recorrection_enabled));
|
2009-10-12 20:48:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
public void swipeLeft() {
|
|
|
|
}
|
|
|
|
|
|
|
|
public void swipeDown() {
|
2009-08-28 00:35:33 +00:00
|
|
|
handleClose();
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void swipeUp() {
|
|
|
|
//launchSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onPress(int primaryCode) {
|
|
|
|
vibrate();
|
|
|
|
playKeyClick(primaryCode);
|
2010-09-09 05:43:17 +00:00
|
|
|
final boolean distinctMultiTouch = mKeyboardSwitcher.hasDistinctMultitouch();
|
|
|
|
if (distinctMultiTouch && primaryCode == Keyboard.KEYCODE_SHIFT) {
|
2010-09-01 16:35:24 +00:00
|
|
|
mShiftKeyState.onPress();
|
2010-09-01 07:36:24 +00:00
|
|
|
handleShift();
|
2010-09-09 05:43:17 +00:00
|
|
|
} else if (distinctMultiTouch && primaryCode == Keyboard.KEYCODE_MODE_CHANGE) {
|
|
|
|
mSymbolKeyState.onPress();
|
|
|
|
changeKeyboardMode();
|
2010-09-01 16:35:24 +00:00
|
|
|
} else {
|
|
|
|
mShiftKeyState.onOtherKeyPressed();
|
2010-09-09 05:43:17 +00:00
|
|
|
mSymbolKeyState.onOtherKeyPressed();
|
2010-09-01 07:36:24 +00:00
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void onRelease(int primaryCode) {
|
2010-01-30 04:09:49 +00:00
|
|
|
// Reset any drag flags in the keyboard
|
2010-08-20 05:35:02 +00:00
|
|
|
((LatinKeyboard) mKeyboardSwitcher.getInputView().getKeyboard()).keyReleased();
|
2009-03-13 22:11:42 +00:00
|
|
|
//vibrate();
|
2010-09-09 05:43:17 +00:00
|
|
|
final boolean distinctMultiTouch = mKeyboardSwitcher.hasDistinctMultitouch();
|
|
|
|
if (distinctMultiTouch && primaryCode == Keyboard.KEYCODE_SHIFT) {
|
2010-09-01 16:35:24 +00:00
|
|
|
if (mShiftKeyState.isMomentary())
|
|
|
|
resetShift();
|
|
|
|
mShiftKeyState.onRelease();
|
2010-09-09 05:43:17 +00:00
|
|
|
} else if (distinctMultiTouch && primaryCode == Keyboard.KEYCODE_MODE_CHANGE) {
|
|
|
|
if (mSymbolKeyState.isMomentary())
|
|
|
|
changeKeyboardMode();
|
|
|
|
mSymbolKeyState.onRelease();
|
2010-09-01 16:35:24 +00:00
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
private FieldContext makeFieldContext() {
|
2010-02-05 02:31:40 +00:00
|
|
|
return new FieldContext(
|
|
|
|
getCurrentInputConnection(),
|
|
|
|
getCurrentInputEditorInfo(),
|
|
|
|
mLanguageSwitcher.getInputLanguage(),
|
|
|
|
mLanguageSwitcher.getEnabledLanguages());
|
2010-01-16 20:21:23 +00:00
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
private boolean fieldCanDoVoice(FieldContext fieldContext) {
|
|
|
|
return !mPasswordText
|
|
|
|
&& mVoiceInput != null
|
|
|
|
&& !mVoiceInput.isBlacklistedField(fieldContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean shouldShowVoiceButton(FieldContext fieldContext, EditorInfo attribute) {
|
2010-02-09 10:29:10 +00:00
|
|
|
return ENABLE_VOICE_BUTTON && fieldCanDoVoice(fieldContext)
|
2010-01-16 20:21:23 +00:00
|
|
|
&& !(attribute != null && attribute.privateImeOptions != null
|
2010-02-09 10:29:10 +00:00
|
|
|
&& attribute.privateImeOptions.equals(IME_OPTION_NO_MICROPHONE))
|
2010-03-30 17:05:53 +00:00
|
|
|
&& SpeechRecognizer.isRecognitionAvailable(this);
|
2010-01-16 20:21:23 +00:00
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
// receive ringer mode changes to detect silent mode
|
|
|
|
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
updateRingerMode();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
private boolean userHasNotTypedRecently() {
|
|
|
|
return (SystemClock.uptimeMillis() - mLastKeyTime)
|
|
|
|
> MIN_MILLIS_AFTER_TYPING_BEFORE_SWIPE;
|
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
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) {
|
|
|
|
case Keyboard.KEYCODE_DELETE:
|
|
|
|
sound = AudioManager.FX_KEYPRESS_DELETE;
|
|
|
|
break;
|
|
|
|
case KEYCODE_ENTER:
|
|
|
|
sound = AudioManager.FX_KEYPRESS_RETURN;
|
|
|
|
break;
|
|
|
|
case KEYCODE_SPACE:
|
|
|
|
sound = AudioManager.FX_KEYPRESS_SPACEBAR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
mAudioManager.playSoundEffect(sound, FX_VOLUME);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void vibrate() {
|
|
|
|
if (!mVibrateOn) {
|
|
|
|
return;
|
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
if (mKeyboardSwitcher.getInputView() != null) {
|
|
|
|
mKeyboardSwitcher.getInputView().performHapticFeedback(
|
|
|
|
HapticFeedbackConstants.KEYBOARD_TAP,
|
2010-02-11 01:45:35 +00:00
|
|
|
HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-26 00:39:38 +00:00
|
|
|
private void checkTutorial(String privateImeOptions) {
|
|
|
|
if (privateImeOptions == null) return;
|
|
|
|
if (privateImeOptions.equals("com.android.setupwizard:ShowTutorial")) {
|
|
|
|
if (mTutorial == null) startTutorial();
|
|
|
|
} else if (privateImeOptions.equals("com.android.setupwizard:HideTutorial")) {
|
|
|
|
if (mTutorial != null) {
|
|
|
|
if (mTutorial.close()) {
|
|
|
|
mTutorial = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2009-03-26 00:39:38 +00:00
|
|
|
private void startTutorial() {
|
|
|
|
mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_START_TUTORIAL), 500);
|
|
|
|
}
|
|
|
|
|
|
|
|
void tutorialDone() {
|
|
|
|
mTutorial = null;
|
|
|
|
}
|
2009-07-17 19:51:45 +00:00
|
|
|
|
|
|
|
void promoteToUserDictionary(String word, int frequency) {
|
|
|
|
if (mUserDictionary.isValidWord(word)) return;
|
|
|
|
mUserDictionary.addWord(word, frequency);
|
|
|
|
}
|
|
|
|
|
2010-02-24 03:01:43 +00:00
|
|
|
WordComposer getCurrentWord() {
|
|
|
|
return mWord;
|
|
|
|
}
|
|
|
|
|
2010-08-20 05:35:02 +00:00
|
|
|
boolean getPopupOn() {
|
|
|
|
return mPopupOn;
|
|
|
|
}
|
|
|
|
|
2009-12-18 21:39:18 +00:00
|
|
|
private void updateCorrectionMode() {
|
|
|
|
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-02-20 00:38:58 +00:00
|
|
|
private void updateAutoTextEnabled(Locale systemLocale) {
|
|
|
|
if (mSuggest == null) return;
|
2010-03-13 01:25:42 +00:00
|
|
|
boolean different =
|
|
|
|
!systemLocale.getLanguage().equalsIgnoreCase(mInputLocale.substring(0, 2));
|
2010-02-20 00:38:58 +00:00
|
|
|
mSuggest.setAutoTextEnabled(!different && mQuickFixes);
|
|
|
|
}
|
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
protected void launchSettings() {
|
|
|
|
launchSettings(LatinIMESettings.class);
|
|
|
|
}
|
|
|
|
|
2010-08-20 05:35:02 +00:00
|
|
|
protected void launchSettings(Class<LatinIMESettings> 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void loadSettings() {
|
|
|
|
// Get the settings preferences
|
|
|
|
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
|
2009-03-25 00:43:19 +00:00
|
|
|
mVibrateOn = sp.getBoolean(PREF_VIBRATE_ON, false);
|
2009-03-13 22:11:42 +00:00
|
|
|
mSoundOn = sp.getBoolean(PREF_SOUND_ON, false);
|
2010-08-20 05:35:02 +00:00
|
|
|
mPopupOn = sp.getBoolean(PREF_POPUP_ON,
|
|
|
|
mResources.getBoolean(R.bool.default_popup_preview));
|
2009-03-13 22:11:42 +00:00
|
|
|
mAutoCap = sp.getBoolean(PREF_AUTO_CAP, true);
|
2009-03-26 00:39:38 +00:00
|
|
|
mQuickFixes = sp.getBoolean(PREF_QUICK_FIXES, true);
|
2010-01-16 20:21:23 +00:00
|
|
|
mHasUsedVoiceInput = sp.getBoolean(PREF_HAS_USED_VOICE_INPUT, false);
|
|
|
|
mHasUsedVoiceInputUnsupportedLocale =
|
|
|
|
sp.getBoolean(PREF_HAS_USED_VOICE_INPUT_UNSUPPORTED_LOCALE, false);
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
// Get the current list of supported locales and check the current locale against that
|
|
|
|
// list. We cache this value so as not to check it every time the user starts a voice
|
|
|
|
// input. Because this method is called by onStartInputView, this should mean that as
|
|
|
|
// long as the locale doesn't change while the user is keeping the IME open, the
|
|
|
|
// value should never be stale.
|
2010-01-28 18:09:44 +00:00
|
|
|
String supportedLocalesString = SettingsUtil.getSettingsString(
|
2010-01-16 20:21:23 +00:00
|
|
|
getContentResolver(),
|
2010-01-28 18:09:44 +00:00
|
|
|
SettingsUtil.LATIN_IME_VOICE_INPUT_SUPPORTED_LOCALES,
|
2010-01-16 20:21:23 +00:00
|
|
|
DEFAULT_VOICE_INPUT_SUPPORTED_LOCALES);
|
|
|
|
ArrayList<String> voiceInputSupportedLocales =
|
2010-02-17 22:42:51 +00:00
|
|
|
newArrayList(supportedLocalesString.split("\\s+"));
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-03-13 01:25:42 +00:00
|
|
|
mLocaleSupportedForVoiceInput = voiceInputSupportedLocales.contains(mInputLocale);
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-02-20 00:38:58 +00:00
|
|
|
mShowSuggestions = sp.getBoolean(PREF_SHOW_SUGGESTIONS, true);
|
2010-01-16 20:21:23 +00:00
|
|
|
|
|
|
|
if (VOICE_INSTALLED) {
|
2010-02-26 19:47:05 +00:00
|
|
|
final String voiceMode = sp.getString(PREF_VOICE_MODE,
|
|
|
|
getString(R.string.voice_mode_main));
|
|
|
|
boolean enableVoice = !voiceMode.equals(getString(R.string.voice_mode_off))
|
|
|
|
&& mEnableVoiceButton;
|
2010-02-09 22:17:30 +00:00
|
|
|
boolean voiceOnPrimary = voiceMode.equals(getString(R.string.voice_mode_main));
|
2010-01-28 15:33:27 +00:00
|
|
|
if (mKeyboardSwitcher != null &&
|
|
|
|
(enableVoice != mEnableVoice || voiceOnPrimary != mVoiceOnPrimary)) {
|
|
|
|
mKeyboardSwitcher.setVoiceMode(enableVoice, voiceOnPrimary);
|
2010-01-16 20:21:23 +00:00
|
|
|
}
|
|
|
|
mEnableVoice = enableVoice;
|
2010-01-28 15:33:27 +00:00
|
|
|
mVoiceOnPrimary = voiceOnPrimary;
|
2010-01-16 20:21:23 +00:00
|
|
|
}
|
2009-12-18 21:39:18 +00:00
|
|
|
mAutoCorrectEnabled = sp.getBoolean(PREF_AUTO_COMPLETE,
|
2009-10-12 20:48:35 +00:00
|
|
|
mResources.getBoolean(R.bool.enable_autocorrect)) & mShowSuggestions;
|
2010-08-20 05:35:02 +00:00
|
|
|
mBigramSuggestionEnabled = sp.getBoolean(PREF_BIGRAM_SUGGESTIONS, true) & mShowSuggestions;
|
2009-12-18 21:39:18 +00:00
|
|
|
updateCorrectionMode();
|
2010-02-20 00:38:58 +00:00
|
|
|
updateAutoTextEnabled(mResources.getConfiguration().locale);
|
2010-01-30 04:09:49 +00:00
|
|
|
mLanguageSwitcher.loadLocales(sp);
|
2009-10-12 20:48:35 +00:00
|
|
|
}
|
|
|
|
|
2010-02-03 23:35:49 +00:00
|
|
|
private void initSuggestPuncList() {
|
|
|
|
mSuggestPuncList = new ArrayList<CharSequence>();
|
2010-08-20 05:35:02 +00:00
|
|
|
mSuggestPuncs = mResources.getString(R.string.suggested_punctuations);
|
|
|
|
if (mSuggestPuncs != null) {
|
|
|
|
for (int i = 0; i < mSuggestPuncs.length(); i++) {
|
|
|
|
mSuggestPuncList.add(mSuggestPuncs.subSequence(i, i + 1));
|
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));
|
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
private void showOptionsMenu() {
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
|
builder.setCancelable(true);
|
|
|
|
builder.setIcon(R.drawable.ic_dialog_keyboard);
|
|
|
|
builder.setNegativeButton(android.R.string.cancel, null);
|
|
|
|
CharSequence itemSettings = getString(R.string.english_ime_settings);
|
2010-09-02 19:25:31 +00:00
|
|
|
CharSequence itemInputMethod = getString(R.string.selectInputMethod);
|
2009-03-13 22:11:42 +00:00
|
|
|
builder.setItems(new CharSequence[] {
|
2010-09-07 11:22:50 +00:00
|
|
|
itemInputMethod, itemSettings},
|
2009-03-13 22:11:42 +00:00
|
|
|
new DialogInterface.OnClickListener() {
|
|
|
|
|
|
|
|
public void onClick(DialogInterface di, int position) {
|
|
|
|
di.dismiss();
|
|
|
|
switch (position) {
|
|
|
|
case POS_SETTINGS:
|
|
|
|
launchSettings();
|
|
|
|
break;
|
|
|
|
case POS_METHOD:
|
2009-08-12 02:22:53 +00:00
|
|
|
((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE))
|
|
|
|
.showInputMethodPicker();
|
2009-03-13 22:11:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2010-09-07 11:22:50 +00:00
|
|
|
builder.setTitle(mResources.getString(R.string.english_ime_input_options));
|
2009-03-13 22:11:42 +00:00
|
|
|
mOptionsDialog = builder.create();
|
|
|
|
Window window = mOptionsDialog.getWindow();
|
|
|
|
WindowManager.LayoutParams lp = window.getAttributes();
|
2010-08-20 05:35:02 +00:00
|
|
|
lp.token = mKeyboardSwitcher.getInputView().getWindowToken();
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void changeKeyboardMode() {
|
|
|
|
mKeyboardSwitcher.toggleSymbols();
|
|
|
|
if (mCapsLock && mKeyboardSwitcher.isAlphabetMode()) {
|
2010-08-20 05:35:02 +00:00
|
|
|
mKeyboardSwitcher.setShiftLocked(mCapsLock);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
updateShiftKeyState(getCurrentInputEditorInfo());
|
|
|
|
}
|
2009-10-12 20:48:35 +00:00
|
|
|
|
2010-02-17 22:42:51 +00:00
|
|
|
public static <E> ArrayList<E> newArrayList(E... elements) {
|
|
|
|
int capacity = (elements.length * 110) / 100 + 5;
|
|
|
|
ArrayList<E> list = new ArrayList<E>(capacity);
|
|
|
|
Collections.addAll(list, elements);
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
@Override protected void dump(FileDescriptor fd, PrintWriter fout, String[] args) {
|
|
|
|
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(" mCapsLock=" + mCapsLock);
|
|
|
|
p.println(" mComposing=" + mComposing.toString());
|
|
|
|
p.println(" mPredictionOn=" + mPredictionOn);
|
|
|
|
p.println(" mCorrectionMode=" + mCorrectionMode);
|
|
|
|
p.println(" mPredicting=" + mPredicting);
|
|
|
|
p.println(" mAutoCorrectOn=" + mAutoCorrectOn);
|
|
|
|
p.println(" mAutoSpace=" + mAutoSpace);
|
|
|
|
p.println(" mCompletionOn=" + mCompletionOn);
|
|
|
|
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));
|
|
|
|
}
|
2009-07-17 19:51:45 +00:00
|
|
|
|
2010-09-02 13:54:37 +00:00
|
|
|
public void onAutoCompletionStateChanged(boolean isAutoCompletion) {
|
|
|
|
mKeyboardSwitcher.onAutoCompletionStateChanged(isAutoCompletion);
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|