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;
|
|
|
|
|
2012-04-19 03:42:13 +00:00
|
|
|
import static com.android.inputmethod.latin.Constants.ImeOption.FORCE_ASCII;
|
|
|
|
import static com.android.inputmethod.latin.Constants.ImeOption.NO_MICROPHONE;
|
|
|
|
import static com.android.inputmethod.latin.Constants.ImeOption.NO_MICROPHONE_COMPAT;
|
|
|
|
|
2012-07-19 01:00:48 +00:00
|
|
|
import android.app.Activity;
|
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;
|
2012-05-25 09:07:52 +00:00
|
|
|
import android.content.pm.ApplicationInfo;
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.content.res.Configuration;
|
2009-10-12 20:48:35 +00:00
|
|
|
import android.content.res.Resources;
|
2012-03-07 06:30:16 +00:00
|
|
|
import android.graphics.Rect;
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.inputmethodservice.InputMethodService;
|
|
|
|
import android.media.AudioManager;
|
2011-01-26 14:13:18 +00:00
|
|
|
import android.net.ConnectivityManager;
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.os.Debug;
|
2012-02-18 01:46:01 +00:00
|
|
|
import android.os.IBinder;
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.os.Message;
|
|
|
|
import android.os.SystemClock;
|
|
|
|
import android.preference.PreferenceManager;
|
2010-12-10 06:24:28 +00:00
|
|
|
import android.text.InputType;
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.util.Log;
|
|
|
|
import android.util.PrintWriterPrinter;
|
|
|
|
import android.util.Printer;
|
2012-05-25 10:56:45 +00:00
|
|
|
import android.view.KeyCharacterMap;
|
|
|
|
import android.view.KeyEvent;
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.view.View;
|
2012-03-07 06:30:16 +00:00
|
|
|
import android.view.ViewGroup.LayoutParams;
|
2012-04-02 13:25:08 +00:00
|
|
|
import android.view.Window;
|
|
|
|
import android.view.WindowManager;
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.view.inputmethod.CompletionInfo;
|
2012-03-31 09:32:48 +00:00
|
|
|
import android.view.inputmethod.CorrectionInfo;
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.view.inputmethod.EditorInfo;
|
2012-04-02 12:31:52 +00:00
|
|
|
import android.view.inputmethod.InputMethodSubtype;
|
2011-05-23 09:30:21 +00:00
|
|
|
|
2011-05-18 00:03:25 +00:00
|
|
|
import com.android.inputmethod.accessibility.AccessibilityUtils;
|
2012-02-07 21:14:18 +00:00
|
|
|
import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy;
|
2011-05-23 09:30:21 +00:00
|
|
|
import com.android.inputmethod.compat.CompatUtils;
|
|
|
|
import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
|
2011-05-24 11:30:30 +00:00
|
|
|
import com.android.inputmethod.compat.SuggestionSpanUtils;
|
2012-07-04 07:55:51 +00:00
|
|
|
import com.android.inputmethod.keyboard.KeyDetector;
|
2011-05-23 09:30:21 +00:00
|
|
|
import com.android.inputmethod.keyboard.Keyboard;
|
|
|
|
import com.android.inputmethod.keyboard.KeyboardActionListener;
|
2011-12-07 12:27:59 +00:00
|
|
|
import com.android.inputmethod.keyboard.KeyboardId;
|
2011-05-23 09:30:21 +00:00
|
|
|
import com.android.inputmethod.keyboard.KeyboardSwitcher;
|
2011-07-04 11:58:58 +00:00
|
|
|
import com.android.inputmethod.keyboard.KeyboardView;
|
2012-07-23 01:27:14 +00:00
|
|
|
import com.android.inputmethod.keyboard.MainKeyboardView;
|
2012-04-03 05:28:56 +00:00
|
|
|
import com.android.inputmethod.latin.LocaleUtils.RunInLocale;
|
2012-03-26 13:10:21 +00:00
|
|
|
import com.android.inputmethod.latin.define.ProductionFlag;
|
2012-07-23 06:28:28 +00:00
|
|
|
import com.android.inputmethod.latin.suggestions.SuggestionStripView;
|
2012-07-20 18:02:39 +00:00
|
|
|
import com.android.inputmethod.research.ResearchLogger;
|
2009-03-13 22:11:42 +00:00
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
import java.io.FileDescriptor;
|
|
|
|
import java.io.PrintWriter;
|
2012-03-13 09:21:35 +00:00
|
|
|
import java.util.ArrayList;
|
2010-01-16 20:21:23 +00:00
|
|
|
import java.util.Locale;
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
/**
|
|
|
|
* Input method implementation for Qwerty'ish keyboard.
|
|
|
|
*/
|
2012-04-02 13:25:08 +00:00
|
|
|
public class LatinIME extends InputMethodService implements KeyboardActionListener,
|
2012-07-24 06:56:25 +00:00
|
|
|
SuggestionStripView.Listener, TargetApplicationGetter.OnTargetApplicationKnownListener,
|
|
|
|
Suggest.SuggestInitializationListener {
|
2011-02-23 08:23:29 +00:00
|
|
|
private static final String TAG = LatinIME.class.getSimpleName();
|
2010-11-21 01:36:37 +00:00
|
|
|
private static final boolean TRACE = false;
|
2011-05-27 12:41:13 +00:00
|
|
|
private static boolean DEBUG;
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2011-01-21 10:04:00 +00:00
|
|
|
private static final int EXTENDED_TOUCHABLE_REGION_HEIGHT = 100;
|
2010-10-27 09:05:27 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
// How many continuous deletes at which to start deleting at a higher speed.
|
|
|
|
private static final int DELETE_ACCELERATE_AT = 20;
|
|
|
|
// Key events coming any faster than this are long-presses.
|
2009-07-28 23:33:36 +00:00
|
|
|
private static final int QUICK_PRESS = 200;
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2011-09-29 08:27:48 +00:00
|
|
|
private static final int PENDING_IMS_CALLBACK_DURATION = 800;
|
2011-07-29 17:45:37 +00:00
|
|
|
|
2011-03-14 18:46:15 +00:00
|
|
|
/**
|
|
|
|
* The name of the scheme used by the Package Manager to warn of a new package installation,
|
|
|
|
* replacement or removal.
|
|
|
|
*/
|
|
|
|
private static final String SCHEME_PACKAGE = "package";
|
|
|
|
|
2012-02-02 08:18:03 +00:00
|
|
|
private static final int SPACE_STATE_NONE = 0;
|
2011-10-25 12:14:33 +00:00
|
|
|
// Double space: the state where the user pressed space twice quickly, which LatinIME
|
|
|
|
// resolved as period-space. Undoing this converts the period to a space.
|
2012-02-02 08:18:03 +00:00
|
|
|
private static final int SPACE_STATE_DOUBLE = 1;
|
2012-02-22 02:54:44 +00:00
|
|
|
// Swap punctuation: the state where a weak space and a punctuation from the suggestion strip
|
|
|
|
// have just been swapped. Undoing this swaps them back; the space is still considered weak.
|
2011-10-25 12:14:33 +00:00
|
|
|
private static final int SPACE_STATE_SWAP_PUNCTUATION = 2;
|
2012-02-02 08:18:03 +00:00
|
|
|
// Weak space: a space that should be swapped only by suggestion strip punctuation. Weak
|
|
|
|
// spaces happen when the user presses space, accepting the current suggestion (whether
|
|
|
|
// it's an auto-correction or not).
|
|
|
|
private static final int SPACE_STATE_WEAK = 3;
|
|
|
|
// Phantom space: a not-yet-inserted space that should get inserted on the next input,
|
|
|
|
// character provided it's not a separator. If it's a separator, the phantom space is dropped.
|
|
|
|
// Phantom spaces happen when a user chooses a word from the suggestion strip.
|
|
|
|
private static final int SPACE_STATE_PHANTOM = 4;
|
2011-10-25 12:14:33 +00:00
|
|
|
|
|
|
|
// Current space state of the input method. This can be any of the above constants.
|
|
|
|
private int mSpaceState;
|
2011-10-24 09:00:05 +00:00
|
|
|
|
2012-06-08 12:34:07 +00:00
|
|
|
private SettingsValues mCurrentSettings;
|
2011-05-10 06:51:43 +00:00
|
|
|
|
2011-10-12 09:50:51 +00:00
|
|
|
private View mExtractArea;
|
2011-09-02 12:03:18 +00:00
|
|
|
private View mKeyPreviewBackingView;
|
2011-09-01 05:54:28 +00:00
|
|
|
private View mSuggestionsContainer;
|
2012-07-23 06:28:28 +00:00
|
|
|
private SuggestionStripView mSuggestionStripView;
|
2012-02-07 10:22:37 +00:00
|
|
|
/* package for tests */ Suggest mSuggest;
|
2010-12-11 08:06:24 +00:00
|
|
|
private CompletionInfo[] mApplicationSpecifiedCompletions;
|
2012-05-25 09:07:52 +00:00
|
|
|
private ApplicationInfo mTargetApplicationInfo;
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2011-03-18 05:49:06 +00:00
|
|
|
private InputMethodManagerCompatWrapper mImm;
|
2011-01-20 13:52:02 +00:00
|
|
|
private Resources mResources;
|
|
|
|
private SharedPreferences mPrefs;
|
2012-03-22 09:08:23 +00:00
|
|
|
/* package for tests */ final KeyboardSwitcher mKeyboardSwitcher;
|
2012-03-06 10:06:58 +00:00
|
|
|
private final SubtypeSwitcher mSubtypeSwitcher;
|
2012-02-18 01:46:01 +00:00
|
|
|
private boolean mShouldSwitchToLastSubtype = true;
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2012-04-19 14:11:31 +00:00
|
|
|
private boolean mIsMainDictionaryAvailable;
|
2012-06-08 08:01:35 +00:00
|
|
|
private UserBinaryDictionary mUserDictionary;
|
2012-03-16 09:01:27 +00:00
|
|
|
private UserHistoryDictionary mUserHistoryDictionary;
|
2011-11-18 06:24:49 +00:00
|
|
|
private boolean mIsUserDictionaryAvailable;
|
2009-10-12 20:48:35 +00:00
|
|
|
|
2012-01-26 07:37:47 +00:00
|
|
|
private LastComposedWord mLastComposedWord = LastComposedWord.NOT_A_COMPOSED_WORD;
|
2011-07-12 01:29:29 +00:00
|
|
|
private WordComposer mWordComposer = new WordComposer();
|
2012-07-05 03:36:06 +00:00
|
|
|
private RichInputConnection mConnection = new RichInputConnection(this);
|
2010-11-21 01:36:37 +00:00
|
|
|
|
2010-08-20 05:35:02 +00:00
|
|
|
// Keep track of the last selection range to decide if we need to show word alternatives
|
2012-01-24 06:45:32 +00:00
|
|
|
private static final int NOT_A_CURSOR_POSITION = -1;
|
|
|
|
private int mLastSelectionStart = NOT_A_CURSOR_POSITION;
|
|
|
|
private int mLastSelectionEnd = NOT_A_CURSOR_POSITION;
|
2010-08-20 05:35:02 +00:00
|
|
|
|
2011-06-08 07:47:19 +00:00
|
|
|
// Whether we are expecting an onUpdateSelection event to fire. If it does when we don't
|
|
|
|
// "expect" it, it means the user actually moved the cursor.
|
|
|
|
private boolean mExpectingUpdateSelection;
|
2009-03-13 22:11:42 +00:00
|
|
|
private int mDeleteCount;
|
|
|
|
private long mLastKeyTime;
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2012-03-06 10:00:23 +00:00
|
|
|
private AudioAndHapticFeedbackManager mFeedbackManager;
|
2011-09-19 05:51:31 +00:00
|
|
|
|
2011-07-21 06:57:00 +00:00
|
|
|
// Member variables for remembering the current device orientation.
|
|
|
|
private int mDisplayOrientation;
|
|
|
|
|
2011-03-14 18:46:15 +00:00
|
|
|
// Object for reacting to adding/removing a dictionary pack.
|
|
|
|
private BroadcastReceiver mDictionaryPackInstallReceiver =
|
|
|
|
new DictionaryPackInstallBroadcastReceiver(this);
|
|
|
|
|
2010-04-01 13:28:52 +00:00
|
|
|
// Keeps track of most recently inserted text (multi-character key) for reverting
|
|
|
|
private CharSequence mEnteredText;
|
|
|
|
|
2012-03-07 06:20:01 +00:00
|
|
|
private boolean mIsAutoCorrectionIndicatorOn;
|
2011-10-12 09:07:09 +00:00
|
|
|
|
2012-04-02 13:25:08 +00:00
|
|
|
private AlertDialog mOptionsDialog;
|
|
|
|
|
2011-06-24 18:54:11 +00:00
|
|
|
public final UIHandler mHandler = new UIHandler(this);
|
2010-11-16 09:07:06 +00:00
|
|
|
|
2011-06-24 18:54:11 +00:00
|
|
|
public static class UIHandler extends StaticInnerHandlerWrapper<LatinIME> {
|
2011-10-03 09:12:53 +00:00
|
|
|
private static final int MSG_UPDATE_SHIFT_STATE = 1;
|
2012-03-13 03:44:03 +00:00
|
|
|
private static final int MSG_PENDING_IMS_CALLBACK = 6;
|
2012-07-06 03:15:45 +00:00
|
|
|
private static final int MSG_UPDATE_SUGGESTION_STRIP = 7;
|
2012-03-13 03:44:03 +00:00
|
|
|
|
2011-11-18 05:45:49 +00:00
|
|
|
private int mDelayUpdateSuggestions;
|
|
|
|
private int mDelayUpdateShiftState;
|
|
|
|
private long mDoubleSpacesTurnIntoPeriodTimeout;
|
2012-06-08 13:36:17 +00:00
|
|
|
private long mDoubleSpaceTimerStart;
|
2011-07-21 06:57:00 +00:00
|
|
|
|
2011-06-24 18:54:11 +00:00
|
|
|
public UIHandler(LatinIME outerInstance) {
|
|
|
|
super(outerInstance);
|
2011-11-18 05:45:49 +00:00
|
|
|
}
|
2011-11-16 23:58:42 +00:00
|
|
|
|
2011-11-18 05:45:49 +00:00
|
|
|
public void onCreate() {
|
|
|
|
final Resources res = getOuterInstance().getResources();
|
2011-11-16 23:58:42 +00:00
|
|
|
mDelayUpdateSuggestions =
|
|
|
|
res.getInteger(R.integer.config_delay_update_suggestions);
|
|
|
|
mDelayUpdateShiftState =
|
|
|
|
res.getInteger(R.integer.config_delay_update_shift_state);
|
|
|
|
mDoubleSpacesTurnIntoPeriodTimeout = res.getInteger(
|
|
|
|
R.integer.config_double_spaces_turn_into_period_timeout);
|
2011-06-24 18:54:11 +00:00
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
@Override
|
|
|
|
public void handleMessage(Message msg) {
|
2011-06-24 18:54:11 +00:00
|
|
|
final LatinIME latinIme = getOuterInstance();
|
|
|
|
final KeyboardSwitcher switcher = latinIme.mKeyboardSwitcher;
|
2009-03-13 22:11:42 +00:00
|
|
|
switch (msg.what) {
|
2012-07-06 03:15:45 +00:00
|
|
|
case MSG_UPDATE_SUGGESTION_STRIP:
|
2012-07-23 09:03:16 +00:00
|
|
|
latinIme.updateSuggestionStrip();
|
2010-11-16 09:07:06 +00:00
|
|
|
break;
|
|
|
|
case MSG_UPDATE_SHIFT_STATE:
|
2011-01-12 11:33:54 +00:00
|
|
|
switcher.updateShiftState();
|
2010-11-16 09:07:06 +00:00
|
|
|
break;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
}
|
2010-11-16 09:07:06 +00:00
|
|
|
|
2012-07-06 02:33:16 +00:00
|
|
|
public void postUpdateSuggestionStrip() {
|
2012-07-06 03:15:45 +00:00
|
|
|
sendMessageDelayed(obtainMessage(MSG_UPDATE_SUGGESTION_STRIP), mDelayUpdateSuggestions);
|
2010-11-16 09:07:06 +00:00
|
|
|
}
|
|
|
|
|
2012-07-05 02:34:48 +00:00
|
|
|
public void cancelUpdateSuggestionStrip() {
|
2012-07-06 03:15:45 +00:00
|
|
|
removeMessages(MSG_UPDATE_SUGGESTION_STRIP);
|
2010-11-16 09:07:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasPendingUpdateSuggestions() {
|
2012-07-06 03:15:45 +00:00
|
|
|
return hasMessages(MSG_UPDATE_SUGGESTION_STRIP);
|
2010-11-16 09:07:06 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 19:45:35 +00:00
|
|
|
public void postUpdateShiftState() {
|
2010-11-16 09:07:06 +00:00
|
|
|
removeMessages(MSG_UPDATE_SHIFT_STATE);
|
2011-11-16 23:58:42 +00:00
|
|
|
sendMessageDelayed(obtainMessage(MSG_UPDATE_SHIFT_STATE), mDelayUpdateShiftState);
|
2010-11-16 09:07:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void cancelUpdateShiftState() {
|
|
|
|
removeMessages(MSG_UPDATE_SHIFT_STATE);
|
|
|
|
}
|
|
|
|
|
2011-03-02 07:40:10 +00:00
|
|
|
public void startDoubleSpacesTimer() {
|
2012-06-08 13:36:17 +00:00
|
|
|
mDoubleSpaceTimerStart = SystemClock.uptimeMillis();
|
2011-03-02 07:40:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void cancelDoubleSpacesTimer() {
|
2012-06-08 13:36:17 +00:00
|
|
|
mDoubleSpaceTimerStart = 0;
|
2011-03-02 07:40:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isAcceptingDoubleSpaces() {
|
2012-06-08 13:36:17 +00:00
|
|
|
return SystemClock.uptimeMillis() - mDoubleSpaceTimerStart
|
|
|
|
< mDoubleSpacesTurnIntoPeriodTimeout;
|
2011-03-02 07:40:10 +00:00
|
|
|
}
|
2011-07-21 06:57:00 +00:00
|
|
|
|
2011-09-29 08:27:48 +00:00
|
|
|
// Working variables for the following methods.
|
|
|
|
private boolean mIsOrientationChanging;
|
2012-01-24 02:58:07 +00:00
|
|
|
private boolean mPendingSuccessiveImsCallback;
|
2011-09-29 08:27:48 +00:00
|
|
|
private boolean mHasPendingStartInput;
|
|
|
|
private boolean mHasPendingFinishInputView;
|
|
|
|
private boolean mHasPendingFinishInput;
|
2011-11-21 22:58:32 +00:00
|
|
|
private EditorInfo mAppliedEditorInfo;
|
2011-09-29 08:27:48 +00:00
|
|
|
|
|
|
|
public void startOrientationChanging() {
|
2011-10-27 08:03:03 +00:00
|
|
|
removeMessages(MSG_PENDING_IMS_CALLBACK);
|
|
|
|
resetPendingImsCallback();
|
2011-09-29 08:27:48 +00:00
|
|
|
mIsOrientationChanging = true;
|
2011-07-29 17:45:37 +00:00
|
|
|
final LatinIME latinIme = getOuterInstance();
|
2011-11-29 05:12:49 +00:00
|
|
|
if (latinIme.isInputViewShown()) {
|
|
|
|
latinIme.mKeyboardSwitcher.saveKeyboardState();
|
|
|
|
}
|
2011-09-29 08:27:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void resetPendingImsCallback() {
|
|
|
|
mHasPendingFinishInputView = false;
|
|
|
|
mHasPendingFinishInput = false;
|
|
|
|
mHasPendingStartInput = false;
|
|
|
|
}
|
|
|
|
|
2011-11-21 22:58:32 +00:00
|
|
|
private void executePendingImsCallback(LatinIME latinIme, EditorInfo editorInfo,
|
2011-09-29 08:27:48 +00:00
|
|
|
boolean restarting) {
|
|
|
|
if (mHasPendingFinishInputView)
|
|
|
|
latinIme.onFinishInputViewInternal(mHasPendingFinishInput);
|
|
|
|
if (mHasPendingFinishInput)
|
|
|
|
latinIme.onFinishInputInternal();
|
|
|
|
if (mHasPendingStartInput)
|
2011-11-21 22:58:32 +00:00
|
|
|
latinIme.onStartInputInternal(editorInfo, restarting);
|
2011-09-29 08:27:48 +00:00
|
|
|
resetPendingImsCallback();
|
|
|
|
}
|
|
|
|
|
2011-11-21 22:58:32 +00:00
|
|
|
public void onStartInput(EditorInfo editorInfo, boolean restarting) {
|
2011-09-29 08:27:48 +00:00
|
|
|
if (hasMessages(MSG_PENDING_IMS_CALLBACK)) {
|
|
|
|
// Typically this is the second onStartInput after orientation changed.
|
|
|
|
mHasPendingStartInput = true;
|
|
|
|
} else {
|
|
|
|
if (mIsOrientationChanging && restarting) {
|
|
|
|
// This is the first onStartInput after orientation changed.
|
|
|
|
mIsOrientationChanging = false;
|
2012-01-24 02:58:07 +00:00
|
|
|
mPendingSuccessiveImsCallback = true;
|
2011-09-29 08:27:48 +00:00
|
|
|
}
|
|
|
|
final LatinIME latinIme = getOuterInstance();
|
2011-11-21 22:58:32 +00:00
|
|
|
executePendingImsCallback(latinIme, editorInfo, restarting);
|
|
|
|
latinIme.onStartInputInternal(editorInfo, restarting);
|
2011-07-29 17:45:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-21 22:58:32 +00:00
|
|
|
public void onStartInputView(EditorInfo editorInfo, boolean restarting) {
|
2011-12-07 12:27:59 +00:00
|
|
|
if (hasMessages(MSG_PENDING_IMS_CALLBACK)
|
|
|
|
&& KeyboardId.equivalentEditorInfoForKeyboard(editorInfo, mAppliedEditorInfo)) {
|
2011-11-21 22:58:32 +00:00
|
|
|
// Typically this is the second onStartInputView after orientation changed.
|
|
|
|
resetPendingImsCallback();
|
|
|
|
} else {
|
2012-01-24 02:58:07 +00:00
|
|
|
if (mPendingSuccessiveImsCallback) {
|
2011-11-21 22:58:32 +00:00
|
|
|
// This is the first onStartInputView after orientation changed.
|
2012-01-24 02:58:07 +00:00
|
|
|
mPendingSuccessiveImsCallback = false;
|
2011-11-21 22:58:32 +00:00
|
|
|
resetPendingImsCallback();
|
|
|
|
sendMessageDelayed(obtainMessage(MSG_PENDING_IMS_CALLBACK),
|
|
|
|
PENDING_IMS_CALLBACK_DURATION);
|
|
|
|
}
|
|
|
|
final LatinIME latinIme = getOuterInstance();
|
|
|
|
executePendingImsCallback(latinIme, editorInfo, restarting);
|
|
|
|
latinIme.onStartInputViewInternal(editorInfo, restarting);
|
|
|
|
mAppliedEditorInfo = editorInfo;
|
|
|
|
}
|
2011-09-29 08:27:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void onFinishInputView(boolean finishingInput) {
|
|
|
|
if (hasMessages(MSG_PENDING_IMS_CALLBACK)) {
|
|
|
|
// Typically this is the first onFinishInputView after orientation changed.
|
|
|
|
mHasPendingFinishInputView = true;
|
|
|
|
} else {
|
|
|
|
final LatinIME latinIme = getOuterInstance();
|
|
|
|
latinIme.onFinishInputViewInternal(finishingInput);
|
2011-11-21 22:58:32 +00:00
|
|
|
mAppliedEditorInfo = null;
|
2011-07-21 06:57:00 +00:00
|
|
|
}
|
|
|
|
}
|
2011-09-27 09:47:54 +00:00
|
|
|
|
2011-09-29 08:27:48 +00:00
|
|
|
public void onFinishInput() {
|
|
|
|
if (hasMessages(MSG_PENDING_IMS_CALLBACK)) {
|
|
|
|
// Typically this is the first onFinishInput after orientation changed.
|
|
|
|
mHasPendingFinishInput = true;
|
|
|
|
} else {
|
|
|
|
final LatinIME latinIme = getOuterInstance();
|
|
|
|
executePendingImsCallback(latinIme, null, false);
|
|
|
|
latinIme.onFinishInputInternal();
|
2011-09-27 09:47:54 +00:00
|
|
|
}
|
|
|
|
}
|
2011-07-21 06:57:00 +00:00
|
|
|
}
|
|
|
|
|
2012-03-06 10:06:58 +00:00
|
|
|
public LatinIME() {
|
|
|
|
super();
|
|
|
|
mSubtypeSwitcher = SubtypeSwitcher.getInstance();
|
|
|
|
mKeyboardSwitcher = KeyboardSwitcher.getInstance();
|
|
|
|
}
|
|
|
|
|
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);
|
2012-03-26 13:10:21 +00:00
|
|
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
2012-06-29 14:02:39 +00:00
|
|
|
ResearchLogger.getInstance().init(this, prefs, mKeyboardSwitcher);
|
2012-03-26 13:10:21 +00:00
|
|
|
}
|
2011-07-18 04:18:47 +00:00
|
|
|
InputMethodManagerCompatWrapper.init(this);
|
2011-07-17 22:23:52 +00:00
|
|
|
SubtypeSwitcher.init(this);
|
2010-11-26 04:08:36 +00:00
|
|
|
KeyboardSwitcher.init(this, prefs);
|
2011-12-15 10:32:11 +00:00
|
|
|
AccessibilityUtils.init(this);
|
2010-12-23 03:24:27 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
super.onCreate();
|
2010-12-23 03:24:27 +00:00
|
|
|
|
2011-07-18 04:18:47 +00:00
|
|
|
mImm = InputMethodManagerCompatWrapper.getInstance();
|
2011-11-18 05:45:49 +00:00
|
|
|
mHandler.onCreate();
|
2011-05-27 12:41:13 +00:00
|
|
|
DEBUG = LatinImeLogger.sDBG;
|
2010-12-23 03:24:27 +00:00
|
|
|
|
|
|
|
final Resources res = getResources();
|
|
|
|
mResources = res;
|
2011-01-18 08:45:22 +00:00
|
|
|
|
2011-09-19 05:51:31 +00:00
|
|
|
loadSettings();
|
|
|
|
|
2012-06-08 12:34:07 +00:00
|
|
|
ImfUtils.setAdditionalInputMethodSubtypes(this, mCurrentSettings.getAdditionalSubtypes());
|
2012-04-11 09:21:10 +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;
|
2012-06-08 13:21:20 +00:00
|
|
|
// Shouldn't this be removed? I think that from Honeycomb on, the GC is now actually working
|
|
|
|
// as expected and this code is useless.
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-23 05:58:45 +00:00
|
|
|
mDisplayOrientation = res.getConfiguration().orientation;
|
2009-07-21 22:47:11 +00:00
|
|
|
|
2011-03-14 18:46:15 +00:00
|
|
|
// Register to receive ringer mode change and network state change.
|
|
|
|
// Also receive installation and removal of a dictionary pack.
|
2011-01-26 14:13:18 +00:00
|
|
|
final IntentFilter filter = new IntentFilter();
|
|
|
|
filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
|
2012-03-09 02:00:23 +00:00
|
|
|
filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);
|
2009-03-13 22:11:42 +00:00
|
|
|
registerReceiver(mReceiver, filter);
|
2011-03-14 18:46:15 +00:00
|
|
|
|
|
|
|
final IntentFilter packageFilter = new IntentFilter();
|
|
|
|
packageFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
|
|
|
|
packageFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
|
|
|
|
packageFilter.addDataScheme(SCHEME_PACKAGE);
|
|
|
|
registerReceiver(mDictionaryPackInstallReceiver, packageFilter);
|
2011-04-14 11:45:47 +00:00
|
|
|
|
|
|
|
final IntentFilter newDictFilter = new IntentFilter();
|
|
|
|
newDictFilter.addAction(
|
|
|
|
DictionaryPackInstallBroadcastReceiver.NEW_DICTIONARY_INTENT_ACTION);
|
|
|
|
registerReceiver(mDictionaryPackInstallReceiver, newDictFilter);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2009-10-12 20:48:35 +00:00
|
|
|
|
2011-05-10 06:51:43 +00:00
|
|
|
// Has to be package-visible for unit tests
|
|
|
|
/* package */ void loadSettings() {
|
2012-06-01 02:22:39 +00:00
|
|
|
// Note that the calling sequence of onCreate() and onCurrentInputMethodSubtypeChanged()
|
|
|
|
// is not guaranteed. It may even be called at the same time on a different thread.
|
2011-05-10 06:51:43 +00:00
|
|
|
if (null == mPrefs) mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
|
2012-06-16 00:57:46 +00:00
|
|
|
final InputAttributes inputAttributes =
|
|
|
|
new InputAttributes(getCurrentInputEditorInfo(), isFullscreenMode());
|
2012-04-03 05:28:56 +00:00
|
|
|
final RunInLocale<SettingsValues> job = new RunInLocale<SettingsValues>() {
|
|
|
|
@Override
|
|
|
|
protected SettingsValues job(Resources res) {
|
2012-06-16 00:57:46 +00:00
|
|
|
return new SettingsValues(mPrefs, inputAttributes, LatinIME.this);
|
2012-04-03 05:28:56 +00:00
|
|
|
}
|
|
|
|
};
|
2012-06-08 12:34:07 +00:00
|
|
|
mCurrentSettings = job.runInLocale(mResources, mSubtypeSwitcher.getCurrentSubtypeLocale());
|
|
|
|
mFeedbackManager = new AudioAndHapticFeedbackManager(this, mCurrentSettings);
|
2011-08-09 02:54:10 +00:00
|
|
|
resetContactsDictionary(null == mSuggest ? null : mSuggest.getContactsDictionary());
|
2011-05-10 06:51:43 +00:00
|
|
|
}
|
|
|
|
|
2012-07-24 06:56:25 +00:00
|
|
|
@Override
|
|
|
|
public void onUpdateMainDictionaryAvailability(boolean isMainDictionaryAvailable) {
|
|
|
|
mIsMainDictionaryAvailable = isMainDictionaryAvailable;
|
2012-07-23 05:59:19 +00:00
|
|
|
updateKeyboardViewGestureHandlingModeByMainDictionaryAvailability();
|
2012-07-24 06:56:25 +00:00
|
|
|
}
|
|
|
|
|
2010-11-17 07:35:35 +00:00
|
|
|
private void initSuggest() {
|
2012-04-19 14:11:31 +00:00
|
|
|
final Locale subtypeLocale = mSubtypeSwitcher.getCurrentSubtypeLocale();
|
|
|
|
final String localeStr = subtypeLocale.toString();
|
2009-10-12 20:48:35 +00:00
|
|
|
|
2012-06-08 08:01:35 +00:00
|
|
|
final ContactsBinaryDictionary oldContactsDictionary;
|
2012-04-11 05:58:02 +00:00
|
|
|
if (mSuggest != null) {
|
|
|
|
oldContactsDictionary = mSuggest.getContactsDictionary();
|
|
|
|
mSuggest.close();
|
|
|
|
} else {
|
|
|
|
oldContactsDictionary = null;
|
|
|
|
}
|
2012-07-24 06:56:25 +00:00
|
|
|
mSuggest = new Suggest(this /* Context */, subtypeLocale,
|
|
|
|
this /* SuggestInitializationListener */);
|
2012-06-16 02:03:22 +00:00
|
|
|
if (mCurrentSettings.mCorrectionEnabled) {
|
2012-06-08 12:34:07 +00:00
|
|
|
mSuggest.setAutoCorrectionThreshold(mCurrentSettings.mAutoCorrectionThreshold);
|
2012-04-11 05:58:02 +00:00
|
|
|
}
|
2011-01-07 06:01:51 +00:00
|
|
|
|
2012-04-19 14:11:31 +00:00
|
|
|
mIsMainDictionaryAvailable = DictionaryFactory.isDictionaryAvailable(this, subtypeLocale);
|
2012-06-16 00:49:42 +00:00
|
|
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
|
|
|
ResearchLogger.getInstance().initSuggest(mSuggest);
|
|
|
|
}
|
2012-04-19 14:11:31 +00:00
|
|
|
|
2012-06-08 08:01:35 +00:00
|
|
|
mUserDictionary = new UserBinaryDictionary(this, localeStr);
|
|
|
|
mIsUserDictionaryAvailable = mUserDictionary.isEnabled();
|
2012-04-11 05:58:02 +00:00
|
|
|
mSuggest.setUserDictionary(mUserDictionary);
|
2011-01-07 06:01:51 +00:00
|
|
|
|
2012-04-11 05:58:02 +00:00
|
|
|
resetContactsDictionary(oldContactsDictionary);
|
2011-01-07 06:01:51 +00:00
|
|
|
|
2012-06-01 02:22:39 +00:00
|
|
|
// Note that the calling sequence of onCreate() and onCurrentInputMethodSubtypeChanged()
|
|
|
|
// is not guaranteed. It may even be called at the same time on a different thread.
|
|
|
|
if (null == mPrefs) mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
|
2012-06-27 08:44:16 +00:00
|
|
|
mUserHistoryDictionary = UserHistoryDictionary.getInstance(this, localeStr, mPrefs);
|
2012-04-11 05:58:02 +00:00
|
|
|
mSuggest.setUserHistoryDictionary(mUserHistoryDictionary);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2009-10-12 20:48:35 +00:00
|
|
|
|
2011-08-09 02:54:10 +00:00
|
|
|
/**
|
|
|
|
* Resets the contacts dictionary in mSuggest according to the user settings.
|
|
|
|
*
|
2012-06-06 04:29:14 +00:00
|
|
|
* This method takes an optional contacts dictionary to use when the locale hasn't changed
|
|
|
|
* since the contacts dictionary can be opened or closed as necessary depending on the settings.
|
2011-08-09 02:54:10 +00:00
|
|
|
*
|
|
|
|
* @param oldContactsDictionary an optional dictionary to use, or null
|
|
|
|
*/
|
2012-06-08 08:01:35 +00:00
|
|
|
private void resetContactsDictionary(final ContactsBinaryDictionary oldContactsDictionary) {
|
2012-06-08 12:34:07 +00:00
|
|
|
final boolean shouldSetDictionary = (null != mSuggest && mCurrentSettings.mUseContactsDict);
|
2011-08-09 02:54:10 +00:00
|
|
|
|
2012-06-08 08:01:35 +00:00
|
|
|
final ContactsBinaryDictionary dictionaryToUse;
|
2011-08-09 02:54:10 +00:00
|
|
|
if (!shouldSetDictionary) {
|
|
|
|
// Make sure the dictionary is closed. If it is already closed, this is a no-op,
|
|
|
|
// so it's safe to call it anyways.
|
|
|
|
if (null != oldContactsDictionary) oldContactsDictionary.close();
|
|
|
|
dictionaryToUse = null;
|
|
|
|
} else {
|
2012-06-06 04:29:14 +00:00
|
|
|
final Locale locale = mSubtypeSwitcher.getCurrentSubtypeLocale();
|
|
|
|
if (null != oldContactsDictionary) {
|
2012-06-08 08:01:35 +00:00
|
|
|
if (!oldContactsDictionary.mLocale.equals(locale)) {
|
|
|
|
// If the locale has changed then recreate the contacts dictionary. This
|
|
|
|
// allows locale dependent rules for handling bigram name predictions.
|
|
|
|
oldContactsDictionary.close();
|
2012-06-27 08:31:09 +00:00
|
|
|
dictionaryToUse = new ContactsBinaryDictionary(this, locale);
|
2012-06-06 04:29:14 +00:00
|
|
|
} else {
|
2012-06-08 08:01:35 +00:00
|
|
|
// Make sure the old contacts dictionary is opened. If it is already open,
|
|
|
|
// this is a no-op, so it's safe to call it anyways.
|
|
|
|
oldContactsDictionary.reopen(this);
|
2012-06-06 04:29:14 +00:00
|
|
|
dictionaryToUse = oldContactsDictionary;
|
|
|
|
}
|
2012-03-26 13:31:20 +00:00
|
|
|
} else {
|
2012-06-27 08:31:09 +00:00
|
|
|
dictionaryToUse = new ContactsBinaryDictionary(this, locale);
|
2012-03-26 13:31:20 +00:00
|
|
|
}
|
2011-08-09 02:54:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (null != mSuggest) {
|
|
|
|
mSuggest.setContactsDictionary(dictionaryToUse);
|
|
|
|
}
|
2011-06-10 09:16:21 +00:00
|
|
|
}
|
|
|
|
|
2011-03-14 18:46:15 +00:00
|
|
|
/* package private */ void resetSuggestMainDict() {
|
2012-04-19 14:11:31 +00:00
|
|
|
final Locale subtypeLocale = mSubtypeSwitcher.getCurrentSubtypeLocale();
|
|
|
|
mSuggest.resetMainDict(this, subtypeLocale);
|
|
|
|
mIsMainDictionaryAvailable = DictionaryFactory.isDictionaryAvailable(this, subtypeLocale);
|
2011-03-14 18:46:15 +00:00
|
|
|
}
|
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
@Override
|
|
|
|
public void onDestroy() {
|
2011-01-07 06:01:51 +00:00
|
|
|
if (mSuggest != null) {
|
|
|
|
mSuggest.close();
|
|
|
|
mSuggest = null;
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
unregisterReceiver(mReceiver);
|
2011-03-14 18:46:15 +00:00
|
|
|
unregisterReceiver(mDictionaryPackInstallReceiver);
|
2010-08-20 05:35:02 +00:00
|
|
|
LatinImeLogger.commit();
|
|
|
|
LatinImeLogger.onDestroy();
|
2009-03-13 22:11:42 +00:00
|
|
|
super.onDestroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onConfigurationChanged(Configuration conf) {
|
2011-01-17 08:52:15 +00:00
|
|
|
mSubtypeSwitcher.onConfigurationChanged(conf);
|
2009-07-21 22:47:11 +00:00
|
|
|
// If orientation changed while predicting, commit the change
|
2011-08-23 05:58:45 +00:00
|
|
|
if (mDisplayOrientation != conf.orientation) {
|
|
|
|
mDisplayOrientation = conf.orientation;
|
|
|
|
mHandler.startOrientationChanging();
|
2012-07-05 03:36:06 +00:00
|
|
|
mConnection.beginBatchEdit();
|
2012-06-08 10:04:09 +00:00
|
|
|
commitTyped(LastComposedWord.NOT_A_SEPARATOR);
|
|
|
|
mConnection.finishComposingText();
|
|
|
|
mConnection.endBatchEdit();
|
2011-01-20 13:52:02 +00:00
|
|
|
if (isShowingOptionDialog())
|
|
|
|
mOptionsDialog.dismiss();
|
2009-07-21 22:47:11 +00:00
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
super.onConfigurationChanged(conf);
|
|
|
|
}
|
2009-07-21 22:47:11 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
@Override
|
|
|
|
public View onCreateInputView() {
|
2011-05-25 09:28:03 +00:00
|
|
|
return mKeyboardSwitcher.onCreateInputView();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setInputView(View view) {
|
|
|
|
super.setInputView(view);
|
2011-10-12 09:50:51 +00:00
|
|
|
mExtractArea = getWindow().getWindow().getDecorView()
|
|
|
|
.findViewById(android.R.id.extractArea);
|
2011-09-02 12:03:18 +00:00
|
|
|
mKeyPreviewBackingView = view.findViewById(R.id.key_preview_backing);
|
2011-09-01 05:54:28 +00:00
|
|
|
mSuggestionsContainer = view.findViewById(R.id.suggestions_container);
|
2012-07-23 06:28:28 +00:00
|
|
|
mSuggestionStripView = (SuggestionStripView)view.findViewById(R.id.suggestion_strip_view);
|
|
|
|
if (mSuggestionStripView != null)
|
|
|
|
mSuggestionStripView.setListener(this, view);
|
2011-09-21 01:41:31 +00:00
|
|
|
if (LatinImeLogger.sVISUALDEBUG) {
|
|
|
|
mKeyPreviewBackingView.setBackgroundColor(0x10FF0000);
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2011-05-23 09:30:21 +00:00
|
|
|
public void setCandidatesView(View view) {
|
|
|
|
// To ensure that CandidatesView will never be set.
|
|
|
|
return;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 08:27:48 +00:00
|
|
|
@Override
|
2011-11-21 22:58:32 +00:00
|
|
|
public void onStartInput(EditorInfo editorInfo, boolean restarting) {
|
|
|
|
mHandler.onStartInput(editorInfo, restarting);
|
2011-09-29 08:27:48 +00:00
|
|
|
}
|
|
|
|
|
2010-01-28 18:09:44 +00:00
|
|
|
@Override
|
2011-11-21 22:58:32 +00:00
|
|
|
public void onStartInputView(EditorInfo editorInfo, boolean restarting) {
|
|
|
|
mHandler.onStartInputView(editorInfo, restarting);
|
2011-09-29 08:27:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFinishInputView(boolean finishingInput) {
|
|
|
|
mHandler.onFinishInputView(finishingInput);
|
|
|
|
}
|
2011-07-21 06:57:00 +00:00
|
|
|
|
2011-09-29 08:27:48 +00:00
|
|
|
@Override
|
|
|
|
public void onFinishInput() {
|
|
|
|
mHandler.onFinishInput();
|
|
|
|
}
|
|
|
|
|
2012-04-02 12:31:52 +00:00
|
|
|
@Override
|
|
|
|
public void onCurrentInputMethodSubtypeChanged(InputMethodSubtype subtype) {
|
2012-06-01 02:22:39 +00:00
|
|
|
// Note that the calling sequence of onCreate() and onCurrentInputMethodSubtypeChanged()
|
|
|
|
// is not guaranteed. It may even be called at the same time on a different thread.
|
2012-04-19 14:11:31 +00:00
|
|
|
mSubtypeSwitcher.updateSubtype(subtype);
|
2012-04-02 12:31:52 +00:00
|
|
|
}
|
|
|
|
|
2011-11-21 22:58:32 +00:00
|
|
|
private void onStartInputInternal(EditorInfo editorInfo, boolean restarting) {
|
|
|
|
super.onStartInput(editorInfo, restarting);
|
2011-09-29 08:27:48 +00:00
|
|
|
}
|
|
|
|
|
2012-04-19 03:42:13 +00:00
|
|
|
@SuppressWarnings("deprecation")
|
2011-11-21 22:58:32 +00:00
|
|
|
private void onStartInputViewInternal(EditorInfo editorInfo, boolean restarting) {
|
|
|
|
super.onStartInputView(editorInfo, restarting);
|
2010-11-12 23:49:56 +00:00
|
|
|
final KeyboardSwitcher switcher = mKeyboardSwitcher;
|
2012-07-23 01:27:14 +00:00
|
|
|
MainKeyboardView inputView = switcher.getKeyboardView();
|
2010-11-21 03:43:10 +00:00
|
|
|
|
2012-03-06 05:56:46 +00:00
|
|
|
if (editorInfo == null) {
|
|
|
|
Log.e(TAG, "Null EditorInfo in onStartInputView()");
|
|
|
|
if (LatinImeLogger.sDBG) {
|
|
|
|
throw new NullPointerException("Null EditorInfo in onStartInputView()");
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2011-04-20 02:50:05 +00:00
|
|
|
if (DEBUG) {
|
2012-03-06 05:56:46 +00:00
|
|
|
Log.d(TAG, "onStartInputView: editorInfo:"
|
|
|
|
+ String.format("inputType=0x%08x imeOptions=0x%08x",
|
|
|
|
editorInfo.inputType, editorInfo.imeOptions));
|
2012-05-11 07:52:22 +00:00
|
|
|
Log.d(TAG, "All caps = "
|
|
|
|
+ ((editorInfo.inputType & InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS) != 0)
|
|
|
|
+ ", sentence caps = "
|
|
|
|
+ ((editorInfo.inputType & InputType.TYPE_TEXT_FLAG_CAP_SENTENCES) != 0)
|
|
|
|
+ ", word caps = "
|
|
|
|
+ ((editorInfo.inputType & InputType.TYPE_TEXT_FLAG_CAP_WORDS) != 0));
|
2011-01-22 20:46:30 +00:00
|
|
|
}
|
2012-03-30 20:15:46 +00:00
|
|
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
2012-04-18 03:54:33 +00:00
|
|
|
ResearchLogger.latinIME_onStartInputViewInternal(editorInfo, mPrefs);
|
2012-03-30 20:15:46 +00:00
|
|
|
}
|
2012-04-19 03:42:13 +00:00
|
|
|
if (InputAttributes.inPrivateImeOptions(null, NO_MICROPHONE_COMPAT, editorInfo)) {
|
2012-01-25 11:54:00 +00:00
|
|
|
Log.w(TAG, "Deprecated private IME option specified: "
|
|
|
|
+ editorInfo.privateImeOptions);
|
2012-04-19 03:42:13 +00:00
|
|
|
Log.w(TAG, "Use " + getPackageName() + "." + NO_MICROPHONE + " instead");
|
2012-01-25 11:54:00 +00:00
|
|
|
}
|
2012-04-19 03:42:13 +00:00
|
|
|
if (InputAttributes.inPrivateImeOptions(getPackageName(), FORCE_ASCII, editorInfo)) {
|
2012-01-25 11:54:00 +00:00
|
|
|
Log.w(TAG, "Deprecated private IME option specified: "
|
|
|
|
+ editorInfo.privateImeOptions);
|
|
|
|
Log.w(TAG, "Use EditorInfo.IME_FLAG_FORCE_ASCII flag instead");
|
|
|
|
}
|
|
|
|
|
2012-05-25 09:19:19 +00:00
|
|
|
mTargetApplicationInfo =
|
|
|
|
TargetApplicationGetter.getCachedApplicationInfo(editorInfo.packageName);
|
|
|
|
if (null == mTargetApplicationInfo) {
|
|
|
|
new TargetApplicationGetter(this /* context */, this /* listener */)
|
|
|
|
.execute(editorInfo.packageName);
|
|
|
|
}
|
2012-05-25 09:07:52 +00:00
|
|
|
|
2011-12-14 05:53:28 +00:00
|
|
|
LatinImeLogger.onStartInputView(editorInfo);
|
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;
|
|
|
|
}
|
|
|
|
|
2011-10-05 23:59:31 +00:00
|
|
|
// Forward this event to the accessibility utilities, if enabled.
|
|
|
|
final AccessibilityUtils accessUtils = AccessibilityUtils.getInstance();
|
|
|
|
if (accessUtils.isTouchExplorationEnabled()) {
|
2011-11-21 22:58:32 +00:00
|
|
|
accessUtils.onStartInputViewInternal(editorInfo, restarting);
|
2011-10-05 23:59:31 +00:00
|
|
|
}
|
|
|
|
|
2012-07-25 10:31:19 +00:00
|
|
|
if (!restarting) {
|
|
|
|
mSubtypeSwitcher.updateParametersOnStartInputView();
|
|
|
|
}
|
2010-11-18 00:55:23 +00:00
|
|
|
|
2011-10-24 06:26:53 +00:00
|
|
|
// The EditorInfo might have a flag that affects fullscreen mode.
|
|
|
|
// Note: This call should be done by InputMethodService?
|
|
|
|
updateFullscreenMode();
|
2011-12-16 05:01:42 +00:00
|
|
|
mApplicationSpecifiedCompletions = null;
|
2011-01-18 06:28:21 +00:00
|
|
|
|
2012-07-25 10:31:19 +00:00
|
|
|
final boolean selectionChanged = mLastSelectionStart != editorInfo.initialSelStart
|
|
|
|
|| mLastSelectionEnd != editorInfo.initialSelEnd;
|
|
|
|
if (!restarting || selectionChanged) {
|
|
|
|
// If the selection changed, we reset the input state. Essentially, we come here with
|
|
|
|
// restarting == true when the app called setText() or similar. We should reset the
|
|
|
|
// state if the app set the text to something else, but keep it if it set a suggestion
|
|
|
|
// or something.
|
|
|
|
mEnteredText = null;
|
|
|
|
resetComposingState(true /* alsoResetLastComposedWord */);
|
|
|
|
mDeleteCount = 0;
|
|
|
|
mSpaceState = SPACE_STATE_NONE;
|
|
|
|
|
|
|
|
if (mSuggestionStripView != null) {
|
|
|
|
mSuggestionStripView.clear();
|
|
|
|
}
|
2011-11-15 17:11:11 +00:00
|
|
|
}
|
2011-05-10 06:51:43 +00:00
|
|
|
|
2012-07-25 10:31:19 +00:00
|
|
|
if (!restarting) {
|
|
|
|
inputView.closing();
|
|
|
|
loadSettings();
|
2011-01-18 06:28:21 +00:00
|
|
|
|
2012-07-25 10:31:19 +00:00
|
|
|
if (mSuggest != null && mCurrentSettings.mCorrectionEnabled) {
|
|
|
|
mSuggest.setAutoCorrectionThreshold(mCurrentSettings.mAutoCorrectionThreshold);
|
|
|
|
}
|
|
|
|
|
|
|
|
switcher.loadKeyboard(editorInfo, mCurrentSettings);
|
|
|
|
updateKeyboardViewGestureHandlingModeByMainDictionaryAvailability();
|
|
|
|
}
|
2011-09-01 05:54:28 +00:00
|
|
|
setSuggestionStripShownInternal(
|
|
|
|
isSuggestionsStripVisible(), /* needsInputViewShown */ false);
|
2012-07-05 06:26:43 +00:00
|
|
|
|
2012-07-25 10:31:19 +00:00
|
|
|
mLastSelectionStart = editorInfo.initialSelStart;
|
|
|
|
mLastSelectionEnd = editorInfo.initialSelEnd;
|
2012-07-26 18:45:42 +00:00
|
|
|
// If we come here something in the text state is very likely to have changed.
|
|
|
|
// We should update the shift state regardless of whether we are restarting or not, because
|
|
|
|
// this is not perceived as a layout change that may be disruptive like we may have with
|
|
|
|
// switcher.loadKeyboard; in apps like Talk, we come here when the text is sent and the
|
|
|
|
// field gets emptied and we need to re-evaluate the shift state, but not the whole layout
|
|
|
|
// which would be disruptive.
|
|
|
|
mKeyboardSwitcher.updateShiftState();
|
2012-07-25 10:31:19 +00:00
|
|
|
|
2012-07-05 06:26:43 +00:00
|
|
|
mHandler.cancelUpdateSuggestionStrip();
|
2011-11-14 09:59:17 +00:00
|
|
|
mHandler.cancelDoubleSpacesTimer();
|
2011-01-18 06:28:21 +00:00
|
|
|
|
2012-06-08 12:34:07 +00:00
|
|
|
inputView.setKeyPreviewPopupEnabled(mCurrentSettings.mKeyPreviewPopupOn,
|
|
|
|
mCurrentSettings.mKeyPreviewPopupDismissDelay);
|
2011-01-18 06:28:21 +00:00
|
|
|
|
|
|
|
if (TRACE) Debug.startMethodTracing("/data/trace/latinime");
|
|
|
|
}
|
|
|
|
|
2012-07-09 03:54:42 +00:00
|
|
|
// Callback for the TargetApplicationGetter
|
2012-06-08 07:00:02 +00:00
|
|
|
@Override
|
2012-05-25 09:07:52 +00:00
|
|
|
public void onTargetApplicationKnown(final ApplicationInfo info) {
|
|
|
|
mTargetApplicationInfo = info;
|
|
|
|
}
|
|
|
|
|
2011-05-17 10:02:32 +00:00
|
|
|
@Override
|
|
|
|
public void onWindowHidden() {
|
2012-05-02 05:09:53 +00:00
|
|
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
|
|
|
ResearchLogger.latinIME_onWindowHidden(mLastSelectionStart, mLastSelectionEnd,
|
|
|
|
getCurrentInputConnection());
|
|
|
|
}
|
2011-05-17 10:02:32 +00:00
|
|
|
super.onWindowHidden();
|
2011-07-04 11:58:58 +00:00
|
|
|
KeyboardView inputView = mKeyboardSwitcher.getKeyboardView();
|
2011-05-17 10:02:32 +00:00
|
|
|
if (inputView != null) inputView.closing();
|
|
|
|
}
|
|
|
|
|
2011-09-29 08:27:48 +00:00
|
|
|
private void onFinishInputInternal() {
|
2009-03-13 22:11:42 +00:00
|
|
|
super.onFinishInput();
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-08-20 05:35:02 +00:00
|
|
|
LatinImeLogger.commit();
|
2012-05-14 16:41:39 +00:00
|
|
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
2012-07-18 20:52:41 +00:00
|
|
|
ResearchLogger.getInstance().latinIME_onFinishInputInternal();
|
2012-05-14 16:41:39 +00:00
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
|
2011-07-04 11:58:58 +00:00
|
|
|
KeyboardView inputView = mKeyboardSwitcher.getKeyboardView();
|
2010-12-03 10:40:31 +00:00
|
|
|
if (inputView != null) inputView.closing();
|
2010-01-16 20:21:23 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 08:27:48 +00:00
|
|
|
private void onFinishInputViewInternal(boolean finishingInput) {
|
2010-10-06 09:39:47 +00:00
|
|
|
super.onFinishInputView(finishingInput);
|
2011-07-29 17:45:37 +00:00
|
|
|
mKeyboardSwitcher.onFinishInputView();
|
2011-07-04 11:58:58 +00:00
|
|
|
KeyboardView inputView = mKeyboardSwitcher.getKeyboardView();
|
2011-07-01 04:07:59 +00:00
|
|
|
if (inputView != null) inputView.cancelAllMessages();
|
2010-11-16 09:07:06 +00:00
|
|
|
// Remove pending messages related to update suggestions
|
2012-07-05 02:34:48 +00:00
|
|
|
mHandler.cancelUpdateSuggestionStrip();
|
2010-10-06 09:39:47 +00:00
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
@Override
|
|
|
|
public void onUpdateSelection(int oldSelStart, int oldSelEnd,
|
|
|
|
int newSelStart, int newSelEnd,
|
2012-02-20 01:26:41 +00:00
|
|
|
int composingSpanStart, int composingSpanEnd) {
|
2009-03-13 22:11:42 +00:00
|
|
|
super.onUpdateSelection(oldSelStart, oldSelEnd, newSelStart, newSelEnd,
|
2012-02-20 01:26:41 +00:00
|
|
|
composingSpanStart, composingSpanEnd);
|
2010-01-16 20:21:23 +00:00
|
|
|
if (DEBUG) {
|
|
|
|
Log.i(TAG, "onUpdateSelection: oss=" + oldSelStart
|
|
|
|
+ ", ose=" + oldSelEnd
|
2011-02-25 09:11:18 +00:00
|
|
|
+ ", lss=" + mLastSelectionStart
|
|
|
|
+ ", lse=" + mLastSelectionEnd
|
2010-01-16 20:21:23 +00:00
|
|
|
+ ", nss=" + newSelStart
|
|
|
|
+ ", nse=" + newSelEnd
|
2012-02-20 01:26:41 +00:00
|
|
|
+ ", cs=" + composingSpanStart
|
|
|
|
+ ", ce=" + composingSpanEnd);
|
2010-01-16 20:21:23 +00:00
|
|
|
}
|
2012-03-30 20:15:46 +00:00
|
|
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
2012-05-02 05:09:53 +00:00
|
|
|
final boolean expectingUpdateSelectionFromLogger =
|
|
|
|
ResearchLogger.getAndClearLatinIMEExpectingUpdateSelection();
|
2012-03-30 20:15:46 +00:00
|
|
|
ResearchLogger.latinIME_onUpdateSelection(mLastSelectionStart, mLastSelectionEnd,
|
|
|
|
oldSelStart, oldSelEnd, newSelStart, newSelEnd, composingSpanStart,
|
2012-05-02 05:09:53 +00:00
|
|
|
composingSpanEnd, mExpectingUpdateSelection,
|
2012-06-08 10:44:38 +00:00
|
|
|
expectingUpdateSelectionFromLogger, mConnection);
|
2012-05-02 05:09:53 +00:00
|
|
|
if (expectingUpdateSelectionFromLogger) {
|
2012-06-08 13:21:20 +00:00
|
|
|
// TODO: Investigate. Quitting now sounds wrong - we won't do the resetting work
|
2012-05-02 05:09:53 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-03-30 20:15:46 +00:00
|
|
|
}
|
2010-01-16 20:21:23 +00:00
|
|
|
|
2012-02-20 01:26:41 +00:00
|
|
|
// TODO: refactor the following code to be less contrived.
|
|
|
|
// "newSelStart != composingSpanEnd" || "newSelEnd != composingSpanEnd" means
|
|
|
|
// that the cursor is not at the end of the composing span, or there is a selection.
|
|
|
|
// "mLastSelectionStart != newSelStart" means that the cursor is not in the same place
|
|
|
|
// as last time we were called (if there is a selection, it means the start hasn't
|
|
|
|
// changed, so it's the end that did).
|
|
|
|
final boolean selectionChanged = (newSelStart != composingSpanEnd
|
|
|
|
|| newSelEnd != composingSpanEnd) && mLastSelectionStart != newSelStart;
|
|
|
|
// if composingSpanStart and composingSpanEnd are -1, it means there is no composing
|
|
|
|
// span in the view - we can use that to narrow down whether the cursor was moved
|
|
|
|
// by us or not. If we are composing a word but there is no composing span, then
|
|
|
|
// we know for sure the cursor moved while we were composing and we should reset
|
|
|
|
// the state.
|
|
|
|
final boolean noComposingSpan = composingSpanStart == -1 && composingSpanEnd == -1;
|
2011-06-08 07:47:19 +00:00
|
|
|
if (!mExpectingUpdateSelection) {
|
2012-01-12 02:01:01 +00:00
|
|
|
// TAKE CARE: there is a race condition when we enter this test even when the user
|
|
|
|
// did not explicitly move the cursor. This happens when typing fast, where two keys
|
|
|
|
// turn this flag on in succession and both onUpdateSelection() calls arrive after
|
|
|
|
// the second one - the first call successfully avoids this test, but the second one
|
2012-02-20 01:26:41 +00:00
|
|
|
// enters. For the moment we rely on noComposingSpan to further reduce the impact.
|
2012-02-02 05:51:25 +00:00
|
|
|
|
2012-02-20 02:17:35 +00:00
|
|
|
// TODO: the following is probably better done in resetEntireInputState().
|
|
|
|
// it should only happen when the cursor moved, and the very purpose of the
|
|
|
|
// test below is to narrow down whether this happened or not. Likewise with
|
|
|
|
// the call to postUpdateShiftState.
|
2012-02-02 05:51:25 +00:00
|
|
|
// We set this to NONE because after a cursor move, we don't want the space
|
|
|
|
// state-related special processing to kick in.
|
|
|
|
mSpaceState = SPACE_STATE_NONE;
|
|
|
|
|
2012-02-22 00:52:39 +00:00
|
|
|
if ((!mWordComposer.isComposingWord()) || selectionChanged || noComposingSpan) {
|
2012-02-20 02:08:40 +00:00
|
|
|
resetEntireInputState();
|
2011-10-03 05:58:34 +00:00
|
|
|
}
|
2012-02-16 19:45:35 +00:00
|
|
|
|
|
|
|
mHandler.postUpdateShiftState();
|
2011-06-08 07:47:19 +00:00
|
|
|
}
|
|
|
|
mExpectingUpdateSelection = false;
|
2011-11-22 02:35:40 +00:00
|
|
|
// TODO: Decide to call restartSuggestionsOnWordBeforeCursorIfAtEndOfWord() or not
|
|
|
|
// here. It would probably be too expensive to call directly here but we may want to post a
|
|
|
|
// message to delay it. The point would be to unify behavior between backspace to the
|
|
|
|
// end of a word and manually put the pointer at the end of the word.
|
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;
|
2011-05-06 09:27:24 +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
|
2011-09-01 05:54:28 +00:00
|
|
|
* the suggestions view when this happens, but only if the extracted text
|
2010-09-15 04:03:34 +00:00
|
|
|
* 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
|
2011-09-01 05:54:28 +00:00
|
|
|
* cause the suggestions strip to disappear and re-appear.
|
2010-09-15 04:03:34 +00:00
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public void onExtractedTextClicked() {
|
2012-06-12 01:00:07 +00:00
|
|
|
if (mCurrentSettings.isSuggestionsRequested(mDisplayOrientation)) return;
|
2010-09-15 04:03:34 +00:00
|
|
|
|
|
|
|
super.onExtractedTextClicked();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is called when the user has performed a cursor movement in the
|
|
|
|
* extracted text view, when it is running in fullscreen mode. The default
|
2011-09-01 05:54:28 +00:00
|
|
|
* implementation hides the suggestions view when a vertical movement
|
2010-09-15 04:03:34 +00:00
|
|
|
* 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
|
2011-09-01 05:54:28 +00:00
|
|
|
* cause the suggestions strip to disappear and re-appear.
|
2010-09-15 04:03:34 +00:00
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public void onExtractedCursorMovement(int dx, int dy) {
|
2012-06-12 01:00:07 +00:00
|
|
|
if (mCurrentSettings.isSuggestionsRequested(mDisplayOrientation)) return;
|
2010-09-15 04:03:34 +00:00
|
|
|
|
|
|
|
super.onExtractedCursorMovement(dx, dy);
|
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
@Override
|
|
|
|
public void hideWindow() {
|
2010-08-20 05:35:02 +00:00
|
|
|
LatinImeLogger.commit();
|
2011-07-27 22:32:25 +00:00
|
|
|
mKeyboardSwitcher.onHideWindow();
|
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;
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
super.hideWindow();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2010-12-11 08:06:24 +00:00
|
|
|
public void onDisplayCompletions(CompletionInfo[] applicationSpecifiedCompletions) {
|
2010-08-20 05:35:02 +00:00
|
|
|
if (DEBUG) {
|
2011-01-10 02:59:46 +00:00
|
|
|
Log.i(TAG, "Received completions:");
|
2011-03-04 07:56:10 +00:00
|
|
|
if (applicationSpecifiedCompletions != null) {
|
|
|
|
for (int i = 0; i < applicationSpecifiedCompletions.length; i++) {
|
|
|
|
Log.i(TAG, " #" + i + ": " + applicationSpecifiedCompletions[i]);
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-30 20:15:46 +00:00
|
|
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
|
|
|
ResearchLogger.latinIME_onDisplayCompletions(applicationSpecifiedCompletions);
|
|
|
|
}
|
2012-06-12 00:35:51 +00:00
|
|
|
if (!mCurrentSettings.isApplicationSpecifiedCompletionsOn()) return;
|
|
|
|
mApplicationSpecifiedCompletions = applicationSpecifiedCompletions;
|
|
|
|
if (applicationSpecifiedCompletions == null) {
|
2012-07-23 09:03:16 +00:00
|
|
|
clearSuggestionStrip();
|
2012-06-12 00:35:51 +00:00
|
|
|
return;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2012-06-12 00:35:51 +00:00
|
|
|
|
|
|
|
final ArrayList<SuggestedWords.SuggestedWordInfo> applicationSuggestedWords =
|
|
|
|
SuggestedWords.getFromApplicationSpecifiedCompletions(
|
|
|
|
applicationSpecifiedCompletions);
|
|
|
|
final SuggestedWords suggestedWords = new SuggestedWords(
|
|
|
|
applicationSuggestedWords,
|
|
|
|
false /* typedWordValid */,
|
|
|
|
false /* hasAutoCorrectionCandidate */,
|
|
|
|
false /* isPunctuationSuggestions */,
|
|
|
|
false /* isObsoleteSuggestions */,
|
|
|
|
false /* isPrediction */);
|
|
|
|
// When in fullscreen mode, show completions generated by the application
|
|
|
|
final boolean isAutoCorrection = false;
|
2012-07-23 09:03:16 +00:00
|
|
|
setSuggestionStrip(suggestedWords, isAutoCorrection);
|
2012-06-12 00:35:51 +00:00
|
|
|
setAutoCorrectionIndicator(isAutoCorrection);
|
|
|
|
// TODO: is this the right thing to do? What should we auto-correct to in
|
|
|
|
// this case? This says to keep whatever the user typed.
|
|
|
|
mWordComposer.setAutoCorrection(mWordComposer.getTypedWord());
|
|
|
|
setSuggestionStripShown(true);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2011-05-23 09:30:21 +00:00
|
|
|
private void setSuggestionStripShownInternal(boolean shown, boolean needsInputViewShown) {
|
2011-09-01 05:54:28 +00:00
|
|
|
// TODO: Modify this if we support suggestions with hard keyboard
|
|
|
|
if (onEvaluateInputViewShown() && mSuggestionsContainer != null) {
|
2012-07-23 01:27:14 +00:00
|
|
|
final MainKeyboardView keyboardView = mKeyboardSwitcher.getKeyboardView();
|
2012-01-31 07:59:32 +00:00
|
|
|
final boolean inputViewShown = (keyboardView != null) ? keyboardView.isShown() : false;
|
2011-09-01 05:54:28 +00:00
|
|
|
final boolean shouldShowSuggestions = shown
|
2012-01-31 07:59:32 +00:00
|
|
|
&& (needsInputViewShown ? inputViewShown : true);
|
2011-07-28 22:06:15 +00:00
|
|
|
if (isFullscreenMode()) {
|
2011-09-01 05:54:28 +00:00
|
|
|
mSuggestionsContainer.setVisibility(
|
|
|
|
shouldShowSuggestions ? View.VISIBLE : View.GONE);
|
2011-04-13 05:12:24 +00:00
|
|
|
} else {
|
2011-09-01 05:54:28 +00:00
|
|
|
mSuggestionsContainer.setVisibility(
|
|
|
|
shouldShowSuggestions ? View.VISIBLE : View.INVISIBLE);
|
2011-04-13 05:12:24 +00:00
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2011-05-23 09:30:21 +00:00
|
|
|
private void setSuggestionStripShown(boolean shown) {
|
|
|
|
setSuggestionStripShownInternal(shown, /* needsInputViewShown */true);
|
2010-08-31 09:00:09 +00:00
|
|
|
}
|
|
|
|
|
2012-06-04 02:14:51 +00:00
|
|
|
private int getAdjustedBackingViewHeight() {
|
|
|
|
final int currentHeight = mKeyPreviewBackingView.getHeight();
|
|
|
|
if (currentHeight > 0) {
|
|
|
|
return currentHeight;
|
2012-03-07 06:30:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
final KeyboardView keyboardView = mKeyboardSwitcher.getKeyboardView();
|
2012-06-04 02:14:51 +00:00
|
|
|
if (keyboardView == null) {
|
|
|
|
return 0;
|
|
|
|
}
|
2012-03-07 06:30:16 +00:00
|
|
|
final int keyboardHeight = keyboardView.getHeight();
|
|
|
|
final int suggestionsHeight = mSuggestionsContainer.getHeight();
|
|
|
|
final int displayHeight = mResources.getDisplayMetrics().heightPixels;
|
|
|
|
final Rect rect = new Rect();
|
|
|
|
mKeyPreviewBackingView.getWindowVisibleDisplayFrame(rect);
|
|
|
|
final int notificationBarHeight = rect.top;
|
|
|
|
final int remainingHeight = displayHeight - notificationBarHeight - suggestionsHeight
|
|
|
|
- keyboardHeight;
|
|
|
|
|
|
|
|
final LayoutParams params = mKeyPreviewBackingView.getLayoutParams();
|
2012-07-23 06:28:28 +00:00
|
|
|
params.height = mSuggestionStripView.setMoreSuggestionsHeight(remainingHeight);
|
2012-03-07 06:30:16 +00:00
|
|
|
mKeyPreviewBackingView.setLayoutParams(params);
|
2012-06-04 02:14:51 +00:00
|
|
|
return params.height;
|
2012-03-07 06:30:16 +00:00
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
@Override
|
|
|
|
public void onComputeInsets(InputMethodService.Insets outInsets) {
|
|
|
|
super.onComputeInsets(outInsets);
|
2011-07-04 11:58:58 +00:00
|
|
|
final KeyboardView inputView = mKeyboardSwitcher.getKeyboardView();
|
2011-09-01 05:54:28 +00:00
|
|
|
if (inputView == null || mSuggestionsContainer == null)
|
2011-04-21 05:51:53 +00:00
|
|
|
return;
|
2012-06-05 23:45:31 +00:00
|
|
|
final int adjustedBackingHeight = getAdjustedBackingViewHeight();
|
|
|
|
final boolean backingGone = (mKeyPreviewBackingView.getVisibility() == View.GONE);
|
|
|
|
final int backingHeight = backingGone ? 0 : adjustedBackingHeight;
|
2011-10-12 09:50:51 +00:00
|
|
|
// In fullscreen mode, the height of the extract area managed by InputMethodService should
|
|
|
|
// be considered.
|
|
|
|
// See {@link android.inputmethodservice.InputMethodService#onComputeInsets}.
|
|
|
|
final int extractHeight = isFullscreenMode() ? mExtractArea.getHeight() : 0;
|
2011-09-20 05:57:31 +00:00
|
|
|
final int suggestionsHeight = (mSuggestionsContainer.getVisibility() == View.GONE) ? 0
|
|
|
|
: mSuggestionsContainer.getHeight();
|
2011-10-12 09:50:51 +00:00
|
|
|
final int extraHeight = extractHeight + backingHeight + suggestionsHeight;
|
2011-09-02 12:03:18 +00:00
|
|
|
int touchY = extraHeight;
|
2011-01-21 10:04:00 +00:00
|
|
|
// Need to set touchable region only if input view is being shown
|
2012-07-23 01:27:14 +00:00
|
|
|
final MainKeyboardView keyboardView = mKeyboardSwitcher.getKeyboardView();
|
2012-01-31 07:59:32 +00:00
|
|
|
if (keyboardView != null && keyboardView.isShown()) {
|
2011-09-01 05:54:28 +00:00
|
|
|
if (mSuggestionsContainer.getVisibility() == View.VISIBLE) {
|
2011-09-20 05:57:31 +00:00
|
|
|
touchY -= suggestionsHeight;
|
2011-01-21 10:04:00 +00:00
|
|
|
}
|
2011-04-13 05:12:24 +00:00
|
|
|
final int touchWidth = inputView.getWidth();
|
2011-09-02 12:03:18 +00:00
|
|
|
final int touchHeight = inputView.getHeight() + extraHeight
|
2011-04-13 05:12:24 +00:00
|
|
|
// Extend touchable region below the keyboard.
|
|
|
|
+ EXTENDED_TOUCHABLE_REGION_HEIGHT;
|
2012-04-02 13:25:08 +00:00
|
|
|
outInsets.touchableInsets = InputMethodService.Insets.TOUCHABLE_INSETS_REGION;
|
|
|
|
outInsets.touchableRegion.set(0, touchY, touchWidth, touchHeight);
|
2011-01-21 10:04:00 +00:00
|
|
|
}
|
2011-04-21 05:51:53 +00:00
|
|
|
outInsets.contentTopInsets = touchY;
|
|
|
|
outInsets.visibleTopInsets = touchY;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-08-20 05:35:02 +00:00
|
|
|
@Override
|
|
|
|
public boolean onEvaluateFullscreenMode() {
|
2012-01-16 02:32:49 +00:00
|
|
|
// Reread resource value here, because this method is called by framework anytime as needed.
|
|
|
|
final boolean isFullscreenModeAllowed =
|
2012-06-08 12:34:07 +00:00
|
|
|
mCurrentSettings.isFullscreenModeAllowed(getResources());
|
2012-01-16 02:32:49 +00:00
|
|
|
return super.onEvaluateFullscreenMode() && isFullscreenModeAllowed;
|
2011-09-20 05:57:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void updateFullscreenMode() {
|
|
|
|
super.updateFullscreenMode();
|
2011-09-07 03:50:48 +00:00
|
|
|
|
2011-09-20 05:57:31 +00:00
|
|
|
if (mKeyPreviewBackingView == null) return;
|
2011-11-15 17:11:11 +00:00
|
|
|
// In fullscreen mode, no need to have extra space to show the key preview.
|
2011-09-20 05:57:31 +00:00
|
|
|
// If not, we should have extra space above the keyboard to show the key preview.
|
2011-11-15 17:11:11 +00:00
|
|
|
mKeyPreviewBackingView.setVisibility(isFullscreenMode() ? View.GONE : View.VISIBLE);
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|
|
|
|
|
2012-02-20 02:08:40 +00:00
|
|
|
// This will reset the whole input state to the starting state. It will clear
|
2012-06-16 01:34:57 +00:00
|
|
|
// the composing word, reset the last composed word, tell the inputconnection about it.
|
2012-02-20 02:08:40 +00:00
|
|
|
private void resetEntireInputState() {
|
|
|
|
resetComposingState(true /* alsoResetLastComposedWord */);
|
2012-07-23 09:03:16 +00:00
|
|
|
clearSuggestionStrip();
|
2012-06-08 10:04:09 +00:00
|
|
|
mConnection.finishComposingText();
|
2012-02-20 02:08:40 +00:00
|
|
|
}
|
|
|
|
|
2012-01-26 07:37:47 +00:00
|
|
|
private void resetComposingState(final boolean alsoResetLastComposedWord) {
|
|
|
|
mWordComposer.reset();
|
|
|
|
if (alsoResetLastComposedWord)
|
|
|
|
mLastComposedWord = LastComposedWord.NOT_A_COMPOSED_WORD;
|
|
|
|
}
|
|
|
|
|
2012-07-09 03:54:42 +00:00
|
|
|
private void commitTyped(final int separatorCode) {
|
2011-12-13 14:24:37 +00:00
|
|
|
if (!mWordComposer.isComposingWord()) return;
|
2011-12-09 14:15:49 +00:00
|
|
|
final CharSequence typedWord = mWordComposer.getTypedWord();
|
|
|
|
if (typedWord.length() > 0) {
|
2012-06-08 10:04:09 +00:00
|
|
|
mConnection.commitText(typedWord, 1);
|
|
|
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
|
|
|
ResearchLogger.latinIME_commitText(typedWord);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2012-05-24 03:11:02 +00:00
|
|
|
final CharSequence prevWord = addToUserHistoryDictionary(typedWord);
|
|
|
|
mLastComposedWord = mWordComposer.commitWord(
|
|
|
|
LastComposedWord.COMMIT_TYPE_USER_TYPED_WORD, typedWord.toString(),
|
|
|
|
separatorCode, prevWord);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2012-07-23 09:03:16 +00:00
|
|
|
updateSuggestionStrip();
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2012-07-09 03:54:42 +00:00
|
|
|
// Called from the KeyboardSwitcher which needs to know auto caps state to display
|
|
|
|
// the right layout.
|
2012-05-18 07:45:26 +00:00
|
|
|
public int getCurrentAutoCapsState() {
|
2012-06-08 12:34:07 +00:00
|
|
|
if (!mCurrentSettings.mAutoCap) return Constants.TextUtils.CAP_MODE_OFF;
|
2012-05-09 06:36:15 +00:00
|
|
|
|
|
|
|
final EditorInfo ei = getCurrentInputEditorInfo();
|
2012-05-18 07:45:26 +00:00
|
|
|
if (ei == null) return Constants.TextUtils.CAP_MODE_OFF;
|
2012-05-09 06:36:15 +00:00
|
|
|
|
|
|
|
final int inputType = ei.inputType;
|
2012-05-18 07:45:26 +00:00
|
|
|
if ((inputType & InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS) != 0) {
|
|
|
|
return TextUtils.CAP_MODE_CHARACTERS;
|
|
|
|
}
|
2012-05-09 06:36:15 +00:00
|
|
|
|
|
|
|
final boolean noNeedToCheckCapsMode = (inputType & (InputType.TYPE_TEXT_FLAG_CAP_SENTENCES
|
|
|
|
| InputType.TYPE_TEXT_FLAG_CAP_WORDS)) == 0;
|
2012-05-18 07:45:26 +00:00
|
|
|
if (noNeedToCheckCapsMode) return Constants.TextUtils.CAP_MODE_OFF;
|
2012-05-09 06:36:15 +00:00
|
|
|
|
2012-05-17 03:55:01 +00:00
|
|
|
// Avoid making heavy round-trip IPC calls of {@link InputConnection#getCursorCapsMode}
|
|
|
|
// unless needed.
|
|
|
|
if (mWordComposer.isComposingWord()) return Constants.TextUtils.CAP_MODE_OFF;
|
|
|
|
|
2012-05-09 06:36:15 +00:00
|
|
|
// TODO: This blocking IPC call is heavy. Consider doing this without using IPC calls.
|
|
|
|
// Note: getCursorCapsMode() returns the current capitalization mode that is any
|
|
|
|
// combination of CAP_MODE_CHARACTERS, CAP_MODE_WORDS, and CAP_MODE_SENTENCES. 0 means none
|
|
|
|
// of them.
|
2012-06-08 10:04:09 +00:00
|
|
|
return mConnection.getCursorCapsMode(inputType);
|
2010-01-24 15:34:07 +00:00
|
|
|
}
|
|
|
|
|
2012-06-08 11:23:13 +00:00
|
|
|
private void swapSwapperAndSpace() {
|
2012-06-08 10:04:09 +00:00
|
|
|
CharSequence lastTwo = mConnection.getTextBeforeCursor(2, 0);
|
2011-05-09 07:54:07 +00:00
|
|
|
// It is guaranteed lastTwo.charAt(1) is a swapper - else this method is not called.
|
2009-03-13 22:11:42 +00:00
|
|
|
if (lastTwo != null && lastTwo.length() == 2
|
2011-05-09 07:54:07 +00:00
|
|
|
&& lastTwo.charAt(0) == Keyboard.CODE_SPACE) {
|
2012-06-08 10:04:09 +00:00
|
|
|
mConnection.deleteSurroundingText(2, 0);
|
2012-04-18 01:34:02 +00:00
|
|
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
|
|
|
ResearchLogger.latinIME_deleteSurroundingText(2);
|
|
|
|
}
|
2012-06-08 10:04:09 +00:00
|
|
|
mConnection.commitText(lastTwo.charAt(1) + " ", 1);
|
2012-04-18 01:34:02 +00:00
|
|
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
|
|
|
ResearchLogger.latinIME_swapSwapperAndSpaceWhileInBatchEdit();
|
|
|
|
}
|
2010-11-13 08:16:34 +00:00
|
|
|
mKeyboardSwitcher.updateShiftState();
|
2010-02-22 14:55:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-08 11:23:13 +00:00
|
|
|
private boolean maybeDoubleSpace() {
|
2012-06-16 01:59:12 +00:00
|
|
|
if (!mCurrentSettings.mCorrectionEnabled) return false;
|
2012-06-08 13:33:17 +00:00
|
|
|
if (!mHandler.isAcceptingDoubleSpaces()) return false;
|
2012-06-08 10:04:09 +00:00
|
|
|
final CharSequence lastThree = mConnection.getTextBeforeCursor(3, 0);
|
2009-03-13 22:11:42 +00:00
|
|
|
if (lastThree != null && lastThree.length() == 3
|
2012-04-19 07:39:25 +00:00
|
|
|
&& canBeFollowedByPeriod(lastThree.charAt(0))
|
2010-12-02 11:54:32 +00:00
|
|
|
&& lastThree.charAt(1) == Keyboard.CODE_SPACE
|
2012-06-08 13:33:17 +00:00
|
|
|
&& lastThree.charAt(2) == Keyboard.CODE_SPACE) {
|
2011-03-02 07:40:10 +00:00
|
|
|
mHandler.cancelDoubleSpacesTimer();
|
2012-06-08 10:04:09 +00:00
|
|
|
mConnection.deleteSurroundingText(2, 0);
|
|
|
|
mConnection.commitText(". ", 1);
|
2012-04-18 01:34:02 +00:00
|
|
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
|
|
|
ResearchLogger.latinIME_doubleSpaceAutoPeriod();
|
|
|
|
}
|
2010-11-13 08:16:34 +00:00
|
|
|
mKeyboardSwitcher.updateShiftState();
|
2011-10-25 12:14:33 +00:00
|
|
|
return true;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2011-10-25 12:14:33 +00:00
|
|
|
return false;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2012-04-19 07:39:25 +00:00
|
|
|
private static boolean canBeFollowedByPeriod(final int codePoint) {
|
|
|
|
// TODO: Check again whether there really ain't a better way to check this.
|
|
|
|
// TODO: This should probably be language-dependant...
|
|
|
|
return Character.isLetterOrDigit(codePoint)
|
|
|
|
|| codePoint == Keyboard.CODE_SINGLE_QUOTE
|
|
|
|
|| codePoint == Keyboard.CODE_DOUBLE_QUOTE
|
|
|
|
|| codePoint == Keyboard.CODE_CLOSING_PARENTHESIS
|
|
|
|
|| codePoint == Keyboard.CODE_CLOSING_SQUARE_BRACKET
|
|
|
|
|| codePoint == Keyboard.CODE_CLOSING_CURLY_BRACKET
|
|
|
|
|| codePoint == Keyboard.CODE_CLOSING_ANGLE_BRACKET;
|
|
|
|
}
|
|
|
|
|
2012-07-23 06:28:28 +00:00
|
|
|
// Callback for the {@link SuggestionStripView}, to call when the "add to dictionary" hint is
|
|
|
|
// pressed.
|
2011-06-09 05:22:37 +00:00
|
|
|
@Override
|
2012-07-05 02:28:05 +00:00
|
|
|
public boolean addWordToUserDictionary(String word) {
|
2012-06-08 08:01:35 +00:00
|
|
|
mUserDictionary.addWordToUserDictionary(word, 128);
|
2009-03-13 22:11:42 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-10-28 04:31:31 +00:00
|
|
|
private static boolean isAlphabet(int code) {
|
|
|
|
return Character.isLetter(code);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-12-06 03:12:27 +00:00
|
|
|
private void onSettingsKeyPressed() {
|
2011-08-06 01:45:19 +00:00
|
|
|
if (isShowingOptionDialog()) return;
|
2012-03-30 07:08:11 +00:00
|
|
|
showSubtypeSelectorAndSettings();
|
2010-09-02 19:25:31 +00:00
|
|
|
}
|
|
|
|
|
2011-08-06 01:45:19 +00:00
|
|
|
// Virtual codes representing custom requests. These are used in onCustomRequest() below.
|
|
|
|
public static final int CODE_SHOW_INPUT_METHOD_PICKER = 1;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onCustomRequest(int requestCode) {
|
|
|
|
if (isShowingOptionDialog()) return false;
|
|
|
|
switch (requestCode) {
|
|
|
|
case CODE_SHOW_INPUT_METHOD_PICKER:
|
2012-04-18 08:39:57 +00:00
|
|
|
if (ImfUtils.hasMultipleEnabledIMEsOrSubtypes(
|
|
|
|
this, true /* include aux subtypes */)) {
|
2010-11-25 00:20:28 +00:00
|
|
|
mImm.showInputMethodPicker();
|
2011-08-06 01:45:19 +00:00
|
|
|
return true;
|
2010-09-02 19:25:31 +00:00
|
|
|
}
|
2011-08-06 01:45:19 +00:00
|
|
|
return false;
|
2010-09-02 19:25:31 +00:00
|
|
|
}
|
2011-08-06 01:45:19 +00:00
|
|
|
return false;
|
2010-09-02 19:25:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private boolean isShowingOptionDialog() {
|
|
|
|
return mOptionsDialog != null && mOptionsDialog.isShowing();
|
|
|
|
}
|
|
|
|
|
2012-02-17 07:14:14 +00:00
|
|
|
private static int getActionId(Keyboard keyboard) {
|
|
|
|
return keyboard != null ? keyboard.mId.imeActionId() : EditorInfo.IME_ACTION_NONE;
|
2012-02-07 08:07:23 +00:00
|
|
|
}
|
|
|
|
|
2012-04-03 08:27:51 +00:00
|
|
|
private void performEditorAction(int actionId) {
|
2012-06-08 10:04:09 +00:00
|
|
|
mConnection.performEditorAction(actionId);
|
|
|
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
|
|
|
ResearchLogger.latinIME_performEditorAction(actionId);
|
2012-02-07 08:07:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-18 01:46:01 +00:00
|
|
|
private void handleLanguageSwitchKey() {
|
2012-06-08 12:34:07 +00:00
|
|
|
final boolean includesOtherImes = mCurrentSettings.mIncludesOtherImesInLanguageSwitchList;
|
2012-02-18 01:46:01 +00:00
|
|
|
final IBinder token = getWindow().getWindow().getAttributes().token;
|
|
|
|
if (mShouldSwitchToLastSubtype) {
|
2012-04-02 12:31:52 +00:00
|
|
|
final InputMethodSubtype lastSubtype = mImm.getLastInputMethodSubtype();
|
2012-05-01 11:06:38 +00:00
|
|
|
final boolean lastSubtypeBelongsToThisIme =
|
|
|
|
ImfUtils.checkIfSubtypeBelongsToThisImeAndEnabled(this, lastSubtype);
|
2012-02-18 01:46:01 +00:00
|
|
|
if ((includesOtherImes || lastSubtypeBelongsToThisIme)
|
|
|
|
&& mImm.switchToLastInputMethod(token)) {
|
|
|
|
mShouldSwitchToLastSubtype = false;
|
|
|
|
} else {
|
|
|
|
mImm.switchToNextInputMethod(token, !includesOtherImes);
|
|
|
|
mShouldSwitchToLastSubtype = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mImm.switchToNextInputMethod(token, !includesOtherImes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-08 10:04:09 +00:00
|
|
|
private void sendUpDownEnterOrBackspace(final int code) {
|
2012-05-25 10:56:45 +00:00
|
|
|
final long eventTime = SystemClock.uptimeMillis();
|
2012-06-08 10:04:09 +00:00
|
|
|
mConnection.sendKeyEvent(new KeyEvent(eventTime, eventTime,
|
2012-05-25 10:56:45 +00:00
|
|
|
KeyEvent.ACTION_DOWN, code, 0, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0,
|
|
|
|
KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE));
|
2012-06-08 10:04:09 +00:00
|
|
|
mConnection.sendKeyEvent(new KeyEvent(SystemClock.uptimeMillis(), eventTime,
|
2012-05-25 10:56:45 +00:00
|
|
|
KeyEvent.ACTION_UP, code, 0, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0,
|
|
|
|
KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE));
|
|
|
|
}
|
|
|
|
|
2012-02-07 08:07:23 +00:00
|
|
|
private void sendKeyCodePoint(int code) {
|
|
|
|
// TODO: Remove this special handling of digit letters.
|
|
|
|
// For backward compatibility. See {@link InputMethodService#sendKeyChar(char)}.
|
|
|
|
if (code >= '0' && code <= '9') {
|
|
|
|
super.sendKeyChar((char)code);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-06-08 10:04:09 +00:00
|
|
|
// 16 is android.os.Build.VERSION_CODES.JELLY_BEAN but we can't write it because
|
|
|
|
// we want to be able to compile against the Ice Cream Sandwich SDK.
|
|
|
|
if (Keyboard.CODE_ENTER == code && mTargetApplicationInfo != null
|
|
|
|
&& mTargetApplicationInfo.targetSdkVersion < 16) {
|
|
|
|
// Backward compatibility mode. Before Jelly bean, the keyboard would simulate
|
|
|
|
// a hardware keyboard event on pressing enter or delete. This is bad for many
|
|
|
|
// reasons (there are race conditions with commits) but some applications are
|
|
|
|
// relying on this behavior so we continue to support it for older apps.
|
|
|
|
sendUpDownEnterOrBackspace(KeyEvent.KEYCODE_ENTER);
|
|
|
|
} else {
|
|
|
|
final String text = new String(new int[] { code }, 0, 1);
|
|
|
|
mConnection.commitText(text, text.length());
|
|
|
|
}
|
|
|
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
|
|
|
ResearchLogger.latinIME_sendKeyCodePoint(code);
|
2012-02-07 08:07:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-30 08:19:55 +00:00
|
|
|
// Implementation of {@link KeyboardActionListener}.
|
2010-12-02 09:46:21 +00:00
|
|
|
@Override
|
2012-03-06 05:56:46 +00:00
|
|
|
public void onCodeInput(int primaryCode, int x, int y) {
|
2011-11-16 23:58:42 +00:00
|
|
|
final 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;
|
2012-07-05 03:36:06 +00:00
|
|
|
mConnection.beginBatchEdit();
|
2012-03-22 02:13:33 +00:00
|
|
|
|
2012-03-26 13:10:21 +00:00
|
|
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
2012-05-14 16:41:39 +00:00
|
|
|
ResearchLogger.latinIME_onCodeInput(primaryCode, x, y);
|
2012-03-22 02:13:33 +00:00
|
|
|
}
|
|
|
|
|
2011-11-16 23:58:42 +00:00
|
|
|
final KeyboardSwitcher switcher = mKeyboardSwitcher;
|
2011-10-25 12:14:33 +00:00
|
|
|
// The space state depends only on the last character pressed and its own previous
|
|
|
|
// state. Here, we revert the space state to neutral if the key is actually modifying
|
|
|
|
// the input contents (any non-shift key), which is what we should do for
|
|
|
|
// all inputs that do not result in a special state. Each character handling is then
|
|
|
|
// free to override the state as they see fit.
|
|
|
|
final int spaceState = mSpaceState;
|
2012-03-07 06:20:01 +00:00
|
|
|
if (!mWordComposer.isComposingWord()) mIsAutoCorrectionIndicatorOn = false;
|
2011-11-14 09:59:17 +00:00
|
|
|
|
|
|
|
// TODO: Consolidate the double space timer, mLastKeyTime, and the space state.
|
|
|
|
if (primaryCode != Keyboard.CODE_SPACE) {
|
|
|
|
mHandler.cancelDoubleSpacesTimer();
|
|
|
|
}
|
|
|
|
|
2012-01-26 08:20:51 +00:00
|
|
|
boolean didAutoCorrect = false;
|
2009-03-13 22:11:42 +00:00
|
|
|
switch (primaryCode) {
|
2010-12-02 11:54:32 +00:00
|
|
|
case Keyboard.CODE_DELETE:
|
2011-10-25 12:14:33 +00:00
|
|
|
mSpaceState = SPACE_STATE_NONE;
|
|
|
|
handleBackspace(spaceState);
|
2010-10-22 10:35:23 +00:00
|
|
|
mDeleteCount++;
|
2011-06-08 07:47:19 +00:00
|
|
|
mExpectingUpdateSelection = true;
|
2012-02-18 01:46:01 +00:00
|
|
|
mShouldSwitchToLastSubtype = true;
|
2012-03-20 14:29:34 +00:00
|
|
|
LatinImeLogger.logOnDelete(x, y);
|
2010-10-22 10:35:23 +00:00
|
|
|
break;
|
2010-12-02 11:54:32 +00:00
|
|
|
case Keyboard.CODE_SHIFT:
|
2010-12-06 03:12:27 +00:00
|
|
|
case Keyboard.CODE_SWITCH_ALPHA_SYMBOL:
|
2012-01-17 08:08:26 +00:00
|
|
|
// Shift and symbol key is handled in onPressKey() and onReleaseKey().
|
2010-10-22 10:35:23 +00:00
|
|
|
break;
|
2010-12-06 03:12:27 +00:00
|
|
|
case Keyboard.CODE_SETTINGS:
|
2011-11-22 00:41:01 +00:00
|
|
|
onSettingsKeyPressed();
|
2010-10-22 10:35:23 +00:00
|
|
|
break;
|
2011-04-21 10:43:20 +00:00
|
|
|
case Keyboard.CODE_SHORTCUT:
|
2011-11-22 00:41:01 +00:00
|
|
|
mSubtypeSwitcher.switchToShortcutIME();
|
2010-10-22 10:35:23 +00:00
|
|
|
break;
|
2012-02-07 08:07:23 +00:00
|
|
|
case Keyboard.CODE_ACTION_ENTER:
|
2012-04-03 08:27:51 +00:00
|
|
|
performEditorAction(getActionId(switcher.getKeyboard()));
|
2012-02-07 08:07:23 +00:00
|
|
|
break;
|
2012-02-17 07:14:14 +00:00
|
|
|
case Keyboard.CODE_ACTION_NEXT:
|
2012-04-03 08:27:51 +00:00
|
|
|
performEditorAction(EditorInfo.IME_ACTION_NEXT);
|
2012-02-17 07:14:14 +00:00
|
|
|
break;
|
|
|
|
case Keyboard.CODE_ACTION_PREVIOUS:
|
2012-04-03 08:27:51 +00:00
|
|
|
performEditorAction(EditorInfo.IME_ACTION_PREVIOUS);
|
2010-10-22 10:35:23 +00:00
|
|
|
break;
|
2012-02-18 01:46:01 +00:00
|
|
|
case Keyboard.CODE_LANGUAGE_SWITCH:
|
|
|
|
handleLanguageSwitchKey();
|
|
|
|
break;
|
2012-06-04 19:27:37 +00:00
|
|
|
case Keyboard.CODE_RESEARCH:
|
|
|
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
|
|
|
ResearchLogger.getInstance().presentResearchDialog(this);
|
|
|
|
}
|
|
|
|
break;
|
2010-10-22 10:35:23 +00:00
|
|
|
default:
|
2011-10-25 12:14:33 +00:00
|
|
|
mSpaceState = SPACE_STATE_NONE;
|
2012-06-08 12:34:07 +00:00
|
|
|
if (mCurrentSettings.isWordSeparator(primaryCode)) {
|
2012-01-26 08:20:51 +00:00
|
|
|
didAutoCorrect = handleSeparator(primaryCode, x, y, spaceState);
|
2010-10-22 10:35:23 +00:00
|
|
|
} else {
|
2012-07-04 06:24:59 +00:00
|
|
|
if (SPACE_STATE_PHANTOM == spaceState) {
|
|
|
|
commitTyped(LastComposedWord.NOT_A_SEPARATOR);
|
|
|
|
}
|
2012-06-12 10:40:37 +00:00
|
|
|
final int keyX, keyY;
|
2012-03-28 08:33:25 +00:00
|
|
|
final Keyboard keyboard = mKeyboardSwitcher.getKeyboard();
|
|
|
|
if (keyboard != null && keyboard.hasProximityCharsCorrection(primaryCode)) {
|
2012-06-12 10:40:37 +00:00
|
|
|
keyX = x;
|
|
|
|
keyY = y;
|
2012-03-28 08:33:25 +00:00
|
|
|
} else {
|
2012-06-12 10:40:37 +00:00
|
|
|
keyX = NOT_A_TOUCH_COORDINATE;
|
|
|
|
keyY = NOT_A_TOUCH_COORDINATE;
|
2012-03-28 08:33:25 +00:00
|
|
|
}
|
2012-06-12 10:40:37 +00:00
|
|
|
handleCharacter(primaryCode, keyX, keyY, spaceState);
|
2010-10-22 10:35:23 +00:00
|
|
|
}
|
2011-06-08 07:47:19 +00:00
|
|
|
mExpectingUpdateSelection = true;
|
2012-02-18 01:46:01 +00:00
|
|
|
mShouldSwitchToLastSubtype = true;
|
2011-06-08 07:47:19 +00:00
|
|
|
break;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2011-12-07 10:31:11 +00:00
|
|
|
switcher.onCodeInput(primaryCode);
|
2012-05-17 08:05:30 +00:00
|
|
|
// Reset after any single keystroke, except shift and symbol-shift
|
|
|
|
if (!didAutoCorrect && primaryCode != Keyboard.CODE_SHIFT
|
|
|
|
&& primaryCode != Keyboard.CODE_SWITCH_ALPHA_SYMBOL)
|
2012-01-26 08:20:51 +00:00
|
|
|
mLastComposedWord.deactivate();
|
2010-04-01 13:28:52 +00:00
|
|
|
mEnteredText = null;
|
2012-06-08 11:03:22 +00:00
|
|
|
mConnection.endBatchEdit();
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2012-07-09 03:54:42 +00:00
|
|
|
// Called from PointerTracker through the KeyboardActionListener interface
|
2010-12-02 09:46:21 +00:00
|
|
|
@Override
|
2010-12-20 07:13:57 +00:00
|
|
|
public void onTextInput(CharSequence text) {
|
2012-07-05 03:36:06 +00:00
|
|
|
mConnection.beginBatchEdit();
|
2012-06-08 10:04:09 +00:00
|
|
|
commitTyped(LastComposedWord.NOT_A_SEPARATOR);
|
|
|
|
text = specificTldProcessingOnTextInput(text);
|
2012-02-02 08:18:03 +00:00
|
|
|
if (SPACE_STATE_PHANTOM == mSpaceState) {
|
2012-02-07 08:07:23 +00:00
|
|
|
sendKeyCodePoint(Keyboard.CODE_SPACE);
|
2012-02-02 08:18:03 +00:00
|
|
|
}
|
2012-06-08 10:04:09 +00:00
|
|
|
mConnection.commitText(text, 1);
|
2012-04-18 01:34:02 +00:00
|
|
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
|
|
|
ResearchLogger.latinIME_commitText(text);
|
|
|
|
}
|
2012-06-08 10:04:09 +00:00
|
|
|
mConnection.endBatchEdit();
|
2010-11-13 08:16:34 +00:00
|
|
|
mKeyboardSwitcher.updateShiftState();
|
2012-01-10 08:24:00 +00:00
|
|
|
mKeyboardSwitcher.onCodeInput(Keyboard.CODE_OUTPUT_TEXT);
|
2011-10-25 12:14:33 +00:00
|
|
|
mSpaceState = SPACE_STATE_NONE;
|
2010-04-01 13:28:52 +00:00
|
|
|
mEnteredText = text;
|
2012-01-26 07:37:47 +00:00
|
|
|
resetComposingState(true /* alsoResetLastComposedWord */);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2012-07-04 06:24:59 +00:00
|
|
|
@Override
|
|
|
|
public void onStartBatchInput() {
|
|
|
|
mConnection.beginBatchEdit();
|
|
|
|
if (mWordComposer.isComposingWord()) {
|
|
|
|
commitTyped(LastComposedWord.NOT_A_SEPARATOR);
|
|
|
|
mExpectingUpdateSelection = true;
|
|
|
|
// TODO: Can we remove this?
|
|
|
|
mSpaceState = SPACE_STATE_PHANTOM;
|
|
|
|
}
|
|
|
|
mConnection.endBatchEdit();
|
2012-06-12 10:40:37 +00:00
|
|
|
// TODO: Should handle TextUtils.CAP_MODE_CHARACTER.
|
|
|
|
mWordComposer.setAutoCapitalized(
|
|
|
|
getCurrentAutoCapsState() != Constants.TextUtils.CAP_MODE_OFF);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-07-18 09:14:51 +00:00
|
|
|
public void onUpdateBatchInput(InputPointers batchPointers) {
|
2012-06-12 10:40:37 +00:00
|
|
|
mWordComposer.setBatchInputPointers(batchPointers);
|
2012-07-23 02:59:11 +00:00
|
|
|
final SuggestedWords suggestedWords = getSuggestedWords();
|
|
|
|
showSuggestionStrip(suggestedWords, null);
|
2012-07-30 07:06:19 +00:00
|
|
|
final String gestureFloatingPreviewText = (suggestedWords.size() > 0)
|
2012-07-20 12:01:44 +00:00
|
|
|
? suggestedWords.getWord(0) : null;
|
2012-07-30 07:06:19 +00:00
|
|
|
mKeyboardSwitcher.getKeyboardView()
|
|
|
|
.showGestureFloatingPreviewText(gestureFloatingPreviewText);
|
2012-07-04 06:24:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-07-18 09:14:51 +00:00
|
|
|
public void onEndBatchInput(InputPointers batchPointers) {
|
|
|
|
mWordComposer.setBatchInputPointers(batchPointers);
|
2012-07-23 02:59:11 +00:00
|
|
|
final SuggestedWords suggestedWords = getSuggestedWords();
|
|
|
|
showSuggestionStrip(suggestedWords, null);
|
2012-07-30 07:06:19 +00:00
|
|
|
mKeyboardSwitcher.getKeyboardView().showGestureFloatingPreviewText(null);
|
2012-07-18 09:14:51 +00:00
|
|
|
if (suggestedWords == null || suggestedWords.size() == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
final CharSequence text = suggestedWords.getWord(0);
|
|
|
|
if (TextUtils.isEmpty(text)) {
|
|
|
|
return;
|
|
|
|
}
|
2012-06-12 10:40:37 +00:00
|
|
|
mWordComposer.setBatchInputWord(text);
|
2012-07-04 06:24:59 +00:00
|
|
|
mConnection.beginBatchEdit();
|
|
|
|
if (SPACE_STATE_PHANTOM == mSpaceState) {
|
|
|
|
sendKeyCodePoint(Keyboard.CODE_SPACE);
|
|
|
|
}
|
|
|
|
mConnection.setComposingText(text, 1);
|
|
|
|
mExpectingUpdateSelection = true;
|
|
|
|
mConnection.endBatchEdit();
|
|
|
|
mKeyboardSwitcher.updateShiftState();
|
|
|
|
mSpaceState = SPACE_STATE_PHANTOM;
|
|
|
|
}
|
|
|
|
|
2012-06-08 10:04:09 +00:00
|
|
|
private CharSequence specificTldProcessingOnTextInput(final CharSequence text) {
|
2012-02-02 08:18:03 +00:00
|
|
|
if (text.length() <= 1 || text.charAt(0) != Keyboard.CODE_PERIOD
|
|
|
|
|| !Character.isLetter(text.charAt(1))) {
|
|
|
|
// Not a tld: do nothing.
|
|
|
|
return text;
|
|
|
|
}
|
2012-02-07 11:36:48 +00:00
|
|
|
// We have a TLD (or something that looks like this): make sure we don't add
|
|
|
|
// a space even if currently in phantom mode.
|
|
|
|
mSpaceState = SPACE_STATE_NONE;
|
2012-06-08 10:04:09 +00:00
|
|
|
final CharSequence lastOne = mConnection.getTextBeforeCursor(1, 0);
|
2012-02-02 08:18:03 +00:00
|
|
|
if (lastOne != null && lastOne.length() == 1
|
|
|
|
&& lastOne.charAt(0) == Keyboard.CODE_PERIOD) {
|
|
|
|
return text.subSequence(1, text.length());
|
|
|
|
} else {
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-09 03:54:42 +00:00
|
|
|
// Called from PointerTracker through the KeyboardActionListener interface
|
2010-12-02 09:46:21 +00:00
|
|
|
@Override
|
2010-12-20 07:13:57 +00:00
|
|
|
public void onCancelInput() {
|
2010-09-07 06:37:59 +00:00
|
|
|
// User released a finger outside any key
|
2010-12-30 08:19:55 +00:00
|
|
|
mKeyboardSwitcher.onCancelInput();
|
2010-09-07 06:37:59 +00:00
|
|
|
}
|
|
|
|
|
2011-10-25 12:14:33 +00:00
|
|
|
private void handleBackspace(final int spaceState) {
|
2011-12-13 06:17:57 +00:00
|
|
|
// In many cases, we may have to put the keyboard in auto-shift state again.
|
2012-02-16 19:45:35 +00:00
|
|
|
mHandler.postUpdateShiftState();
|
2011-12-13 06:17:57 +00:00
|
|
|
|
2012-06-08 12:45:41 +00:00
|
|
|
if (mEnteredText != null && mConnection.sameAsTextBeforeCursor(mEnteredText)) {
|
2011-12-12 11:30:23 +00:00
|
|
|
// Cancel multi-character input: remove the text we just entered.
|
|
|
|
// This is triggered on backspace after a key that inputs multiple characters,
|
|
|
|
// like the smiley key or the .com key.
|
2012-04-18 01:34:02 +00:00
|
|
|
final int length = mEnteredText.length();
|
2012-06-08 10:04:09 +00:00
|
|
|
mConnection.deleteSurroundingText(length, 0);
|
2012-04-18 01:34:02 +00:00
|
|
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
|
|
|
ResearchLogger.latinIME_deleteSurroundingText(length);
|
|
|
|
}
|
2011-12-12 11:30:23 +00:00
|
|
|
// If we have mEnteredText, then we know that mHasUncommittedTypedChars == false.
|
|
|
|
// In addition we know that spaceState is false, and that we should not be
|
|
|
|
// reverting any autocorrect at this point. So we can safely return.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-13 14:24:37 +00:00
|
|
|
if (mWordComposer.isComposingWord()) {
|
2011-12-09 14:15:49 +00:00
|
|
|
final int length = mWordComposer.size();
|
2009-03-13 22:11:42 +00:00
|
|
|
if (length > 0) {
|
2012-07-04 06:24:59 +00:00
|
|
|
// Immediately after a batch input.
|
|
|
|
if (SPACE_STATE_PHANTOM == spaceState) {
|
|
|
|
mWordComposer.reset();
|
|
|
|
} else {
|
|
|
|
mWordComposer.deleteLast();
|
|
|
|
}
|
2012-06-08 10:04:09 +00:00
|
|
|
mConnection.setComposingText(getTextWithUnderline(mWordComposer.getTypedWord()), 1);
|
2012-07-06 02:33:16 +00:00
|
|
|
mHandler.postUpdateSuggestionStrip();
|
2009-03-13 22:11:42 +00:00
|
|
|
} else {
|
2012-06-08 10:04:09 +00:00
|
|
|
mConnection.deleteSurroundingText(1, 0);
|
2012-04-18 01:34:02 +00:00
|
|
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
|
|
|
ResearchLogger.latinIME_deleteSurroundingText(1);
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2011-12-12 06:09:17 +00:00
|
|
|
} else {
|
2012-02-22 09:09:23 +00:00
|
|
|
if (mLastComposedWord.canRevertCommit()) {
|
2011-12-13 06:20:36 +00:00
|
|
|
Utils.Stats.onAutoCorrectionCancellation();
|
2012-06-08 10:04:09 +00:00
|
|
|
revertCommit();
|
2011-10-25 12:14:33 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-12-13 06:20:36 +00:00
|
|
|
if (SPACE_STATE_DOUBLE == spaceState) {
|
2012-06-08 12:49:13 +00:00
|
|
|
mHandler.cancelDoubleSpacesTimer();
|
2012-06-08 12:50:34 +00:00
|
|
|
if (mConnection.revertDoubleSpace()) {
|
2011-12-13 06:20:36 +00:00
|
|
|
// No need to reset mSpaceState, it has already be done (that's why we
|
|
|
|
// receive it as a parameter)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (SPACE_STATE_SWAP_PUNCTUATION == spaceState) {
|
2012-06-08 12:56:44 +00:00
|
|
|
if (mConnection.revertSwapPunctuation()) {
|
2011-12-13 06:20:36 +00:00
|
|
|
// Likewise
|
|
|
|
return;
|
|
|
|
}
|
2011-06-08 07:47:19 +00:00
|
|
|
}
|
2011-01-13 08:14:27 +00:00
|
|
|
|
2012-02-22 08:21:55 +00:00
|
|
|
// No cancelling of commit/double space/swap: we have a regular backspace.
|
|
|
|
// We should backspace one char and restart suggestion if at the end of a word.
|
|
|
|
if (mLastSelectionStart != mLastSelectionEnd) {
|
|
|
|
// If there is a selection, remove it.
|
|
|
|
final int lengthToDelete = mLastSelectionEnd - mLastSelectionStart;
|
2012-06-08 10:04:09 +00:00
|
|
|
mConnection.setSelection(mLastSelectionEnd, mLastSelectionEnd);
|
|
|
|
mConnection.deleteSurroundingText(lengthToDelete, 0);
|
2012-04-18 01:34:02 +00:00
|
|
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
|
|
|
ResearchLogger.latinIME_deleteSurroundingText(lengthToDelete);
|
|
|
|
}
|
2010-08-03 18:47:42 +00:00
|
|
|
} else {
|
2012-02-22 08:21:55 +00:00
|
|
|
// There is no selection, just delete one character.
|
|
|
|
if (NOT_A_CURSOR_POSITION == mLastSelectionEnd) {
|
|
|
|
// This should never happen.
|
|
|
|
Log.e(TAG, "Backspace when we don't know the selection position");
|
2010-08-03 18:47:42 +00:00
|
|
|
}
|
2012-05-25 10:56:45 +00:00
|
|
|
// 16 is android.os.Build.VERSION_CODES.JELLY_BEAN but we can't write it because
|
|
|
|
// we want to be able to compile against the Ice Cream Sandwich SDK.
|
|
|
|
if (mTargetApplicationInfo != null
|
|
|
|
&& mTargetApplicationInfo.targetSdkVersion < 16) {
|
|
|
|
// Backward compatibility mode. Before Jelly bean, the keyboard would simulate
|
|
|
|
// a hardware keyboard event on pressing enter or delete. This is bad for many
|
|
|
|
// reasons (there are race conditions with commits) but some applications are
|
|
|
|
// relying on this behavior so we continue to support it for older apps.
|
2012-06-08 10:04:09 +00:00
|
|
|
sendUpDownEnterOrBackspace(KeyEvent.KEYCODE_DEL);
|
2012-05-25 10:56:45 +00:00
|
|
|
} else {
|
2012-06-08 10:04:09 +00:00
|
|
|
mConnection.deleteSurroundingText(1, 0);
|
2012-05-25 10:56:45 +00:00
|
|
|
}
|
2012-04-18 01:34:02 +00:00
|
|
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
|
|
|
ResearchLogger.latinIME_deleteSurroundingText(1);
|
|
|
|
}
|
2012-02-22 08:21:55 +00:00
|
|
|
if (mDeleteCount > DELETE_ACCELERATE_AT) {
|
2012-06-08 10:04:09 +00:00
|
|
|
mConnection.deleteSurroundingText(1, 0);
|
2012-04-18 01:34:02 +00:00
|
|
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
|
|
|
ResearchLogger.latinIME_deleteSurroundingText(1);
|
|
|
|
}
|
2012-01-17 06:17:17 +00:00
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2012-06-12 01:00:07 +00:00
|
|
|
if (mCurrentSettings.isSuggestionsRequested(mDisplayOrientation)) {
|
2012-06-08 10:04:09 +00:00
|
|
|
restartSuggestionsOnWordBeforeCursorIfAtEndOfWord();
|
2012-02-22 08:21:55 +00:00
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-08 11:03:22 +00:00
|
|
|
private boolean maybeStripSpace(final int code,
|
2012-02-08 02:48:19 +00:00
|
|
|
final int spaceState, final boolean isFromSuggestionStrip) {
|
|
|
|
if (Keyboard.CODE_ENTER == code && SPACE_STATE_SWAP_PUNCTUATION == spaceState) {
|
2012-06-08 11:23:13 +00:00
|
|
|
mConnection.removeTrailingSpace();
|
2012-02-08 02:48:19 +00:00
|
|
|
return false;
|
|
|
|
} else if ((SPACE_STATE_WEAK == spaceState
|
|
|
|
|| SPACE_STATE_SWAP_PUNCTUATION == spaceState)
|
|
|
|
&& isFromSuggestionStrip) {
|
2012-06-08 12:34:07 +00:00
|
|
|
if (mCurrentSettings.isWeakSpaceSwapper(code)) {
|
2012-02-08 02:48:19 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
2012-06-08 12:34:07 +00:00
|
|
|
if (mCurrentSettings.isWeakSpaceStripper(code)) {
|
2012-06-08 11:23:13 +00:00
|
|
|
mConnection.removeTrailingSpace();
|
2012-02-08 02:48:19 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-06 05:56:46 +00:00
|
|
|
private void handleCharacter(final int primaryCode, final int x,
|
2011-10-25 12:14:33 +00:00
|
|
|
final int y, final int spaceState) {
|
2011-12-13 14:24:37 +00:00
|
|
|
boolean isComposingWord = mWordComposer.isComposingWord();
|
2012-02-02 08:18:03 +00:00
|
|
|
|
|
|
|
if (SPACE_STATE_PHANTOM == spaceState &&
|
2012-06-08 12:34:07 +00:00
|
|
|
!mCurrentSettings.isSymbolExcludedFromWordSeparators(primaryCode)) {
|
2012-02-02 08:18:03 +00:00
|
|
|
if (isComposingWord) {
|
|
|
|
// Sanity check
|
|
|
|
throw new RuntimeException("Should not be composing here");
|
|
|
|
}
|
2012-02-07 08:07:23 +00:00
|
|
|
sendKeyCodePoint(Keyboard.CODE_SPACE);
|
2012-02-02 08:18:03 +00:00
|
|
|
}
|
|
|
|
|
2012-05-09 06:45:35 +00:00
|
|
|
// NOTE: isCursorTouchingWord() is a blocking IPC call, so it often takes several
|
|
|
|
// dozen milliseconds. Avoid calling it as much as possible, since we are on the UI
|
|
|
|
// thread here.
|
|
|
|
if (!isComposingWord && (isAlphabet(primaryCode)
|
2012-06-08 12:34:07 +00:00
|
|
|
|| mCurrentSettings.isSymbolExcludedFromWordSeparators(primaryCode))
|
2012-06-12 01:00:07 +00:00
|
|
|
&& mCurrentSettings.isSuggestionsRequested(mDisplayOrientation) &&
|
2012-06-08 12:34:07 +00:00
|
|
|
!mConnection.isCursorTouchingWord(mCurrentSettings)) {
|
2012-05-09 06:19:35 +00:00
|
|
|
// Reset entirely the composing state anyway, then start composing a new word unless
|
|
|
|
// the character is a single quote. The idea here is, single quote is not a
|
|
|
|
// separator and it should be treated as a normal character, except in the first
|
|
|
|
// position where it should not start composing a word.
|
|
|
|
isComposingWord = (Keyboard.CODE_SINGLE_QUOTE != primaryCode);
|
|
|
|
// Here we don't need to reset the last composed word. It will be reset
|
|
|
|
// when we commit this one, if we ever do; if on the other hand we backspace
|
|
|
|
// it entirely and resume suggestions on the previous word, we'd like to still
|
|
|
|
// have touch coordinates for it.
|
|
|
|
resetComposingState(false /* alsoResetLastComposedWord */);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2011-12-13 13:06:02 +00:00
|
|
|
if (isComposingWord) {
|
2012-07-04 07:55:51 +00:00
|
|
|
final int keyX, keyY;
|
|
|
|
if (KeyboardActionListener.Adapter.isInvalidCoordinate(x)
|
|
|
|
|| KeyboardActionListener.Adapter.isInvalidCoordinate(y)) {
|
|
|
|
keyX = x;
|
|
|
|
keyY = y;
|
|
|
|
} else {
|
|
|
|
final KeyDetector keyDetector =
|
|
|
|
mKeyboardSwitcher.getKeyboardView().getKeyDetector();
|
|
|
|
keyX = keyDetector.getTouchX(x);
|
|
|
|
keyY = keyDetector.getTouchY(y);
|
|
|
|
}
|
|
|
|
mWordComposer.add(primaryCode, keyX, keyY);
|
2012-06-08 10:04:09 +00:00
|
|
|
// If it's the first letter, make note of auto-caps state
|
|
|
|
if (mWordComposer.size() == 1) {
|
|
|
|
mWordComposer.setAutoCapitalized(
|
|
|
|
getCurrentAutoCapsState() != Constants.TextUtils.CAP_MODE_OFF);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2012-06-08 10:04:09 +00:00
|
|
|
mConnection.setComposingText(getTextWithUnderline(mWordComposer.getTypedWord()), 1);
|
2009-03-13 22:11:42 +00:00
|
|
|
} else {
|
2012-06-08 11:03:22 +00:00
|
|
|
final boolean swapWeakSpace = maybeStripSpace(primaryCode,
|
2012-02-08 02:48:19 +00:00
|
|
|
spaceState, KeyboardActionListener.SUGGESTION_STRIP_COORDINATE == x);
|
2011-05-09 07:54:07 +00:00
|
|
|
|
2012-02-07 08:07:23 +00:00
|
|
|
sendKeyCodePoint(primaryCode);
|
2012-02-08 02:48:19 +00:00
|
|
|
|
|
|
|
if (swapWeakSpace) {
|
2012-06-08 11:23:13 +00:00
|
|
|
swapSwapperAndSpace();
|
2012-02-08 02:48:19 +00:00
|
|
|
mSpaceState = SPACE_STATE_WEAK;
|
|
|
|
}
|
2012-07-06 02:31:52 +00:00
|
|
|
// In case the "add to dictionary" hint was still displayed.
|
2012-07-23 06:28:28 +00:00
|
|
|
if (null != mSuggestionStripView) mSuggestionStripView.dismissAddToDictionaryHint();
|
2012-02-08 02:48:19 +00:00
|
|
|
}
|
2012-07-06 02:33:16 +00:00
|
|
|
mHandler.postUpdateSuggestionStrip();
|
2012-02-08 02:48:19 +00:00
|
|
|
Utils.Stats.onNonSeparator((char)primaryCode, x, y);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2012-01-26 08:20:51 +00:00
|
|
|
// Returns true if we did an autocorrection, false otherwise.
|
|
|
|
private boolean handleSeparator(final int primaryCode, final int x, final int y,
|
2011-10-25 12:14:33 +00:00
|
|
|
final int spaceState) {
|
2012-01-26 08:20:51 +00:00
|
|
|
boolean didAutoCorrect = false;
|
2009-03-13 22:11:42 +00:00
|
|
|
// Handle separator
|
2011-12-13 14:24:37 +00:00
|
|
|
if (mWordComposer.isComposingWord()) {
|
2009-03-13 22:11:42 +00:00
|
|
|
// In certain languages where single quote is a separator, it's better
|
2010-01-28 18:09:44 +00:00
|
|
|
// not to auto correct, but accept the typed word. For instance,
|
2009-03-13 22:11:42 +00:00
|
|
|
// in Italian dov' should not be expanded to dove' because the elision
|
|
|
|
// requires the last vowel to be removed.
|
2012-06-16 02:03:22 +00:00
|
|
|
if (mCurrentSettings.mCorrectionEnabled && primaryCode != Keyboard.CODE_SINGLE_QUOTE) {
|
2012-06-08 10:04:09 +00:00
|
|
|
commitCurrentAutoCorrection(primaryCode);
|
2012-01-26 08:20:51 +00:00
|
|
|
didAutoCorrect = true;
|
2009-03-13 22:11:42 +00:00
|
|
|
} else {
|
2012-06-08 10:04:09 +00:00
|
|
|
commitTyped(primaryCode);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
}
|
2010-02-22 14:55:45 +00:00
|
|
|
|
2012-06-08 11:03:22 +00:00
|
|
|
final boolean swapWeakSpace = maybeStripSpace(primaryCode, spaceState,
|
2012-02-08 02:48:19 +00:00
|
|
|
KeyboardActionListener.SUGGESTION_STRIP_COORDINATE == x);
|
2011-05-09 07:54:07 +00:00
|
|
|
|
2012-03-06 05:00:34 +00:00
|
|
|
if (SPACE_STATE_PHANTOM == spaceState &&
|
2012-06-08 12:34:07 +00:00
|
|
|
mCurrentSettings.isPhantomSpacePromotingSymbol(primaryCode)) {
|
2012-03-06 05:00:34 +00:00
|
|
|
sendKeyCodePoint(Keyboard.CODE_SPACE);
|
|
|
|
}
|
2012-02-07 08:07:23 +00:00
|
|
|
sendKeyCodePoint(primaryCode);
|
2011-04-20 02:50:05 +00:00
|
|
|
|
|
|
|
if (Keyboard.CODE_SPACE == primaryCode) {
|
2012-06-12 01:00:07 +00:00
|
|
|
if (mCurrentSettings.isSuggestionsRequested(mDisplayOrientation)) {
|
2012-06-08 11:23:13 +00:00
|
|
|
if (maybeDoubleSpace()) {
|
2011-10-25 12:14:33 +00:00
|
|
|
mSpaceState = SPACE_STATE_DOUBLE;
|
|
|
|
} else if (!isShowingPunctuationList()) {
|
|
|
|
mSpaceState = SPACE_STATE_WEAK;
|
|
|
|
}
|
2011-10-24 09:00:05 +00:00
|
|
|
}
|
2011-10-25 12:14:33 +00:00
|
|
|
|
|
|
|
mHandler.startDoubleSpacesTimer();
|
2012-06-08 12:34:07 +00:00
|
|
|
if (!mConnection.isCursorTouchingWord(mCurrentSettings)) {
|
2012-07-06 02:33:16 +00:00
|
|
|
mHandler.postUpdateSuggestionStrip();
|
2011-04-20 02:50:05 +00:00
|
|
|
}
|
|
|
|
} else {
|
2012-02-02 08:18:03 +00:00
|
|
|
if (swapWeakSpace) {
|
2012-06-08 11:23:13 +00:00
|
|
|
swapSwapperAndSpace();
|
2012-02-09 02:34:00 +00:00
|
|
|
mSpaceState = SPACE_STATE_SWAP_PUNCTUATION;
|
2012-07-27 15:49:43 +00:00
|
|
|
} else if (SPACE_STATE_PHANTOM == spaceState
|
|
|
|
&& !mCurrentSettings.isWeakSpaceStripper(primaryCode)) {
|
2012-02-02 08:18:03 +00:00
|
|
|
// If we are in phantom space state, and the user presses a separator, we want to
|
|
|
|
// stay in phantom space state so that the next keypress has a chance to add the
|
|
|
|
// space. For example, if I type "Good dat", pick "day" from the suggestion strip
|
|
|
|
// then insert a comma and go on to typing the next word, I want the space to be
|
|
|
|
// inserted automatically before the next word, the same way it is when I don't
|
|
|
|
// input the comma.
|
2012-07-27 15:49:43 +00:00
|
|
|
// The case is a little different if the separator is a space stripper. Such a
|
|
|
|
// separator does not normally need a space on the right (that's the difference
|
|
|
|
// between swappers and strippers), so we should not stay in phantom space state if
|
|
|
|
// the separator is a stripper. Hence the additional test above.
|
2012-02-02 08:18:03 +00:00
|
|
|
mSpaceState = SPACE_STATE_PHANTOM;
|
2011-10-25 12:14:33 +00:00
|
|
|
}
|
|
|
|
|
2011-04-20 02:50:05 +00:00
|
|
|
// Set punctuation right away. onUpdateSelection will fire but tests whether it is
|
|
|
|
// already displayed or not, so it's okay.
|
2010-12-09 07:36:45 +00:00
|
|
|
setPunctuationSuggestions();
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2011-10-25 12:14:33 +00:00
|
|
|
|
2011-12-12 07:22:07 +00:00
|
|
|
Utils.Stats.onSeparator((char)primaryCode, x, y);
|
2011-10-25 12:14:33 +00:00
|
|
|
|
2012-01-26 08:20:51 +00:00
|
|
|
return didAutoCorrect;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-01-16 20:21:23 +00:00
|
|
|
|
2011-12-13 07:11:50 +00:00
|
|
|
private CharSequence getTextWithUnderline(final CharSequence text) {
|
2012-03-07 06:31:22 +00:00
|
|
|
return mIsAutoCorrectionIndicatorOn
|
2011-12-13 07:11:50 +00:00
|
|
|
? SuggestionSpanUtils.getTextWithAutoCorrectionIndicatorUnderline(this, text)
|
2012-01-26 02:40:16 +00:00
|
|
|
: text;
|
2011-12-13 07:11:50 +00:00
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
private void handleClose() {
|
2012-06-08 10:04:09 +00:00
|
|
|
commitTyped(LastComposedWord.NOT_A_SEPARATOR);
|
2009-03-13 22:11:42 +00:00
|
|
|
requestHideSelf(0);
|
2012-07-23 01:27:14 +00:00
|
|
|
MainKeyboardView inputView = mKeyboardSwitcher.getKeyboardView();
|
2010-11-13 08:01:13 +00:00
|
|
|
if (inputView != null)
|
|
|
|
inputView.closing();
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2012-07-09 03:54:42 +00:00
|
|
|
// TODO: make this private
|
|
|
|
// Outside LatinIME, only used by the test suite.
|
|
|
|
/* package for tests */ boolean isShowingPunctuationList() {
|
2012-07-23 06:28:28 +00:00
|
|
|
if (mSuggestionStripView == null) return false;
|
|
|
|
return mCurrentSettings.mSuggestPuncList == mSuggestionStripView.getSuggestions();
|
2010-11-13 10:09:30 +00:00
|
|
|
}
|
|
|
|
|
2012-07-09 03:54:42 +00:00
|
|
|
private boolean isSuggestionsStripVisible() {
|
2012-07-23 06:28:28 +00:00
|
|
|
if (mSuggestionStripView == null)
|
2011-01-26 16:33:02 +00:00
|
|
|
return false;
|
2012-07-23 06:28:28 +00:00
|
|
|
if (mSuggestionStripView.isShowingAddToDictionaryHint())
|
2010-12-19 08:32:26 +00:00
|
|
|
return true;
|
2012-06-11 23:16:16 +00:00
|
|
|
if (!mCurrentSettings.isSuggestionStripVisibleInOrientation(mDisplayOrientation))
|
2010-12-19 08:32:26 +00:00
|
|
|
return false;
|
2012-06-12 00:35:51 +00:00
|
|
|
if (mCurrentSettings.isApplicationSpecifiedCompletionsOn())
|
2010-12-19 08:32:26 +00:00
|
|
|
return true;
|
2012-06-12 01:00:07 +00:00
|
|
|
return mCurrentSettings.isSuggestionsRequested(mDisplayOrientation);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2012-07-23 09:03:16 +00:00
|
|
|
private void clearSuggestionStrip() {
|
|
|
|
setSuggestionStrip(SuggestedWords.EMPTY, false);
|
2012-03-02 11:04:42 +00:00
|
|
|
setAutoCorrectionIndicator(false);
|
2010-01-16 20:21:23 +00:00
|
|
|
}
|
|
|
|
|
2012-07-23 09:03:16 +00:00
|
|
|
private void setSuggestionStrip(final SuggestedWords words, final boolean isAutoCorrection) {
|
2012-07-23 06:28:28 +00:00
|
|
|
if (mSuggestionStripView != null) {
|
|
|
|
mSuggestionStripView.setSuggestions(words);
|
2012-03-02 11:33:23 +00:00
|
|
|
mKeyboardSwitcher.onAutoCorrectionStateChanged(isAutoCorrection);
|
2010-01-16 20:21:23 +00:00
|
|
|
}
|
2012-03-02 10:52:06 +00:00
|
|
|
}
|
2011-09-28 06:59:11 +00:00
|
|
|
|
2012-03-02 11:01:34 +00:00
|
|
|
private void setAutoCorrectionIndicator(final boolean newAutoCorrectionIndicator) {
|
2011-09-28 06:59:11 +00:00
|
|
|
// Put a blue underline to a word in TextView which will be auto-corrected.
|
2012-03-15 06:53:55 +00:00
|
|
|
if (mIsAutoCorrectionIndicatorOn != newAutoCorrectionIndicator
|
|
|
|
&& mWordComposer.isComposingWord()) {
|
|
|
|
mIsAutoCorrectionIndicatorOn = newAutoCorrectionIndicator;
|
|
|
|
final CharSequence textWithUnderline =
|
|
|
|
getTextWithUnderline(mWordComposer.getTypedWord());
|
2012-06-08 10:04:09 +00:00
|
|
|
mConnection.setComposingText(textWithUnderline, 1);
|
2011-09-28 06:59:11 +00:00
|
|
|
}
|
2010-01-16 20:21:23 +00:00
|
|
|
}
|
|
|
|
|
2012-07-23 02:59:11 +00:00
|
|
|
private void updateSuggestionStrip() {
|
2012-07-05 02:34:48 +00:00
|
|
|
mHandler.cancelUpdateSuggestionStrip();
|
2012-06-28 06:48:23 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
// Check if we have a suggestion engine attached.
|
2012-06-29 06:20:28 +00:00
|
|
|
if (mSuggest == null || !mCurrentSettings.isSuggestionsRequested(mDisplayOrientation)) {
|
2012-01-17 06:17:17 +00:00
|
|
|
if (mWordComposer.isComposingWord()) {
|
2012-06-29 06:20:28 +00:00
|
|
|
Log.w(TAG, "Called updateSuggestionsOrPredictions but suggestions were not "
|
|
|
|
+ "requested!");
|
2012-01-17 06:17:17 +00:00
|
|
|
mWordComposer.setAutoCorrection(mWordComposer.getTypedWord());
|
|
|
|
}
|
2012-07-23 02:59:11 +00:00
|
|
|
return;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-01-16 20:21:23 +00:00
|
|
|
|
2012-07-06 05:52:22 +00:00
|
|
|
if (!mWordComposer.isComposingWord() && !mCurrentSettings.mBigramPredictionEnabled) {
|
|
|
|
setPunctuationSuggestions();
|
2012-07-23 02:59:11 +00:00
|
|
|
return;
|
2012-07-06 05:52:22 +00:00
|
|
|
}
|
|
|
|
|
2012-07-23 02:59:11 +00:00
|
|
|
final SuggestedWords suggestedWords = getSuggestedWords();
|
|
|
|
final String typedWord = mWordComposer.getTypedWord();
|
|
|
|
showSuggestionStrip(suggestedWords, typedWord);
|
|
|
|
}
|
|
|
|
|
|
|
|
private SuggestedWords getSuggestedWords() {
|
|
|
|
final String typedWord = mWordComposer.getTypedWord();
|
2012-07-06 07:14:52 +00:00
|
|
|
// Get the word on which we should search the bigrams. If we are composing a word, it's
|
|
|
|
// whatever is *before* the half-committed word in the buffer, hence 2; if we aren't, we
|
|
|
|
// should just skip whitespace if any, so 1.
|
|
|
|
// TODO: this is slow (2-way IPC) - we should probably cache this instead.
|
|
|
|
final CharSequence prevWord =
|
|
|
|
mConnection.getNthPreviousWord(mCurrentSettings.mWordSeparators,
|
|
|
|
mWordComposer.isComposingWord() ? 2 : 1);
|
2012-07-23 02:59:11 +00:00
|
|
|
final SuggestedWords suggestedWords = mSuggest.getSuggestedWords(mWordComposer,
|
2012-07-06 07:14:52 +00:00
|
|
|
prevWord, mKeyboardSwitcher.getKeyboard().getProximityInfo(),
|
2012-07-10 10:31:36 +00:00
|
|
|
mCurrentSettings.mCorrectionEnabled);
|
2012-07-23 02:59:11 +00:00
|
|
|
return maybeRetrieveOlderSuggestions(typedWord, suggestedWords);
|
2012-06-29 06:20:28 +00:00
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
|
2012-07-06 07:14:52 +00:00
|
|
|
private SuggestedWords maybeRetrieveOlderSuggestions(final CharSequence typedWord,
|
|
|
|
final SuggestedWords suggestedWords) {
|
|
|
|
// TODO: consolidate this into getSuggestedWords
|
2012-07-06 07:20:04 +00:00
|
|
|
// We update the suggestion strip only when we have some suggestions to show, i.e. when
|
|
|
|
// the suggestion count is > 1; else, we leave the old suggestions, with the typed word
|
|
|
|
// replaced with the new one. However, when the word is a dictionary word, or when the
|
|
|
|
// length of the typed word is 1 or 0 (after a deletion typically), we do want to remove the
|
|
|
|
// old suggestions. Also, if we are showing the "add to dictionary" hint, we need to
|
|
|
|
// revert to suggestions - although it is unclear how we can come here if it's displayed.
|
|
|
|
if (suggestedWords.size() > 1 || typedWord.length() <= 1
|
2012-06-28 09:28:29 +00:00
|
|
|
|| !suggestedWords.mTypedWordValid
|
2012-07-23 06:28:28 +00:00
|
|
|
|| mSuggestionStripView.isShowingAddToDictionaryHint()) {
|
2012-06-29 06:54:51 +00:00
|
|
|
return suggestedWords;
|
2012-03-09 06:52:23 +00:00
|
|
|
} else {
|
2012-07-23 06:28:28 +00:00
|
|
|
SuggestedWords previousSuggestions = mSuggestionStripView.getSuggestions();
|
2012-06-08 12:34:07 +00:00
|
|
|
if (previousSuggestions == mCurrentSettings.mSuggestPuncList) {
|
2012-03-09 06:52:23 +00:00
|
|
|
previousSuggestions = SuggestedWords.EMPTY;
|
2011-05-13 11:27:01 +00:00
|
|
|
}
|
2012-03-13 09:21:35 +00:00
|
|
|
final ArrayList<SuggestedWords.SuggestedWordInfo> typedWordAndPreviousSuggestions =
|
2012-03-13 11:39:21 +00:00
|
|
|
SuggestedWords.getTypedWordAndPreviousSuggestions(
|
2012-03-13 09:21:35 +00:00
|
|
|
typedWord, previousSuggestions);
|
2012-06-29 06:54:51 +00:00
|
|
|
return new SuggestedWords(typedWordAndPreviousSuggestions,
|
2012-03-13 11:05:00 +00:00
|
|
|
false /* typedWordValid */,
|
2012-03-14 06:59:04 +00:00
|
|
|
false /* hasAutoCorrectionCandidate */,
|
2012-03-15 04:12:08 +00:00
|
|
|
false /* isPunctuationSuggestions */,
|
2012-05-14 05:42:40 +00:00
|
|
|
true /* isObsoleteSuggestions */,
|
|
|
|
false /* isPrediction */);
|
2010-12-19 08:32:26 +00:00
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|
2009-07-23 19:17:48 +00:00
|
|
|
|
2012-07-23 09:03:16 +00:00
|
|
|
private void showSuggestionStrip(final SuggestedWords suggestedWords,
|
2012-06-29 06:20:28 +00:00
|
|
|
final CharSequence typedWord) {
|
2012-07-11 09:49:44 +00:00
|
|
|
if (null == suggestedWords || suggestedWords.size() <= 0) {
|
2012-07-23 09:03:16 +00:00
|
|
|
clearSuggestionStrip();
|
2012-07-11 09:49:44 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-03-02 09:54:50 +00:00
|
|
|
final CharSequence autoCorrection;
|
2010-12-10 11:50:30 +00:00
|
|
|
if (suggestedWords.size() > 0) {
|
2012-06-28 10:43:09 +00:00
|
|
|
if (suggestedWords.mWillAutoCorrect) {
|
2012-03-02 09:54:50 +00:00
|
|
|
autoCorrection = suggestedWords.getWord(1);
|
2009-03-13 22:11:42 +00:00
|
|
|
} else {
|
2012-03-02 09:54:50 +00:00
|
|
|
autoCorrection = typedWord;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
} else {
|
2012-03-02 09:54:50 +00:00
|
|
|
autoCorrection = null;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2012-03-02 09:54:50 +00:00
|
|
|
mWordComposer.setAutoCorrection(autoCorrection);
|
2012-03-05 05:19:35 +00:00
|
|
|
final boolean isAutoCorrection = suggestedWords.willAutoCorrect();
|
2012-07-23 09:03:16 +00:00
|
|
|
setSuggestionStrip(suggestedWords, isAutoCorrection);
|
2012-03-02 11:33:23 +00:00
|
|
|
setAutoCorrectionIndicator(isAutoCorrection);
|
2011-09-01 05:54:28 +00:00
|
|
|
setSuggestionStripShown(isSuggestionsStripVisible());
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2012-06-08 10:04:09 +00:00
|
|
|
private void commitCurrentAutoCorrection(final int separatorCodePoint) {
|
2011-09-01 05:54:28 +00:00
|
|
|
// Complete any pending suggestions query first
|
2010-11-16 09:07:06 +00:00
|
|
|
if (mHandler.hasPendingUpdateSuggestions()) {
|
2012-07-23 09:03:16 +00:00
|
|
|
updateSuggestionStrip();
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2012-06-12 10:40:37 +00:00
|
|
|
final CharSequence typedAutoCorrection = mWordComposer.getAutoCorrectionOrNull();
|
|
|
|
final String typedWord = mWordComposer.getTypedWord();
|
|
|
|
final CharSequence autoCorrection = (typedAutoCorrection != null)
|
|
|
|
? typedAutoCorrection : typedWord;
|
2011-12-13 10:38:36 +00:00
|
|
|
if (autoCorrection != null) {
|
2011-12-14 08:54:18 +00:00
|
|
|
if (TextUtils.isEmpty(typedWord)) {
|
|
|
|
throw new RuntimeException("We have an auto-correction but the typed word "
|
|
|
|
+ "is empty? Impossible! I must commit suicide.");
|
|
|
|
}
|
2011-12-14 08:59:01 +00:00
|
|
|
Utils.Stats.onAutoCorrection(typedWord, autoCorrection.toString(), separatorCodePoint);
|
2012-04-13 00:13:52 +00:00
|
|
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
2012-04-18 01:34:02 +00:00
|
|
|
ResearchLogger.latinIME_commitCurrentAutoCorrection(typedWord,
|
2012-04-13 00:13:52 +00:00
|
|
|
autoCorrection.toString());
|
|
|
|
}
|
2011-06-08 07:47:19 +00:00
|
|
|
mExpectingUpdateSelection = true;
|
2012-02-22 07:17:54 +00:00
|
|
|
commitChosenWord(autoCorrection, LastComposedWord.COMMIT_TYPE_DECIDED_WORD,
|
|
|
|
separatorCodePoint);
|
2012-06-08 10:04:09 +00:00
|
|
|
if (!typedWord.equals(autoCorrection)) {
|
2011-12-14 08:56:57 +00:00
|
|
|
// This will make the correction flash for a short while as a visual clue
|
|
|
|
// to the user that auto-correction happened.
|
2012-06-08 10:04:09 +00:00
|
|
|
mConnection.commitCorrection(
|
|
|
|
new CorrectionInfo(mLastSelectionEnd - typedWord.length(),
|
2012-03-31 09:32:48 +00:00
|
|
|
typedWord, autoCorrection));
|
2011-12-14 08:56:57 +00:00
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-23 06:28:28 +00:00
|
|
|
// Called from {@link SuggestionStripView} through the {@link SuggestionStripView#Listener}
|
|
|
|
// interface
|
2011-06-09 05:22:37 +00:00
|
|
|
@Override
|
2012-04-12 04:42:22 +00:00
|
|
|
public void pickSuggestionManually(final int index, final CharSequence suggestion,
|
2012-06-08 14:02:37 +00:00
|
|
|
final int x, final int y) {
|
2012-07-23 06:28:28 +00:00
|
|
|
final SuggestedWords suggestedWords = mSuggestionStripView.getSuggestions();
|
2012-04-23 09:15:51 +00:00
|
|
|
// If this is a punctuation picked from the suggestion strip, pass it to onCodeInput
|
|
|
|
if (suggestion.length() == 1 && isShowingPunctuationList()) {
|
|
|
|
// Word separators are suggested before the user inputs something.
|
|
|
|
// So, LatinImeLogger logs "" as a user's input.
|
|
|
|
LatinImeLogger.logOnManualSuggestion("", suggestion.toString(), index, suggestedWords);
|
|
|
|
// Rely on onCodeInput to do the complicated swapping/stripping logic consistently.
|
|
|
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
|
|
|
ResearchLogger.latinIME_punctuationSuggestion(index, suggestion, x, y);
|
|
|
|
}
|
|
|
|
final int primaryCode = suggestion.charAt(0);
|
|
|
|
onCodeInput(primaryCode,
|
|
|
|
KeyboardActionListener.SUGGESTION_STRIP_COORDINATE,
|
|
|
|
KeyboardActionListener.SUGGESTION_STRIP_COORDINATE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-06 08:50:35 +00:00
|
|
|
mConnection.beginBatchEdit();
|
2012-06-12 10:40:37 +00:00
|
|
|
if (SPACE_STATE_PHANTOM == mSpaceState && suggestion.length() > 0
|
|
|
|
// In the batch input mode, a manually picked suggested word should just replace
|
|
|
|
// the current batch input text and there is no need for a phantom space.
|
|
|
|
&& !mWordComposer.isBatchMode()) {
|
2012-03-07 06:59:53 +00:00
|
|
|
int firstChar = Character.codePointAt(suggestion, 0);
|
2012-06-08 12:34:07 +00:00
|
|
|
if ((!mCurrentSettings.isWeakSpaceStripper(firstChar))
|
|
|
|
&& (!mCurrentSettings.isWeakSpaceSwapper(firstChar))) {
|
2012-03-07 06:59:53 +00:00
|
|
|
sendKeyCodePoint(Keyboard.CODE_SPACE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-12 00:35:51 +00:00
|
|
|
if (mCurrentSettings.isApplicationSpecifiedCompletionsOn()
|
2011-12-16 03:57:27 +00:00
|
|
|
&& mApplicationSpecifiedCompletions != null
|
2010-12-11 08:06:24 +00:00
|
|
|
&& index >= 0 && index < mApplicationSpecifiedCompletions.length) {
|
2012-07-23 06:28:28 +00:00
|
|
|
if (mSuggestionStripView != null) {
|
|
|
|
mSuggestionStripView.clear();
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-11-13 08:16:34 +00:00
|
|
|
mKeyboardSwitcher.updateShiftState();
|
2012-03-05 08:39:01 +00:00
|
|
|
resetComposingState(true /* alsoResetLastComposedWord */);
|
2012-06-08 10:04:09 +00:00
|
|
|
final CompletionInfo completionInfo = mApplicationSpecifiedCompletions[index];
|
|
|
|
mConnection.commitCompletion(completionInfo);
|
2012-06-08 14:02:37 +00:00
|
|
|
mConnection.endBatchEdit();
|
2012-06-08 10:04:09 +00:00
|
|
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
|
|
|
ResearchLogger.latinIME_pickApplicationSpecifiedCompletion(index,
|
|
|
|
completionInfo.getText(), x, y);
|
2010-02-07 00:34:43 +00:00
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-02-03 23:35:49 +00:00
|
|
|
|
2012-01-20 06:39:06 +00:00
|
|
|
// We need to log before we commit, because the word composer will store away the user
|
|
|
|
// typed word.
|
2012-04-12 04:42:22 +00:00
|
|
|
final String replacedWord = mWordComposer.getTypedWord().toString();
|
|
|
|
LatinImeLogger.logOnManualSuggestion(replacedWord,
|
2012-03-05 07:56:58 +00:00
|
|
|
suggestion.toString(), index, suggestedWords);
|
2012-04-12 04:42:22 +00:00
|
|
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
|
|
|
ResearchLogger.latinIME_pickSuggestionManually(replacedWord, index, suggestion, x, y);
|
|
|
|
}
|
2011-06-08 07:47:19 +00:00
|
|
|
mExpectingUpdateSelection = true;
|
2012-02-22 07:17:54 +00:00
|
|
|
commitChosenWord(suggestion, LastComposedWord.COMMIT_TYPE_MANUAL_PICK,
|
|
|
|
LastComposedWord.NOT_A_SEPARATOR);
|
2012-07-06 08:50:35 +00:00
|
|
|
mConnection.endBatchEdit();
|
2012-04-20 06:55:19 +00:00
|
|
|
// Don't allow cancellation of manual pick
|
|
|
|
mLastComposedWord.deactivate();
|
2012-02-02 08:18:03 +00:00
|
|
|
mSpaceState = SPACE_STATE_PHANTOM;
|
|
|
|
// TODO: is this necessary?
|
|
|
|
mKeyboardSwitcher.updateShiftState();
|
2010-08-20 05:35:02 +00:00
|
|
|
|
2011-08-08 09:33:56 +00:00
|
|
|
// We should show the "Touch again to save" hint if the user pressed the first entry
|
2012-07-23 09:30:53 +00:00
|
|
|
// AND it's in none of our current dictionaries (main, user or otherwise).
|
2011-02-23 13:04:47 +00:00
|
|
|
// Please note that if mSuggest is null, it means that everything is off: suggestion
|
|
|
|
// and correction, so we shouldn't try to show the hint
|
2011-03-04 07:56:10 +00:00
|
|
|
final boolean showingAddToDictionaryHint = index == 0 && mSuggest != null
|
2012-07-23 09:30:53 +00:00
|
|
|
// If the suggestion is not in the dictionary, the hint should be shown.
|
|
|
|
&& !AutoCorrection.isValidWord(mSuggest.getUnigramDictionaries(), suggestion, true);
|
2010-08-26 19:22:58 +00:00
|
|
|
|
2011-12-12 07:22:07 +00:00
|
|
|
Utils.Stats.onSeparator((char)Keyboard.CODE_SPACE, WordComposer.NOT_A_COORDINATE,
|
|
|
|
WordComposer.NOT_A_COORDINATE);
|
2012-07-05 03:45:42 +00:00
|
|
|
if (showingAddToDictionaryHint && mIsUserDictionaryAvailable) {
|
2012-07-23 06:28:28 +00:00
|
|
|
mSuggestionStripView.showAddToDictionaryHint(
|
|
|
|
suggestion, mCurrentSettings.mHintToSaveText);
|
2012-07-05 03:45:42 +00:00
|
|
|
} else {
|
2012-07-06 02:31:52 +00:00
|
|
|
// If we're not showing the "Touch again to save", then update the suggestion strip.
|
2012-07-06 02:33:16 +00:00
|
|
|
mHandler.postUpdateSuggestionStrip();
|
2010-02-11 01:45:35 +00:00
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-08-20 05:35:02 +00:00
|
|
|
/**
|
2011-07-12 07:47:08 +00:00
|
|
|
* Commits the chosen word to the text field and saves it for later retrieval.
|
2010-08-20 05:35:02 +00:00
|
|
|
*/
|
2012-05-24 03:11:02 +00:00
|
|
|
private void commitChosenWord(final CharSequence chosenWord, final int commitType,
|
2012-02-22 07:17:54 +00:00
|
|
|
final int separatorCode) {
|
2012-07-23 06:28:28 +00:00
|
|
|
final SuggestedWords suggestedWords = mSuggestionStripView.getSuggestions();
|
2012-06-16 02:06:29 +00:00
|
|
|
mConnection.commitText(SuggestionSpanUtils.getTextWithSuggestionSpan(
|
|
|
|
this, chosenWord, suggestedWords, mIsMainDictionaryAvailable), 1);
|
2012-06-08 13:09:20 +00:00
|
|
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
|
|
|
ResearchLogger.latinIME_commitText(chosenWord);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2012-05-24 03:11:02 +00:00
|
|
|
// Add the word to the user history dictionary
|
|
|
|
final CharSequence prevWord = addToUserHistoryDictionary(chosenWord);
|
2011-12-20 08:52:29 +00:00
|
|
|
// TODO: figure out here if this is an auto-correct or if the best word is actually
|
|
|
|
// what user typed. Note: currently this is done much later in
|
2012-02-22 08:15:10 +00:00
|
|
|
// LastComposedWord#didCommitTypedWord by string equality of the remembered
|
2011-12-20 08:52:29 +00:00
|
|
|
// strings.
|
2012-05-24 03:11:02 +00:00
|
|
|
mLastComposedWord = mWordComposer.commitWord(commitType, chosenWord.toString(),
|
|
|
|
separatorCode, prevWord);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2012-07-09 03:54:42 +00:00
|
|
|
private void setPunctuationSuggestions() {
|
2012-06-15 00:03:52 +00:00
|
|
|
if (mCurrentSettings.mBigramPredictionEnabled) {
|
2012-07-23 09:03:16 +00:00
|
|
|
clearSuggestionStrip();
|
2012-06-14 18:52:48 +00:00
|
|
|
} else {
|
2012-07-23 09:03:16 +00:00
|
|
|
setSuggestionStrip(mCurrentSettings.mSuggestPuncList, false);
|
2012-06-14 18:52:48 +00:00
|
|
|
}
|
2012-03-02 11:04:42 +00:00
|
|
|
setAutoCorrectionIndicator(false);
|
2011-09-01 05:54:28 +00:00
|
|
|
setSuggestionStripShown(isSuggestionsStripVisible());
|
2010-02-03 23:35:49 +00:00
|
|
|
}
|
|
|
|
|
2012-05-24 03:11:02 +00:00
|
|
|
private CharSequence addToUserHistoryDictionary(final CharSequence suggestion) {
|
|
|
|
if (TextUtils.isEmpty(suggestion)) return null;
|
2011-03-04 07:56:10 +00:00
|
|
|
|
2012-06-16 02:03:22 +00:00
|
|
|
// If correction is not enabled, we don't add words to the user history dictionary.
|
|
|
|
// That's to avoid unintended additions in some sensitive fields, or fields that
|
|
|
|
// expect to receive non-words.
|
|
|
|
if (!mCurrentSettings.mCorrectionEnabled) return null;
|
2011-03-04 07:56:10 +00:00
|
|
|
|
2012-06-18 18:28:19 +00:00
|
|
|
final UserHistoryDictionary userHistoryDictionary = mUserHistoryDictionary;
|
|
|
|
if (userHistoryDictionary != null) {
|
2012-06-08 10:44:38 +00:00
|
|
|
final CharSequence prevWord
|
2012-07-06 03:34:41 +00:00
|
|
|
= mConnection.getNthPreviousWord(mCurrentSettings.mWordSeparators, 2);
|
2012-03-23 12:35:56 +00:00
|
|
|
final String secondWord;
|
|
|
|
if (mWordComposer.isAutoCapitalized() && !mWordComposer.isMostlyCaps()) {
|
2012-04-19 14:11:31 +00:00
|
|
|
secondWord = suggestion.toString().toLowerCase(
|
|
|
|
mSubtypeSwitcher.getCurrentSubtypeLocale());
|
2012-03-23 12:35:56 +00:00
|
|
|
} else {
|
|
|
|
secondWord = suggestion.toString();
|
|
|
|
}
|
2012-06-14 03:39:14 +00:00
|
|
|
// We demote unrecognized words (frequency < 0, below) by specifying them as "invalid".
|
|
|
|
// We don't add words with 0-frequency (assuming they would be profanity etc.).
|
2012-05-29 10:07:22 +00:00
|
|
|
final int maxFreq = AutoCorrection.getMaxFrequency(
|
|
|
|
mSuggest.getUnigramDictionaries(), suggestion);
|
2012-06-14 03:39:14 +00:00
|
|
|
if (maxFreq == 0) return null;
|
2012-06-18 18:28:19 +00:00
|
|
|
userHistoryDictionary.addToUserHistory(null == prevWord ? null : prevWord.toString(),
|
2012-05-29 10:07:22 +00:00
|
|
|
secondWord, maxFreq > 0);
|
2012-05-24 03:11:02 +00:00
|
|
|
return prevWord;
|
2010-02-20 00:38:58 +00:00
|
|
|
}
|
2012-05-24 03:11:02 +00:00
|
|
|
return null;
|
2010-02-20 00:38:58 +00:00
|
|
|
}
|
|
|
|
|
2011-11-22 02:35:40 +00:00
|
|
|
/**
|
|
|
|
* Check if the cursor is actually at the end of a word. If so, restart suggestions on this
|
|
|
|
* word, else do nothing.
|
|
|
|
*/
|
2012-06-08 10:04:09 +00:00
|
|
|
private void restartSuggestionsOnWordBeforeCursorIfAtEndOfWord() {
|
2012-06-08 12:45:41 +00:00
|
|
|
final CharSequence word = mConnection.getWordBeforeCursorIfAtEndOfWord(mCurrentSettings);
|
|
|
|
if (null != word) {
|
|
|
|
restartSuggestionsOnWordBeforeCursor(word);
|
2012-01-17 05:58:27 +00:00
|
|
|
}
|
2011-11-22 02:35:40 +00:00
|
|
|
}
|
|
|
|
|
2012-06-08 10:04:09 +00:00
|
|
|
private void restartSuggestionsOnWordBeforeCursor(final CharSequence word) {
|
2011-12-17 23:36:16 +00:00
|
|
|
mWordComposer.setComposingWord(word, mKeyboardSwitcher.getKeyboard());
|
2012-04-18 01:34:02 +00:00
|
|
|
final int length = word.length();
|
2012-06-08 10:04:09 +00:00
|
|
|
mConnection.deleteSurroundingText(length, 0);
|
2012-04-18 01:34:02 +00:00
|
|
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
|
|
|
ResearchLogger.latinIME_deleteSurroundingText(length);
|
|
|
|
}
|
2012-06-08 10:04:09 +00:00
|
|
|
mConnection.setComposingText(word, 1);
|
2012-07-06 02:33:16 +00:00
|
|
|
mHandler.postUpdateSuggestionStrip();
|
2011-11-22 02:35:40 +00:00
|
|
|
}
|
|
|
|
|
2012-06-08 10:04:09 +00:00
|
|
|
private void revertCommit() {
|
2012-05-24 03:11:02 +00:00
|
|
|
final CharSequence previousWord = mLastComposedWord.mPrevWord;
|
2012-01-26 08:16:40 +00:00
|
|
|
final String originallyTypedWord = mLastComposedWord.mTypedWord;
|
2012-02-22 07:11:07 +00:00
|
|
|
final CharSequence committedWord = mLastComposedWord.mCommittedWord;
|
|
|
|
final int cancelLength = committedWord.length();
|
2012-03-06 05:56:46 +00:00
|
|
|
final int separatorLength = LastComposedWord.getSeparatorLength(
|
2012-02-22 07:48:37 +00:00
|
|
|
mLastComposedWord.mSeparatorCode);
|
|
|
|
// TODO: should we check our saved separator against the actual contents of the text view?
|
2012-04-18 01:34:02 +00:00
|
|
|
final int deleteLength = cancelLength + separatorLength;
|
2011-12-12 06:09:17 +00:00
|
|
|
if (DEBUG) {
|
2012-01-26 08:16:40 +00:00
|
|
|
if (mWordComposer.isComposingWord()) {
|
2012-02-22 09:09:23 +00:00
|
|
|
throw new RuntimeException("revertCommit, but we are composing a word");
|
2012-01-26 08:16:40 +00:00
|
|
|
}
|
2011-12-12 06:09:17 +00:00
|
|
|
final String wordBeforeCursor =
|
2012-06-08 10:04:09 +00:00
|
|
|
mConnection.getTextBeforeCursor(deleteLength, 0)
|
2012-02-22 07:48:37 +00:00
|
|
|
.subSequence(0, cancelLength).toString();
|
2012-02-22 07:11:07 +00:00
|
|
|
if (!TextUtils.equals(committedWord, wordBeforeCursor)) {
|
2012-02-22 09:09:23 +00:00
|
|
|
throw new RuntimeException("revertCommit check failed: we thought we were "
|
2012-02-22 07:11:07 +00:00
|
|
|
+ "reverting \"" + committedWord
|
2011-12-12 06:09:17 +00:00
|
|
|
+ "\", but before the cursor we found \"" + wordBeforeCursor + "\"");
|
|
|
|
}
|
2011-07-12 07:47:08 +00:00
|
|
|
}
|
2012-06-08 10:04:09 +00:00
|
|
|
mConnection.deleteSurroundingText(deleteLength, 0);
|
2012-04-18 01:34:02 +00:00
|
|
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
|
|
|
ResearchLogger.latinIME_deleteSurroundingText(deleteLength);
|
|
|
|
}
|
2012-05-24 03:11:02 +00:00
|
|
|
if (!TextUtils.isEmpty(previousWord) && !TextUtils.isEmpty(committedWord)) {
|
|
|
|
mUserHistoryDictionary.cancelAddingUserHistory(
|
|
|
|
previousWord.toString(), committedWord.toString());
|
|
|
|
}
|
2012-07-05 02:43:03 +00:00
|
|
|
mConnection.commitText(originallyTypedWord, 1);
|
|
|
|
// Re-insert the separator
|
|
|
|
sendKeyCodePoint(mLastComposedWord.mSeparatorCode);
|
|
|
|
Utils.Stats.onSeparator(mLastComposedWord.mSeparatorCode, WordComposer.NOT_A_COORDINATE,
|
|
|
|
WordComposer.NOT_A_COORDINATE);
|
|
|
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
|
|
|
ResearchLogger.latinIME_revertCommit(originallyTypedWord);
|
2012-02-22 07:48:37 +00:00
|
|
|
}
|
2012-07-05 02:43:03 +00:00
|
|
|
// Don't restart suggestion yet. We'll restart if the user deletes the
|
|
|
|
// separator.
|
2012-01-26 08:16:40 +00:00
|
|
|
mLastComposedWord = LastComposedWord.NOT_A_COMPOSED_WORD;
|
2012-07-05 03:05:07 +00:00
|
|
|
// We have a separator between the word and the cursor: we should show predictions.
|
2012-07-06 02:33:16 +00:00
|
|
|
mHandler.postUpdateSuggestionStrip();
|
2011-12-12 06:09:17 +00:00
|
|
|
}
|
|
|
|
|
2012-07-09 03:54:42 +00:00
|
|
|
// Used by the RingCharBuffer
|
2009-03-13 22:11:42 +00:00
|
|
|
public boolean isWordSeparator(int code) {
|
2012-06-08 12:34:07 +00:00
|
|
|
return mCurrentSettings.isWordSeparator(code);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2011-04-08 10:57:13 +00:00
|
|
|
// Notify that language or mode have been changed and toggleLanguage will update KeyboardID
|
2012-07-09 03:54:42 +00:00
|
|
|
// according to new language or mode. Called from SubtypeSwitcher.
|
2011-01-18 06:28:21 +00:00
|
|
|
public void onRefreshKeyboard() {
|
2011-11-04 03:36:38 +00:00
|
|
|
// When the device locale is changed in SetupWizard etc., this method may get called via
|
|
|
|
// onConfigurationChanged before SoftInputWindow is shown.
|
2012-07-23 05:59:19 +00:00
|
|
|
initSuggest();
|
|
|
|
loadSettings();
|
2011-11-04 03:36:38 +00:00
|
|
|
if (mKeyboardSwitcher.getKeyboardView() != null) {
|
|
|
|
// Reload keyboard because the current language has been changed.
|
2012-06-08 12:34:07 +00:00
|
|
|
mKeyboardSwitcher.loadKeyboard(getCurrentInputEditorInfo(), mCurrentSettings);
|
2012-07-23 05:59:19 +00:00
|
|
|
updateKeyboardViewGestureHandlingModeByMainDictionaryAvailability();
|
2011-11-04 03:36:38 +00:00
|
|
|
}
|
2012-03-07 08:13:06 +00:00
|
|
|
// Since we just changed languages, we should re-evaluate suggestions with whatever word
|
|
|
|
// we are currently composing. If we are not composing anything, we may want to display
|
2012-07-06 02:31:52 +00:00
|
|
|
// predictions or punctuation signs (which is done by the updateSuggestionStrip anyway).
|
2012-07-06 02:33:16 +00:00
|
|
|
mHandler.postUpdateSuggestionStrip();
|
2009-10-12 20:48:35 +00:00
|
|
|
}
|
|
|
|
|
2012-07-23 05:59:19 +00:00
|
|
|
private void updateKeyboardViewGestureHandlingModeByMainDictionaryAvailability() {
|
|
|
|
final MainKeyboardView keyboardView = mKeyboardSwitcher.getKeyboardView();
|
|
|
|
if (keyboardView != null) {
|
|
|
|
final boolean shouldHandleGesture = mCurrentSettings.mGestureInputEnabled
|
|
|
|
&& mIsMainDictionaryAvailable;
|
2012-07-27 06:32:29 +00:00
|
|
|
keyboardView.setGestureHandlingMode(shouldHandleGesture,
|
|
|
|
mCurrentSettings.mGesturePreviewTrailEnabled,
|
|
|
|
mCurrentSettings.mGestureFloatingPreviewTextEnabled);
|
2012-07-23 05:59:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-21 03:11:23 +00:00
|
|
|
// TODO: Remove this method from {@link LatinIME} and move {@link FeedbackManager} to
|
2012-07-09 03:54:42 +00:00
|
|
|
// {@link KeyboardSwitcher}. Called from KeyboardSwitcher
|
2012-03-06 10:00:23 +00:00
|
|
|
public void hapticAndAudioFeedback(final int primaryCode) {
|
2012-03-07 04:11:58 +00:00
|
|
|
mFeedbackManager.hapticAndAudioFeedback(primaryCode, mKeyboardSwitcher.getKeyboardView());
|
2011-10-26 11:49:57 +00:00
|
|
|
}
|
|
|
|
|
2012-07-09 03:54:42 +00:00
|
|
|
// Callback called by PointerTracker through the KeyboardActionListener. This is called when a
|
|
|
|
// key is depressed; release matching call is onReleaseKey below.
|
2010-12-02 09:46:21 +00:00
|
|
|
@Override
|
2012-01-17 08:08:26 +00:00
|
|
|
public void onPressKey(int primaryCode) {
|
2012-02-01 06:07:25 +00:00
|
|
|
mKeyboardSwitcher.onPressKey(primaryCode);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2012-07-09 03:54:42 +00:00
|
|
|
// Callback by PointerTracker through the KeyboardActionListener. This is called when a key
|
|
|
|
// is released; press matching call is onPressKey above.
|
2010-12-02 09:46:21 +00:00
|
|
|
@Override
|
2012-01-17 08:08:26 +00:00
|
|
|
public void onReleaseKey(int primaryCode, boolean withSliding) {
|
|
|
|
mKeyboardSwitcher.onReleaseKey(primaryCode, withSliding);
|
2012-02-07 21:14:18 +00:00
|
|
|
|
|
|
|
// If accessibility is on, ensure the user receives keyboard state updates.
|
|
|
|
if (AccessibilityUtils.getInstance().isTouchExplorationEnabled()) {
|
|
|
|
switch (primaryCode) {
|
|
|
|
case Keyboard.CODE_SHIFT:
|
|
|
|
AccessibleKeyboardViewProxy.getInstance().notifyShiftState();
|
|
|
|
break;
|
|
|
|
case Keyboard.CODE_SWITCH_ALPHA_SYMBOL:
|
|
|
|
AccessibleKeyboardViewProxy.getInstance().notifySymbolsState();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-05-22 09:41:27 +00:00
|
|
|
|
|
|
|
if (Keyboard.CODE_DELETE == primaryCode) {
|
|
|
|
// This is a stopgap solution to avoid leaving a high surrogate alone in a text view.
|
|
|
|
// In the future, we need to deprecate deteleSurroundingText() and have a surrogate
|
|
|
|
// pair-friendly way of deleting characters in InputConnection.
|
2012-06-08 10:04:09 +00:00
|
|
|
final CharSequence lastChar = mConnection.getTextBeforeCursor(1, 0);
|
|
|
|
if (!TextUtils.isEmpty(lastChar) && Character.isHighSurrogate(lastChar.charAt(0))) {
|
|
|
|
mConnection.deleteSurroundingText(1, 0);
|
2012-05-22 09:41:27 +00:00
|
|
|
}
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2011-01-26 14:13:18 +00:00
|
|
|
// receive ringer mode change and network state change.
|
2009-03-13 22:11:42 +00:00
|
|
|
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
2011-01-26 14:13:18 +00:00
|
|
|
final String action = intent.getAction();
|
2012-03-06 10:00:23 +00:00
|
|
|
if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
|
2011-01-26 14:13:18 +00:00
|
|
|
mSubtypeSwitcher.onNetworkStateChanged(intent);
|
2012-03-09 02:00:23 +00:00
|
|
|
} else if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) {
|
|
|
|
mFeedbackManager.onRingerModeChanged();
|
2011-01-26 14:13:18 +00:00
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-04-13 10:53:44 +00:00
|
|
|
private void launchSettings() {
|
2012-07-19 01:00:48 +00:00
|
|
|
handleClose();
|
|
|
|
launchSubActivity(SettingsActivity.class);
|
2010-01-16 20:21:23 +00:00
|
|
|
}
|
|
|
|
|
2012-07-09 03:54:42 +00:00
|
|
|
// Called from debug code only
|
2010-09-27 03:55:21 +00:00
|
|
|
public void launchDebugSettings() {
|
2012-07-19 01:00:48 +00:00
|
|
|
handleClose();
|
|
|
|
launchSubActivity(DebugSettingsActivity.class);
|
2010-09-27 03:55:21 +00:00
|
|
|
}
|
|
|
|
|
2012-07-19 01:00:48 +00:00
|
|
|
public void launchKeyboardedDialogActivity(Class<? extends Activity> activityClass) {
|
|
|
|
// Put the text in the attached EditText into a safe, saved state before switching to a
|
|
|
|
// new activity that will also use the soft keyboard.
|
|
|
|
commitTyped(LastComposedWord.NOT_A_SEPARATOR);
|
|
|
|
launchSubActivity(activityClass);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void launchSubActivity(Class<? extends Activity> activityClass) {
|
2009-03-13 22:11:42 +00:00
|
|
|
Intent intent = new Intent();
|
2012-07-19 01:00:48 +00:00
|
|
|
intent.setClass(LatinIME.this, activityClass);
|
2009-03-13 22:11:42 +00:00
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
startActivity(intent);
|
|
|
|
}
|
|
|
|
|
2011-01-20 13:52:02 +00:00
|
|
|
private void showSubtypeSelectorAndSettings() {
|
2011-01-25 02:48:06 +00:00
|
|
|
final CharSequence title = getString(R.string.english_ime_input_options);
|
|
|
|
final CharSequence[] items = new CharSequence[] {
|
|
|
|
// TODO: Should use new string "Select active input modes".
|
|
|
|
getString(R.string.language_selection_title),
|
|
|
|
getString(R.string.english_ime_settings),
|
|
|
|
};
|
2012-04-18 08:39:57 +00:00
|
|
|
final Context context = this;
|
2011-01-25 02:48:06 +00:00
|
|
|
final DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
|
2011-01-20 13:52:02 +00:00
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface di, int position) {
|
|
|
|
di.dismiss();
|
|
|
|
switch (position) {
|
2011-01-25 02:48:06 +00:00
|
|
|
case 0:
|
2011-03-17 02:37:51 +00:00
|
|
|
Intent intent = CompatUtils.getInputLanguageSelectionIntent(
|
2012-04-18 08:39:57 +00:00
|
|
|
ImfUtils.getInputMethodIdOfThisIme(context),
|
2011-12-12 10:55:42 +00:00
|
|
|
Intent.FLAG_ACTIVITY_NEW_TASK
|
2011-01-20 13:52:02 +00:00
|
|
|
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
|
|
|
|
| Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
|
|
startActivity(intent);
|
|
|
|
break;
|
2011-01-25 17:56:09 +00:00
|
|
|
case 1:
|
|
|
|
launchSettings();
|
|
|
|
break;
|
2011-01-20 13:52:02 +00:00
|
|
|
}
|
|
|
|
}
|
2011-01-25 02:48:06 +00:00
|
|
|
};
|
2011-07-18 04:18:47 +00:00
|
|
|
final AlertDialog.Builder builder = new AlertDialog.Builder(this)
|
|
|
|
.setItems(items, listener)
|
|
|
|
.setTitle(title);
|
2012-06-04 19:27:37 +00:00
|
|
|
showOptionDialog(builder.create());
|
2011-01-20 13:52:02 +00:00
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
|
2012-07-20 18:02:39 +00:00
|
|
|
public void showOptionDialog(AlertDialog dialog) {
|
2012-04-19 14:11:31 +00:00
|
|
|
final IBinder windowToken = mKeyboardSwitcher.getKeyboardView().getWindowToken();
|
2012-04-02 13:25:08 +00:00
|
|
|
if (windowToken == null) return;
|
|
|
|
|
|
|
|
dialog.setCancelable(true);
|
|
|
|
dialog.setCanceledOnTouchOutside(true);
|
|
|
|
|
|
|
|
final Window window = dialog.getWindow();
|
|
|
|
final WindowManager.LayoutParams lp = window.getAttributes();
|
|
|
|
lp.token = windowToken;
|
|
|
|
lp.type = WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
|
|
|
|
window.setAttributes(lp);
|
|
|
|
window.addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
|
|
|
|
|
|
|
|
mOptionsDialog = dialog;
|
|
|
|
dialog.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 :");
|
2011-12-17 23:36:16 +00:00
|
|
|
final Keyboard keyboard = mKeyboardSwitcher.getKeyboard();
|
2011-12-09 10:53:36 +00:00
|
|
|
final int keyboardMode = keyboard != null ? keyboard.mId.mMode : -1;
|
|
|
|
p.println(" Keyboard mode = " + keyboardMode);
|
2012-06-12 01:00:07 +00:00
|
|
|
p.println(" mIsSuggestionsSuggestionsRequested = "
|
|
|
|
+ mCurrentSettings.isSuggestionsRequested(mDisplayOrientation));
|
2012-06-16 01:59:12 +00:00
|
|
|
p.println(" mCorrectionEnabled=" + mCurrentSettings.mCorrectionEnabled);
|
2011-12-14 10:01:17 +00:00
|
|
|
p.println(" isComposingWord=" + mWordComposer.isComposingWord());
|
2012-06-08 12:34:07 +00:00
|
|
|
p.println(" mSoundOn=" + mCurrentSettings.mSoundOn);
|
|
|
|
p.println(" mVibrateOn=" + mCurrentSettings.mVibrateOn);
|
|
|
|
p.println(" mKeyPreviewPopupOn=" + mCurrentSettings.mKeyPreviewPopupOn);
|
2012-06-12 00:35:51 +00:00
|
|
|
p.println(" inputAttributes=" + mCurrentSettings.getInputAttributesDebugString());
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
}
|