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
|
|
|
*
|
2013-01-21 12:52:57 +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
|
|
|
*
|
2013-01-21 12:52:57 +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
|
2013-01-21 12:52:57 +00:00
|
|
|
* 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.
|
2009-03-13 22:11:42 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
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;
|
2013-05-15 07:49:15 +00:00
|
|
|
import android.content.pm.PackageInfo;
|
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;
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.inputmethodservice.InputMethodService;
|
|
|
|
import android.media.AudioManager;
|
2011-01-26 14:13:18 +00:00
|
|
|
import android.net.ConnectivityManager;
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.os.Debug;
|
2012-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;
|
2013-04-10 07:38:37 +00:00
|
|
|
import android.text.style.SuggestionSpan;
|
2009-03-13 22:11:42 +00:00
|
|
|
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-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;
|
2013-05-15 07:49:15 +00:00
|
|
|
import com.android.inputmethod.compat.AppWorkaroundsUtils;
|
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;
|
2013-03-19 07:45:25 +00:00
|
|
|
import com.android.inputmethod.dictionarypack.DictionaryPackConstants;
|
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;
|
2012-07-23 01:27:14 +00:00
|
|
|
import com.android.inputmethod.keyboard.MainKeyboardView;
|
2013-04-04 08:45:21 +00:00
|
|
|
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
|
2012-03-26 13:10:21 +00:00
|
|
|
import com.android.inputmethod.latin.define.ProductionFlag;
|
2013-07-26 09:11:06 +00:00
|
|
|
import com.android.inputmethod.latin.personalization.PersonalizationDictionaryHelper;
|
2013-08-12 03:20:18 +00:00
|
|
|
import com.android.inputmethod.latin.personalization.PersonalizationDictionarySessionRegister;
|
2013-08-01 06:38:40 +00:00
|
|
|
import com.android.inputmethod.latin.personalization.PersonalizationPredictionDictionary;
|
2013-07-31 05:42:50 +00:00
|
|
|
import com.android.inputmethod.latin.personalization.UserHistoryPredictionDictionary;
|
2013-07-22 03:43:37 +00:00
|
|
|
import com.android.inputmethod.latin.settings.Settings;
|
|
|
|
import com.android.inputmethod.latin.settings.SettingsActivity;
|
|
|
|
import com.android.inputmethod.latin.settings.SettingsValues;
|
2012-07-23 06:28:28 +00:00
|
|
|
import com.android.inputmethod.latin.suggestions.SuggestionStripView;
|
2013-07-05 09:23:22 +00:00
|
|
|
import com.android.inputmethod.latin.utils.ApplicationUtils;
|
2013-07-18 13:59:26 +00:00
|
|
|
import com.android.inputmethod.latin.utils.AutoCorrectionUtils;
|
2013-06-23 16:11:32 +00:00
|
|
|
import com.android.inputmethod.latin.utils.CapsModeUtils;
|
|
|
|
import com.android.inputmethod.latin.utils.CollectionUtils;
|
|
|
|
import com.android.inputmethod.latin.utils.CompletionInfoUtils;
|
|
|
|
import com.android.inputmethod.latin.utils.InputTypeUtils;
|
|
|
|
import com.android.inputmethod.latin.utils.IntentUtils;
|
2013-06-24 06:26:29 +00:00
|
|
|
import com.android.inputmethod.latin.utils.JniUtils;
|
2013-07-05 09:23:22 +00:00
|
|
|
import com.android.inputmethod.latin.utils.LatinImeLoggerUtils;
|
2013-06-23 16:11:32 +00:00
|
|
|
import com.android.inputmethod.latin.utils.PositionalInfoForUserDictPendingAddition;
|
|
|
|
import com.android.inputmethod.latin.utils.RecapitalizeStatus;
|
|
|
|
import com.android.inputmethod.latin.utils.StaticInnerHandlerWrapper;
|
|
|
|
import com.android.inputmethod.latin.utils.TargetPackageInfoGetterTask;
|
2013-06-25 08:28:39 +00:00
|
|
|
import com.android.inputmethod.latin.utils.TextRange;
|
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;
|
2013-01-17 10:27:39 +00:00
|
|
|
import java.util.TreeSet;
|
2010-01-16 20:21:23 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
/**
|
|
|
|
* Input method implementation for Qwerty'ish keyboard.
|
|
|
|
*/
|
2013-05-15 03:12:58 +00:00
|
|
|
public class LatinIME extends InputMethodService implements KeyboardActionListener,
|
2013-05-15 07:49:15 +00:00
|
|
|
SuggestionStripView.Listener, TargetPackageInfoGetterTask.OnTargetPackageInfoKnownListener,
|
2012-07-24 06:56:25 +00:00
|
|
|
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
|
|
|
|
2013-08-08 07:13:17 +00:00
|
|
|
private View mInputView;
|
|
|
|
private int mInputViewMinHeight;
|
2012-07-23 06:28:28 +00:00
|
|
|
private SuggestionStripView mSuggestionStripView;
|
2013-02-26 07:25:30 +00:00
|
|
|
// Never null
|
|
|
|
private SuggestedWords mSuggestedWords = SuggestedWords.EMPTY;
|
2013-07-29 08:47:13 +00:00
|
|
|
private Suggest mSuggest;
|
2010-12-11 08:06:24 +00:00
|
|
|
private CompletionInfo[] mApplicationSpecifiedCompletions;
|
2013-05-15 07:49:15 +00:00
|
|
|
private AppWorkaroundsUtils mAppWorkAroundsUtils = new AppWorkaroundsUtils();
|
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;
|
2013-07-31 05:42:50 +00:00
|
|
|
private UserHistoryPredictionDictionary mUserHistoryPredictionDictionary;
|
2013-08-01 06:38:40 +00:00
|
|
|
private PersonalizationPredictionDictionary mPersonalizationPredictionDictionary;
|
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();
|
2013-03-25 10:00:38 +00:00
|
|
|
private final RichInputConnection mConnection = new RichInputConnection(this);
|
2013-04-16 03:44:39 +00:00
|
|
|
private final RecapitalizeStatus mRecapitalizeStatus = new RecapitalizeStatus();
|
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;
|
2013-01-17 10:27:39 +00:00
|
|
|
private TreeSet<Long> mCurrentlyPressedHardwareKeys = CollectionUtils.newTreeSet();
|
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.
|
|
|
|
private BroadcastReceiver mDictionaryPackInstallReceiver =
|
2013-06-06 05:11:20 +00:00
|
|
|
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
|
|
|
|
2013-05-15 03:12:58 +00:00
|
|
|
// TODO: This boolean is persistent state and causes large side effects at unexpected times.
|
|
|
|
// Find a way to remove it for readability.
|
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;
|
2013-04-10 07:38:37 +00:00
|
|
|
private static final int MSG_RESUME_SUGGESTIONS = 4;
|
2013-06-13 06:26:47 +00:00
|
|
|
private static final int MSG_REOPEN_DICTIONARIES = 5;
|
2012-09-12 04:03:44 +00:00
|
|
|
|
|
|
|
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;
|
2013-04-10 07:38:37 +00:00
|
|
|
case MSG_RESUME_SUGGESTIONS:
|
|
|
|
latinIme.restartSuggestionsOnWordTouchedByCursor();
|
|
|
|
break;
|
2013-06-13 06:26:47 +00:00
|
|
|
case MSG_REOPEN_DICTIONARIES:
|
|
|
|
latinIme.initSuggest();
|
|
|
|
// In theory we could call latinIme.updateSuggestionStrip() right away, but
|
|
|
|
// in the practice, the dictionary is not finished opening yet so we wouldn't
|
|
|
|
// get any suggestions. Wait one frame.
|
|
|
|
postUpdateSuggestionStrip();
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-06-13 06:26:47 +00:00
|
|
|
public void postReopenDictionaries() {
|
|
|
|
sendMessage(obtainMessage(MSG_REOPEN_DICTIONARIES));
|
|
|
|
}
|
|
|
|
|
2013-04-10 07:38:37 +00:00
|
|
|
public void postResumeSuggestions() {
|
2013-05-08 09:44:50 +00:00
|
|
|
removeMessages(MSG_RESUME_SUGGESTIONS);
|
2013-04-10 07:38:37 +00:00
|
|
|
sendMessageDelayed(obtainMessage(MSG_RESUME_SUGGESTIONS), mDelayUpdateSuggestions);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-06-13 06:26:47 +00:00
|
|
|
public boolean hasPendingReopenDictionaries() {
|
|
|
|
return hasMessages(MSG_REOPEN_DICTIONARIES);
|
|
|
|
}
|
|
|
|
|
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 */);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-24 06:26:29 +00:00
|
|
|
// Loading the native library eagerly to avoid unexpected UnsatisfiedLinkError at the initial
|
|
|
|
// JNI call as much as possible.
|
|
|
|
static {
|
|
|
|
JniUtils.loadNativeLibrary();
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
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);
|
2013-08-12 03:20:18 +00:00
|
|
|
PersonalizationDictionarySessionRegister.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
|
|
|
|
2013-04-18 03:34:45 +00:00
|
|
|
// TODO: Resolve mutual dependencies of {@link #loadSettings()} and {@link #initSuggest()}.
|
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-03-18 09:21:18 +00:00
|
|
|
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
|
2013-02-14 00:19:01 +00:00
|
|
|
ResearchLogger.getInstance().init(this, mKeyboardSwitcher, mSuggest);
|
2013-01-24 19:12:58 +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
|
|
|
|
2013-06-06 05:11:20 +00:00
|
|
|
final IntentFilter packageFilter = new IntentFilter();
|
|
|
|
packageFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
|
|
|
|
packageFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
|
|
|
|
packageFilter.addDataScheme(SCHEME_PACKAGE);
|
|
|
|
registerReceiver(mDictionaryPackInstallReceiver, packageFilter);
|
|
|
|
|
|
|
|
final IntentFilter newDictFilter = new IntentFilter();
|
|
|
|
newDictFilter.addAction(DictionaryPackConstants.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);
|
2013-05-21 22:32:08 +00:00
|
|
|
AudioAndHapticFeedbackManager.getInstance().onSettingsChanged(mSettings.getCurrent());
|
2013-06-13 06:26:47 +00:00
|
|
|
// To load the keyboard we need to load all the settings once, but resetting the
|
|
|
|
// contacts dictionary should be deferred until after the new layout has been displayed
|
|
|
|
// to improve responsivity. In the language switching process, we post a reopenDictionaries
|
|
|
|
// message, then come here to read the settings for the new language before we change
|
|
|
|
// the layout; at this time, we need to skip resetting the contacts dictionary. It will
|
|
|
|
// be done later inside {@see #initSuggest()} when the reopenDictionaries message is
|
|
|
|
// processed.
|
|
|
|
if (!mHandler.hasPendingReopenDictionaries()) {
|
|
|
|
// May need to reset the contacts dictionary depending on the user settings.
|
|
|
|
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
|
|
|
|
2013-07-30 05:44:09 +00:00
|
|
|
final Suggest newSuggest = new Suggest(this /* Context */, subtypeLocale,
|
2012-07-24 06:56:25 +00:00
|
|
|
this /* SuggestInitializationListener */);
|
2013-07-30 03:54:33 +00:00
|
|
|
final SettingsValues settingsValues = mSettings.getCurrent();
|
|
|
|
if (settingsValues.mCorrectionEnabled) {
|
2013-07-30 05:44:09 +00:00
|
|
|
newSuggest.setAutoCorrectionThreshold(settingsValues.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);
|
2013-03-18 09:21:18 +00:00
|
|
|
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
|
2013-07-30 05:44:09 +00:00
|
|
|
ResearchLogger.getInstance().initSuggest(newSuggest);
|
2012-06-16 00:49:42 +00:00
|
|
|
}
|
2012-04-19 14:11:31 +00:00
|
|
|
|
2012-06-08 08:01:35 +00:00
|
|
|
mUserDictionary = new UserBinaryDictionary(this, localeStr);
|
|
|
|
mIsUserDictionaryAvailable = mUserDictionary.isEnabled();
|
2013-07-30 05:44:09 +00:00
|
|
|
newSuggest.setUserDictionary(mUserDictionary);
|
2011-01-07 06:01:51 +00:00
|
|
|
|
2013-01-08 07:35:21 +00:00
|
|
|
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
2013-07-30 05:44:09 +00:00
|
|
|
|
2013-07-31 05:42:50 +00:00
|
|
|
mUserHistoryPredictionDictionary = PersonalizationDictionaryHelper
|
|
|
|
.getUserHistoryPredictionDictionary(this, localeStr, prefs);
|
2013-07-30 05:44:09 +00:00
|
|
|
newSuggest.setUserHistoryPredictionDictionary(mUserHistoryPredictionDictionary);
|
2013-08-01 06:38:40 +00:00
|
|
|
mPersonalizationPredictionDictionary = PersonalizationDictionaryHelper
|
|
|
|
.getPersonalizationPredictionDictionary(this, localeStr, prefs);
|
|
|
|
newSuggest.setPersonalizationPredictionDictionary(mPersonalizationPredictionDictionary);
|
2013-07-30 05:44:09 +00:00
|
|
|
|
|
|
|
final Suggest oldSuggest = mSuggest;
|
|
|
|
resetContactsDictionary(null != oldSuggest ? oldSuggest.getContactsDictionary() : null);
|
|
|
|
mSuggest = newSuggest;
|
|
|
|
if (oldSuggest != null) oldSuggest.close();
|
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-07-30 05:44:09 +00:00
|
|
|
final Suggest suggest = mSuggest;
|
2013-01-08 07:35:21 +00:00
|
|
|
final boolean shouldSetDictionary =
|
2013-07-30 05:44:09 +00:00
|
|
|
(null != suggest && 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
|
|
|
}
|
|
|
|
|
2013-07-30 05:44:09 +00:00
|
|
|
if (null != suggest) {
|
|
|
|
suggest.setContactsDictionary(dictionaryToUse);
|
2011-08-09 02:54:10 +00:00
|
|
|
}
|
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() {
|
2013-07-30 05:44:09 +00:00
|
|
|
final Suggest suggest = mSuggest;
|
|
|
|
if (suggest != null) {
|
|
|
|
suggest.close();
|
2011-01-07 06:01:51 +00:00
|
|
|
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);
|
2013-03-19 01:48:10 +00:00
|
|
|
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
|
2013-02-27 01:53:05 +00:00
|
|
|
ResearchLogger.getInstance().onDestroy();
|
|
|
|
}
|
2013-06-06 05:11:20 +00:00
|
|
|
unregisterReceiver(mDictionaryPackInstallReceiver);
|
2010-08-20 05:35:02 +00:00
|
|
|
LatinImeLogger.commit();
|
|
|
|
LatinImeLogger.onDestroy();
|
2009-03-13 22:11:42 +00:00
|
|
|
super.onDestroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
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
|
|
|
}
|
2013-08-12 03:20:18 +00:00
|
|
|
PersonalizationDictionarySessionRegister.onConfigurationChanged(this, conf);
|
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
|
|
|
}
|
|
|
|
|
2013-08-08 07:13:17 +00:00
|
|
|
private void setInputViewMinHeight(final int minHeight) {
|
|
|
|
if (mInputView != null && mInputViewMinHeight != minHeight) {
|
|
|
|
mInputView.setMinimumHeight(minHeight);
|
|
|
|
mInputViewMinHeight = minHeight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-25 09:28:03 +00:00
|
|
|
@Override
|
2013-08-08 07:13:17 +00:00
|
|
|
public void setInputView(final View inputView) {
|
|
|
|
super.setInputView(inputView);
|
|
|
|
mInputView = inputView;
|
|
|
|
setInputViewMinHeight(0);
|
|
|
|
mSuggestionStripView = (SuggestionStripView)inputView.findViewById(
|
|
|
|
R.id.suggestion_strip_view);
|
|
|
|
if (mSuggestionStripView != null) {
|
|
|
|
mSuggestionStripView.setListener(this, inputView);
|
|
|
|
}
|
2011-09-21 01:41:31 +00:00
|
|
|
if (LatinImeLogger.sVISUALDEBUG) {
|
2013-08-08 07:13:17 +00:00
|
|
|
inputView.setBackgroundColor(0x10FF0000);
|
2011-09-21 01:41:31 +00:00
|
|
|
}
|
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();
|
2013-07-30 03:57:35 +00:00
|
|
|
// If we are starting input in a different text field from before, we'll have to reload
|
|
|
|
// settings, so currentSettingsValues can't be final.
|
|
|
|
SettingsValues currentSettingsValues = mSettings.getCurrent();
|
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
|
|
|
}
|
2013-03-18 09:21:18 +00:00
|
|
|
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
|
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");
|
|
|
|
}
|
|
|
|
|
2013-05-15 07:49:15 +00:00
|
|
|
final PackageInfo packageInfo =
|
|
|
|
TargetPackageInfoGetterTask.getCachedPackageInfo(editorInfo.packageName);
|
|
|
|
mAppWorkAroundsUtils.setPackageInfo(packageInfo);
|
|
|
|
if (null == packageInfo) {
|
|
|
|
new TargetPackageInfoGetterTask(this /* context */, this /* listener */)
|
2012-05-25 09:19:19 +00:00
|
|
|
.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-07-29 09:53:23 +00:00
|
|
|
final boolean inputTypeChanged = !currentSettingsValues.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 */);
|
2013-06-25 10:35:23 +00:00
|
|
|
if (isDifferentTextField) mHandler.postResumeSuggestions();
|
2012-11-09 09:58:50 +00:00
|
|
|
mDeleteCount = 0;
|
|
|
|
mSpaceState = SPACE_STATE_NONE;
|
2013-04-16 03:44:39 +00:00
|
|
|
mRecapitalizeStatus.deactivate();
|
2013-01-17 10:27:39 +00:00
|
|
|
mCurrentlyPressedHardwareKeys.clear();
|
2012-11-09 09:58:50 +00:00
|
|
|
|
2013-04-18 03:34:45 +00:00
|
|
|
// Note: the following does a round-trip IPC on the main thread: be careful
|
|
|
|
final Locale currentLocale = mSubtypeSwitcher.getCurrentSubtypeLocale();
|
2013-07-30 05:44:09 +00:00
|
|
|
final Suggest suggest = mSuggest;
|
|
|
|
if (null != suggest && null != currentLocale && !currentLocale.equals(suggest.mLocale)) {
|
2013-04-18 03:34:45 +00:00
|
|
|
initSuggest();
|
|
|
|
}
|
2012-11-09 09:58:50 +00:00
|
|
|
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
|
|
|
}
|
2013-02-26 07:25:30 +00:00
|
|
|
mSuggestedWords = SuggestedWords.EMPTY;
|
2011-05-10 06:51:43 +00:00
|
|
|
|
2013-05-08 09:44:50 +00:00
|
|
|
mConnection.resetCachesUponCursorMove(editorInfo.initialSelStart,
|
|
|
|
false /* shouldFinishComposition */);
|
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();
|
2013-07-30 03:57:35 +00:00
|
|
|
currentSettingsValues = mSettings.getCurrent();
|
|
|
|
|
2013-07-30 05:44:09 +00:00
|
|
|
if (suggest != null && currentSettingsValues.mCorrectionEnabled) {
|
|
|
|
suggest.setAutoCorrectionThreshold(currentSettingsValues.mAutoCorrectionThreshold);
|
2012-07-25 10:31:19 +00:00
|
|
|
}
|
|
|
|
|
2013-07-29 09:53:23 +00:00
|
|
|
switcher.loadKeyboard(editorInfo, currentSettingsValues);
|
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-07-29 09:53:23 +00:00
|
|
|
mainKeyboardView.setKeyPreviewPopupEnabled(currentSettingsValues.mKeyPreviewPopupOn,
|
|
|
|
currentSettingsValues.mKeyPreviewPopupDismissDelay);
|
2013-01-24 07:08:33 +00:00
|
|
|
mainKeyboardView.setSlidingKeyInputPreviewEnabled(
|
2013-07-29 09:53:23 +00:00
|
|
|
currentSettingsValues.mSlidingKeyInputPreviewEnabled);
|
2013-01-08 07:35:21 +00:00
|
|
|
mainKeyboardView.setGestureHandlingEnabledByUser(
|
2013-08-09 12:07:40 +00:00
|
|
|
currentSettingsValues.mGestureInputEnabled,
|
|
|
|
currentSettingsValues.mGestureTrailEnabled,
|
2013-07-29 09:53:23 +00:00
|
|
|
currentSettingsValues.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(
|
2013-04-18 03:34:45 +00:00
|
|
|
mConnection, editorInfo, mLastSelectionEnd, currentLocale)) {
|
2012-12-13 12:59:13 +00:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
2013-05-15 07:49:15 +00:00
|
|
|
// Callback for the TargetPackageInfoGetterTask
|
2012-06-08 07:00:02 +00:00
|
|
|
@Override
|
2013-05-15 07:49:15 +00:00
|
|
|
public void onTargetPackageInfoKnown(final PackageInfo info) {
|
|
|
|
mAppWorkAroundsUtils.setPackageInfo(info);
|
2012-05-25 09:07:52 +00:00
|
|
|
}
|
|
|
|
|
2011-05-17 10:02:32 +00:00
|
|
|
@Override
|
|
|
|
public void onWindowHidden() {
|
|
|
|
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) {
|
2013-07-25 10:00:45 +00:00
|
|
|
mainKeyboardView.cancelAllOngoingEvents();
|
2013-07-30 11:29:19 +00:00
|
|
|
mainKeyboardView.deallocateMemory();
|
2012-08-07 02:48:10 +00:00
|
|
|
}
|
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();
|
2013-06-11 08:33:58 +00:00
|
|
|
// Should do the following in onFinishInputInternal but until JB MR2 it's not called :(
|
2013-05-29 09:44:40 +00:00
|
|
|
if (mWordComposer.isComposingWord()) mConnection.finishComposingText();
|
2012-12-14 08:44:43 +00:00
|
|
|
resetComposingState(true /* alsoResetLastComposedWord */);
|
2013-06-11 08:33:58 +00:00
|
|
|
mRichImm.clearSubtypeCaches();
|
2013-03-20 18:28:31 +00:00
|
|
|
// Notify ResearchLogger
|
2013-03-18 09:21:18 +00:00
|
|
|
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
|
2013-03-20 18:28:31 +00:00
|
|
|
ResearchLogger.latinIME_onFinishInputViewInternal(finishingInput, mLastSelectionStart,
|
|
|
|
mLastSelectionEnd, getCurrentInputConnection());
|
2012-08-13 02:28:31 +00:00
|
|
|
}
|
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
|
|
|
}
|
2013-03-18 09:21:18 +00:00
|
|
|
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
|
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
|
|
|
|
2013-06-21 06:59:06 +00:00
|
|
|
final boolean selectionChanged = mLastSelectionStart != newSelStart
|
|
|
|
|| mLastSelectionEnd != newSelEnd;
|
2013-06-26 03:22:04 +00:00
|
|
|
|
2012-02-20 01:26:41 +00:00
|
|
|
// 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
|
2013-06-21 06:59:06 +00:00
|
|
|
// the state. TODO: rescind this policy: the framework never removes the composing
|
|
|
|
// span on its own accord while editing. This test is useless.
|
2012-02-20 01:26:41 +00:00
|
|
|
final boolean noComposingSpan = composingSpanStart == -1 && composingSpanEnd == -1;
|
2013-06-26 03:22:04 +00:00
|
|
|
|
2013-05-15 03:12:58 +00:00
|
|
|
// If the keyboard is not visible, we don't need to do all the housekeeping work, as it
|
|
|
|
// will be reset when the keyboard shows up anyway.
|
|
|
|
// TODO: revisit this when LatinIME supports hardware keyboards.
|
|
|
|
// NOTE: the test harness subclasses LatinIME and overrides isInputViewShown().
|
|
|
|
// TODO: find a better way to simulate actual execution.
|
|
|
|
if (isInputViewShown() && !mExpectingUpdateSelection
|
2012-09-12 03:40:36 +00:00
|
|
|
&& !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;
|
|
|
|
|
2013-06-26 03:22:04 +00:00
|
|
|
// TODO: is it still necessary to test for composingSpan related stuff?
|
|
|
|
final boolean selectionChangedOrSafeToReset = selectionChanged
|
|
|
|
|| (!mWordComposer.isComposingWord()) || noComposingSpan;
|
2013-06-25 10:26:30 +00:00
|
|
|
final boolean hasOrHadSelection = (oldSelStart != oldSelEnd
|
|
|
|
|| newSelStart != newSelEnd);
|
|
|
|
final int moveAmount = newSelStart - oldSelStart;
|
|
|
|
if (selectionChangedOrSafeToReset && (hasOrHadSelection
|
|
|
|
|| !mWordComposer.moveCursorByAndReturnIfInsideComposingWord(moveAmount))) {
|
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);
|
2013-06-26 02:32:07 +00:00
|
|
|
} else {
|
|
|
|
// resetEntireInputState calls resetCachesUponCursorMove, but with the second
|
|
|
|
// argument as true. But in all cases where we don't reset the entire input state,
|
|
|
|
// we still want to tell the rich input connection about the new cursor position so
|
|
|
|
// that it can update its caches.
|
|
|
|
mConnection.resetCachesUponCursorMove(newSelStart,
|
|
|
|
false /* shouldFinishComposition */);
|
2011-10-03 05:58:34 +00:00
|
|
|
}
|
2012-02-16 19:45:35 +00:00
|
|
|
|
2013-04-30 05:23:55 +00:00
|
|
|
// We moved the cursor. If we are touching a word, we need to resume suggestion,
|
|
|
|
// unless suggestions are off.
|
|
|
|
if (isSuggestionsStripVisible()) {
|
|
|
|
mHandler.postResumeSuggestions();
|
|
|
|
}
|
2013-04-15 12:16:53 +00:00
|
|
|
// Reset the last recapitalization.
|
2013-04-16 03:44:39 +00:00
|
|
|
mRecapitalizeStatus.deactivate();
|
2012-09-24 05:40:23 +00:00
|
|
|
mKeyboardSwitcher.updateShiftState();
|
2011-06-08 07:47:19 +00:00
|
|
|
}
|
|
|
|
mExpectingUpdateSelection = false;
|
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
|
|
|
|
2013-03-07 18:39:55 +00:00
|
|
|
if (AccessibilityUtils.getInstance().isAccessibilityEnabled()) {
|
|
|
|
AccessibleKeyboardViewProxy.getInstance().onHideWindow();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
if (applicationSpecifiedCompletions == null) {
|
2012-07-23 09:03:16 +00:00
|
|
|
clearSuggestionStrip();
|
2013-03-18 09:21:18 +00:00
|
|
|
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
|
2012-08-02 00:26:45 +00:00
|
|
|
ResearchLogger.latinIME_onDisplayCompletions(null);
|
|
|
|
}
|
2012-06-12 00:35:51 +00:00
|
|
|
return;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2013-04-16 03:17:22 +00:00
|
|
|
mApplicationSpecifiedCompletions =
|
|
|
|
CompletionInfoUtils.removeNulls(applicationSpecifiedCompletions);
|
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;
|
2013-02-26 07:25:30 +00:00
|
|
|
setSuggestedWords(suggestedWords, isAutoCorrection);
|
2012-06-12 00:35:51 +00:00
|
|
|
setAutoCorrectionIndicator(isAutoCorrection);
|
|
|
|
setSuggestionStripShown(true);
|
2013-03-18 09:21:18 +00:00
|
|
|
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
|
2012-08-02 00:26:45 +00:00
|
|
|
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
|
2013-08-06 01:48:39 +00:00
|
|
|
if (onEvaluateInputViewShown() && mSuggestionStripView != 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()) {
|
2013-08-06 01:48:39 +00:00
|
|
|
mSuggestionStripView.setVisibility(
|
2011-09-01 05:54:28 +00:00
|
|
|
shouldShowSuggestions ? View.VISIBLE : View.GONE);
|
2011-04-13 05:12:24 +00:00
|
|
|
} else {
|
2013-08-06 01:48:39 +00:00
|
|
|
mSuggestionStripView.setVisibility(
|
2011-09-01 05:54:28 +00:00
|
|
|
shouldShowSuggestions ? View.VISIBLE : View.INVISIBLE);
|
2011-04-13 05:12:24 +00:00
|
|
|
}
|
2013-08-08 07:13:17 +00:00
|
|
|
if (shouldShowSuggestions && mainKeyboardView != null) {
|
|
|
|
final int remainingHeight = getWindow().getWindow().getDecorView().getHeight()
|
|
|
|
- mainKeyboardView.getHeight() - mSuggestionStripView.getHeight();
|
|
|
|
mSuggestionStripView.setMoreSuggestionsHeight(remainingHeight);
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
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();
|
2013-08-06 01:48:39 +00:00
|
|
|
if (mainKeyboardView == null || mSuggestionStripView == null) {
|
2011-04-21 05:51:53 +00:00
|
|
|
return;
|
2012-08-07 02:48:10 +00:00
|
|
|
}
|
2013-08-08 07:13:17 +00:00
|
|
|
// This method is never called when in fullscreen mode.
|
|
|
|
// The contentTop is the top coordinate of the keyboard. The application behind will be
|
|
|
|
// resized/panned above this coordibnate to be able to show an input field.
|
|
|
|
final int contentTop = mInputView.getHeight() - mainKeyboardView.getHeight();
|
|
|
|
final int suggestionsHeight = (mSuggestionStripView.getVisibility() == View.VISIBLE)
|
|
|
|
? mSuggestionStripView.getHeight() : 0;
|
|
|
|
// The visibleTop is the top coordinates of the visible part of this IME. The application
|
|
|
|
// behind will never be resized, but may be panned or scrolled.
|
|
|
|
final int visibleTop = mainKeyboardView.isShowingMoreKeysPanel() ? 0
|
|
|
|
: contentTop - suggestionsHeight;
|
|
|
|
outInsets.contentTopInsets = contentTop;
|
|
|
|
outInsets.visibleTopInsets = visibleTop;
|
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()) {
|
2013-08-08 07:13:17 +00:00
|
|
|
final int touchLeft = 0;
|
|
|
|
final int touchTop = visibleTop;
|
|
|
|
final int touchRight = touchLeft + mainKeyboardView.getWidth();
|
|
|
|
final int touchBottom = contentTop + mainKeyboardView.getHeight()
|
2011-04-13 05:12:24 +00:00
|
|
|
// Extend touchable region below the keyboard.
|
|
|
|
+ EXTENDED_TOUCHABLE_REGION_HEIGHT;
|
2013-08-08 07:13:17 +00:00
|
|
|
// The touch event on touchableRegion will be delivered to this IME.
|
|
|
|
outInsets.touchableRegion.set(touchLeft, touchTop, touchRight, touchBottom);
|
2012-04-02 13:25:08 +00:00
|
|
|
outInsets.touchableInsets = InputMethodService.Insets.TOUCHABLE_INSETS_REGION;
|
2011-01-21 10:04:00 +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
|
|
|
@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();
|
2013-08-08 07:13:17 +00:00
|
|
|
if (!isFullscreenMode()) {
|
|
|
|
// Expand the input view to cover entire display to be able to show key previews and
|
|
|
|
// more suggestions view that may be displayed above the keyboard.
|
|
|
|
setInputViewMinHeight(getResources().getDisplayMetrics().heightPixels);
|
|
|
|
}
|
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) {
|
2013-05-08 09:44:50 +00:00
|
|
|
final boolean shouldFinishComposition = mWordComposer.isComposingWord();
|
2012-02-20 02:08:40 +00:00
|
|
|
resetComposingState(true /* alsoResetLastComposedWord */);
|
2013-07-30 03:54:33 +00:00
|
|
|
final SettingsValues settingsValues = mSettings.getCurrent();
|
|
|
|
if (settingsValues.mBigramPredictionEnabled) {
|
2012-09-04 10:54:55 +00:00
|
|
|
clearSuggestionStrip();
|
|
|
|
} else {
|
2013-07-30 03:54:33 +00:00
|
|
|
setSuggestedWords(settingsValues.mSuggestPuncList, false);
|
2012-09-04 10:54:55 +00:00
|
|
|
}
|
2013-05-08 09:44:50 +00:00
|
|
|
mConnection.resetCachesUponCursorMove(newCursorPosition, shouldFinishComposition);
|
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) {
|
2013-03-18 09:21:18 +00:00
|
|
|
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
|
2012-12-23 23:12:51 +00:00
|
|
|
ResearchLogger.getInstance().onWordFinished(typedWord, mWordComposer.isBatchMode());
|
2012-08-28 17:26:21 +00:00
|
|
|
}
|
2013-03-26 00:17:48 +00:00
|
|
|
commitChosenWord(typedWord, LastComposedWord.COMMIT_TYPE_USER_TYPED_WORD,
|
|
|
|
separatorString);
|
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
|
|
|
}
|
|
|
|
|
2013-04-15 13:00:29 +00:00
|
|
|
public int getCurrentRecapitalizeState() {
|
|
|
|
if (!mRecapitalizeStatus.isActive()
|
|
|
|
|| !mRecapitalizeStatus.isSetAt(mLastSelectionStart, mLastSelectionEnd)) {
|
|
|
|
// Not recapitalizing at the moment
|
|
|
|
return RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE;
|
|
|
|
}
|
|
|
|
return mRecapitalizeStatus.getCurrentMode();
|
|
|
|
}
|
|
|
|
|
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-12-23 23:12:51 +00:00
|
|
|
final 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);
|
2013-03-18 09:21:18 +00:00
|
|
|
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
|
2012-12-23 23:12:51 +00:00
|
|
|
ResearchLogger.latinIME_swapSwapperAndSpace(lastTwo, 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-07-30 03:54:33 +00:00
|
|
|
final SettingsValues settingsValues = mSettings.getCurrent();
|
|
|
|
if (!settingsValues.mCorrectionEnabled) return false;
|
|
|
|
if (!settingsValues.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);
|
2013-03-18 09:21:18 +00:00
|
|
|
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
|
2012-12-23 23:12:51 +00:00
|
|
|
ResearchLogger.latinIME_maybeDoubleSpacePeriod(textToInsert,
|
|
|
|
false /* isBatchMode */);
|
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;
|
|
|
|
}
|
2013-01-16 13:07:43 +00:00
|
|
|
final String wordToEdit;
|
2013-02-12 07:15:47 +00:00
|
|
|
if (CapsModeUtils.isAutoCapsMode(mLastComposedWord.mCapitalizedMode)) {
|
2013-01-16 13:07:43 +00:00
|
|
|
wordToEdit = word.toLowerCase(mSubtypeSwitcher.getCurrentSubtypeLocale());
|
|
|
|
} else {
|
|
|
|
wordToEdit = word;
|
|
|
|
}
|
|
|
|
mUserDictionary.addWordToUserDictionary(wordToEdit);
|
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(
|
2013-01-16 13:07:43 +00:00
|
|
|
mConnection, getCurrentInputEditorInfo(), mLastSelectionEnd,
|
|
|
|
mSubtypeSwitcher.getCurrentSubtypeLocale())) {
|
2012-12-13 12:59:13 +00:00
|
|
|
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
|
|
|
@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) {
|
2013-07-02 09:07:35 +00:00
|
|
|
case Constants.CUSTOM_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 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) {
|
2013-03-18 09:21:18 +00:00
|
|
|
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
|
2013-01-10 22:40:29 +00:00
|
|
|
ResearchLogger.latinIME_sendKeyCodePoint(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-02-07 08:07:23 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-15 07:49:15 +00:00
|
|
|
if (Constants.CODE_ENTER == code && mAppWorkAroundsUtils.isBeforeJellyBean()) {
|
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) {
|
2013-03-18 09:21:18 +00:00
|
|
|
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
|
2013-01-10 22:40:29 +00:00
|
|
|
ResearchLogger.latinIME_onCodeInput(primaryCode, x, 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:
|
2013-05-22 00:14:31 +00:00
|
|
|
// Note: Calling back to the keyboard on Shift key is handled in
|
|
|
|
// {@link #onPressKey(int,boolean)} and {@link #onReleaseKey(int,boolean)}.
|
2013-04-16 03:33:41 +00:00
|
|
|
final Keyboard currentKeyboard = switcher.getKeyboard();
|
|
|
|
if (null != currentKeyboard && currentKeyboard.mId.isAlphabetKeyboard()) {
|
|
|
|
// TODO: Instead of checking for alphabetic keyboard here, separate keycodes for
|
|
|
|
// alphabetic shift and shift while in symbol layout.
|
|
|
|
handleRecapitalize();
|
|
|
|
}
|
2012-12-03 13:00:35 +00:00
|
|
|
break;
|
2013-05-22 00:14:31 +00:00
|
|
|
case Constants.CODE_CAPSLOCK:
|
|
|
|
// Note: Changing keyboard to shift lock state is handled in
|
|
|
|
// {@link KeyboardSwitcher#onCodeInput(int)}.
|
|
|
|
break;
|
2012-10-29 05:46:34 +00:00
|
|
|
case Constants.CODE_SWITCH_ALPHA_SYMBOL:
|
2013-05-22 00:14:31 +00:00
|
|
|
// Note: Calling back to the keyboard on symbol key is handled in
|
|
|
|
// {@link #onPressKey(int,boolean)} and {@link #onReleaseKey(int,boolean)}.
|
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_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;
|
2013-08-05 09:21:55 +00:00
|
|
|
case Constants.CODE_EMOJI:
|
|
|
|
// TODO: Implement emoji keyboard switch.
|
|
|
|
break;
|
2013-02-19 19:45:44 +00:00
|
|
|
case Constants.CODE_ENTER:
|
|
|
|
final EditorInfo editorInfo = getCurrentInputEditorInfo();
|
|
|
|
final int imeOptionsActionId =
|
|
|
|
InputTypeUtils.getImeOptionsActionIdFromEditorInfo(editorInfo);
|
|
|
|
if (InputTypeUtils.IME_ACTION_CUSTOM_LABEL == imeOptionsActionId) {
|
|
|
|
// Either we have an actionLabel and we should performEditorAction with actionId
|
|
|
|
// regardless of its value.
|
|
|
|
performEditorAction(editorInfo.actionId);
|
|
|
|
} else if (EditorInfo.IME_ACTION_NONE != imeOptionsActionId) {
|
|
|
|
// We didn't have an actionLabel, but we had another action to execute.
|
|
|
|
// EditorInfo.IME_ACTION_NONE explicitly means no action. In contrast,
|
|
|
|
// EditorInfo.IME_ACTION_UNSPECIFIED is the default value for an action, so it
|
|
|
|
// means there should be an action and the app didn't bother to set a specific
|
|
|
|
// code for it - presumably it only handles one. It does not have to be treated
|
|
|
|
// in any specific way: anything that is not IME_ACTION_NONE should be sent to
|
|
|
|
// performEditorAction.
|
|
|
|
performEditorAction(imeOptionsActionId);
|
|
|
|
} else {
|
|
|
|
// No action label, and the action from imeOptions is NONE: this is a regular
|
|
|
|
// enter key that should input a carriage return.
|
|
|
|
didAutoCorrect = handleNonSpecialCharacter(Constants.CODE_ENTER, x, y, spaceState);
|
2010-10-22 10:35:23 +00:00
|
|
|
}
|
2013-01-15 08:33:58 +00:00
|
|
|
break;
|
|
|
|
case Constants.CODE_SHIFT_ENTER:
|
|
|
|
didAutoCorrect = handleNonSpecialCharacter(Constants.CODE_ENTER, x, y, spaceState);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
didAutoCorrect = handleNonSpecialCharacter(primaryCode, x, y, spaceState);
|
2011-06-08 07:47:19 +00:00
|
|
|
break;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2011-12-07 10:31:11 +00:00
|
|
|
switcher.onCodeInput(primaryCode);
|
2013-05-22 00:14:31 +00:00
|
|
|
// Reset after any single keystroke, except shift, capslock, and symbol-shift
|
2012-10-29 05:46:34 +00:00
|
|
|
if (!didAutoCorrect && primaryCode != Constants.CODE_SHIFT
|
2013-05-22 00:14:31 +00:00
|
|
|
&& primaryCode != Constants.CODE_CAPSLOCK
|
2012-10-29 05:46:34 +00:00
|
|
|
&& 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();
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2013-01-15 08:33:58 +00:00
|
|
|
private boolean handleNonSpecialCharacter(final int primaryCode, final int x, final int y,
|
|
|
|
final int spaceState) {
|
|
|
|
mSpaceState = SPACE_STATE_NONE;
|
|
|
|
final boolean didAutoCorrect;
|
2013-07-30 03:54:33 +00:00
|
|
|
final SettingsValues settingsValues = mSettings.getCurrent();
|
|
|
|
if (settingsValues.isWordSeparator(primaryCode)) {
|
2013-01-15 08:33:58 +00:00
|
|
|
didAutoCorrect = handleSeparator(primaryCode, x, y, spaceState);
|
|
|
|
} else {
|
|
|
|
didAutoCorrect = false;
|
|
|
|
if (SPACE_STATE_PHANTOM == spaceState) {
|
2013-07-30 03:54:33 +00:00
|
|
|
if (settingsValues.mIsInternal) {
|
2013-01-15 08:33:58 +00:00
|
|
|
if (mWordComposer.isComposingWord() && mWordComposer.isBatchMode()) {
|
2013-07-05 09:23:22 +00:00
|
|
|
LatinImeLoggerUtils.onAutoCorrection(
|
2013-01-15 08:33:58 +00:00
|
|
|
"", mWordComposer.getTypedWord(), " ", mWordComposer);
|
|
|
|
}
|
|
|
|
}
|
2013-04-10 09:30:11 +00:00
|
|
|
if (mWordComposer.isCursorFrontOrMiddleOfComposingWord()) {
|
|
|
|
// If we are in the middle of a recorrection, we need to commit the recorrection
|
|
|
|
// first so that we can insert the character at the current cursor position.
|
|
|
|
resetEntireInputState(mLastSelectionStart);
|
|
|
|
} else {
|
|
|
|
commitTyped(LastComposedWord.NOT_A_SEPARATOR);
|
|
|
|
}
|
2013-01-15 08:33:58 +00:00
|
|
|
}
|
|
|
|
final int keyX, keyY;
|
|
|
|
final Keyboard keyboard = mKeyboardSwitcher.getKeyboard();
|
|
|
|
if (keyboard != null && keyboard.hasProximityCharsCorrection(primaryCode)) {
|
|
|
|
keyX = x;
|
|
|
|
keyY = y;
|
|
|
|
} else {
|
|
|
|
keyX = Constants.NOT_A_COORDINATE;
|
|
|
|
keyY = Constants.NOT_A_COORDINATE;
|
|
|
|
}
|
|
|
|
handleCharacter(primaryCode, keyX, keyY, spaceState);
|
|
|
|
}
|
|
|
|
mExpectingUpdateSelection = true;
|
|
|
|
return didAutoCorrect;
|
|
|
|
}
|
|
|
|
|
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();
|
2013-08-05 09:39:07 +00:00
|
|
|
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS
|
|
|
|
&& ResearchLogger.RESEARCH_KEY_OUTPUT_TEXT.equals(rawText)) {
|
|
|
|
ResearchLogger.getInstance().onResearchKeySelected(this);
|
|
|
|
return;
|
|
|
|
}
|
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);
|
2013-03-18 09:21:18 +00:00
|
|
|
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
|
2012-12-23 23:12:51 +00:00
|
|
|
ResearchLogger.latinIME_onTextInput(text, false /* isBatchMode */);
|
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);
|
2013-01-25 08:00:41 +00:00
|
|
|
mHandler.cancelUpdateSuggestionStrip();
|
2012-07-04 06:24:59 +00:00
|
|
|
mConnection.beginBatchEdit();
|
2013-07-30 03:54:33 +00:00
|
|
|
final SettingsValues settingsValues = mSettings.getCurrent();
|
2012-07-04 06:24:59 +00:00
|
|
|
if (mWordComposer.isComposingWord()) {
|
2013-07-30 03:54:33 +00:00
|
|
|
if (settingsValues.mIsInternal) {
|
2012-09-19 07:18:24 +00:00
|
|
|
if (mWordComposer.isBatchMode()) {
|
2013-07-05 09:23:22 +00:00
|
|
|
LatinImeLoggerUtils.onAutoCorrection(
|
|
|
|
"", mWordComposer.getTypedWord(), " ", mWordComposer);
|
2012-09-19 07:18:24 +00:00
|
|
|
}
|
|
|
|
}
|
2013-01-11 11:31:09 +00:00
|
|
|
final int wordComposerSize = mWordComposer.size();
|
|
|
|
// Since isComposingWord() is true, the size is at least 1.
|
2013-04-10 09:30:11 +00:00
|
|
|
if (mWordComposer.isCursorFrontOrMiddleOfComposingWord()) {
|
|
|
|
// If we are in the middle of a recorrection, we need to commit the recorrection
|
|
|
|
// first so that we can insert the batch input at the current cursor position.
|
|
|
|
resetEntireInputState(mLastSelectionStart);
|
|
|
|
} else if (wordComposerSize <= 1) {
|
2012-09-20 06:52:40 +00:00
|
|
|
// 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;
|
2013-05-07 08:07:47 +00:00
|
|
|
}
|
|
|
|
final int codePointBeforeCursor = mConnection.getCodePointBeforeCursor();
|
|
|
|
if (Character.isLetterOrDigit(codePointBeforeCursor)
|
2013-07-30 03:54:33 +00:00
|
|
|
|| settingsValues.isUsuallyFollowedBySpace(codePointBeforeCursor)) {
|
2013-05-07 08:07:47 +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;
|
2013-04-10 09:27:11 +00:00
|
|
|
private final Object mLock = new Object();
|
|
|
|
private boolean mInBatchInput; // synchronized using {@link #mLock}.
|
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.
|
2013-04-10 09:27:11 +00:00
|
|
|
public void onStartBatchInput(final LatinIME latinIme) {
|
|
|
|
synchronized (mLock) {
|
|
|
|
mHandler.removeMessages(MSG_UPDATE_GESTURE_PREVIEW_AND_SUGGESTION_STRIP);
|
|
|
|
mInBatchInput = true;
|
2013-06-03 08:59:26 +00:00
|
|
|
mLatinIme = latinIme;
|
|
|
|
mLatinIme.mHandler.showGesturePreviewAndSuggestionStrip(
|
|
|
|
SuggestedWords.EMPTY, false /* dismissGestureFloatingPreviewText */);
|
2013-04-10 09:27:11 +00:00
|
|
|
}
|
2012-09-27 10:01:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Run in the Handler thread.
|
2013-04-10 09:27:11 +00:00
|
|
|
private void updateBatchInput(final InputPointers batchPointers) {
|
|
|
|
synchronized (mLock) {
|
|
|
|
if (!mInBatchInput) {
|
|
|
|
// Batch input has ended or canceled while the message was being delivered.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
final SuggestedWords suggestedWords = getSuggestedWordsGestureLocked(batchPointers);
|
|
|
|
mLatinIme.mHandler.showGesturePreviewAndSuggestionStrip(
|
|
|
|
suggestedWords, false /* dismissGestureFloatingPreviewText */);
|
2012-09-27 10:01:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
}
|
|
|
|
|
2013-04-10 09:27:11 +00:00
|
|
|
public void onCancelBatchInput() {
|
|
|
|
synchronized (mLock) {
|
|
|
|
mInBatchInput = false;
|
|
|
|
mLatinIme.mHandler.showGesturePreviewAndSuggestionStrip(
|
|
|
|
SuggestedWords.EMPTY, true /* dismissGestureFloatingPreviewText */);
|
|
|
|
}
|
2012-11-22 06:39:28 +00:00
|
|
|
}
|
|
|
|
|
2012-09-27 10:01:17 +00:00
|
|
|
// Run in the UI thread.
|
2013-04-10 09:27:11 +00:00
|
|
|
public SuggestedWords onEndBatchInput(final InputPointers batchPointers) {
|
|
|
|
synchronized (mLock) {
|
|
|
|
mInBatchInput = false;
|
|
|
|
final SuggestedWords suggestedWords = getSuggestedWordsGestureLocked(batchPointers);
|
|
|
|
mLatinIme.mHandler.showGesturePreviewAndSuggestionStrip(
|
|
|
|
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 =
|
2013-04-19 02:48:14 +00:00
|
|
|
mLatinIme.getSuggestedWordsOrOlderSuggestions(Suggest.SESSION_GESTURE);
|
2012-12-17 06:11:44 +00:00
|
|
|
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);
|
2013-01-21 06:57:32 +00:00
|
|
|
final MainKeyboardView mainKeyboardView = mKeyboardSwitcher.getMainKeyboardView();
|
2013-01-10 02:31:47 +00:00
|
|
|
mainKeyboardView.showGestureFloatingPreviewText(suggestedWords);
|
2012-09-12 04:03:44 +00:00
|
|
|
if (dismissGestureFloatingPreviewText) {
|
|
|
|
mainKeyboardView.dismissGestureFloatingPreviewText();
|
|
|
|
}
|
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();
|
2013-03-18 09:21:18 +00:00
|
|
|
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
|
2013-01-15 21:48:15 +00:00
|
|
|
ResearchLogger.latinIME_onEndBatchInput(batchInputText, 0, suggestedWords);
|
2012-08-10 21:21:18 +00:00
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-14 03:25:21 +00:00
|
|
|
// Called from PointerTracker through the KeyboardActionListener interface
|
|
|
|
@Override
|
|
|
|
public void onFinishSlidingInput() {
|
|
|
|
// User finished sliding input.
|
|
|
|
mKeyboardSwitcher.onFinishSlidingInput();
|
|
|
|
}
|
|
|
|
|
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
|
2013-05-14 03:25:21 +00:00
|
|
|
// Nothing to do so far.
|
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
|
|
|
|
2013-04-10 09:30:11 +00:00
|
|
|
if (mWordComposer.isCursorFrontOrMiddleOfComposingWord()) {
|
|
|
|
// If we are in the middle of a recorrection, we need to commit the recorrection
|
|
|
|
// first so that we can remove the character at the current cursor position.
|
2013-04-10 07:38:37 +00:00
|
|
|
resetEntireInputState(mLastSelectionStart);
|
2013-04-10 09:30:11 +00:00
|
|
|
// When we exit this if-clause, mWordComposer.isComposingWord() will return false.
|
2013-04-10 07:38:37 +00:00
|
|
|
}
|
2011-12-13 14:24:37 +00:00
|
|
|
if (mWordComposer.isComposingWord()) {
|
2013-08-14 07:10:04 +00:00
|
|
|
if (mWordComposer.isBatchMode()) {
|
|
|
|
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
|
|
|
|
final String word = mWordComposer.getTypedWord();
|
|
|
|
ResearchLogger.latinIME_handleBackspace_batch(word, 1);
|
2012-07-04 06:24:59 +00:00
|
|
|
}
|
2013-08-14 07:10:04 +00:00
|
|
|
final String rejectedSuggestion = mWordComposer.getTypedWord();
|
|
|
|
mWordComposer.reset();
|
|
|
|
mWordComposer.setRejectedBatchModeSuggestion(rejectedSuggestion);
|
2009-03-13 22:11:42 +00:00
|
|
|
} else {
|
2013-08-14 07:10:04 +00:00
|
|
|
mWordComposer.deleteLast();
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2013-08-14 07:10:04 +00:00
|
|
|
mConnection.setComposingText(getTextWithUnderline(mWordComposer.getTypedWord()), 1);
|
|
|
|
mHandler.postUpdateSuggestionStrip();
|
2011-12-12 06:09:17 +00:00
|
|
|
} else {
|
2013-07-30 03:54:33 +00:00
|
|
|
final SettingsValues currentSettings = mSettings.getCurrent();
|
2012-02-22 09:09:23 +00:00
|
|
|
if (mLastComposedWord.canRevertCommit()) {
|
2013-07-30 03:54:33 +00:00
|
|
|
if (currentSettings.mIsInternal) {
|
2013-07-05 09:23:22 +00:00
|
|
|
LatinImeLoggerUtils.onAutoCorrectionCancellation();
|
2012-09-19 07:18:24 +00:00
|
|
|
}
|
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.
|
2013-08-14 07:10:04 +00:00
|
|
|
mConnection.deleteSurroundingText(mEnteredText.length(), 0);
|
2013-06-01 05:02:19 +00:00
|
|
|
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
|
|
|
|
ResearchLogger.latinIME_handleBackspace_cancelTextInput(mEnteredText);
|
|
|
|
}
|
2012-08-27 11:09:46 +00:00
|
|
|
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.
|
2013-01-10 22:50:11 +00:00
|
|
|
final int numCharsDeleted = 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;
|
2013-01-10 22:50:11 +00:00
|
|
|
mConnection.deleteSurroundingText(numCharsDeleted, 0);
|
2013-03-18 09:21:18 +00:00
|
|
|
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
|
2013-06-01 05:03:04 +00:00
|
|
|
ResearchLogger.latinIME_handleBackspace(numCharsDeleted,
|
|
|
|
false /* shouldUncommitLogUnit */);
|
2013-01-10 22:50:11 +00:00
|
|
|
}
|
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
|
|
|
}
|
2013-05-15 07:49:15 +00:00
|
|
|
if (mAppWorkAroundsUtils.isBeforeJellyBean()) {
|
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
|
|
|
}
|
2013-03-18 09:21:18 +00:00
|
|
|
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
|
2013-06-01 05:03:04 +00:00
|
|
|
ResearchLogger.latinIME_handleBackspace(1, true /* shouldUncommitLogUnit */);
|
2013-01-10 22:50:11 +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);
|
2013-03-18 09:21:18 +00:00
|
|
|
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
|
2013-06-01 05:03:04 +00:00
|
|
|
ResearchLogger.latinIME_handleBackspace(1,
|
|
|
|
true /* shouldUncommitLogUnit */);
|
2013-01-10 22:50:11 +00:00
|
|
|
}
|
2012-01-17 06:17:17 +00:00
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2013-07-30 03:54:33 +00:00
|
|
|
if (currentSettings.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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-11 11:23:48 +00:00
|
|
|
/*
|
|
|
|
* Strip a trailing space if necessary and returns whether it's a swap weak space situation.
|
|
|
|
*/
|
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;
|
2013-01-11 11:23:48 +00:00
|
|
|
}
|
|
|
|
if ((SPACE_STATE_WEAK == spaceState || SPACE_STATE_SWAP_PUNCTUATION == spaceState)
|
2012-02-08 02:48:19 +00:00
|
|
|
&& isFromSuggestionStrip) {
|
2013-07-30 03:54:33 +00:00
|
|
|
final SettingsValues currentSettings = mSettings.getCurrent();
|
|
|
|
if (currentSettings.isUsuallyPrecededBySpace(code)) return false;
|
|
|
|
if (currentSettings.isUsuallyFollowedBySpace(code)) return true;
|
2013-01-11 11:23:48 +00:00
|
|
|
mConnection.removeTrailingSpace();
|
2012-02-08 02:48:19 +00:00
|
|
|
}
|
2013-01-11 11:23:48 +00:00
|
|
|
return false;
|
2012-02-08 02:48:19 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2013-05-07 08:07:47 +00:00
|
|
|
// TODO: remove isWordConnector() and use isUsuallyFollowedBySpace() instead.
|
|
|
|
// See onStartBatchInput() to see how to do it.
|
2013-07-30 03:54:33 +00:00
|
|
|
final SettingsValues currentSettings = mSettings.getCurrent();
|
|
|
|
if (SPACE_STATE_PHANTOM == spaceState && !currentSettings.isWordConnector(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
|
|
|
}
|
|
|
|
|
2013-04-10 09:30:11 +00:00
|
|
|
if (mWordComposer.isCursorFrontOrMiddleOfComposingWord()) {
|
|
|
|
// If we are in the middle of a recorrection, we need to commit the recorrection
|
|
|
|
// first so that we can insert the character at the current cursor position.
|
2013-04-10 07:38:37 +00:00
|
|
|
resetEntireInputState(mLastSelectionStart);
|
|
|
|
isComposingWord = false;
|
|
|
|
}
|
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-07-30 03:54:33 +00:00
|
|
|
|| currentSettings.isWordConnector(primaryCode))
|
|
|
|
&& currentSettings.isSuggestionsRequested(mDisplayOrientation) &&
|
|
|
|
!mConnection.isCursorTouchingWord(currentSettings)) {
|
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();
|
2013-07-30 03:54:33 +00:00
|
|
|
if (currentSettings.mIsInternal) {
|
2013-07-05 09:23:22 +00:00
|
|
|
LatinImeLoggerUtils.onNonSeparator((char)primaryCode, x, y);
|
2012-09-19 07:18:24 +00:00
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2012-12-03 13:00:35 +00:00
|
|
|
private void handleRecapitalize() {
|
|
|
|
if (mLastSelectionStart == mLastSelectionEnd) return; // No selection
|
|
|
|
// If we have a recapitalize in progress, use it; otherwise, create a new one.
|
2013-04-16 03:44:39 +00:00
|
|
|
if (!mRecapitalizeStatus.isActive()
|
2012-12-03 13:00:35 +00:00
|
|
|
|| !mRecapitalizeStatus.isSetAt(mLastSelectionStart, mLastSelectionEnd)) {
|
2013-04-19 05:51:47 +00:00
|
|
|
final CharSequence selectedText =
|
|
|
|
mConnection.getSelectedText(0 /* flags, 0 for no styles */);
|
|
|
|
if (TextUtils.isEmpty(selectedText)) return; // Race condition with the input connection
|
2013-07-30 03:54:33 +00:00
|
|
|
final SettingsValues currentSettings = mSettings.getCurrent();
|
2013-04-16 03:44:39 +00:00
|
|
|
mRecapitalizeStatus.initialize(mLastSelectionStart, mLastSelectionEnd,
|
2013-07-30 03:54:33 +00:00
|
|
|
selectedText.toString(), currentSettings.mLocale,
|
|
|
|
currentSettings.mWordSeparators);
|
2012-12-03 13:00:35 +00:00
|
|
|
// We trim leading and trailing whitespace.
|
|
|
|
mRecapitalizeStatus.trim();
|
|
|
|
// Trimming the object may have changed the length of the string, and we need to
|
|
|
|
// reposition the selection handles accordingly. As this result in an IPC call,
|
|
|
|
// only do it if it's actually necessary, in other words if the recapitalize status
|
|
|
|
// is not set at the same place as before.
|
|
|
|
if (!mRecapitalizeStatus.isSetAt(mLastSelectionStart, mLastSelectionEnd)) {
|
|
|
|
mLastSelectionStart = mRecapitalizeStatus.getNewCursorStart();
|
|
|
|
mLastSelectionEnd = mRecapitalizeStatus.getNewCursorEnd();
|
|
|
|
mConnection.setSelection(mLastSelectionStart, mLastSelectionEnd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mRecapitalizeStatus.rotate();
|
|
|
|
final int numCharsDeleted = mLastSelectionEnd - mLastSelectionStart;
|
|
|
|
mConnection.setSelection(mLastSelectionEnd, mLastSelectionEnd);
|
|
|
|
mConnection.deleteSurroundingText(numCharsDeleted, 0);
|
|
|
|
mConnection.commitText(mRecapitalizeStatus.getRecapitalizedString(), 0);
|
|
|
|
mLastSelectionStart = mRecapitalizeStatus.getNewCursorStart();
|
|
|
|
mLastSelectionEnd = mRecapitalizeStatus.getNewCursorEnd();
|
|
|
|
mConnection.setSelection(mLastSelectionStart, mLastSelectionEnd);
|
2013-04-15 13:00:29 +00:00
|
|
|
// Match the keyboard to the new state.
|
|
|
|
mKeyboardSwitcher.updateShiftState();
|
2012-12-03 13:00:35 +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;
|
2013-04-10 09:30:11 +00:00
|
|
|
if (mWordComposer.isCursorFrontOrMiddleOfComposingWord()) {
|
|
|
|
// If we are in the middle of a recorrection, we need to commit the recorrection
|
|
|
|
// first so that we can insert the separator at the current cursor position.
|
|
|
|
resetEntireInputState(mLastSelectionStart);
|
|
|
|
}
|
2013-07-30 03:54:33 +00:00
|
|
|
final SettingsValues currentSettings = mSettings.getCurrent();
|
2011-12-13 14:24:37 +00:00
|
|
|
if (mWordComposer.isComposingWord()) {
|
2013-07-30 03:54:33 +00:00
|
|
|
if (currentSettings.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-07-30 03:54:33 +00:00
|
|
|
currentSettings.isUsuallyPrecededBySpace(primaryCode)) {
|
2012-11-12 05:05:51 +00:00
|
|
|
promotePhantomSpace();
|
2012-03-06 05:00:34 +00:00
|
|
|
}
|
2013-05-17 01:39:40 +00:00
|
|
|
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
|
|
|
|
ResearchLogger.latinIME_handleSeparator(primaryCode, mWordComposer.isComposingWord());
|
|
|
|
}
|
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-07-30 03:54:33 +00:00
|
|
|
if (currentSettings.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-11 11:23:48 +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-07-30 03:54:33 +00:00
|
|
|
&& currentSettings.isUsuallyFollowedBySpace(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
|
|
|
}
|
2013-07-30 03:54:33 +00:00
|
|
|
if (currentSettings.mIsInternal) {
|
2013-07-05 09:23:22 +00:00
|
|
|
LatinImeLoggerUtils.onSeparator((char)primaryCode, x, y);
|
2012-09-19 07:18:24 +00:00
|
|
|
}
|
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() {
|
2013-02-26 07:25:30 +00:00
|
|
|
if (mSuggestedWords == null) return false;
|
|
|
|
return mSettings.getCurrent().mSuggestPuncList == mSuggestedWords;
|
2010-11-13 10:09:30 +00:00
|
|
|
}
|
|
|
|
|
2012-07-09 03:54:42 +00:00
|
|
|
private boolean isSuggestionsStripVisible() {
|
2013-07-30 03:54:33 +00:00
|
|
|
final SettingsValues currentSettings = mSettings.getCurrent();
|
2013-05-14 11:44:22 +00:00
|
|
|
if (mSuggestionStripView == null)
|
2011-01-26 16:33:02 +00:00
|
|
|
return false;
|
2013-05-14 11:44:22 +00:00
|
|
|
if (mSuggestionStripView.isShowingAddToDictionaryHint())
|
2010-12-19 08:32:26 +00:00
|
|
|
return true;
|
2013-07-30 03:54:33 +00:00
|
|
|
if (null == currentSettings)
|
2013-04-30 05:23:55 +00:00
|
|
|
return false;
|
2013-07-30 03:54:33 +00:00
|
|
|
if (!currentSettings.isSuggestionStripVisibleInOrientation(mDisplayOrientation))
|
2010-12-19 08:32:26 +00:00
|
|
|
return false;
|
2013-07-30 03:54:33 +00:00
|
|
|
if (currentSettings.isApplicationSpecifiedCompletionsOn())
|
2010-12-19 08:32:26 +00:00
|
|
|
return true;
|
2013-07-30 03:54:33 +00:00
|
|
|
return currentSettings.isSuggestionsRequested(mDisplayOrientation);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2012-07-23 09:03:16 +00:00
|
|
|
private void clearSuggestionStrip() {
|
2013-02-26 07:25:30 +00:00
|
|
|
setSuggestedWords(SuggestedWords.EMPTY, false);
|
2012-03-02 11:04:42 +00:00
|
|
|
setAutoCorrectionIndicator(false);
|
2010-01-16 20:21:23 +00:00
|
|
|
}
|
|
|
|
|
2013-02-26 07:25:30 +00:00
|
|
|
private void setSuggestedWords(final SuggestedWords words, final boolean isAutoCorrection) {
|
|
|
|
mSuggestedWords = words;
|
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();
|
2013-07-30 03:54:33 +00:00
|
|
|
final SettingsValues currentSettings = mSettings.getCurrent();
|
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
|
2013-07-30 03:54:33 +00:00
|
|
|
|| !currentSettings.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-07-30 03:54:33 +00:00
|
|
|
if (!mWordComposer.isComposingWord() && !currentSettings.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
|
|
|
}
|
|
|
|
|
2013-04-19 02:48:14 +00:00
|
|
|
final SuggestedWords suggestedWords =
|
|
|
|
getSuggestedWordsOrOlderSuggestions(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();
|
2013-07-29 08:47:13 +00:00
|
|
|
final Suggest suggest = mSuggest;
|
|
|
|
if (keyboard == null || suggest == null) {
|
2012-10-03 04:01:52 +00:00
|
|
|
return SuggestedWords.EMPTY;
|
|
|
|
}
|
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.
|
2013-07-30 03:54:33 +00:00
|
|
|
final SettingsValues currentSettings = mSettings.getCurrent();
|
2012-10-03 06:19:43 +00:00
|
|
|
final String prevWord =
|
2013-07-30 03:54:33 +00:00
|
|
|
mConnection.getNthPreviousWord(currentSettings.mWordSeparators,
|
2012-07-06 07:14:52 +00:00
|
|
|
mWordComposer.isComposingWord() ? 2 : 1);
|
2013-07-29 08:47:13 +00:00
|
|
|
return suggest.getSuggestedWords(mWordComposer, prevWord, keyboard.getProximityInfo(),
|
2013-07-30 03:54:33 +00:00
|
|
|
currentSettings.mBlockPotentiallyOffensive,
|
|
|
|
currentSettings.mCorrectionEnabled, sessionId);
|
2013-04-19 02:48:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private SuggestedWords getSuggestedWordsOrOlderSuggestions(final int sessionId) {
|
|
|
|
return maybeRetrieveOlderSuggestions(mWordComposer.getTypedWord(),
|
|
|
|
getSuggestedWords(sessionId));
|
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
|
2013-04-19 02:48:14 +00:00
|
|
|
|| suggestedWords.mTypedWordValid || null == mSuggestionStripView
|
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) {
|
2013-02-26 07:25:30 +00:00
|
|
|
SuggestedWords previousSuggestedWords = mSuggestedWords;
|
|
|
|
if (previousSuggestedWords == mSettings.getCurrent().mSuggestPuncList) {
|
|
|
|
previousSuggestedWords = SuggestedWords.EMPTY;
|
2012-12-17 06:11:44 +00:00
|
|
|
}
|
|
|
|
if (typedWord == null) {
|
2013-02-26 07:25:30 +00:00
|
|
|
return previousSuggestedWords;
|
2012-12-17 06:11:44 +00:00
|
|
|
}
|
|
|
|
final ArrayList<SuggestedWords.SuggestedWordInfo> typedWordAndPreviousSuggestions =
|
2013-02-26 07:25:30 +00:00
|
|
|
SuggestedWords.getTypedWordAndPreviousSuggestions(typedWord,
|
|
|
|
previousSuggestedWords);
|
2012-12-17 06:11:44 +00:00
|
|
|
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();
|
2013-02-26 07:25:30 +00:00
|
|
|
setSuggestedWords(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.");
|
|
|
|
}
|
2013-03-13 04:08:34 +00:00
|
|
|
if (mSettings.isInternal()) {
|
2013-07-05 09:23:22 +00:00
|
|
|
LatinImeLoggerUtils.onAutoCorrection(
|
|
|
|
typedWord, autoCorrection, separatorString, mWordComposer);
|
2012-09-19 07:18:24 +00:00
|
|
|
}
|
2013-03-18 09:21:18 +00:00
|
|
|
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
|
2013-02-26 07:25:30 +00:00
|
|
|
final SuggestedWords suggestedWords = mSuggestedWords;
|
2012-12-23 20:08:42 +00:00
|
|
|
ResearchLogger.latinIme_commitCurrentAutoCorrection(typedWord, autoCorrection,
|
2013-01-15 21:48:15 +00:00
|
|
|
separatorString, mWordComposer.isBatchMode(), suggestedWords);
|
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
|
2013-04-04 08:45:21 +00:00
|
|
|
public void pickSuggestionManually(final int index, final SuggestedWordInfo suggestionInfo) {
|
2013-02-26 07:25:30 +00:00
|
|
|
final SuggestedWords suggestedWords = mSuggestedWords;
|
2013-04-04 08:45:21 +00:00
|
|
|
final String suggestion = suggestionInfo.mWord;
|
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);
|
2013-03-18 09:21:18 +00:00
|
|
|
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
|
2012-12-23 23:12:51 +00:00
|
|
|
ResearchLogger.latinIME_punctuationSuggestion(index, suggestion,
|
2013-01-11 17:55:09 +00:00
|
|
|
false /* isBatchMode */, suggestedWords.mIsPrediction);
|
2012-08-02 00:26:45 +00:00
|
|
|
}
|
2012-04-23 09:15:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-06 08:50:35 +00:00
|
|
|
mConnection.beginBatchEdit();
|
2013-07-30 03:54:33 +00:00
|
|
|
final SettingsValues currentSettings = mSettings.getCurrent();
|
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()) {
|
2013-01-11 11:23:48 +00:00
|
|
|
final int firstChar = Character.codePointAt(suggestion, 0);
|
2013-07-30 03:54:33 +00:00
|
|
|
if (!currentSettings.isWordSeparator(firstChar)
|
|
|
|
|| currentSettings.isUsuallyPrecededBySpace(firstChar)) {
|
2012-11-12 05:05:51 +00:00
|
|
|
promotePhantomSpace();
|
2012-03-07 06:59:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-30 03:54:33 +00:00
|
|
|
if (currentSettings.isApplicationSpecifiedCompletionsOn()
|
2011-12-16 03:57:27 +00:00
|
|
|
&& mApplicationSpecifiedCompletions != null
|
2010-12-11 08:06:24 +00:00
|
|
|
&& index >= 0 && index < mApplicationSpecifiedCompletions.length) {
|
2013-02-26 07:25:30 +00:00
|
|
|
mSuggestedWords = SuggestedWords.EMPTY;
|
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);
|
2013-03-18 09:21:18 +00:00
|
|
|
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
|
2012-12-23 23:12:51 +00:00
|
|
|
ResearchLogger.latinIME_pickSuggestionManually(replacedWord, index, suggestion,
|
2013-06-13 17:17:47 +00:00
|
|
|
mWordComposer.isBatchMode(), suggestionInfo.mScore, suggestionInfo.mKind,
|
|
|
|
suggestionInfo.mSourceDict);
|
2012-08-02 00:26:45 +00:00
|
|
|
}
|
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
|
2013-07-30 05:44:09 +00:00
|
|
|
final Suggest suggest = mSuggest;
|
2013-04-04 08:45:21 +00:00
|
|
|
final boolean showingAddToDictionaryHint =
|
2013-05-28 01:53:43 +00:00
|
|
|
(SuggestedWordInfo.KIND_TYPED == suggestionInfo.mKind
|
|
|
|
|| SuggestedWordInfo.KIND_OOV_CORRECTION == suggestionInfo.mKind)
|
2013-07-30 05:44:09 +00:00
|
|
|
&& suggest != null
|
2013-05-28 01:53:43 +00:00
|
|
|
// If the suggestion is not in the dictionary, the hint should be shown.
|
2013-07-30 05:44:09 +00:00
|
|
|
&& !AutoCorrectionUtils.isValidWord(suggest, suggestion, true);
|
2010-08-26 19:22:58 +00:00
|
|
|
|
2013-07-30 03:54:33 +00:00
|
|
|
if (currentSettings.mIsInternal) {
|
2013-07-05 09:23:22 +00:00
|
|
|
LatinImeLoggerUtils.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-07-30 03:54:33 +00:00
|
|
|
suggestion, currentSettings.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) {
|
2013-02-26 07:25:30 +00:00
|
|
|
final SuggestedWords suggestedWords = mSuggestedWords;
|
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-07-30 03:54:33 +00:00
|
|
|
final SettingsValues currentSettings = mSettings.getCurrent();
|
|
|
|
if (currentSettings.mBigramPredictionEnabled) {
|
2012-07-23 09:03:16 +00:00
|
|
|
clearSuggestionStrip();
|
2012-06-14 18:52:48 +00:00
|
|
|
} else {
|
2013-07-30 03:54:33 +00:00
|
|
|
setSuggestedWords(currentSettings.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;
|
2013-07-30 05:44:09 +00:00
|
|
|
final Suggest suggest = mSuggest;
|
|
|
|
if (suggest == 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-07-30 03:54:33 +00:00
|
|
|
final SettingsValues currentSettings = mSettings.getCurrent();
|
|
|
|
if (!currentSettings.mCorrectionEnabled) return null;
|
2011-03-04 07:56:10 +00:00
|
|
|
|
2013-08-01 06:38:40 +00:00
|
|
|
final UserHistoryPredictionDictionary userHistoryPredictionDictionary =
|
2013-07-31 05:42:50 +00:00
|
|
|
mUserHistoryPredictionDictionary;
|
2013-08-01 06:38:40 +00:00
|
|
|
if (userHistoryPredictionDictionary == null) return null;
|
2013-07-30 05:44:09 +00:00
|
|
|
|
2013-07-30 03:54:33 +00:00
|
|
|
final String prevWord = mConnection.getNthPreviousWord(currentSettings.mWordSeparators, 2);
|
2013-03-25 10:00:38 +00:00
|
|
|
final String secondWord;
|
|
|
|
if (mWordComposer.wasAutoCapitalized() && !mWordComposer.isMostlyCaps()) {
|
|
|
|
secondWord = suggestion.toLowerCase(mSubtypeSwitcher.getCurrentSubtypeLocale());
|
|
|
|
} else {
|
|
|
|
secondWord = suggestion;
|
|
|
|
}
|
|
|
|
// 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.).
|
2013-07-18 13:59:26 +00:00
|
|
|
final int maxFreq = AutoCorrectionUtils.getMaxFrequency(
|
2013-03-25 10:00:38 +00:00
|
|
|
suggest.getUnigramDictionaries(), suggestion);
|
|
|
|
if (maxFreq == 0) return null;
|
2013-08-05 07:01:30 +00:00
|
|
|
userHistoryPredictionDictionary
|
|
|
|
.addToPersonalizationPredictionDictionary(prevWord, secondWord, maxFreq > 0);
|
2013-03-25 10:00:38 +00:00
|
|
|
return prevWord;
|
2010-02-20 00:38:58 +00:00
|
|
|
}
|
|
|
|
|
2013-04-10 07:38:37 +00:00
|
|
|
/**
|
|
|
|
* Check if the cursor is touching a word. If so, restart suggestions on this word, else
|
|
|
|
* do nothing.
|
|
|
|
*/
|
|
|
|
private void restartSuggestionsOnWordTouchedByCursor() {
|
2013-05-15 09:53:56 +00:00
|
|
|
// HACK: We may want to special-case some apps that exhibit bad behavior in case of
|
|
|
|
// recorrection. This is a temporary, stopgap measure that will be removed later.
|
|
|
|
// TODO: remove this.
|
|
|
|
if (mAppWorkAroundsUtils.isBrokenByRecorrection()) return;
|
2013-04-10 07:38:37 +00:00
|
|
|
// If the cursor is not touching a word, or if there is a selection, return right away.
|
|
|
|
if (mLastSelectionStart != mLastSelectionEnd) return;
|
2013-05-08 09:44:50 +00:00
|
|
|
// If we don't know the cursor location, return.
|
|
|
|
if (mLastSelectionStart < 0) return;
|
2013-07-30 03:54:33 +00:00
|
|
|
final SettingsValues currentSettings = mSettings.getCurrent();
|
|
|
|
if (!mConnection.isCursorTouchingWord(currentSettings)) return;
|
|
|
|
final TextRange range = mConnection.getWordRangeAtCursor(currentSettings.mWordSeparators,
|
2013-04-10 07:38:37 +00:00
|
|
|
0 /* additionalPrecedingWordsCount */);
|
2013-04-16 03:20:10 +00:00
|
|
|
if (null == range) return; // Happens if we don't have an input connection at all
|
2013-05-08 09:44:50 +00:00
|
|
|
// If for some strange reason (editor bug or so) we measure the text before the cursor as
|
|
|
|
// longer than what the entire text is supposed to be, the safe thing to do is bail out.
|
2013-06-20 09:58:58 +00:00
|
|
|
final int numberOfCharsInWordBeforeCursor = range.getNumberOfCharsInWordBeforeCursor();
|
|
|
|
if (numberOfCharsInWordBeforeCursor > mLastSelectionStart) return;
|
2013-04-10 07:38:37 +00:00
|
|
|
final ArrayList<SuggestedWordInfo> suggestions = CollectionUtils.newArrayList();
|
2013-06-24 10:43:03 +00:00
|
|
|
final String typedWord = range.mWord.toString();
|
|
|
|
int i = 0;
|
|
|
|
for (final SuggestionSpan span : range.getSuggestionSpansAtWord()) {
|
|
|
|
for (final String s : span.getSuggestions()) {
|
|
|
|
++i;
|
|
|
|
if (!TextUtils.equals(s, typedWord)) {
|
|
|
|
suggestions.add(new SuggestedWordInfo(s,
|
|
|
|
SuggestionStripView.MAX_SUGGESTIONS - i,
|
|
|
|
SuggestedWordInfo.KIND_RESUMED, Dictionary.TYPE_RESUMED));
|
2013-04-10 07:38:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-04-10 09:30:11 +00:00
|
|
|
mWordComposer.setComposingWord(typedWord, mKeyboardSwitcher.getKeyboard());
|
2013-08-14 07:00:28 +00:00
|
|
|
mWordComposer.setCursorPositionWithinWord(
|
|
|
|
typedWord.codePointCount(0, numberOfCharsInWordBeforeCursor));
|
2013-06-20 09:58:58 +00:00
|
|
|
mConnection.setComposingRegion(
|
|
|
|
mLastSelectionStart - numberOfCharsInWordBeforeCursor,
|
|
|
|
mLastSelectionEnd + range.getNumberOfCharsInWordAfterCursor());
|
2013-04-10 09:30:11 +00:00
|
|
|
final SuggestedWords suggestedWords;
|
2013-04-10 07:38:37 +00:00
|
|
|
if (suggestions.isEmpty()) {
|
2013-04-10 09:30:11 +00:00
|
|
|
// We come here if there weren't any suggestion spans on this word. We will try to
|
|
|
|
// compute suggestions for it instead.
|
|
|
|
final SuggestedWords suggestedWordsIncludingTypedWord =
|
|
|
|
getSuggestedWords(Suggest.SESSION_TYPING);
|
|
|
|
if (suggestedWordsIncludingTypedWord.size() > 1) {
|
|
|
|
// We were able to compute new suggestions for this word.
|
|
|
|
// Remove the typed word, since we don't want to display it in this case.
|
|
|
|
// The #getSuggestedWordsExcludingTypedWord() method sets willAutoCorrect to false.
|
|
|
|
suggestedWords =
|
|
|
|
suggestedWordsIncludingTypedWord.getSuggestedWordsExcludingTypedWord();
|
|
|
|
} else {
|
|
|
|
// No saved suggestions, and we were unable to compute any good one either.
|
|
|
|
// Rather than displaying an empty suggestion strip, we'll display the original
|
|
|
|
// word alone in the middle.
|
|
|
|
// Since there is only one word, willAutoCorrect is false.
|
|
|
|
suggestedWords = suggestedWordsIncludingTypedWord;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// We found suggestion spans in the word. We'll create the SuggestedWords out of
|
|
|
|
// them, and make willAutoCorrect false.
|
|
|
|
suggestedWords = new SuggestedWords(suggestions,
|
|
|
|
true /* typedWordValid */, false /* willAutoCorrect */,
|
|
|
|
false /* isPunctuationSuggestions */, false /* isObsoleteSuggestions */,
|
|
|
|
false /* isPrediction */);
|
2013-04-10 07:38:37 +00:00
|
|
|
}
|
2013-04-10 09:30:11 +00:00
|
|
|
|
|
|
|
// Note that it's very important here that suggestedWords.mWillAutoCorrect is false.
|
|
|
|
// We never want to auto-correct on a resumed suggestion. Please refer to the three
|
2013-05-15 03:12:58 +00:00
|
|
|
// places above where suggestedWords is affected. We also need to reset
|
|
|
|
// mIsAutoCorrectionIndicatorOn to avoid showSuggestionStrip touching the text to adapt it.
|
|
|
|
// TODO: remove mIsAutoCorrectionIndicator on (see comment on definition)
|
|
|
|
mIsAutoCorrectionIndicatorOn = false;
|
2013-04-10 09:30:11 +00:00
|
|
|
showSuggestionStrip(suggestedWords, typedWord);
|
2013-04-10 07:38:37 +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) {
|
2013-04-10 07:38:37 +00:00
|
|
|
final String wordString = word.toString();
|
|
|
|
restartSuggestionsOnWordBeforeCursor(wordString);
|
2012-12-23 23:12:51 +00:00
|
|
|
// TODO: Handle the case where the user manually moves the cursor and then backs up over
|
|
|
|
// a separator. In that case, the current log unit should not be uncommitted.
|
2013-03-18 09:21:18 +00:00
|
|
|
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
|
2013-04-10 07:38:37 +00:00
|
|
|
ResearchLogger.getInstance().uncommitCurrentLogUnit(wordString,
|
2012-12-23 23:12:51 +00:00
|
|
|
true /* dumpCurrentLogUnit */);
|
|
|
|
}
|
2012-01-17 05:58:27 +00:00
|
|
|
}
|
2011-11-22 02:35:40 +00:00
|
|
|
}
|
|
|
|
|
2013-04-10 07:38:37 +00:00
|
|
|
private void restartSuggestionsOnWordBeforeCursor(final String 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)) {
|
2013-07-31 05:42:50 +00:00
|
|
|
mUserHistoryPredictionDictionary.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);
|
2013-03-13 04:08:34 +00:00
|
|
|
if (mSettings.isInternal()) {
|
2013-07-05 09:23:22 +00:00
|
|
|
LatinImeLoggerUtils.onSeparator(mLastComposedWord.mSeparatorString,
|
2012-09-19 07:18:24 +00:00
|
|
|
Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE);
|
|
|
|
}
|
2013-03-18 09:21:18 +00:00
|
|
|
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
|
2012-12-23 23:12:51 +00:00
|
|
|
ResearchLogger.latinIME_revertCommit(committedWord, originallyTypedWord,
|
2013-01-10 22:53:19 +00:00
|
|
|
mWordComposer.isBatchMode(), mLastComposedWord.mSeparatorString);
|
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-04-15 08:33:48 +00:00
|
|
|
if (mSettings.getCurrent().shouldInsertSpacesAutomatically()
|
|
|
|
&& !mConnection.textBeforeCursorLooksLikeURL()) {
|
2013-03-18 09:21:18 +00:00
|
|
|
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
|
2013-01-10 22:40:29 +00:00
|
|
|
ResearchLogger.latinIME_promotePhantomSpace();
|
|
|
|
}
|
2013-05-17 01:39:40 +00:00
|
|
|
sendKeyCodePoint(Constants.CODE_SPACE);
|
2012-11-13 06:10:07 +00:00
|
|
|
}
|
2012-11-12 05:05:51 +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() {
|
2013-06-13 06:26:47 +00:00
|
|
|
// Since we are switching languages, the most urgent thing is to let the keyboard graphics
|
|
|
|
// update. LoadKeyboard does that, but we need to wait for buffer flip for it to be on
|
|
|
|
// the screen. Anything we do right now will delay this, so wait until the next frame
|
|
|
|
// before we do the rest, like reopening dictionaries and updating suggestions. So we
|
|
|
|
// post a message.
|
|
|
|
mHandler.postReopenDictionaries();
|
2012-07-23 05:59:19 +00:00
|
|
|
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
|
|
|
}
|
2009-10-12 20:48:35 +00:00
|
|
|
}
|
|
|
|
|
2013-07-16 03:29:50 +00:00
|
|
|
private void hapticAndAudioFeedback(final int code, final boolean isRepeatKey) {
|
|
|
|
final MainKeyboardView keyboardView = mKeyboardSwitcher.getMainKeyboardView();
|
|
|
|
if (keyboardView != null && keyboardView.isInSlidingKeyInput()) {
|
|
|
|
// No need to feedback while sliding input.
|
|
|
|
return;
|
|
|
|
}
|
2013-08-13 08:02:49 +00:00
|
|
|
if (isRepeatKey) {
|
|
|
|
// No need to feedback when repeating key.
|
2013-07-16 03:29:50 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
AudioAndHapticFeedbackManager.getInstance().hapticAndAudioFeedback(code, keyboardView);
|
|
|
|
}
|
|
|
|
|
2013-07-02 09:07:35 +00:00
|
|
|
// Callback of the {@link KeyboardActionListener}. This is called when a key is depressed;
|
|
|
|
// release matching call is {@link #onReleaseKey(int,boolean)} below.
|
2010-12-02 09:46:21 +00:00
|
|
|
@Override
|
2013-07-16 03:29:50 +00:00
|
|
|
public void onPressKey(final int primaryCode, final boolean isRepeatKey,
|
|
|
|
final boolean isSinglePointer) {
|
2013-05-14 03:25:21 +00:00
|
|
|
mKeyboardSwitcher.onPressKey(primaryCode, isSinglePointer);
|
2013-07-16 03:29:50 +00:00
|
|
|
hapticAndAudioFeedback(primaryCode, isRepeatKey);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2013-07-02 09:07:35 +00:00
|
|
|
// Callback of the {@link KeyboardActionListener}. This is called when a key is released;
|
2013-07-16 03:29:50 +00:00
|
|
|
// press matching call is {@link #onPressKey(int,boolean,boolean)} 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) {
|
2013-01-17 06:49:00 +00:00
|
|
|
if (!ProductionFlag.IS_HARDWARE_KEYBOARD_SUPPORTED) return super.onKeyDown(keyCode, event);
|
2012-12-06 11:35:59 +00:00
|
|
|
// 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.
|
2013-01-17 10:27:39 +00:00
|
|
|
if (mEventInterpreter.onHardwareKeyEvent(event)) {
|
|
|
|
final long keyIdentifier = event.getDeviceId() << 32 + event.getKeyCode();
|
|
|
|
mCurrentlyPressedHardwareKeys.add(keyIdentifier);
|
|
|
|
return true;
|
|
|
|
}
|
2012-12-06 11:35:59 +00:00
|
|
|
return super.onKeyDown(keyCode, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onKeyUp(final int keyCode, final KeyEvent event) {
|
2013-01-17 10:27:39 +00:00
|
|
|
final long keyIdentifier = event.getDeviceId() << 32 + event.getKeyCode();
|
|
|
|
if (mCurrentlyPressedHardwareKeys.remove(keyIdentifier)) {
|
|
|
|
return true;
|
|
|
|
}
|
2012-12-06 11:35:59 +00:00
|
|
|
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)) {
|
2013-05-21 22:32:08 +00:00
|
|
|
AudioAndHapticFeedbackManager.getInstance().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-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);
|
2013-01-23 05:35:39 +00:00
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
|
|
|
|
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
|
|
|
|
| Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
2009-03-13 22:11:42 +00:00
|
|
|
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),
|
2013-07-05 09:23:22 +00:00
|
|
|
getString(ApplicationUtils.getAcitivityTitleResId(this, SettingsActivity.class)),
|
2011-01-25 02:48:06 +00:00
|
|
|
};
|
|
|
|
final DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
|
2011-01-20 13:52:02 +00:00
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface di, int position) {
|
|
|
|
di.dismiss();
|
|
|
|
switch (position) {
|
2011-01-25 02:48:06 +00:00
|
|
|
case 0:
|
2013-02-04 23:59:59 +00:00
|
|
|
final Intent intent = IntentUtils.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();
|
|
|
|
}
|
|
|
|
|
2013-02-26 07:25:30 +00:00
|
|
|
// TODO: can this be removed somehow without breaking the tests?
|
|
|
|
@UsedForTesting
|
|
|
|
/* package for test */ String getFirstSuggestedWord() {
|
|
|
|
return mSuggestedWords.size() > 0 ? mSuggestedWords.getWord(0) : null;
|
|
|
|
}
|
|
|
|
|
2013-07-29 08:47:13 +00:00
|
|
|
// DO NOT USE THIS for any other purpose than testing. This is information private to LatinIME.
|
|
|
|
@UsedForTesting
|
|
|
|
/* package for test */ boolean isCurrentlyWaitingForMainDictionary() {
|
|
|
|
return mSuggest.isCurrentlyWaitingForMainDictionary();
|
|
|
|
}
|
|
|
|
|
|
|
|
// DO NOT USE THIS for any other purpose than testing. This is information private to LatinIME.
|
|
|
|
@UsedForTesting
|
|
|
|
/* package for test */ boolean hasMainDictionary() {
|
|
|
|
return mSuggest.hasMainDictionary();
|
|
|
|
}
|
|
|
|
|
2012-09-10 10:27:45 +00:00
|
|
|
public void debugDumpStateAndCrashWithException(final String context) {
|
2013-05-15 07:49:15 +00:00
|
|
|
final StringBuilder s = new StringBuilder(mAppWorkAroundsUtils.toString());
|
|
|
|
s.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
|
|
|
}
|
|
|
|
}
|