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-12-02 09:46:21 +00:00
|
|
|
import com.android.inputmethod.keyboard.Keyboard;
|
|
|
|
import com.android.inputmethod.keyboard.KeyboardActionListener;
|
|
|
|
import com.android.inputmethod.keyboard.KeyboardId;
|
2010-12-02 11:54:32 +00:00
|
|
|
import com.android.inputmethod.keyboard.KeyboardSwitcher;
|
2010-12-02 09:46:21 +00:00
|
|
|
import com.android.inputmethod.keyboard.KeyboardView;
|
|
|
|
import com.android.inputmethod.keyboard.LatinKeyboardView;
|
2010-12-09 12:06:26 +00:00
|
|
|
import com.android.inputmethod.latin.Utils.RingCharBuffer;
|
2010-11-21 01:36:37 +00:00
|
|
|
import com.android.inputmethod.voice.VoiceIMEConnector;
|
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.media.AudioManager;
|
|
|
|
import android.os.Debug;
|
|
|
|
import android.os.Handler;
|
|
|
|
import android.os.Message;
|
|
|
|
import android.os.SystemClock;
|
2010-11-11 09:15:41 +00:00
|
|
|
import android.os.Vibrator;
|
2010-09-27 03:55:21 +00:00
|
|
|
import android.preference.PreferenceActivity;
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.preference.PreferenceManager;
|
|
|
|
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-12-06 12:26:38 +00:00
|
|
|
import android.view.Gravity;
|
2010-02-11 01:45:35 +00:00
|
|
|
import android.view.HapticFeedbackConstants;
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.view.KeyEvent;
|
2010-12-06 12:26:38 +00:00
|
|
|
import android.view.LayoutInflater;
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.view.View;
|
2010-11-21 03:43:10 +00:00
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.view.ViewParent;
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.view.Window;
|
|
|
|
import android.view.WindowManager;
|
|
|
|
import android.view.inputmethod.CompletionInfo;
|
|
|
|
import android.view.inputmethod.EditorInfo;
|
2010-01-16 20:21:23 +00:00
|
|
|
import android.view.inputmethod.ExtractedText;
|
|
|
|
import android.view.inputmethod.ExtractedTextRequest;
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.view.inputmethod.InputConnection;
|
|
|
|
import android.view.inputmethod.InputMethodManager;
|
2010-11-17 07:35:35 +00:00
|
|
|
import android.view.inputmethod.InputMethodSubtype;
|
2010-12-06 12:26:38 +00:00
|
|
|
import android.widget.HorizontalScrollView;
|
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-09-28 03:23:26 +00:00
|
|
|
import java.util.Arrays;
|
2010-01-16 20:21:23 +00:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.Locale;
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
/**
|
|
|
|
* Input method implementation for Qwerty'ish keyboard.
|
|
|
|
*/
|
2010-12-09 07:36:45 +00:00
|
|
|
public class LatinIME extends InputMethodService implements KeyboardActionListener,
|
|
|
|
SharedPreferences.OnSharedPreferenceChangeListener, Tutorial.TutorialListener {
|
2010-01-16 20:21:23 +00:00
|
|
|
private static final String TAG = "LatinIME";
|
2010-08-20 05:35:02 +00:00
|
|
|
private static final boolean PERF_DEBUG = false;
|
2010-11-21 01:36:37 +00:00
|
|
|
private static final boolean DEBUG = false;
|
|
|
|
private static final boolean TRACE = false;
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-10-27 09:05:27 +00:00
|
|
|
private static final int DELAY_UPDATE_SUGGESTIONS = 180;
|
|
|
|
private static final int DELAY_UPDATE_OLD_SUGGESTIONS = 300;
|
2010-11-16 09:07:06 +00:00
|
|
|
private static final int DELAY_UPDATE_SHIFT_STATE = 300;
|
|
|
|
private static final int DELAY_START_TUTORIAL = 500;
|
2010-10-27 09:05:27 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
// How many continuous deletes at which to start deleting at a higher speed.
|
|
|
|
private static final int DELETE_ACCELERATE_AT = 20;
|
|
|
|
// Key events coming any faster than this are long-presses.
|
2009-07-28 23:33:36 +00:00
|
|
|
private static final int QUICK_PRESS = 200;
|
2010-01-28 18:09:44 +00:00
|
|
|
|
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-11-13 10:09:30 +00:00
|
|
|
private int mSuggestionVisibility;
|
|
|
|
private static final int SUGGESTION_VISIBILILTY_SHOW_VALUE
|
|
|
|
= R.string.prefs_suggestion_visibility_show_value;
|
|
|
|
private static final int SUGGESTION_VISIBILILTY_SHOW_ONLY_PORTRAIT_VALUE
|
|
|
|
= R.string.prefs_suggestion_visibility_show_only_portrait_value;
|
|
|
|
private static final int SUGGESTION_VISIBILILTY_HIDE_VALUE
|
|
|
|
= R.string.prefs_suggestion_visibility_hide_value;
|
|
|
|
|
|
|
|
private static final int[] SUGGESTION_VISIBILITY_VALUE_ARRAY = new int[] {
|
|
|
|
SUGGESTION_VISIBILILTY_SHOW_VALUE,
|
|
|
|
SUGGESTION_VISIBILILTY_SHOW_ONLY_PORTRAIT_VALUE,
|
|
|
|
SUGGESTION_VISIBILILTY_HIDE_VALUE
|
|
|
|
};
|
|
|
|
|
2010-12-06 12:26:38 +00:00
|
|
|
private View mCandidateViewContainer;
|
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-28 18:09:44 +00:00
|
|
|
|
2010-11-25 00:20:28 +00:00
|
|
|
private InputMethodManager mImm;
|
2010-11-13 08:46:45 +00:00
|
|
|
private KeyboardSwitcher mKeyboardSwitcher;
|
2010-11-17 07:35:35 +00:00
|
|
|
private SubtypeSwitcher mSubtypeSwitcher;
|
2010-11-21 01:36:37 +00:00
|
|
|
private VoiceIMEConnector mVoiceConnector;
|
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-10-08 13:17:16 +00:00
|
|
|
private Resources mResources;
|
2010-11-26 04:08:36 +00:00
|
|
|
private SharedPreferences mPrefs;
|
2009-10-12 20:48:35 +00:00
|
|
|
|
2010-11-13 08:46:45 +00:00
|
|
|
private final StringBuilder mComposing = new StringBuilder();
|
2009-03-13 22:11:42 +00:00
|
|
|
private WordComposer mWord = new WordComposer();
|
|
|
|
private CharSequence mBestWord;
|
2010-11-25 00:20:28 +00:00
|
|
|
private boolean mPredicting;
|
2009-03-13 22:11:42 +00:00
|
|
|
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;
|
|
|
|
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-11-21 01:36:37 +00:00
|
|
|
|
2010-11-25 00:20:28 +00:00
|
|
|
private int mCorrectionMode;
|
|
|
|
private int mCommittedLength;
|
|
|
|
private int mOrientation;
|
2010-08-20 05:35:02 +00:00
|
|
|
// Keep track of the last selection range to decide if we need to show word alternatives
|
2010-11-25 00:20:28 +00:00
|
|
|
private int mLastSelectionStart;
|
|
|
|
private int mLastSelectionEnd;
|
|
|
|
private List<CharSequence> mSuggestPuncList;
|
2010-08-20 05:35:02 +00:00
|
|
|
|
|
|
|
// 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;
|
2010-11-16 09:57:03 +00:00
|
|
|
private boolean mJustReverted;
|
2009-03-13 22:11:42 +00:00
|
|
|
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
|
2010-11-13 08:46:45 +00:00
|
|
|
private static final float FX_VOLUME = -1.0f;
|
2009-03-13 22:11:42 +00:00
|
|
|
private boolean mSilentMode;
|
|
|
|
|
2010-08-20 05:35:02 +00:00
|
|
|
/* package */ String mWordSeparators;
|
2009-03-13 22:11:42 +00:00
|
|
|
private String mSentenceSeparators;
|
2010-08-20 05:35:02 +00:00
|
|
|
private String mSuggestPuncs;
|
2010-11-21 01:36:37 +00:00
|
|
|
// TODO: Move this flag to VoiceIMEConnector
|
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-11-13 08:46:45 +00:00
|
|
|
private final ArrayList<WordAlternatives> mWordHistory = new ArrayList<WordAlternatives>();
|
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
|
|
|
|
2010-12-02 11:54:32 +00:00
|
|
|
public final UIHandler mHandler = new UIHandler();
|
2010-11-16 09:07:06 +00:00
|
|
|
|
2010-11-21 01:36:37 +00:00
|
|
|
public class UIHandler extends Handler {
|
2010-11-16 09:07:06 +00:00
|
|
|
private static final int MSG_UPDATE_SUGGESTIONS = 0;
|
|
|
|
private static final int MSG_UPDATE_OLD_SUGGESTIONS = 1;
|
|
|
|
private static final int MSG_UPDATE_SHIFT_STATE = 2;
|
|
|
|
private static final int MSG_VOICE_RESULTS = 3;
|
|
|
|
private static final int MSG_START_TUTORIAL = 4;
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
@Override
|
|
|
|
public void handleMessage(Message msg) {
|
|
|
|
switch (msg.what) {
|
2010-11-16 09:07:06 +00:00
|
|
|
case MSG_UPDATE_SUGGESTIONS:
|
|
|
|
updateSuggestions();
|
|
|
|
break;
|
|
|
|
case MSG_UPDATE_OLD_SUGGESTIONS:
|
|
|
|
setOldSuggestions();
|
|
|
|
break;
|
|
|
|
case MSG_UPDATE_SHIFT_STATE:
|
2010-11-13 08:16:34 +00:00
|
|
|
mKeyboardSwitcher.updateShiftState();
|
2010-11-16 09:07:06 +00:00
|
|
|
break;
|
|
|
|
case MSG_VOICE_RESULTS:
|
2010-11-21 01:36:37 +00:00
|
|
|
mVoiceConnector.handleVoiceResults(mKeyboardSwitcher, preferCapitalization()
|
|
|
|
|| (mKeyboardSwitcher.isAlphabetMode()
|
|
|
|
&& mKeyboardSwitcher.isShiftedOrShiftLocked()));
|
2010-11-16 09:07:06 +00:00
|
|
|
break;
|
|
|
|
case MSG_START_TUTORIAL:
|
|
|
|
if (mTutorial == null) {
|
|
|
|
if (mKeyboardSwitcher.isInputViewShown()) {
|
|
|
|
mTutorial = new Tutorial(LatinIME.this, mKeyboardSwitcher);
|
|
|
|
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
|
|
|
}
|
2010-11-16 09:07:06 +00:00
|
|
|
}
|
|
|
|
break;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
}
|
2010-11-16 09:07:06 +00:00
|
|
|
|
|
|
|
public void postUpdateSuggestions() {
|
|
|
|
removeMessages(MSG_UPDATE_SUGGESTIONS);
|
|
|
|
sendMessageDelayed(obtainMessage(MSG_UPDATE_SUGGESTIONS), DELAY_UPDATE_SUGGESTIONS);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void cancelUpdateSuggestions() {
|
|
|
|
removeMessages(MSG_UPDATE_SUGGESTIONS);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasPendingUpdateSuggestions() {
|
|
|
|
return hasMessages(MSG_UPDATE_SUGGESTIONS);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void postUpdateOldSuggestions() {
|
|
|
|
removeMessages(MSG_UPDATE_OLD_SUGGESTIONS);
|
|
|
|
sendMessageDelayed(obtainMessage(MSG_UPDATE_OLD_SUGGESTIONS),
|
|
|
|
DELAY_UPDATE_OLD_SUGGESTIONS);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void cancelUpdateOldSuggestions() {
|
|
|
|
removeMessages(MSG_UPDATE_OLD_SUGGESTIONS);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void postUpdateShiftKeyState() {
|
|
|
|
removeMessages(MSG_UPDATE_SHIFT_STATE);
|
|
|
|
sendMessageDelayed(obtainMessage(MSG_UPDATE_SHIFT_STATE), DELAY_UPDATE_SHIFT_STATE);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void cancelUpdateShiftState() {
|
|
|
|
removeMessages(MSG_UPDATE_SHIFT_STATE);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void updateVoiceResults() {
|
|
|
|
sendMessage(obtainMessage(MSG_VOICE_RESULTS));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void startTutorial() {
|
|
|
|
sendMessageDelayed(obtainMessage(MSG_START_TUTORIAL), DELAY_START_TUTORIAL);
|
|
|
|
}
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
|
2010-10-08 13:17:16 +00:00
|
|
|
@Override
|
|
|
|
public void onCreate() {
|
2010-11-26 04:08:36 +00:00
|
|
|
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
|
|
|
mPrefs = prefs;
|
|
|
|
LatinImeLogger.init(this, prefs);
|
|
|
|
SubtypeSwitcher.init(this, prefs);
|
|
|
|
KeyboardSwitcher.init(this, prefs);
|
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();
|
2010-11-25 00:20:28 +00:00
|
|
|
mImm = ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE));
|
2009-10-12 20:48:35 +00:00
|
|
|
final Configuration conf = mResources.getConfiguration();
|
2010-11-17 07:35:35 +00:00
|
|
|
mSubtypeSwitcher = SubtypeSwitcher.getInstance();
|
|
|
|
mKeyboardSwitcher = KeyboardSwitcher.getInstance();
|
2010-12-09 12:06:26 +00:00
|
|
|
mReCorrectionEnabled = prefs.getBoolean(Settings.PREF_RECORRECTION_ENABLED,
|
2010-09-06 10:18:38 +00:00
|
|
|
getResources().getBoolean(R.bool.default_recorrection_enabled));
|
2010-08-20 05:35:02 +00:00
|
|
|
|
2010-12-09 12:06:26 +00:00
|
|
|
Utils.GCUtils.getInstance().reset();
|
2010-08-20 05:35:02 +00:00
|
|
|
boolean tryGC = true;
|
2010-12-09 12:06:26 +00:00
|
|
|
for (int i = 0; i < Utils.GCUtils.GC_TRY_LOOP_MAX && tryGC; ++i) {
|
2010-08-20 05:35:02 +00:00
|
|
|
try {
|
2010-11-17 07:35:35 +00:00
|
|
|
initSuggest();
|
2010-08-20 05:35:02 +00:00
|
|
|
tryGC = false;
|
|
|
|
} catch (OutOfMemoryError e) {
|
2010-12-09 12:06:26 +00:00
|
|
|
tryGC = Utils.GCUtils.getInstance().tryGCOrWait("InitSuggest", e);
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-11-26 04:08:36 +00:00
|
|
|
mVoiceConnector = VoiceIMEConnector.init(this, prefs, mHandler);
|
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
|
|
|
|
*/
|
2010-11-13 08:46:45 +00:00
|
|
|
public static int[] getDictionary(Resources res) {
|
2010-08-20 05:35:02 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2010-11-17 07:35:35 +00:00
|
|
|
private void initSuggest() {
|
|
|
|
updateAutoTextEnabled();
|
2010-11-18 00:55:23 +00:00
|
|
|
String locale = mSubtypeSwitcher.getInputLocaleStr();
|
2009-10-12 20:48:35 +00:00
|
|
|
|
|
|
|
Resources orig = getResources();
|
2010-11-17 07:35:35 +00:00
|
|
|
Locale savedLocale = mSubtypeSwitcher.changeSystemLocale(new Locale(locale));
|
2009-10-12 20:48:35 +00:00
|
|
|
if (mSuggest != null) {
|
|
|
|
mSuggest.close();
|
|
|
|
}
|
2010-11-26 04:08:36 +00:00
|
|
|
final SharedPreferences prefs = mPrefs;
|
2010-12-09 12:06:26 +00:00
|
|
|
mQuickFixes = prefs.getBoolean(Settings.PREF_QUICK_FIXES, true);
|
2010-08-20 05:35:02 +00:00
|
|
|
|
|
|
|
int[] dictionaries = getDictionary(orig);
|
|
|
|
mSuggest = new Suggest(this, dictionaries);
|
2010-11-26 04:08:36 +00:00
|
|
|
loadAndSetAutoCompletionThreshold(prefs);
|
2010-01-17 21:55:56 +00:00
|
|
|
if (mUserDictionary != null) mUserDictionary.close();
|
2010-11-17 07:35:35 +00:00
|
|
|
mUserDictionary = new UserDictionary(this, locale);
|
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-11-17 07:35:35 +00:00
|
|
|
mAutoDictionary = new AutoDictionary(this, this, locale, Suggest.DIC_AUTO);
|
2010-08-20 05:35:02 +00:00
|
|
|
if (mUserBigramDictionary != null) {
|
|
|
|
mUserBigramDictionary.close();
|
|
|
|
}
|
2010-11-17 07:35:35 +00:00
|
|
|
mUserBigramDictionary = new UserBigramDictionary(this, this, locale, Suggest.DIC_USER);
|
2010-08-20 05:35:02 +00:00
|
|
|
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);
|
|
|
|
|
2010-11-17 07:35:35 +00:00
|
|
|
mSubtypeSwitcher.changeSystemLocale(savedLocale);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2009-10-12 20:48:35 +00:00
|
|
|
|
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-11-21 01:36:37 +00:00
|
|
|
mVoiceConnector.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-11-17 07:35:35 +00:00
|
|
|
mSubtypeSwitcher.onConfigurationChanged(conf);
|
2010-11-25 01:02:50 +00:00
|
|
|
if (mSubtypeSwitcher.isKeyboardMode())
|
|
|
|
onKeyboardLanguageChanged();
|
2010-11-17 07:35:35 +00:00
|
|
|
updateAutoTextEnabled();
|
|
|
|
|
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-11-11 07:03:19 +00:00
|
|
|
final int mode = mKeyboardSwitcher.getKeyboardMode();
|
|
|
|
final EditorInfo attribute = getCurrentInputEditorInfo();
|
2010-11-12 23:26:54 +00:00
|
|
|
final int imeOptions = (attribute != null) ? attribute.imeOptions : 0;
|
2010-11-21 01:36:37 +00:00
|
|
|
mKeyboardSwitcher.loadKeyboard(mode, imeOptions,
|
|
|
|
mVoiceConnector.isVoiceButtonEnabled(),
|
|
|
|
mVoiceConnector.isVoiceButtonOnPrimary());
|
2009-07-21 22:47:11 +00:00
|
|
|
}
|
2010-11-11 07:03:19 +00:00
|
|
|
|
2010-03-07 15:27:05 +00:00
|
|
|
mConfigurationChanging = true;
|
2009-03-13 22:11:42 +00:00
|
|
|
super.onConfigurationChanged(conf);
|
2010-11-21 01:36:37 +00:00
|
|
|
mVoiceConnector.onConfigurationChanged(mConfigurationChanging);
|
2010-03-07 15:27:05 +00:00
|
|
|
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-11-25 01:02:50 +00:00
|
|
|
return mKeyboardSwitcher.onCreateInputView();
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public View onCreateCandidatesView() {
|
2010-12-06 12:26:38 +00:00
|
|
|
LayoutInflater inflater = getLayoutInflater();
|
|
|
|
LinearLayout container = (LinearLayout)inflater.inflate(R.layout.candidates, null);
|
|
|
|
mCandidateViewContainer = container;
|
|
|
|
if (container.getPaddingRight() != 0) {
|
|
|
|
HorizontalScrollView scrollView =
|
|
|
|
(HorizontalScrollView) container.findViewById(R.id.candidates_scroll_view);
|
|
|
|
scrollView.setOverScrollMode(View.OVER_SCROLL_NEVER);
|
|
|
|
container.setGravity(Gravity.CENTER_HORIZONTAL);
|
|
|
|
}
|
|
|
|
mCandidateView = (CandidateView) container.findViewById(R.id.candidates);
|
2009-03-13 22:11:42 +00:00
|
|
|
mCandidateView.setService(this);
|
|
|
|
setCandidatesViewShown(true);
|
2010-12-06 12:26:38 +00:00
|
|
|
return container;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2010-11-02 18:34:45 +00:00
|
|
|
private static boolean isPasswordVariation(int variation) {
|
|
|
|
return variation == EditorInfo.TYPE_TEXT_VARIATION_PASSWORD
|
|
|
|
|| variation == EditorInfo.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD
|
|
|
|
|| variation == EditorInfo.TYPE_TEXT_VARIATION_WEB_PASSWORD;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static boolean isEmailVariation(int variation) {
|
|
|
|
return variation == EditorInfo.TYPE_TEXT_VARIATION_EMAIL_ADDRESS
|
|
|
|
|| variation == EditorInfo.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS;
|
|
|
|
}
|
|
|
|
|
2010-01-28 18:09:44 +00:00
|
|
|
@Override
|
2009-03-13 22:11:42 +00:00
|
|
|
public void onStartInputView(EditorInfo attribute, boolean restarting) {
|
2010-11-12 23:49:56 +00:00
|
|
|
final KeyboardSwitcher switcher = mKeyboardSwitcher;
|
|
|
|
LatinKeyboardView inputView = switcher.getInputView();
|
2010-11-21 03:43:10 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
// In landscape mode, this method gets called without the input view being created.
|
2010-08-20 05:35:02 +00:00
|
|
|
if (inputView == null) {
|
2009-03-13 22:11:42 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-11-25 01:02:50 +00:00
|
|
|
mSubtypeSwitcher.updateParametersOnStartInputView();
|
2010-11-18 00:55:23 +00:00
|
|
|
|
2009-10-12 20:48:35 +00:00
|
|
|
if (mRefreshKeyboardRequired) {
|
|
|
|
mRefreshKeyboardRequired = false;
|
2010-11-21 03:43:10 +00:00
|
|
|
onKeyboardLanguageChanged();
|
2009-10-12 20:48:35 +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.
|
|
|
|
int variation = attribute.inputType & EditorInfo.TYPE_MASK_VARIATION;
|
2010-11-21 01:36:37 +00:00
|
|
|
mVoiceConnector.resetVoiceStates(isPasswordVariation(variation));
|
2009-12-18 21:39:18 +00:00
|
|
|
mInputTypeNoAutoCorrect = false;
|
2009-03-13 22:11:42 +00:00
|
|
|
mPredictionOn = false;
|
|
|
|
mCompletionOn = false;
|
|
|
|
mCompletions = null;
|
2010-04-01 13:28:52 +00:00
|
|
|
mEnteredText = null;
|
|
|
|
|
2010-11-09 07:24:19 +00:00
|
|
|
final int mode;
|
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:
|
2010-12-02 09:46:21 +00:00
|
|
|
mode = KeyboardId.MODE_NUMBER;
|
2010-11-24 01:55:22 +00:00
|
|
|
break;
|
2009-03-13 22:11:42 +00:00
|
|
|
case EditorInfo.TYPE_CLASS_PHONE:
|
2010-12-02 09:46:21 +00:00
|
|
|
mode = KeyboardId.MODE_PHONE;
|
2009-03-13 22:11:42 +00:00
|
|
|
break;
|
|
|
|
case EditorInfo.TYPE_CLASS_TEXT:
|
|
|
|
//startPrediction();
|
|
|
|
mPredictionOn = true;
|
|
|
|
// Make sure that passwords are not displayed in candidate view
|
2010-11-02 18:34:45 +00:00
|
|
|
if (isPasswordVariation(variation)) {
|
2009-03-13 22:11:42 +00:00
|
|
|
mPredictionOn = false;
|
|
|
|
}
|
2010-11-02 18:34:45 +00:00
|
|
|
if (isEmailVariation(variation)
|
2009-03-13 22:11:42 +00:00
|
|
|
|| variation == EditorInfo.TYPE_TEXT_VARIATION_PERSON_NAME) {
|
|
|
|
mAutoSpace = false;
|
|
|
|
} else {
|
|
|
|
mAutoSpace = true;
|
|
|
|
}
|
2010-11-02 18:34:45 +00:00
|
|
|
if (isEmailVariation(variation)) {
|
2009-03-13 22:11:42 +00:00
|
|
|
mPredictionOn = false;
|
2010-12-02 09:46:21 +00:00
|
|
|
mode = KeyboardId.MODE_EMAIL;
|
2009-03-13 22:11:42 +00:00
|
|
|
} else if (variation == EditorInfo.TYPE_TEXT_VARIATION_URI) {
|
|
|
|
mPredictionOn = false;
|
2010-12-02 09:46:21 +00:00
|
|
|
mode = KeyboardId.MODE_URL;
|
2009-03-13 22:11:42 +00:00
|
|
|
} else if (variation == EditorInfo.TYPE_TEXT_VARIATION_SHORT_MESSAGE) {
|
2010-12-02 09:46:21 +00:00
|
|
|
mode = KeyboardId.MODE_IM;
|
2009-03-13 22:11:42 +00:00
|
|
|
} else if (variation == EditorInfo.TYPE_TEXT_VARIATION_FILTER) {
|
|
|
|
mPredictionOn = false;
|
2010-12-02 09:46:21 +00:00
|
|
|
mode = KeyboardId.MODE_TEXT;
|
2009-06-04 22:31:01 +00:00
|
|
|
} else if (variation == EditorInfo.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT) {
|
2010-12-02 09:46:21 +00:00
|
|
|
mode = KeyboardId.MODE_WEB;
|
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
|
|
|
}
|
2010-11-09 07:24:19 +00:00
|
|
|
} else {
|
2010-12-02 09:46:21 +00:00
|
|
|
mode = KeyboardId.MODE_TEXT;
|
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:
|
2010-12-02 09:46:21 +00:00
|
|
|
mode = KeyboardId.MODE_TEXT;
|
2010-11-09 07:24:19 +00:00
|
|
|
break;
|
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;
|
2010-11-09 07:24:19 +00:00
|
|
|
|
2010-11-11 00:10:10 +00:00
|
|
|
loadSettings(attribute);
|
2010-11-25 01:02:50 +00:00
|
|
|
if (mSubtypeSwitcher.isKeyboardMode()) {
|
|
|
|
switcher.loadKeyboard(mode, attribute.imeOptions,
|
|
|
|
mVoiceConnector.isVoiceButtonEnabled(),
|
|
|
|
mVoiceConnector.isVoiceButtonOnPrimary());
|
|
|
|
switcher.updateShiftState();
|
|
|
|
}
|
2009-12-18 21:39:18 +00:00
|
|
|
|
2010-11-11 04:37:18 +00:00
|
|
|
setCandidatesViewShownInternal(isCandidateStripVisible(),
|
2010-08-31 09:00:09 +00:00
|
|
|
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-11-13 10:09:30 +00:00
|
|
|
mPredictionOn = mPredictionOn && (mCorrectionMode > 0 || isSuggestionShown());
|
2010-09-28 23:35:29 +00:00
|
|
|
// If we just entered a text field, maybe it has some old text that requires correction
|
|
|
|
checkReCorrectionOnStart();
|
2009-03-26 00:39:38 +00:00
|
|
|
checkTutorial(attribute.privateImeOptions);
|
2010-10-17 10:10:46 +00:00
|
|
|
inputView.setForeground(true);
|
2010-11-21 03:43:10 +00:00
|
|
|
|
2010-11-24 08:32:23 +00:00
|
|
|
mVoiceConnector.onStartInputView(mKeyboardSwitcher.getInputView().getWindowToken());
|
2010-11-21 03:43:10 +00:00
|
|
|
|
2009-07-23 19:17:48 +00:00
|
|
|
if (TRACE) Debug.startMethodTracing("/data/trace/latinime");
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2010-09-28 23:35:29 +00:00
|
|
|
private void checkReCorrectionOnStart() {
|
2010-12-03 10:40:31 +00:00
|
|
|
if (!mReCorrectionEnabled) return;
|
|
|
|
|
|
|
|
final InputConnection ic = getCurrentInputConnection();
|
|
|
|
if (ic == null) return;
|
|
|
|
// There could be a pending composing span. Clean it up first.
|
|
|
|
ic.finishComposingText();
|
|
|
|
|
|
|
|
if (isSuggestionShown() && isPredictionOn()) {
|
2010-09-28 23:35:29 +00:00
|
|
|
// First get the cursor position. This is required by setOldSuggestions(), so that
|
|
|
|
// it can pass the correct range to setComposingRegion(). At this point, we don't
|
|
|
|
// have valid values for mLastSelectionStart/Stop because onUpdateSelection() has
|
|
|
|
// not been called yet.
|
|
|
|
ExtractedTextRequest etr = new ExtractedTextRequest();
|
|
|
|
etr.token = 0; // anything is fine here
|
|
|
|
ExtractedText et = ic.getExtractedText(etr, 0);
|
|
|
|
if (et == null) return;
|
|
|
|
|
|
|
|
mLastSelectionStart = et.startOffset + et.selectionStart;
|
|
|
|
mLastSelectionEnd = et.startOffset + et.selectionEnd;
|
|
|
|
|
|
|
|
// Then look for possible corrections in a delayed fashion
|
2010-10-05 13:51:59 +00:00
|
|
|
if (!TextUtils.isEmpty(et.text) && isCursorTouchingWord()) {
|
2010-11-16 09:07:06 +00:00
|
|
|
mHandler.postUpdateOldSuggestions();
|
2010-10-05 13:51:59 +00:00
|
|
|
}
|
2010-09-28 23:35:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
@Override
|
|
|
|
public void onFinishInput() {
|
|
|
|
super.onFinishInput();
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-08-20 05:35:02 +00:00
|
|
|
LatinImeLogger.commit();
|
2010-09-03 10:05:23 +00:00
|
|
|
onAutoCompletionStateChanged(false);
|
2010-08-20 05:35:02 +00:00
|
|
|
|
2010-11-21 01:36:37 +00:00
|
|
|
mVoiceConnector.flushVoiceInputLogs(mConfigurationChanging);
|
|
|
|
|
2010-12-02 09:46:21 +00:00
|
|
|
KeyboardView inputView = mKeyboardSwitcher.getInputView();
|
2010-12-03 10:40:31 +00:00
|
|
|
if (inputView != null) inputView.closing();
|
2010-03-23 22:59:59 +00:00
|
|
|
if (mAutoDictionary != null) mAutoDictionary.flushPendingWrites();
|
2010-08-20 05:35:02 +00:00
|
|
|
if (mUserBigramDictionary != null) mUserBigramDictionary.flushPendingWrites();
|
2010-01-16 20:21:23 +00:00
|
|
|
}
|
|
|
|
|
2010-10-06 09:39:47 +00:00
|
|
|
@Override
|
|
|
|
public void onFinishInputView(boolean finishingInput) {
|
|
|
|
super.onFinishInputView(finishingInput);
|
2010-12-02 09:46:21 +00:00
|
|
|
KeyboardView inputView = mKeyboardSwitcher.getInputView();
|
2010-12-03 10:40:31 +00:00
|
|
|
if (inputView != null) inputView.setForeground(false);
|
2010-11-16 09:07:06 +00:00
|
|
|
// Remove pending messages related to update suggestions
|
|
|
|
mHandler.cancelUpdateSuggestions();
|
|
|
|
mHandler.cancelUpdateOldSuggestions();
|
2010-10-06 09:39:47 +00:00
|
|
|
}
|
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
@Override
|
|
|
|
public void onUpdateExtractedText(int token, ExtractedText text) {
|
|
|
|
super.onUpdateExtractedText(token, text);
|
2010-11-21 01:36:37 +00:00
|
|
|
mVoiceConnector.showPunctuationHintIfNecessary();
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onUpdateSelection(int oldSelStart, int oldSelEnd,
|
|
|
|
int newSelStart, int newSelEnd,
|
|
|
|
int candidatesStart, int candidatesEnd) {
|
|
|
|
super.onUpdateSelection(oldSelStart, oldSelEnd, newSelStart, newSelEnd,
|
|
|
|
candidatesStart, candidatesEnd);
|
2010-01-16 20:21:23 +00:00
|
|
|
|
|
|
|
if (DEBUG) {
|
|
|
|
Log.i(TAG, "onUpdateSelection: oss=" + oldSelStart
|
|
|
|
+ ", ose=" + oldSelEnd
|
|
|
|
+ ", nss=" + newSelStart
|
|
|
|
+ ", nse=" + newSelEnd
|
|
|
|
+ ", cs=" + candidatesStart
|
|
|
|
+ ", ce=" + candidatesEnd);
|
|
|
|
}
|
|
|
|
|
2010-11-21 01:36:37 +00:00
|
|
|
mVoiceConnector.setCursorAndSelection(newSelEnd, newSelStart);
|
2010-03-04 14:34:21 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
// If the current selection in the text view changes, we should
|
|
|
|
// clear whatever candidate text we have.
|
2010-11-21 01:36:37 +00:00
|
|
|
if ((((mComposing.length() > 0 && mPredicting)
|
2010-11-21 03:43:10 +00:00
|
|
|
|| mVoiceConnector.isVoiceInputHighlighted()) && (newSelStart != candidatesEnd
|
|
|
|
|| newSelEnd != candidatesEnd) && mLastSelectionStart != newSelStart)) {
|
2009-03-13 22:11:42 +00:00
|
|
|
mComposing.setLength(0);
|
|
|
|
mPredicting = false;
|
2010-11-16 09:07:06 +00:00
|
|
|
mHandler.postUpdateSuggestions();
|
2009-03-13 22:11:42 +00:00
|
|
|
TextEntryState.reset();
|
|
|
|
InputConnection ic = getCurrentInputConnection();
|
|
|
|
if (ic != null) {
|
|
|
|
ic.finishComposingText();
|
|
|
|
}
|
2010-11-21 01:36:37 +00:00
|
|
|
mVoiceConnector.setVoiceInputHighlighted(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;
|
2010-11-16 09:07:06 +00:00
|
|
|
mHandler.postUpdateShiftKeyState();
|
2010-01-16 20:21:23 +00:00
|
|
|
|
2010-08-20 05:35:02 +00:00
|
|
|
// Make a note of the cursor position
|
|
|
|
mLastSelectionStart = newSelStart;
|
|
|
|
mLastSelectionEnd = newSelEnd;
|
2010-01-16 20:21:23 +00:00
|
|
|
|
2010-12-01 11:24:05 +00:00
|
|
|
if (mReCorrectionEnabled && isSuggestionShown()) {
|
2010-09-06 10:18:38 +00:00
|
|
|
// Don't look for corrections if the keyboard is not visible
|
2010-11-13 08:01:13 +00:00
|
|
|
if (mKeyboardSwitcher.isInputViewShown()) {
|
2010-09-06 10:18:38 +00:00
|
|
|
// Check if we should go in or out of correction mode.
|
2010-11-16 09:57:03 +00:00
|
|
|
if (isPredictionOn() && !mJustReverted
|
2010-09-06 10:18:38 +00:00
|
|
|
&& (candidatesStart == candidatesEnd || newSelStart != oldSelStart
|
|
|
|
|| TextEntryState.isCorrecting())
|
2010-11-21 01:36:37 +00:00
|
|
|
&& (newSelStart < newSelEnd - 1 || (!mPredicting))) {
|
2010-09-06 10:18:38 +00:00
|
|
|
if (isCursorTouchingWord() || mLastSelectionStart < mLastSelectionEnd) {
|
2010-11-16 09:07:06 +00:00
|
|
|
mHandler.postUpdateOldSuggestions();
|
2010-09-06 10:18:38 +00:00
|
|
|
} else {
|
|
|
|
abortCorrection(false);
|
2010-10-05 13:51:59 +00:00
|
|
|
// Show the punctuation suggestions list if the current one is not
|
2010-10-10 17:52:08 +00:00
|
|
|
// and if not showing "Touch again to save".
|
2010-11-13 10:09:30 +00:00
|
|
|
if (mCandidateView != null && !isShowingPunctuationList()
|
|
|
|
&& !mCandidateView.isShowingAddToDictionaryHint()) {
|
2010-11-11 04:37:18 +00:00
|
|
|
setPunctuationSuggestions();
|
2010-10-05 13:51:59 +00:00
|
|
|
}
|
2010-09-06 10:18:38 +00:00
|
|
|
}
|
2010-08-26 19:22:58 +00:00
|
|
|
}
|
2010-01-16 20:21:23 +00:00
|
|
|
}
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2010-09-15 04:03:34 +00:00
|
|
|
/**
|
|
|
|
* This is called when the user has clicked on the extracted text view,
|
|
|
|
* when running in fullscreen mode. The default implementation hides
|
|
|
|
* the candidates view when this happens, but only if the extracted text
|
|
|
|
* editor has a vertical scroll bar because its text doesn't fit.
|
|
|
|
* Here we override the behavior due to the possibility that a re-correction could
|
|
|
|
* cause the candidate strip to disappear and re-appear.
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public void onExtractedTextClicked() {
|
|
|
|
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-11-21 01:36:37 +00:00
|
|
|
mVoiceConnector.hideVoiceWindow(mConfigurationChanging);
|
2010-08-20 05:35:02 +00:00
|
|
|
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-11-13 08:01:13 +00:00
|
|
|
super.setCandidatesViewShown(shown
|
|
|
|
&& (needsInputViewShown ? mKeyboardSwitcher.isInputViewShown() : 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;
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
// Enable shift key and DPAD to do selections
|
2010-11-13 08:16:34 +00:00
|
|
|
if (mKeyboardSwitcher.isInputViewShown()
|
|
|
|
&& mKeyboardSwitcher.isShiftedOrShiftLocked()) {
|
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-11-21 01:36:37 +00:00
|
|
|
public void commitTyped(InputConnection inputConnection) {
|
2009-03-13 22:11:42 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-13 08:16:34 +00:00
|
|
|
public boolean getCurrentAutoCapsState() {
|
2009-03-13 22:11:42 +00:00
|
|
|
InputConnection ic = getCurrentInputConnection();
|
2010-01-24 15:34:07 +00:00
|
|
|
EditorInfo ei = getCurrentInputEditorInfo();
|
2010-11-13 08:16:34 +00:00
|
|
|
if (mAutoCap && ic != null && ei != null && ei.inputType != EditorInfo.TYPE_NULL) {
|
|
|
|
return ic.getCursorCapsMode(ei.inputType) != 0;
|
2010-01-24 15:34:07 +00:00
|
|
|
}
|
2010-11-13 08:16:34 +00:00
|
|
|
return false;
|
2010-01-24 15:34:07 +00:00
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
private void swapPunctuationAndSpace() {
|
|
|
|
final InputConnection ic = getCurrentInputConnection();
|
|
|
|
if (ic == null) return;
|
|
|
|
CharSequence lastTwo = ic.getTextBeforeCursor(2, 0);
|
|
|
|
if (lastTwo != null && lastTwo.length() == 2
|
2010-12-02 11:54:32 +00:00
|
|
|
&& lastTwo.charAt(0) == Keyboard.CODE_SPACE
|
|
|
|
&& isSentenceSeparator(lastTwo.charAt(1))) {
|
2009-03-13 22:11:42 +00:00
|
|
|
ic.beginBatchEdit();
|
|
|
|
ic.deleteSurroundingText(2, 0);
|
|
|
|
ic.commitText(lastTwo.charAt(1) + " ", 1);
|
|
|
|
ic.endBatchEdit();
|
2010-11-13 08:16:34 +00:00
|
|
|
mKeyboardSwitcher.updateShiftState();
|
2010-02-07 00:34:43 +00:00
|
|
|
mJustAddedAutoSpace = true;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
}
|
2010-01-24 15:34:07 +00:00
|
|
|
|
2010-02-22 14:55:45 +00:00
|
|
|
private void reswapPeriodAndSpace() {
|
|
|
|
final InputConnection ic = getCurrentInputConnection();
|
|
|
|
if (ic == null) return;
|
|
|
|
CharSequence lastThree = ic.getTextBeforeCursor(3, 0);
|
|
|
|
if (lastThree != null && lastThree.length() == 3
|
2010-12-02 11:54:32 +00:00
|
|
|
&& lastThree.charAt(0) == Keyboard.CODE_PERIOD
|
|
|
|
&& lastThree.charAt(1) == Keyboard.CODE_SPACE
|
|
|
|
&& lastThree.charAt(2) == Keyboard.CODE_PERIOD) {
|
2010-02-22 14:55:45 +00:00
|
|
|
ic.beginBatchEdit();
|
|
|
|
ic.deleteSurroundingText(3, 0);
|
|
|
|
ic.commitText(" ..", 1);
|
|
|
|
ic.endBatchEdit();
|
2010-11-13 08:16:34 +00:00
|
|
|
mKeyboardSwitcher.updateShiftState();
|
2010-02-22 14:55:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
private void doubleSpace() {
|
|
|
|
//if (!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))
|
2010-12-02 11:54:32 +00:00
|
|
|
&& lastThree.charAt(1) == Keyboard.CODE_SPACE
|
|
|
|
&& lastThree.charAt(2) == Keyboard.CODE_SPACE) {
|
2009-03-13 22:11:42 +00:00
|
|
|
ic.beginBatchEdit();
|
|
|
|
ic.deleteSurroundingText(2, 0);
|
|
|
|
ic.commitText(". ", 1);
|
|
|
|
ic.endBatchEdit();
|
2010-11-13 08:16:34 +00:00
|
|
|
mKeyboardSwitcher.updateShiftState();
|
2010-02-07 00:34:43 +00:00
|
|
|
mJustAddedAutoSpace = true;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-01-31 16:34:55 +00:00
|
|
|
private void maybeRemovePreviousPeriod(CharSequence text) {
|
|
|
|
final InputConnection ic = getCurrentInputConnection();
|
|
|
|
if (ic == null) return;
|
|
|
|
|
|
|
|
// When the text's first character is '.', remove the previous period
|
|
|
|
// if there is one.
|
|
|
|
CharSequence lastOne = ic.getTextBeforeCursor(1, 0);
|
2010-02-22 14:55:45 +00:00
|
|
|
if (lastOne != null && lastOne.length() == 1
|
2010-12-02 11:54:32 +00:00
|
|
|
&& lastOne.charAt(0) == Keyboard.CODE_PERIOD
|
|
|
|
&& text.charAt(0) == Keyboard.CODE_PERIOD) {
|
2010-01-31 16:34:55 +00:00
|
|
|
ic.deleteSurroundingText(1, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-07 00:34:43 +00:00
|
|
|
private void removeTrailingSpace() {
|
|
|
|
final InputConnection ic = getCurrentInputConnection();
|
|
|
|
if (ic == null) return;
|
|
|
|
|
|
|
|
CharSequence lastOne = ic.getTextBeforeCursor(1, 0);
|
|
|
|
if (lastOne != null && lastOne.length() == 1
|
2010-12-02 11:54:32 +00:00
|
|
|
&& lastOne.charAt(0) == Keyboard.CODE_SPACE) {
|
2010-02-07 00:34:43 +00:00
|
|
|
ic.deleteSurroundingText(1, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
public boolean addWordToDictionary(String word) {
|
|
|
|
mUserDictionary.addWord(word, 128);
|
2010-08-03 18:47:42 +00:00
|
|
|
// Suggestion strip should be updated after the operation of adding word to the
|
|
|
|
// user dictionary
|
2010-11-16 09:07:06 +00:00
|
|
|
mHandler.postUpdateSuggestions();
|
2009-03-13 22:11:42 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean isAlphabet(int code) {
|
|
|
|
if (Character.isLetter(code)) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-12-06 03:12:27 +00:00
|
|
|
private void onSettingsKeyPressed() {
|
2010-09-02 19:25:31 +00:00
|
|
|
if (!isShowingOptionDialog()) {
|
2010-12-09 12:06:26 +00:00
|
|
|
if (Utils.hasMultipleEnabledIMEsOrSubtypes(mImm)) {
|
2010-09-02 19:25:31 +00:00
|
|
|
showOptionsMenu();
|
|
|
|
} else {
|
|
|
|
launchSettings();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-06 03:12:27 +00:00
|
|
|
private void onSettingsKeyLongPressed() {
|
2010-09-02 19:25:31 +00:00
|
|
|
if (!isShowingOptionDialog()) {
|
2010-12-09 12:06:26 +00:00
|
|
|
if (Utils.hasMultipleEnabledIMEsOrSubtypes(mImm)) {
|
2010-11-25 00:20:28 +00:00
|
|
|
mImm.showInputMethodPicker();
|
2010-09-02 19:25:31 +00:00
|
|
|
} else {
|
|
|
|
launchSettings();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean isShowingOptionDialog() {
|
|
|
|
return mOptionsDialog != null && mOptionsDialog.isShowing();
|
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
// Implementation of KeyboardViewListener
|
|
|
|
|
2010-12-02 09:46:21 +00:00
|
|
|
@Override
|
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-12-02 11:54:32 +00:00
|
|
|
if (primaryCode != Keyboard.CODE_DELETE || when > mLastKeyTime + QUICK_PRESS) {
|
2009-03-13 22:11:42 +00:00
|
|
|
mDeleteCount = 0;
|
|
|
|
}
|
|
|
|
mLastKeyTime = when;
|
2010-11-13 08:16:34 +00:00
|
|
|
KeyboardSwitcher switcher = mKeyboardSwitcher;
|
|
|
|
final boolean distinctMultiTouch = switcher.hasDistinctMultitouch();
|
2009-03-13 22:11:42 +00:00
|
|
|
switch (primaryCode) {
|
2010-12-02 11:54:32 +00:00
|
|
|
case Keyboard.CODE_DELETE:
|
2010-10-22 10:35:23 +00:00
|
|
|
handleBackspace();
|
|
|
|
mDeleteCount++;
|
|
|
|
LatinImeLogger.logOnDelete();
|
|
|
|
break;
|
2010-12-02 11:54:32 +00:00
|
|
|
case Keyboard.CODE_SHIFT:
|
2010-10-22 10:35:23 +00:00
|
|
|
// Shift key is handled in onPress() when device has distinct multi-touch panel.
|
|
|
|
if (!distinctMultiTouch)
|
2010-11-13 08:16:34 +00:00
|
|
|
switcher.toggleShift();
|
2010-10-22 10:35:23 +00:00
|
|
|
break;
|
2010-12-06 03:12:27 +00:00
|
|
|
case Keyboard.CODE_SWITCH_ALPHA_SYMBOL:
|
2010-10-22 10:35:23 +00:00
|
|
|
// Symbol key is handled in onPress() when device has distinct multi-touch panel.
|
|
|
|
if (!distinctMultiTouch)
|
2010-11-13 08:16:34 +00:00
|
|
|
switcher.changeKeyboardMode();
|
2010-10-22 10:35:23 +00:00
|
|
|
break;
|
2010-12-02 11:54:32 +00:00
|
|
|
case Keyboard.CODE_CANCEL:
|
2010-10-22 10:35:23 +00:00
|
|
|
if (!isShowingOptionDialog()) {
|
|
|
|
handleClose();
|
|
|
|
}
|
|
|
|
break;
|
2010-12-06 03:12:27 +00:00
|
|
|
case Keyboard.CODE_SETTINGS:
|
|
|
|
onSettingsKeyPressed();
|
2010-10-22 10:35:23 +00:00
|
|
|
break;
|
2010-12-06 03:12:27 +00:00
|
|
|
case Keyboard.CODE_SETTINGS_LONGPRESS:
|
|
|
|
onSettingsKeyLongPressed();
|
2010-10-22 10:35:23 +00:00
|
|
|
break;
|
2010-12-02 11:54:32 +00:00
|
|
|
case Keyboard.CODE_NEXT_LANGUAGE:
|
2010-10-22 10:35:23 +00:00
|
|
|
toggleLanguage(false, true);
|
|
|
|
break;
|
2010-12-02 11:54:32 +00:00
|
|
|
case Keyboard.CODE_PREV_LANGUAGE:
|
2010-10-22 10:35:23 +00:00
|
|
|
toggleLanguage(false, false);
|
|
|
|
break;
|
2010-12-02 11:54:32 +00:00
|
|
|
case Keyboard.CODE_CAPSLOCK:
|
2010-11-13 08:16:34 +00:00
|
|
|
switcher.toggleCapsLock();
|
2010-10-22 10:35:23 +00:00
|
|
|
break;
|
2010-12-09 18:18:32 +00:00
|
|
|
case Keyboard.CODE_VOICE:
|
|
|
|
mSubtypeSwitcher.switchToShortcutIME();
|
2010-10-22 10:35:23 +00:00
|
|
|
break;
|
2010-12-02 11:54:32 +00:00
|
|
|
case Keyboard.CODE_TAB:
|
2010-11-12 23:49:56 +00:00
|
|
|
handleTab();
|
2010-10-22 10:35:23 +00:00
|
|
|
break;
|
|
|
|
default:
|
2010-12-02 11:54:32 +00:00
|
|
|
if (primaryCode != Keyboard.CODE_ENTER) {
|
2010-10-22 10:35:23 +00:00
|
|
|
mJustAddedAutoSpace = false;
|
|
|
|
}
|
|
|
|
RingCharBuffer.getInstance().push((char)primaryCode, x, y);
|
|
|
|
LatinImeLogger.logOnInputChar();
|
|
|
|
if (isWordSeparator(primaryCode)) {
|
|
|
|
handleSeparator(primaryCode);
|
|
|
|
} else {
|
|
|
|
handleCharacter(primaryCode, keyCodes);
|
|
|
|
}
|
|
|
|
// Cancel the just reverted state
|
2010-11-16 09:57:03 +00:00
|
|
|
mJustReverted = false;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-11-13 08:16:34 +00:00
|
|
|
switcher.onKey(primaryCode);
|
2010-04-01 13:28:52 +00:00
|
|
|
// Reset after any single keystroke
|
|
|
|
mEnteredText = null;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-12-02 09:46:21 +00:00
|
|
|
@Override
|
2009-03-13 22:11:42 +00:00
|
|
|
public void onText(CharSequence text) {
|
2010-11-21 01:36:37 +00:00
|
|
|
mVoiceConnector.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();
|
2010-12-09 07:36:45 +00:00
|
|
|
commitTyped(ic);
|
2010-01-31 16:34:55 +00:00
|
|
|
maybeRemovePreviousPeriod(text);
|
2009-03-13 22:11:42 +00:00
|
|
|
ic.commitText(text, 1);
|
|
|
|
ic.endBatchEdit();
|
2010-11-13 08:16:34 +00:00
|
|
|
mKeyboardSwitcher.updateShiftState();
|
2010-11-16 09:57:03 +00:00
|
|
|
mJustReverted = false;
|
2010-02-07 00:34:43 +00:00
|
|
|
mJustAddedAutoSpace = false;
|
2010-04-01 13:28:52 +00:00
|
|
|
mEnteredText = text;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2010-12-02 09:46:21 +00:00
|
|
|
@Override
|
2010-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-11-21 01:36:37 +00:00
|
|
|
if (mVoiceConnector.logAndRevertVoiceInput()) 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-11-21 01:36:37 +00:00
|
|
|
mVoiceConnector.handleBackspace();
|
2010-03-04 14:34:21 +00:00
|
|
|
|
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;
|
|
|
|
}
|
2010-11-16 09:07:06 +00:00
|
|
|
mHandler.postUpdateSuggestions();
|
2009-03-13 22:11:42 +00:00
|
|
|
} else {
|
|
|
|
ic.deleteSurroundingText(1, 0);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
deleteChar = true;
|
|
|
|
}
|
2010-11-16 09:07:06 +00:00
|
|
|
mHandler.postUpdateShiftKeyState();
|
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
|
2010-10-05 13:51:59 +00:00
|
|
|
// "Touch again to save".
|
2010-08-03 18:47:42 +00:00
|
|
|
// NOTE: In gerenal, we don't revert the word when backspacing
|
|
|
|
// from a manual suggestion pick. We deliberately chose a
|
|
|
|
// different behavior only in the case of picking the first
|
|
|
|
// suggestion (typed word). It's intentional to have made this
|
|
|
|
// inconsistent with backspacing after selecting other suggestions.
|
|
|
|
revertLastWord(deleteChar);
|
|
|
|
} else {
|
2009-03-13 22:11:42 +00:00
|
|
|
sendDownUpKeyEvents(KeyEvent.KEYCODE_DEL);
|
2010-08-03 18:47:42 +00:00
|
|
|
if (mDeleteCount > DELETE_ACCELERATE_AT) {
|
|
|
|
sendDownUpKeyEvents(KeyEvent.KEYCODE_DEL);
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
}
|
2010-11-16 09:57:03 +00:00
|
|
|
mJustReverted = false;
|
2010-08-20 05:35:02 +00:00
|
|
|
ic.endBatchEdit();
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2010-11-12 23:49:56 +00:00
|
|
|
private void handleTab() {
|
|
|
|
final int imeOptions = getCurrentInputEditorInfo().imeOptions;
|
|
|
|
final int navigationFlags =
|
|
|
|
EditorInfo.IME_FLAG_NAVIGATE_NEXT | EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS;
|
|
|
|
if ((imeOptions & navigationFlags) == 0) {
|
|
|
|
sendDownUpKeyEvents(KeyEvent.KEYCODE_TAB);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
final InputConnection ic = getCurrentInputConnection();
|
|
|
|
if (ic == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// True if keyboard is in either chording shift or manual temporary upper case mode.
|
|
|
|
final boolean isManualTemporaryUpperCase = mKeyboardSwitcher.isManualTemporaryUpperCase();
|
|
|
|
if ((imeOptions & EditorInfo.IME_FLAG_NAVIGATE_NEXT) != 0
|
|
|
|
&& !isManualTemporaryUpperCase) {
|
|
|
|
ic.performEditorAction(EditorInfo.IME_ACTION_NEXT);
|
|
|
|
} else if ((imeOptions & EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS) != 0
|
|
|
|
&& isManualTemporaryUpperCase) {
|
|
|
|
ic.performEditorAction(EditorInfo.IME_ACTION_PREVIOUS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-20 05:35:02 +00:00
|
|
|
private void abortCorrection(boolean force) {
|
|
|
|
if (force || TextEntryState.isCorrecting()) {
|
2010-11-11 04:37:18 +00:00
|
|
|
TextEntryState.onAbortCorrection();
|
|
|
|
setCandidatesViewShown(isCandidateStripVisible());
|
2010-08-20 05:35:02 +00:00
|
|
|
getCurrentInputConnection().finishComposingText();
|
2010-08-26 19:22:58 +00:00
|
|
|
clearSuggestions();
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
private void handleCharacter(int primaryCode, int[] keyCodes) {
|
2010-11-21 01:36:37 +00:00
|
|
|
mVoiceConnector.handleCharacter();
|
2010-03-04 14:34:21 +00:00
|
|
|
|
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-11-13 08:01:13 +00:00
|
|
|
KeyboardSwitcher switcher = mKeyboardSwitcher;
|
2010-11-13 08:16:34 +00:00
|
|
|
if (switcher.isShiftedOrShiftLocked()) {
|
2009-10-09 14:03:11 +00:00
|
|
|
if (keyCodes == null || keyCodes[0] < Character.MIN_CODE_POINT
|
|
|
|
|| keyCodes[0] > Character.MAX_CODE_POINT) {
|
|
|
|
return;
|
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
primaryCode = keyCodes[0];
|
2010-11-13 08:01:13 +00:00
|
|
|
if (switcher.isAlphabetMode() && Character.isLowerCase(primaryCode)) {
|
2010-09-14 07:22:08 +00:00
|
|
|
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-11-13 08:16:34 +00:00
|
|
|
if (mComposing.length() == 0 && switcher.isAlphabetMode()
|
|
|
|
&& switcher.isShiftedOrShiftLocked()) {
|
2010-09-27 15:32:35 +00:00
|
|
|
mWord.setFirstCharCapitalized(true);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
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) {
|
2010-11-13 08:16:34 +00:00
|
|
|
mWord.setAutoCapitalized(getCurrentAutoCapsState());
|
2010-01-24 15:34:07 +00:00
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
ic.setComposingText(mComposing, 1);
|
|
|
|
}
|
2010-11-16 09:07:06 +00:00
|
|
|
mHandler.postUpdateSuggestions();
|
2009-03-13 22:11:42 +00:00
|
|
|
} else {
|
|
|
|
sendKeyChar((char)primaryCode);
|
|
|
|
}
|
2010-11-13 08:16:34 +00:00
|
|
|
switcher.updateShiftState();
|
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-11-21 01:36:37 +00:00
|
|
|
mVoiceConnector.handleSeparator();
|
2010-03-04 14:34:21 +00:00
|
|
|
|
2010-10-05 13:51:59 +00:00
|
|
|
// Should dismiss the "Touch again to save" message when handling separator
|
2010-08-03 18:47:42 +00:00
|
|
|
if (mCandidateView != null && mCandidateView.dismissAddToDictionaryHint()) {
|
2010-11-16 09:07:06 +00:00
|
|
|
mHandler.postUpdateSuggestions();
|
2010-08-03 18:47:42 +00:00
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
boolean pickedDefault = false;
|
|
|
|
// Handle separator
|
|
|
|
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-11-16 09:57:03 +00:00
|
|
|
if (mAutoCorrectOn && primaryCode != '\'' && !mJustReverted) {
|
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".
|
2010-12-02 11:54:32 +00:00
|
|
|
if (primaryCode == Keyboard.CODE_SPACE) {
|
2010-02-07 00:34:43 +00:00
|
|
|
mJustAddedAutoSpace = true;
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
} else {
|
|
|
|
commitTyped(ic);
|
|
|
|
}
|
|
|
|
}
|
2010-12-02 11:54:32 +00:00
|
|
|
if (mJustAddedAutoSpace && primaryCode == Keyboard.CODE_ENTER) {
|
2010-02-07 00:34:43 +00:00
|
|
|
removeTrailingSpace();
|
|
|
|
mJustAddedAutoSpace = false;
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
sendKeyChar((char)primaryCode);
|
2010-02-22 14:55:45 +00:00
|
|
|
|
|
|
|
// Handle the case of ". ." -> " .." with auto-space if necessary
|
|
|
|
// before changing the TextEntryState.
|
2010-08-20 05:35:02 +00:00
|
|
|
if (TextEntryState.getState() == TextEntryState.State.PUNCTUATION_AFTER_ACCEPTED
|
2010-12-02 11:54:32 +00:00
|
|
|
&& primaryCode == Keyboard.CODE_PERIOD) {
|
2010-02-22 14:55:45 +00:00
|
|
|
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
|
2010-12-02 11:54:32 +00:00
|
|
|
&& primaryCode != Keyboard.CODE_ENTER) {
|
2009-03-13 22:11:42 +00:00
|
|
|
swapPunctuationAndSpace();
|
2010-12-02 11:54:32 +00:00
|
|
|
} else if (isPredictionOn() && primaryCode == Keyboard.CODE_SPACE) {
|
2009-03-13 22:11:42 +00:00
|
|
|
doubleSpace();
|
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
if (pickedDefault) {
|
2010-12-09 07:36:45 +00:00
|
|
|
CharSequence typedWord = mWord.getTypedWord();
|
|
|
|
TextEntryState.backToAcceptedDefault(typedWord);
|
|
|
|
if (!TextUtils.isEmpty(typedWord) && !typedWord.equals(mBestWord)) {
|
|
|
|
// TODO: Will call InputConnection.commitCorrection() here.
|
|
|
|
if (mCandidateView != null)
|
|
|
|
mCandidateView.onAutoCorrectionInverted(mBestWord);
|
|
|
|
}
|
|
|
|
setPunctuationSuggestions();
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-11-13 08:16:34 +00:00
|
|
|
mKeyboardSwitcher.updateShiftState();
|
2009-03-13 22:11:42 +00:00
|
|
|
if (ic != null) {
|
|
|
|
ic.endBatchEdit();
|
|
|
|
}
|
|
|
|
}
|
2010-01-16 20:21:23 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
private void handleClose() {
|
|
|
|
commitTyped(getCurrentInputConnection());
|
2010-11-21 01:36:37 +00:00
|
|
|
mVoiceConnector.handleClose();
|
2009-03-13 22:11:42 +00:00
|
|
|
requestHideSelf(0);
|
2010-11-13 08:01:13 +00:00
|
|
|
LatinKeyboardView inputView = mKeyboardSwitcher.getInputView();
|
|
|
|
if (inputView != null)
|
|
|
|
inputView.closing();
|
2009-03-13 22:11:42 +00:00
|
|
|
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 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
|
|
|
|
2010-11-13 10:09:30 +00:00
|
|
|
private boolean isShowingPunctuationList() {
|
|
|
|
return mSuggestPuncList.equals(mCandidateView.getSuggestions());
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean isSuggestionShown() {
|
|
|
|
return (mSuggestionVisibility == SUGGESTION_VISIBILILTY_SHOW_VALUE)
|
|
|
|
|| (mSuggestionVisibility == SUGGESTION_VISIBILILTY_SHOW_ONLY_PORTRAIT_VALUE
|
|
|
|
&& mOrientation == Configuration.ORIENTATION_PORTRAIT);
|
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
private boolean isCandidateStripVisible() {
|
2010-11-13 10:09:30 +00:00
|
|
|
boolean forceVisible = mCandidateView.isShowingAddToDictionaryHint()
|
|
|
|
|| TextEntryState.isCorrecting();
|
|
|
|
return forceVisible || (isSuggestionShown()
|
|
|
|
&& (isPredictionOn() || mCompletionOn || isShowingPunctuationList()));
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2010-11-21 01:36:37 +00:00
|
|
|
public void switchToKeyboardView() {
|
2010-12-02 09:46:21 +00:00
|
|
|
mHandler.post(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if (DEBUG) {
|
|
|
|
Log.d(TAG, "Switch to keyboard view.");
|
|
|
|
}
|
|
|
|
View v = mKeyboardSwitcher.getInputView();
|
|
|
|
if (v != null) {
|
|
|
|
// Confirms that the keyboard view doesn't have parent view.
|
|
|
|
ViewParent p = v.getParent();
|
|
|
|
if (p != null && p instanceof ViewGroup) {
|
|
|
|
((ViewGroup) p).removeView(v);
|
|
|
|
}
|
|
|
|
setInputView(v);
|
|
|
|
}
|
|
|
|
setCandidatesViewShown(isCandidateStripVisible());
|
|
|
|
updateInputViewShown();
|
|
|
|
mHandler.postUpdateSuggestions();
|
|
|
|
}
|
|
|
|
});
|
2010-01-16 20:21:23 +00:00
|
|
|
}
|
|
|
|
|
2010-11-21 01:36:37 +00:00
|
|
|
public void clearSuggestions() {
|
2010-08-26 19:22:58 +00:00
|
|
|
setSuggestions(null, false, false, false);
|
2010-01-16 20:21:23 +00:00
|
|
|
}
|
|
|
|
|
2010-11-21 01:36:37 +00:00
|
|
|
public void setSuggestions(
|
2010-01-16 20:21:23 +00:00
|
|
|
List<CharSequence> suggestions,
|
|
|
|
boolean completions,
|
|
|
|
boolean typedWordValid,
|
|
|
|
boolean haveMinimalSuggestion) {
|
|
|
|
|
2010-11-21 01:36:37 +00:00
|
|
|
if (mVoiceConnector.getAndResetIsShowingHint()) {
|
2010-01-16 20:21:23 +00:00
|
|
|
setCandidatesView(mCandidateViewContainer);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mCandidateView != null) {
|
|
|
|
mCandidateView.setSuggestions(
|
|
|
|
suggestions, completions, typedWordValid, haveMinimalSuggestion);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-21 01:36:37 +00:00
|
|
|
public void updateSuggestions() {
|
2010-11-13 08:01:13 +00:00
|
|
|
mKeyboardSwitcher.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-11-21 01:36:37 +00:00
|
|
|
if ((mSuggest == null || !isPredictionOn())
|
|
|
|
&& !mVoiceConnector.isVoiceInputHighlighted()) {
|
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-11-11 04:37:18 +00:00
|
|
|
setPunctuationSuggestions();
|
2009-03-13 22:11:42 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
showSuggestions(mWord);
|
|
|
|
}
|
|
|
|
|
|
|
|
private List<CharSequence> getTypedSuggestions(WordComposer word) {
|
|
|
|
List<CharSequence> stringList = mSuggest.getSuggestions(
|
|
|
|
mKeyboardSwitcher.getInputView(), word, false, null);
|
|
|
|
return stringList;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void showCorrections(WordAlternatives alternatives) {
|
2010-11-13 08:01:13 +00:00
|
|
|
mKeyboardSwitcher.setPreferredLetters(null);
|
2010-08-20 05:35:02 +00:00
|
|
|
List<CharSequence> stringList = alternatives.getAlternatives();
|
|
|
|
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-11-13 08:01:13 +00:00
|
|
|
mKeyboardSwitcher.setPreferredLetters(nextLettersFrequencies);
|
2010-02-05 22:07:04 +00:00
|
|
|
|
2010-11-17 07:40:48 +00:00
|
|
|
boolean correctionAvailable = !mInputTypeNoAutoCorrect && !mJustReverted
|
|
|
|
&& mSuggest.hasMinimalCorrection();
|
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;
|
|
|
|
}
|
2010-11-11 04:37:18 +00:00
|
|
|
setCandidatesViewShown(isCandidateStripVisible());
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
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
|
2010-11-16 09:07:06 +00:00
|
|
|
if (mHandler.hasPendingUpdateSuggestions()) {
|
|
|
|
mHandler.cancelUpdateSuggestions();
|
2009-03-13 22:11:42 +00:00
|
|
|
updateSuggestions();
|
|
|
|
}
|
2010-03-18 04:37:25 +00:00
|
|
|
if (mBestWord != null && mBestWord.length() > 0) {
|
2009-03-13 22:11:42 +00:00
|
|
|
TextEntryState.acceptedDefault(mWord.getTypedWord(), mBestWord);
|
|
|
|
mJustAccepted = true;
|
2010-12-09 07:36:45 +00:00
|
|
|
pickSuggestion(mBestWord);
|
2010-02-25 18:37:19 +00:00
|
|
|
// Add the word to the auto dictionary if it's not a known word
|
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-11-21 01:36:37 +00:00
|
|
|
mVoiceConnector.flushAndLogAllTextModificationCounters(index, suggestion, mWordSeparators);
|
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();
|
|
|
|
}
|
2010-11-13 08:16:34 +00:00
|
|
|
mKeyboardSwitcher.updateShiftState();
|
2010-02-07 00:34:43 +00:00
|
|
|
if (ic != null) {
|
|
|
|
ic.endBatchEdit();
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-02-03 23:35:49 +00:00
|
|
|
|
|
|
|
// If this is a punctuation, apply it through the normal key press
|
2010-08-20 05:35:02 +00:00
|
|
|
if (suggestion.length() == 1 && (isWordSeparator(suggestion.charAt(0))
|
|
|
|
|| isSuggestedPunctuation(suggestion.charAt(0)))) {
|
|
|
|
// Word separators are suggested before the user inputs something.
|
|
|
|
// So, LatinImeLogger logs "" as a user's input.
|
|
|
|
LatinImeLogger.logOnManualSuggestion(
|
|
|
|
"", suggestion.toString(), index, suggestions);
|
2010-10-05 13:51:59 +00:00
|
|
|
final char primaryCode = suggestion.charAt(0);
|
2010-12-02 09:46:21 +00:00
|
|
|
onKey(primaryCode, new int[]{primaryCode}, KeyboardView.NOT_A_TOUCH_COORDINATE,
|
|
|
|
KeyboardView.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-12-09 07:36:45 +00:00
|
|
|
pickSuggestion(suggestion);
|
2010-02-25 18:37:19 +00:00
|
|
|
// Add the word to the auto dictionary if it's not a known word
|
2010-03-24 23:44:31 +00:00
|
|
|
if (index == 0) {
|
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-12-02 11:54:32 +00:00
|
|
|
TextEntryState.typedCharacter((char) Keyboard.CODE_SPACE, true);
|
2010-11-11 04:37:18 +00:00
|
|
|
setPunctuationSuggestions();
|
2010-08-26 19:22:58 +00:00
|
|
|
} else if (!showingAddToDictionaryHint) {
|
2010-10-10 17:52:08 +00:00
|
|
|
// If we're not showing the "Touch again to save", then show corrections again.
|
2010-08-20 05:35:02 +00:00
|
|
|
// In case the cursor position doesn't change, make sure we show the suggestions again.
|
2010-08-26 19:22:58 +00:00
|
|
|
clearSuggestions();
|
2010-11-16 09:07:06 +00:00
|
|
|
mHandler.postUpdateOldSuggestions();
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|
2010-08-26 19:22:58 +00:00
|
|
|
if (showingAddToDictionaryHint) {
|
2010-02-11 01:45:35 +00:00
|
|
|
mCandidateView.showAddToDictionaryHint(suggestion);
|
|
|
|
}
|
2010-02-07 00:34:43 +00:00
|
|
|
if (ic != null) {
|
|
|
|
ic.endBatchEdit();
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-08-20 05:35:02 +00:00
|
|
|
/**
|
|
|
|
* Commits the chosen word to the text field and saves it for later
|
|
|
|
* retrieval.
|
|
|
|
* @param suggestion the suggestion picked by the user to be committed to
|
|
|
|
* the text field
|
|
|
|
*/
|
2010-12-09 07:36:45 +00:00
|
|
|
private void pickSuggestion(CharSequence suggestion) {
|
2010-11-13 08:16:34 +00:00
|
|
|
KeyboardSwitcher switcher = mKeyboardSwitcher;
|
|
|
|
if (!switcher.isKeyboardAvailable())
|
2010-11-13 08:01:13 +00:00
|
|
|
return;
|
2009-03-13 22:11:42 +00:00
|
|
|
InputConnection ic = getCurrentInputConnection();
|
|
|
|
if (ic != null) {
|
2010-11-21 01:36:37 +00:00
|
|
|
mVoiceConnector.rememberReplacedWord(suggestion, mWordSeparators);
|
2010-08-20 05:35:02 +00:00
|
|
|
ic.commitText(suggestion, 1);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
saveWordInHistory(suggestion);
|
2009-03-13 22:11:42 +00:00
|
|
|
mPredicting = false;
|
|
|
|
mCommittedLength = suggestion.length();
|
2010-11-13 08:16:34 +00:00
|
|
|
switcher.setPreferredLetters(null);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2010-08-26 19:22:58 +00:00
|
|
|
/**
|
|
|
|
* Tries to apply any typed alternatives for the word if we have any cached alternatives,
|
|
|
|
* otherwise tries to find new corrections and completions for the word.
|
|
|
|
* @param touching The word that the cursor is touching, with position information
|
|
|
|
* @return true if an alternative was found, false otherwise.
|
|
|
|
*/
|
|
|
|
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)
|
|
|
|
});
|
|
|
|
}
|
2010-09-27 15:32:35 +00:00
|
|
|
foundWord.setFirstCharCapitalized(Character.isUpperCase(touching.word.charAt(0)));
|
2010-08-26 19:22:58 +00:00
|
|
|
}
|
|
|
|
// 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() {
|
2010-11-21 01:36:37 +00:00
|
|
|
mVoiceConnector.setShowingVoiceSuggestions(false);
|
2010-08-26 19:22:58 +00:00
|
|
|
if (mCandidateView != null && mCandidateView.isShowingAddToDictionaryHint()) {
|
|
|
|
return;
|
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
InputConnection ic = getCurrentInputConnection();
|
|
|
|
if (ic == null) return;
|
2010-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-11-21 01:36:37 +00:00
|
|
|
if (!mVoiceConnector.applyVoiceAlternatives(touching)
|
|
|
|
&& !applyTypedAlternatives(touching)) {
|
2010-08-26 19:22:58 +00:00
|
|
|
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);
|
2010-11-11 04:37:18 +00:00
|
|
|
setPunctuationSuggestions(); // Show the punctuation suggestions list
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
abortCorrection(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-11 04:37:18 +00:00
|
|
|
private void setPunctuationSuggestions() {
|
|
|
|
setCandidatesViewShown(isCandidateStripVisible());
|
2010-02-03 23:35:49 +00:00
|
|
|
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)
|
2010-10-05 13:51:59 +00:00
|
|
|
&& !isWordSeparator(toLeft.charAt(0))
|
|
|
|
&& !isSuggestedPunctuation(toLeft.charAt(0))) {
|
2009-03-13 22:11:42 +00:00
|
|
|
return true;
|
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
if (!TextUtils.isEmpty(toRight)
|
2010-10-05 13:51:59 +00:00
|
|
|
&& !isWordSeparator(toRight.charAt(0))
|
|
|
|
&& !isSuggestedPunctuation(toRight.charAt(0))) {
|
2009-03-13 22:11:42 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-04-01 13:28:52 +00:00
|
|
|
private boolean sameAsTextBeforeCursor(InputConnection ic, CharSequence text) {
|
|
|
|
CharSequence beforeText = ic.getTextBeforeCursor(text.length(), 0);
|
|
|
|
return TextUtils.equals(text, beforeText);
|
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
public void revertLastWord(boolean deleteChar) {
|
|
|
|
final int length = mComposing.length();
|
|
|
|
if (!mPredicting && length > 0) {
|
|
|
|
final InputConnection ic = getCurrentInputConnection();
|
|
|
|
mPredicting = true;
|
2010-11-16 09:57:03 +00:00
|
|
|
mJustReverted = true;
|
2009-03-13 22:11:42 +00:00
|
|
|
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();
|
2010-11-16 09:07:06 +00:00
|
|
|
mHandler.postUpdateSuggestions();
|
2009-03-13 22:11:42 +00:00
|
|
|
} else {
|
|
|
|
sendDownUpKeyEvents(KeyEvent.KEYCODE_DEL);
|
2010-11-16 09:57:03 +00:00
|
|
|
mJustReverted = false;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected String getWordSeparators() {
|
|
|
|
return mWordSeparators;
|
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
public boolean isWordSeparator(int code) {
|
|
|
|
String separators = getWordSeparators();
|
|
|
|
return separators.contains(String.valueOf((char)code));
|
|
|
|
}
|
|
|
|
|
2010-08-20 05:35:02 +00:00
|
|
|
private boolean isSentenceSeparator(int code) {
|
2009-03-13 22:11:42 +00:00
|
|
|
return mSentenceSeparators.contains(String.valueOf((char)code));
|
|
|
|
}
|
|
|
|
|
|
|
|
private void sendSpace() {
|
2010-12-02 11:54:32 +00:00
|
|
|
sendKeyChar((char)Keyboard.CODE_SPACE);
|
2010-11-13 08:16:34 +00:00
|
|
|
mKeyboardSwitcher.updateShiftState();
|
2009-03-13 22:11:42 +00:00
|
|
|
//onKey(KEY_SPACE[0], KEY_SPACE);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean preferCapitalization() {
|
2010-09-27 15:32:35 +00:00
|
|
|
return mWord.isFirstCharCapitalized();
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2010-11-18 00:55:23 +00:00
|
|
|
// Notify that Language has been changed and toggleLanguage will update KeyboaredID according
|
|
|
|
// to new Language.
|
2010-11-21 03:43:10 +00:00
|
|
|
public void onKeyboardLanguageChanged() {
|
2010-11-18 00:55:23 +00:00
|
|
|
toggleLanguage(true, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// "reset" and "next" are used only for USE_SPACEBAR_LANGUAGE_SWITCHER.
|
2010-01-30 04:09:49 +00:00
|
|
|
private void toggleLanguage(boolean reset, boolean next) {
|
2010-11-18 00:55:23 +00:00
|
|
|
if (SubtypeSwitcher.USE_SPACEBAR_LANGUAGE_SWITCHER) {
|
|
|
|
mSubtypeSwitcher.toggleLanguage(reset, next);
|
|
|
|
}
|
|
|
|
// Reload keyboard because the current language has been changed.
|
2010-11-13 08:16:34 +00:00
|
|
|
KeyboardSwitcher switcher = mKeyboardSwitcher;
|
|
|
|
final int mode = switcher.getKeyboardMode();
|
2010-11-11 07:03:19 +00:00
|
|
|
final EditorInfo attribute = getCurrentInputEditorInfo();
|
2010-11-12 23:26:54 +00:00
|
|
|
final int imeOptions = (attribute != null) ? attribute.imeOptions : 0;
|
2010-11-21 01:36:37 +00:00
|
|
|
switcher.loadKeyboard(mode, imeOptions, mVoiceConnector.isVoiceButtonEnabled(),
|
|
|
|
mVoiceConnector.isVoiceButtonOnPrimary());
|
2010-11-17 07:35:35 +00:00
|
|
|
initSuggest();
|
2010-11-13 08:16:34 +00:00
|
|
|
switcher.updateShiftState();
|
2009-10-12 20:48:35 +00:00
|
|
|
}
|
|
|
|
|
2010-12-02 09:46:21 +00:00
|
|
|
@Override
|
2009-10-12 20:48:35 +00:00
|
|
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
|
|
|
|
String key) {
|
2010-11-17 07:35:35 +00:00
|
|
|
mSubtypeSwitcher.onSharedPreferenceChanged(sharedPreferences, key);
|
2010-12-09 12:06:26 +00:00
|
|
|
if (Settings.PREF_SELECTED_LANGUAGES.equals(key)) {
|
2009-10-12 20:48:35 +00:00
|
|
|
mRefreshKeyboardRequired = true;
|
2010-12-09 12:06:26 +00:00
|
|
|
} else if (Settings.PREF_RECORRECTION_ENABLED.equals(key)) {
|
|
|
|
mReCorrectionEnabled = sharedPreferences.getBoolean(
|
|
|
|
Settings.PREF_RECORRECTION_ENABLED,
|
2010-09-06 10:18:38 +00:00
|
|
|
getResources().getBoolean(R.bool.default_recorrection_enabled));
|
2009-10-12 20:48:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-02 09:46:21 +00:00
|
|
|
@Override
|
2010-09-23 03:42:15 +00:00
|
|
|
public void swipeRight() {
|
|
|
|
if (LatinKeyboardView.DEBUG_AUTO_PLAY) {
|
2010-11-21 01:36:37 +00:00
|
|
|
CharSequence text = ((android.text.ClipboardManager)getSystemService(
|
|
|
|
CLIPBOARD_SERVICE)).getText();
|
2010-09-23 03:42:15 +00:00
|
|
|
if (!TextUtils.isEmpty(text)) {
|
|
|
|
mKeyboardSwitcher.getInputView().startPlaying(text.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-02 09:46:21 +00:00
|
|
|
@Override
|
2009-03-13 22:11:42 +00:00
|
|
|
public void swipeLeft() {
|
|
|
|
}
|
|
|
|
|
2010-12-02 09:46:21 +00:00
|
|
|
@Override
|
2009-03-13 22:11:42 +00:00
|
|
|
public void swipeDown() {
|
2009-08-28 00:35:33 +00:00
|
|
|
handleClose();
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2010-12-02 09:46:21 +00:00
|
|
|
@Override
|
2009-03-13 22:11:42 +00:00
|
|
|
public void swipeUp() {
|
|
|
|
}
|
|
|
|
|
2010-12-02 09:46:21 +00:00
|
|
|
@Override
|
2009-03-13 22:11:42 +00:00
|
|
|
public void onPress(int primaryCode) {
|
|
|
|
vibrate();
|
|
|
|
playKeyClick(primaryCode);
|
2010-11-13 08:01:13 +00:00
|
|
|
KeyboardSwitcher switcher = mKeyboardSwitcher;
|
|
|
|
final boolean distinctMultiTouch = switcher.hasDistinctMultitouch();
|
2010-12-02 11:54:32 +00:00
|
|
|
if (distinctMultiTouch && primaryCode == Keyboard.CODE_SHIFT) {
|
2010-11-13 08:16:34 +00:00
|
|
|
switcher.onPressShift();
|
2010-12-06 03:12:27 +00:00
|
|
|
} else if (distinctMultiTouch && primaryCode == Keyboard.CODE_SWITCH_ALPHA_SYMBOL) {
|
2010-11-16 08:28:50 +00:00
|
|
|
switcher.onPressSymbol();
|
2010-09-01 16:35:24 +00:00
|
|
|
} else {
|
2010-11-16 08:28:50 +00:00
|
|
|
switcher.onOtherKeyPressed();
|
2010-09-01 07:36:24 +00:00
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2010-12-02 09:46:21 +00:00
|
|
|
@Override
|
2009-03-13 22:11:42 +00:00
|
|
|
public void onRelease(int primaryCode) {
|
2010-11-13 08:01:13 +00:00
|
|
|
KeyboardSwitcher switcher = mKeyboardSwitcher;
|
2010-01-30 04:09:49 +00:00
|
|
|
// Reset any drag flags in the keyboard
|
2010-11-13 08:01:13 +00:00
|
|
|
switcher.keyReleased();
|
|
|
|
final boolean distinctMultiTouch = switcher.hasDistinctMultitouch();
|
2010-12-02 11:54:32 +00:00
|
|
|
if (distinctMultiTouch && primaryCode == Keyboard.CODE_SHIFT) {
|
2010-11-16 09:47:39 +00:00
|
|
|
switcher.onReleaseShift();
|
2010-12-06 03:12:27 +00:00
|
|
|
} else if (distinctMultiTouch && primaryCode == Keyboard.CODE_SWITCH_ALPHA_SYMBOL) {
|
2010-11-16 08:28:50 +00:00
|
|
|
switcher.onReleaseSymbol();
|
2010-09-01 16:35:24 +00:00
|
|
|
}
|
2009-03-13 22:11:42 +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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void playKeyClick(int primaryCode) {
|
|
|
|
// if mAudioManager is null, we don't have the ringer state yet
|
|
|
|
// mAudioManager will be set by updateRingerMode
|
|
|
|
if (mAudioManager == null) {
|
2010-08-20 05:35:02 +00:00
|
|
|
if (mKeyboardSwitcher.getInputView() != null) {
|
2009-03-13 22:11:42 +00:00
|
|
|
updateRingerMode();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mSoundOn && !mSilentMode) {
|
|
|
|
// FIXME: Volume and enable should come from UI settings
|
|
|
|
// FIXME: These should be triggered after auto-repeat logic
|
|
|
|
int sound = AudioManager.FX_KEYPRESS_STANDARD;
|
|
|
|
switch (primaryCode) {
|
2010-12-02 11:54:32 +00:00
|
|
|
case Keyboard.CODE_DELETE:
|
2009-03-13 22:11:42 +00:00
|
|
|
sound = AudioManager.FX_KEYPRESS_DELETE;
|
|
|
|
break;
|
2010-12-02 11:54:32 +00:00
|
|
|
case Keyboard.CODE_ENTER:
|
2009-03-13 22:11:42 +00:00
|
|
|
sound = AudioManager.FX_KEYPRESS_RETURN;
|
|
|
|
break;
|
2010-12-02 11:54:32 +00:00
|
|
|
case Keyboard.CODE_SPACE:
|
2009-03-13 22:11:42 +00:00
|
|
|
sound = AudioManager.FX_KEYPRESS_SPACEBAR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
mAudioManager.playSoundEffect(sound, FX_VOLUME);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-21 01:36:37 +00:00
|
|
|
public void vibrate() {
|
2009-03-13 22:11:42 +00:00
|
|
|
if (!mVibrateOn) {
|
|
|
|
return;
|
|
|
|
}
|
2010-11-13 08:01:13 +00:00
|
|
|
LatinKeyboardView inputView = mKeyboardSwitcher.getInputView();
|
|
|
|
if (inputView != null) {
|
|
|
|
inputView.performHapticFeedback(
|
2010-08-20 05:35:02 +00:00
|
|
|
HapticFeedbackConstants.KEYBOARD_TAP,
|
2010-02-11 01:45:35 +00:00
|
|
|
HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-26 00:39:38 +00:00
|
|
|
private void checkTutorial(String privateImeOptions) {
|
|
|
|
if (privateImeOptions == null) return;
|
|
|
|
if (privateImeOptions.equals("com.android.setupwizard:ShowTutorial")) {
|
2010-11-16 09:07:06 +00:00
|
|
|
if (mTutorial == null) mHandler.startTutorial();
|
2009-03-26 00:39:38 +00:00
|
|
|
} else if (privateImeOptions.equals("com.android.setupwizard:HideTutorial")) {
|
|
|
|
if (mTutorial != null) {
|
|
|
|
if (mTutorial.close()) {
|
|
|
|
mTutorial = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-11-13 08:46:45 +00:00
|
|
|
// Tutorial.TutorialListener
|
2010-12-02 09:46:21 +00:00
|
|
|
@Override
|
2010-11-13 08:46:45 +00:00
|
|
|
public void onTutorialDone() {
|
|
|
|
sendDownUpKeyEvents(-1); // Inform the setupwizard that tutorial is in last bubble
|
2009-03-26 00:39:38 +00:00
|
|
|
mTutorial = null;
|
|
|
|
}
|
2009-07-17 19:51:45 +00:00
|
|
|
|
2010-11-13 08:46:45 +00:00
|
|
|
public void promoteToUserDictionary(String word, int frequency) {
|
2009-07-17 19:51:45 +00:00
|
|
|
if (mUserDictionary.isValidWord(word)) return;
|
|
|
|
mUserDictionary.addWord(word, frequency);
|
|
|
|
}
|
|
|
|
|
2010-11-13 08:46:45 +00:00
|
|
|
public WordComposer getCurrentWord() {
|
2010-02-24 03:01:43 +00:00
|
|
|
return mWord;
|
|
|
|
}
|
|
|
|
|
2010-11-13 08:46:45 +00:00
|
|
|
public boolean getPopupOn() {
|
2010-08-20 05:35:02 +00:00
|
|
|
return mPopupOn;
|
|
|
|
}
|
|
|
|
|
2009-12-18 21:39:18 +00:00
|
|
|
private void updateCorrectionMode() {
|
|
|
|
mHasDictionary = mSuggest != null ? mSuggest.hasMainDictionary() : false;
|
|
|
|
mAutoCorrectOn = (mAutoCorrectEnabled || mQuickFixes)
|
|
|
|
&& !mInputTypeNoAutoCorrect && mHasDictionary;
|
2010-02-20 00:38:58 +00:00
|
|
|
mCorrectionMode = (mAutoCorrectOn && mAutoCorrectEnabled)
|
2009-12-18 21:39:18 +00:00
|
|
|
? Suggest.CORRECTION_FULL
|
2010-02-20 00:38:58 +00:00
|
|
|
: (mAutoCorrectOn ? Suggest.CORRECTION_BASIC : Suggest.CORRECTION_NONE);
|
2010-08-20 05:35:02 +00:00
|
|
|
mCorrectionMode = (mBigramSuggestionEnabled && mAutoCorrectOn && mAutoCorrectEnabled)
|
|
|
|
? Suggest.CORRECTION_FULL_BIGRAM : mCorrectionMode;
|
2009-12-18 21:39:18 +00:00
|
|
|
if (mSuggest != null) {
|
|
|
|
mSuggest.setCorrectionMode(mCorrectionMode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-17 07:35:35 +00:00
|
|
|
private void updateAutoTextEnabled() {
|
2010-02-20 00:38:58 +00:00
|
|
|
if (mSuggest == null) return;
|
2010-11-17 07:35:35 +00:00
|
|
|
mSuggest.setAutoTextEnabled(mQuickFixes
|
2010-11-18 00:55:23 +00:00
|
|
|
&& SubtypeSwitcher.getInstance().isSystemLanguageSameAsInputLanguage());
|
2010-02-20 00:38:58 +00:00
|
|
|
}
|
|
|
|
|
2010-11-13 10:09:30 +00:00
|
|
|
private void updateSuggestionVisibility(SharedPreferences prefs) {
|
|
|
|
final String suggestionVisiblityStr = prefs.getString(
|
2010-12-09 12:06:26 +00:00
|
|
|
Settings.PREF_SHOW_SUGGESTIONS_SETTING,
|
|
|
|
mResources.getString(R.string.prefs_suggestion_visibility_default_value));
|
2010-11-13 10:09:30 +00:00
|
|
|
for (int visibility : SUGGESTION_VISIBILITY_VALUE_ARRAY) {
|
|
|
|
if (suggestionVisiblityStr.equals(mResources.getString(visibility))) {
|
|
|
|
mSuggestionVisibility = visibility;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
protected void launchSettings() {
|
2010-12-09 12:06:26 +00:00
|
|
|
launchSettings(Settings.class);
|
2010-01-16 20:21:23 +00:00
|
|
|
}
|
|
|
|
|
2010-09-27 03:55:21 +00:00
|
|
|
public void launchDebugSettings() {
|
2010-12-09 12:06:26 +00:00
|
|
|
launchSettings(DebugSettings.class);
|
2010-09-27 03:55:21 +00:00
|
|
|
}
|
|
|
|
|
2010-11-11 00:10:10 +00:00
|
|
|
protected void launchSettings(Class<? extends PreferenceActivity> settingsClass) {
|
2009-03-13 22:11:42 +00:00
|
|
|
handleClose();
|
|
|
|
Intent intent = new Intent();
|
2010-01-16 20:21:23 +00:00
|
|
|
intent.setClass(LatinIME.this, settingsClass);
|
2009-03-13 22:11:42 +00:00
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
startActivity(intent);
|
|
|
|
}
|
|
|
|
|
2010-11-11 00:10:10 +00:00
|
|
|
private void loadSettings(EditorInfo attribute) {
|
2009-03-13 22:11:42 +00:00
|
|
|
// Get the settings preferences
|
2010-11-26 04:08:36 +00:00
|
|
|
final SharedPreferences prefs = mPrefs;
|
2010-11-11 09:15:41 +00:00
|
|
|
Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
|
|
|
|
mVibrateOn = vibrator != null && vibrator.hasVibrator()
|
2010-12-09 12:06:26 +00:00
|
|
|
&& prefs.getBoolean(Settings.PREF_VIBRATE_ON, false);
|
|
|
|
mSoundOn = prefs.getBoolean(Settings.PREF_SOUND_ON, false);
|
|
|
|
mPopupOn = prefs.getBoolean(Settings.PREF_POPUP_ON,
|
2010-08-20 05:35:02 +00:00
|
|
|
mResources.getBoolean(R.bool.default_popup_preview));
|
2010-12-09 12:06:26 +00:00
|
|
|
mAutoCap = prefs.getBoolean(Settings.PREF_AUTO_CAP, true);
|
|
|
|
mQuickFixes = prefs.getBoolean(Settings.PREF_QUICK_FIXES, true);
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-11-26 04:08:36 +00:00
|
|
|
mAutoCorrectEnabled = isAutoCorrectEnabled(prefs);
|
|
|
|
mBigramSuggestionEnabled = mAutoCorrectEnabled && isBigramSuggestionEnabled(prefs);
|
|
|
|
loadAndSetAutoCompletionThreshold(prefs);
|
2010-01-16 20:21:23 +00:00
|
|
|
|
2010-11-26 04:08:36 +00:00
|
|
|
mVoiceConnector.loadSettings(attribute, prefs);
|
2010-11-21 01:36:37 +00:00
|
|
|
|
2009-12-18 21:39:18 +00:00
|
|
|
updateCorrectionMode();
|
2010-11-17 07:35:35 +00:00
|
|
|
updateAutoTextEnabled();
|
2010-11-26 04:08:36 +00:00
|
|
|
updateSuggestionVisibility(prefs);
|
|
|
|
SubtypeSwitcher.getInstance().loadSettings();
|
2009-10-12 20:48:35 +00:00
|
|
|
}
|
|
|
|
|
2010-09-28 03:23:26 +00:00
|
|
|
/**
|
|
|
|
* load Auto completion threshold from SharedPreferences,
|
|
|
|
* and modify mSuggest's threshold.
|
|
|
|
*/
|
|
|
|
private void loadAndSetAutoCompletionThreshold(SharedPreferences sp) {
|
|
|
|
// When mSuggest is not initialized, cannnot modify mSuggest's threshold.
|
|
|
|
if (mSuggest == null) return;
|
|
|
|
// When auto completion setting is turned off, the threshold is ignored.
|
|
|
|
if (!isAutoCorrectEnabled(sp)) return;
|
|
|
|
|
2010-12-09 12:06:26 +00:00
|
|
|
final String currentAutoCompletionSetting = sp.getString(
|
|
|
|
Settings.PREF_AUTO_COMPLETION_THRESHOLD,
|
2010-09-28 03:23:26 +00:00
|
|
|
mResources.getString(R.string.auto_completion_threshold_mode_value_modest));
|
|
|
|
final String[] autoCompletionThresholdValues = mResources.getStringArray(
|
|
|
|
R.array.auto_complete_threshold_values);
|
|
|
|
// When autoCompletionThreshold is greater than 1.0,
|
|
|
|
// auto completion is virtually turned off.
|
|
|
|
double autoCompletionThreshold = Double.MAX_VALUE;
|
|
|
|
try {
|
|
|
|
final int arrayIndex = Integer.valueOf(currentAutoCompletionSetting);
|
|
|
|
if (arrayIndex >= 0 && arrayIndex < autoCompletionThresholdValues.length) {
|
|
|
|
autoCompletionThreshold = Double.parseDouble(
|
|
|
|
autoCompletionThresholdValues[arrayIndex]);
|
|
|
|
}
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
// Whenever the threshold settings are correct,
|
|
|
|
// never come here.
|
|
|
|
autoCompletionThreshold = Double.MAX_VALUE;
|
|
|
|
Log.w(TAG, "Cannot load auto completion threshold setting."
|
|
|
|
+ " currentAutoCompletionSetting: " + currentAutoCompletionSetting
|
|
|
|
+ ", autoCompletionThresholdValues: "
|
|
|
|
+ Arrays.toString(autoCompletionThresholdValues));
|
|
|
|
}
|
|
|
|
// TODO: This should be refactored :
|
|
|
|
// setAutoCompleteThreshold should be called outside of this method.
|
|
|
|
mSuggest.setAutoCompleteThreshold(autoCompletionThreshold);
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean isAutoCorrectEnabled(SharedPreferences sp) {
|
2010-12-09 12:06:26 +00:00
|
|
|
final String currentAutoCompletionSetting = sp.getString(
|
|
|
|
Settings.PREF_AUTO_COMPLETION_THRESHOLD,
|
2010-09-28 03:23:26 +00:00
|
|
|
mResources.getString(R.string.auto_completion_threshold_mode_value_modest));
|
|
|
|
final String autoCompletionOff = mResources.getString(
|
|
|
|
R.string.auto_completion_threshold_mode_value_off);
|
|
|
|
return !currentAutoCompletionSetting.equals(autoCompletionOff);
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean isBigramSuggestionEnabled(SharedPreferences sp) {
|
|
|
|
// TODO: Define default value instead of 'true'.
|
2010-12-09 12:06:26 +00:00
|
|
|
return sp.getBoolean(Settings.PREF_BIGRAM_SUGGESTIONS, true);
|
2010-09-28 03:23:26 +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() {
|
|
|
|
|
2010-12-02 09:46:21 +00:00
|
|
|
@Override
|
2009-03-13 22:11:42 +00:00
|
|
|
public void onClick(DialogInterface di, int position) {
|
|
|
|
di.dismiss();
|
|
|
|
switch (position) {
|
|
|
|
case POS_SETTINGS:
|
|
|
|
launchSettings();
|
|
|
|
break;
|
|
|
|
case POS_METHOD:
|
2010-11-25 00:20:28 +00:00
|
|
|
mImm.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();
|
|
|
|
}
|
|
|
|
|
2010-10-08 13:17:16 +00:00
|
|
|
@Override
|
|
|
|
protected void dump(FileDescriptor fd, PrintWriter fout, String[] args) {
|
2009-03-13 22:11:42 +00:00
|
|
|
super.dump(fd, fout, args);
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
final Printer p = new PrintWriterPrinter(fout);
|
|
|
|
p.println("LatinIME state :");
|
|
|
|
p.println(" Keyboard mode = " + mKeyboardSwitcher.getKeyboardMode());
|
|
|
|
p.println(" mComposing=" + mComposing.toString());
|
|
|
|
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);
|
|
|
|
}
|
2010-11-17 07:35:35 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCurrentInputMethodSubtypeChanged(InputMethodSubtype subtype) {
|
2010-11-18 00:55:23 +00:00
|
|
|
SubtypeSwitcher.getInstance().updateSubtype(subtype);
|
2010-11-17 07:35:35 +00:00
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|