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;
|
2013-08-30 07:50:37 +00:00
|
|
|
import android.graphics.Rect;
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.inputmethodservice.InputMethodService;
|
|
|
|
import android.media.AudioManager;
|
2011-01-26 14:13:18 +00:00
|
|
|
import android.net.ConnectivityManager;
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.os.Debug;
|
2012-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;
|
2013-09-19 11:31:15 +00:00
|
|
|
import android.util.Pair;
|
2009-03-13 22:11:42 +00:00
|
|
|
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;
|
2013-08-30 07:50:37 +00:00
|
|
|
import android.view.ViewGroup.LayoutParams;
|
2012-04-02 13:25:08 +00:00
|
|
|
import android.view.Window;
|
|
|
|
import android.view.WindowManager;
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.view.inputmethod.CompletionInfo;
|
2012-03-31 09:32:48 +00:00
|
|
|
import android.view.inputmethod.CorrectionInfo;
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.view.inputmethod.EditorInfo;
|
2012-04-02 12:31:52 +00:00
|
|
|
import android.view.inputmethod.InputMethodSubtype;
|
2011-05-23 09:30:21 +00:00
|
|
|
|
2011-05-18 00:03:25 +00:00
|
|
|
import com.android.inputmethod.accessibility.AccessibilityUtils;
|
2012-02-07 21:14:18 +00:00
|
|
|
import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy;
|
2012-10-03 08:36:45 +00:00
|
|
|
import com.android.inputmethod.annotations.UsedForTesting;
|
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;
|
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-08-29 06:15:49 +00:00
|
|
|
import com.android.inputmethod.latin.Suggest.OnGetSuggestedWordsCallback;
|
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-12-18 09:08:35 +00:00
|
|
|
import com.android.inputmethod.latin.inputlogic.InputLogic;
|
2013-12-19 05:34:35 +00:00
|
|
|
import com.android.inputmethod.latin.inputlogic.SpaceState;
|
2013-10-02 09:06:08 +00:00
|
|
|
import com.android.inputmethod.latin.personalization.DictionaryDecayBroadcastReciever;
|
2013-08-12 03:20:18 +00:00
|
|
|
import com.android.inputmethod.latin.personalization.PersonalizationDictionarySessionRegister;
|
2013-09-28 03:50:09 +00:00
|
|
|
import com.android.inputmethod.latin.personalization.UserHistoryDictionary;
|
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-09-09 14:10:33 +00:00
|
|
|
import com.android.inputmethod.latin.utils.AsyncResultHolder;
|
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-12-13 08:09:16 +00:00
|
|
|
import com.android.inputmethod.latin.utils.LeakGuardHandlerWrapper;
|
2013-06-23 16:11:32 +00:00
|
|
|
import com.android.inputmethod.latin.utils.RecapitalizeStatus;
|
2013-10-12 07:41:37 +00:00
|
|
|
import com.android.inputmethod.latin.utils.StringUtils;
|
2013-06-23 16:11:32 +00:00
|
|
|
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;
|
2013-12-13 08:09:16 +00:00
|
|
|
import java.util.concurrent.TimeUnit;
|
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;
|
2013-12-19 09:30:21 +00:00
|
|
|
// TODO[IL]: Make this private
|
|
|
|
public 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
|
|
|
|
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
|
|
|
|
2013-08-13 03:10:26 +00:00
|
|
|
private static final int PERIOD_FOR_AUDIO_AND_HAPTIC_FEEDBACK_IN_KEY_REPEAT = 2;
|
|
|
|
|
2013-09-03 08:39:47 +00:00
|
|
|
// TODO: Set this value appropriately.
|
|
|
|
private static final int GET_SUGGESTED_WORDS_TIMEOUT = 200;
|
2013-09-02 07:49:32 +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";
|
|
|
|
|
2013-01-08 07:35:21 +00:00
|
|
|
private final Settings mSettings;
|
2013-12-18 09:08:35 +00:00
|
|
|
private final InputLogic mInputLogic = new InputLogic(this);
|
2011-05-10 06:51:43 +00:00
|
|
|
|
2013-08-30 07:50:37 +00:00
|
|
|
private View mExtractArea;
|
|
|
|
private View mKeyPreviewBackingView;
|
2012-07-23 06:28:28 +00:00
|
|
|
private SuggestionStripView mSuggestionStripView;
|
2013-12-18 09:08:35 +00:00
|
|
|
|
2010-12-11 08:06:24 +00:00
|
|
|
private CompletionInfo[] mApplicationSpecifiedCompletions;
|
2013-12-19 07:07:24 +00:00
|
|
|
// TODO[IL]: Make this an AsyncResultHolder or a Future in SettingsValues
|
|
|
|
public 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();
|
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;
|
2011-11-18 06:24:49 +00:00
|
|
|
private boolean mIsUserDictionaryAvailable;
|
2009-10-12 20:48:35 +00:00
|
|
|
|
2013-08-20 05:42:53 +00:00
|
|
|
// Personalization debugging params
|
|
|
|
private boolean mUseOnlyPersonalizationDictionaryForDebug = false;
|
|
|
|
private boolean mBoostPersonalizationDictionaryForDebug = false;
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2013-12-19 07:07:24 +00:00
|
|
|
// Member variable for remembering the current device orientation.
|
|
|
|
// TODO[IL]: Move this to SettingsValues.
|
|
|
|
public int mDisplayOrientation;
|
2011-07-21 06:57:00 +00:00
|
|
|
|
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
|
|
|
|
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);
|
2013-09-02 07:49:32 +00:00
|
|
|
private InputUpdater mInputUpdater;
|
2010-11-16 09:07:06 +00:00
|
|
|
|
2013-12-13 08:09:16 +00:00
|
|
|
public static final class UIHandler extends LeakGuardHandlerWrapper<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;
|
2013-09-02 07:49:32 +00:00
|
|
|
private static final int MSG_ON_END_BATCH_INPUT = 6;
|
2013-09-20 09:01:32 +00:00
|
|
|
private static final int MSG_RESET_CACHES = 7;
|
2013-12-13 08:09:16 +00:00
|
|
|
// Update this when adding new messages
|
|
|
|
private static final int MSG_LAST = MSG_RESET_CACHES;
|
2012-09-12 04:03:44 +00:00
|
|
|
|
2013-09-02 07:49:32 +00:00
|
|
|
private static final int ARG1_NOT_GESTURE_INPUT = 0;
|
2012-09-12 04:03:44 +00:00
|
|
|
private static final int ARG1_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT = 1;
|
2013-09-02 07:49:32 +00:00
|
|
|
private static final int ARG1_SHOW_GESTURE_FLOATING_PREVIEW_TEXT = 2;
|
2013-09-19 11:31:15 +00:00
|
|
|
private static final int ARG2_WITHOUT_TYPED_WORD = 0;
|
|
|
|
private static final int ARG2_WITH_TYPED_WORD = 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
|
|
|
|
2013-12-13 08:09:16 +00:00
|
|
|
public UIHandler(final LatinIME ownerInstance) {
|
|
|
|
super(ownerInstance);
|
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() {
|
2013-12-13 08:09:16 +00:00
|
|
|
final Resources res = getOwnerInstance().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) {
|
2013-12-13 08:09:16 +00:00
|
|
|
final LatinIME latinIme = getOwnerInstance();
|
2011-06-24 18:54:11 +00:00
|
|
|
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:
|
2013-09-02 07:49:32 +00:00
|
|
|
if (msg.arg1 == ARG1_NOT_GESTURE_INPUT) {
|
2013-09-19 11:31:15 +00:00
|
|
|
if (msg.arg2 == ARG2_WITH_TYPED_WORD) {
|
|
|
|
final Pair<SuggestedWords, String> p =
|
|
|
|
(Pair<SuggestedWords, String>) msg.obj;
|
|
|
|
latinIme.showSuggestionStripWithTypedWord(p.first, p.second);
|
|
|
|
} else {
|
|
|
|
latinIme.showSuggestionStrip((SuggestedWords) msg.obj);
|
|
|
|
}
|
2013-09-02 07:49:32 +00:00
|
|
|
} else {
|
|
|
|
latinIme.showGesturePreviewAndSuggestionStrip((SuggestedWords) msg.obj,
|
|
|
|
msg.arg1 == ARG1_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT);
|
|
|
|
}
|
2012-09-12 04:03:44 +00:00
|
|
|
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;
|
2013-09-02 07:49:32 +00:00
|
|
|
case MSG_ON_END_BATCH_INPUT:
|
|
|
|
latinIme.onEndBatchInputAsyncInternal((SuggestedWords) msg.obj);
|
|
|
|
break;
|
2013-09-20 09:01:32 +00:00
|
|
|
case MSG_RESET_CACHES:
|
|
|
|
latinIme.retryResetCaches(msg.arg1 == 1 /* tryResumeSuggestions */,
|
|
|
|
msg.arg2 /* remainingTries */);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2013-09-20 09:01:32 +00:00
|
|
|
public void postResetCaches(final boolean tryResumeSuggestions, final int remainingTries) {
|
|
|
|
removeMessages(MSG_RESET_CACHES);
|
|
|
|
sendMessage(obtainMessage(MSG_RESET_CACHES, tryResumeSuggestions ? 1 : 0,
|
|
|
|
remainingTries, null));
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2013-12-13 08:09:16 +00:00
|
|
|
@UsedForTesting
|
|
|
|
public void removeAllMessages() {
|
|
|
|
for (int i = 0; i <= MSG_LAST; ++i) {
|
|
|
|
removeMessages(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
2013-09-02 07:49:32 +00:00
|
|
|
? ARG1_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT
|
|
|
|
: ARG1_SHOW_GESTURE_FLOATING_PREVIEW_TEXT;
|
2013-09-19 11:31:15 +00:00
|
|
|
obtainMessage(MSG_SHOW_GESTURE_PREVIEW_AND_SUGGESTION_STRIP, arg1,
|
|
|
|
ARG2_WITHOUT_TYPED_WORD, suggestedWords).sendToTarget();
|
2012-09-12 04:03:44 +00:00
|
|
|
}
|
|
|
|
|
2013-09-02 07:49:32 +00:00
|
|
|
public void showSuggestionStrip(final SuggestedWords suggestedWords) {
|
|
|
|
removeMessages(MSG_SHOW_GESTURE_PREVIEW_AND_SUGGESTION_STRIP);
|
|
|
|
obtainMessage(MSG_SHOW_GESTURE_PREVIEW_AND_SUGGESTION_STRIP,
|
2013-09-19 11:31:15 +00:00
|
|
|
ARG1_NOT_GESTURE_INPUT, ARG2_WITHOUT_TYPED_WORD, suggestedWords).sendToTarget();
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Remove this method.
|
|
|
|
public void showSuggestionStripWithTypedWord(final SuggestedWords suggestedWords,
|
|
|
|
final String typedWord) {
|
|
|
|
removeMessages(MSG_SHOW_GESTURE_PREVIEW_AND_SUGGESTION_STRIP);
|
|
|
|
obtainMessage(MSG_SHOW_GESTURE_PREVIEW_AND_SUGGESTION_STRIP, ARG1_NOT_GESTURE_INPUT,
|
|
|
|
ARG2_WITH_TYPED_WORD,
|
|
|
|
new Pair<SuggestedWords, String>(suggestedWords, typedWord)).sendToTarget();
|
2013-09-02 07:49:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void onEndBatchInput(final SuggestedWords suggestedWords) {
|
|
|
|
obtainMessage(MSG_ON_END_BATCH_INPUT, 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;
|
2013-12-13 08:09:16 +00:00
|
|
|
final LatinIME latinIme = getOwnerInstance();
|
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
|
|
|
}
|
2013-12-13 08:09:16 +00:00
|
|
|
final LatinIME latinIme = getOwnerInstance();
|
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);
|
|
|
|
}
|
2013-12-13 08:09:16 +00:00
|
|
|
final LatinIME latinIme = getOwnerInstance();
|
2011-11-21 22:58:32 +00:00
|
|
|
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 {
|
2013-12-13 08:09:16 +00:00
|
|
|
final LatinIME latinIme = getOwnerInstance();
|
2011-09-29 08:27:48 +00:00
|
|
|
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 {
|
2013-12-13 08:09:16 +00:00
|
|
|
final LatinIME latinIme = getOwnerInstance();
|
2011-09-29 08:27:48 +00:00
|
|
|
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-12-18 09:08:35 +00:00
|
|
|
ResearchLogger.getInstance().init(this, mKeyboardSwitcher, mInputLogic.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);
|
2013-09-02 07:49:32 +00:00
|
|
|
|
2013-10-02 09:06:08 +00:00
|
|
|
DictionaryDecayBroadcastReciever.setUpIntervalAlarmForDictionaryDecaying(this);
|
|
|
|
|
2013-09-02 07:49:32 +00:00
|
|
|
mInputUpdater = new InputUpdater(this);
|
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.
|
2013-12-18 09:08:35 +00:00
|
|
|
if (!mHandler.hasPendingReopenDictionaries() && mInputLogic.mSuggest != null) {
|
2013-12-17 10:36:19 +00:00
|
|
|
// May need to reset dictionaries depending on the user settings.
|
2013-12-18 09:08:35 +00:00
|
|
|
mInputLogic.mSuggest.setAdditionalDictionaries(mInputLogic.mSuggest /* oldSuggest */,
|
|
|
|
mSettings.getCurrent());
|
2013-06-13 06:26:47 +00:00
|
|
|
}
|
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() {
|
2013-10-04 11:24:41 +00:00
|
|
|
final Locale switcherSubtypeLocale = mSubtypeSwitcher.getCurrentSubtypeLocale();
|
|
|
|
final String switcherLocaleStr = switcherSubtypeLocale.toString();
|
|
|
|
final Locale subtypeLocale;
|
|
|
|
if (TextUtils.isEmpty(switcherLocaleStr)) {
|
|
|
|
// This happens in very rare corner cases - for example, immediately after a switch
|
|
|
|
// to LatinIME has been requested, about a frame later another switch happens. In this
|
|
|
|
// case, we are about to go down but we still don't know it, however the system tells
|
|
|
|
// us there is no current subtype so the locale is the empty string. Take the best
|
|
|
|
// possible guess instead -- it's bound to have no consequences, and we have no way
|
|
|
|
// of knowing anyway.
|
|
|
|
Log.e(TAG, "System is reporting no current subtype.");
|
|
|
|
subtypeLocale = getResources().getConfiguration().locale;
|
|
|
|
} else {
|
|
|
|
subtypeLocale = switcherSubtypeLocale;
|
|
|
|
}
|
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
|
|
|
|
2013-12-13 08:09:16 +00:00
|
|
|
mUserDictionary = new UserBinaryDictionary(this, subtypeLocale);
|
2012-06-08 08:01:35 +00:00
|
|
|
mIsUserDictionaryAvailable = mUserDictionary.isEnabled();
|
2013-07-30 05:44:09 +00:00
|
|
|
newSuggest.setUserDictionary(mUserDictionary);
|
2013-12-18 09:08:35 +00:00
|
|
|
newSuggest.setAdditionalDictionaries(mInputLogic.mSuggest /* oldSuggest */,
|
|
|
|
mSettings.getCurrent());
|
|
|
|
final Suggest oldSuggest = mInputLogic.mSuggest;
|
|
|
|
mInputLogic.mSuggest = newSuggest;
|
2013-07-30 05:44:09 +00:00
|
|
|
if (oldSuggest != null) oldSuggest.close();
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2009-10-12 20:48:35 +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();
|
2013-12-18 09:08:35 +00:00
|
|
|
mInputLogic.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-12-18 09:08:35 +00:00
|
|
|
final Suggest suggest = mInputLogic.mSuggest;
|
2013-07-30 05:44:09 +00:00
|
|
|
if (suggest != null) {
|
|
|
|
suggest.close();
|
2013-12-18 09:08:35 +00:00
|
|
|
mInputLogic.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);
|
2013-08-21 08:24:12 +00:00
|
|
|
PersonalizationDictionarySessionRegister.onDestroy(this);
|
2010-08-20 05:35:02 +00:00
|
|
|
LatinImeLogger.commit();
|
|
|
|
LatinImeLogger.onDestroy();
|
2013-09-02 07:49:32 +00:00
|
|
|
if (mInputUpdater != null) {
|
2013-11-15 08:34:45 +00:00
|
|
|
mInputUpdater.quitLooper();
|
2013-09-02 07:49:32 +00:00
|
|
|
}
|
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();
|
2013-12-18 09:08:35 +00:00
|
|
|
mInputLogic.mConnection.beginBatchEdit();
|
2013-12-19 07:37:07 +00:00
|
|
|
mInputLogic.commitTyped(LastComposedWord.NOT_A_SEPARATOR);
|
2013-12-18 09:08:35 +00:00
|
|
|
mInputLogic.mConnection.finishComposingText();
|
|
|
|
mInputLogic.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
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-08-30 07:50:37 +00:00
|
|
|
public void setInputView(final View view) {
|
|
|
|
super.setInputView(view);
|
|
|
|
mExtractArea = getWindow().getWindow().getDecorView()
|
|
|
|
.findViewById(android.R.id.extractArea);
|
|
|
|
mKeyPreviewBackingView = view.findViewById(R.id.key_preview_backing);
|
|
|
|
mSuggestionStripView = (SuggestionStripView)view.findViewById(R.id.suggestion_strip_view);
|
2013-12-13 08:09:16 +00:00
|
|
|
if (mSuggestionStripView != null) {
|
2013-08-30 07:50:37 +00:00
|
|
|
mSuggestionStripView.setListener(this, view);
|
2013-12-13 08:09:16 +00:00
|
|
|
}
|
2011-09-21 01:41:31 +00:00
|
|
|
if (LatinImeLogger.sVISUALDEBUG) {
|
2013-08-30 07:50:37 +00:00
|
|
|
mKeyPreviewBackingView.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);
|
2013-10-07 11:10:58 +00:00
|
|
|
mRichImm.clearSubtypeCaches();
|
2010-11-12 23:49:56 +00:00
|
|
|
final KeyboardSwitcher switcher = mKeyboardSwitcher;
|
2013-11-11 11:39:03 +00:00
|
|
|
switcher.updateKeyboardTheme();
|
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.
|
2013-12-18 09:08:35 +00:00
|
|
|
mInputLogic.mEnteredText = null;
|
2013-12-19 07:07:24 +00:00
|
|
|
mInputLogic.resetComposingState(true /* alsoResetLastComposedWord */);
|
2013-12-18 09:08:35 +00:00
|
|
|
mInputLogic.mDeleteCount = 0;
|
2013-12-19 05:34:35 +00:00
|
|
|
mInputLogic.mSpaceState = SpaceState.NONE;
|
2013-12-18 09:08:35 +00:00
|
|
|
mInputLogic.mRecapitalizeStatus.deactivate();
|
|
|
|
mInputLogic.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-12-18 09:08:35 +00:00
|
|
|
final Suggest suggest = mInputLogic.mSuggest;
|
2013-07-30 05:44:09 +00:00
|
|
|
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-12-18 09:08:35 +00:00
|
|
|
mInputLogic.mSuggestedWords = SuggestedWords.EMPTY;
|
2011-05-10 06:51:43 +00:00
|
|
|
|
2013-09-20 09:01:32 +00:00
|
|
|
// Sometimes, while rotating, for some reason the framework tells the app we are not
|
|
|
|
// connected to it and that means we can't refresh the cache. In this case, schedule a
|
|
|
|
// refresh later.
|
2013-10-07 12:43:05 +00:00
|
|
|
final boolean canReachInputConnection;
|
2013-12-18 09:08:35 +00:00
|
|
|
if (!mInputLogic.mConnection.resetCachesUponCursorMoveAndReturnSuccess(
|
|
|
|
editorInfo.initialSelStart, editorInfo.initialSelEnd,
|
|
|
|
false /* shouldFinishComposition */)) {
|
2013-09-20 09:01:32 +00:00
|
|
|
// We try resetting the caches up to 5 times before giving up.
|
|
|
|
mHandler.postResetCaches(isDifferentTextField, 5 /* remainingTries */);
|
2013-11-13 05:20:45 +00:00
|
|
|
// mLastSelection{Start,End} are reset later in this method, don't need to do it here
|
2013-10-07 12:43:05 +00:00
|
|
|
canReachInputConnection = false;
|
2013-09-20 09:01:32 +00:00
|
|
|
} else {
|
2013-10-07 12:43:05 +00:00
|
|
|
if (isDifferentTextField) {
|
|
|
|
mHandler.postResumeSuggestions();
|
|
|
|
}
|
|
|
|
canReachInputConnection = true;
|
2013-09-20 09:01:32 +00:00
|
|
|
}
|
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-10-08 07:33:27 +00:00
|
|
|
switcher.loadKeyboard(editorInfo, currentSettingsValues);
|
|
|
|
if (!canReachInputConnection) {
|
|
|
|
// If we can't reach the input connection, we will call loadKeyboard again later,
|
|
|
|
// so we need to save its state now. The call will be done in #retryResetCaches.
|
|
|
|
switcher.saveKeyboardState();
|
2013-10-07 12:43:05 +00:00
|
|
|
}
|
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
|
|
|
|
2013-12-18 09:08:35 +00:00
|
|
|
mInputLogic.mLastSelectionStart = editorInfo.initialSelStart;
|
|
|
|
mInputLogic.mLastSelectionEnd = editorInfo.initialSelEnd;
|
2013-09-20 09:01:32 +00:00
|
|
|
// In some cases (namely, after rotation of the device) editorInfo.initialSelStart is lying
|
|
|
|
// so we try using some heuristics to find out about these and fix them.
|
|
|
|
tryFixLyingCursorPosition();
|
2012-07-25 10:31:19 +00:00
|
|
|
|
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
|
|
|
|
2013-08-20 05:42:53 +00:00
|
|
|
initPersonalizationDebugSettings(currentSettingsValues);
|
|
|
|
|
2011-01-18 06:28:21 +00:00
|
|
|
if (TRACE) Debug.startMethodTracing("/data/trace/latinime");
|
|
|
|
}
|
|
|
|
|
2013-09-20 09:01:32 +00:00
|
|
|
/**
|
|
|
|
* Try to get the text from the editor to expose lies the framework may have been
|
|
|
|
* telling us. Concretely, when the device rotates, the frameworks tells us about where the
|
|
|
|
* cursor used to be initially in the editor at the time it first received the focus; this
|
|
|
|
* may be completely different from the place it is upon rotation. Since we don't have any
|
|
|
|
* means to get the real value, try at least to ask the text view for some characters and
|
|
|
|
* detect the most damaging cases: when the cursor position is declared to be much smaller
|
|
|
|
* than it really is.
|
|
|
|
*/
|
|
|
|
private void tryFixLyingCursorPosition() {
|
2013-12-18 09:08:35 +00:00
|
|
|
final CharSequence textBeforeCursor = mInputLogic.mConnection.getTextBeforeCursor(
|
|
|
|
Constants.EDITOR_CONTENTS_CACHE_SIZE, 0);
|
2013-09-20 09:01:32 +00:00
|
|
|
if (null == textBeforeCursor) {
|
2013-12-18 09:08:35 +00:00
|
|
|
mInputLogic.mLastSelectionStart = mInputLogic.mLastSelectionEnd =
|
|
|
|
mInputLogic.NOT_A_CURSOR_POSITION;
|
2013-09-20 09:01:32 +00:00
|
|
|
} else {
|
|
|
|
final int textLength = textBeforeCursor.length();
|
2013-12-18 09:08:35 +00:00
|
|
|
if (textLength > mInputLogic.mLastSelectionStart
|
2013-09-20 09:01:32 +00:00
|
|
|
|| (textLength < Constants.EDITOR_CONTENTS_CACHE_SIZE
|
2013-12-18 09:08:35 +00:00
|
|
|
&& mInputLogic.mLastSelectionStart <
|
|
|
|
Constants.EDITOR_CONTENTS_CACHE_SIZE)) {
|
2013-11-13 05:20:45 +00:00
|
|
|
// It should not be possible to have only one of those variables be
|
|
|
|
// NOT_A_CURSOR_POSITION, so if they are equal, either the selection is zero-sized
|
|
|
|
// (simple cursor, no selection) or there is no cursor/we don't know its pos
|
2013-12-18 09:08:35 +00:00
|
|
|
final boolean wasEqual =
|
|
|
|
mInputLogic.mLastSelectionStart == mInputLogic.mLastSelectionEnd;
|
|
|
|
mInputLogic.mLastSelectionStart = textLength;
|
2013-09-20 09:01:32 +00:00
|
|
|
// We can't figure out the value of mLastSelectionEnd :(
|
2013-11-13 05:20:45 +00:00
|
|
|
// But at least if it's smaller than mLastSelectionStart something is wrong,
|
|
|
|
// and if they used to be equal we also don't want to make it look like there is a
|
|
|
|
// selection.
|
2013-12-18 09:08:35 +00:00
|
|
|
if (wasEqual || mInputLogic.mLastSelectionStart > mInputLogic.mLastSelectionEnd) {
|
|
|
|
mInputLogic.mLastSelectionEnd = mInputLogic.mLastSelectionStart;
|
2013-09-20 09:01:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-20 05:42:53 +00:00
|
|
|
// Initialization of personalization debug settings. This must be called inside
|
|
|
|
// onStartInputView.
|
|
|
|
private void initPersonalizationDebugSettings(SettingsValues currentSettingsValues) {
|
|
|
|
if (mUseOnlyPersonalizationDictionaryForDebug
|
|
|
|
!= currentSettingsValues.mUseOnlyPersonalizationDictionaryForDebug) {
|
|
|
|
// Only for debug
|
|
|
|
initSuggest();
|
|
|
|
mUseOnlyPersonalizationDictionaryForDebug =
|
|
|
|
currentSettingsValues.mUseOnlyPersonalizationDictionaryForDebug;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mBoostPersonalizationDictionaryForDebug !=
|
|
|
|
currentSettingsValues.mBoostPersonalizationDictionaryForDebug) {
|
|
|
|
// Only for debug
|
|
|
|
mBoostPersonalizationDictionaryForDebug =
|
|
|
|
currentSettingsValues.mBoostPersonalizationDictionaryForDebug;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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();
|
2013-10-08 11:11:35 +00:00
|
|
|
mKeyboardSwitcher.deallocateMemory();
|
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-12-18 09:08:35 +00:00
|
|
|
if (mInputLogic.mWordComposer.isComposingWord()) {
|
|
|
|
mInputLogic.mConnection.finishComposingText();
|
|
|
|
}
|
2013-12-19 07:07:24 +00:00
|
|
|
mInputLogic.resetComposingState(true /* alsoResetLastComposedWord */);
|
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-12-18 09:08:35 +00:00
|
|
|
ResearchLogger.latinIME_onFinishInputViewInternal(finishingInput,
|
|
|
|
mInputLogic.mLastSelectionStart,
|
|
|
|
mInputLogic.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
|
2013-12-18 09:08:35 +00:00
|
|
|
+ ", lss=" + mInputLogic.mLastSelectionStart
|
|
|
|
+ ", lse=" + mInputLogic.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) {
|
2013-12-18 09:08:35 +00:00
|
|
|
ResearchLogger.latinIME_onUpdateSelection(mInputLogic.mLastSelectionStart,
|
|
|
|
mInputLogic.mLastSelectionEnd,
|
2012-03-30 20:15:46 +00:00
|
|
|
oldSelStart, oldSelEnd, newSelStart, newSelEnd, composingSpanStart,
|
2013-12-18 09:08:35 +00:00
|
|
|
composingSpanEnd, mInputLogic.mConnection);
|
2012-03-30 20:15:46 +00:00
|
|
|
}
|
2010-01-16 20:21:23 +00:00
|
|
|
|
2013-12-18 09:08:35 +00:00
|
|
|
final boolean selectionChanged = mInputLogic.mLastSelectionStart != newSelStart
|
|
|
|
|| mInputLogic.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.
|
2013-12-18 09:08:35 +00:00
|
|
|
if (isInputViewShown() && !mInputLogic.mConnection.isBelatedExpectedUpdate(oldSelStart,
|
|
|
|
newSelStart, oldSelEnd, newSelEnd)) {
|
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.
|
2013-12-19 05:34:35 +00:00
|
|
|
mInputLogic.mSpaceState = SpaceState.NONE;
|
2012-02-02 05:51:25 +00:00
|
|
|
|
2013-06-26 03:22:04 +00:00
|
|
|
// TODO: is it still necessary to test for composingSpan related stuff?
|
|
|
|
final boolean selectionChangedOrSafeToReset = selectionChanged
|
2013-12-18 09:08:35 +00:00
|
|
|
|| (!mInputLogic.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
|
2013-12-18 09:08:35 +00:00
|
|
|
|| !mInputLogic.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.
|
2013-12-19 07:07:24 +00:00
|
|
|
mInputLogic.resetEntireInputState(mSettings.getCurrent(), newSelStart, newSelEnd);
|
2013-06-26 02:32:07 +00:00
|
|
|
} else {
|
2013-12-13 08:09:16 +00:00
|
|
|
// resetEntireInputState calls resetCachesUponCursorMove, but forcing the
|
|
|
|
// composition to end. 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.
|
2013-12-18 09:08:35 +00:00
|
|
|
mInputLogic.mConnection.resetCachesUponCursorMoveAndReturnSuccess(
|
|
|
|
newSelStart, newSelEnd, 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-12-18 09:08:35 +00:00
|
|
|
mInputLogic.mRecapitalizeStatus.deactivate();
|
2012-09-24 05:40:23 +00:00
|
|
|
mKeyboardSwitcher.updateShiftState();
|
2011-06-08 07:47:19 +00:00
|
|
|
}
|
2010-01-16 20:21:23 +00:00
|
|
|
|
2010-08-20 05:35:02 +00:00
|
|
|
// Make a note of the cursor position
|
2013-12-18 09:08:35 +00:00
|
|
|
mInputLogic.mLastSelectionStart = newSelStart;
|
|
|
|
mInputLogic.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) {
|
2013-10-11 10:15:16 +00:00
|
|
|
final boolean inputViewShown = mKeyboardSwitcher.isShowingMainKeyboardOrEmojiPalettes();
|
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
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2013-08-30 07:50:37 +00:00
|
|
|
private int getAdjustedBackingViewHeight() {
|
|
|
|
final int currentHeight = mKeyPreviewBackingView.getHeight();
|
|
|
|
if (currentHeight > 0) {
|
|
|
|
return currentHeight;
|
|
|
|
}
|
|
|
|
|
2013-08-29 11:43:03 +00:00
|
|
|
final View visibleKeyboardView = mKeyboardSwitcher.getVisibleKeyboardView();
|
|
|
|
if (visibleKeyboardView == null) {
|
2013-08-30 07:50:37 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2013-08-29 11:43:03 +00:00
|
|
|
// TODO: !!!!!!!!!!!!!!!!!!!! Handle different backing view heights between the main !!!
|
|
|
|
// keyboard and the emoji keyboard. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
|
|
final int keyboardHeight = visibleKeyboardView.getHeight();
|
2013-08-30 07:50:37 +00:00
|
|
|
final int suggestionsHeight = mSuggestionStripView.getHeight();
|
|
|
|
final int displayHeight = getResources().getDisplayMetrics().heightPixels;
|
|
|
|
final Rect rect = new Rect();
|
|
|
|
mKeyPreviewBackingView.getWindowVisibleDisplayFrame(rect);
|
|
|
|
final int notificationBarHeight = rect.top;
|
|
|
|
final int remainingHeight = displayHeight - notificationBarHeight - suggestionsHeight
|
|
|
|
- keyboardHeight;
|
|
|
|
|
|
|
|
final LayoutParams params = mKeyPreviewBackingView.getLayoutParams();
|
|
|
|
params.height = mSuggestionStripView.setMoreSuggestionsHeight(remainingHeight);
|
|
|
|
mKeyPreviewBackingView.setLayoutParams(params);
|
|
|
|
return params.height;
|
|
|
|
}
|
|
|
|
|
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);
|
2013-08-29 11:43:03 +00:00
|
|
|
final View visibleKeyboardView = mKeyboardSwitcher.getVisibleKeyboardView();
|
|
|
|
if (visibleKeyboardView == null || mSuggestionStripView == null) {
|
2011-04-21 05:51:53 +00:00
|
|
|
return;
|
2012-08-07 02:48:10 +00:00
|
|
|
}
|
2013-08-30 07:50:37 +00:00
|
|
|
final int adjustedBackingHeight = getAdjustedBackingViewHeight();
|
|
|
|
final boolean backingGone = (mKeyPreviewBackingView.getVisibility() == View.GONE);
|
|
|
|
final int backingHeight = backingGone ? 0 : adjustedBackingHeight;
|
|
|
|
// In fullscreen mode, the height of the extract area managed by InputMethodService should
|
|
|
|
// be considered.
|
|
|
|
// See {@link android.inputmethodservice.InputMethodService#onComputeInsets}.
|
|
|
|
final int extractHeight = isFullscreenMode() ? mExtractArea.getHeight() : 0;
|
|
|
|
final int suggestionsHeight = (mSuggestionStripView.getVisibility() == View.GONE) ? 0
|
|
|
|
: mSuggestionStripView.getHeight();
|
|
|
|
final int extraHeight = extractHeight + backingHeight + suggestionsHeight;
|
|
|
|
int visibleTopY = extraHeight;
|
2011-01-21 10:04:00 +00:00
|
|
|
// Need to set touchable region only if input view is being shown
|
2013-08-29 11:43:03 +00:00
|
|
|
if (visibleKeyboardView.isShown()) {
|
2013-09-05 03:19:43 +00:00
|
|
|
// Note that the height of Emoji layout is the same as the height of the main keyboard
|
|
|
|
// and the suggestion strip
|
2013-10-11 10:15:16 +00:00
|
|
|
if (mKeyboardSwitcher.isShowingEmojiPalettes()
|
2013-09-05 03:19:43 +00:00
|
|
|
|| mSuggestionStripView.getVisibility() == View.VISIBLE) {
|
2013-08-30 07:50:37 +00:00
|
|
|
visibleTopY -= suggestionsHeight;
|
|
|
|
}
|
2013-08-29 11:43:03 +00:00
|
|
|
final int touchY = mKeyboardSwitcher.isShowingMoreKeysPanel() ? 0 : visibleTopY;
|
|
|
|
final int touchWidth = visibleKeyboardView.getWidth();
|
|
|
|
final int touchHeight = visibleKeyboardView.getHeight() + extraHeight
|
2011-04-13 05:12:24 +00:00
|
|
|
// Extend touchable region below the keyboard.
|
|
|
|
+ EXTENDED_TOUCHABLE_REGION_HEIGHT;
|
2012-04-02 13:25:08 +00:00
|
|
|
outInsets.touchableInsets = InputMethodService.Insets.TOUCHABLE_INSETS_REGION;
|
2013-08-30 07:50:37 +00:00
|
|
|
outInsets.touchableRegion.set(0, touchY, touchWidth, touchHeight);
|
2011-01-21 10:04:00 +00:00
|
|
|
}
|
2013-08-30 07:50:37 +00:00
|
|
|
outInsets.contentTopInsets = visibleTopY;
|
|
|
|
outInsets.visibleTopInsets = visibleTopY;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-08-20 05:35:02 +00:00
|
|
|
@Override
|
|
|
|
public boolean onEvaluateFullscreenMode() {
|
2012-01-16 02:32:49 +00:00
|
|
|
// Reread resource value here, because this method is called by framework anytime as needed.
|
2013-12-13 08:09:16 +00:00
|
|
|
final boolean isFullscreenModeAllowed = 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-30 07:50:37 +00:00
|
|
|
|
|
|
|
if (mKeyPreviewBackingView == null) return;
|
|
|
|
// In fullscreen mode, no need to have extra space to show the key preview.
|
|
|
|
// If not, we should have extra space above the keyboard to show the key preview.
|
|
|
|
mKeyPreviewBackingView.setVisibility(isFullscreenMode() ? View.GONE : View.VISIBLE);
|
2010-08-20 05:35:02 +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.
|
2013-12-19 08:57:10 +00:00
|
|
|
// TODO[IL]: Move this to InputLogic.
|
2012-05-18 07:45:26 +00:00
|
|
|
public int getCurrentAutoCapsState() {
|
2013-10-08 04:06:16 +00:00
|
|
|
final SettingsValues currentSettingsValues = mSettings.getCurrent();
|
|
|
|
if (!currentSettingsValues.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.
|
2013-12-18 09:08:35 +00:00
|
|
|
return mInputLogic.mConnection.getCursorCapsMode(inputType, currentSettingsValues,
|
2013-12-19 05:34:35 +00:00
|
|
|
SpaceState.PHANTOM == mInputLogic.mSpaceState);
|
2010-01-24 15:34:07 +00:00
|
|
|
}
|
|
|
|
|
2013-04-15 13:00:29 +00:00
|
|
|
public int getCurrentRecapitalizeState() {
|
2013-12-18 09:08:35 +00:00
|
|
|
if (!mInputLogic.mRecapitalizeStatus.isActive()
|
|
|
|
|| !mInputLogic.mRecapitalizeStatus.isSetAt(mInputLogic.mLastSelectionStart,
|
|
|
|
mInputLogic.mLastSelectionEnd)) {
|
2013-04-15 13:00:29 +00:00
|
|
|
// Not recapitalizing at the moment
|
|
|
|
return RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE;
|
|
|
|
}
|
2013-12-18 09:08:35 +00:00
|
|
|
return mInputLogic.mRecapitalizeStatus.getCurrentMode();
|
2013-04-15 13:00:29 +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.
|
|
|
|
return;
|
|
|
|
}
|
2013-01-16 13:07:43 +00:00
|
|
|
final String wordToEdit;
|
2013-12-18 09:08:35 +00:00
|
|
|
if (CapsModeUtils.isAutoCapsMode(mInputLogic.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
|
|
|
}
|
|
|
|
|
2013-12-19 05:34:35 +00:00
|
|
|
// TODO[IL]: Rework the route through which this is called.
|
|
|
|
public 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-10-02 08:09:56 +00:00
|
|
|
// TODO: Revise the language switch key behavior to make it much smarter and more reasonable.
|
2013-12-19 05:34:35 +00:00
|
|
|
// TODO[IL]: Move a part of this to InputLogic and straighten out the interface for this.
|
|
|
|
public void handleLanguageSwitchKey() {
|
2012-02-18 01:46:01 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
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-12-19 05:34:35 +00:00
|
|
|
mInputLogic.onCodeInput(primaryCode, x, y, mHandler, mKeyboardSwitcher, mSubtypeSwitcher);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2013-09-10 07:16:25 +00:00
|
|
|
// Called from PointerTracker through the KeyboardActionListener interface
|
2013-12-19 08:14:11 +00:00
|
|
|
// TODO[IL]: Move this to InputLogic
|
2013-09-10 07:16:25 +00:00
|
|
|
@Override
|
|
|
|
public void onTextInput(final String rawText) {
|
2013-12-18 09:08:35 +00:00
|
|
|
mInputLogic.mConnection.beginBatchEdit();
|
|
|
|
if (mInputLogic.mWordComposer.isComposingWord()) {
|
2013-12-19 09:18:18 +00:00
|
|
|
mInputLogic.commitCurrentAutoCorrection(mSettings.getCurrent(), rawText, mHandler);
|
2013-09-10 07:16:25 +00:00
|
|
|
} else {
|
2013-12-19 07:07:24 +00:00
|
|
|
mInputLogic.resetComposingState(true /* alsoResetLastComposedWord */);
|
2013-09-10 07:16:25 +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);
|
2013-12-19 05:34:35 +00:00
|
|
|
if (SpaceState.PHANTOM == mInputLogic.mSpaceState) {
|
2013-12-19 08:14:11 +00:00
|
|
|
mInputLogic.promotePhantomSpace(mSettings.getCurrent());
|
2012-02-02 08:18:03 +00:00
|
|
|
}
|
2013-12-18 09:08:35 +00:00
|
|
|
mInputLogic.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
|
|
|
}
|
2013-12-18 09:08:35 +00:00
|
|
|
mInputLogic.mConnection.endBatchEdit();
|
2012-09-14 07:53:01 +00:00
|
|
|
// Space state must be updated before calling updateShiftState
|
2013-12-19 05:34:35 +00:00
|
|
|
mInputLogic.mSpaceState = SpaceState.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);
|
2013-12-18 09:08:35 +00:00
|
|
|
mInputLogic.mEnteredText = text;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2012-07-04 06:24:59 +00:00
|
|
|
@Override
|
|
|
|
public void onStartBatchInput() {
|
2013-09-02 07:49:32 +00:00
|
|
|
mInputUpdater.onStartBatchInput();
|
2013-01-25 08:00:41 +00:00
|
|
|
mHandler.cancelUpdateSuggestionStrip();
|
2013-12-18 09:08:35 +00:00
|
|
|
mInputLogic.mConnection.beginBatchEdit();
|
2013-12-13 08:09:16 +00:00
|
|
|
final SettingsValues currentSettingsValues = mSettings.getCurrent();
|
2013-12-18 09:08:35 +00:00
|
|
|
if (mInputLogic.mWordComposer.isComposingWord()) {
|
2013-12-13 08:09:16 +00:00
|
|
|
if (currentSettingsValues.mIsInternal) {
|
2013-12-18 09:08:35 +00:00
|
|
|
if (mInputLogic.mWordComposer.isBatchMode()) {
|
|
|
|
LatinImeLoggerUtils.onAutoCorrection("",
|
|
|
|
mInputLogic.mWordComposer.getTypedWord(), " ",
|
|
|
|
mInputLogic.mWordComposer);
|
2012-09-19 07:18:24 +00:00
|
|
|
}
|
|
|
|
}
|
2013-12-18 09:08:35 +00:00
|
|
|
final int wordComposerSize = mInputLogic.mWordComposer.size();
|
2013-01-11 11:31:09 +00:00
|
|
|
// Since isComposingWord() is true, the size is at least 1.
|
2013-12-18 09:08:35 +00:00
|
|
|
if (mInputLogic.mWordComposer.isCursorFrontOrMiddleOfComposingWord()) {
|
2013-04-10 09:30:11 +00:00
|
|
|
// 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.
|
2013-12-19 07:07:24 +00:00
|
|
|
mInputLogic.resetEntireInputState(currentSettingsValues,
|
|
|
|
mInputLogic.mLastSelectionStart, mInputLogic.mLastSelectionEnd);
|
2013-04-10 09:30:11 +00:00
|
|
|
} 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.
|
2013-12-19 09:18:18 +00:00
|
|
|
mInputLogic.commitCurrentAutoCorrection(currentSettingsValues,
|
|
|
|
LastComposedWord.NOT_A_SEPARATOR, mHandler);
|
2012-09-20 06:52:40 +00:00
|
|
|
} else {
|
2013-12-19 07:37:07 +00:00
|
|
|
mInputLogic.commitTyped(LastComposedWord.NOT_A_SEPARATOR);
|
2012-09-20 06:52:40 +00:00
|
|
|
}
|
2013-05-07 08:07:47 +00:00
|
|
|
}
|
2013-12-18 09:08:35 +00:00
|
|
|
final int codePointBeforeCursor = mInputLogic.mConnection.getCodePointBeforeCursor();
|
2013-09-10 07:16:25 +00:00
|
|
|
if (Character.isLetterOrDigit(codePointBeforeCursor)
|
2013-12-13 08:09:16 +00:00
|
|
|
|| currentSettingsValues.isUsuallyFollowedBySpace(codePointBeforeCursor)) {
|
2013-12-13 10:07:29 +00:00
|
|
|
final boolean autoShiftHasBeenOverriden = mKeyboardSwitcher.getKeyboardShiftMode() !=
|
|
|
|
getCurrentAutoCapsState();
|
2013-12-19 05:34:35 +00:00
|
|
|
mInputLogic.mSpaceState = SpaceState.PHANTOM;
|
2013-12-13 10:07:29 +00:00
|
|
|
if (!autoShiftHasBeenOverriden) {
|
|
|
|
// When we change the space state, we need to update the shift state of the
|
|
|
|
// keyboard unless it has been overridden manually. This is happening for example
|
|
|
|
// after typing some letters and a period, then gesturing; the keyboard is not in
|
|
|
|
// caps mode yet, but since a gesture is starting, it should go in caps mode,
|
|
|
|
// unless the user explictly said it should not.
|
|
|
|
mKeyboardSwitcher.updateShiftState();
|
|
|
|
}
|
2012-07-04 06:24:59 +00:00
|
|
|
}
|
2013-12-18 09:08:35 +00:00
|
|
|
mInputLogic.mConnection.endBatchEdit();
|
|
|
|
mInputLogic.mWordComposer.setCapitalizedModeAndPreviousWordAtStartComposingTime(
|
2013-12-19 08:57:10 +00:00
|
|
|
mInputLogic.getActualCapsMode(mKeyboardSwitcher),
|
2013-12-13 08:09:16 +00:00
|
|
|
// Prev word is 1st word before cursor
|
2013-12-19 08:57:10 +00:00
|
|
|
mInputLogic.getNthPreviousWordForSuggestion(currentSettingsValues,
|
|
|
|
1 /* nthPreviousWord */));
|
2012-06-12 10:40:37 +00:00
|
|
|
}
|
|
|
|
|
2013-11-15 08:34:45 +00:00
|
|
|
static final class InputUpdater implements Handler.Callback {
|
2012-09-12 04:03:44 +00:00
|
|
|
private final Handler mHandler;
|
2013-09-02 07:49:32 +00:00
|
|
|
private final 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
|
|
|
|
2013-11-15 08:34:45 +00:00
|
|
|
InputUpdater(final LatinIME latinIme) {
|
2012-09-12 04:03:44 +00:00
|
|
|
final HandlerThread handlerThread = new HandlerThread(
|
2013-09-02 07:49:32 +00:00
|
|
|
InputUpdater.class.getSimpleName());
|
2012-09-12 04:03:44 +00:00
|
|
|
handlerThread.start();
|
|
|
|
mHandler = new Handler(handlerThread.getLooper(), this);
|
2013-09-02 07:49:32 +00:00
|
|
|
mLatinIme = latinIme;
|
2012-09-12 04:03:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private static final int MSG_UPDATE_GESTURE_PREVIEW_AND_SUGGESTION_STRIP = 1;
|
2013-09-02 07:49:32 +00:00
|
|
|
private static final int MSG_GET_SUGGESTED_WORDS = 2;
|
2012-09-12 04:03:44 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean handleMessage(final Message msg) {
|
2013-10-22 01:51:11 +00:00
|
|
|
// TODO: straighten message passing - we don't need two kinds of messages calling
|
|
|
|
// each other.
|
2012-09-12 04:03:44 +00:00
|
|
|
switch (msg.what) {
|
2013-09-02 07:49:32 +00:00
|
|
|
case MSG_UPDATE_GESTURE_PREVIEW_AND_SUGGESTION_STRIP:
|
2013-10-22 01:51:11 +00:00
|
|
|
updateBatchInput((InputPointers)msg.obj, msg.arg2 /* sequenceNumber */);
|
2013-09-02 07:49:32 +00:00
|
|
|
break;
|
|
|
|
case MSG_GET_SUGGESTED_WORDS:
|
2013-10-22 01:51:11 +00:00
|
|
|
mLatinIme.getSuggestedWords(msg.arg1 /* sessionId */,
|
|
|
|
msg.arg2 /* sequenceNumber */, (OnGetSuggestedWordsCallback) msg.obj);
|
2013-09-02 07:49:32 +00:00
|
|
|
break;
|
2012-09-12 04:03:44 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-09-27 10:01:17 +00:00
|
|
|
// Run in the UI thread.
|
2013-09-02 07:49:32 +00:00
|
|
|
public void onStartBatchInput() {
|
2013-04-10 09:27:11 +00:00
|
|
|
synchronized (mLock) {
|
|
|
|
mHandler.removeMessages(MSG_UPDATE_GESTURE_PREVIEW_AND_SUGGESTION_STRIP);
|
|
|
|
mInBatchInput = true;
|
2013-06-03 08:59:26 +00:00
|
|
|
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-10-22 01:51:11 +00:00
|
|
|
private void updateBatchInput(final InputPointers batchPointers, final int sequenceNumber) {
|
2013-04-10 09:27:11 +00:00
|
|
|
synchronized (mLock) {
|
|
|
|
if (!mInBatchInput) {
|
|
|
|
// Batch input has ended or canceled while the message was being delivered.
|
|
|
|
return;
|
|
|
|
}
|
2013-08-29 06:15:49 +00:00
|
|
|
|
2013-10-22 01:51:11 +00:00
|
|
|
getSuggestedWordsGestureLocked(batchPointers, sequenceNumber,
|
|
|
|
new OnGetSuggestedWordsCallback() {
|
2013-08-29 06:15:49 +00:00
|
|
|
@Override
|
|
|
|
public void onGetSuggestedWords(final SuggestedWords suggestedWords) {
|
|
|
|
mLatinIme.mHandler.showGesturePreviewAndSuggestionStrip(
|
|
|
|
suggestedWords, false /* dismissGestureFloatingPreviewText */);
|
2013-09-02 07:49:32 +00:00
|
|
|
}
|
|
|
|
});
|
2012-09-27 10:01:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run in the UI thread.
|
2013-10-22 01:51:11 +00:00
|
|
|
public void onUpdateBatchInput(final InputPointers batchPointers,
|
|
|
|
final int sequenceNumber) {
|
2012-09-12 04:03:44 +00:00
|
|
|
if (mHandler.hasMessages(MSG_UPDATE_GESTURE_PREVIEW_AND_SUGGESTION_STRIP)) {
|
|
|
|
return;
|
|
|
|
}
|
2013-10-22 01:51:11 +00:00
|
|
|
mHandler.obtainMessage(MSG_UPDATE_GESTURE_PREVIEW_AND_SUGGESTION_STRIP, 0 /* arg1 */,
|
|
|
|
sequenceNumber /* arg2 */, batchPointers /* obj */).sendToTarget();
|
2012-09-12 04:03:44 +00:00
|
|
|
}
|
|
|
|
|
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-08-29 06:15:49 +00:00
|
|
|
public void onEndBatchInput(final InputPointers batchPointers) {
|
|
|
|
synchronized(mLock) {
|
2013-10-22 01:51:11 +00:00
|
|
|
getSuggestedWordsGestureLocked(batchPointers, SuggestedWords.NOT_A_SEQUENCE_NUMBER,
|
|
|
|
new OnGetSuggestedWordsCallback() {
|
2013-08-29 06:15:49 +00:00
|
|
|
@Override
|
|
|
|
public void onGetSuggestedWords(final SuggestedWords suggestedWords) {
|
|
|
|
mInBatchInput = false;
|
|
|
|
mLatinIme.mHandler.showGesturePreviewAndSuggestionStrip(suggestedWords,
|
|
|
|
true /* dismissGestureFloatingPreviewText */);
|
2013-09-02 07:49:32 +00:00
|
|
|
mLatinIme.mHandler.onEndBatchInput(suggestedWords);
|
2013-08-29 06:15:49 +00:00
|
|
|
}
|
|
|
|
});
|
2013-08-30 14:06:19 +00:00
|
|
|
}
|
2012-09-12 04:03:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// {@link LatinIME#getSuggestedWords(int)} method calls with same session id have to
|
|
|
|
// be synchronized.
|
2013-08-29 06:15:49 +00:00
|
|
|
private void getSuggestedWordsGestureLocked(final InputPointers batchPointers,
|
2013-10-22 01:51:11 +00:00
|
|
|
final int sequenceNumber, final OnGetSuggestedWordsCallback callback) {
|
2013-12-18 09:08:35 +00:00
|
|
|
mLatinIme.mInputLogic.mWordComposer.setBatchInputPointers(batchPointers);
|
2013-09-02 07:49:32 +00:00
|
|
|
mLatinIme.getSuggestedWordsOrOlderSuggestionsAsync(Suggest.SESSION_GESTURE,
|
2013-10-22 01:51:11 +00:00
|
|
|
sequenceNumber, new OnGetSuggestedWordsCallback() {
|
2013-08-29 06:15:49 +00:00
|
|
|
@Override
|
|
|
|
public void onGetSuggestedWords(SuggestedWords suggestedWords) {
|
|
|
|
final int suggestionCount = suggestedWords.size();
|
|
|
|
if (suggestionCount <= 1) {
|
|
|
|
final String mostProbableSuggestion = (suggestionCount == 0) ? null
|
|
|
|
: suggestedWords.getWord(0);
|
|
|
|
callback.onGetSuggestedWords(
|
|
|
|
mLatinIme.getOlderSuggestions(mostProbableSuggestion));
|
|
|
|
}
|
|
|
|
callback.onGetSuggestedWords(suggestedWords);
|
|
|
|
}
|
|
|
|
});
|
2012-09-12 04:03:44 +00:00
|
|
|
}
|
2013-09-02 07:49:32 +00:00
|
|
|
|
2013-10-22 01:51:11 +00:00
|
|
|
public void getSuggestedWords(final int sessionId, final int sequenceNumber,
|
2013-09-02 07:49:32 +00:00
|
|
|
final OnGetSuggestedWordsCallback callback) {
|
2013-10-22 01:51:11 +00:00
|
|
|
mHandler.obtainMessage(MSG_GET_SUGGESTED_WORDS, sessionId, sequenceNumber, callback)
|
|
|
|
.sendToTarget();
|
2013-09-02 07:49:32 +00:00
|
|
|
}
|
|
|
|
|
2013-11-15 08:34:45 +00:00
|
|
|
void quitLooper() {
|
2013-09-02 07:49:32 +00:00
|
|
|
mHandler.removeMessages(MSG_GET_SUGGESTED_WORDS);
|
|
|
|
mHandler.removeMessages(MSG_UPDATE_GESTURE_PREVIEW_AND_SUGGESTION_STRIP);
|
|
|
|
mHandler.getLooper().quit();
|
|
|
|
}
|
2012-09-12 04:03:44 +00:00
|
|
|
}
|
|
|
|
|
2013-09-02 07:49:32 +00:00
|
|
|
// This method must run in UI Thread.
|
2012-09-12 04:03:44 +00:00
|
|
|
private void showGesturePreviewAndSuggestionStrip(final SuggestedWords suggestedWords,
|
|
|
|
final boolean dismissGestureFloatingPreviewText) {
|
2013-09-02 12:58:36 +00:00
|
|
|
showSuggestionStrip(suggestedWords);
|
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
|
|
|
}
|
|
|
|
|
2013-10-22 01:51:11 +00:00
|
|
|
/* The sequence number member is only used in onUpdateBatchInput. It is increased each time
|
|
|
|
* auto-commit happens. The reason we need this is, when auto-commit happens we trim the
|
|
|
|
* input pointers that are held in a singleton, and to know how much to trim we rely on the
|
|
|
|
* results of the suggestion process that is held in mSuggestedWords.
|
|
|
|
* However, the suggestion process is asynchronous, and sometimes we may enter the
|
|
|
|
* onUpdateBatchInput method twice without having recomputed suggestions yet, or having
|
|
|
|
* received new suggestions generated from not-yet-trimmed input pointers. In this case, the
|
|
|
|
* mIndexOfTouchPointOfSecondWords member will be out of date, and we must not use it lest we
|
|
|
|
* remove an unrelated number of pointers (possibly even more than are left in the input
|
|
|
|
* pointers, leading to a crash).
|
|
|
|
* To avoid that, we increase the sequence number each time we auto-commit and trim the
|
|
|
|
* input pointers, and we do not use any suggested words that have been generated with an
|
|
|
|
* earlier sequence number.
|
|
|
|
*/
|
|
|
|
private int mAutoCommitSequenceNumber = 1;
|
2012-07-04 06:24:59 +00:00
|
|
|
@Override
|
2012-09-12 04:03:44 +00:00
|
|
|
public void onUpdateBatchInput(final InputPointers batchPointers) {
|
2013-09-10 08:48:00 +00:00
|
|
|
if (mSettings.getCurrent().mPhraseGestureEnabled) {
|
2013-12-18 09:08:35 +00:00
|
|
|
final SuggestedWordInfo candidate =
|
|
|
|
mInputLogic.mSuggestedWords.getAutoCommitCandidate();
|
2013-10-22 01:51:11 +00:00
|
|
|
// If these suggested words have been generated with out of date input pointers, then
|
|
|
|
// we skip auto-commit (see comments above on the mSequenceNumber member).
|
2013-12-18 09:08:35 +00:00
|
|
|
if (null != candidate
|
|
|
|
&& mInputLogic.mSuggestedWords.mSequenceNumber >= mAutoCommitSequenceNumber) {
|
2013-09-10 08:48:00 +00:00
|
|
|
if (candidate.mSourceDict.shouldAutoCommit(candidate)) {
|
|
|
|
final String[] commitParts = candidate.mWord.split(" ", 2);
|
|
|
|
batchPointers.shift(candidate.mIndexOfTouchPointOfSecondWord);
|
2013-12-19 08:14:11 +00:00
|
|
|
mInputLogic.promotePhantomSpace(mSettings.getCurrent());
|
2013-12-18 09:08:35 +00:00
|
|
|
mInputLogic.mConnection.commitText(commitParts[0], 0);
|
2013-12-19 05:34:35 +00:00
|
|
|
mInputLogic.mSpaceState = SpaceState.PHANTOM;
|
2013-09-10 08:48:00 +00:00
|
|
|
mKeyboardSwitcher.updateShiftState();
|
2013-12-18 09:08:35 +00:00
|
|
|
mInputLogic.mWordComposer.
|
|
|
|
setCapitalizedModeAndPreviousWordAtStartComposingTime(
|
2013-12-19 08:57:10 +00:00
|
|
|
mInputLogic.getActualCapsMode(mKeyboardSwitcher), commitParts[0]);
|
2013-10-22 01:51:11 +00:00
|
|
|
++mAutoCommitSequenceNumber;
|
2013-09-10 08:48:00 +00:00
|
|
|
}
|
2013-08-20 07:21:27 +00:00
|
|
|
}
|
|
|
|
}
|
2013-10-22 01:51:11 +00:00
|
|
|
mInputUpdater.onUpdateBatchInput(batchPointers, mAutoCommitSequenceNumber);
|
2012-09-12 04:03:44 +00:00
|
|
|
}
|
|
|
|
|
2013-09-02 07:49:32 +00:00
|
|
|
// This method must run in UI Thread.
|
2013-08-29 06:15:49 +00:00
|
|
|
public void onEndBatchInputAsyncInternal(final SuggestedWords suggestedWords) {
|
2013-12-13 08:09:16 +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;
|
|
|
|
}
|
2013-12-18 09:08:35 +00:00
|
|
|
mInputLogic.mConnection.beginBatchEdit();
|
2013-12-19 05:34:35 +00:00
|
|
|
if (SpaceState.PHANTOM == mInputLogic.mSpaceState) {
|
2013-12-19 08:14:11 +00:00
|
|
|
mInputLogic.promotePhantomSpace(mSettings.getCurrent());
|
2012-07-04 06:24:59 +00:00
|
|
|
}
|
2013-09-10 08:48:00 +00:00
|
|
|
if (mSettings.getCurrent().mPhraseGestureEnabled) {
|
|
|
|
// Find the last space
|
|
|
|
final int indexOfLastSpace = batchInputText.lastIndexOf(Constants.CODE_SPACE) + 1;
|
|
|
|
if (0 != indexOfLastSpace) {
|
2013-12-18 09:08:35 +00:00
|
|
|
mInputLogic.mConnection.commitText(batchInputText.substring(0, indexOfLastSpace),
|
|
|
|
1);
|
2013-09-13 07:49:41 +00:00
|
|
|
showSuggestionStrip(suggestedWords.getSuggestedWordsForLastWordOfPhraseGesture());
|
2013-09-10 08:48:00 +00:00
|
|
|
}
|
|
|
|
final String lastWord = batchInputText.substring(indexOfLastSpace);
|
2013-12-18 09:08:35 +00:00
|
|
|
mInputLogic.mWordComposer.setBatchInputWord(lastWord);
|
|
|
|
mInputLogic.mConnection.setComposingText(lastWord, 1);
|
2013-09-10 08:48:00 +00:00
|
|
|
} else {
|
2013-12-18 09:08:35 +00:00
|
|
|
mInputLogic.mWordComposer.setBatchInputWord(batchInputText);
|
|
|
|
mInputLogic.mConnection.setComposingText(batchInputText, 1);
|
2013-09-10 08:48:00 +00:00
|
|
|
}
|
2013-12-18 09:08:35 +00:00
|
|
|
mInputLogic.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
|
2013-12-19 05:34:35 +00:00
|
|
|
mInputLogic.mSpaceState = SpaceState.PHANTOM;
|
2012-09-14 07:53:01 +00:00
|
|
|
mKeyboardSwitcher.updateShiftState();
|
2012-07-04 06:24:59 +00:00
|
|
|
}
|
|
|
|
|
2013-08-29 06:15:49 +00:00
|
|
|
@Override
|
|
|
|
public void onEndBatchInput(final InputPointers batchPointers) {
|
2013-09-02 07:49:32 +00:00
|
|
|
mInputUpdater.onEndBatchInput(batchPointers);
|
2013-08-29 06:15:49 +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.
|
2013-12-19 05:34:35 +00:00
|
|
|
mInputLogic.mSpaceState = SpaceState.NONE;
|
2012-10-16 21:41:15 +00:00
|
|
|
// TODO: use getCodePointBeforeCursor instead to improve performance and simplify the code
|
2013-12-18 09:08:35 +00:00
|
|
|
final CharSequence lastOne = mInputLogic.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() {
|
2013-09-02 07:49:32 +00:00
|
|
|
mInputUpdater.onCancelBatchInput();
|
2012-11-22 06:39:28 +00:00
|
|
|
}
|
|
|
|
|
2013-12-19 08:14:11 +00:00
|
|
|
// TODO[IL]: Rename this to avoid using handle*
|
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.
|
2013-12-19 07:37:07 +00:00
|
|
|
mInputLogic.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
|
|
|
}
|
|
|
|
|
2013-12-19 08:14:11 +00:00
|
|
|
// TODO[IL]: Move this to InputLogic and make it private
|
2012-07-09 03:54:42 +00:00
|
|
|
// Outside LatinIME, only used by the test suite.
|
2012-10-03 08:36:45 +00:00
|
|
|
@UsedForTesting
|
2013-12-19 08:14:11 +00:00
|
|
|
public boolean isShowingPunctuationList() {
|
2013-12-18 09:08:35 +00:00
|
|
|
if (mInputLogic.mSuggestedWords == null) return false;
|
|
|
|
return mSettings.getCurrent().mSuggestPuncList == mInputLogic.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
|
|
|
}
|
|
|
|
|
2013-12-19 08:57:10 +00:00
|
|
|
public void dismissAddToDictionaryHint() {
|
|
|
|
if (null != mSuggestionStripView) {
|
|
|
|
mSuggestionStripView.dismissAddToDictionaryHint();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-19 07:07:24 +00:00
|
|
|
// TODO[IL]: Define a clear interface for this
|
|
|
|
public 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-12-19 07:07:24 +00:00
|
|
|
// TODO[IL]: Define a clear interface for this
|
|
|
|
public void setSuggestedWords(final SuggestedWords words, final boolean isAutoCorrection) {
|
2013-12-18 09:08:35 +00:00
|
|
|
mInputLogic.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.
|
2013-12-18 09:08:35 +00:00
|
|
|
if (mInputLogic.mIsAutoCorrectionIndicatorOn != newAutoCorrectionIndicator
|
|
|
|
&& mInputLogic.mWordComposer.isComposingWord()) {
|
|
|
|
mInputLogic.mIsAutoCorrectionIndicatorOn = newAutoCorrectionIndicator;
|
2012-03-15 06:53:55 +00:00
|
|
|
final CharSequence textWithUnderline =
|
2013-12-19 07:07:24 +00:00
|
|
|
mInputLogic.getTextWithUnderline(mInputLogic.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.
|
2013-12-18 09:08:35 +00:00
|
|
|
mInputLogic.mConnection.setComposingText(textWithUnderline, 1);
|
2011-09-28 06:59:11 +00:00
|
|
|
}
|
2010-01-16 20:21:23 +00:00
|
|
|
}
|
|
|
|
|
2013-12-19 09:18:18 +00:00
|
|
|
// TODO[IL]: Move this to InputLogic and make private again
|
|
|
|
public 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-12-18 09:08:35 +00:00
|
|
|
if (mInputLogic.mSuggest == null
|
2013-07-30 03:54:33 +00:00
|
|
|
|| !currentSettings.isSuggestionsRequested(mDisplayOrientation)) {
|
2013-12-18 09:08:35 +00:00
|
|
|
if (mInputLogic.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-12-18 09:08:35 +00:00
|
|
|
if (!mInputLogic.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-09-09 14:10:33 +00:00
|
|
|
final AsyncResultHolder<SuggestedWords> holder = new AsyncResultHolder<SuggestedWords>();
|
2013-09-02 07:49:32 +00:00
|
|
|
getSuggestedWordsOrOlderSuggestionsAsync(Suggest.SESSION_TYPING,
|
2013-10-22 01:51:11 +00:00
|
|
|
SuggestedWords.NOT_A_SEQUENCE_NUMBER, new OnGetSuggestedWordsCallback() {
|
2013-09-02 07:49:32 +00:00
|
|
|
@Override
|
|
|
|
public void onGetSuggestedWords(final SuggestedWords suggestedWords) {
|
2013-09-09 14:10:33 +00:00
|
|
|
holder.set(suggestedWords);
|
2013-09-02 07:49:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2013-09-09 14:10:33 +00:00
|
|
|
// This line may cause the current thread to wait.
|
|
|
|
final SuggestedWords suggestedWords = holder.get(null, GET_SUGGESTED_WORDS_TIMEOUT);
|
|
|
|
if (suggestedWords != null) {
|
|
|
|
showSuggestionStrip(suggestedWords);
|
2013-09-02 07:49:32 +00:00
|
|
|
}
|
2012-07-23 02:59:11 +00:00
|
|
|
}
|
|
|
|
|
2013-10-22 01:51:11 +00:00
|
|
|
private void getSuggestedWords(final int sessionId, final int sequenceNumber,
|
2013-08-29 06:15:49 +00:00
|
|
|
final OnGetSuggestedWordsCallback callback) {
|
2012-10-03 04:01:52 +00:00
|
|
|
final Keyboard keyboard = mKeyboardSwitcher.getKeyboard();
|
2013-12-18 09:08:35 +00:00
|
|
|
final Suggest suggest = mInputLogic.mSuggest;
|
2013-07-29 08:47:13 +00:00
|
|
|
if (keyboard == null || suggest == null) {
|
2013-08-29 06:15:49 +00:00
|
|
|
callback.onGetSuggestedWords(SuggestedWords.EMPTY);
|
|
|
|
return;
|
2012-10-03 04:01:52 +00:00
|
|
|
}
|
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.
|
2013-07-30 03:54:33 +00:00
|
|
|
final SettingsValues currentSettings = mSettings.getCurrent();
|
2013-08-28 10:24:28 +00:00
|
|
|
final int[] additionalFeaturesOptions = currentSettings.mAdditionalFeaturesSettingValues;
|
2013-12-13 08:09:16 +00:00
|
|
|
|
|
|
|
if (DEBUG) {
|
2013-12-18 09:08:35 +00:00
|
|
|
if (mInputLogic.mWordComposer.isComposingWord()
|
|
|
|
|| mInputLogic.mWordComposer.isBatchMode()) {
|
|
|
|
final String previousWord
|
|
|
|
= mInputLogic.mWordComposer.getPreviousWordForSuggestion();
|
2013-12-16 12:32:13 +00:00
|
|
|
// TODO: this is for checking consistency with older versions. Remove this when
|
|
|
|
// we are confident this is stable.
|
|
|
|
// We're checking the previous word in the text field against the memorized previous
|
|
|
|
// word. If we are composing a word we should have the second word before the cursor
|
|
|
|
// memorized, otherwise we should have the first.
|
2013-12-19 08:57:10 +00:00
|
|
|
final String rereadPrevWord = mInputLogic.getNthPreviousWordForSuggestion(
|
|
|
|
currentSettings, mInputLogic.mWordComposer.isComposingWord() ? 2 : 1);
|
2013-12-16 12:32:13 +00:00
|
|
|
if (!TextUtils.equals(previousWord, rereadPrevWord)) {
|
|
|
|
throw new RuntimeException("Unexpected previous word: "
|
|
|
|
+ previousWord + " <> " + rereadPrevWord);
|
|
|
|
}
|
2013-12-13 08:09:16 +00:00
|
|
|
}
|
2013-08-15 07:31:29 +00:00
|
|
|
}
|
2013-12-18 09:08:35 +00:00
|
|
|
suggest.getSuggestedWords(mInputLogic.mWordComposer,
|
|
|
|
mInputLogic.mWordComposer.getPreviousWordForSuggestion(),
|
2013-12-13 08:09:16 +00:00
|
|
|
keyboard.getProximityInfo(),
|
2013-08-29 06:15:49 +00:00
|
|
|
currentSettings.mBlockPotentiallyOffensive, currentSettings.mCorrectionEnabled,
|
2013-10-22 01:51:11 +00:00
|
|
|
additionalFeaturesOptions, sessionId, sequenceNumber, callback);
|
2013-04-19 02:48:14 +00:00
|
|
|
}
|
|
|
|
|
2013-09-02 07:49:32 +00:00
|
|
|
private void getSuggestedWordsOrOlderSuggestionsAsync(final int sessionId,
|
2013-10-22 01:51:11 +00:00
|
|
|
final int sequenceNumber, final OnGetSuggestedWordsCallback callback) {
|
|
|
|
mInputUpdater.getSuggestedWords(sessionId, sequenceNumber,
|
|
|
|
new OnGetSuggestedWordsCallback() {
|
|
|
|
@Override
|
|
|
|
public void onGetSuggestedWords(SuggestedWords suggestedWords) {
|
|
|
|
callback.onGetSuggestedWords(maybeRetrieveOlderSuggestions(
|
2013-12-18 09:08:35 +00:00
|
|
|
mInputLogic.mWordComposer.getTypedWord(), suggestedWords));
|
2013-10-22 01:51:11 +00:00
|
|
|
}
|
|
|
|
});
|
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-12-18 09:08:35 +00:00
|
|
|
SuggestedWords previousSuggestedWords = mInputLogic.mSuggestedWords;
|
2013-02-26 07:25:30 +00:00
|
|
|
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 */);
|
|
|
|
}
|
|
|
|
|
2013-09-19 11:31:15 +00:00
|
|
|
private void setAutoCorrection(final SuggestedWords suggestedWords, final String typedWord) {
|
2013-09-05 08:56:00 +00:00
|
|
|
if (suggestedWords.isEmpty()) return;
|
2012-10-03 06:19:43 +00:00
|
|
|
final String autoCorrection;
|
2012-10-03 05:06:44 +00:00
|
|
|
if (suggestedWords.mWillAutoCorrect) {
|
2013-09-02 12:58:36 +00:00
|
|
|
autoCorrection = suggestedWords.getWord(SuggestedWords.INDEX_OF_AUTO_CORRECTION);
|
2009-03-13 22:11:42 +00:00
|
|
|
} else {
|
2013-09-19 11:31:15 +00:00
|
|
|
// We can't use suggestedWords.getWord(SuggestedWords.INDEX_OF_TYPED_WORD)
|
|
|
|
// because it may differ from mWordComposer.mTypedWord.
|
|
|
|
autoCorrection = typedWord;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2013-12-18 09:08:35 +00:00
|
|
|
mInputLogic.mWordComposer.setAutoCorrection(autoCorrection);
|
2013-09-05 08:56:00 +00:00
|
|
|
}
|
|
|
|
|
2013-09-19 11:31:15 +00:00
|
|
|
private void showSuggestionStripWithTypedWord(final SuggestedWords suggestedWords,
|
|
|
|
final String typedWord) {
|
|
|
|
if (suggestedWords.isEmpty()) {
|
2013-09-27 21:15:53 +00:00
|
|
|
// No auto-correction is available, clear the cached values.
|
|
|
|
AccessibilityUtils.getInstance().setAutoCorrection(null, null);
|
2013-09-19 11:31:15 +00:00
|
|
|
clearSuggestionStrip();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
setAutoCorrection(suggestedWords, typedWord);
|
|
|
|
final boolean isAutoCorrection = suggestedWords.willAutoCorrect();
|
|
|
|
setSuggestedWords(suggestedWords, isAutoCorrection);
|
|
|
|
setAutoCorrectionIndicator(isAutoCorrection);
|
|
|
|
setSuggestionStripShown(isSuggestionsStripVisible());
|
2013-09-27 21:15:53 +00:00
|
|
|
// An auto-correction is available, cache it in accessibility code so
|
|
|
|
// we can be speak it if the user touches a key that will insert it.
|
|
|
|
AccessibilityUtils.getInstance().setAutoCorrection(suggestedWords, typedWord);
|
2013-09-19 11:31:15 +00:00
|
|
|
}
|
|
|
|
|
2013-09-05 08:56:00 +00:00
|
|
|
private void showSuggestionStrip(final SuggestedWords suggestedWords) {
|
|
|
|
if (suggestedWords.isEmpty()) {
|
|
|
|
clearSuggestionStrip();
|
|
|
|
return;
|
|
|
|
}
|
2013-09-19 11:31:15 +00:00
|
|
|
showSuggestionStripWithTypedWord(suggestedWords,
|
|
|
|
suggestedWords.getWord(SuggestedWords.INDEX_OF_TYPED_WORD));
|
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-12-18 09:08:35 +00:00
|
|
|
final SuggestedWords suggestedWords = mInputLogic.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;
|
|
|
|
}
|
|
|
|
|
2013-12-18 09:08:35 +00:00
|
|
|
mInputLogic.mConnection.beginBatchEdit();
|
2013-07-30 03:54:33 +00:00
|
|
|
final SettingsValues currentSettings = mSettings.getCurrent();
|
2013-12-19 05:34:35 +00:00
|
|
|
if (SpaceState.PHANTOM == mInputLogic.mSpaceState && suggestion.length() > 0
|
2012-06-12 10:40:37 +00:00
|
|
|
// 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.
|
2013-12-18 09:08:35 +00:00
|
|
|
&& !mInputLogic.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)) {
|
2013-12-19 08:14:11 +00:00
|
|
|
mInputLogic.promotePhantomSpace(currentSettings);
|
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-12-18 09:08:35 +00:00
|
|
|
mInputLogic.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();
|
2013-12-19 07:07:24 +00:00
|
|
|
mInputLogic.resetComposingState(true /* alsoResetLastComposedWord */);
|
2012-06-08 10:04:09 +00:00
|
|
|
final CompletionInfo completionInfo = mApplicationSpecifiedCompletions[index];
|
2013-12-18 09:08:35 +00:00
|
|
|
mInputLogic.mConnection.commitCompletion(completionInfo);
|
|
|
|
mInputLogic.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.
|
2013-12-18 09:08:35 +00:00
|
|
|
final String replacedWord = mInputLogic.mWordComposer.getTypedWord();
|
2012-08-28 17:26:21 +00:00
|
|
|
LatinImeLogger.logOnManualSuggestion(replacedWord, suggestion, index, suggestedWords);
|
2012-08-20 17:17:45 +00:00
|
|
|
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-12-18 09:08:35 +00:00
|
|
|
mInputLogic.mWordComposer.isBatchMode(), suggestionInfo.mScore,
|
|
|
|
suggestionInfo.mKind, suggestionInfo.mSourceDict.mDictType);
|
2012-08-02 00:26:45 +00:00
|
|
|
}
|
2013-12-18 09:08:35 +00:00
|
|
|
mInputLogic.mConnection.endBatchEdit();
|
2012-04-20 06:55:19 +00:00
|
|
|
// Don't allow cancellation of manual pick
|
2013-12-18 09:08:35 +00:00
|
|
|
mInputLogic.mLastComposedWord.deactivate();
|
2012-09-14 07:53:01 +00:00
|
|
|
// Space state must be updated before calling updateShiftState
|
2013-12-19 05:34:35 +00:00
|
|
|
mInputLogic.mSpaceState = SpaceState.PHANTOM;
|
2012-02-02 08:18:03 +00:00
|
|
|
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-12-18 09:08:35 +00:00
|
|
|
final Suggest suggest = mInputLogic.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
|
|
|
*/
|
2013-12-19 07:37:07 +00:00
|
|
|
// TODO[IL]: Move to InputLogic and make public again
|
|
|
|
public void commitChosenWord(final String chosenWord, final int commitType,
|
2012-08-27 11:09:46 +00:00
|
|
|
final String separatorString) {
|
2013-12-18 09:08:35 +00:00
|
|
|
final SuggestedWords suggestedWords = mInputLogic.mSuggestedWords;
|
|
|
|
mInputLogic.mConnection.commitText(SuggestionSpanUtils.getTextWithSuggestionSpan(
|
2012-06-16 02:06:29 +00:00
|
|
|
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.
|
2013-12-18 09:08:35 +00:00
|
|
|
mInputLogic.mLastComposedWord = mInputLogic.mWordComposer.commitWord(commitType,
|
|
|
|
chosenWord, separatorString, prevWord);
|
2013-12-16 12:41:03 +00:00
|
|
|
final boolean shouldDiscardPreviousWordForSuggestion;
|
|
|
|
if (0 == StringUtils.codePointCount(separatorString)) {
|
|
|
|
// Separator is 0-length. Discard the word only if the current language has spaces.
|
|
|
|
shouldDiscardPreviousWordForSuggestion =
|
|
|
|
mSettings.getCurrent().mCurrentLanguageHasSpaces;
|
|
|
|
} else {
|
|
|
|
// Otherwise, we discard if the separator contains any non-whitespace.
|
|
|
|
shouldDiscardPreviousWordForSuggestion =
|
|
|
|
!StringUtils.containsOnlyWhitespace(separatorString);
|
|
|
|
}
|
|
|
|
if (shouldDiscardPreviousWordForSuggestion) {
|
2013-12-18 09:08:35 +00:00
|
|
|
mInputLogic.mWordComposer.discardPreviousWordForSuggestion();
|
2013-12-16 12:41:03 +00:00
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2013-12-19 08:14:11 +00:00
|
|
|
// TODO[IL]: Define a clean interface for this
|
|
|
|
public 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-12-18 09:08:35 +00:00
|
|
|
final Suggest suggest = mInputLogic.mSuggest;
|
2013-07-30 05:44:09 +00:00
|
|
|
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-12-17 10:36:19 +00:00
|
|
|
final UserHistoryDictionary userHistoryDictionary = suggest.getUserHistoryDictionary();
|
2013-09-28 03:50:09 +00:00
|
|
|
if (userHistoryDictionary == null) return null;
|
2013-07-30 05:44:09 +00:00
|
|
|
|
2013-12-18 09:08:35 +00:00
|
|
|
final String prevWord = mInputLogic.mConnection.getNthPreviousWord(currentSettings, 2);
|
2013-03-25 10:00:38 +00:00
|
|
|
final String secondWord;
|
2013-12-18 09:08:35 +00:00
|
|
|
if (mInputLogic.mWordComposer.wasAutoCapitalized()
|
|
|
|
&& !mInputLogic.mWordComposer.isMostlyCaps()) {
|
2013-03-25 10:00:38 +00:00
|
|
|
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-12-13 08:09:16 +00:00
|
|
|
userHistoryDictionary.addToDictionary(prevWord, secondWord, maxFreq > 0,
|
|
|
|
(int)TimeUnit.MILLISECONDS.toSeconds((System.currentTimeMillis())));
|
2013-03-25 10:00:38 +00:00
|
|
|
return prevWord;
|
2010-02-20 00:38:58 +00:00
|
|
|
}
|
|
|
|
|
2013-09-17 13:34:47 +00:00
|
|
|
private boolean isResumableWord(final String word, final SettingsValues settings) {
|
|
|
|
final int firstCodePoint = word.codePointAt(0);
|
|
|
|
return settings.isWordCodePoint(firstCodePoint)
|
|
|
|
&& Constants.CODE_SINGLE_QUOTE != firstCodePoint
|
|
|
|
&& Constants.CODE_DASH != firstCodePoint;
|
|
|
|
}
|
|
|
|
|
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-09-12 12:20:07 +00:00
|
|
|
// A simple way to test for support from the TextView.
|
|
|
|
if (!isSuggestionsStripVisible()) return;
|
2013-08-15 07:31:29 +00:00
|
|
|
// Recorrection is not supported in languages without spaces because we don't know
|
|
|
|
// how to segment them yet.
|
|
|
|
if (!mSettings.getCurrent().mCurrentLanguageHasSpaces) 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.
|
2013-12-18 09:08:35 +00:00
|
|
|
if (mInputLogic.mLastSelectionStart != mInputLogic.mLastSelectionEnd) return;
|
2013-05-08 09:44:50 +00:00
|
|
|
// If we don't know the cursor location, return.
|
2013-12-18 09:08:35 +00:00
|
|
|
if (mInputLogic.mLastSelectionStart < 0) return;
|
2013-07-30 03:54:33 +00:00
|
|
|
final SettingsValues currentSettings = mSettings.getCurrent();
|
2013-12-18 09:08:35 +00:00
|
|
|
if (!mInputLogic.mConnection.isCursorTouchingWord(currentSettings)) return;
|
|
|
|
final TextRange range = mInputLogic.mConnection.getWordRangeAtCursor(
|
|
|
|
currentSettings.mWordSeparators, 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-09-20 09:21:10 +00:00
|
|
|
if (range.length() <= 0) return; // Race condition. No text to resume on, so bail out.
|
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();
|
2013-12-18 09:08:35 +00:00
|
|
|
if (numberOfCharsInWordBeforeCursor > mInputLogic.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();
|
2013-09-17 13:34:47 +00:00
|
|
|
if (!isResumableWord(typedWord, currentSettings)) return;
|
2013-06-24 10:43:03 +00:00
|
|
|
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,
|
2013-08-20 07:11:03 +00:00
|
|
|
SuggestedWordInfo.KIND_RESUMED, Dictionary.DICTIONARY_RESUMED,
|
2013-08-20 09:00:21 +00:00
|
|
|
SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */,
|
|
|
|
SuggestedWordInfo.NOT_A_CONFIDENCE
|
|
|
|
/* autoCommitFirstWordConfidence */));
|
2013-04-10 07:38:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-12-18 09:08:35 +00:00
|
|
|
mInputLogic.mWordComposer.setComposingWord(typedWord,
|
2013-12-19 08:57:10 +00:00
|
|
|
mInputLogic.getNthPreviousWordForSuggestion(currentSettings,
|
2013-12-13 08:09:16 +00:00
|
|
|
// We want the previous word for suggestion. If we have chars in the word
|
|
|
|
// before the cursor, then we want the word before that, hence 2; otherwise,
|
|
|
|
// we want the word immediately before the cursor, hence 1.
|
|
|
|
0 == numberOfCharsInWordBeforeCursor ? 1 : 2),
|
|
|
|
mKeyboardSwitcher.getKeyboard());
|
2013-12-18 09:08:35 +00:00
|
|
|
mInputLogic.mWordComposer.setCursorPositionWithinWord(
|
2013-08-14 07:00:28 +00:00
|
|
|
typedWord.codePointCount(0, numberOfCharsInWordBeforeCursor));
|
2013-12-18 09:08:35 +00:00
|
|
|
mInputLogic.mConnection.setComposingRegion(
|
|
|
|
mInputLogic.mLastSelectionStart - numberOfCharsInWordBeforeCursor,
|
|
|
|
mInputLogic.mLastSelectionEnd + range.getNumberOfCharsInWordAfterCursor());
|
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.
|
2013-09-02 07:49:32 +00:00
|
|
|
mInputUpdater.getSuggestedWords(Suggest.SESSION_TYPING,
|
2013-10-22 01:51:11 +00:00
|
|
|
SuggestedWords.NOT_A_SEQUENCE_NUMBER, new OnGetSuggestedWordsCallback() {
|
|
|
|
@Override
|
|
|
|
public void onGetSuggestedWords(
|
|
|
|
final SuggestedWords suggestedWordsIncludingTypedWord) {
|
|
|
|
final SuggestedWords suggestedWords;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
// We need to pass typedWord because mWordComposer.mTypedWord may
|
|
|
|
// differ from typedWord.
|
|
|
|
unsetIsAutoCorrectionIndicatorOnAndCallShowSuggestionStrip(
|
|
|
|
suggestedWords, typedWord);
|
|
|
|
}});
|
2013-04-10 09:30:11 +00:00
|
|
|
} else {
|
|
|
|
// We found suggestion spans in the word. We'll create the SuggestedWords out of
|
|
|
|
// them, and make willAutoCorrect false.
|
2013-08-29 06:15:49 +00:00
|
|
|
final SuggestedWords suggestedWords = new SuggestedWords(suggestions,
|
2013-04-10 09:30:11 +00:00
|
|
|
true /* typedWordValid */, false /* willAutoCorrect */,
|
|
|
|
false /* isPunctuationSuggestions */, false /* isObsoleteSuggestions */,
|
|
|
|
false /* isPrediction */);
|
2013-09-19 11:31:15 +00:00
|
|
|
// We need to pass typedWord because mWordComposer.mTypedWord may differ from typedWord.
|
|
|
|
unsetIsAutoCorrectionIndicatorOnAndCallShowSuggestionStrip(suggestedWords, typedWord);
|
2013-04-10 07:38:37 +00:00
|
|
|
}
|
2013-08-29 06:15:49 +00:00
|
|
|
}
|
2013-04-10 09:30:11 +00:00
|
|
|
|
2013-08-29 06:15:49 +00:00
|
|
|
public void unsetIsAutoCorrectionIndicatorOnAndCallShowSuggestionStrip(
|
2013-09-19 11:31:15 +00:00
|
|
|
final SuggestedWords suggestedWords, final String typedWord) {
|
2013-04-10 09:30:11 +00:00
|
|
|
// Note that it's very important here that suggestedWords.mWillAutoCorrect is false.
|
2013-08-29 06:15:49 +00:00
|
|
|
// We never want to auto-correct on a resumed suggestion. Please refer to the three places
|
|
|
|
// above in restartSuggestionsOnWordTouchedByCursor() where suggestedWords is affected.
|
|
|
|
// We also need to unset mIsAutoCorrectionIndicatorOn to avoid showSuggestionStrip touching
|
|
|
|
// the text to adapt it.
|
|
|
|
// TODO: remove mIsAutoCorrectionIndicatorOn (see comment on definition)
|
2013-12-18 09:08:35 +00:00
|
|
|
mInputLogic.mIsAutoCorrectionIndicatorOn = false;
|
2013-09-19 11:31:15 +00:00
|
|
|
mHandler.showSuggestionStripWithTypedWord(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.
|
|
|
|
*/
|
2013-12-19 07:07:24 +00:00
|
|
|
// TODO[IL]: Move this to InputLogic and make it private.
|
|
|
|
public void restartSuggestionsOnWordBeforeCursorIfAtEndOfWord() {
|
2013-01-08 07:35:21 +00:00
|
|
|
final CharSequence word =
|
2013-12-18 09:08:35 +00:00
|
|
|
mInputLogic.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-12-19 08:57:10 +00:00
|
|
|
// TODO[IL]: Move this to InputLogic
|
2013-04-10 07:38:37 +00:00
|
|
|
private void restartSuggestionsOnWordBeforeCursor(final String word) {
|
2013-12-18 09:08:35 +00:00
|
|
|
mInputLogic.mWordComposer.setComposingWord(word,
|
2013-12-13 08:09:16 +00:00
|
|
|
// Previous word is the 2nd word before cursor because we are restarting on the
|
|
|
|
// 1st word before cursor.
|
2013-12-19 08:57:10 +00:00
|
|
|
mInputLogic.getNthPreviousWordForSuggestion(mSettings.getCurrent(),
|
|
|
|
2 /* nthPreviousWord */),
|
2013-12-13 08:09:16 +00:00
|
|
|
mKeyboardSwitcher.getKeyboard());
|
2012-04-18 01:34:02 +00:00
|
|
|
final int length = word.length();
|
2013-12-18 09:08:35 +00:00
|
|
|
mInputLogic.mConnection.deleteSurroundingText(length, 0);
|
|
|
|
mInputLogic.mConnection.setComposingText(word, 1);
|
2012-07-06 02:33:16 +00:00
|
|
|
mHandler.postUpdateSuggestionStrip();
|
2011-11-22 02:35:40 +00:00
|
|
|
}
|
|
|
|
|
2013-09-20 09:01:32 +00:00
|
|
|
/**
|
|
|
|
* Retry resetting caches in the rich input connection.
|
|
|
|
*
|
|
|
|
* When the editor can't be accessed we can't reset the caches, so we schedule a retry.
|
|
|
|
* This method handles the retry, and re-schedules a new retry if we still can't access.
|
|
|
|
* We only retry up to 5 times before giving up.
|
|
|
|
*
|
|
|
|
* @param tryResumeSuggestions Whether we should resume suggestions or not.
|
|
|
|
* @param remainingTries How many times we may try again before giving up.
|
|
|
|
*/
|
|
|
|
private void retryResetCaches(final boolean tryResumeSuggestions, final int remainingTries) {
|
2013-12-18 09:08:35 +00:00
|
|
|
if (!mInputLogic.mConnection.resetCachesUponCursorMoveAndReturnSuccess(
|
|
|
|
mInputLogic.mLastSelectionStart, mInputLogic.mLastSelectionEnd, false)) {
|
2013-09-20 09:01:32 +00:00
|
|
|
if (0 < remainingTries) {
|
|
|
|
mHandler.postResetCaches(tryResumeSuggestions, remainingTries - 1);
|
2013-10-07 12:43:05 +00:00
|
|
|
return;
|
2013-09-20 09:01:32 +00:00
|
|
|
}
|
2013-10-07 12:43:05 +00:00
|
|
|
// If remainingTries is 0, we should stop waiting for new tries, but it's still
|
|
|
|
// better to load the keyboard (less things will be broken).
|
2013-09-20 09:01:32 +00:00
|
|
|
}
|
|
|
|
tryFixLyingCursorPosition();
|
2013-10-07 12:43:05 +00:00
|
|
|
mKeyboardSwitcher.loadKeyboard(getCurrentInputEditorInfo(), mSettings.getCurrent());
|
2013-09-20 09:01:32 +00:00
|
|
|
if (tryResumeSuggestions) mHandler.postResumeSuggestions();
|
|
|
|
}
|
|
|
|
|
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-08-13 03:10:26 +00:00
|
|
|
private void hapticAndAudioFeedback(final int code, final int repeatCount) {
|
2013-07-16 03:29:50 +00:00
|
|
|
final MainKeyboardView keyboardView = mKeyboardSwitcher.getMainKeyboardView();
|
2013-12-13 08:09:16 +00:00
|
|
|
if (keyboardView != null && keyboardView.isInDraggingFinger()) {
|
|
|
|
// No need to feedback while finger is dragging.
|
2013-07-16 03:29:50 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-08-13 03:10:26 +00:00
|
|
|
if (repeatCount > 0) {
|
2013-12-18 09:08:35 +00:00
|
|
|
if (code == Constants.CODE_DELETE && !mInputLogic.mConnection.canDeleteCharacters()) {
|
2013-08-13 03:10:26 +00:00
|
|
|
// No need to feedback when repeat delete key will have no effect.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// TODO: Use event time that the last feedback has been generated instead of relying on
|
|
|
|
// a repeat count to thin out feedback.
|
|
|
|
if (repeatCount % PERIOD_FOR_AUDIO_AND_HAPTIC_FEEDBACK_IN_KEY_REPEAT == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
final AudioAndHapticFeedbackManager feedbackManager =
|
|
|
|
AudioAndHapticFeedbackManager.getInstance();
|
|
|
|
if (repeatCount == 0) {
|
|
|
|
// TODO: Reconsider how to perform haptic feedback when repeating key.
|
|
|
|
feedbackManager.performHapticFeedback(keyboardView);
|
2013-07-16 03:29:50 +00:00
|
|
|
}
|
2013-08-13 03:10:26 +00:00
|
|
|
feedbackManager.performAudioFeedback(code);
|
2013-07-16 03:29:50 +00:00
|
|
|
}
|
|
|
|
|
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-08-13 03:10:26 +00:00
|
|
|
public void onPressKey(final int primaryCode, final int repeatCount,
|
2013-07-16 03:29:50 +00:00
|
|
|
final boolean isSinglePointer) {
|
2013-05-14 03:25:21 +00:00
|
|
|
mKeyboardSwitcher.onPressKey(primaryCode, isSinglePointer);
|
2013-08-13 03:10:26 +00:00
|
|
|
hapticAndAudioFeedback(primaryCode, repeatCount);
|
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-08-13 03:10:26 +00:00
|
|
|
// press matching call is {@link #onPressKey(int,int,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;
|
|
|
|
}
|
|
|
|
}
|
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-12-18 09:08:35 +00:00
|
|
|
if (mInputLogic.mEventInterpreter.onHardwareKeyEvent(event)) {
|
2013-01-17 10:27:39 +00:00
|
|
|
final long keyIdentifier = event.getDeviceId() << 32 + event.getKeyCode();
|
2013-12-18 09:08:35 +00:00
|
|
|
mInputLogic.mCurrentlyPressedHardwareKeys.add(keyIdentifier);
|
2013-01-17 10:27:39 +00:00
|
|
|
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();
|
2013-12-18 09:08:35 +00:00
|
|
|
if (mInputLogic.mCurrentlyPressedHardwareKeys.remove(keyIdentifier)) {
|
2013-01-17 10:27:39 +00:00
|
|
|
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.
|
2013-12-19 07:37:07 +00:00
|
|
|
mInputLogic.commitTyped(LastComposedWord.NOT_A_SEPARATOR);
|
2012-07-19 01:00:48 +00:00
|
|
|
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
|
2013-12-13 08:09:16 +00:00
|
|
|
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
|
|
|
|
| Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
2011-01-20 13:52:02 +00:00
|
|
|
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
|
|
|
};
|
2013-12-13 08:09:16 +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
|
2013-12-18 07:53:54 +00:00
|
|
|
/* package for test */ SuggestedWords getSuggestedWords() {
|
|
|
|
// You may not use this method for anything else than debug
|
2013-12-18 09:08:35 +00:00
|
|
|
return DEBUG ? mInputLogic.mSuggestedWords : null;
|
2013-02-26 07:25:30 +00:00
|
|
|
}
|
|
|
|
|
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() {
|
2013-12-18 09:08:35 +00:00
|
|
|
return mInputLogic.mSuggest.isCurrentlyWaitingForMainDictionary();
|
2013-07-29 08:47:13 +00:00
|
|
|
}
|
|
|
|
|
2013-08-15 07:31:29 +00:00
|
|
|
// DO NOT USE THIS for any other purpose than testing. This can break the keyboard badly.
|
|
|
|
@UsedForTesting
|
|
|
|
/* package for test */ void replaceMainDictionaryForTest(final Locale locale) {
|
2013-12-18 09:08:35 +00:00
|
|
|
mInputLogic.mSuggest.resetMainDict(this, locale, null);
|
2013-08-15 07:31:29 +00:00
|
|
|
}
|
|
|
|
|
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 :");
|
2013-12-13 08:09:16 +00:00
|
|
|
p.println(" VersionCode = " + ApplicationUtils.getVersionCode(this));
|
|
|
|
p.println(" VersionName = " + ApplicationUtils.getVersionName(this));
|
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();
|
2013-12-13 08:09:16 +00:00
|
|
|
p.println(" mIsSuggestionsRequested = "
|
2013-01-08 07:35:21 +00:00
|
|
|
+ settingsValues.isSuggestionsRequested(mDisplayOrientation));
|
|
|
|
p.println(" mCorrectionEnabled=" + settingsValues.mCorrectionEnabled);
|
2013-12-18 09:08:35 +00:00
|
|
|
p.println(" isComposingWord=" + mInputLogic.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
|
|
|
}
|
|
|
|
}
|