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;
|
|
|
|
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-02-18 01:46:01 +00:00
|
|
|
import android.os.IBinder;
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.os.Message;
|
|
|
|
import android.os.SystemClock;
|
|
|
|
import android.preference.PreferenceManager;
|
2010-12-10 06:24:28 +00:00
|
|
|
import android.text.InputType;
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.util.Log;
|
|
|
|
import android.util.PrintWriterPrinter;
|
|
|
|
import android.util.Printer;
|
2012-05-25 10:56:45 +00:00
|
|
|
import android.view.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;
|
|
|
|
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;
|
2012-08-02 04:25:17 +00:00
|
|
|
import com.android.inputmethod.compat.InputMethodServiceCompatUtils;
|
2013-03-19 07:45:25 +00:00
|
|
|
import com.android.inputmethod.dictionarypack.DictionaryPackConstants;
|
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-10-02 09:06:08 +00:00
|
|
|
import com.android.inputmethod.latin.personalization.DictionaryDecayBroadcastReciever;
|
2013-12-25 02:44:16 +00:00
|
|
|
import com.android.inputmethod.latin.personalization.PersonalizationDictionarySessionRegistrar;
|
|
|
|
import com.android.inputmethod.latin.personalization.PersonalizationHelper;
|
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;
|
2014-01-24 14:11:48 +00:00
|
|
|
import com.android.inputmethod.latin.suggestions.SuggestionStripViewAccessor;
|
2013-07-05 09:23:22 +00:00
|
|
|
import com.android.inputmethod.latin.utils.ApplicationUtils;
|
2013-06-23 16:11:32 +00:00
|
|
|
import com.android.inputmethod.latin.utils.CapsModeUtils;
|
|
|
|
import com.android.inputmethod.latin.utils.CompletionInfoUtils;
|
2013-12-27 11:58:32 +00:00
|
|
|
import com.android.inputmethod.latin.utils.CoordinateUtils;
|
2014-02-03 05:03:58 +00:00
|
|
|
import com.android.inputmethod.latin.utils.ImportantNoticeUtils;
|
2013-06-23 16:11:32 +00:00
|
|
|
import com.android.inputmethod.latin.utils.IntentUtils;
|
2013-06-24 06:26:29 +00:00
|
|
|
import com.android.inputmethod.latin.utils.JniUtils;
|
2013-12-13 08:09:16 +00:00
|
|
|
import com.android.inputmethod.latin.utils.LeakGuardHandlerWrapper;
|
2014-01-27 10:04:40 +00:00
|
|
|
import com.android.inputmethod.latin.utils.SubtypeLocaleUtils;
|
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;
|
2014-01-08 09:59:43 +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,
|
2014-01-24 14:11:48 +00:00
|
|
|
SuggestionStripView.Listener, SuggestionStripViewAccessor,
|
2013-12-27 05:49:32 +00:00
|
|
|
DictionaryFacilitatorForSuggest.DictionaryInitializationListener {
|
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 13:18:46 +00:00
|
|
|
private static boolean DEBUG = false;
|
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;
|
|
|
|
|
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;
|
2014-01-24 14:17:40 +00:00
|
|
|
private final InputLogic mInputLogic = new InputLogic(this /* LatinIME */,
|
|
|
|
this /* SuggestionStripViewAccessor */);
|
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
|
|
|
|
2014-01-29 07:15:12 +00:00
|
|
|
// TODO[IL]: remove this member completely.
|
|
|
|
public CompletionInfo[] mApplicationSpecifiedCompletions;
|
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
|
|
|
|
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
|
|
|
|
2014-02-04 12:29:09 +00:00
|
|
|
private BroadcastReceiver mDictionaryDumpBroadcastReceiver =
|
|
|
|
new DictionaryDumpBroadcastReceiver(this);
|
|
|
|
|
2012-04-02 13:25:08 +00:00
|
|
|
private AlertDialog mOptionsDialog;
|
|
|
|
|
2012-08-02 04:25:17 +00:00
|
|
|
private final boolean mIsHardwareAcceleratedDrawingEnabled;
|
|
|
|
|
2011-06-24 18:54:11 +00:00
|
|
|
public final UIHandler mHandler = new UIHandler(this);
|
2010-11-16 09:07:06 +00:00
|
|
|
|
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;
|
2014-01-24 13:42:40 +00:00
|
|
|
private static final int ARG2_UNUSED = 0;
|
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:
|
2013-12-19 13:08:31 +00:00
|
|
|
latinIme.mInputLogic.performUpdateSuggestionStripSync(
|
2013-12-25 12:04:27 +00:00
|
|
|
latinIme.mSettings.getCurrent(), this /* handler */);
|
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) {
|
2014-01-24 13:42:40 +00:00
|
|
|
final SuggestedWords suggestedWords = (SuggestedWords) msg.obj;
|
2014-01-24 13:45:20 +00:00
|
|
|
latinIme.showSuggestionStrip(suggestedWords);
|
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:
|
2013-12-20 09:05:35 +00:00
|
|
|
latinIme.mInputLogic.restartSuggestionsOnWordTouchedByCursor(
|
2014-01-10 11:18:24 +00:00
|
|
|
latinIme.mSettings.getCurrent(),
|
2013-12-27 12:00:28 +00:00
|
|
|
false /* includeResumedWordInSuggestions */);
|
2013-04-10 07:38:37 +00:00
|
|
|
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:
|
2013-12-26 10:13:43 +00:00
|
|
|
latinIme.mInputLogic.endBatchInputInternal(latinIme.mSettings.getCurrent(),
|
2013-12-25 11:08:52 +00:00
|
|
|
(SuggestedWords) msg.obj, latinIme.mKeyboardSwitcher);
|
2013-09-02 07:49:32 +00:00
|
|
|
break;
|
2013-09-20 09:01:32 +00:00
|
|
|
case MSG_RESET_CACHES:
|
2013-12-27 08:04:12 +00:00
|
|
|
final SettingsValues settingsValues = latinIme.mSettings.getCurrent();
|
|
|
|
if (latinIme.mInputLogic.retryResetCachesAndReturnSuccess(settingsValues,
|
2013-12-20 11:07:16 +00:00
|
|
|
msg.arg1 == 1 /* tryResumeSuggestions */,
|
2013-12-27 08:04:12 +00:00
|
|
|
msg.arg2 /* remainingTries */, this /* handler */)) {
|
|
|
|
// If we were able to reset the caches, then we can reload the keyboard.
|
|
|
|
// Otherwise, we'll do it when we can.
|
|
|
|
latinIme.mKeyboardSwitcher.loadKeyboard(latinIme.getCurrentInputEditorInfo(),
|
|
|
|
settingsValues);
|
|
|
|
}
|
2013-09-20 09:01:32 +00:00
|
|
|
break;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
}
|
2010-11-16 09:07:06 +00:00
|
|
|
|
2012-07-06 02:33:16 +00:00
|
|
|
public void postUpdateSuggestionStrip() {
|
2012-07-06 03:15:45 +00:00
|
|
|
sendMessageDelayed(obtainMessage(MSG_UPDATE_SUGGESTION_STRIP), mDelayUpdateSuggestions);
|
2010-11-16 09:07:06 +00:00
|
|
|
}
|
|
|
|
|
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-12-25 12:48:48 +00:00
|
|
|
if (!getOwnerInstance().mSettings.getCurrent().isSuggestionStripVisible()) {
|
|
|
|
return;
|
|
|
|
}
|
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,
|
2014-01-24 13:42:40 +00:00
|
|
|
ARG2_UNUSED, 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,
|
2014-01-24 13:42:40 +00:00
|
|
|
ARG1_NOT_GESTURE_INPUT, ARG2_UNUSED, suggestedWords).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);
|
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-26 11:28:37 +00:00
|
|
|
ResearchLogger.getInstance().init(this, mKeyboardSwitcher);
|
2013-01-24 19:12:58 +00:00
|
|
|
}
|
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
|
|
|
|
2014-02-04 12:29:09 +00:00
|
|
|
final IntentFilter dictDumpFilter = new IntentFilter();
|
|
|
|
dictDumpFilter.addAction(DictionaryDumpBroadcastReceiver.DICTIONARY_DUMP_INTENT_ACTION);
|
|
|
|
registerReceiver(mDictionaryDumpBroadcastReceiver, dictDumpFilter);
|
|
|
|
|
2013-10-02 09:06:08 +00:00
|
|
|
DictionaryDecayBroadcastReciever.setUpIntervalAlarmForDictionaryDecaying(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();
|
2013-12-20 06:00:44 +00:00
|
|
|
final EditorInfo editorInfo = getCurrentInputEditorInfo();
|
|
|
|
final InputAttributes inputAttributes = new InputAttributes(editorInfo, isFullscreenMode());
|
|
|
|
mSettings.loadSettings(this, 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-25 02:44:16 +00:00
|
|
|
final SettingsValues currentSettingsValues = mSettings.getCurrent();
|
2013-12-27 05:49:32 +00:00
|
|
|
final Suggest suggest = mInputLogic.mSuggest;
|
|
|
|
if (!mHandler.hasPendingReopenDictionaries() && suggest != null) {
|
2013-12-17 10:36:19 +00:00
|
|
|
// May need to reset dictionaries depending on the user settings.
|
2013-12-27 05:49:32 +00:00
|
|
|
final DictionaryFacilitatorForSuggest oldDictionaryFacilitator =
|
|
|
|
suggest.mDictionaryFacilitator;
|
|
|
|
final DictionaryFacilitatorForSuggest dictionaryFacilitator =
|
|
|
|
new DictionaryFacilitatorForSuggest(currentSettingsValues,
|
|
|
|
oldDictionaryFacilitator);
|
|
|
|
// Create Suggest instance with the new dictionary facilitator.
|
2014-01-08 09:59:43 +00:00
|
|
|
resetSuggest(new Suggest(suggest /* oldSuggest */, dictionaryFacilitator));
|
|
|
|
} else if (suggest == null) {
|
|
|
|
initSuggestForLocale(locale);
|
2013-12-25 02:44:16 +00:00
|
|
|
}
|
2014-01-08 09:59:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void refreshPersonalizationDictionarySession() {
|
|
|
|
if (mSettings.getCurrent().mUsePersonalizedDicts) {
|
2014-01-07 09:10:27 +00:00
|
|
|
if (mSubtypeSwitcher.isSystemLocaleSameAsLocaleOfAllEnabledSubtypes()) {
|
2014-01-08 03:43:58 +00:00
|
|
|
final DictionaryFacilitatorForSuggest dictionaryFacilitator =
|
|
|
|
(mInputLogic.mSuggest == null) ?
|
|
|
|
null : mInputLogic.mSuggest.mDictionaryFacilitator;
|
|
|
|
PersonalizationDictionarySessionRegistrar.init(this, dictionaryFacilitator);
|
2014-01-07 09:10:27 +00:00
|
|
|
} else {
|
|
|
|
PersonalizationDictionarySessionRegistrar.close(this);
|
|
|
|
}
|
2013-12-25 02:44:16 +00:00
|
|
|
} else {
|
|
|
|
PersonalizationHelper.removeAllPersonalizedDictionaries(this);
|
|
|
|
PersonalizationDictionarySessionRegistrar.resetAll(this);
|
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-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;
|
|
|
|
}
|
2014-01-08 09:59:43 +00:00
|
|
|
initSuggestForLocale(subtypeLocale);
|
|
|
|
}
|
2009-10-12 20:48:35 +00:00
|
|
|
|
2014-01-08 09:59:43 +00:00
|
|
|
private void initSuggestForLocale(final Locale locale) {
|
2013-07-30 03:54:33 +00:00
|
|
|
final SettingsValues settingsValues = mSettings.getCurrent();
|
2013-12-27 05:49:32 +00:00
|
|
|
final DictionaryFacilitatorForSuggest oldDictionaryFacilitator =
|
|
|
|
(mInputLogic.mSuggest == null) ? null : mInputLogic.mSuggest.mDictionaryFacilitator;
|
|
|
|
// Creates new dictionary facilitator for the new locale.
|
|
|
|
final DictionaryFacilitatorForSuggest dictionaryFacilitator =
|
2014-01-08 09:59:43 +00:00
|
|
|
new DictionaryFacilitatorForSuggest(this /* context */, locale,
|
2013-12-27 05:49:32 +00:00
|
|
|
settingsValues, this /* DictionaryInitializationListener */,
|
|
|
|
oldDictionaryFacilitator);
|
2014-01-08 09:59:43 +00:00
|
|
|
final Suggest newSuggest = new Suggest(locale, dictionaryFacilitator);
|
2013-07-30 03:54:33 +00:00
|
|
|
if (settingsValues.mCorrectionEnabled) {
|
2013-07-30 05:44:09 +00:00
|
|
|
newSuggest.setAutoCorrectionThreshold(settingsValues.mAutoCorrectionThreshold);
|
2012-04-11 05:58:02 +00:00
|
|
|
}
|
2014-01-08 09:59:43 +00:00
|
|
|
resetSuggest(newSuggest);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* package private */ void resetSuggestMainDict() {
|
|
|
|
final DictionaryFacilitatorForSuggest oldDictionaryFacilitator =
|
|
|
|
mInputLogic.mSuggest.mDictionaryFacilitator;
|
|
|
|
final DictionaryFacilitatorForSuggest dictionaryFacilitator =
|
|
|
|
new DictionaryFacilitatorForSuggest(this /* listener */, oldDictionaryFacilitator);
|
|
|
|
resetSuggest(new Suggest(mInputLogic.mSuggest /* oldSuggest */, dictionaryFacilitator));
|
|
|
|
}
|
|
|
|
|
|
|
|
private void resetSuggest(final Suggest newSuggest) {
|
2013-03-18 09:21:18 +00:00
|
|
|
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
|
2013-12-26 11:28:37 +00:00
|
|
|
ResearchLogger.getInstance().initDictionary(newSuggest.mDictionaryFacilitator);
|
2012-06-16 00:49:42 +00:00
|
|
|
}
|
2013-12-18 09:08:35 +00:00
|
|
|
final Suggest oldSuggest = mInputLogic.mSuggest;
|
|
|
|
mInputLogic.mSuggest = newSuggest;
|
2013-07-30 05:44:09 +00:00
|
|
|
if (oldSuggest != null) oldSuggest.close();
|
2014-01-08 09:59:43 +00:00
|
|
|
refreshPersonalizationDictionarySession();
|
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);
|
2014-02-06 06:37:41 +00:00
|
|
|
unregisterReceiver(mDictionaryDumpBroadcastReceiver);
|
2014-01-07 09:10:27 +00:00
|
|
|
PersonalizationDictionarySessionRegistrar.close(this);
|
2010-08-20 05:35:02 +00:00
|
|
|
LatinImeLogger.commit();
|
|
|
|
LatinImeLogger.onDestroy();
|
2009-03-13 22:11:42 +00:00
|
|
|
super.onDestroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-09-12 04:03:44 +00:00
|
|
|
public void onConfigurationChanged(final Configuration conf) {
|
2009-07-21 22:47:11 +00:00
|
|
|
// If orientation changed while predicting, commit the change
|
2013-12-20 07:34:38 +00:00
|
|
|
final SettingsValues settingsValues = mSettings.getCurrent();
|
|
|
|
if (settingsValues.mDisplayOrientation != conf.orientation) {
|
2011-08-23 05:58:45 +00:00
|
|
|
mHandler.startOrientationChanging();
|
2013-12-18 09:08:35 +00:00
|
|
|
mInputLogic.mConnection.beginBatchEdit();
|
2013-12-19 12:53:08 +00:00
|
|
|
mInputLogic.commitTyped(mSettings.getCurrent(), 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
|
|
|
}
|
2014-01-07 07:24:29 +00:00
|
|
|
PersonalizationDictionarySessionRegistrar.onConfigurationChanged(this, conf,
|
|
|
|
mInputLogic.mSuggest.mDictionaryFacilitator);
|
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");
|
|
|
|
}
|
|
|
|
|
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-25 12:03:24 +00:00
|
|
|
mInputLogic.startInput(restarting, editorInfo);
|
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.
|
2014-01-24 09:36:18 +00:00
|
|
|
setNeutralSuggestionStrip();
|
2011-11-15 17:11:11 +00:00
|
|
|
}
|
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-12-25 12:03:24 +00:00
|
|
|
// TODO[IL]: Can the following be moved to InputLogic#startInput?
|
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
|
|
|
|
2013-12-20 07:34:38 +00:00
|
|
|
if (isDifferentTextField ||
|
|
|
|
!currentSettingsValues.hasSameOrientation(getResources().getConfiguration())) {
|
|
|
|
loadSettings();
|
|
|
|
}
|
2012-08-15 08:57:38 +00:00
|
|
|
if (isDifferentTextField) {
|
2012-08-07 02:48:10 +00:00
|
|
|
mainKeyboardView.closing();
|
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
|
|
|
|
|
|
|
mHandler.cancelUpdateSuggestionStrip();
|
2012-12-05 03:35:41 +00:00
|
|
|
mHandler.cancelDoubleSpacePeriodTimer();
|
2011-01-18 06:28:21 +00:00
|
|
|
|
2013-12-19 12:53:08 +00:00
|
|
|
mainKeyboardView.setMainDictionaryAvailability(null != suggest
|
2013-12-26 11:28:37 +00:00
|
|
|
? suggest.mDictionaryFacilitator.hasMainDictionary() : false);
|
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
|
|
|
|
|
|
|
if (TRACE) Debug.startMethodTracing("/data/trace/latinime");
|
|
|
|
}
|
|
|
|
|
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-25 12:03:24 +00:00
|
|
|
mInputLogic.finishInput();
|
2013-03-20 18:28:31 +00:00
|
|
|
// Notify ResearchLogger
|
2013-03-18 09:21:18 +00:00
|
|
|
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
|
2014-01-15 01:23:54 +00:00
|
|
|
ResearchLogger.latinIME_onFinishInputViewInternal(finishingInput);
|
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
|
|
|
|
+ ", 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) {
|
2014-01-09 05:09:26 +00:00
|
|
|
ResearchLogger.latinIME_onUpdateSelection(oldSelStart, oldSelEnd,
|
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
|
|
|
|
2014-01-24 05:03:08 +00:00
|
|
|
// If the keyboard is not visible, we don't need to do all the housekeeping work, as it
|
|
|
|
// will be reset when the keyboard shows up anyway.
|
|
|
|
// TODO: revisit this when LatinIME supports hardware keyboards.
|
|
|
|
// NOTE: the test harness subclasses LatinIME and overrides isInputViewShown().
|
|
|
|
// TODO: find a better way to simulate actual execution.
|
|
|
|
if (isInputViewShown() &&
|
|
|
|
mInputLogic.onUpdateSelection(mSettings.getCurrent(), oldSelStart, oldSelEnd,
|
|
|
|
newSelStart, newSelEnd, composingSpanStart, composingSpanEnd)) {
|
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
|
|
|
|
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-12-20 07:34:38 +00:00
|
|
|
if (mSettings.getCurrent().isSuggestionsRequested()) {
|
|
|
|
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-12-20 07:34:38 +00:00
|
|
|
if (mSettings.getCurrent().isSuggestionsRequested()) {
|
|
|
|
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) {
|
2014-01-24 09:39:05 +00:00
|
|
|
setNeutralSuggestionStrip();
|
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(
|
2014-02-06 06:51:04 +00:00
|
|
|
applicationSuggestedWords, null /* rawSuggestions */,
|
2012-06-12 00:35:51 +00:00
|
|
|
false /* typedWordValid */,
|
2014-01-24 09:18:32 +00:00
|
|
|
false /* willAutoCorrect */,
|
2012-06-12 00:35:51 +00:00
|
|
|
false /* isPunctuationSuggestions */,
|
|
|
|
false /* isObsoleteSuggestions */,
|
|
|
|
false /* isPrediction */);
|
|
|
|
// When in fullscreen mode, show completions generated by the application
|
2014-01-24 12:30:25 +00:00
|
|
|
setSuggestedWords(suggestedWords, true /* shouldShow */);
|
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
|
2014-01-24 12:47:17 +00:00
|
|
|
if (!onEvaluateInputViewShown() || null == mSuggestionStripView) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
final boolean inputViewShown = mKeyboardSwitcher.isShowingMainKeyboardOrEmojiPalettes();
|
|
|
|
final boolean shouldShowSuggestions = shown
|
|
|
|
&& (needsInputViewShown ? inputViewShown : true);
|
|
|
|
if (shouldShowSuggestions) {
|
|
|
|
mSuggestionStripView.setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
mSuggestionStripView.setVisibility(isFullscreenMode() ? View.GONE : View.INVISIBLE);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
}
|
2010-01-28 18:09:44 +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() {
|
2013-12-24 12:55:09 +00:00
|
|
|
// Reread resource value here, because this method is called by the framework 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 11:36:32 +00:00
|
|
|
// TODO[IL]: Remove this, pass the input logic to the keyboard switcher instead?
|
2012-05-18 07:45:26 +00:00
|
|
|
public int getCurrentAutoCapsState() {
|
2014-01-24 05:00:26 +00:00
|
|
|
return mInputLogic.getCurrentAutoCapsState(mSettings.getCurrent());
|
2010-01-24 15:34:07 +00:00
|
|
|
}
|
|
|
|
|
2013-12-19 11:36:32 +00:00
|
|
|
// Called from the KeyboardSwitcher which needs to know recaps state to display
|
|
|
|
// the right layout.
|
|
|
|
// TODO[IL]: Remove this, pass the input logic to the keyboard switcher instead?
|
2013-04-15 13:00:29 +00:00
|
|
|
public int getCurrentRecapitalizeState() {
|
2013-12-19 11:36:32 +00:00
|
|
|
return mInputLogic.getCurrentRecapitalizeState();
|
2013-04-15 13:00:29 +00:00
|
|
|
}
|
|
|
|
|
2013-12-20 10:05:33 +00:00
|
|
|
public Locale getCurrentSubtypeLocale() {
|
|
|
|
return mSubtypeSwitcher.getCurrentSubtypeLocale();
|
|
|
|
}
|
|
|
|
|
2013-12-27 11:58:32 +00:00
|
|
|
/**
|
|
|
|
* @param codePoints code points to get coordinates for.
|
|
|
|
* @return x,y coordinates for this keyboard, as a flattened array.
|
|
|
|
*/
|
|
|
|
public int[] getCoordinatesForCurrentKeyboard(final int[] codePoints) {
|
2014-01-23 07:10:26 +00:00
|
|
|
final Keyboard keyboard = mKeyboardSwitcher.getKeyboard();
|
|
|
|
if (null == keyboard) {
|
|
|
|
return CoordinateUtils.newCoordinateArray(codePoints.length,
|
|
|
|
Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE);
|
|
|
|
} else {
|
|
|
|
return keyboard.getCoordinates(codePoints);
|
2013-12-27 11:58:32 +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-12-20 10:05:33 +00:00
|
|
|
wordToEdit = word.toLowerCase(getCurrentSubtypeLocale());
|
2013-01-16 13:07:43 +00:00
|
|
|
} else {
|
|
|
|
wordToEdit = word;
|
|
|
|
}
|
2013-12-26 11:28:37 +00:00
|
|
|
mInputLogic.mSuggest.mDictionaryFacilitator.addWordToUserDictionary(wordToEdit);
|
2012-12-13 12:59:13 +00:00
|
|
|
}
|
|
|
|
|
2014-02-03 05:03:58 +00:00
|
|
|
// TODO: Move this method out of {@link LatinIME}.
|
2014-01-28 07:19:29 +00:00
|
|
|
// Callback for the {@link SuggestionStripView}, to call when the important notice strip is
|
|
|
|
// pressed.
|
|
|
|
@Override
|
|
|
|
public void showImportantNoticeContents() {
|
2014-02-03 05:03:58 +00:00
|
|
|
final Context context = this;
|
|
|
|
final DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(final DialogInterface di, final int position) {
|
|
|
|
di.dismiss();
|
|
|
|
ImportantNoticeUtils.updateLastImportantNoticeVersion(context);
|
2014-02-03 09:26:52 +00:00
|
|
|
setNeutralSuggestionStrip();
|
2014-02-03 05:03:58 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
final AlertDialog.Builder builder =
|
|
|
|
new AlertDialog.Builder(context, AlertDialog.THEME_HOLO_DARK);
|
|
|
|
builder.setMessage(R.string.important_notice_contents)
|
|
|
|
.setPositiveButton(android.R.string.ok, listener);
|
2014-02-12 02:59:43 +00:00
|
|
|
showOptionDialog(builder.create(), true /* cancelable */);
|
2014-01-28 07:19:29 +00:00
|
|
|
}
|
|
|
|
|
2013-12-19 11:56:37 +00:00
|
|
|
public void displaySettingsDialog() {
|
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 11:36:32 +00:00
|
|
|
public void switchToNextSubtype() {
|
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
|
2013-12-27 07:38:13 +00:00
|
|
|
public void onCodeInput(final int codePoint, final int x, final int y) {
|
|
|
|
final MainKeyboardView mainKeyboardView = mKeyboardSwitcher.getMainKeyboardView();
|
|
|
|
// x and y include some padding, but everything down the line (especially native
|
|
|
|
// code) needs the coordinates in the keyboard frame.
|
|
|
|
// TODO: We should reconsider which coordinate system should be used to represent
|
|
|
|
// keyboard event. Also we should pull this up -- LatinIME has no business doing
|
|
|
|
// this transformation, it should be done already before calling onCodeInput.
|
2013-12-27 07:43:07 +00:00
|
|
|
final int keyX = mainKeyboardView.getKeyX(x);
|
|
|
|
final int keyY = mainKeyboardView.getKeyY(y);
|
2013-12-27 10:06:45 +00:00
|
|
|
final int codeToSend;
|
|
|
|
if (Constants.CODE_SHIFT == codePoint) {
|
|
|
|
// TODO: Instead of checking for alphabetic keyboard here, separate keycodes for
|
|
|
|
// alphabetic shift and shift while in symbol layout.
|
|
|
|
final Keyboard currentKeyboard = mKeyboardSwitcher.getKeyboard();
|
|
|
|
if (null != currentKeyboard && currentKeyboard.mId.isAlphabetKeyboard()) {
|
|
|
|
codeToSend = codePoint;
|
|
|
|
} else {
|
|
|
|
codeToSend = Constants.CODE_SYMBOL_SHIFT;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
codeToSend = codePoint;
|
|
|
|
}
|
2014-01-15 02:27:27 +00:00
|
|
|
if (Constants.CODE_SHORTCUT == codePoint) {
|
|
|
|
mSubtypeSwitcher.switchToShortcutIME(this);
|
|
|
|
// Still call the *#onCodeInput methods for readability.
|
|
|
|
}
|
2014-01-24 05:00:26 +00:00
|
|
|
mInputLogic.onCodeInput(codeToSend, keyX, keyY, mSettings.getCurrent(),
|
2014-01-24 02:38:07 +00:00
|
|
|
mHandler, mKeyboardSwitcher);
|
2013-12-27 08:04:12 +00:00
|
|
|
mKeyboardSwitcher.onCodeInput(codePoint);
|
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
|
|
|
|
@Override
|
|
|
|
public void onTextInput(final String rawText) {
|
2013-12-25 12:04:27 +00:00
|
|
|
mInputLogic.onTextInput(mSettings.getCurrent(), rawText, mHandler);
|
2013-12-20 12:51:13 +00:00
|
|
|
mKeyboardSwitcher.updateShiftState();
|
|
|
|
mKeyboardSwitcher.onCodeInput(Constants.CODE_OUTPUT_TEXT);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2012-07-04 06:24:59 +00:00
|
|
|
@Override
|
|
|
|
public void onStartBatchInput() {
|
2013-12-25 12:04:27 +00:00
|
|
|
mInputLogic.onStartBatchInput(mSettings.getCurrent(), mKeyboardSwitcher, mHandler);
|
2013-12-20 11:45:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onUpdateBatchInput(final InputPointers batchPointers) {
|
2013-12-25 12:04:27 +00:00
|
|
|
mInputLogic.onUpdateBatchInput(mSettings.getCurrent(), batchPointers, mKeyboardSwitcher);
|
2013-12-20 11:45:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onEndBatchInput(final InputPointers batchPointers) {
|
2013-12-25 12:04:27 +00:00
|
|
|
mInputLogic.onEndBatchInput(mSettings.getCurrent(), batchPointers);
|
2013-12-20 11:45:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCancelBatchInput() {
|
2013-12-25 12:04:27 +00:00
|
|
|
mInputLogic.onCancelBatchInput(mHandler);
|
2012-09-12 04:03:44 +00:00
|
|
|
}
|
|
|
|
|
2013-12-24 09:07:20 +00:00
|
|
|
// This method must run on the UI Thread.
|
2012-09-12 04:03:44 +00:00
|
|
|
private void showGesturePreviewAndSuggestionStrip(final SuggestedWords suggestedWords,
|
|
|
|
final boolean dismissGestureFloatingPreviewText) {
|
2014-01-24 13:45:20 +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-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
|
|
|
}
|
|
|
|
|
2014-01-29 07:15:12 +00:00
|
|
|
// TODO: remove this, read this directly from mInputLogic or something in the tests
|
|
|
|
@UsedForTesting
|
2013-12-19 08:14:11 +00:00
|
|
|
public boolean isShowingPunctuationList() {
|
2014-01-29 07:15:12 +00:00
|
|
|
return mInputLogic.isShowingPunctuationList(mSettings.getCurrent());
|
2010-11-13 10:09:30 +00:00
|
|
|
}
|
|
|
|
|
2013-12-20 09:05:35 +00:00
|
|
|
// TODO[IL]: Define a clear interface for this
|
|
|
|
public 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-12-20 07:34:38 +00:00
|
|
|
if (!currentSettings.isSuggestionStripVisible())
|
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-12-20 07:34:38 +00:00
|
|
|
return currentSettings.isSuggestionsRequested();
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2014-01-24 14:11:48 +00:00
|
|
|
@Override
|
|
|
|
public boolean hasSuggestionStripView() {
|
|
|
|
return null != mSuggestionStripView;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isShowingAddToDictionaryHint() {
|
|
|
|
return hasSuggestionStripView() && mSuggestionStripView.isShowingAddToDictionaryHint();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
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
|
2014-01-24 12:57:34 +00:00
|
|
|
public void setSuggestedWords(final SuggestedWords suggestedWords, final boolean shouldShow) {
|
|
|
|
mInputLogic.setSuggestedWords(suggestedWords);
|
2014-01-24 12:50:46 +00:00
|
|
|
if (mSuggestionStripView != null) {
|
2014-02-03 02:49:34 +00:00
|
|
|
final boolean showSuggestions;
|
|
|
|
if (SuggestedWords.EMPTY == suggestedWords
|
|
|
|
|| suggestedWords.mIsPunctuationSuggestions) {
|
|
|
|
showSuggestions = !mSuggestionStripView.maybeShowImportantNoticeTitle();
|
|
|
|
} else {
|
|
|
|
showSuggestions = true;
|
|
|
|
}
|
|
|
|
if (showSuggestions) {
|
|
|
|
mSuggestionStripView.setSuggestions(suggestedWords,
|
|
|
|
SubtypeLocaleUtils.isRtlLanguage(mSubtypeSwitcher.getCurrentSubtype()));
|
|
|
|
}
|
2014-01-24 12:57:34 +00:00
|
|
|
mKeyboardSwitcher.onAutoCorrectionStateChanged(suggestedWords.mWillAutoCorrect);
|
2014-01-24 12:50:46 +00:00
|
|
|
setSuggestionStripShownInternal(shouldShow, true /* needsInputViewShown */);
|
|
|
|
}
|
2010-01-16 20:21:23 +00:00
|
|
|
}
|
|
|
|
|
2013-12-25 12:04:27 +00:00
|
|
|
// TODO[IL]: Move this out of LatinIME.
|
|
|
|
public 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.
|
2014-01-09 09:36:23 +00:00
|
|
|
final CharSequence rereadPrevWord = mInputLogic.getNthPreviousWordForSuggestion(
|
2014-01-09 08:27:33 +00:00
|
|
|
currentSettings.mSpacingAndPunctuations,
|
|
|
|
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-12-24 13:52:34 +00:00
|
|
|
// TODO[IL]: Move this to InputLogic
|
|
|
|
public SuggestedWords maybeRetrieveOlderSuggestions(final String typedWord,
|
2014-01-20 03:06:44 +00:00
|
|
|
final SuggestedWords suggestedWords, final SuggestedWords previousSuggestedWords) {
|
2012-07-06 07:14:52 +00:00
|
|
|
// 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
|
2013-12-24 13:41:17 +00:00
|
|
|
// replaced with the new one. However, 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.
|
2012-07-06 07:20:04 +00:00
|
|
|
if (suggestedWords.size() > 1 || typedWord.length() <= 1
|
2014-01-24 14:11:48 +00:00
|
|
|
|| null == mSuggestionStripView || isShowingAddToDictionaryHint()) {
|
2012-06-29 06:54:51 +00:00
|
|
|
return suggestedWords;
|
2012-03-09 06:52:23 +00:00
|
|
|
} else {
|
2014-01-20 03:06:44 +00:00
|
|
|
final SuggestedWords punctuationList =
|
|
|
|
mSettings.getCurrent().mSpacingAndPunctuations.mSuggestPuncList;
|
|
|
|
final SuggestedWords oldSuggestedWords = previousSuggestedWords == punctuationList
|
2014-01-27 07:08:27 +00:00
|
|
|
? SuggestedWords.EMPTY : previousSuggestedWords;
|
2014-01-20 03:06:44 +00:00
|
|
|
final ArrayList<SuggestedWords.SuggestedWordInfo> typedWordAndPreviousSuggestions =
|
|
|
|
SuggestedWords.getTypedWordAndPreviousSuggestions(typedWord, oldSuggestedWords);
|
2014-02-06 06:51:04 +00:00
|
|
|
return new SuggestedWords(typedWordAndPreviousSuggestions, null /* rawSuggestions */,
|
2014-01-20 03:06:44 +00:00
|
|
|
false /* typedWordValid */,
|
|
|
|
false /* hasAutoCorrectionCandidate */,
|
|
|
|
false /* isPunctuationSuggestions */,
|
|
|
|
true /* isObsoleteSuggestions */,
|
|
|
|
false /* isPrediction */);
|
2012-12-17 06:11:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-24 14:11:48 +00:00
|
|
|
@Override
|
2014-01-24 13:45:20 +00:00
|
|
|
public void showSuggestionStrip(final SuggestedWords sourceSuggestedWords) {
|
2014-01-24 11:56:16 +00:00
|
|
|
final SuggestedWords suggestedWords =
|
|
|
|
sourceSuggestedWords.isEmpty() ? SuggestedWords.EMPTY : sourceSuggestedWords;
|
2014-01-27 07:08:27 +00:00
|
|
|
final String autoCorrection;
|
|
|
|
if (suggestedWords.mWillAutoCorrect) {
|
|
|
|
autoCorrection = suggestedWords.getWord(SuggestedWords.INDEX_OF_AUTO_CORRECTION);
|
|
|
|
} else {
|
|
|
|
// We can't use suggestedWords.getWord(SuggestedWords.INDEX_OF_TYPED_WORD)
|
|
|
|
// because it may differ from mWordComposer.mTypedWord.
|
2014-01-24 13:45:20 +00:00
|
|
|
autoCorrection = sourceSuggestedWords.mTypedWord;
|
2014-01-27 07:08:27 +00:00
|
|
|
}
|
2014-02-03 06:03:41 +00:00
|
|
|
if (SuggestedWords.EMPTY == suggestedWords) {
|
|
|
|
setNeutralSuggestionStrip();
|
|
|
|
} else {
|
2014-01-24 12:01:05 +00:00
|
|
|
mInputLogic.mWordComposer.setAutoCorrection(autoCorrection);
|
2014-02-03 06:03:41 +00:00
|
|
|
setSuggestedWords(suggestedWords, isSuggestionsStripVisible());
|
2014-01-24 11:57:48 +00:00
|
|
|
}
|
|
|
|
// Cache the auto-correction in accessibility code so we can speak it if the user
|
|
|
|
// touches a key that will insert it.
|
2014-01-24 13:45:20 +00:00
|
|
|
AccessibilityUtils.getInstance().setAutoCorrection(suggestedWords,
|
|
|
|
sourceSuggestedWords.mTypedWord);
|
2013-09-19 11:31:15 +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) {
|
2014-01-29 07:15:12 +00:00
|
|
|
mInputLogic.onPickSuggestionManually(mSettings.getCurrent(), index, suggestionInfo,
|
|
|
|
mHandler, mKeyboardSwitcher);
|
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
|
2014-01-29 07:15:12 +00:00
|
|
|
@Override
|
|
|
|
public void showAddToDictionaryHint(final String word) {
|
|
|
|
if (null == mSuggestionStripView) return;
|
|
|
|
mSuggestionStripView.showAddToDictionaryHint(word);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2013-12-19 08:14:11 +00:00
|
|
|
// TODO[IL]: Define a clean interface for this
|
2014-01-24 09:36:18 +00:00
|
|
|
// This will show either an empty suggestion strip (if prediction is enabled) or
|
|
|
|
// punctuation suggestions (if it's disabled).
|
2014-01-24 14:11:48 +00:00
|
|
|
@Override
|
2014-01-24 09:36:18 +00:00
|
|
|
public void setNeutralSuggestionStrip() {
|
2013-07-30 03:54:33 +00:00
|
|
|
final SettingsValues currentSettings = mSettings.getCurrent();
|
|
|
|
if (currentSettings.mBigramPredictionEnabled) {
|
2014-01-24 12:30:25 +00:00
|
|
|
setSuggestedWords(SuggestedWords.EMPTY, isSuggestionsStripVisible());
|
2012-06-14 18:52:48 +00:00
|
|
|
} else {
|
2014-01-24 12:30:25 +00:00
|
|
|
setSuggestedWords(currentSettings.mSpacingAndPunctuations.mSuggestPuncList,
|
|
|
|
isSuggestionsStripVisible());
|
2012-06-14 18:52:48 +00:00
|
|
|
}
|
2010-02-03 23:35:49 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 01:19:56 +00:00
|
|
|
// TODO: Make this private
|
|
|
|
// Outside LatinIME, only used by the {@link InputTestsBase} test suite.
|
2012-10-03 08:36:45 +00:00
|
|
|
@UsedForTesting
|
2012-08-22 01:19:56 +00:00
|
|
|
void loadKeyboard() {
|
2013-06-13 06:26:47 +00:00
|
|
|
// Since we are switching languages, the most urgent thing is to let the keyboard graphics
|
|
|
|
// update. LoadKeyboard does that, but we need to wait for buffer flip for it to be on
|
|
|
|
// the screen. Anything we do right now will delay this, so wait until the next frame
|
|
|
|
// before we do the rest, like reopening dictionaries and updating suggestions. So we
|
|
|
|
// post a message.
|
|
|
|
mHandler.postReopenDictionaries();
|
2012-07-23 05:59:19 +00:00
|
|
|
loadSettings();
|
2012-08-07 02:48:10 +00:00
|
|
|
if (mKeyboardSwitcher.getMainKeyboardView() != null) {
|
2011-11-04 03:36:38 +00:00
|
|
|
// Reload keyboard because the current language has been changed.
|
2013-01-08 07:35:21 +00:00
|
|
|
mKeyboardSwitcher.loadKeyboard(getCurrentInputEditorInfo(), mSettings.getCurrent());
|
2011-11-04 03:36:38 +00:00
|
|
|
}
|
2009-10-12 20:48:35 +00:00
|
|
|
}
|
|
|
|
|
2013-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() {
|
2013-12-20 07:35:35 +00:00
|
|
|
mInputLogic.commitTyped(mSettings.getCurrent(), LastComposedWord.NOT_A_SEPARATOR);
|
|
|
|
requestHideSelf(0);
|
|
|
|
final MainKeyboardView mainKeyboardView = mKeyboardSwitcher.getMainKeyboardView();
|
|
|
|
if (mainKeyboardView != null) {
|
|
|
|
mainKeyboardView.closing();
|
|
|
|
}
|
2012-07-19 01:00:48 +00:00
|
|
|
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 12:53:08 +00:00
|
|
|
mInputLogic.commitTyped(mSettings.getCurrent(), 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-12-19 11:56:37 +00:00
|
|
|
getString(ApplicationUtils.getActivityTitleResId(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);
|
2014-02-03 05:03:58 +00:00
|
|
|
showOptionDialog(builder.create(), true /*cancelable */);
|
2011-01-20 13:52:02 +00:00
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
|
2014-02-03 05:03:58 +00:00
|
|
|
// TODO: Move this method out of {@link LatinIME}.
|
|
|
|
private void showOptionDialog(final AlertDialog dialog, final boolean cancelable) {
|
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
|
|
|
|
2014-02-03 05:03:58 +00:00
|
|
|
dialog.setCancelable(cancelable);
|
|
|
|
dialog.setCanceledOnTouchOutside(cancelable);
|
2012-04-02 13:25:08 +00:00
|
|
|
|
|
|
|
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
|
2014-01-08 09:59:43 +00:00
|
|
|
/* package for test */ void waitForMainDictionary(final long timeout, final TimeUnit unit)
|
|
|
|
throws InterruptedException {
|
|
|
|
mInputLogic.mSuggest.mDictionaryFacilitator.waitForLoadingMainDictionary(timeout, unit);
|
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
|
2014-01-08 09:59:43 +00:00
|
|
|
/* package for test */ void replaceDictionariesForTest(final Locale locale) {
|
|
|
|
final DictionaryFacilitatorForSuggest oldDictionaryFacilitator =
|
|
|
|
mInputLogic.mSuggest.mDictionaryFacilitator;
|
|
|
|
final DictionaryFacilitatorForSuggest dictionaryFacilitator =
|
|
|
|
new DictionaryFacilitatorForSuggest(this, locale, mSettings.getCurrent(),
|
|
|
|
this /* listener */, oldDictionaryFacilitator);
|
|
|
|
resetSuggest(new Suggest(locale, dictionaryFacilitator));
|
2013-08-15 07:31:29 +00:00
|
|
|
}
|
|
|
|
|
2014-02-04 12:29:09 +00:00
|
|
|
public void dumpDictionaryForDebug(final String dictName) {
|
|
|
|
if (mInputLogic.mSuggest == null) {
|
|
|
|
initSuggest();
|
|
|
|
}
|
|
|
|
mInputLogic.mSuggest.mDictionaryFacilitator.dumpDictionaryForDebug(dictName);
|
|
|
|
}
|
|
|
|
|
2012-09-10 10:27:45 +00:00
|
|
|
public void debugDumpStateAndCrashWithException(final String context) {
|
2013-12-20 06:00:44 +00:00
|
|
|
final SettingsValues settingsValues = mSettings.getCurrent();
|
|
|
|
final StringBuilder s = new StringBuilder(settingsValues.toString());
|
|
|
|
s.append("\nAttributes : ").append(settingsValues.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-20 07:34:38 +00:00
|
|
|
p.println(" mIsSuggestionsRequested = " + settingsValues.isSuggestionsRequested());
|
2013-01-08 07:35:21 +00:00
|
|
|
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);
|
2013-12-20 06:00:44 +00:00
|
|
|
// TODO: Dump all settings values
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
}
|