2009-03-13 22:11:42 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2008-2009 Google Inc.
|
2010-01-28 18:09:44 +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.EditingUtil;
|
|
|
|
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
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.app.AlertDialog;
|
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.DialogInterface;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.IntentFilter;
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.content.res.Configuration;
|
2009-10-12 20:48:35 +00:00
|
|
|
import android.content.res.Resources;
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.inputmethodservice.InputMethodService;
|
|
|
|
import android.inputmethodservice.Keyboard;
|
|
|
|
import android.inputmethodservice.KeyboardView;
|
|
|
|
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-02-09 10:29:10 +00:00
|
|
|
import android.speech.RecognitionManager;
|
2009-03-26 00:39:38 +00:00
|
|
|
import android.text.AutoText;
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.text.ClipboardManager;
|
|
|
|
import android.text.TextUtils;
|
|
|
|
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;
|
|
|
|
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-01-16 20:21:23 +00:00
|
|
|
import java.io.FileDescriptor;
|
|
|
|
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
|
2009-10-12 20:48:35 +00:00
|
|
|
implements KeyboardView.OnKeyboardActionListener,
|
2010-01-16 20:21:23 +00:00
|
|
|
VoiceInput.UiListener,
|
|
|
|
SharedPreferences.OnSharedPreferenceChangeListener {
|
|
|
|
private static final String TAG = "LatinIME";
|
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";
|
|
|
|
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-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";
|
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;
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
// If we detect a swipe gesture, and the user types N ms later, cancel the
|
|
|
|
// swipe since it was probably a false trigger.
|
|
|
|
private static final long MIN_MILLIS_AFTER_SWIPE_TO_WAIT_FOR_TYPING = 500;
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
// How many continuous deletes at which to start deleting at a higher speed.
|
|
|
|
private static final int DELETE_ACCELERATE_AT = 20;
|
|
|
|
// Key events coming any faster than this are long-presses.
|
2009-07-28 23:33:36 +00:00
|
|
|
private static final int QUICK_PRESS = 200;
|
|
|
|
// Weight added to a user picking a new word from the suggestion strip
|
|
|
|
static final int FREQUENCY_FOR_PICKED = 3;
|
|
|
|
// Weight added to a user typing a new word that doesn't get corrected (or is reverted)
|
|
|
|
static final int FREQUENCY_FOR_TYPED = 1;
|
|
|
|
// A word that is frequently typed and get's promoted to the user dictionary, uses this
|
|
|
|
// frequency.
|
|
|
|
static final int FREQUENCY_FOR_AUTO_ADD = 250;
|
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 = ' ';
|
2009-03-13 22:11:42 +00:00
|
|
|
|
|
|
|
// Contextual menu positions
|
|
|
|
private static final int POS_SETTINGS = 0;
|
|
|
|
private static final int POS_METHOD = 1;
|
2010-01-16 20:21:23 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
private LatinKeyboardView mInputView;
|
|
|
|
private CandidateViewContainer mCandidateViewContainer;
|
|
|
|
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;
|
2009-07-28 23:48:47 +00:00
|
|
|
private ContactsDictionary mContactsDictionary;
|
2009-07-17 19:51:45 +00:00
|
|
|
private ExpandableDictionary 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;
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
private String mLocale;
|
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 mImmediatelyAfterVoiceSuggestions;
|
|
|
|
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;
|
2009-03-13 22:11:42 +00:00
|
|
|
private boolean mAutoCorrectOn;
|
|
|
|
private boolean mCapsLock;
|
2010-01-16 20:21:23 +00:00
|
|
|
private boolean mPasswordText;
|
|
|
|
private boolean mEmailText;
|
2009-03-13 22:11:42 +00:00
|
|
|
private boolean mVibrateOn;
|
|
|
|
private boolean mSoundOn;
|
|
|
|
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 mSuggestionShouldReplaceCurrentWord;
|
|
|
|
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-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
|
|
|
|
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;
|
|
|
|
|
|
|
|
private String mWordSeparators;
|
|
|
|
private String mSentenceSeparators;
|
2010-01-16 20:21:23 +00:00
|
|
|
private VoiceInput mVoiceInput;
|
|
|
|
private VoiceResults mVoiceResults = new VoiceResults();
|
|
|
|
private long mSwipeTriggerTimeMillis;
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
private class VoiceResults {
|
|
|
|
List<String> candidates;
|
|
|
|
Map<String, List<CharSequence>> alternatives;
|
|
|
|
}
|
2009-10-12 20:48:35 +00:00
|
|
|
private boolean mRefreshKeyboardRequired;
|
|
|
|
|
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;
|
2009-03-26 00:39:38 +00:00
|
|
|
case MSG_START_TUTORIAL:
|
|
|
|
if (mTutorial == null) {
|
|
|
|
if (mInputView.isShown()) {
|
|
|
|
mTutorial = new Tutorial(LatinIME.this, mInputView);
|
|
|
|
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() {
|
|
|
|
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);
|
|
|
|
boolean enableMultipleLanguages = mLanguageSwitcher.getLocaleCount() > 0;
|
|
|
|
String inputLanguage = mLanguageSwitcher.getInputLanguage();
|
|
|
|
if (inputLanguage == null) {
|
|
|
|
inputLanguage = conf.locale.toString();
|
|
|
|
}
|
|
|
|
initSuggest(inputLanguage);
|
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
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
private void initSuggest(String locale) {
|
|
|
|
mLocale = 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);
|
2009-03-13 22:11:42 +00:00
|
|
|
mSuggest = new Suggest(this, R.raw.main);
|
2010-02-20 00:38:58 +00:00
|
|
|
updateAutoTextEnabled(saveLocale);
|
2010-01-17 21:55:56 +00:00
|
|
|
if (mUserDictionary != null) mUserDictionary.close();
|
2009-03-13 22:11:42 +00:00
|
|
|
mUserDictionary = new UserDictionary(this);
|
2009-10-12 20:48:35 +00:00
|
|
|
if (mContactsDictionary == null) {
|
|
|
|
mContactsDictionary = new ContactsDictionary(this);
|
|
|
|
}
|
|
|
|
// TODO: Save and restore the dictionary for the current input language.
|
|
|
|
if (mAutoDictionary == null) {
|
|
|
|
mAutoDictionary = new AutoDictionary(this);
|
|
|
|
}
|
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() {
|
2009-03-13 22:11:42 +00:00
|
|
|
mUserDictionary.close();
|
2009-07-28 23:48:47 +00:00
|
|
|
mContactsDictionary.close();
|
2009-03-13 22:11:42 +00:00
|
|
|
unregisterReceiver(mReceiver);
|
2010-01-16 20:21:23 +00:00
|
|
|
if (VOICE_INSTALLED) {
|
|
|
|
mVoiceInput.destroy();
|
|
|
|
}
|
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
|
|
|
|
// locale (mLocale), then reload the input locale list from the
|
|
|
|
// latin ime settings (shared prefs) and reset the input locale
|
|
|
|
// to the first one.
|
2009-03-13 22:11:42 +00:00
|
|
|
if (!TextUtils.equals(conf.locale.toString(), mLocale)) {
|
2010-02-21 23:59:15 +00:00
|
|
|
if (mLanguageSwitcher != null) {
|
|
|
|
mLanguageSwitcher.loadLocales(
|
|
|
|
PreferenceManager.getDefaultSharedPreferences(this));
|
|
|
|
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
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
super.onConfigurationChanged(conf);
|
|
|
|
}
|
2009-07-21 22:47:11 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
@Override
|
|
|
|
public View onCreateInputView() {
|
|
|
|
mInputView = (LatinKeyboardView) getLayoutInflater().inflate(
|
|
|
|
R.layout.input, null);
|
|
|
|
mKeyboardSwitcher.setInputView(mInputView);
|
2009-10-01 04:15:47 +00:00
|
|
|
mKeyboardSwitcher.makeKeyboards(true);
|
2009-03-13 22:11:42 +00:00
|
|
|
mInputView.setOnKeyboardActionListener(this);
|
2010-01-16 20:21:23 +00:00
|
|
|
mKeyboardSwitcher.setKeyboardMode(
|
|
|
|
KeyboardSwitcher.MODE_TEXT, 0,
|
|
|
|
shouldShowVoiceButton(makeFieldContext(), getCurrentInputEditorInfo()));
|
2009-03-13 22:11:42 +00:00
|
|
|
return mInputView;
|
|
|
|
}
|
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
@Override
|
|
|
|
public void onInitializeInterface() {
|
|
|
|
// Create a new view associated with voice input if the old
|
|
|
|
// view is stuck in another layout (e.g. if switching from
|
|
|
|
// portrait to landscape while speaking)
|
|
|
|
// NOTE: This must be done here because for some reason
|
|
|
|
// onCreateInputView isn't called after an orientation change while
|
|
|
|
// speech rec is in progress.
|
|
|
|
if (mVoiceInput != null && mVoiceInput.getView().getParent() != null) {
|
|
|
|
mVoiceInput.newView();
|
|
|
|
}
|
|
|
|
|
|
|
|
super.onInitializeInterface();
|
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
@Override
|
|
|
|
public View onCreateCandidatesView() {
|
2009-10-01 04:15:47 +00:00
|
|
|
mKeyboardSwitcher.makeKeyboards(true);
|
2009-03-13 22:11:42 +00:00
|
|
|
mCandidateViewContainer = (CandidateViewContainer) getLayoutInflater().inflate(
|
|
|
|
R.layout.candidates, null);
|
|
|
|
mCandidateViewContainer.initViews();
|
|
|
|
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) {
|
|
|
|
// In landscape mode, this method gets called without the input view being created.
|
|
|
|
if (mInputView == null) {
|
|
|
|
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;
|
|
|
|
mImmediatelyAfterVoiceSuggestions = false;
|
|
|
|
mVoiceInputHighlighted = false;
|
|
|
|
mWordToSuggestions.clear();
|
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-01-16 20:21:23 +00:00
|
|
|
mEmailText = false;
|
|
|
|
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;
|
|
|
|
}
|
2010-01-16 20:21:23 +00:00
|
|
|
if (variation == EditorInfo.TYPE_TEXT_VARIATION_EMAIL_ADDRESS) {
|
|
|
|
mEmailText = true;
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
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
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
if ((attribute.inputType&EditorInfo.TYPE_TEXT_FLAG_AUTO_COMPLETE) != 0) {
|
|
|
|
mPredictionOn = false;
|
|
|
|
mCompletionOn = true && isFullscreenMode();
|
|
|
|
}
|
|
|
|
updateShiftKeyState(attribute);
|
|
|
|
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
|
|
|
updateShiftKeyState(attribute);
|
|
|
|
}
|
|
|
|
mInputView.closing();
|
|
|
|
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();
|
2009-12-18 21:39:18 +00:00
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
setCandidatesViewShown(false);
|
|
|
|
setSuggestions(null, false, false, false);
|
|
|
|
|
2009-12-18 21:39:18 +00:00
|
|
|
// If the dictionary is not big enough, don't auto correct
|
|
|
|
mHasDictionary = mSuggest.hasMainDictionary();
|
|
|
|
|
|
|
|
updateCorrectionMode();
|
|
|
|
|
2009-03-26 00:39:38 +00:00
|
|
|
mInputView.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-02-05 12:11:59 +00:00
|
|
|
if (VOICE_INSTALLED && mAfterVoiceInput) {
|
|
|
|
mVoiceInput.logInputEnded();
|
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-02-05 12:11:59 +00:00
|
|
|
if (VOICE_INSTALLED) {
|
|
|
|
mVoiceInput.flushLogs();
|
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
if (mInputView != null) {
|
|
|
|
mInputView.closing();
|
|
|
|
}
|
2010-02-05 12:11:59 +00:00
|
|
|
if (VOICE_INSTALLED && mRecognizing) {
|
2010-01-16 20:21:23 +00:00
|
|
|
mVoiceInput.cancel();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onUpdateExtractedText(int token, ExtractedText text) {
|
|
|
|
super.onUpdateExtractedText(token, text);
|
|
|
|
InputConnection ic = getCurrentInputConnection();
|
|
|
|
if (!mImmediatelyAfterVoiceInput && mAfterVoiceInput && ic != null) {
|
|
|
|
mVoiceInput.logTextModified();
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
mSuggestionShouldReplaceCurrentWord = false;
|
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
|
|
|
|
|| newSelEnd != candidatesEnd))) {
|
2009-03-13 22:11:42 +00:00
|
|
|
mComposing.setLength(0);
|
|
|
|
mPredicting = false;
|
|
|
|
updateSuggestions();
|
|
|
|
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()) {
|
|
|
|
case TextEntryState.STATE_ACCEPTED_DEFAULT:
|
|
|
|
TextEntryState.reset();
|
|
|
|
// fall through
|
|
|
|
case TextEntryState.STATE_SPACE_AFTER_PICKED:
|
|
|
|
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
|
|
|
|
|
|
|
if (VOICE_INSTALLED) {
|
|
|
|
if (mShowingVoiceSuggestions) {
|
|
|
|
if (mImmediatelyAfterVoiceSuggestions) {
|
|
|
|
mImmediatelyAfterVoiceSuggestions = false;
|
|
|
|
} else {
|
|
|
|
updateSuggestions();
|
|
|
|
mShowingVoiceSuggestions = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (VoiceInput.ENABLE_WORD_CORRECTIONS) {
|
|
|
|
// If we have alternatives for the current word, then show them.
|
|
|
|
String word = EditingUtil.getWordAtCursor(
|
|
|
|
getCurrentInputConnection(), getWordSeparators());
|
|
|
|
if (word != null && mWordToSuggestions.containsKey(word.trim())) {
|
|
|
|
mSuggestionShouldReplaceCurrentWord = true;
|
|
|
|
final List<CharSequence> suggestions = mWordToSuggestions.get(word.trim());
|
|
|
|
|
|
|
|
setSuggestions(suggestions, false, true, true);
|
|
|
|
setCandidatesViewShown(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void hideWindow() {
|
2010-01-16 20:21:23 +00:00
|
|
|
if (mAfterVoiceInput) mVoiceInput.logInputEnded();
|
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-01-16 20:21:23 +00:00
|
|
|
if (mVoiceWarningDialog != null && mVoiceWarningDialog.isShowing()) {
|
|
|
|
mVoiceInput.logKeyboardWarningDialogDismissed();
|
|
|
|
mVoiceWarningDialog.dismiss();
|
|
|
|
mVoiceWarningDialog = null;
|
|
|
|
}
|
2009-03-26 00:39:38 +00:00
|
|
|
if (mTutorial != null) {
|
|
|
|
mTutorial.close();
|
2009-03-25 01:40:11 +00:00
|
|
|
mTutorial = null;
|
|
|
|
}
|
2010-01-16 20:21:23 +00:00
|
|
|
if (VOICE_INSTALLED & mRecognizing) {
|
|
|
|
mVoiceInput.cancel();
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
super.hideWindow();
|
|
|
|
TextEntryState.endSession();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDisplayCompletions(CompletionInfo[] completions) {
|
|
|
|
if (false) {
|
|
|
|
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-01-16 20:21:23 +00:00
|
|
|
setSuggestions(null, false, false, false);
|
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());
|
|
|
|
}
|
|
|
|
//CharSequence typedWord = mWord.getTypedWord();
|
2010-01-16 20:21:23 +00:00
|
|
|
setSuggestions(stringList, true, true, true);
|
2009-03-13 22:11:42 +00:00
|
|
|
mBestWord = null;
|
|
|
|
setCandidatesViewShown(isCandidateStripVisible() || mCompletionOn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setCandidatesViewShown(boolean shown) {
|
|
|
|
// TODO: Remove this if we support candidates with hard keyboard
|
|
|
|
if (onEvaluateInputViewShown()) {
|
|
|
|
super.setCandidatesViewShown(shown);
|
|
|
|
}
|
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
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
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
@Override
|
|
|
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
|
|
|
switch (keyCode) {
|
|
|
|
case KeyEvent.KEYCODE_BACK:
|
|
|
|
if (event.getRepeatCount() == 0 && mInputView != null) {
|
|
|
|
if (mInputView.handleBack()) {
|
|
|
|
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;
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
// Enable shift key and DPAD to do selections
|
|
|
|
if (mInputView != null && mInputView.isShown() && mInputView.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-01-28 20:34:01 +00:00
|
|
|
if (mInputView != null) {
|
|
|
|
mKeyboardSwitcher.setVoiceMode(mEnableVoice, mVoiceOnPrimary);
|
|
|
|
}
|
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-02-20 00:38:58 +00:00
|
|
|
checkAddToDictionary(mComposing, 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);
|
|
|
|
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();
|
|
|
|
if (attr != null && mInputView != null && mKeyboardSwitcher.isAlphabetMode()
|
|
|
|
&& ic != null) {
|
2010-01-24 15:34:07 +00:00
|
|
|
mInputView.setShifted(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
|
|
|
|
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);
|
|
|
|
if (lastOne != null && lastOne.length() == 1 && lastOne.charAt(0) == '.'
|
|
|
|
&& text.charAt(0) == '.') {
|
|
|
|
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);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean isAlphabet(int code) {
|
|
|
|
if (Character.isLetter(code)) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
// Implementation of KeyboardViewListener
|
|
|
|
|
|
|
|
public void onKey(int primaryCode, int[] keyCodes) {
|
|
|
|
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;
|
|
|
|
switch (primaryCode) {
|
|
|
|
case Keyboard.KEYCODE_DELETE:
|
|
|
|
handleBackspace();
|
|
|
|
mDeleteCount++;
|
|
|
|
break;
|
|
|
|
case Keyboard.KEYCODE_SHIFT:
|
|
|
|
handleShift();
|
|
|
|
break;
|
|
|
|
case Keyboard.KEYCODE_CANCEL:
|
|
|
|
if (mOptionsDialog == null || !mOptionsDialog.isShowing()) {
|
|
|
|
handleClose();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LatinKeyboardView.KEYCODE_OPTIONS:
|
|
|
|
showOptionsMenu();
|
|
|
|
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;
|
2009-03-13 22:11:42 +00:00
|
|
|
case LatinKeyboardView.KEYCODE_SHIFT_LONGPRESS:
|
|
|
|
if (mCapsLock) {
|
|
|
|
handleShift();
|
|
|
|
} else {
|
|
|
|
toggleCapsLock();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Keyboard.KEYCODE_MODE_CHANGE:
|
|
|
|
changeKeyboardMode();
|
|
|
|
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;
|
|
|
|
}
|
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();
|
|
|
|
}
|
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;
|
|
|
|
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;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void handleBackspace() {
|
2010-01-16 20:21:23 +00:00
|
|
|
if (VOICE_INSTALLED && mVoiceInputHighlighted) {
|
|
|
|
revertVoiceInput();
|
|
|
|
return;
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
boolean deleteChar = false;
|
|
|
|
InputConnection ic = getCurrentInputConnection();
|
|
|
|
if (ic == null) return;
|
|
|
|
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();
|
|
|
|
if (TextEntryState.getState() == TextEntryState.STATE_UNDO_COMMIT) {
|
|
|
|
revertLastWord(deleteChar);
|
|
|
|
return;
|
|
|
|
} else if (deleteChar) {
|
|
|
|
sendDownUpKeyEvents(KeyEvent.KEYCODE_DEL);
|
|
|
|
if (mDeleteCount > DELETE_ACCELERATE_AT) {
|
|
|
|
sendDownUpKeyEvents(KeyEvent.KEYCODE_DEL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mJustRevertedSeparator = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handleShift() {
|
2009-12-04 19:58:57 +00:00
|
|
|
mHandler.removeMessages(MSG_UPDATE_SHIFT_STATE);
|
2009-03-13 22:11:42 +00:00
|
|
|
if (mKeyboardSwitcher.isAlphabetMode()) {
|
|
|
|
// Alphabet keyboard
|
|
|
|
checkToggleCapsLock();
|
|
|
|
mInputView.setShifted(mCapsLock || !mInputView.isShifted());
|
|
|
|
} else {
|
|
|
|
mKeyboardSwitcher.toggleShift();
|
|
|
|
}
|
|
|
|
}
|
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();
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
if (isAlphabet(primaryCode) && isPredictionOn() && !isCursorTouchingWord()) {
|
|
|
|
if (!mPredicting) {
|
|
|
|
mPredicting = true;
|
|
|
|
mComposing.setLength(0);
|
|
|
|
mWord.reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mInputView.isShifted()) {
|
2009-08-04 01:16:19 +00:00
|
|
|
// TODO: This doesn't work with ß, need to fix it in the next release.
|
2009-10-09 14:03:11 +00:00
|
|
|
if (keyCodes == null || keyCodes[0] < Character.MIN_CODE_POINT
|
|
|
|
|| keyCodes[0] > Character.MAX_CODE_POINT) {
|
|
|
|
return;
|
|
|
|
}
|
2009-08-04 01:16:19 +00:00
|
|
|
primaryCode = new String(keyCodes, 0, 1).toUpperCase().charAt(0);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
if (mPredicting) {
|
|
|
|
if (mInputView.isShifted() && mComposing.length() == 0) {
|
|
|
|
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());
|
2009-03-13 22:11:42 +00:00
|
|
|
measureCps();
|
|
|
|
TextEntryState.typedCharacter((char) primaryCode, isWordSeparator(primaryCode));
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handleSeparator(int primaryCode) {
|
2010-01-16 20:21:23 +00:00
|
|
|
if (VOICE_INSTALLED && mVoiceInputHighlighted) {
|
|
|
|
commitVoiceInput();
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
boolean pickedDefault = false;
|
|
|
|
// Handle separator
|
|
|
|
InputConnection ic = getCurrentInputConnection();
|
|
|
|
if (ic != null) {
|
|
|
|
ic.beginBatchEdit();
|
|
|
|
}
|
|
|
|
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)) {
|
|
|
|
pickDefaultSuggestion();
|
|
|
|
pickedDefault = true;
|
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);
|
|
|
|
TextEntryState.typedCharacter((char) primaryCode, true);
|
2010-01-28 18:09:44 +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
|
|
|
//else if (TextEntryState.STATE_SPACE_AFTER_ACCEPTED) {
|
|
|
|
doubleSpace();
|
|
|
|
}
|
|
|
|
if (pickedDefault && mBestWord != null) {
|
|
|
|
TextEntryState.acceptedDefault(mWord.getTypedWord(), mBestWord);
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
mInputView.closing();
|
|
|
|
TextEntryState.endSession();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void checkToggleCapsLock() {
|
|
|
|
if (mInputView.getKeyboard().isShifted()) {
|
|
|
|
toggleCapsLock();
|
|
|
|
}
|
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
private void toggleCapsLock() {
|
|
|
|
mCapsLock = !mCapsLock;
|
|
|
|
if (mKeyboardSwitcher.isAlphabetMode()) {
|
|
|
|
((LatinKeyboard) mInputView.getKeyboard()).setShiftLocked(mCapsLock);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void postUpdateSuggestions() {
|
|
|
|
mHandler.removeMessages(MSG_UPDATE_SUGGESTIONS);
|
|
|
|
mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_UPDATE_SUGGESTIONS), 100);
|
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
private boolean isPredictionOn() {
|
|
|
|
boolean predictionOn = mPredictionOn;
|
|
|
|
//if (isFullscreenMode()) predictionOn &= mPredictionLandscape;
|
|
|
|
return predictionOn;
|
|
|
|
}
|
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;
|
|
|
|
if (mInputView != null) {
|
|
|
|
setInputView(mInputView);
|
|
|
|
}
|
|
|
|
updateInputViewShown();
|
|
|
|
}});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void switchToRecognitionStatusView() {
|
|
|
|
mHandler.post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
mRecognizing = true;
|
|
|
|
setInputView(mVoiceInput.getView());
|
|
|
|
updateInputViewShown();
|
|
|
|
}});
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
editor.commit();
|
|
|
|
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);
|
|
|
|
editor.commit();
|
|
|
|
mHasUsedVoiceInputUnsupportedLocale = true;
|
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
// Clear N-best suggestions
|
|
|
|
setSuggestions(null, false, false, true);
|
|
|
|
|
|
|
|
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();
|
|
|
|
lp.token = mInputView.getWindowToken();
|
|
|
|
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()
|
|
|
|
|| (mKeyboardSwitcher.isAlphabetMode() && mInputView.isShifted());
|
|
|
|
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();
|
|
|
|
|
|
|
|
mVoiceInput.logVoiceInputDelivered();
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
// Show N-Best alternates, if there is more than one choice.
|
|
|
|
if (nBest.size() > 1) {
|
|
|
|
mImmediatelyAfterVoiceSuggestions = true;
|
|
|
|
mShowingVoiceSuggestions = true;
|
|
|
|
setSuggestions(nBest.subList(1, nBest.size()), false, true, true);
|
|
|
|
setCandidatesViewShown(true);
|
|
|
|
}
|
|
|
|
mVoiceInputHighlighted = true;
|
|
|
|
mWordToSuggestions.putAll(mVoiceResults.alternatives);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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-01-16 20:21:23 +00:00
|
|
|
mSuggestionShouldReplaceCurrentWord = false;
|
|
|
|
|
2010-02-05 22:07:04 +00:00
|
|
|
((LatinKeyboard) mInputView.getKeyboard()).setPreferredLetters(null);
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
List<CharSequence> stringList = mSuggest.getSuggestions(mInputView, mWord, false);
|
2010-02-05 22:07:04 +00:00
|
|
|
int[] nextLettersFrequencies = mSuggest.getNextLettersFrequencies();
|
|
|
|
|
|
|
|
((LatinKeyboard) mInputView.getKeyboard()).setPreferredLetters(nextLettersFrequencies);
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
boolean correctionAvailable = mSuggest.hasMinimalCorrection();
|
|
|
|
//|| mCorrectionMode == mSuggest.CORRECTION_FULL;
|
|
|
|
CharSequence typedWord = mWord.getTypedWord();
|
|
|
|
// If we're in basic correct
|
2009-12-01 19:44:22 +00:00
|
|
|
boolean typedWordValid = mSuggest.isValidWord(typedWord) ||
|
|
|
|
(preferCapitalization() && mSuggest.isValidWord(typedWord.toString().toLowerCase()));
|
2009-03-13 22:11:42 +00:00
|
|
|
if (mCorrectionMode == Suggest.CORRECTION_FULL) {
|
|
|
|
correctionAvailable |= typedWordValid;
|
|
|
|
}
|
2009-07-23 19:17:48 +00:00
|
|
|
// Don't auto-correct words with multiple capital letter
|
|
|
|
correctionAvailable &= !mWord.isMostlyCaps();
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void pickDefaultSuggestion() {
|
|
|
|
// Complete any pending candidate query first
|
|
|
|
if (mHandler.hasMessages(MSG_UPDATE_SUGGESTIONS)) {
|
|
|
|
mHandler.removeMessages(MSG_UPDATE_SUGGESTIONS);
|
|
|
|
updateSuggestions();
|
|
|
|
}
|
|
|
|
if (mBestWord != null) {
|
|
|
|
TextEntryState.acceptedDefault(mWord.getTypedWord(), mBestWord);
|
|
|
|
mJustAccepted = true;
|
|
|
|
pickSuggestion(mBestWord);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void pickSuggestionManually(int index, CharSequence suggestion) {
|
2010-01-16 20:21:23 +00:00
|
|
|
if (mAfterVoiceInput && mShowingVoiceSuggestions) mVoiceInput.logNBestChoose(index);
|
|
|
|
|
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
|
|
|
|
if (suggestion.length() == 1 && isWordSeparator(suggestion.charAt(0))) {
|
|
|
|
onKey(suggestion.charAt(0), null);
|
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;
|
2009-03-13 22:11:42 +00:00
|
|
|
pickSuggestion(suggestion);
|
|
|
|
TextEntryState.acceptedSuggestion(mComposing.toString(), suggestion);
|
|
|
|
// Follow it with a space
|
|
|
|
if (mAutoSpace) {
|
|
|
|
sendSpace();
|
2010-02-07 00:34:43 +00:00
|
|
|
mJustAddedAutoSpace = true;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
// Fool the state watcher so that a subsequent backspace will not do a revert
|
|
|
|
TextEntryState.typedCharacter((char) KEYCODE_SPACE, true);
|
2010-02-20 00:38:58 +00:00
|
|
|
if (index == 0 && mCorrectionMode > 0 && !mSuggest.isValidWord(suggestion)) {
|
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
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
private void pickSuggestion(CharSequence suggestion) {
|
|
|
|
if (mCapsLock) {
|
|
|
|
suggestion = suggestion.toString().toUpperCase();
|
2010-01-28 18:09:44 +00:00
|
|
|
} else if (preferCapitalization()
|
2009-03-13 22:11:42 +00:00
|
|
|
|| (mKeyboardSwitcher.isAlphabetMode() && mInputView.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-01-16 20:21:23 +00:00
|
|
|
if (mSuggestionShouldReplaceCurrentWord) {
|
|
|
|
EditingUtil.deleteWordAtCursor(ic, getWordSeparators());
|
|
|
|
}
|
|
|
|
if (!VoiceInput.DELETE_SYMBOL.equals(suggestion)) {
|
|
|
|
ic.commitText(suggestion, 1);
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2009-07-17 19:51:45 +00:00
|
|
|
// Add the word to the auto dictionary if it's not a known word
|
2010-02-20 00:38:58 +00:00
|
|
|
checkAddToDictionary(suggestion, FREQUENCY_FOR_PICKED);
|
2009-03-13 22:11:42 +00:00
|
|
|
mPredicting = false;
|
|
|
|
mCommittedLength = suggestion.length();
|
2010-02-03 23:35:49 +00:00
|
|
|
setNextSuggestions();
|
2009-03-13 22:11:42 +00:00
|
|
|
updateShiftKeyState(getCurrentInputEditorInfo());
|
|
|
|
}
|
|
|
|
|
2010-02-03 23:35:49 +00:00
|
|
|
private void setNextSuggestions() {
|
|
|
|
setSuggestions(mSuggestPuncList, false, false, false);
|
|
|
|
}
|
|
|
|
|
2010-02-20 00:38:58 +00:00
|
|
|
private void checkAddToDictionary(CharSequence suggestion, int frequencyDelta) {
|
|
|
|
if (mAutoDictionary.isValidWord(suggestion)
|
|
|
|
|| !mSuggest.isValidWord(suggestion.toString().toLowerCase())) {
|
|
|
|
mAutoDictionary.addWord(suggestion.toString(), frequencyDelta);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
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;
|
|
|
|
ic.beginBatchEdit();
|
|
|
|
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();
|
|
|
|
ic.endBatchEdit();
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isSentenceSeparator(int code) {
|
|
|
|
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)) {
|
|
|
|
mInputView.startPlaying(text.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onRelease(int primaryCode) {
|
2010-01-30 04:09:49 +00:00
|
|
|
// Reset any drag flags in the keyboard
|
|
|
|
((LatinKeyboard) mInputView.getKeyboard()).keyReleased();
|
2009-03-13 22:11:42 +00:00
|
|
|
//vibrate();
|
|
|
|
}
|
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 fieldIsRecommendedForVoice(FieldContext fieldContext) {
|
|
|
|
// TODO: Move this logic into the VoiceInput method.
|
|
|
|
return !mPasswordText && !mEmailText && mVoiceInput.isRecommendedField(fieldContext);
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
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))
|
|
|
|
&& RecognitionManager.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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Only trigger a swipe action if the user hasn't typed X millis before
|
|
|
|
* now, and if they don't type Y millis after the swipe is detected. This
|
|
|
|
* delays the onset of the swipe action by Y millis.
|
|
|
|
*/
|
|
|
|
private void conservativelyTriggerSwipeAction(final Runnable action) {
|
|
|
|
if (userHasNotTypedRecently()) {
|
|
|
|
mSwipeTriggerTimeMillis = System.currentTimeMillis();
|
|
|
|
mHandler.sendMessageDelayed(
|
|
|
|
mHandler.obtainMessage(MSG_START_LISTENING_AFTER_SWIPE),
|
|
|
|
MIN_MILLIS_AFTER_SWIPE_TO_WAIT_FOR_TYPING);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
if (mInputView != null) {
|
|
|
|
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-02-11 01:45:35 +00:00
|
|
|
if (mInputView != null) {
|
|
|
|
mInputView.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY,
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
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);
|
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;
|
|
|
|
boolean different = !systemLocale.getLanguage().equalsIgnoreCase(mLocale.substring(0, 2));
|
|
|
|
mSuggest.setAutoTextEnabled(!different && mQuickFixes);
|
|
|
|
}
|
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
protected void launchSettings() {
|
|
|
|
launchSettings(LatinIMESettings.class);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void launchSettings(Class 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);
|
|
|
|
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-01-16 20:21:23 +00:00
|
|
|
mLocaleSupportedForVoiceInput = voiceInputSupportedLocales.contains(mLocale);
|
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-09 22:17:30 +00:00
|
|
|
final String voiceMode = sp.getString(PREF_VOICE_MODE, "");
|
|
|
|
boolean enableVoice = !voiceMode.equals(getString(R.string.voice_mode_off));
|
|
|
|
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;
|
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>();
|
|
|
|
String suggestPuncs = mResources.getString(R.string.suggested_punctuations);
|
|
|
|
if (suggestPuncs != null) {
|
|
|
|
for (int i = 0; i < suggestPuncs.length(); i++) {
|
|
|
|
mSuggestPuncList.add(suggestPuncs.subSequence(i, i + 1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-01-16 20:21:23 +00:00
|
|
|
CharSequence itemInputMethod = getString(R.string.inputMethod);
|
2009-03-13 22:11:42 +00:00
|
|
|
builder.setItems(new CharSequence[] {
|
|
|
|
itemSettings, itemInputMethod},
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2009-10-12 20:48:35 +00:00
|
|
|
builder.setTitle(mResources.getString(R.string.english_ime_name));
|
2009-03-13 22:11:42 +00:00
|
|
|
mOptionsDialog = builder.create();
|
|
|
|
Window window = mOptionsDialog.getWindow();
|
|
|
|
WindowManager.LayoutParams lp = window.getAttributes();
|
|
|
|
lp.token = mInputView.getWindowToken();
|
|
|
|
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()) {
|
|
|
|
((LatinKeyboard) mInputView.getKeyboard()).setShiftLocked(mCapsLock);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
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 static final boolean PERF_DEBUG = false;
|
|
|
|
private long mLastCpsTime;
|
|
|
|
private static final int CPS_BUFFER_SIZE = 16;
|
|
|
|
private long[] mCpsIntervals = new long[CPS_BUFFER_SIZE];
|
|
|
|
private int mCpsIndex;
|
2009-12-18 21:39:18 +00:00
|
|
|
private boolean mInputTypeNoAutoCorrect;
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
private void measureCps() {
|
|
|
|
if (!LatinIME.PERF_DEBUG) return;
|
|
|
|
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
|
|
|
|
|
|
|
class AutoDictionary extends ExpandableDictionary {
|
2009-07-28 23:33:36 +00:00
|
|
|
// If the user touches a typed word 2 times or more, it will become valid.
|
|
|
|
private static final int VALIDITY_THRESHOLD = 2 * FREQUENCY_FOR_PICKED;
|
|
|
|
// If the user touches a typed word 5 times or more, it will be added to the user dict.
|
2009-12-17 03:21:11 +00:00
|
|
|
private static final int PROMOTION_THRESHOLD = 4 * FREQUENCY_FOR_PICKED;
|
2009-07-17 19:51:45 +00:00
|
|
|
|
|
|
|
public AutoDictionary(Context context) {
|
|
|
|
super(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isValidWord(CharSequence word) {
|
|
|
|
final int frequency = getWordFrequency(word);
|
2009-12-17 03:21:11 +00:00
|
|
|
return frequency >= VALIDITY_THRESHOLD;
|
2009-07-17 19:51:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2009-07-28 23:33:36 +00:00
|
|
|
public void addWord(String word, int addFrequency) {
|
2009-08-04 00:47:44 +00:00
|
|
|
final int length = word.length();
|
|
|
|
// Don't add very short or very long words.
|
|
|
|
if (length < 2 || length > getMaxWordLength()) return;
|
2010-01-24 15:34:07 +00:00
|
|
|
if (mWord.isAutoCapitalized()) {
|
|
|
|
// Remove caps before adding
|
|
|
|
word = Character.toLowerCase(word.charAt(0))
|
|
|
|
+ word.substring(1);
|
|
|
|
}
|
2009-12-17 03:21:11 +00:00
|
|
|
int freq = getWordFrequency(word);
|
|
|
|
freq = freq < 0 ? addFrequency : freq + addFrequency;
|
|
|
|
super.addWord(word, freq);
|
|
|
|
if (freq >= PROMOTION_THRESHOLD) {
|
2009-07-28 23:33:36 +00:00
|
|
|
LatinIME.this.promoteToUserDictionary(word, FREQUENCY_FOR_AUTO_ADD);
|
2009-07-17 19:51:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|