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;
|
2013-01-06 02:10:27 +00:00
|
|
|
import android.os.Build.VERSION_CODES;
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.os.Debug;
|
2012-09-12 04:03:44 +00:00
|
|
|
import android.os.Handler;
|
|
|
|
import android.os.HandlerThread;
|
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;
|
2012-10-03 08:36:45 +00:00
|
|
|
import com.android.inputmethod.annotations.UsedForTesting;
|
2011-05-23 09:30:21 +00:00
|
|
|
import com.android.inputmethod.compat.CompatUtils;
|
2012-08-02 04:25:17 +00:00
|
|
|
import com.android.inputmethod.compat.InputMethodServiceCompatUtils;
|
2011-05-24 11:30:30 +00:00
|
|
|
import com.android.inputmethod.compat.SuggestionSpanUtils;
|
2012-12-06 11:35:59 +00:00
|
|
|
import com.android.inputmethod.event.EventInterpreter;
|
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-09-19 07:18:24 +00:00
|
|
|
import com.android.inputmethod.latin.Utils.Stats;
|
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-09-27 09:16:16 +00:00
|
|
|
public final 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
|
|
|
|
2013-01-08 07:35:21 +00:00
|
|
|
private final Settings mSettings;
|
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-10-03 08:36:45 +00:00
|
|
|
@UsedForTesting 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
|
|
|
|
2012-11-09 09:21:41 +00:00
|
|
|
private RichInputMethodManager mRichImm;
|
2012-10-03 08:36:45 +00:00
|
|
|
@UsedForTesting final KeyboardSwitcher mKeyboardSwitcher;
|
2012-03-06 10:06:58 +00:00
|
|
|
private final SubtypeSwitcher mSubtypeSwitcher;
|
2012-10-02 09:40:06 +00:00
|
|
|
private final SubtypeState mSubtypeState = new SubtypeState();
|
2012-12-06 11:35:59 +00:00
|
|
|
// At start, create a default event interpreter that does nothing by passing it no decoder spec.
|
|
|
|
// The event interpreter should never be null.
|
2012-12-26 06:38:53 +00:00
|
|
|
private EventInterpreter mEventInterpreter = new EventInterpreter(this);
|
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;
|
2012-12-13 12:59:13 +00:00
|
|
|
private PositionalInfoForUserDictPendingAddition
|
|
|
|
mPositionalInfoForUserDictPendingAddition = null;
|
2012-09-19 07:18:24 +00:00
|
|
|
private final 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
|
|
|
|
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.
|
2012-11-09 03:59:06 +00:00
|
|
|
// TODO: The experimental version is not supported by the Dictionary Pack Service yet.
|
2011-03-14 18:46:15 +00:00
|
|
|
private BroadcastReceiver mDictionaryPackInstallReceiver =
|
2012-11-09 03:59:06 +00:00
|
|
|
ProductionFlag.IS_EXPERIMENTAL
|
|
|
|
? null : new DictionaryPackInstallBroadcastReceiver(this);
|
2011-03-14 18:46:15 +00:00
|
|
|
|
2010-04-01 13:28:52 +00:00
|
|
|
// Keeps track of most recently inserted text (multi-character key) for reverting
|
2012-10-03 06:19:43 +00:00
|
|
|
private String mEnteredText;
|
2010-04-01 13:28:52 +00:00
|
|
|
|
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;
|
|
|
|
|
2012-08-02 04:25:17 +00:00
|
|
|
private final boolean mIsHardwareAcceleratedDrawingEnabled;
|
|
|
|
|
2011-06-24 18:54:11 +00:00
|
|
|
public final UIHandler mHandler = new UIHandler(this);
|
2010-11-16 09:07:06 +00:00
|
|
|
|
2012-09-27 09:16:16 +00:00
|
|
|
public static final class UIHandler extends StaticInnerHandlerWrapper<LatinIME> {
|
2012-08-07 02:48:10 +00:00
|
|
|
private static final int MSG_UPDATE_SHIFT_STATE = 0;
|
|
|
|
private static final int MSG_PENDING_IMS_CALLBACK = 1;
|
|
|
|
private static final int MSG_UPDATE_SUGGESTION_STRIP = 2;
|
2012-09-12 04:03:44 +00:00
|
|
|
private static final int MSG_SHOW_GESTURE_PREVIEW_AND_SUGGESTION_STRIP = 3;
|
|
|
|
|
|
|
|
private static final int ARG1_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT = 1;
|
2012-03-13 03:44:03 +00:00
|
|
|
|
2011-11-18 05:45:49 +00:00
|
|
|
private int mDelayUpdateSuggestions;
|
|
|
|
private int mDelayUpdateShiftState;
|
2012-12-05 03:35:41 +00:00
|
|
|
private long mDoubleSpacePeriodTimeout;
|
|
|
|
private long mDoubleSpacePeriodTimerStart;
|
2011-07-21 06:57:00 +00:00
|
|
|
|
2012-09-12 04:03:44 +00:00
|
|
|
public UIHandler(final LatinIME outerInstance) {
|
2011-06-24 18:54:11 +00:00
|
|
|
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);
|
2012-12-05 03:35:41 +00:00
|
|
|
mDoubleSpacePeriodTimeout =
|
|
|
|
res.getInteger(R.integer.config_double_space_period_timeout);
|
2011-06-24 18:54:11 +00:00
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
@Override
|
2012-09-12 04:03:44 +00:00
|
|
|
public void handleMessage(final 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;
|
2012-09-12 04:03:44 +00:00
|
|
|
case MSG_SHOW_GESTURE_PREVIEW_AND_SUGGESTION_STRIP:
|
|
|
|
latinIme.showGesturePreviewAndSuggestionStrip((SuggestedWords)msg.obj,
|
|
|
|
msg.arg1 == ARG1_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-09-12 04:03:44 +00:00
|
|
|
public void showGesturePreviewAndSuggestionStrip(final SuggestedWords suggestedWords,
|
|
|
|
final boolean dismissGestureFloatingPreviewText) {
|
|
|
|
removeMessages(MSG_SHOW_GESTURE_PREVIEW_AND_SUGGESTION_STRIP);
|
|
|
|
final int arg1 = dismissGestureFloatingPreviewText
|
|
|
|
? ARG1_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT : 0;
|
|
|
|
obtainMessage(MSG_SHOW_GESTURE_PREVIEW_AND_SUGGESTION_STRIP, arg1, 0, suggestedWords)
|
|
|
|
.sendToTarget();
|
|
|
|
}
|
|
|
|
|
2012-12-05 03:35:41 +00:00
|
|
|
public void startDoubleSpacePeriodTimer() {
|
|
|
|
mDoubleSpacePeriodTimerStart = SystemClock.uptimeMillis();
|
2011-03-02 07:40:10 +00:00
|
|
|
}
|
|
|
|
|
2012-12-05 03:35:41 +00:00
|
|
|
public void cancelDoubleSpacePeriodTimer() {
|
|
|
|
mDoubleSpacePeriodTimerStart = 0;
|
2011-03-02 07:40:10 +00:00
|
|
|
}
|
|
|
|
|
2012-12-05 03:35:41 +00:00
|
|
|
public boolean isAcceptingDoubleSpacePeriod() {
|
|
|
|
return SystemClock.uptimeMillis() - mDoubleSpacePeriodTimerStart
|
|
|
|
< mDoubleSpacePeriodTimeout;
|
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;
|
|
|
|
}
|
|
|
|
|
2012-09-12 04:03:44 +00:00
|
|
|
private void executePendingImsCallback(final LatinIME latinIme, final 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();
|
|
|
|
}
|
|
|
|
|
2012-09-12 04:03:44 +00:00
|
|
|
public void onStartInput(final EditorInfo editorInfo, final 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-12 04:03:44 +00:00
|
|
|
public void onStartInputView(final EditorInfo editorInfo, final 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
|
|
|
}
|
|
|
|
|
2012-09-12 04:03:44 +00:00
|
|
|
public void onFinishInputView(final boolean finishingInput) {
|
2011-09-29 08:27:48 +00:00
|
|
|
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-10-02 09:40:06 +00:00
|
|
|
static final class SubtypeState {
|
|
|
|
private InputMethodSubtype mLastActiveSubtype;
|
|
|
|
private boolean mCurrentSubtypeUsed;
|
|
|
|
|
|
|
|
public void currentSubtypeUsed() {
|
|
|
|
mCurrentSubtypeUsed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void switchSubtype(final IBinder token, final RichInputMethodManager richImm) {
|
|
|
|
final InputMethodSubtype currentSubtype = richImm.getInputMethodManager()
|
|
|
|
.getCurrentInputMethodSubtype();
|
|
|
|
final InputMethodSubtype lastActiveSubtype = mLastActiveSubtype;
|
|
|
|
final boolean currentSubtypeUsed = mCurrentSubtypeUsed;
|
|
|
|
if (currentSubtypeUsed) {
|
|
|
|
mLastActiveSubtype = currentSubtype;
|
|
|
|
mCurrentSubtypeUsed = false;
|
|
|
|
}
|
|
|
|
if (currentSubtypeUsed
|
|
|
|
&& richImm.checkIfSubtypeBelongsToThisImeAndEnabled(lastActiveSubtype)
|
|
|
|
&& !currentSubtype.equals(lastActiveSubtype)) {
|
|
|
|
richImm.setInputMethodAndSubtype(token, lastActiveSubtype);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
richImm.switchToNextInputMethod(token, true /* onlyCurrentIme */);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-06 10:06:58 +00:00
|
|
|
public LatinIME() {
|
|
|
|
super();
|
2013-01-08 07:35:21 +00:00
|
|
|
mSettings = Settings.getInstance();
|
2012-03-06 10:06:58 +00:00
|
|
|
mSubtypeSwitcher = SubtypeSwitcher.getInstance();
|
|
|
|
mKeyboardSwitcher = KeyboardSwitcher.getInstance();
|
2012-08-02 04:25:17 +00:00
|
|
|
mIsHardwareAcceleratedDrawingEnabled =
|
|
|
|
InputMethodServiceCompatUtils.enableHardwareAcceleration(this);
|
|
|
|
Log.i(TAG, "Hardware accelerated drawing: " + mIsHardwareAcceleratedDrawingEnabled);
|
2012-03-06 10:06:58 +00:00
|
|
|
}
|
|
|
|
|
2010-10-08 13:17:16 +00:00
|
|
|
@Override
|
|
|
|
public void onCreate() {
|
2013-01-08 07:35:21 +00:00
|
|
|
Settings.init(this);
|
2013-01-07 09:40:59 +00:00
|
|
|
LatinImeLogger.init(this);
|
2012-03-26 13:10:21 +00:00
|
|
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
2013-01-07 09:40:59 +00:00
|
|
|
ResearchLogger.getInstance().init(this);
|
2012-03-26 13:10:21 +00:00
|
|
|
}
|
2013-01-07 09:40:59 +00:00
|
|
|
RichInputMethodManager.init(this);
|
2012-11-28 04:28:18 +00:00
|
|
|
mRichImm = RichInputMethodManager.getInstance();
|
2011-07-17 22:23:52 +00:00
|
|
|
SubtypeSwitcher.init(this);
|
2013-01-07 09:40:59 +00:00
|
|
|
KeyboardSwitcher.init(this);
|
2013-01-08 05:58:08 +00:00
|
|
|
AudioAndHapticFeedbackManager.init(this);
|
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-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
|
|
|
|
2011-09-19 05:51:31 +00:00
|
|
|
loadSettings();
|
2012-08-22 03:32:47 +00:00
|
|
|
initSuggest();
|
2010-08-20 05:35:02 +00:00
|
|
|
|
2013-01-08 07:35:21 +00:00
|
|
|
mDisplayOrientation = getResources().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
|
|
|
|
2012-11-09 03:59:06 +00:00
|
|
|
// TODO: The experimental version is not supported by the Dictionary Pack Service yet.
|
|
|
|
if (!ProductionFlag.IS_EXPERIMENTAL) {
|
|
|
|
final IntentFilter packageFilter = new IntentFilter();
|
|
|
|
packageFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
|
|
|
|
packageFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
|
|
|
|
packageFilter.addDataScheme(SCHEME_PACKAGE);
|
|
|
|
registerReceiver(mDictionaryPackInstallReceiver, packageFilter);
|
|
|
|
|
|
|
|
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
|
2012-10-03 08:36:45 +00:00
|
|
|
@UsedForTesting
|
2012-08-22 01:19:56 +00:00
|
|
|
void loadSettings() {
|
2013-01-08 07:35:21 +00:00
|
|
|
final Locale locale = mSubtypeSwitcher.getCurrentSubtypeLocale();
|
2012-06-16 00:57:46 +00:00
|
|
|
final InputAttributes inputAttributes =
|
|
|
|
new InputAttributes(getCurrentInputEditorInfo(), isFullscreenMode());
|
2013-01-08 07:35:21 +00:00
|
|
|
mSettings.loadSettings(locale, inputAttributes);
|
2011-08-09 02:54:10 +00:00
|
|
|
resetContactsDictionary(null == mSuggest ? null : mSuggest.getContactsDictionary());
|
2011-05-10 06:51:43 +00:00
|
|
|
}
|
|
|
|
|
2012-08-08 02:41:58 +00:00
|
|
|
// Note that this method is called from a non-UI thread.
|
2012-07-24 06:56:25 +00:00
|
|
|
@Override
|
2012-09-12 04:03:44 +00:00
|
|
|
public void onUpdateMainDictionaryAvailability(final boolean isMainDictionaryAvailable) {
|
2012-07-24 06:56:25 +00:00
|
|
|
mIsMainDictionaryAvailable = isMainDictionaryAvailable;
|
2012-08-08 02:41:58 +00:00
|
|
|
final MainKeyboardView mainKeyboardView = mKeyboardSwitcher.getMainKeyboardView();
|
|
|
|
if (mainKeyboardView != null) {
|
|
|
|
mainKeyboardView.setMainDictionaryAvailability(isMainDictionaryAvailable);
|
|
|
|
}
|
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 */);
|
2013-01-08 07:35:21 +00:00
|
|
|
if (mSettings.getCurrent().mCorrectionEnabled) {
|
|
|
|
mSuggest.setAutoCorrectionThreshold(mSettings.getCurrent().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
|
|
|
|
2013-01-08 07:35:21 +00:00
|
|
|
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
|
|
|
mUserHistoryDictionary = UserHistoryDictionary.getInstance(this, localeStr, prefs);
|
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) {
|
2013-01-08 07:35:21 +00:00
|
|
|
final boolean shouldSetDictionary =
|
|
|
|
(null != mSuggest && mSettings.getCurrent().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();
|
2012-08-08 06:55:26 +00:00
|
|
|
mSuggest.resetMainDict(this, subtypeLocale, this /* SuggestInitializationListener */);
|
2012-04-19 14:11:31 +00:00
|
|
|
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
|
|
|
}
|
2013-01-08 07:35:21 +00:00
|
|
|
mSettings.onDestroy();
|
2009-03-13 22:11:42 +00:00
|
|
|
unregisterReceiver(mReceiver);
|
2012-11-09 03:59:06 +00:00
|
|
|
// TODO: The experimental version is not supported by the Dictionary Pack Service yet.
|
|
|
|
if (!ProductionFlag.IS_EXPERIMENTAL) {
|
|
|
|
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
|
2012-09-12 04:03:44 +00:00
|
|
|
public void onConfigurationChanged(final Configuration 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();
|
2012-08-06 04:05:39 +00:00
|
|
|
if (isShowingOptionDialog()) {
|
2011-01-20 13:52:02 +00:00
|
|
|
mOptionsDialog.dismiss();
|
2012-08-06 04:05:39 +00:00
|
|
|
}
|
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() {
|
2012-08-02 07:39:27 +00:00
|
|
|
return mKeyboardSwitcher.onCreateInputView(mIsHardwareAcceleratedDrawingEnabled);
|
2011-05-25 09:28:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-09-12 04:03:44 +00:00
|
|
|
public void setInputView(final View view) {
|
2011-05-25 09:28:03 +00:00
|
|
|
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
|
2012-09-12 04:03:44 +00:00
|
|
|
public void setCandidatesView(final View view) {
|
2011-05-23 09:30:21 +00:00
|
|
|
// 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
|
2012-09-12 04:03:44 +00:00
|
|
|
public void onStartInput(final EditorInfo editorInfo, final boolean restarting) {
|
2011-11-21 22:58:32 +00:00
|
|
|
mHandler.onStartInput(editorInfo, restarting);
|
2011-09-29 08:27:48 +00:00
|
|
|
}
|
|
|
|
|
2010-01-28 18:09:44 +00:00
|
|
|
@Override
|
2012-09-12 04:03:44 +00:00
|
|
|
public void onStartInputView(final EditorInfo editorInfo, final boolean restarting) {
|
2011-11-21 22:58:32 +00:00
|
|
|
mHandler.onStartInputView(editorInfo, restarting);
|
2011-09-29 08:27:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-09-12 04:03:44 +00:00
|
|
|
public void onFinishInputView(final boolean finishingInput) {
|
2011-09-29 08:27:48 +00:00
|
|
|
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
|
2012-09-12 04:03:44 +00:00
|
|
|
public void onCurrentInputMethodSubtypeChanged(final 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-12-26 05:31:13 +00:00
|
|
|
mSubtypeSwitcher.onSubtypeChanged(subtype);
|
2012-08-22 01:19:56 +00:00
|
|
|
loadKeyboard();
|
2012-04-02 12:31:52 +00:00
|
|
|
}
|
|
|
|
|
2012-09-12 04:03:44 +00:00
|
|
|
private void onStartInputInternal(final EditorInfo editorInfo, final boolean restarting) {
|
2011-11-21 22:58:32 +00:00
|
|
|
super.onStartInput(editorInfo, restarting);
|
2011-09-29 08:27:48 +00:00
|
|
|
}
|
|
|
|
|
2012-04-19 03:42:13 +00:00
|
|
|
@SuppressWarnings("deprecation")
|
2012-09-12 04:03:44 +00:00
|
|
|
private void onStartInputViewInternal(final EditorInfo editorInfo, final boolean restarting) {
|
2011-11-21 22:58:32 +00:00
|
|
|
super.onStartInputView(editorInfo, restarting);
|
2010-11-12 23:49:56 +00:00
|
|
|
final KeyboardSwitcher switcher = mKeyboardSwitcher;
|
2012-08-07 02:48:10 +00:00
|
|
|
final MainKeyboardView mainKeyboardView = switcher.getMainKeyboardView();
|
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) {
|
2013-01-08 07:35:21 +00:00
|
|
|
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
|
|
|
ResearchLogger.latinIME_onStartInputViewInternal(editorInfo, prefs);
|
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.
|
2012-08-07 02:48:10 +00:00
|
|
|
if (mainKeyboardView == 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()) {
|
2012-08-14 22:34:29 +00:00
|
|
|
accessUtils.onStartInputViewInternal(mainKeyboardView, editorInfo, restarting);
|
2011-10-05 23:59:31 +00:00
|
|
|
}
|
|
|
|
|
2013-01-08 07:35:21 +00:00
|
|
|
final boolean inputTypeChanged = !mSettings.getCurrent().isSameInputType(editorInfo);
|
2012-08-15 08:57:38 +00:00
|
|
|
final boolean isDifferentTextField = !restarting || inputTypeChanged;
|
|
|
|
if (isDifferentTextField) {
|
2012-12-26 05:31:13 +00:00
|
|
|
mSubtypeSwitcher.updateParametersOnStartInputView();
|
2012-07-25 10:31:19 +00:00
|
|
|
}
|
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-11-09 09:58:50 +00:00
|
|
|
// The app calling setText() has the effect of clearing the composing
|
|
|
|
// span, so we should reset our state unconditionally, even if restarting is true.
|
|
|
|
mEnteredText = null;
|
|
|
|
resetComposingState(true /* alsoResetLastComposedWord */);
|
|
|
|
mDeleteCount = 0;
|
|
|
|
mSpaceState = SPACE_STATE_NONE;
|
|
|
|
|
|
|
|
if (mSuggestionStripView != null) {
|
|
|
|
// This will set the punctuation suggestions if next word suggestion is off;
|
|
|
|
// otherwise it will clear the suggestion strip.
|
|
|
|
setPunctuationSuggestions();
|
2011-11-15 17:11:11 +00:00
|
|
|
}
|
2011-05-10 06:51:43 +00:00
|
|
|
|
2012-09-24 10:33:42 +00:00
|
|
|
mConnection.resetCachesUponCursorMove(editorInfo.initialSelStart);
|
2012-09-10 10:27:45 +00:00
|
|
|
|
2012-08-15 08:57:38 +00:00
|
|
|
if (isDifferentTextField) {
|
2012-08-07 02:48:10 +00:00
|
|
|
mainKeyboardView.closing();
|
2012-07-25 10:31:19 +00:00
|
|
|
loadSettings();
|
2011-01-18 06:28:21 +00:00
|
|
|
|
2013-01-08 07:35:21 +00:00
|
|
|
if (mSuggest != null && mSettings.getCurrent().mCorrectionEnabled) {
|
|
|
|
mSuggest.setAutoCorrectionThreshold(
|
|
|
|
mSettings.getCurrent().mAutoCorrectionThreshold);
|
2012-07-25 10:31:19 +00:00
|
|
|
}
|
|
|
|
|
2013-01-08 07:35:21 +00:00
|
|
|
switcher.loadKeyboard(editorInfo, mSettings.getCurrent());
|
2012-11-06 07:45:44 +00:00
|
|
|
} else if (restarting) {
|
|
|
|
// TODO: Come up with a more comprehensive way to reset the keyboard layout when
|
|
|
|
// a keyboard layout set doesn't get reloaded in this method.
|
|
|
|
switcher.resetKeyboardStateToAlphabet();
|
2012-11-14 08:37:55 +00:00
|
|
|
// 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.
|
|
|
|
// Space state must be updated before calling updateShiftState
|
|
|
|
switcher.updateShiftState();
|
2012-07-25 10:31:19 +00:00
|
|
|
}
|
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-05 06:26:43 +00:00
|
|
|
mHandler.cancelUpdateSuggestionStrip();
|
2012-12-05 03:35:41 +00:00
|
|
|
mHandler.cancelDoubleSpacePeriodTimer();
|
2011-01-18 06:28:21 +00:00
|
|
|
|
2012-08-09 07:09:54 +00:00
|
|
|
mainKeyboardView.setMainDictionaryAvailability(mIsMainDictionaryAvailable);
|
2013-01-08 07:35:21 +00:00
|
|
|
mainKeyboardView.setKeyPreviewPopupEnabled(mSettings.getCurrent().mKeyPreviewPopupOn,
|
|
|
|
mSettings.getCurrent().mKeyPreviewPopupDismissDelay);
|
|
|
|
mainKeyboardView.setGestureHandlingEnabledByUser(
|
|
|
|
mSettings.getCurrent().mGestureInputEnabled);
|
|
|
|
mainKeyboardView.setGesturePreviewMode(mSettings.getCurrent().mGesturePreviewTrailEnabled,
|
|
|
|
mSettings.getCurrent().mGestureFloatingPreviewTextEnabled);
|
2011-01-18 06:28:21 +00:00
|
|
|
|
2012-12-13 12:59:13 +00:00
|
|
|
// If we have a user dictionary addition in progress, we should check now if we should
|
|
|
|
// replace the previously committed string with the word that has actually been added
|
|
|
|
// to the user dictionary.
|
|
|
|
if (null != mPositionalInfoForUserDictPendingAddition
|
|
|
|
&& mPositionalInfoForUserDictPendingAddition.tryReplaceWithActualWord(
|
|
|
|
mConnection, editorInfo, mLastSelectionEnd)) {
|
|
|
|
mPositionalInfoForUserDictPendingAddition = null;
|
|
|
|
}
|
|
|
|
// If tryReplaceWithActualWord returns false, we don't know what word was
|
|
|
|
// added to the user dictionary yet, so we keep the data and defer processing. The word will
|
|
|
|
// be replaced when the user dictionary reports back with the actual word, which ends
|
|
|
|
// up calling #onWordAddedToUserDictionary() in this class.
|
|
|
|
|
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();
|
2012-09-12 04:03:44 +00:00
|
|
|
final MainKeyboardView mainKeyboardView = mKeyboardSwitcher.getMainKeyboardView();
|
2012-08-07 02:48:10 +00:00
|
|
|
if (mainKeyboardView != null) {
|
|
|
|
mainKeyboardView.closing();
|
|
|
|
}
|
2011-05-17 10:02:32 +00:00
|
|
|
}
|
|
|
|
|
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-09-12 04:03:44 +00:00
|
|
|
final MainKeyboardView mainKeyboardView = mKeyboardSwitcher.getMainKeyboardView();
|
2012-08-07 02:48:10 +00:00
|
|
|
if (mainKeyboardView != null) {
|
|
|
|
mainKeyboardView.closing();
|
|
|
|
}
|
2010-01-16 20:21:23 +00:00
|
|
|
}
|
|
|
|
|
2012-09-12 04:03:44 +00:00
|
|
|
private void onFinishInputViewInternal(final boolean finishingInput) {
|
2010-10-06 09:39:47 +00:00
|
|
|
super.onFinishInputView(finishingInput);
|
2011-07-29 17:45:37 +00:00
|
|
|
mKeyboardSwitcher.onFinishInputView();
|
2012-09-12 04:03:44 +00:00
|
|
|
final MainKeyboardView mainKeyboardView = mKeyboardSwitcher.getMainKeyboardView();
|
2012-08-07 02:48:10 +00:00
|
|
|
if (mainKeyboardView != null) {
|
|
|
|
mainKeyboardView.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();
|
2012-12-14 08:44:43 +00:00
|
|
|
resetComposingState(true /* alsoResetLastComposedWord */);
|
2012-08-13 02:28:31 +00:00
|
|
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
|
|
|
ResearchLogger.getInstance().latinIME_onFinishInputViewInternal();
|
|
|
|
}
|
2010-10-06 09:39:47 +00:00
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
@Override
|
2012-09-12 04:03:44 +00:00
|
|
|
public void onUpdateSelection(final int oldSelStart, final int oldSelEnd,
|
|
|
|
final int newSelStart, final int newSelEnd,
|
|
|
|
final int composingSpanStart, final 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;
|
2012-09-12 03:40:36 +00:00
|
|
|
if (!mExpectingUpdateSelection
|
|
|
|
&& !mConnection.isBelatedExpectedUpdate(oldSelStart, newSelStart)) {
|
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
|
2012-09-24 05:40:23 +00:00
|
|
|
// the call to updateShiftState.
|
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-09-24 07:15:20 +00:00
|
|
|
// If we are composing a word and moving the cursor, we would want to set a
|
|
|
|
// suggestion span for recorrection to work correctly. Unfortunately, that
|
|
|
|
// would involve the keyboard committing some new text, which would move the
|
|
|
|
// cursor back to where it was. Latin IME could then fix the position of the cursor
|
|
|
|
// again, but the asynchronous nature of the calls results in this wreaking havoc
|
|
|
|
// with selection on double tap and the like.
|
|
|
|
// Another option would be to send suggestions each time we set the composing
|
|
|
|
// text, but that is probably too expensive to do, so we decided to leave things
|
|
|
|
// as is.
|
2012-09-10 10:27:45 +00:00
|
|
|
resetEntireInputState(newSelStart);
|
2011-10-03 05:58:34 +00:00
|
|
|
}
|
2012-02-16 19:45:35 +00:00
|
|
|
|
2012-09-24 05:40:23 +00:00
|
|
|
mKeyboardSwitcher.updateShiftState();
|
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;
|
2012-10-02 09:40:06 +00:00
|
|
|
mSubtypeState.currentSubtypeUsed();
|
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() {
|
2013-01-08 07:35:21 +00:00
|
|
|
if (mSettings.getCurrent().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
|
2012-09-12 04:03:44 +00:00
|
|
|
public void onExtractedCursorMovement(final int dx, final int dy) {
|
2013-01-08 07:35:21 +00:00
|
|
|
if (mSettings.getCurrent().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
|
2012-09-12 04:03:44 +00:00
|
|
|
public void onDisplayCompletions(final 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
|
|
|
}
|
|
|
|
}
|
2013-01-08 07:35:21 +00:00
|
|
|
if (!mSettings.getCurrent().isApplicationSpecifiedCompletionsOn()) return;
|
2012-06-12 00:35:51 +00:00
|
|
|
mApplicationSpecifiedCompletions = applicationSpecifiedCompletions;
|
|
|
|
if (applicationSpecifiedCompletions == null) {
|
2012-07-23 09:03:16 +00:00
|
|
|
clearSuggestionStrip();
|
2012-08-02 00:26:45 +00:00
|
|
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
|
|
|
ResearchLogger.latinIME_onDisplayCompletions(null);
|
|
|
|
}
|
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);
|
|
|
|
setSuggestionStripShown(true);
|
2012-08-02 00:26:45 +00:00
|
|
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
|
|
|
ResearchLogger.latinIME_onDisplayCompletions(applicationSpecifiedCompletions);
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2012-09-12 04:03:44 +00:00
|
|
|
private void setSuggestionStripShownInternal(final boolean shown,
|
|
|
|
final 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-08-07 02:48:10 +00:00
|
|
|
final MainKeyboardView mainKeyboardView = mKeyboardSwitcher.getMainKeyboardView();
|
|
|
|
final boolean inputViewShown = (mainKeyboardView != null)
|
|
|
|
? mainKeyboardView.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
|
|
|
|
2012-09-12 04:03:44 +00:00
|
|
|
private void setSuggestionStripShown(final boolean shown) {
|
2011-05-23 09:30:21 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-09-12 04:03:44 +00:00
|
|
|
final MainKeyboardView mainKeyboardView = mKeyboardSwitcher.getMainKeyboardView();
|
2012-08-07 02:48:10 +00:00
|
|
|
if (mainKeyboardView == null) {
|
2012-06-04 02:14:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2012-08-07 02:48:10 +00:00
|
|
|
final int keyboardHeight = mainKeyboardView.getHeight();
|
2012-03-07 06:30:16 +00:00
|
|
|
final int suggestionsHeight = mSuggestionsContainer.getHeight();
|
2013-01-08 07:35:21 +00:00
|
|
|
final int displayHeight = getResources().getDisplayMetrics().heightPixels;
|
2012-03-07 06:30:16 +00:00
|
|
|
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
|
2012-09-12 04:03:44 +00:00
|
|
|
public void onComputeInsets(final InputMethodService.Insets outInsets) {
|
2009-03-13 22:11:42 +00:00
|
|
|
super.onComputeInsets(outInsets);
|
2012-09-12 04:03:44 +00:00
|
|
|
final MainKeyboardView mainKeyboardView = mKeyboardSwitcher.getMainKeyboardView();
|
2012-08-07 02:48:10 +00:00
|
|
|
if (mainKeyboardView == null || mSuggestionsContainer == null) {
|
2011-04-21 05:51:53 +00:00
|
|
|
return;
|
2012-08-07 02:48:10 +00:00
|
|
|
}
|
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;
|
2012-12-03 06:49:10 +00:00
|
|
|
int visibleTopY = extraHeight;
|
2011-01-21 10:04:00 +00:00
|
|
|
// Need to set touchable region only if input view is being shown
|
2012-08-07 02:48:10 +00:00
|
|
|
if (mainKeyboardView.isShown()) {
|
2011-09-01 05:54:28 +00:00
|
|
|
if (mSuggestionsContainer.getVisibility() == View.VISIBLE) {
|
2012-12-03 06:49:10 +00:00
|
|
|
visibleTopY -= suggestionsHeight;
|
2011-01-21 10:04:00 +00:00
|
|
|
}
|
2012-12-03 06:49:10 +00:00
|
|
|
final int touchY = mainKeyboardView.isShowingMoreKeysPanel() ? 0 : visibleTopY;
|
2012-08-07 02:48:10 +00:00
|
|
|
final int touchWidth = mainKeyboardView.getWidth();
|
|
|
|
final int touchHeight = mainKeyboardView.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
|
|
|
}
|
2012-12-03 06:49:10 +00:00
|
|
|
outInsets.contentTopInsets = visibleTopY;
|
|
|
|
outInsets.visibleTopInsets = visibleTopY;
|
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 =
|
2013-01-08 09:20:31 +00:00
|
|
|
Settings.readUseFullscreenMode(getResources());
|
2012-10-25 05:48:12 +00:00
|
|
|
if (super.onEvaluateFullscreenMode() && isFullscreenModeAllowed) {
|
|
|
|
// TODO: Remove this hack. Actually we should not really assume NO_EXTRACT_UI
|
|
|
|
// implies NO_FULLSCREEN. However, the framework mistakenly does. i.e. NO_EXTRACT_UI
|
|
|
|
// without NO_FULLSCREEN doesn't work as expected. Because of this we need this
|
|
|
|
// hack for now. Let's get rid of this once the framework gets fixed.
|
|
|
|
final EditorInfo ei = getCurrentInputEditorInfo();
|
|
|
|
return !(ei != null && ((ei.imeOptions & EditorInfo.IME_FLAG_NO_EXTRACT_UI) != 0));
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
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-09-10 10:27:45 +00:00
|
|
|
private void resetEntireInputState(final int newCursorPosition) {
|
2012-02-20 02:08:40 +00:00
|
|
|
resetComposingState(true /* alsoResetLastComposedWord */);
|
2013-01-08 07:35:21 +00:00
|
|
|
if (mSettings.getCurrent().mBigramPredictionEnabled) {
|
2012-09-04 10:54:55 +00:00
|
|
|
clearSuggestionStrip();
|
|
|
|
} else {
|
2013-01-08 07:35:21 +00:00
|
|
|
setSuggestionStrip(mSettings.getCurrent().mSuggestPuncList, false);
|
2012-09-04 10:54:55 +00:00
|
|
|
}
|
2012-09-10 10:27:45 +00:00
|
|
|
mConnection.resetCachesUponCursorMove(newCursorPosition);
|
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-08-27 11:09:46 +00:00
|
|
|
private void commitTyped(final String separatorString) {
|
2011-12-13 14:24:37 +00:00
|
|
|
if (!mWordComposer.isComposingWord()) return;
|
2012-10-03 06:19:43 +00:00
|
|
|
final String typedWord = mWordComposer.getTypedWord();
|
2011-12-09 14:15:49 +00:00
|
|
|
if (typedWord.length() > 0) {
|
2012-09-24 07:15:20 +00:00
|
|
|
commitChosenWord(typedWord, LastComposedWord.COMMIT_TYPE_USER_TYPED_WORD,
|
|
|
|
separatorString);
|
2012-08-28 17:26:21 +00:00
|
|
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
2012-08-31 02:09:28 +00:00
|
|
|
ResearchLogger.getInstance().onWordFinished(typedWord);
|
2012-08-28 17:26:21 +00:00
|
|
|
}
|
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() {
|
2013-01-08 07:35:21 +00:00
|
|
|
if (!mSettings.getCurrent().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-09-14 07:53:01 +00:00
|
|
|
// Warning: this depends on mSpaceState, which may not be the most current value. If
|
|
|
|
// mSpaceState gets updated later, whoever called this may need to be told about it.
|
|
|
|
return mConnection.getCursorCapsMode(inputType, mSubtypeSwitcher.getCurrentSubtypeLocale(),
|
|
|
|
SPACE_STATE_PHANTOM == mSpaceState);
|
2010-01-24 15:34:07 +00:00
|
|
|
}
|
|
|
|
|
2012-08-21 10:49:25 +00:00
|
|
|
// Factor in auto-caps and manual caps and compute the current caps mode.
|
|
|
|
private int getActualCapsMode() {
|
2012-10-16 20:21:52 +00:00
|
|
|
final int keyboardShiftMode = mKeyboardSwitcher.getKeyboardShiftMode();
|
|
|
|
if (keyboardShiftMode != WordComposer.CAPS_MODE_AUTO_SHIFTED) return keyboardShiftMode;
|
2012-08-21 10:49:25 +00:00
|
|
|
final int auto = getCurrentAutoCapsState();
|
|
|
|
if (0 != (auto & TextUtils.CAP_MODE_CHARACTERS)) {
|
|
|
|
return WordComposer.CAPS_MODE_AUTO_SHIFT_LOCKED;
|
|
|
|
}
|
|
|
|
if (0 != auto) return WordComposer.CAPS_MODE_AUTO_SHIFTED;
|
|
|
|
return WordComposer.CAPS_MODE_OFF;
|
|
|
|
}
|
|
|
|
|
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
|
2012-10-29 05:46:34 +00:00
|
|
|
&& lastTwo.charAt(0) == Constants.CODE_SPACE) {
|
2012-06-08 10:04:09 +00:00
|
|
|
mConnection.deleteSurroundingText(2, 0);
|
2012-08-28 17:26:21 +00:00
|
|
|
final String text = lastTwo.charAt(1) + " ";
|
|
|
|
mConnection.commitText(text, 1);
|
2012-04-18 01:34:02 +00:00
|
|
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
2012-08-31 02:09:28 +00:00
|
|
|
ResearchLogger.latinIME_swapSwapperAndSpace(text);
|
2012-04-18 01:34:02 +00:00
|
|
|
}
|
2010-11-13 08:16:34 +00:00
|
|
|
mKeyboardSwitcher.updateShiftState();
|
2010-02-22 14:55:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-05 03:35:41 +00:00
|
|
|
private boolean maybeDoubleSpacePeriod() {
|
2013-01-08 07:35:21 +00:00
|
|
|
if (!mSettings.getCurrent().mCorrectionEnabled) return false;
|
|
|
|
if (!mSettings.getCurrent().mUseDoubleSpacePeriod) return false;
|
2012-12-05 03:35:41 +00:00
|
|
|
if (!mHandler.isAcceptingDoubleSpacePeriod()) 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-12-05 03:35:41 +00:00
|
|
|
&& canBeFollowedByDoubleSpacePeriod(lastThree.charAt(0))
|
2012-10-29 05:46:34 +00:00
|
|
|
&& lastThree.charAt(1) == Constants.CODE_SPACE
|
|
|
|
&& lastThree.charAt(2) == Constants.CODE_SPACE) {
|
2012-12-05 03:35:41 +00:00
|
|
|
mHandler.cancelDoubleSpacePeriodTimer();
|
2012-06-08 10:04:09 +00:00
|
|
|
mConnection.deleteSurroundingText(2, 0);
|
2012-08-28 17:26:21 +00:00
|
|
|
final String textToInsert = ". ";
|
|
|
|
mConnection.commitText(textToInsert, 1);
|
|
|
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
2012-08-31 02:09:28 +00:00
|
|
|
ResearchLogger.latinIME_maybeDoubleSpacePeriod(textToInsert);
|
2012-08-28 17:26:21 +00:00
|
|
|
}
|
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-12-05 03:35:41 +00:00
|
|
|
private static boolean canBeFollowedByDoubleSpacePeriod(final int codePoint) {
|
2012-04-19 07:39:25 +00:00
|
|
|
// 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)
|
2012-10-29 05:46:34 +00:00
|
|
|
|| codePoint == Constants.CODE_SINGLE_QUOTE
|
|
|
|
|| codePoint == Constants.CODE_DOUBLE_QUOTE
|
|
|
|
|| codePoint == Constants.CODE_CLOSING_PARENTHESIS
|
|
|
|
|| codePoint == Constants.CODE_CLOSING_SQUARE_BRACKET
|
|
|
|
|| codePoint == Constants.CODE_CLOSING_CURLY_BRACKET
|
|
|
|
|| codePoint == Constants.CODE_CLOSING_ANGLE_BRACKET;
|
2012-04-19 07:39:25 +00:00
|
|
|
}
|
|
|
|
|
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-12-13 12:59:13 +00:00
|
|
|
public void addWordToUserDictionary(final String word) {
|
|
|
|
if (TextUtils.isEmpty(word)) {
|
|
|
|
// Probably never supposed to happen, but just in case.
|
|
|
|
mPositionalInfoForUserDictPendingAddition = null;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mPositionalInfoForUserDictPendingAddition =
|
|
|
|
new PositionalInfoForUserDictPendingAddition(
|
|
|
|
word, mLastSelectionEnd, getCurrentInputEditorInfo());
|
2012-06-08 08:01:35 +00:00
|
|
|
mUserDictionary.addWordToUserDictionary(word, 128);
|
2012-12-13 12:59:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void onWordAddedToUserDictionary(final String newSpelling) {
|
|
|
|
// If word was added but not by us, bail out
|
|
|
|
if (null == mPositionalInfoForUserDictPendingAddition) return;
|
|
|
|
if (mWordComposer.isComposingWord()) {
|
|
|
|
// We are late... give up and return
|
|
|
|
mPositionalInfoForUserDictPendingAddition = null;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mPositionalInfoForUserDictPendingAddition.setActualWordBeingAdded(newSpelling);
|
|
|
|
if (mPositionalInfoForUserDictPendingAddition.tryReplaceWithActualWord(
|
|
|
|
mConnection, getCurrentInputEditorInfo(), mLastSelectionEnd)) {
|
|
|
|
mPositionalInfoForUserDictPendingAddition = null;
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2012-09-12 04:03:44 +00:00
|
|
|
private static boolean isAlphabet(final int code) {
|
2011-10-28 04:31:31 +00:00
|
|
|
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
|
2012-09-12 04:03:44 +00:00
|
|
|
public boolean onCustomRequest(final int requestCode) {
|
2011-08-06 01:45:19 +00:00
|
|
|
if (isShowingOptionDialog()) return false;
|
|
|
|
switch (requestCode) {
|
|
|
|
case CODE_SHOW_INPUT_METHOD_PICKER:
|
2012-11-09 09:21:41 +00:00
|
|
|
if (mRichImm.hasMultipleEnabledIMEsOrSubtypes(true /* include aux subtypes */)) {
|
|
|
|
mRichImm.getInputMethodManager().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-09-12 04:03:44 +00:00
|
|
|
private static int getActionId(final Keyboard keyboard) {
|
2012-02-17 07:14:14 +00:00
|
|
|
return keyboard != null ? keyboard.mId.imeActionId() : EditorInfo.IME_ACTION_NONE;
|
2012-02-07 08:07:23 +00:00
|
|
|
}
|
|
|
|
|
2012-09-12 04:03:44 +00:00
|
|
|
private void performEditorAction(final int actionId) {
|
2012-06-08 10:04:09 +00:00
|
|
|
mConnection.performEditorAction(actionId);
|
2012-02-07 08:07:23 +00:00
|
|
|
}
|
|
|
|
|
2012-10-02 08:09:56 +00:00
|
|
|
// TODO: Revise the language switch key behavior to make it much smarter and more reasonable.
|
2012-02-18 01:46:01 +00:00
|
|
|
private void handleLanguageSwitchKey() {
|
|
|
|
final IBinder token = getWindow().getWindow().getAttributes().token;
|
2013-01-08 07:35:21 +00:00
|
|
|
if (mSettings.getCurrent().mIncludesOtherImesInLanguageSwitchList) {
|
2012-11-09 09:21:41 +00:00
|
|
|
mRichImm.switchToNextInputMethod(token, false /* onlyCurrentIme */);
|
2012-10-02 08:09:56 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-10-02 09:40:06 +00:00
|
|
|
mSubtypeState.switchSubtype(token, mRichImm);
|
2012-02-18 01:46:01 +00:00
|
|
|
}
|
|
|
|
|
2012-09-10 10:27:45 +00:00
|
|
|
private void sendDownUpKeyEventForBackwardCompatibility(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-09-12 04:03:44 +00:00
|
|
|
private void sendKeyCodePoint(final int code) {
|
2012-02-07 08:07:23 +00:00
|
|
|
// TODO: Remove this special handling of digit letters.
|
|
|
|
// For backward compatibility. See {@link InputMethodService#sendKeyChar(char)}.
|
|
|
|
if (code >= '0' && code <= '9') {
|
2012-09-10 10:27:45 +00:00
|
|
|
sendDownUpKeyEventForBackwardCompatibility(code - '0' + KeyEvent.KEYCODE_0);
|
2012-08-02 00:26:45 +00:00
|
|
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
|
|
|
ResearchLogger.latinIME_sendKeyCodePoint(code);
|
|
|
|
}
|
2012-02-07 08:07:23 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-29 05:46:34 +00:00
|
|
|
if (Constants.CODE_ENTER == code && mTargetApplicationInfo != null
|
2013-01-06 02:10:27 +00:00
|
|
|
&& mTargetApplicationInfo.targetSdkVersion < VERSION_CODES.JELLY_BEAN) {
|
2012-06-08 10:04:09 +00:00
|
|
|
// 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-09-10 10:27:45 +00:00
|
|
|
sendDownUpKeyEventForBackwardCompatibility(KeyEvent.KEYCODE_ENTER);
|
2012-06-08 10:04:09 +00:00
|
|
|
} else {
|
|
|
|
final String text = new String(new int[] { code }, 0, 1);
|
|
|
|
mConnection.commitText(text, text.length());
|
|
|
|
}
|
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-09-12 04:03:44 +00:00
|
|
|
public void onCodeInput(final int primaryCode, final int x, final int y) {
|
2011-11-16 23:58:42 +00:00
|
|
|
final long when = SystemClock.uptimeMillis();
|
2012-10-29 05:46:34 +00:00
|
|
|
if (primaryCode != Constants.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();
|
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
|
|
|
|
2012-12-05 03:35:41 +00:00
|
|
|
// TODO: Consolidate the double-space period timer, mLastKeyTime, and the space state.
|
2012-10-29 05:46:34 +00:00
|
|
|
if (primaryCode != Constants.CODE_SPACE) {
|
2012-12-05 03:35:41 +00:00
|
|
|
mHandler.cancelDoubleSpacePeriodTimer();
|
2011-11-14 09:59:17 +00:00
|
|
|
}
|
|
|
|
|
2012-01-26 08:20:51 +00:00
|
|
|
boolean didAutoCorrect = false;
|
2009-03-13 22:11:42 +00:00
|
|
|
switch (primaryCode) {
|
2012-10-29 05:46:34 +00:00
|
|
|
case Constants.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-03-20 14:29:34 +00:00
|
|
|
LatinImeLogger.logOnDelete(x, y);
|
2010-10-22 10:35:23 +00:00
|
|
|
break;
|
2012-10-29 05:46:34 +00:00
|
|
|
case Constants.CODE_SHIFT:
|
|
|
|
case Constants.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;
|
2012-10-29 05:46:34 +00:00
|
|
|
case Constants.CODE_SETTINGS:
|
2011-11-22 00:41:01 +00:00
|
|
|
onSettingsKeyPressed();
|
2010-10-22 10:35:23 +00:00
|
|
|
break;
|
2012-10-29 05:46:34 +00:00
|
|
|
case Constants.CODE_SHORTCUT:
|
2012-08-22 01:19:56 +00:00
|
|
|
mSubtypeSwitcher.switchToShortcutIME(this);
|
2010-10-22 10:35:23 +00:00
|
|
|
break;
|
2012-10-29 05:46:34 +00:00
|
|
|
case Constants.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-10-29 05:46:34 +00:00
|
|
|
case Constants.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;
|
2012-10-29 05:46:34 +00:00
|
|
|
case Constants.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-10-29 05:46:34 +00:00
|
|
|
case Constants.CODE_LANGUAGE_SWITCH:
|
2012-02-18 01:46:01 +00:00
|
|
|
handleLanguageSwitchKey();
|
|
|
|
break;
|
2012-10-29 05:46:34 +00:00
|
|
|
case Constants.CODE_RESEARCH:
|
2012-06-04 19:27:37 +00:00
|
|
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
2012-07-26 22:39:55 +00:00
|
|
|
ResearchLogger.getInstance().onResearchKeySelected(this);
|
2012-06-04 19:27:37 +00:00
|
|
|
}
|
|
|
|
break;
|
2010-10-22 10:35:23 +00:00
|
|
|
default:
|
2011-10-25 12:14:33 +00:00
|
|
|
mSpaceState = SPACE_STATE_NONE;
|
2013-01-08 07:35:21 +00:00
|
|
|
if (mSettings.getCurrent().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) {
|
2012-09-19 07:18:24 +00:00
|
|
|
if (ProductionFlag.IS_INTERNAL) {
|
|
|
|
if (mWordComposer.isComposingWord() && mWordComposer.isBatchMode()) {
|
|
|
|
Stats.onAutoCorrection(
|
|
|
|
"", mWordComposer.getTypedWord(), " ", mWordComposer);
|
|
|
|
}
|
|
|
|
}
|
2012-07-04 06:24:59 +00:00
|
|
|
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-08-21 05:05:57 +00:00
|
|
|
keyX = Constants.NOT_A_COORDINATE;
|
|
|
|
keyY = Constants.NOT_A_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;
|
|
|
|
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
|
2012-10-29 05:46:34 +00:00
|
|
|
if (!didAutoCorrect && primaryCode != Constants.CODE_SHIFT
|
|
|
|
&& primaryCode != Constants.CODE_SWITCH_ALPHA_SYMBOL)
|
2012-01-26 08:20:51 +00:00
|
|
|
mLastComposedWord.deactivate();
|
2012-10-29 05:46:34 +00:00
|
|
|
if (Constants.CODE_DELETE != primaryCode) {
|
2012-08-27 11:09:46 +00:00
|
|
|
mEnteredText = null;
|
|
|
|
}
|
2012-06-08 11:03:22 +00:00
|
|
|
mConnection.endBatchEdit();
|
2012-08-03 03:22:29 +00:00
|
|
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
|
|
|
ResearchLogger.latinIME_onCodeInput(primaryCode, x, y);
|
|
|
|
}
|
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
|
2012-10-03 06:19:43 +00:00
|
|
|
public void onTextInput(final String rawText) {
|
2012-07-05 03:36:06 +00:00
|
|
|
mConnection.beginBatchEdit();
|
2012-08-27 09:54:05 +00:00
|
|
|
if (mWordComposer.isComposingWord()) {
|
2012-12-23 20:08:42 +00:00
|
|
|
commitCurrentAutoCorrection(rawText);
|
2012-08-27 11:09:46 +00:00
|
|
|
} else {
|
|
|
|
resetComposingState(true /* alsoResetLastComposedWord */);
|
2012-08-27 09:54:05 +00:00
|
|
|
}
|
2012-08-06 04:05:39 +00:00
|
|
|
mHandler.postUpdateSuggestionStrip();
|
2012-10-03 06:19:43 +00:00
|
|
|
final String text = specificTldProcessingOnTextInput(rawText);
|
2012-02-02 08:18:03 +00:00
|
|
|
if (SPACE_STATE_PHANTOM == mSpaceState) {
|
2012-11-12 05:05:51 +00:00
|
|
|
promotePhantomSpace();
|
2012-02-02 08:18:03 +00:00
|
|
|
}
|
2012-06-08 10:04:09 +00:00
|
|
|
mConnection.commitText(text, 1);
|
2012-08-28 17:26:21 +00:00
|
|
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
2012-08-31 02:09:28 +00:00
|
|
|
ResearchLogger.latinIME_onTextInput(text);
|
2012-08-28 17:26:21 +00:00
|
|
|
}
|
2012-06-08 10:04:09 +00:00
|
|
|
mConnection.endBatchEdit();
|
2012-09-14 07:53:01 +00:00
|
|
|
// Space state must be updated before calling updateShiftState
|
|
|
|
mSpaceState = SPACE_STATE_NONE;
|
2010-11-13 08:16:34 +00:00
|
|
|
mKeyboardSwitcher.updateShiftState();
|
2012-10-29 05:46:34 +00:00
|
|
|
mKeyboardSwitcher.onCodeInput(Constants.CODE_OUTPUT_TEXT);
|
2010-04-01 13:28:52 +00:00
|
|
|
mEnteredText = text;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2012-07-04 06:24:59 +00:00
|
|
|
@Override
|
|
|
|
public void onStartBatchInput() {
|
2012-12-17 06:11:44 +00:00
|
|
|
BatchInputUpdater.getInstance().onStartBatchInput(this);
|
2012-07-04 06:24:59 +00:00
|
|
|
mConnection.beginBatchEdit();
|
|
|
|
if (mWordComposer.isComposingWord()) {
|
2012-09-19 07:18:24 +00:00
|
|
|
if (ProductionFlag.IS_INTERNAL) {
|
|
|
|
if (mWordComposer.isBatchMode()) {
|
|
|
|
Stats.onAutoCorrection("", mWordComposer.getTypedWord(), " ", mWordComposer);
|
|
|
|
}
|
|
|
|
}
|
2012-09-20 06:52:40 +00:00
|
|
|
if (mWordComposer.size() <= 1) {
|
|
|
|
// We auto-correct the previous (typed, not gestured) string iff it's one character
|
|
|
|
// long. The reason for this is, even in the middle of gesture typing, you'll still
|
|
|
|
// tap one-letter words and you want them auto-corrected (typically, "i" in English
|
|
|
|
// should become "I"). However for any longer word, we assume that the reason for
|
|
|
|
// tapping probably is that the word you intend to type is not in the dictionary,
|
|
|
|
// so we do not attempt to correct, on the assumption that if that was a dictionary
|
|
|
|
// word, the user would probably have gestured instead.
|
|
|
|
commitCurrentAutoCorrection(LastComposedWord.NOT_A_SEPARATOR);
|
|
|
|
} else {
|
|
|
|
commitTyped(LastComposedWord.NOT_A_SEPARATOR);
|
|
|
|
}
|
2012-07-04 06:24:59 +00:00
|
|
|
mExpectingUpdateSelection = true;
|
2012-09-14 10:36:50 +00:00
|
|
|
// The following is necessary for the case where the user typed something but didn't
|
|
|
|
// manual pick it and didn't input any separator.
|
2012-07-04 06:24:59 +00:00
|
|
|
mSpaceState = SPACE_STATE_PHANTOM;
|
2012-10-16 21:41:15 +00:00
|
|
|
} else {
|
|
|
|
final int codePointBeforeCursor = mConnection.getCodePointBeforeCursor();
|
2012-10-23 02:30:39 +00:00
|
|
|
// TODO: reverse this logic. We should have the means to determine whether a character
|
|
|
|
// should usually be followed by a space, and it should be more readable.
|
2012-10-16 21:41:15 +00:00
|
|
|
if (Constants.NOT_A_CODE != codePointBeforeCursor
|
2012-10-23 02:30:39 +00:00
|
|
|
&& !Character.isWhitespace(codePointBeforeCursor)
|
2013-01-08 07:35:21 +00:00
|
|
|
&& !mSettings.getCurrent().isPhantomSpacePromotingSymbol(codePointBeforeCursor)
|
|
|
|
&& !mSettings.getCurrent().isWeakSpaceStripper(codePointBeforeCursor)) {
|
2012-10-16 21:41:15 +00:00
|
|
|
mSpaceState = SPACE_STATE_PHANTOM;
|
|
|
|
}
|
2012-07-04 06:24:59 +00:00
|
|
|
}
|
|
|
|
mConnection.endBatchEdit();
|
2012-08-21 10:49:25 +00:00
|
|
|
mWordComposer.setCapitalizedModeAtStartComposingTime(getActualCapsMode());
|
2012-06-12 10:40:37 +00:00
|
|
|
}
|
|
|
|
|
2012-09-12 04:03:44 +00:00
|
|
|
private static final class BatchInputUpdater implements Handler.Callback {
|
|
|
|
private final Handler mHandler;
|
|
|
|
private LatinIME mLatinIme;
|
2012-11-30 05:53:38 +00:00
|
|
|
private boolean mInBatchInput; // synchronized using "this".
|
2012-09-12 04:03:44 +00:00
|
|
|
|
|
|
|
private BatchInputUpdater() {
|
|
|
|
final HandlerThread handlerThread = new HandlerThread(
|
|
|
|
BatchInputUpdater.class.getSimpleName());
|
|
|
|
handlerThread.start();
|
|
|
|
mHandler = new Handler(handlerThread.getLooper(), this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialization-on-demand holder
|
|
|
|
private static final class OnDemandInitializationHolder {
|
|
|
|
public static final BatchInputUpdater sInstance = new BatchInputUpdater();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static BatchInputUpdater getInstance() {
|
|
|
|
return OnDemandInitializationHolder.sInstance;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static final int MSG_UPDATE_GESTURE_PREVIEW_AND_SUGGESTION_STRIP = 1;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean handleMessage(final Message msg) {
|
|
|
|
switch (msg.what) {
|
|
|
|
case MSG_UPDATE_GESTURE_PREVIEW_AND_SUGGESTION_STRIP:
|
2012-12-17 06:11:44 +00:00
|
|
|
updateBatchInput((InputPointers)msg.obj);
|
2012-09-12 04:03:44 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-09-27 10:01:17 +00:00
|
|
|
// Run in the UI thread.
|
2012-12-17 06:11:44 +00:00
|
|
|
public synchronized void onStartBatchInput(final LatinIME latinIme) {
|
2012-11-30 05:53:38 +00:00
|
|
|
mHandler.removeMessages(MSG_UPDATE_GESTURE_PREVIEW_AND_SUGGESTION_STRIP);
|
2012-12-17 06:11:44 +00:00
|
|
|
mLatinIme = latinIme;
|
2012-09-27 10:01:17 +00:00
|
|
|
mInBatchInput = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run in the Handler thread.
|
2012-12-17 06:11:44 +00:00
|
|
|
private synchronized void updateBatchInput(final InputPointers batchPointers) {
|
2012-09-27 10:01:17 +00:00
|
|
|
if (!mInBatchInput) {
|
2012-11-30 05:53:38 +00:00
|
|
|
// Batch input has ended or canceled while the message was being delivered.
|
2012-09-27 10:01:17 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-12-17 06:11:44 +00:00
|
|
|
final SuggestedWords suggestedWords = getSuggestedWordsGestureLocked(batchPointers);
|
|
|
|
mLatinIme.mHandler.showGesturePreviewAndSuggestionStrip(
|
2012-09-27 10:01:17 +00:00
|
|
|
suggestedWords, false /* dismissGestureFloatingPreviewText */);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run in the UI thread.
|
2012-12-17 06:11:44 +00:00
|
|
|
public void onUpdateBatchInput(final InputPointers batchPointers) {
|
2012-09-12 04:03:44 +00:00
|
|
|
if (mHandler.hasMessages(MSG_UPDATE_GESTURE_PREVIEW_AND_SUGGESTION_STRIP)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mHandler.obtainMessage(
|
|
|
|
MSG_UPDATE_GESTURE_PREVIEW_AND_SUGGESTION_STRIP, batchPointers)
|
|
|
|
.sendToTarget();
|
|
|
|
}
|
|
|
|
|
2012-12-17 06:11:44 +00:00
|
|
|
public synchronized void onCancelBatchInput() {
|
2012-11-22 06:39:28 +00:00
|
|
|
mInBatchInput = false;
|
2012-12-17 06:11:44 +00:00
|
|
|
mLatinIme.mHandler.showGesturePreviewAndSuggestionStrip(
|
2012-11-22 06:39:28 +00:00
|
|
|
SuggestedWords.EMPTY, true /* dismissGestureFloatingPreviewText */);
|
|
|
|
}
|
|
|
|
|
2012-09-27 10:01:17 +00:00
|
|
|
// Run in the UI thread.
|
2012-12-17 06:11:44 +00:00
|
|
|
public synchronized SuggestedWords onEndBatchInput(final InputPointers batchPointers) {
|
2012-09-27 10:01:17 +00:00
|
|
|
mInBatchInput = false;
|
2012-12-17 06:11:44 +00:00
|
|
|
final SuggestedWords suggestedWords = getSuggestedWordsGestureLocked(batchPointers);
|
|
|
|
mLatinIme.mHandler.showGesturePreviewAndSuggestionStrip(
|
2012-09-27 10:01:17 +00:00
|
|
|
suggestedWords, true /* dismissGestureFloatingPreviewText */);
|
|
|
|
return suggestedWords;
|
2012-09-12 04:03:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// {@link LatinIME#getSuggestedWords(int)} method calls with same session id have to
|
|
|
|
// be synchronized.
|
2012-12-17 06:11:44 +00:00
|
|
|
private SuggestedWords getSuggestedWordsGestureLocked(final InputPointers batchPointers) {
|
|
|
|
mLatinIme.mWordComposer.setBatchInputPointers(batchPointers);
|
|
|
|
final SuggestedWords suggestedWords =
|
|
|
|
mLatinIme.getSuggestedWords(Suggest.SESSION_GESTURE);
|
|
|
|
final int suggestionCount = suggestedWords.size();
|
|
|
|
if (suggestionCount <= 1) {
|
|
|
|
final String mostProbableSuggestion = (suggestionCount == 0) ? null
|
|
|
|
: suggestedWords.getWord(0);
|
|
|
|
return mLatinIme.getOlderSuggestions(mostProbableSuggestion);
|
|
|
|
}
|
|
|
|
return suggestedWords;
|
2012-09-12 04:03:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void showGesturePreviewAndSuggestionStrip(final SuggestedWords suggestedWords,
|
|
|
|
final boolean dismissGestureFloatingPreviewText) {
|
|
|
|
showSuggestionStrip(suggestedWords, null);
|
2012-12-06 01:49:35 +00:00
|
|
|
final KeyboardView mainKeyboardView = mKeyboardSwitcher.getMainKeyboardView();
|
2012-09-12 04:03:44 +00:00
|
|
|
if (dismissGestureFloatingPreviewText) {
|
|
|
|
mainKeyboardView.dismissGestureFloatingPreviewText();
|
2012-12-06 01:49:35 +00:00
|
|
|
} else {
|
2012-12-19 21:01:57 +00:00
|
|
|
mainKeyboardView.showGestureFloatingPreviewText(suggestedWords);
|
2012-09-12 04:03:44 +00:00
|
|
|
}
|
2012-07-04 06:24:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-09-12 04:03:44 +00:00
|
|
|
public void onUpdateBatchInput(final InputPointers batchPointers) {
|
2012-12-17 06:11:44 +00:00
|
|
|
BatchInputUpdater.getInstance().onUpdateBatchInput(batchPointers);
|
2012-09-12 04:03:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onEndBatchInput(final InputPointers batchPointers) {
|
2012-09-27 10:01:17 +00:00
|
|
|
final SuggestedWords suggestedWords = BatchInputUpdater.getInstance().onEndBatchInput(
|
2012-12-17 06:11:44 +00:00
|
|
|
batchPointers);
|
2012-10-03 05:06:44 +00:00
|
|
|
final String batchInputText = suggestedWords.isEmpty()
|
|
|
|
? null : suggestedWords.getWord(0);
|
2012-09-12 04:03:44 +00:00
|
|
|
if (TextUtils.isEmpty(batchInputText)) {
|
2012-07-18 09:14:51 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-09-12 04:03:44 +00:00
|
|
|
mWordComposer.setBatchInputWord(batchInputText);
|
2012-07-04 06:24:59 +00:00
|
|
|
mConnection.beginBatchEdit();
|
|
|
|
if (SPACE_STATE_PHANTOM == mSpaceState) {
|
2012-11-12 05:05:51 +00:00
|
|
|
promotePhantomSpace();
|
2012-07-04 06:24:59 +00:00
|
|
|
}
|
2012-09-12 04:03:44 +00:00
|
|
|
mConnection.setComposingText(batchInputText, 1);
|
2012-07-04 06:24:59 +00:00
|
|
|
mExpectingUpdateSelection = true;
|
|
|
|
mConnection.endBatchEdit();
|
2012-08-10 21:21:18 +00:00
|
|
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
|
|
|
ResearchLogger.latinIME_onEndBatchInput(batchInputText, 0);
|
|
|
|
}
|
2012-09-14 07:53:01 +00:00
|
|
|
// Space state must be updated before calling updateShiftState
|
2012-07-04 06:24:59 +00:00
|
|
|
mSpaceState = SPACE_STATE_PHANTOM;
|
2012-09-14 07:53:01 +00:00
|
|
|
mKeyboardSwitcher.updateShiftState();
|
2012-07-04 06:24:59 +00:00
|
|
|
}
|
|
|
|
|
2012-10-03 06:19:43 +00:00
|
|
|
private String specificTldProcessingOnTextInput(final String text) {
|
2012-10-29 05:46:34 +00:00
|
|
|
if (text.length() <= 1 || text.charAt(0) != Constants.CODE_PERIOD
|
2012-02-02 08:18:03 +00:00
|
|
|
|| !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-10-16 21:41:15 +00:00
|
|
|
// TODO: use getCodePointBeforeCursor instead to improve performance and simplify the code
|
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
|
2012-10-29 05:46:34 +00:00
|
|
|
&& lastOne.charAt(0) == Constants.CODE_PERIOD) {
|
2012-10-03 06:19:43 +00:00
|
|
|
return text.substring(1);
|
2012-02-02 08:18:03 +00:00
|
|
|
} 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
|
|
|
}
|
|
|
|
|
2012-11-22 06:39:28 +00:00
|
|
|
@Override
|
|
|
|
public void onCancelBatchInput() {
|
2012-12-17 06:11:44 +00:00
|
|
|
BatchInputUpdater.getInstance().onCancelBatchInput();
|
2012-11-22 06:39:28 +00:00
|
|
|
}
|
|
|
|
|
2011-10-25 12:14:33 +00:00
|
|
|
private void handleBackspace(final int spaceState) {
|
2012-09-24 05:40:23 +00:00
|
|
|
// In many cases, we may have to put the keyboard in auto-shift state again. However
|
|
|
|
// we want to wait a few milliseconds before doing it to avoid the keyboard flashing
|
|
|
|
// during key repeat.
|
2012-02-16 19:45:35 +00:00
|
|
|
mHandler.postUpdateShiftState();
|
2011-12-13 06:17:57 +00:00
|
|
|
|
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-11-09 10:16:37 +00:00
|
|
|
if (mWordComposer.isBatchMode()) {
|
2012-07-04 06:24:59 +00:00
|
|
|
mWordComposer.reset();
|
2012-08-13 17:30:12 +00:00
|
|
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
|
|
|
ResearchLogger.latinIME_handleBackspace_batch(mWordComposer.getTypedWord());
|
|
|
|
}
|
2012-07-04 06:24:59 +00:00
|
|
|
} 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);
|
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()) {
|
2012-09-19 07:18:24 +00:00
|
|
|
if (ProductionFlag.IS_INTERNAL) {
|
|
|
|
Stats.onAutoCorrectionCancellation();
|
|
|
|
}
|
2012-06-08 10:04:09 +00:00
|
|
|
revertCommit();
|
2011-10-25 12:14:33 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-08-27 11:09:46 +00:00
|
|
|
if (mEnteredText != null && mConnection.sameAsTextBeforeCursor(mEnteredText)) {
|
|
|
|
// 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.
|
|
|
|
final int length = mEnteredText.length();
|
|
|
|
mConnection.deleteSurroundingText(length, 0);
|
|
|
|
mEnteredText = null;
|
|
|
|
// 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 06:20:36 +00:00
|
|
|
if (SPACE_STATE_DOUBLE == spaceState) {
|
2012-12-05 03:35:41 +00:00
|
|
|
mHandler.cancelDoubleSpacePeriodTimer();
|
2012-08-31 02:09:28 +00:00
|
|
|
if (mConnection.revertDoubleSpacePeriod()) {
|
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);
|
2013-01-09 09:37:10 +00:00
|
|
|
// Reset mLastSelectionEnd to mLastSelectionStart. This is what is supposed to
|
|
|
|
// happen, and if it's wrong, the next call to onUpdateSelection will correct it,
|
|
|
|
// but we want to set it right away to avoid it being used with the wrong values
|
|
|
|
// later (typically, in a subsequent press on backspace).
|
|
|
|
mLastSelectionEnd = mLastSelectionStart;
|
2012-06-08 10:04:09 +00:00
|
|
|
mConnection.deleteSurroundingText(lengthToDelete, 0);
|
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
|
|
|
if (mTargetApplicationInfo != null
|
2013-01-06 02:10:27 +00:00
|
|
|
&& mTargetApplicationInfo.targetSdkVersion < VERSION_CODES.JELLY_BEAN) {
|
2012-05-25 10:56:45 +00:00
|
|
|
// 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-09-10 10:27:45 +00:00
|
|
|
sendDownUpKeyEventForBackwardCompatibility(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-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-01-17 06:17:17 +00:00
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2013-01-08 07:35:21 +00:00
|
|
|
if (mSettings.getCurrent().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) {
|
2012-10-29 05:46:34 +00:00
|
|
|
if (Constants.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) {
|
2013-01-08 07:35:21 +00:00
|
|
|
if (mSettings.getCurrent().isWeakSpaceSwapper(code)) {
|
2012-02-08 02:48:19 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
2013-01-08 07:35:21 +00:00
|
|
|
if (mSettings.getCurrent().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 &&
|
2013-01-08 07:35:21 +00:00
|
|
|
!mSettings.getCurrent().isSymbolExcludedFromWordSeparators(primaryCode)) {
|
2012-02-02 08:18:03 +00:00
|
|
|
if (isComposingWord) {
|
|
|
|
// Sanity check
|
|
|
|
throw new RuntimeException("Should not be composing here");
|
|
|
|
}
|
2012-11-12 05:05:51 +00:00
|
|
|
promotePhantomSpace();
|
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)
|
2013-01-08 07:35:21 +00:00
|
|
|
|| mSettings.getCurrent().isSymbolExcludedFromWordSeparators(primaryCode))
|
|
|
|
&& mSettings.getCurrent().isSuggestionsRequested(mDisplayOrientation) &&
|
|
|
|
!mConnection.isCursorTouchingWord(mSettings.getCurrent())) {
|
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.
|
2012-10-29 05:46:34 +00:00
|
|
|
isComposingWord = (Constants.CODE_SINGLE_QUOTE != primaryCode);
|
2012-05-09 06:19:35 +00:00
|
|
|
// 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;
|
2012-11-01 03:32:33 +00:00
|
|
|
if (Constants.isValidCoordinate(x) && Constants.isValidCoordinate(y)) {
|
2012-07-04 07:55:51 +00:00
|
|
|
final KeyDetector keyDetector =
|
2012-08-07 02:48:10 +00:00
|
|
|
mKeyboardSwitcher.getMainKeyboardView().getKeyDetector();
|
2012-07-04 07:55:51 +00:00
|
|
|
keyX = keyDetector.getTouchX(x);
|
|
|
|
keyY = keyDetector.getTouchY(y);
|
2012-11-01 03:32:33 +00:00
|
|
|
} else {
|
|
|
|
keyX = x;
|
|
|
|
keyY = y;
|
2012-07-04 07:55:51 +00:00
|
|
|
}
|
|
|
|
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) {
|
2012-08-21 10:49:25 +00:00
|
|
|
mWordComposer.setCapitalizedModeAtStartComposingTime(getActualCapsMode());
|
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-08-21 05:05:57 +00:00
|
|
|
spaceState, Constants.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-09-19 07:18:24 +00:00
|
|
|
if (ProductionFlag.IS_INTERNAL) {
|
|
|
|
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()) {
|
2013-01-08 07:35:21 +00:00
|
|
|
if (mSettings.getCurrent().mCorrectionEnabled) {
|
2012-08-27 11:09:46 +00:00
|
|
|
// TODO: maybe cache Strings in an <String> sparse array or something
|
|
|
|
commitCurrentAutoCorrection(new String(new int[]{primaryCode}, 0, 1));
|
2012-01-26 08:20:51 +00:00
|
|
|
didAutoCorrect = true;
|
2009-03-13 22:11:42 +00:00
|
|
|
} else {
|
2012-08-27 11:09:46 +00:00
|
|
|
commitTyped(new String(new int[]{primaryCode}, 0, 1));
|
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-08-21 05:05:57 +00:00
|
|
|
Constants.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 &&
|
2013-01-08 07:35:21 +00:00
|
|
|
mSettings.getCurrent().isPhantomSpacePromotingSymbol(primaryCode)) {
|
2012-11-12 05:05:51 +00:00
|
|
|
promotePhantomSpace();
|
2012-03-06 05:00:34 +00:00
|
|
|
}
|
2012-02-07 08:07:23 +00:00
|
|
|
sendKeyCodePoint(primaryCode);
|
2011-04-20 02:50:05 +00:00
|
|
|
|
2012-10-29 05:46:34 +00:00
|
|
|
if (Constants.CODE_SPACE == primaryCode) {
|
2013-01-08 07:35:21 +00:00
|
|
|
if (mSettings.getCurrent().isSuggestionsRequested(mDisplayOrientation)) {
|
2012-12-05 03:35:41 +00:00
|
|
|
if (maybeDoubleSpacePeriod()) {
|
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
|
|
|
|
2012-12-05 03:35:41 +00:00
|
|
|
mHandler.startDoubleSpacePeriodTimer();
|
2013-01-08 07:35:21 +00:00
|
|
|
if (!mConnection.isCursorTouchingWord(mSettings.getCurrent())) {
|
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
|
2013-01-08 07:35:21 +00:00
|
|
|
&& !mSettings.getCurrent().isWeakSpaceStripper(primaryCode)
|
|
|
|
&& !mSettings.getCurrent().isPhantomSpacePromotingSymbol(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
|
|
|
}
|
2012-09-19 07:18:24 +00:00
|
|
|
if (ProductionFlag.IS_INTERNAL) {
|
|
|
|
Utils.Stats.onSeparator((char)primaryCode, x, y);
|
|
|
|
}
|
2011-10-25 12:14:33 +00:00
|
|
|
|
2012-09-24 05:40:23 +00:00
|
|
|
mKeyboardSwitcher.updateShiftState();
|
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
|
|
|
|
2012-10-03 06:19:43 +00:00
|
|
|
private CharSequence getTextWithUnderline(final String 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-08-28 17:26:21 +00:00
|
|
|
// TODO: Verify that words are logged properly when IME is closed.
|
2012-06-08 10:04:09 +00:00
|
|
|
commitTyped(LastComposedWord.NOT_A_SEPARATOR);
|
2009-03-13 22:11:42 +00:00
|
|
|
requestHideSelf(0);
|
2012-08-07 02:48:10 +00:00
|
|
|
final MainKeyboardView mainKeyboardView = mKeyboardSwitcher.getMainKeyboardView();
|
|
|
|
if (mainKeyboardView != null) {
|
|
|
|
mainKeyboardView.closing();
|
2012-08-06 04:05:39 +00:00
|
|
|
}
|
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.
|
2012-10-03 08:36:45 +00:00
|
|
|
@UsedForTesting
|
2012-08-22 01:19:56 +00:00
|
|
|
boolean isShowingPunctuationList() {
|
2012-07-23 06:28:28 +00:00
|
|
|
if (mSuggestionStripView == null) return false;
|
2013-01-08 07:35:21 +00:00
|
|
|
return mSettings.getCurrent().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;
|
2013-01-08 07:35:21 +00:00
|
|
|
if (!mSettings.getCurrent().isSuggestionStripVisibleInOrientation(mDisplayOrientation))
|
2010-12-19 08:32:26 +00:00
|
|
|
return false;
|
2013-01-08 07:35:21 +00:00
|
|
|
if (mSettings.getCurrent().isApplicationSpecifiedCompletionsOn())
|
2010-12-19 08:32:26 +00:00
|
|
|
return true;
|
2013-01-08 07:35:21 +00:00
|
|
|
return mSettings.getCurrent().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-10-01 07:03:21 +00:00
|
|
|
// TODO: when called from an updateSuggestionStrip() call that results from a posted
|
|
|
|
// message, this is called outside any batch edit. Potentially, this may result in some
|
|
|
|
// janky flickering of the screen, although the display speed makes it unlikely in
|
|
|
|
// the practice.
|
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.
|
2013-01-08 07:35:21 +00:00
|
|
|
if (mSuggest == null
|
|
|
|
|| !mSettings.getCurrent().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
|
|
|
}
|
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
|
|
|
|
2013-01-08 07:35:21 +00:00
|
|
|
if (!mWordComposer.isComposingWord() && !mSettings.getCurrent().mBigramPredictionEnabled) {
|
2012-07-06 05:52:22 +00:00
|
|
|
setPunctuationSuggestions();
|
2012-07-23 02:59:11 +00:00
|
|
|
return;
|
2012-07-06 05:52:22 +00:00
|
|
|
}
|
|
|
|
|
2012-09-12 04:03:44 +00:00
|
|
|
final SuggestedWords suggestedWords = getSuggestedWords(Suggest.SESSION_TYPING);
|
2012-07-23 02:59:11 +00:00
|
|
|
final String typedWord = mWordComposer.getTypedWord();
|
|
|
|
showSuggestionStrip(suggestedWords, typedWord);
|
|
|
|
}
|
|
|
|
|
2012-09-12 04:03:44 +00:00
|
|
|
private SuggestedWords getSuggestedWords(final int sessionId) {
|
2012-10-03 04:01:52 +00:00
|
|
|
final Keyboard keyboard = mKeyboardSwitcher.getKeyboard();
|
2012-10-29 09:40:37 +00:00
|
|
|
if (keyboard == null || mSuggest == null) {
|
2012-10-03 04:01:52 +00:00
|
|
|
return SuggestedWords.EMPTY;
|
|
|
|
}
|
2012-07-23 02:59:11 +00:00
|
|
|
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.
|
2012-10-03 06:19:43 +00:00
|
|
|
final String prevWord =
|
2013-01-08 07:35:21 +00:00
|
|
|
mConnection.getNthPreviousWord(mSettings.getCurrent().mWordSeparators,
|
2012-07-06 07:14:52 +00:00
|
|
|
mWordComposer.isComposingWord() ? 2 : 1);
|
2012-07-23 02:59:11 +00:00
|
|
|
final SuggestedWords suggestedWords = mSuggest.getSuggestedWords(mWordComposer,
|
2013-01-08 07:35:21 +00:00
|
|
|
prevWord, keyboard.getProximityInfo(), mSettings.getCurrent().mCorrectionEnabled,
|
2012-10-03 04:01:52 +00:00
|
|
|
sessionId);
|
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-10-03 06:19:43 +00:00
|
|
|
private SuggestedWords maybeRetrieveOlderSuggestions(final String typedWord,
|
2012-07-06 07:14:52 +00:00
|
|
|
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-12-17 05:15:56 +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-12-17 06:11:44 +00:00
|
|
|
return getOlderSuggestions(typedWord);
|
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-12-17 06:11:44 +00:00
|
|
|
private SuggestedWords getOlderSuggestions(final String typedWord) {
|
|
|
|
SuggestedWords previousSuggestions = mSuggestionStripView.getSuggestions();
|
2013-01-08 07:35:21 +00:00
|
|
|
if (previousSuggestions == mSettings.getCurrent().mSuggestPuncList) {
|
2012-12-17 06:11:44 +00:00
|
|
|
previousSuggestions = SuggestedWords.EMPTY;
|
|
|
|
}
|
|
|
|
if (typedWord == null) {
|
|
|
|
return previousSuggestions;
|
|
|
|
}
|
|
|
|
final ArrayList<SuggestedWords.SuggestedWordInfo> typedWordAndPreviousSuggestions =
|
|
|
|
SuggestedWords.getTypedWordAndPreviousSuggestions(typedWord, previousSuggestions);
|
|
|
|
return new SuggestedWords(typedWordAndPreviousSuggestions,
|
|
|
|
false /* typedWordValid */,
|
|
|
|
false /* hasAutoCorrectionCandidate */,
|
|
|
|
false /* isPunctuationSuggestions */,
|
|
|
|
true /* isObsoleteSuggestions */,
|
|
|
|
false /* isPrediction */);
|
|
|
|
}
|
|
|
|
|
2012-10-03 06:19:43 +00:00
|
|
|
private void showSuggestionStrip(final SuggestedWords suggestedWords, final String typedWord) {
|
2012-10-03 05:06:44 +00:00
|
|
|
if (suggestedWords.isEmpty()) {
|
2012-07-23 09:03:16 +00:00
|
|
|
clearSuggestionStrip();
|
2012-07-11 09:49:44 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-10-03 06:19:43 +00:00
|
|
|
final String autoCorrection;
|
2012-10-03 05:06:44 +00:00
|
|
|
if (suggestedWords.mWillAutoCorrect) {
|
|
|
|
autoCorrection = suggestedWords.getWord(1);
|
2009-03-13 22:11:42 +00:00
|
|
|
} else {
|
2012-10-03 05:06:44 +00:00
|
|
|
autoCorrection = typedWord;
|
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-08-27 11:09:46 +00:00
|
|
|
private void commitCurrentAutoCorrection(final String separatorString) {
|
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-10-03 06:19:43 +00:00
|
|
|
final String typedAutoCorrection = mWordComposer.getAutoCorrectionOrNull();
|
2012-06-12 10:40:37 +00:00
|
|
|
final String typedWord = mWordComposer.getTypedWord();
|
2012-10-03 06:19:43 +00:00
|
|
|
final String autoCorrection = (typedAutoCorrection != null)
|
2012-06-12 10:40:37 +00:00
|
|
|
? 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.");
|
|
|
|
}
|
2012-09-19 07:18:24 +00:00
|
|
|
if (ProductionFlag.IS_INTERNAL) {
|
2012-12-23 20:08:42 +00:00
|
|
|
Stats.onAutoCorrection(typedWord, autoCorrection, separatorString, mWordComposer);
|
2012-09-19 07:18:24 +00:00
|
|
|
}
|
2012-12-22 21:34:59 +00:00
|
|
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
2012-12-23 20:08:42 +00:00
|
|
|
ResearchLogger.latinIme_commitCurrentAutoCorrection(typedWord, autoCorrection,
|
|
|
|
separatorString);
|
2012-12-22 21:34:59 +00:00
|
|
|
}
|
2012-12-23 18:40:34 +00:00
|
|
|
mExpectingUpdateSelection = true;
|
2012-02-22 07:17:54 +00:00
|
|
|
commitChosenWord(autoCorrection, LastComposedWord.COMMIT_TYPE_DECIDED_WORD,
|
2012-08-27 11:09:46 +00:00
|
|
|
separatorString);
|
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
|
2012-09-10 10:27:45 +00:00
|
|
|
// to the user that auto-correction happened. It has no other effect; in particular
|
|
|
|
// note that this won't affect the text inside the text field AT ALL: it only makes
|
|
|
|
// the segment of text starting at the supplied index and running for the length
|
|
|
|
// of the auto-correction flash. At this moment, the "typedWord" argument is
|
|
|
|
// ignored by TextView.
|
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-10-03 06:19:43 +00:00
|
|
|
public void pickSuggestionManually(final int index, final String suggestion) {
|
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.
|
2012-08-28 17:26:21 +00:00
|
|
|
LatinImeLogger.logOnManualSuggestion("", suggestion, index, suggestedWords);
|
2012-04-23 09:15:51 +00:00
|
|
|
// Rely on onCodeInput to do the complicated swapping/stripping logic consistently.
|
|
|
|
final int primaryCode = suggestion.charAt(0);
|
|
|
|
onCodeInput(primaryCode,
|
2012-08-21 05:05:57 +00:00
|
|
|
Constants.SUGGESTION_STRIP_COORDINATE, Constants.SUGGESTION_STRIP_COORDINATE);
|
2012-08-02 00:26:45 +00:00
|
|
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
|
|
|
ResearchLogger.latinIME_punctuationSuggestion(index, suggestion);
|
|
|
|
}
|
2012-04-23 09:15:51 +00:00
|
|
|
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);
|
2013-01-08 07:35:21 +00:00
|
|
|
if ((!mSettings.getCurrent().isWeakSpaceStripper(firstChar))
|
|
|
|
&& (!mSettings.getCurrent().isWeakSpaceSwapper(firstChar))) {
|
2012-11-12 05:05:51 +00:00
|
|
|
promotePhantomSpace();
|
2012-03-07 06:59:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-08 07:35:21 +00:00
|
|
|
if (mSettings.getCurrent().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();
|
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-12-23 20:08:42 +00:00
|
|
|
final String replacedWord = mWordComposer.getTypedWord();
|
2012-08-28 17:26:21 +00:00
|
|
|
LatinImeLogger.logOnManualSuggestion(replacedWord, suggestion, index, suggestedWords);
|
2012-08-20 17:17:45 +00:00
|
|
|
mExpectingUpdateSelection = true;
|
|
|
|
commitChosenWord(suggestion, LastComposedWord.COMMIT_TYPE_MANUAL_PICK,
|
|
|
|
LastComposedWord.NOT_A_SEPARATOR);
|
2012-08-02 00:26:45 +00:00
|
|
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
|
|
|
ResearchLogger.latinIME_pickSuggestionManually(replacedWord, index, suggestion);
|
|
|
|
}
|
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-09-14 07:53:01 +00:00
|
|
|
// Space state must be updated before calling updateShiftState
|
2012-02-02 08:18:03 +00:00
|
|
|
mSpaceState = SPACE_STATE_PHANTOM;
|
|
|
|
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
|
|
|
|
2012-09-19 07:18:24 +00:00
|
|
|
if (ProductionFlag.IS_INTERNAL) {
|
2012-10-29 05:46:34 +00:00
|
|
|
Stats.onSeparator((char)Constants.CODE_SPACE,
|
2012-09-19 07:18:24 +00:00
|
|
|
Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE);
|
|
|
|
}
|
2012-07-05 03:45:42 +00:00
|
|
|
if (showingAddToDictionaryHint && mIsUserDictionaryAvailable) {
|
2012-07-23 06:28:28 +00:00
|
|
|
mSuggestionStripView.showAddToDictionaryHint(
|
2013-01-08 07:35:21 +00:00
|
|
|
suggestion, mSettings.getCurrent().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-10-03 06:19:43 +00:00
|
|
|
private void commitChosenWord(final String chosenWord, final int commitType,
|
2012-08-27 11:09:46 +00:00
|
|
|
final String separatorString) {
|
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-05-24 03:11:02 +00:00
|
|
|
// Add the word to the user history dictionary
|
2012-10-03 06:19:43 +00:00
|
|
|
final String 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-12-23 20:08:42 +00:00
|
|
|
mLastComposedWord = mWordComposer.commitWord(commitType, chosenWord, separatorString,
|
|
|
|
prevWord);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2012-07-09 03:54:42 +00:00
|
|
|
private void setPunctuationSuggestions() {
|
2013-01-08 07:35:21 +00:00
|
|
|
if (mSettings.getCurrent().mBigramPredictionEnabled) {
|
2012-07-23 09:03:16 +00:00
|
|
|
clearSuggestionStrip();
|
2012-06-14 18:52:48 +00:00
|
|
|
} else {
|
2013-01-08 07:35:21 +00:00
|
|
|
setSuggestionStrip(mSettings.getCurrent().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-10-03 06:19:43 +00:00
|
|
|
private String addToUserHistoryDictionary(final String suggestion) {
|
2012-05-24 03:11:02 +00:00
|
|
|
if (TextUtils.isEmpty(suggestion)) return null;
|
2012-08-17 15:04:33 +00:00
|
|
|
if (mSuggest == null) 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.
|
2013-01-08 07:35:21 +00:00
|
|
|
if (!mSettings.getCurrent().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-12-23 20:08:42 +00:00
|
|
|
final String prevWord
|
2013-01-08 07:35:21 +00:00
|
|
|
= mConnection.getNthPreviousWord(mSettings.getCurrent().mWordSeparators, 2);
|
2012-03-23 12:35:56 +00:00
|
|
|
final String secondWord;
|
2012-08-21 10:49:25 +00:00
|
|
|
if (mWordComposer.wasAutoCapitalized() && !mWordComposer.isMostlyCaps()) {
|
2012-10-03 06:19:43 +00:00
|
|
|
secondWord = suggestion.toLowerCase(mSubtypeSwitcher.getCurrentSubtypeLocale());
|
2012-03-23 12:35:56 +00:00
|
|
|
} else {
|
2012-10-03 06:19:43 +00:00
|
|
|
secondWord = suggestion;
|
2012-03-23 12:35:56 +00:00
|
|
|
}
|
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-12-23 20:08:42 +00:00
|
|
|
userHistoryDictionary.addToUserHistory(prevWord, secondWord, maxFreq > 0);
|
|
|
|
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() {
|
2013-01-08 07:35:21 +00:00
|
|
|
final CharSequence word =
|
|
|
|
mConnection.getWordBeforeCursorIfAtEndOfWord(mSettings.getCurrent());
|
2012-06-08 12:45:41 +00:00
|
|
|
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);
|
|
|
|
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-10-03 06:19:43 +00:00
|
|
|
final String previousWord = mLastComposedWord.mPrevWord;
|
2012-01-26 08:16:40 +00:00
|
|
|
final String originallyTypedWord = mLastComposedWord.mTypedWord;
|
2012-10-03 06:19:43 +00:00
|
|
|
final String committedWord = mLastComposedWord.mCommittedWord;
|
2012-02-22 07:11:07 +00:00
|
|
|
final int cancelLength = committedWord.length();
|
2012-03-06 05:56:46 +00:00
|
|
|
final int separatorLength = LastComposedWord.getSeparatorLength(
|
2012-08-27 11:09:46 +00:00
|
|
|
mLastComposedWord.mSeparatorString);
|
2012-02-22 07:48:37 +00:00
|
|
|
// 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
|
|
|
}
|
2012-10-03 06:19:43 +00:00
|
|
|
final CharSequence wordBeforeCursor =
|
2012-06-08 10:04:09 +00:00
|
|
|
mConnection.getTextBeforeCursor(deleteLength, 0)
|
2012-10-03 06:19:43 +00:00
|
|
|
.subSequence(0, cancelLength);
|
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-05-24 03:11:02 +00:00
|
|
|
if (!TextUtils.isEmpty(previousWord) && !TextUtils.isEmpty(committedWord)) {
|
2012-08-28 17:26:21 +00:00
|
|
|
mUserHistoryDictionary.cancelAddingUserHistory(previousWord, committedWord);
|
2012-05-24 03:11:02 +00:00
|
|
|
}
|
2012-08-27 11:09:46 +00:00
|
|
|
mConnection.commitText(originallyTypedWord + mLastComposedWord.mSeparatorString, 1);
|
2012-09-19 07:18:24 +00:00
|
|
|
if (ProductionFlag.IS_INTERNAL) {
|
|
|
|
Stats.onSeparator(mLastComposedWord.mSeparatorString,
|
|
|
|
Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE);
|
|
|
|
}
|
2012-07-05 02:43:03 +00:00
|
|
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
2012-08-28 17:26:21 +00:00
|
|
|
ResearchLogger.latinIME_revertCommit(committedWord, 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-11-12 05:05:51 +00:00
|
|
|
// This essentially inserts a space, and that's it.
|
|
|
|
public void promotePhantomSpace() {
|
2013-01-08 07:35:21 +00:00
|
|
|
if (mSettings.getCurrent().shouldInsertSpacesAutomatically()) {
|
2012-11-21 04:07:31 +00:00
|
|
|
sendKeyCodePoint(Constants.CODE_SPACE);
|
2012-11-13 06:10:07 +00:00
|
|
|
}
|
2012-11-12 05:05:51 +00:00
|
|
|
}
|
|
|
|
|
2012-07-09 03:54:42 +00:00
|
|
|
// Used by the RingCharBuffer
|
2012-09-12 04:03:44 +00:00
|
|
|
public boolean isWordSeparator(final int code) {
|
2013-01-08 07:35:21 +00:00
|
|
|
return mSettings.getCurrent().isWordSeparator(code);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 01:19:56 +00:00
|
|
|
// TODO: Make this private
|
|
|
|
// Outside LatinIME, only used by the {@link InputTestsBase} test suite.
|
2012-10-03 08:36:45 +00:00
|
|
|
@UsedForTesting
|
2012-08-22 01:19:56 +00:00
|
|
|
void loadKeyboard() {
|
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();
|
2012-08-07 02:48:10 +00:00
|
|
|
if (mKeyboardSwitcher.getMainKeyboardView() != null) {
|
2011-11-04 03:36:38 +00:00
|
|
|
// Reload keyboard because the current language has been changed.
|
2013-01-08 07:35:21 +00:00
|
|
|
mKeyboardSwitcher.loadKeyboard(getCurrentInputEditorInfo(), mSettings.getCurrent());
|
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-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-09-12 04:03:44 +00:00
|
|
|
public void onPressKey(final 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-09-12 04:03:44 +00:00
|
|
|
public void onReleaseKey(final int primaryCode, final boolean withSliding) {
|
2012-01-17 08:08:26 +00:00
|
|
|
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) {
|
2012-10-29 05:46:34 +00:00
|
|
|
case Constants.CODE_SHIFT:
|
2012-02-07 21:14:18 +00:00
|
|
|
AccessibleKeyboardViewProxy.getInstance().notifyShiftState();
|
|
|
|
break;
|
2012-10-29 05:46:34 +00:00
|
|
|
case Constants.CODE_SWITCH_ALPHA_SYMBOL:
|
2012-02-07 21:14:18 +00:00
|
|
|
AccessibleKeyboardViewProxy.getInstance().notifySymbolsState();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-05-22 09:41:27 +00:00
|
|
|
|
2012-10-29 05:46:34 +00:00
|
|
|
if (Constants.CODE_DELETE == primaryCode) {
|
2012-05-22 09:41:27 +00:00
|
|
|
// 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-10-16 21:41:15 +00:00
|
|
|
// TODO: use getCodePointBeforeCursor instead to improve performance
|
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
|
|
|
|
2012-12-06 11:35:59 +00:00
|
|
|
// Hooks for hardware keyboard
|
|
|
|
@Override
|
|
|
|
public boolean onKeyDown(final int keyCode, final KeyEvent event) {
|
|
|
|
// onHardwareKeyEvent, like onKeyDown returns true if it handled the event, false if
|
|
|
|
// it doesn't know what to do with it and leave it to the application. For example,
|
|
|
|
// hardware key events for adjusting the screen's brightness are passed as is.
|
|
|
|
if (mEventInterpreter.onHardwareKeyEvent(event)) return true;
|
|
|
|
return super.onKeyDown(keyCode, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onKeyUp(final int keyCode, final KeyEvent event) {
|
|
|
|
return super.onKeyUp(keyCode, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
// onKeyDown and onKeyUp are the main events we are interested in. There are two more events
|
|
|
|
// related to handling of hardware key events that we may want to implement in the future:
|
|
|
|
// boolean onKeyLongPress(final int keyCode, final KeyEvent event);
|
|
|
|
// boolean onKeyMultiple(final int keyCode, final int count, final KeyEvent event);
|
|
|
|
|
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
|
2012-09-12 04:03:44 +00:00
|
|
|
public void onReceive(final Context context, final 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)) {
|
2012-10-15 20:59:35 +00:00
|
|
|
mKeyboardSwitcher.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-09-12 04:03:44 +00:00
|
|
|
public void launchKeyboardedDialogActivity(final Class<? extends Activity> activityClass) {
|
2012-07-19 01:00:48 +00:00
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
2012-09-12 04:03:44 +00:00
|
|
|
private void launchSubActivity(final 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),
|
|
|
|
};
|
|
|
|
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-11-09 09:21:41 +00:00
|
|
|
mRichImm.getInputMethodIdOfThisIme(),
|
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-09-12 04:03:44 +00:00
|
|
|
public void showOptionDialog(final AlertDialog dialog) {
|
2012-08-07 02:48:10 +00:00
|
|
|
final IBinder windowToken = mKeyboardSwitcher.getMainKeyboardView().getWindowToken();
|
|
|
|
if (windowToken == null) {
|
|
|
|
return;
|
|
|
|
}
|
2012-04-02 13:25:08 +00:00
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2012-09-10 10:27:45 +00:00
|
|
|
public void debugDumpStateAndCrashWithException(final String context) {
|
|
|
|
final StringBuilder s = new StringBuilder();
|
|
|
|
s.append("Target application : ").append(mTargetApplicationInfo.name)
|
|
|
|
.append("\nPackage : ").append(mTargetApplicationInfo.packageName)
|
|
|
|
.append("\nTarget app sdk version : ")
|
|
|
|
.append(mTargetApplicationInfo.targetSdkVersion)
|
2013-01-08 07:35:21 +00:00
|
|
|
.append("\nAttributes : ").append(mSettings.getCurrent().mInputAttributes)
|
2012-09-10 10:27:45 +00:00
|
|
|
.append("\nContext : ").append(context);
|
|
|
|
throw new RuntimeException(s.toString());
|
|
|
|
}
|
|
|
|
|
2010-10-08 13:17:16 +00:00
|
|
|
@Override
|
2012-09-12 04:03:44 +00:00
|
|
|
protected void dump(final FileDescriptor fd, final PrintWriter fout, final 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);
|
2013-01-08 07:35:21 +00:00
|
|
|
final SettingsValues settingsValues = mSettings.getCurrent();
|
2012-06-12 01:00:07 +00:00
|
|
|
p.println(" mIsSuggestionsSuggestionsRequested = "
|
2013-01-08 07:35:21 +00:00
|
|
|
+ settingsValues.isSuggestionsRequested(mDisplayOrientation));
|
|
|
|
p.println(" mCorrectionEnabled=" + settingsValues.mCorrectionEnabled);
|
2011-12-14 10:01:17 +00:00
|
|
|
p.println(" isComposingWord=" + mWordComposer.isComposingWord());
|
2013-01-08 07:35:21 +00:00
|
|
|
p.println(" mSoundOn=" + settingsValues.mSoundOn);
|
|
|
|
p.println(" mVibrateOn=" + settingsValues.mVibrateOn);
|
|
|
|
p.println(" mKeyPreviewPopupOn=" + settingsValues.mKeyPreviewPopupOn);
|
|
|
|
p.println(" inputAttributes=" + settingsValues.mInputAttributes);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
}
|