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;
|
|
|
|
|
2014-10-23 09:37:32 +00:00
|
|
|
import static com.android.inputmethod.latin.common.Constants.ImeOption.FORCE_ASCII;
|
|
|
|
import static com.android.inputmethod.latin.common.Constants.ImeOption.NO_MICROPHONE;
|
|
|
|
import static com.android.inputmethod.latin.common.Constants.ImeOption.NO_MICROPHONE_COMPAT;
|
2012-04-19 03:42:13 +00:00
|
|
|
|
2014-10-21 08:07:47 +00:00
|
|
|
import android.annotation.TargetApi;
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.app.AlertDialog;
|
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.DialogInterface;
|
2014-02-19 04:17:36 +00:00
|
|
|
import android.content.DialogInterface.OnClickListener;
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.IntentFilter;
|
|
|
|
import android.content.res.Configuration;
|
2009-10-12 20:48:35 +00:00
|
|
|
import android.content.res.Resources;
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.inputmethodservice.InputMethodService;
|
|
|
|
import android.media.AudioManager;
|
2011-01-26 14:13:18 +00:00
|
|
|
import android.net.ConnectivityManager;
|
2014-10-07 10:11:55 +00:00
|
|
|
import android.os.Build;
|
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;
|
2014-07-17 01:41:46 +00:00
|
|
|
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;
|
2014-03-14 11:11:01 +00:00
|
|
|
import android.util.SparseArray;
|
2014-08-25 09:26:11 +00:00
|
|
|
import android.view.Gravity;
|
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;
|
2014-09-10 12:02:45 +00:00
|
|
|
import android.view.ViewTreeObserver;
|
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;
|
2014-08-13 10:33:01 +00:00
|
|
|
import android.view.inputmethod.CursorAnchorInfo;
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.view.inputmethod.EditorInfo;
|
2012-04-02 12:31:52 +00:00
|
|
|
import android.view.inputmethod.InputMethodSubtype;
|
2014-09-10 12:02:45 +00:00
|
|
|
import android.widget.TextView;
|
2011-05-23 09:30:21 +00:00
|
|
|
|
2011-05-18 00:03:25 +00:00
|
|
|
import com.android.inputmethod.accessibility.AccessibilityUtils;
|
2012-10-03 08:36:45 +00:00
|
|
|
import com.android.inputmethod.annotations.UsedForTesting;
|
2014-08-13 10:33:01 +00:00
|
|
|
import com.android.inputmethod.compat.CursorAnchorInfoCompatWrapper;
|
2012-08-02 04:25:17 +00:00
|
|
|
import com.android.inputmethod.compat.InputMethodServiceCompatUtils;
|
2014-10-07 06:11:43 +00:00
|
|
|
import com.android.inputmethod.compat.ViewOutlineProviderCompatUtils;
|
|
|
|
import com.android.inputmethod.compat.ViewOutlineProviderCompatUtils.InsetsUpdater;
|
2013-03-19 07:45:25 +00:00
|
|
|
import com.android.inputmethod.dictionarypack.DictionaryPackConstants;
|
2014-03-12 07:41:45 +00:00
|
|
|
import com.android.inputmethod.event.Event;
|
2014-03-14 11:11:01 +00:00
|
|
|
import com.android.inputmethod.event.HardwareEventDecoder;
|
|
|
|
import com.android.inputmethod.event.HardwareKeyboardEventDecoder;
|
2014-03-04 08:28:20 +00:00
|
|
|
import com.android.inputmethod.event.InputTransaction;
|
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;
|
2014-08-25 03:08:55 +00:00
|
|
|
import com.android.inputmethod.keyboard.TextDecoratorUi;
|
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;
|
2014-10-23 09:37:32 +00:00
|
|
|
import com.android.inputmethod.latin.common.Constants;
|
2014-10-29 02:37:21 +00:00
|
|
|
import com.android.inputmethod.latin.common.InputPointers;
|
2014-07-17 01:41:46 +00:00
|
|
|
import com.android.inputmethod.latin.define.DebugFlags;
|
2014-07-17 02:22:35 +00:00
|
|
|
import com.android.inputmethod.latin.define.ProductionFlags;
|
2013-12-18 09:08:35 +00:00
|
|
|
import com.android.inputmethod.latin.inputlogic.InputLogic;
|
2014-06-13 09:39:29 +00:00
|
|
|
import com.android.inputmethod.latin.personalization.ContextualDictionaryUpdater;
|
2013-10-02 09:06:08 +00:00
|
|
|
import com.android.inputmethod.latin.personalization.DictionaryDecayBroadcastReciever;
|
2014-06-13 07:31:12 +00:00
|
|
|
import com.android.inputmethod.latin.personalization.PersonalizationDictionaryUpdater;
|
2013-12-25 02:44:16 +00:00
|
|
|
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;
|
2014-09-04 20:42:10 +00:00
|
|
|
import com.android.inputmethod.latin.touchinputconsumer.GestureConsumer;
|
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;
|
2013-12-27 11:58:32 +00:00
|
|
|
import com.android.inputmethod.latin.utils.CoordinateUtils;
|
2014-09-08 08:56:19 +00:00
|
|
|
import com.android.inputmethod.latin.utils.CursorAnchorInfoUtils;
|
2014-04-04 05:14:47 +00:00
|
|
|
import com.android.inputmethod.latin.utils.DialogUtils;
|
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-04-08 09:33:41 +00:00
|
|
|
import com.android.inputmethod.latin.utils.StatsUtils;
|
2014-08-26 20:06:21 +00:00
|
|
|
import com.android.inputmethod.latin.utils.StatsUtilsManager;
|
2014-01-27 10:04:40 +00:00
|
|
|
import com.android.inputmethod.latin.utils.SubtypeLocaleUtils;
|
2014-08-25 09:26:11 +00:00
|
|
|
import com.android.inputmethod.latin.utils.ViewLayoutUtils;
|
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;
|
2014-10-06 12:27:16 +00:00
|
|
|
import java.util.Arrays;
|
2014-05-23 07:10:36 +00:00
|
|
|
import java.util.List;
|
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
|
|
|
|
2014-10-14 08:42:10 +00:00
|
|
|
import javax.annotation.Nonnull;
|
|
|
|
|
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,
|
2014-05-23 00:30:55 +00:00
|
|
|
DictionaryFacilitator.DictionaryInitializationListener,
|
2014-02-20 15:54:02 +00:00
|
|
|
ImportantNoticeDialog.ImportantNoticeDialogListener {
|
2014-10-20 05:48:56 +00:00
|
|
|
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;
|
2013-08-13 03:10:26 +00:00
|
|
|
private static final int PERIOD_FOR_AUDIO_AND_HAPTIC_FEEDBACK_IN_KEY_REPEAT = 2;
|
2014-09-29 06:15:07 +00:00
|
|
|
private static final int PENDING_IMS_CALLBACK_DURATION_MILLIS = 800;
|
2014-10-20 05:48:56 +00:00
|
|
|
static final long DELAY_WAIT_FOR_DICTIONARY_LOAD_MILLIS = TimeUnit.SECONDS.toMillis(2);
|
|
|
|
static final long DELAY_DEALLOCATE_MEMORY_MILLIS = TimeUnit.SECONDS.toMillis(10);
|
2013-08-13 03:10:26 +00:00
|
|
|
|
2011-03-14 18:46:15 +00:00
|
|
|
/**
|
|
|
|
* The name of the scheme used by the Package Manager to warn of a new package installation,
|
|
|
|
* replacement or removal.
|
|
|
|
*/
|
|
|
|
private static final String SCHEME_PACKAGE = "package";
|
|
|
|
|
2014-10-20 05:48:56 +00:00
|
|
|
final Settings mSettings;
|
2014-05-23 07:10:36 +00:00
|
|
|
private final DictionaryFacilitator mDictionaryFacilitator =
|
2014-08-29 03:57:50 +00:00
|
|
|
new DictionaryFacilitator(this /* context */);
|
2014-06-13 07:31:12 +00:00
|
|
|
// TODO: Move from LatinIME.
|
|
|
|
private final PersonalizationDictionaryUpdater mPersonalizationDictionaryUpdater =
|
|
|
|
new PersonalizationDictionaryUpdater(this /* context */, mDictionaryFacilitator);
|
2014-06-13 09:39:29 +00:00
|
|
|
private final ContextualDictionaryUpdater mContextualDictionaryUpdater =
|
2014-06-16 09:30:59 +00:00
|
|
|
new ContextualDictionaryUpdater(this /* context */, mDictionaryFacilitator,
|
|
|
|
new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2014-08-14 03:48:50 +00:00
|
|
|
mHandler.postUpdateSuggestionStrip(SuggestedWords.INPUT_STYLE_NONE);
|
2014-06-16 09:30:59 +00:00
|
|
|
}
|
|
|
|
});
|
2014-10-20 05:48:56 +00:00
|
|
|
final InputLogic mInputLogic = new InputLogic(this /* LatinIME */,
|
2014-05-23 00:30:55 +00:00
|
|
|
this /* SuggestionStripViewAccessor */, mDictionaryFacilitator);
|
2014-03-14 11:11:01 +00:00
|
|
|
// We expect to have only one decoder in almost all cases, hence the default capacity of 1.
|
|
|
|
// If it turns out we need several, it will get grown seamlessly.
|
2014-05-23 11:18:17 +00:00
|
|
|
final SparseArray<HardwareEventDecoder> mHardwareEventDecoders = new SparseArray<>(1);
|
2011-05-10 06:51:43 +00:00
|
|
|
|
2014-08-08 07:26:25 +00:00
|
|
|
// TODO: Move these {@link View}s to {@link KeyboardSwitcher}.
|
|
|
|
private View mInputView;
|
2014-10-07 06:11:43 +00:00
|
|
|
private InsetsUpdater mInsetsUpdater;
|
2012-07-23 06:28:28 +00:00
|
|
|
private SuggestionStripView mSuggestionStripView;
|
2014-09-10 12:02:45 +00:00
|
|
|
private TextView mExtractEditText;
|
2013-12-18 09:08:35 +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;
|
2014-10-20 05:48:56 +00:00
|
|
|
final SubtypeSwitcher mSubtypeSwitcher;
|
2012-10-02 09:40:06 +00:00
|
|
|
private final SubtypeState mSubtypeState = new SubtypeState();
|
2014-10-27 02:59:57 +00:00
|
|
|
private final EmojiAltPhysicalKeyDetector mEmojiAltPhysicalKeyDetector =
|
|
|
|
new EmojiAltPhysicalKeyDetector();
|
2014-08-26 20:06:21 +00:00
|
|
|
private StatsUtilsManager mStatsUtilsManager;
|
2014-09-08 08:56:19 +00:00
|
|
|
// Working variable for {@link #startShowingInputView()} and
|
|
|
|
// {@link #onEvaluateInputViewShown()}.
|
|
|
|
private boolean mIsExecutingStartShowingInputView;
|
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.
|
2014-05-16 13:19:41 +00:00
|
|
|
private final BroadcastReceiver mDictionaryPackInstallReceiver =
|
2013-06-06 05:11:20 +00:00
|
|
|
new DictionaryPackInstallBroadcastReceiver(this);
|
2011-03-14 18:46:15 +00:00
|
|
|
|
2014-05-16 13:19:41 +00:00
|
|
|
private final BroadcastReceiver mDictionaryDumpBroadcastReceiver =
|
2014-02-04 12:29:09 +00:00
|
|
|
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;
|
|
|
|
|
2014-09-04 20:42:10 +00:00
|
|
|
private GestureConsumer mGestureConsumer = GestureConsumer.NULL_GESTURE_CONSUMER;
|
|
|
|
|
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;
|
2014-03-06 07:10:15 +00:00
|
|
|
private static final int MSG_UPDATE_TAIL_BATCH_INPUT_COMPLETED = 6;
|
2013-09-20 09:01:32 +00:00
|
|
|
private static final int MSG_RESET_CACHES = 7;
|
2014-07-01 09:07:42 +00:00
|
|
|
private static final int MSG_WAIT_FOR_DICTIONARY_LOAD = 8;
|
2014-09-29 06:15:07 +00:00
|
|
|
private static final int MSG_DEALLOCATE_MEMORY = 9;
|
2013-12-13 08:09:16 +00:00
|
|
|
// Update this when adding new messages
|
2014-09-29 06:15:07 +00:00
|
|
|
private static final int MSG_LAST = MSG_DEALLOCATE_MEMORY;
|
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;
|
2014-06-06 04:12:11 +00:00
|
|
|
private static final int ARG1_TRUE = 1;
|
2012-03-13 03:44:03 +00:00
|
|
|
|
2014-08-25 09:08:21 +00:00
|
|
|
private int mDelayInMillisecondsToUpdateSuggestions;
|
|
|
|
private int mDelayInMillisecondsToUpdateShiftState;
|
2011-07-21 06:57:00 +00:00
|
|
|
|
2014-10-14 08:42:10 +00:00
|
|
|
public UIHandler(@Nonnull final LatinIME ownerInstance) {
|
2013-12-13 08:09:16 +00:00
|
|
|
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() {
|
2014-02-28 07:13:51 +00:00
|
|
|
final LatinIME latinIme = getOwnerInstance();
|
|
|
|
if (latinIme == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
final Resources res = latinIme.getResources();
|
2014-08-25 03:08:55 +00:00
|
|
|
mDelayInMillisecondsToUpdateSuggestions = res.getInteger(
|
|
|
|
R.integer.config_delay_in_milliseconds_to_update_suggestions);
|
|
|
|
mDelayInMillisecondsToUpdateShiftState = res.getInteger(
|
|
|
|
R.integer.config_delay_in_milliseconds_to_update_shift_state);
|
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();
|
2014-02-28 07:13:51 +00:00
|
|
|
if (latinIme == null) {
|
|
|
|
return;
|
|
|
|
}
|
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:
|
2014-03-03 05:19:52 +00:00
|
|
|
cancelUpdateSuggestionStrip();
|
2013-12-19 13:08:31 +00:00
|
|
|
latinIme.mInputLogic.performUpdateSuggestionStripSync(
|
2014-08-14 03:48:50 +00:00
|
|
|
latinIme.mSettings.getCurrent(), msg.arg1 /* inputStyle */);
|
2010-11-16 09:07:06 +00:00
|
|
|
break;
|
|
|
|
case MSG_UPDATE_SHIFT_STATE:
|
2014-03-27 09:37:16 +00:00
|
|
|
switcher.requestUpdatingShiftState(latinIme.getCurrentAutoCapsState(),
|
|
|
|
latinIme.getCurrentRecapitalizeState());
|
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(),
|
2014-06-26 09:43:14 +00:00
|
|
|
latinIme.mKeyboardSwitcher.getCurrentKeyboardScriptId());
|
2013-04-10 07:38:37 +00:00
|
|
|
break;
|
2013-06-13 06:26:47 +00:00
|
|
|
case MSG_REOPEN_DICTIONARIES:
|
2014-06-27 12:38:57 +00:00
|
|
|
// We need to re-evaluate the currently composing word in case the script has
|
|
|
|
// changed.
|
2014-07-01 09:07:42 +00:00
|
|
|
postWaitForDictionaryLoad();
|
2014-10-02 06:08:16 +00:00
|
|
|
latinIme.resetDictionaryFacilitatorIfNecessary();
|
2013-06-13 06:26:47 +00:00
|
|
|
break;
|
2014-03-06 07:10:15 +00:00
|
|
|
case MSG_UPDATE_TAIL_BATCH_INPUT_COMPLETED:
|
2014-09-04 20:42:10 +00:00
|
|
|
final SuggestedWords suggestedWords = (SuggestedWords) msg.obj;
|
2014-03-06 07:10:15 +00:00
|
|
|
latinIme.mInputLogic.onUpdateTailBatchInputCompleted(
|
|
|
|
latinIme.mSettings.getCurrent(),
|
2014-09-04 20:42:10 +00:00
|
|
|
suggestedWords, latinIme.mKeyboardSwitcher);
|
|
|
|
latinIme.onTailBatchInputResultShown(suggestedWords);
|
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();
|
2014-08-04 13:07:15 +00:00
|
|
|
if (latinIme.mInputLogic.retryResetCachesAndReturnSuccess(
|
2014-08-25 03:08:55 +00:00
|
|
|
msg.arg1 == ARG1_TRUE /* 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(),
|
2014-04-14 08:04:50 +00:00
|
|
|
settingsValues, latinIme.getCurrentAutoCapsState(),
|
2014-04-17 06:44:55 +00:00
|
|
|
latinIme.getCurrentRecapitalizeState());
|
2013-12-27 08:04:12 +00:00
|
|
|
}
|
2013-09-20 09:01:32 +00:00
|
|
|
break;
|
2014-07-01 09:07:42 +00:00
|
|
|
case MSG_WAIT_FOR_DICTIONARY_LOAD:
|
|
|
|
Log.i(TAG, "Timeout waiting for dictionary load");
|
|
|
|
break;
|
2014-09-29 06:15:07 +00:00
|
|
|
case MSG_DEALLOCATE_MEMORY:
|
|
|
|
latinIme.deallocateMemory();
|
|
|
|
break;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
}
|
2010-11-16 09:07:06 +00:00
|
|
|
|
2014-08-14 03:48:50 +00:00
|
|
|
public void postUpdateSuggestionStrip(final int inputStyle) {
|
|
|
|
sendMessageDelayed(obtainMessage(MSG_UPDATE_SUGGESTION_STRIP, inputStyle,
|
2014-08-25 09:08:21 +00:00
|
|
|
0 /* ignored */), mDelayInMillisecondsToUpdateSuggestions);
|
2010-11-16 09:07:06 +00:00
|
|
|
}
|
|
|
|
|
2013-06-13 06:26:47 +00:00
|
|
|
public void postReopenDictionaries() {
|
|
|
|
sendMessage(obtainMessage(MSG_REOPEN_DICTIONARIES));
|
|
|
|
}
|
|
|
|
|
2014-10-01 09:32:02 +00:00
|
|
|
public void postResumeSuggestions(final boolean shouldDelay) {
|
2014-02-28 07:13:51 +00:00
|
|
|
final LatinIME latinIme = getOwnerInstance();
|
|
|
|
if (latinIme == null) {
|
|
|
|
return;
|
|
|
|
}
|
2014-08-25 09:08:21 +00:00
|
|
|
if (!latinIme.mSettings.getCurrent().isSuggestionsEnabledPerUserSettings()) {
|
2013-12-25 12:48:48 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-05-08 09:44:50 +00:00
|
|
|
removeMessages(MSG_RESUME_SUGGESTIONS);
|
2014-07-01 09:07:42 +00:00
|
|
|
if (shouldDelay) {
|
2014-10-01 09:32:02 +00:00
|
|
|
sendMessageDelayed(obtainMessage(MSG_RESUME_SUGGESTIONS),
|
|
|
|
mDelayInMillisecondsToUpdateSuggestions);
|
2014-07-01 09:07:42 +00:00
|
|
|
} else {
|
2014-10-01 09:32:02 +00:00
|
|
|
sendMessage(obtainMessage(MSG_RESUME_SUGGESTIONS));
|
2014-07-01 09:07:42 +00:00
|
|
|
}
|
2013-04-10 07:38:37 +00:00
|
|
|
}
|
|
|
|
|
2014-08-06 09:34:26 +00:00
|
|
|
public void postResetCaches(final boolean tryResumeSuggestions, final int remainingTries) {
|
2013-09-20 09:01:32 +00:00
|
|
|
removeMessages(MSG_RESET_CACHES);
|
|
|
|
sendMessage(obtainMessage(MSG_RESET_CACHES, tryResumeSuggestions ? 1 : 0,
|
|
|
|
remainingTries, null));
|
|
|
|
}
|
|
|
|
|
2014-07-01 09:07:42 +00:00
|
|
|
public void postWaitForDictionaryLoad() {
|
|
|
|
sendMessageDelayed(obtainMessage(MSG_WAIT_FOR_DICTIONARY_LOAD),
|
2014-09-29 06:15:07 +00:00
|
|
|
DELAY_WAIT_FOR_DICTIONARY_LOAD_MILLIS);
|
2014-07-01 09:07:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void cancelWaitForDictionaryLoad() {
|
|
|
|
removeMessages(MSG_WAIT_FOR_DICTIONARY_LOAD);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasPendingWaitForDictionaryLoad() {
|
|
|
|
return hasMessages(MSG_WAIT_FOR_DICTIONARY_LOAD);
|
|
|
|
}
|
|
|
|
|
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);
|
2014-08-25 09:08:21 +00:00
|
|
|
sendMessageDelayed(obtainMessage(MSG_UPDATE_SHIFT_STATE),
|
|
|
|
mDelayInMillisecondsToUpdateShiftState);
|
2010-11-16 09:07:06 +00:00
|
|
|
}
|
|
|
|
|
2014-09-29 06:15:07 +00:00
|
|
|
public void postDeallocateMemory() {
|
|
|
|
sendMessageDelayed(obtainMessage(MSG_DEALLOCATE_MEMORY),
|
|
|
|
DELAY_DEALLOCATE_MEMORY_MILLIS);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void cancelDeallocateMemory() {
|
|
|
|
removeMessages(MSG_DEALLOCATE_MEMORY);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasPendingDeallocateMemory() {
|
|
|
|
return hasMessages(MSG_DEALLOCATE_MEMORY);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-03-06 07:10:15 +00:00
|
|
|
public void showTailBatchInputResult(final SuggestedWords suggestedWords) {
|
|
|
|
obtainMessage(MSG_UPDATE_TAIL_BATCH_INPUT_COMPLETED, suggestedWords).sendToTarget();
|
2013-09-02 07:49:32 +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();
|
2014-02-28 07:13:51 +00:00
|
|
|
if (latinIme == null) {
|
|
|
|
return;
|
|
|
|
}
|
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) {
|
2014-02-18 05:48:41 +00:00
|
|
|
if (mHasPendingFinishInputView) {
|
2011-09-29 08:27:48 +00:00
|
|
|
latinIme.onFinishInputViewInternal(mHasPendingFinishInput);
|
2014-02-18 05:48:41 +00:00
|
|
|
}
|
|
|
|
if (mHasPendingFinishInput) {
|
2011-09-29 08:27:48 +00:00
|
|
|
latinIme.onFinishInputInternal();
|
2014-02-18 05:48:41 +00:00
|
|
|
}
|
|
|
|
if (mHasPendingStartInput) {
|
2011-11-21 22:58:32 +00:00
|
|
|
latinIme.onStartInputInternal(editorInfo, restarting);
|
2014-02-18 05:48:41 +00:00
|
|
|
}
|
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();
|
2014-02-28 07:13:51 +00:00
|
|
|
if (latinIme != null) {
|
|
|
|
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),
|
2014-09-29 06:15:07 +00:00
|
|
|
PENDING_IMS_CALLBACK_DURATION_MILLIS);
|
2011-11-21 22:58:32 +00:00
|
|
|
}
|
2013-12-13 08:09:16 +00:00
|
|
|
final LatinIME latinIme = getOwnerInstance();
|
2014-02-28 07:13:51 +00:00
|
|
|
if (latinIme != null) {
|
|
|
|
executePendingImsCallback(latinIme, editorInfo, restarting);
|
|
|
|
latinIme.onStartInputViewInternal(editorInfo, restarting);
|
|
|
|
mAppliedEditorInfo = editorInfo;
|
|
|
|
}
|
2014-09-29 06:15:07 +00:00
|
|
|
cancelDeallocateMemory();
|
2011-11-21 22:58:32 +00:00
|
|
|
}
|
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();
|
2014-02-28 07:13:51 +00:00
|
|
|
if (latinIme != null) {
|
|
|
|
latinIme.onFinishInputViewInternal(finishingInput);
|
|
|
|
mAppliedEditorInfo = null;
|
|
|
|
}
|
2014-09-29 06:15:07 +00:00
|
|
|
if (!hasPendingDeallocateMemory()) {
|
|
|
|
postDeallocateMemory();
|
|
|
|
}
|
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();
|
2014-02-28 07:13:51 +00:00
|
|
|
if (latinIme != null) {
|
|
|
|
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;
|
2014-06-27 12:38:57 +00:00
|
|
|
private boolean mCurrentSubtypeHasBeenUsed;
|
2012-10-02 09:40:06 +00:00
|
|
|
|
2014-06-27 12:38:57 +00:00
|
|
|
public void setCurrentSubtypeHasBeenUsed() {
|
|
|
|
mCurrentSubtypeHasBeenUsed = true;
|
2012-10-02 09:40:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void switchSubtype(final IBinder token, final RichInputMethodManager richImm) {
|
|
|
|
final InputMethodSubtype currentSubtype = richImm.getInputMethodManager()
|
|
|
|
.getCurrentInputMethodSubtype();
|
|
|
|
final InputMethodSubtype lastActiveSubtype = mLastActiveSubtype;
|
2014-06-27 12:38:57 +00:00
|
|
|
final boolean currentSubtypeHasBeenUsed = mCurrentSubtypeHasBeenUsed;
|
|
|
|
if (currentSubtypeHasBeenUsed) {
|
2012-10-02 09:40:06 +00:00
|
|
|
mLastActiveSubtype = currentSubtype;
|
2014-06-27 12:38:57 +00:00
|
|
|
mCurrentSubtypeHasBeenUsed = false;
|
2012-10-02 09:40:06 +00:00
|
|
|
}
|
2014-06-27 12:38:57 +00:00
|
|
|
if (currentSubtypeHasBeenUsed
|
2012-10-02 09:40:06 +00:00
|
|
|
&& 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();
|
2014-08-26 20:06:21 +00:00
|
|
|
mStatsUtilsManager = StatsUtilsManager.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);
|
2014-07-17 01:41:46 +00:00
|
|
|
DebugFlags.init(PreferenceManager.getDefaultSharedPreferences(this));
|
2013-01-07 09:40:59 +00:00
|
|
|
RichInputMethodManager.init(this);
|
2012-11-28 04:28:18 +00:00
|
|
|
mRichImm = RichInputMethodManager.getInstance();
|
2011-07-17 22:23:52 +00:00
|
|
|
SubtypeSwitcher.init(this);
|
2013-01-07 09:40:59 +00:00
|
|
|
KeyboardSwitcher.init(this);
|
2013-01-08 05:58:08 +00:00
|
|
|
AudioAndHapticFeedbackManager.init(this);
|
2011-12-15 10:32:11 +00:00
|
|
|
AccessibilityUtils.init(this);
|
2014-08-29 22:51:57 +00:00
|
|
|
mStatsUtilsManager.onCreate(this /* context */);
|
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();
|
2014-07-17 01:41:46 +00:00
|
|
|
DEBUG = DebugFlags.DEBUG_ENABLED;
|
2010-12-23 03:24:27 +00:00
|
|
|
|
2014-10-02 06:08:16 +00:00
|
|
|
// TODO: Resolve mutual dependencies of {@link #loadSettings()} and
|
|
|
|
// {@link #resetDictionaryFacilitatorIfNecessary()}.
|
2011-09-19 05:51:31 +00:00
|
|
|
loadSettings();
|
2014-10-14 06:11:39 +00:00
|
|
|
mSubtypeSwitcher.onSubtypeChanged(mRichImm.getCurrentRawSubtype());
|
2014-10-02 06:08:16 +00:00
|
|
|
resetDictionaryFacilitatorIfNecessary();
|
2010-08-20 05:35:02 +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);
|
2014-04-15 10:23:01 +00:00
|
|
|
registerReceiver(mConnectivityAndRingerModeChangeReceiver, 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);
|
2014-08-14 00:09:06 +00:00
|
|
|
StatsUtils.onCreate(mSettings.getCurrent(), mRichImm);
|
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() {
|
2014-10-06 12:27:16 +00:00
|
|
|
final Locale[] locales = mSubtypeSwitcher.getCurrentSubtypeLocales();
|
2013-12-20 06:00:44 +00:00
|
|
|
final EditorInfo editorInfo = getCurrentInputEditorInfo();
|
2014-06-05 16:41:42 +00:00
|
|
|
final InputAttributes inputAttributes = new InputAttributes(
|
|
|
|
editorInfo, isFullscreenMode(), getPackageName());
|
2014-10-06 12:27:16 +00:00
|
|
|
// TODO: pass the array instead
|
|
|
|
mSettings.loadSettings(this, locales[0], inputAttributes);
|
2013-12-25 02:44:16 +00:00
|
|
|
final SettingsValues currentSettingsValues = mSettings.getCurrent();
|
2014-02-27 13:31:57 +00:00
|
|
|
AudioAndHapticFeedbackManager.getInstance().onSettingsChanged(currentSettingsValues);
|
|
|
|
// This method is called on startup and language switch, before the new layout has
|
|
|
|
// been displayed. Opening dictionaries never affects responsivity as dictionaries are
|
|
|
|
// asynchronously loaded.
|
2014-03-25 06:35:20 +00:00
|
|
|
if (!mHandler.hasPendingReopenDictionaries()) {
|
2014-10-06 12:27:16 +00:00
|
|
|
resetDictionaryFacilitatorForLocale(locales);
|
2013-12-25 02:44:16 +00:00
|
|
|
}
|
2014-05-23 07:10:36 +00:00
|
|
|
mDictionaryFacilitator.updateEnabledSubtypes(mRichImm.getMyEnabledInputMethodSubtypeList(
|
|
|
|
true /* allowsImplicitlySelectedSubtypes */));
|
2014-06-13 07:31:12 +00:00
|
|
|
refreshPersonalizationDictionarySession(currentSettingsValues);
|
2014-08-26 20:06:21 +00:00
|
|
|
mStatsUtilsManager.onLoadSettings(currentSettingsValues);
|
2014-01-08 09:59:43 +00:00
|
|
|
}
|
|
|
|
|
2014-06-13 07:31:12 +00:00
|
|
|
private void refreshPersonalizationDictionarySession(
|
|
|
|
final SettingsValues currentSettingsValues) {
|
2014-09-02 09:03:49 +00:00
|
|
|
mDictionaryFacilitator.setIsMonolingualUser(
|
2014-06-13 07:31:12 +00:00
|
|
|
mSubtypeSwitcher.isSystemLocaleSameAsLocaleOfAllEnabledSubtypesOfEnabledImes());
|
2014-09-02 09:03:49 +00:00
|
|
|
mPersonalizationDictionaryUpdater.onLoadSettings(
|
|
|
|
currentSettingsValues.mUsePersonalizedDicts);
|
2014-06-13 09:39:29 +00:00
|
|
|
mContextualDictionaryUpdater.onLoadSettings(currentSettingsValues.mUsePersonalizedDicts);
|
2014-02-19 12:00:27 +00:00
|
|
|
final boolean shouldKeepUserHistoryDictionaries;
|
2014-06-13 09:39:29 +00:00
|
|
|
if (currentSettingsValues.mUsePersonalizedDicts) {
|
2014-02-19 12:00:27 +00:00
|
|
|
shouldKeepUserHistoryDictionaries = true;
|
2013-12-25 02:44:16 +00:00
|
|
|
} else {
|
2014-02-19 12:00:27 +00:00
|
|
|
shouldKeepUserHistoryDictionaries = false;
|
|
|
|
}
|
|
|
|
if (!shouldKeepUserHistoryDictionaries) {
|
|
|
|
// Remove user history dictionaries.
|
|
|
|
PersonalizationHelper.removeAllUserHistoryDictionaries(this);
|
2014-05-23 00:30:55 +00:00
|
|
|
mDictionaryFacilitator.clearUserHistoryDictionary();
|
2014-02-19 12:00:27 +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);
|
|
|
|
}
|
2014-07-01 09:07:42 +00:00
|
|
|
if (mHandler.hasPendingWaitForDictionaryLoad()) {
|
|
|
|
mHandler.cancelWaitForDictionaryLoad();
|
2014-10-01 09:32:02 +00:00
|
|
|
mHandler.postResumeSuggestions(false /* shouldDelay */);
|
2014-07-01 09:07:42 +00:00
|
|
|
}
|
2012-07-24 06:56:25 +00:00
|
|
|
}
|
|
|
|
|
2014-10-20 05:48:56 +00:00
|
|
|
void resetDictionaryFacilitatorIfNecessary() {
|
2014-10-06 12:27:16 +00:00
|
|
|
final Locale[] subtypeSwitcherLocales = mSubtypeSwitcher.getCurrentSubtypeLocales();
|
|
|
|
if (mDictionaryFacilitator.isForLocales(subtypeSwitcherLocales)) {
|
2014-10-02 06:08:16 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-10-06 12:27:16 +00:00
|
|
|
final Locale[] subtypeLocales;
|
|
|
|
if (0 == subtypeSwitcherLocales.length) {
|
2013-10-04 11:24:41 +00:00
|
|
|
// 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
|
2014-10-06 12:27:16 +00:00
|
|
|
// us there is no current subtype.
|
2013-10-04 11:24:41 +00:00
|
|
|
Log.e(TAG, "System is reporting no current subtype.");
|
2014-10-06 12:27:16 +00:00
|
|
|
subtypeLocales = new Locale[] { getResources().getConfiguration().locale };
|
2013-10-04 11:24:41 +00:00
|
|
|
} else {
|
2014-10-06 12:27:16 +00:00
|
|
|
subtypeLocales = subtypeSwitcherLocales;
|
2013-10-04 11:24:41 +00:00
|
|
|
}
|
2014-10-06 12:27:16 +00:00
|
|
|
resetDictionaryFacilitatorForLocale(subtypeLocales);
|
2014-01-08 09:59:43 +00:00
|
|
|
}
|
2009-10-12 20:48:35 +00:00
|
|
|
|
2014-03-25 06:35:20 +00:00
|
|
|
/**
|
2014-10-06 12:27:16 +00:00
|
|
|
* Reset the facilitator by loading dictionaries for the locales and the current settings values
|
2014-03-25 06:35:20 +00:00
|
|
|
*
|
2014-10-06 12:27:16 +00:00
|
|
|
* @param locales the locales
|
2014-03-25 06:35:20 +00:00
|
|
|
*/
|
2014-10-06 12:27:16 +00:00
|
|
|
// TODO: make sure the current settings always have the right locales, and read from them
|
|
|
|
private void resetDictionaryFacilitatorForLocale(final Locale[] locales) {
|
2014-03-25 06:35:20 +00:00
|
|
|
final SettingsValues settingsValues = mSettings.getCurrent();
|
2014-10-07 06:56:45 +00:00
|
|
|
mDictionaryFacilitator.resetDictionaries(this /* context */, locales,
|
2014-03-25 06:35:20 +00:00
|
|
|
settingsValues.mUseContactsDict, settingsValues.mUsePersonalizedDicts,
|
|
|
|
false /* forceReloadMainDictionary */, this);
|
2014-07-22 17:18:38 +00:00
|
|
|
if (settingsValues.mAutoCorrectionEnabledPerUserSettings) {
|
2014-03-25 06:35:20 +00:00
|
|
|
mInputLogic.mSuggest.setAutoCorrectionThreshold(
|
|
|
|
settingsValues.mAutoCorrectionThreshold);
|
2012-04-11 05:58:02 +00:00
|
|
|
}
|
2014-01-08 09:59:43 +00:00
|
|
|
}
|
|
|
|
|
2014-03-25 06:35:20 +00:00
|
|
|
/**
|
|
|
|
* Reset suggest by loading the main dictionary of the current locale.
|
|
|
|
*/
|
2014-01-08 09:59:43 +00:00
|
|
|
/* package private */ void resetSuggestMainDict() {
|
2014-03-25 06:35:20 +00:00
|
|
|
final SettingsValues settingsValues = mSettings.getCurrent();
|
2014-05-23 00:30:55 +00:00
|
|
|
mDictionaryFacilitator.resetDictionaries(this /* context */,
|
2014-10-07 06:56:45 +00:00
|
|
|
mDictionaryFacilitator.getLocales(), settingsValues.mUseContactsDict,
|
2014-03-25 06:35:20 +00:00
|
|
|
settingsValues.mUsePersonalizedDicts, true /* forceReloadMainDictionary */, this);
|
2011-03-14 18:46:15 +00:00
|
|
|
}
|
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
@Override
|
|
|
|
public void onDestroy() {
|
2014-05-23 00:30:55 +00:00
|
|
|
mDictionaryFacilitator.closeDictionaries();
|
2014-06-13 07:31:12 +00:00
|
|
|
mPersonalizationDictionaryUpdater.onDestroy();
|
2014-06-13 09:39:29 +00:00
|
|
|
mContextualDictionaryUpdater.onDestroy();
|
2013-01-08 07:35:21 +00:00
|
|
|
mSettings.onDestroy();
|
2014-04-15 10:23:01 +00:00
|
|
|
unregisterReceiver(mConnectivityAndRingerModeChangeReceiver);
|
2013-06-06 05:11:20 +00:00
|
|
|
unregisterReceiver(mDictionaryPackInstallReceiver);
|
2014-02-06 06:37:41 +00:00
|
|
|
unregisterReceiver(mDictionaryDumpBroadcastReceiver);
|
2014-08-26 20:06:21 +00:00
|
|
|
mStatsUtilsManager.onDestroy();
|
2009-03-13 22:11:42 +00:00
|
|
|
super.onDestroy();
|
|
|
|
}
|
|
|
|
|
2014-04-07 13:32:06 +00:00
|
|
|
@UsedForTesting
|
|
|
|
public void recycle() {
|
2014-04-15 10:23:01 +00:00
|
|
|
unregisterReceiver(mDictionaryPackInstallReceiver);
|
|
|
|
unregisterReceiver(mDictionaryDumpBroadcastReceiver);
|
|
|
|
unregisterReceiver(mConnectivityAndRingerModeChangeReceiver);
|
2014-04-07 13:32:06 +00:00
|
|
|
mInputLogic.recycle();
|
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
@Override
|
2012-09-12 04:03:44 +00:00
|
|
|
public void onConfigurationChanged(final Configuration conf) {
|
2014-09-05 11:07:23 +00:00
|
|
|
SettingsValues settingsValues = mSettings.getCurrent();
|
2013-12-20 07:34:38 +00:00
|
|
|
if (settingsValues.mDisplayOrientation != conf.orientation) {
|
2011-08-23 05:58:45 +00:00
|
|
|
mHandler.startOrientationChanging();
|
2014-06-30 13:15:36 +00:00
|
|
|
mInputLogic.onOrientationChange(mSettings.getCurrent());
|
2009-07-21 22:47:11 +00:00
|
|
|
}
|
2014-09-05 11:07:23 +00:00
|
|
|
if (settingsValues.mHasHardwareKeyboard != Settings.readHasHardwareKeyboard(conf)) {
|
|
|
|
// If the state of having a hardware keyboard changed, then we want to reload the
|
|
|
|
// settings to adjust for that.
|
|
|
|
// TODO: we should probably do this unconditionally here, rather than only when we
|
|
|
|
// have a change in hardware keyboard configuration.
|
|
|
|
loadSettings();
|
|
|
|
settingsValues = mSettings.getCurrent();
|
|
|
|
if (settingsValues.mHasHardwareKeyboard) {
|
|
|
|
// We call cleanupInternalStateForFinishInput() because it's the right thing to do;
|
|
|
|
// however, it seems at the moment the framework is passing us a seemingly valid
|
|
|
|
// but actually non-functional InputConnection object. So if this bug ever gets
|
|
|
|
// fixed we'll be able to remove the composition, but until it is this code is
|
|
|
|
// actually not doing much.
|
|
|
|
cleanupInternalStateForFinishInput();
|
|
|
|
}
|
|
|
|
}
|
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() {
|
2014-09-10 02:05:31 +00:00
|
|
|
StatsUtils.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);
|
2014-08-08 07:26:25 +00:00
|
|
|
mInputView = view;
|
2014-10-07 06:11:43 +00:00
|
|
|
mInsetsUpdater = ViewOutlineProviderCompatUtils.setInsetsOutlineProvider(view);
|
2014-10-01 01:40:12 +00:00
|
|
|
updateSoftInputWindowLayoutParameters();
|
2013-08-30 07:50:37 +00:00
|
|
|
mSuggestionStripView = (SuggestionStripView)view.findViewById(R.id.suggestion_strip_view);
|
2014-02-18 05:48:41 +00:00
|
|
|
if (hasSuggestionStripView()) {
|
2013-08-30 07:50:37 +00:00
|
|
|
mSuggestionStripView.setListener(this, view);
|
2013-12-13 08:09:16 +00:00
|
|
|
}
|
2014-08-25 03:08:55 +00:00
|
|
|
mInputLogic.setTextDecoratorUi(new TextDecoratorUi(this, view));
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2014-09-10 12:02:45 +00:00
|
|
|
@Override
|
|
|
|
public void setExtractView(final View view) {
|
|
|
|
final TextView prevExtractEditText = mExtractEditText;
|
|
|
|
super.setExtractView(view);
|
|
|
|
TextView nextExtractEditText = null;
|
|
|
|
if (view != null) {
|
|
|
|
final View extractEditText = view.findViewById(android.R.id.inputExtractEditText);
|
|
|
|
if (extractEditText instanceof TextView) {
|
|
|
|
nextExtractEditText = (TextView)extractEditText;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (prevExtractEditText == nextExtractEditText) {
|
|
|
|
return;
|
|
|
|
}
|
2014-10-06 10:32:01 +00:00
|
|
|
if (prevExtractEditText != null) {
|
2014-09-10 12:02:45 +00:00
|
|
|
prevExtractEditText.getViewTreeObserver().removeOnPreDrawListener(
|
|
|
|
mExtractTextViewPreDrawListener);
|
|
|
|
}
|
|
|
|
mExtractEditText = nextExtractEditText;
|
2014-10-06 10:32:01 +00:00
|
|
|
if (mExtractEditText != null) {
|
2014-09-10 12:02:45 +00:00
|
|
|
mExtractEditText.getViewTreeObserver().addOnPreDrawListener(
|
|
|
|
mExtractTextViewPreDrawListener);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-20 05:48:56 +00:00
|
|
|
void updateCursorAnchorInfo() {
|
|
|
|
// CursorAnchorInfo is used on L and later.
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
|
|
if (isFullscreenMode() && mExtractEditText != null) {
|
|
|
|
mInputLogic.onUpdateCursorAnchorInfo(
|
|
|
|
CursorAnchorInfoUtils.extractFromTextView(mExtractEditText));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-10 12:02:45 +00:00
|
|
|
private final ViewTreeObserver.OnPreDrawListener mExtractTextViewPreDrawListener =
|
|
|
|
new ViewTreeObserver.OnPreDrawListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreDraw() {
|
2014-10-20 05:48:56 +00:00
|
|
|
updateCursorAnchorInfo();
|
2014-09-10 12:02:45 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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);
|
2014-09-15 18:48:58 +00:00
|
|
|
mStatsUtilsManager.onStartInputView();
|
2011-09-29 08:27:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-09-12 04:03:44 +00:00
|
|
|
public void onFinishInputView(final boolean finishingInput) {
|
2014-09-10 02:05:31 +00:00
|
|
|
StatsUtils.onFinishInputView();
|
2011-09-29 08:27:48 +00:00
|
|
|
mHandler.onFinishInputView(finishingInput);
|
2014-09-15 18:48:58 +00:00
|
|
|
mStatsUtilsManager.onFinishInputView();
|
2014-09-04 20:42:10 +00:00
|
|
|
mGestureConsumer = GestureConsumer.NULL_GESTURE_CONSUMER;
|
2011-09-29 08:27:48 +00:00
|
|
|
}
|
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.
|
2014-10-14 06:11:39 +00:00
|
|
|
mSubtypeSwitcher.onSubtypeChanged(subtype);
|
2014-08-27 04:32:25 +00:00
|
|
|
mInputLogic.onSubtypeChanged(SubtypeLocaleUtils.getCombiningRulesExtraValue(subtype),
|
|
|
|
mSettings.getCurrent());
|
2012-08-22 01:19:56 +00:00
|
|
|
loadKeyboard();
|
2012-04-02 12:31:52 +00:00
|
|
|
}
|
|
|
|
|
2014-10-20 05:48:56 +00:00
|
|
|
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")
|
2014-10-20 05:48:56 +00:00
|
|
|
void onStartInputViewInternal(final EditorInfo editorInfo, final boolean restarting) {
|
2011-11-21 22:58:32 +00:00
|
|
|
super.onStartInputView(editorInfo, restarting);
|
2014-09-04 20:42:10 +00:00
|
|
|
// Switch to the null consumer to handle cases leading to early exit below, for which we
|
|
|
|
// also wouldn't be consuming gesture data.
|
|
|
|
mGestureConsumer = GestureConsumer.NULL_GESTURE_CONSUMER;
|
2014-08-06 09:34:26 +00:00
|
|
|
mRichImm.clearSubtypeCaches();
|
2014-10-16 09:14:30 +00:00
|
|
|
mSubtypeSwitcher.refreshSubtypeInfo();
|
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();
|
2014-08-06 09:34:59 +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()");
|
2014-07-17 01:41:46 +00:00
|
|
|
if (DebugFlags.DEBUG_ENABLED) {
|
2012-03-06 05:56:46 +00:00
|
|
|
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
|
|
|
}
|
2014-02-20 06:35:01 +00:00
|
|
|
Log.i(TAG, "Starting input. Cursor position = "
|
|
|
|
+ editorInfo.initialSelStart + "," + editorInfo.initialSelEnd);
|
2014-06-05 09:09:24 +00:00
|
|
|
// TODO: Consolidate these checks with {@link InputAttributes}.
|
2012-04-19 03:42:13 +00:00
|
|
|
if (InputAttributes.inPrivateImeOptions(null, NO_MICROPHONE_COMPAT, editorInfo)) {
|
2014-02-18 05:48:41 +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)) {
|
2014-02-18 05:48:41 +00:00
|
|
|
Log.w(TAG, "Deprecated private IME option specified: " + editorInfo.privateImeOptions);
|
2012-01-25 11:54:00 +00:00
|
|
|
Log.w(TAG, "Use EditorInfo.IME_FLAG_FORCE_ASCII flag instead");
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-09-04 20:42:10 +00:00
|
|
|
// Update to a gesture consumer with the current editor and IME state.
|
|
|
|
mGestureConsumer = GestureConsumer.newInstance(editorInfo,
|
|
|
|
mInputLogic.getPrivateCommandPerformer(),
|
2014-10-06 12:27:16 +00:00
|
|
|
Arrays.asList(mSubtypeSwitcher.getCurrentSubtypeLocales()),
|
2014-09-04 20:42:10 +00:00
|
|
|
switcher.getKeyboard());
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-08-06 09:34:59 +00:00
|
|
|
final boolean inputTypeChanged = !currentSettingsValues.isSameInputType(editorInfo);
|
2012-08-15 08:57:38 +00:00
|
|
|
final boolean isDifferentTextField = !restarting || inputTypeChanged;
|
2014-09-10 02:05:31 +00:00
|
|
|
|
|
|
|
StatsUtils.onStartInputView(editorInfo.inputType,
|
|
|
|
Settings.getInstance().getCurrent().mDisplayOrientation,
|
|
|
|
!isDifferentTextField);
|
|
|
|
|
2012-08-15 08:57:38 +00:00
|
|
|
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-01-18 06:28:21 +00:00
|
|
|
|
2014-09-05 11:07:23 +00:00
|
|
|
// ALERT: settings have not been reloaded and there is a chance they may be stale.
|
|
|
|
// In the practice, if it is, we should have gotten onConfigurationChanged so it should
|
|
|
|
// be fine, but this is horribly confusing and must be fixed AS SOON AS POSSIBLE.
|
2014-08-06 09:34:26 +00:00
|
|
|
|
2014-09-05 11:07:23 +00:00
|
|
|
// In some cases the input connection has not been reset yet and we can't access it. In
|
|
|
|
// this case we will need to call loadKeyboard() later, when it's accessible, so that we
|
|
|
|
// can go into the correct mode, so we need to do some housekeeping here.
|
|
|
|
final boolean needToCallLoadKeyboardLater;
|
2014-08-06 09:34:26 +00:00
|
|
|
final Suggest suggest = mInputLogic.mSuggest;
|
2014-09-05 11:07:23 +00:00
|
|
|
if (!currentSettingsValues.mHasHardwareKeyboard) {
|
|
|
|
// The app calling setText() has the effect of clearing the composing
|
|
|
|
// span, so we should reset our state unconditionally, even if restarting is true.
|
|
|
|
// We also tell the input logic about the combining rules for the current subtype, so
|
|
|
|
// it can adjust its combiners if needed.
|
|
|
|
mInputLogic.startInput(mSubtypeSwitcher.getCombiningRulesExtraValueOfCurrentSubtype(),
|
|
|
|
currentSettingsValues);
|
|
|
|
|
2014-10-02 06:08:16 +00:00
|
|
|
resetDictionaryFacilitatorIfNecessary();
|
2014-09-05 11:07:23 +00:00
|
|
|
|
|
|
|
// TODO[IL]: Can the following be moved to InputLogic#startInput?
|
|
|
|
if (!mInputLogic.mConnection.resetCachesUponCursorMoveAndReturnSuccess(
|
|
|
|
editorInfo.initialSelStart, editorInfo.initialSelEnd,
|
|
|
|
false /* shouldFinishComposition */)) {
|
|
|
|
// 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.
|
|
|
|
// We try resetting the caches up to 5 times before giving up.
|
|
|
|
mHandler.postResetCaches(isDifferentTextField, 5 /* remainingTries */);
|
|
|
|
// mLastSelection{Start,End} are reset later in this method, no need to do it here
|
|
|
|
needToCallLoadKeyboardLater = true;
|
|
|
|
} else {
|
2014-10-01 09:06:26 +00:00
|
|
|
// When rotating, and when input is starting again in a field from where the focus
|
|
|
|
// didn't move (the keyboard having been closed with the back key),
|
|
|
|
// initialSelStart and initialSelEnd sometimes are lying. Make a best effort to
|
|
|
|
// work around this bug.
|
2014-09-05 11:07:23 +00:00
|
|
|
mInputLogic.mConnection.tryFixLyingCursorPosition();
|
2014-10-01 09:32:02 +00:00
|
|
|
mHandler.postResumeSuggestions(true /* shouldDelay */);
|
2014-09-05 11:07:23 +00:00
|
|
|
needToCallLoadKeyboardLater = false;
|
|
|
|
}
|
2014-08-06 09:34:26 +00:00
|
|
|
} else {
|
2014-09-05 11:07:23 +00:00
|
|
|
// If we have a hardware keyboard we don't need to call loadKeyboard later anyway.
|
|
|
|
needToCallLoadKeyboardLater = false;
|
2014-08-06 09:34:26 +00:00
|
|
|
}
|
|
|
|
|
2014-08-06 09:34:59 +00:00
|
|
|
if (isDifferentTextField ||
|
|
|
|
!currentSettingsValues.hasSameOrientation(getResources().getConfiguration())) {
|
2014-08-06 09:34:26 +00:00
|
|
|
loadSettings();
|
|
|
|
}
|
2012-08-15 08:57:38 +00:00
|
|
|
if (isDifferentTextField) {
|
2012-08-07 02:48:10 +00:00
|
|
|
mainKeyboardView.closing();
|
2014-08-06 09:34:59 +00:00
|
|
|
currentSettingsValues = mSettings.getCurrent();
|
2013-07-30 03:57:35 +00:00
|
|
|
|
2014-08-06 09:34:26 +00:00
|
|
|
if (currentSettingsValues.mAutoCorrectionEnabledPerUserSettings) {
|
|
|
|
suggest.setAutoCorrectionThreshold(
|
|
|
|
currentSettingsValues.mAutoCorrectionThreshold);
|
|
|
|
}
|
|
|
|
|
2014-04-14 08:04:50 +00:00
|
|
|
switcher.loadKeyboard(editorInfo, currentSettingsValues, getCurrentAutoCapsState(),
|
|
|
|
getCurrentRecapitalizeState());
|
2014-09-05 11:07:23 +00:00
|
|
|
if (needToCallLoadKeyboardLater) {
|
|
|
|
// If we need to call loadKeyboard again later, we need to save its state now. The
|
|
|
|
// later call will be done in #retryResetCaches.
|
2013-10-08 07:33:27 +00:00
|
|
|
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.
|
2014-04-14 08:04:50 +00:00
|
|
|
switcher.resetKeyboardStateToAlphabet(getCurrentAutoCapsState(),
|
|
|
|
getCurrentRecapitalizeState());
|
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
|
2014-03-27 09:37:16 +00:00
|
|
|
switcher.requestUpdatingShiftState(getCurrentAutoCapsState(),
|
|
|
|
getCurrentRecapitalizeState());
|
2012-07-25 10:31:19 +00:00
|
|
|
}
|
2014-02-17 16:10:17 +00:00
|
|
|
// This will set the punctuation suggestions if next word suggestion is off;
|
|
|
|
// otherwise it will clear the suggestion strip.
|
2014-02-26 06:26:41 +00:00
|
|
|
setNeutralSuggestionStrip();
|
2012-07-05 06:26:43 +00:00
|
|
|
|
|
|
|
mHandler.cancelUpdateSuggestionStrip();
|
2011-01-18 06:28:21 +00:00
|
|
|
|
2014-03-25 06:35:20 +00:00
|
|
|
mainKeyboardView.setMainDictionaryAvailability(
|
2014-09-11 09:51:31 +00:00
|
|
|
mDictionaryFacilitator.hasAtLeastOneInitializedMainDictionary());
|
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
|
|
|
|
2014-06-13 09:39:29 +00:00
|
|
|
// Contextual dictionary should be updated for the current application.
|
|
|
|
mContextualDictionaryUpdater.onStartInputView(editorInfo.packageName);
|
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
|
|
|
}
|
|
|
|
|
2014-10-20 05:48:56 +00:00
|
|
|
void onFinishInputInternal() {
|
2009-03-13 22:11:42 +00:00
|
|
|
super.onFinishInput();
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2012-09-12 04:03:44 +00:00
|
|
|
final MainKeyboardView mainKeyboardView = mKeyboardSwitcher.getMainKeyboardView();
|
2012-08-07 02:48:10 +00:00
|
|
|
if (mainKeyboardView != null) {
|
|
|
|
mainKeyboardView.closing();
|
|
|
|
}
|
2010-01-16 20:21:23 +00:00
|
|
|
}
|
|
|
|
|
2014-10-20 05:48:56 +00:00
|
|
|
void onFinishInputViewInternal(final boolean finishingInput) {
|
2010-10-06 09:39:47 +00:00
|
|
|
super.onFinishInputView(finishingInput);
|
2014-09-05 11:07:23 +00:00
|
|
|
cleanupInternalStateForFinishInput();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void cleanupInternalStateForFinishInput() {
|
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();
|
2010-10-06 09:39:47 +00:00
|
|
|
}
|
|
|
|
|
2014-09-29 06:15:07 +00:00
|
|
|
protected void deallocateMemory() {
|
|
|
|
mKeyboardSwitcher.deallocateMemory();
|
|
|
|
}
|
|
|
|
|
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) {
|
2014-02-18 05:48:41 +00:00
|
|
|
Log.i(TAG, "onUpdateSelection: oss=" + oldSelStart + ", ose=" + oldSelEnd
|
|
|
|
+ ", nss=" + newSelStart + ", nse=" + newSelEnd
|
|
|
|
+ ", cs=" + composingSpanStart + ", ce=" + composingSpanEnd);
|
2010-01-16 20:21:23 +00:00
|
|
|
}
|
|
|
|
|
2014-11-05 08:41:15 +00:00
|
|
|
// This call happens whether our view is displayed or not, but if it's not then we should
|
|
|
|
// not attempt recorrection. This is true even with a hardware keyboard connected: if the
|
|
|
|
// view is not displayed we have no means of showing suggestions anyway, and if it is then
|
|
|
|
// we want to show suggestions anyway.
|
2014-09-05 11:07:23 +00:00
|
|
|
final SettingsValues settingsValues = mSettings.getCurrent();
|
2014-11-05 08:41:15 +00:00
|
|
|
if (isInputViewShown()
|
2014-10-15 05:02:32 +00:00
|
|
|
&& mInputLogic.onUpdateSelection(oldSelStart, oldSelEnd, newSelStart, newSelEnd,
|
|
|
|
settingsValues)) {
|
2014-03-27 09:37:16 +00:00
|
|
|
mKeyboardSwitcher.requestUpdatingShiftState(getCurrentAutoCapsState(),
|
|
|
|
getCurrentRecapitalizeState());
|
2011-06-08 07:47:19 +00:00
|
|
|
}
|
2011-05-06 09:27:24 +00:00
|
|
|
}
|
|
|
|
|
2014-10-21 08:07:47 +00:00
|
|
|
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
|
|
|
@Override
|
2014-08-13 10:33:01 +00:00
|
|
|
public void onUpdateCursorAnchorInfo(final CursorAnchorInfo info) {
|
2014-10-06 10:32:01 +00:00
|
|
|
if (isFullscreenMode()) {
|
2014-09-10 12:02:45 +00:00
|
|
|
return;
|
2014-08-13 10:33:01 +00:00
|
|
|
}
|
2014-10-07 15:07:40 +00:00
|
|
|
mInputLogic.onUpdateCursorAnchorInfo(CursorAnchorInfoCompatWrapper.wrap(info));
|
2014-08-13 10:33:01 +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() {
|
2014-07-22 17:18:38 +00:00
|
|
|
if (mSettings.getCurrent().needsToLookupSuggestions()) {
|
2013-12-20 07:34:38 +00:00
|
|
|
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) {
|
2014-07-22 17:18:38 +00:00
|
|
|
if (mSettings.getCurrent().needsToLookupSuggestions()) {
|
2013-12-20 07:34:38 +00:00
|
|
|
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() {
|
2011-07-27 22:32:25 +00:00
|
|
|
mKeyboardSwitcher.onHideWindow();
|
2010-08-20 05:35:02 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
if (TRACE) Debug.stopMethodTracing();
|
2014-04-14 02:31:44 +00:00
|
|
|
if (isShowingOptionDialog()) {
|
2009-03-26 00:39:38 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2014-02-18 02:48:00 +00:00
|
|
|
if (!mSettings.getCurrent().isApplicationSpecifiedCompletionsOn()) {
|
|
|
|
return;
|
|
|
|
}
|
2014-06-27 07:55:03 +00:00
|
|
|
// If we have an update request in flight, we need to cancel it so it does not override
|
|
|
|
// these completions.
|
|
|
|
mHandler.cancelUpdateSuggestionStrip();
|
2012-06-12 00:35:51 +00:00
|
|
|
if (applicationSpecifiedCompletions == null) {
|
2014-01-24 09:39:05 +00:00
|
|
|
setNeutralSuggestionStrip();
|
2012-06-12 00:35:51 +00:00
|
|
|
return;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2012-06-12 00:35:51 +00:00
|
|
|
|
|
|
|
final ArrayList<SuggestedWords.SuggestedWordInfo> applicationSuggestedWords =
|
|
|
|
SuggestedWords.getFromApplicationSpecifiedCompletions(
|
|
|
|
applicationSpecifiedCompletions);
|
2014-02-18 02:48:00 +00:00
|
|
|
final SuggestedWords suggestedWords = new SuggestedWords(applicationSuggestedWords,
|
|
|
|
null /* rawSuggestions */, false /* typedWordValid */, false /* willAutoCorrect */,
|
2014-08-26 09:54:08 +00:00
|
|
|
false /* isObsoleteSuggestions */,
|
2014-08-14 03:48:50 +00:00
|
|
|
SuggestedWords.INPUT_STYLE_APPLICATION_SPECIFIED /* inputStyle */);
|
2014-02-18 02:48:00 +00:00
|
|
|
// When in fullscreen mode, show completions generated by the application forcibly
|
2014-06-05 02:25:56 +00:00
|
|
|
setSuggestedWords(suggestedWords);
|
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);
|
2014-10-01 01:40:12 +00:00
|
|
|
// This method may be called before {@link #setInputView(View)}.
|
|
|
|
if (mInputView == null) {
|
|
|
|
return;
|
|
|
|
}
|
2014-09-03 10:36:35 +00:00
|
|
|
final SettingsValues settingsValues = mSettings.getCurrent();
|
2013-08-29 11:43:03 +00:00
|
|
|
final View visibleKeyboardView = mKeyboardSwitcher.getVisibleKeyboardView();
|
2014-02-18 05:48:41 +00:00
|
|
|
if (visibleKeyboardView == null || !hasSuggestionStripView()) {
|
2011-04-21 05:51:53 +00:00
|
|
|
return;
|
2012-08-07 02:48:10 +00:00
|
|
|
}
|
2014-08-25 09:26:11 +00:00
|
|
|
final int inputHeight = mInputView.getHeight();
|
2014-09-03 10:36:35 +00:00
|
|
|
final boolean hasHardwareKeyboard = settingsValues.mHasHardwareKeyboard;
|
2014-08-08 07:26:25 +00:00
|
|
|
if (hasHardwareKeyboard && visibleKeyboardView.getVisibility() == View.GONE) {
|
|
|
|
// If there is a hardware keyboard and a visible software keyboard view has been hidden,
|
|
|
|
// no visual element will be shown on the screen.
|
2014-11-04 02:48:57 +00:00
|
|
|
outInsets.contentTopInsets = inputHeight;
|
2014-08-25 09:26:11 +00:00
|
|
|
outInsets.visibleTopInsets = inputHeight;
|
2014-10-07 06:11:43 +00:00
|
|
|
mInsetsUpdater.setInsets(outInsets);
|
2014-08-08 07:26:25 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-08-25 09:26:11 +00:00
|
|
|
final int suggestionsHeight = (!mKeyboardSwitcher.isShowingEmojiPalettes()
|
|
|
|
&& mSuggestionStripView.getVisibility() == View.VISIBLE)
|
|
|
|
? mSuggestionStripView.getHeight() : 0;
|
|
|
|
final int visibleTopY = inputHeight - visibleKeyboardView.getHeight() - suggestionsHeight;
|
|
|
|
mSuggestionStripView.setMoreSuggestionsHeight(visibleTopY);
|
2014-11-04 02:48:57 +00:00
|
|
|
// Need to set expanded touchable region only if a keyboard view is being shown.
|
2013-08-29 11:43:03 +00:00
|
|
|
if (visibleKeyboardView.isShown()) {
|
2014-08-25 09:26:11 +00:00
|
|
|
final int touchLeft = 0;
|
|
|
|
final int touchTop = mKeyboardSwitcher.isShowingMoreKeysPanel() ? 0 : visibleTopY;
|
|
|
|
final int touchRight = visibleKeyboardView.getWidth();
|
|
|
|
final int touchBottom = inputHeight
|
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;
|
2014-08-25 09:26:11 +00:00
|
|
|
outInsets.touchableRegion.set(touchLeft, touchTop, touchRight, touchBottom);
|
2011-01-21 10:04:00 +00:00
|
|
|
}
|
2013-08-30 07:50:37 +00:00
|
|
|
outInsets.contentTopInsets = visibleTopY;
|
|
|
|
outInsets.visibleTopInsets = visibleTopY;
|
2014-10-07 06:11:43 +00:00
|
|
|
mInsetsUpdater.setInsets(outInsets);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2014-10-01 01:40:12 +00:00
|
|
|
public void startShowingInputView(final boolean needsToLoadKeyboard) {
|
2014-09-08 08:56:19 +00:00
|
|
|
mIsExecutingStartShowingInputView = true;
|
|
|
|
// This {@link #showWindow(boolean)} will eventually call back
|
|
|
|
// {@link #onEvaluateInputViewShown()}.
|
|
|
|
showWindow(true /* showInput */);
|
|
|
|
mIsExecutingStartShowingInputView = false;
|
2014-10-01 01:40:12 +00:00
|
|
|
if (needsToLoadKeyboard) {
|
|
|
|
loadKeyboard();
|
|
|
|
}
|
2014-09-08 08:56:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void stopShowingInputView() {
|
|
|
|
showWindow(false /* showInput */);
|
2014-08-08 07:26:25 +00:00
|
|
|
}
|
|
|
|
|
2014-10-01 01:40:12 +00:00
|
|
|
@Override
|
|
|
|
public boolean onShowInputRequested(final int flags, final boolean configChange) {
|
|
|
|
if (Settings.getInstance().getCurrent().mHasHardwareKeyboard) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return super.onShowInputRequested(flags, configChange);
|
|
|
|
}
|
|
|
|
|
2014-08-25 06:56:08 +00:00
|
|
|
@Override
|
2014-09-08 08:56:19 +00:00
|
|
|
public boolean onEvaluateInputViewShown() {
|
|
|
|
if (mIsExecutingStartShowingInputView) {
|
2014-08-25 06:56:08 +00:00
|
|
|
return true;
|
|
|
|
}
|
2014-09-08 08:56:19 +00:00
|
|
|
return super.onEvaluateInputViewShown();
|
2014-08-25 06:56:08 +00:00
|
|
|
}
|
|
|
|
|
2010-08-20 05:35:02 +00:00
|
|
|
@Override
|
|
|
|
public boolean onEvaluateFullscreenMode() {
|
2014-09-03 10:36:35 +00:00
|
|
|
final SettingsValues settingsValues = mSettings.getCurrent();
|
|
|
|
if (settingsValues.mHasHardwareKeyboard) {
|
2014-08-08 07:26:25 +00:00
|
|
|
// If there is a hardware keyboard, disable full screen mode.
|
|
|
|
return false;
|
|
|
|
}
|
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));
|
|
|
|
}
|
2014-09-08 08:56:19 +00:00
|
|
|
return false;
|
2011-09-20 05:57:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void updateFullscreenMode() {
|
2014-10-01 01:40:12 +00:00
|
|
|
super.updateFullscreenMode();
|
|
|
|
mInputLogic.onUpdateFullscreenMode(isFullscreenMode());
|
|
|
|
updateSoftInputWindowLayoutParameters();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateSoftInputWindowLayoutParameters() {
|
2014-08-25 09:26:11 +00:00
|
|
|
// Override layout parameters to expand {@link SoftInputWindow} to the entire screen.
|
2014-10-01 01:40:12 +00:00
|
|
|
// See {@link InputMethodService#setinputView(View)} and
|
2014-08-25 09:26:11 +00:00
|
|
|
// {@link SoftInputWindow#updateWidthHeight(WindowManager.LayoutParams)}.
|
|
|
|
final Window window = getWindow().getWindow();
|
|
|
|
ViewLayoutUtils.updateLayoutHeightOf(window, LayoutParams.MATCH_PARENT);
|
|
|
|
// This method may be called before {@link #setInputView(View)}.
|
|
|
|
if (mInputView != null) {
|
|
|
|
// In non-fullscreen mode, {@link InputView} and its parent inputArea should expand to
|
|
|
|
// the entire screen and be placed at the bottom of {@link SoftInputWindow}.
|
|
|
|
// In fullscreen mode, these shouldn't expand to the entire screen and should be
|
|
|
|
// coexistent with {@link #mExtractedArea} above.
|
|
|
|
// See {@link InputMethodService#setInputView(View) and
|
|
|
|
// com.android.internal.R.layout.input_method.xml.
|
|
|
|
final int layoutHeight = isFullscreenMode()
|
|
|
|
? LayoutParams.WRAP_CONTENT : LayoutParams.MATCH_PARENT;
|
|
|
|
final View inputArea = window.findViewById(android.R.id.inputArea);
|
|
|
|
ViewLayoutUtils.updateLayoutHeightOf(inputArea, layoutHeight);
|
|
|
|
ViewLayoutUtils.updateLayoutGravityOf(inputArea, Gravity.BOTTOM);
|
|
|
|
ViewLayoutUtils.updateLayoutHeightOf(mInputView, layoutHeight);
|
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|
|
|
|
|
2014-10-20 05:48:56 +00:00
|
|
|
int getCurrentAutoCapsState() {
|
2014-01-24 05:00:26 +00:00
|
|
|
return mInputLogic.getCurrentAutoCapsState(mSettings.getCurrent());
|
2010-01-24 15:34:07 +00:00
|
|
|
}
|
|
|
|
|
2014-10-20 05:48:56 +00:00
|
|
|
int getCurrentRecapitalizeState() {
|
2013-12-19 11:36:32 +00:00
|
|
|
return mInputLogic.getCurrentRecapitalizeState();
|
2013-04-15 13:00:29 +00:00
|
|
|
}
|
|
|
|
|
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);
|
2013-12-27 11:58:32 +00:00
|
|
|
}
|
2014-09-08 08:56:19 +00:00
|
|
|
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;
|
|
|
|
}
|
2014-08-18 11:43:40 +00:00
|
|
|
mDictionaryFacilitator.addWordToUserDictionary(this /* context */, word);
|
2014-08-25 03:08:55 +00:00
|
|
|
mInputLogic.onAddWordToUserDictionary();
|
2012-12-13 12:59:13 +00:00
|
|
|
}
|
|
|
|
|
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-20 15:54:02 +00:00
|
|
|
showOptionDialog(new ImportantNoticeDialog(this /* context */, this /* listener */));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Implement {@link ImportantNoticeDialog.ImportantNoticeDialogListener}
|
|
|
|
@Override
|
|
|
|
public void onClickSettingsOfImportantNoticeDialog(final int nextVersion) {
|
|
|
|
launchSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Implement {@link ImportantNoticeDialog.ImportantNoticeDialogListener}
|
|
|
|
@Override
|
2014-04-14 02:31:44 +00:00
|
|
|
public void onUserAcknowledgmentOfImportantNoticeDialog(final int nextVersion) {
|
2014-02-20 15:54:02 +00:00
|
|
|
setNeutralSuggestionStrip();
|
2014-02-19 04:17:36 +00:00
|
|
|
}
|
|
|
|
|
2013-12-19 11:56:37 +00:00
|
|
|
public void displaySettingsDialog() {
|
2014-02-18 05:48:41 +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;
|
2014-04-27 22:39:00 +00:00
|
|
|
if (shouldSwitchToOtherInputMethods()) {
|
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
|
|
|
}
|
|
|
|
|
2014-08-06 01:39:26 +00:00
|
|
|
// TODO: Instead of checking for alphabetic keyboard here, separate keycodes for
|
|
|
|
// alphabetic shift and shift while in symbol layout and get rid of this method.
|
|
|
|
private int getCodePointForKeyboard(final int codePoint) {
|
|
|
|
if (Constants.CODE_SHIFT == codePoint) {
|
|
|
|
final Keyboard currentKeyboard = mKeyboardSwitcher.getKeyboard();
|
|
|
|
if (null != currentKeyboard && currentKeyboard.mId.isAlphabetKeyboard()) {
|
|
|
|
return codePoint;
|
|
|
|
}
|
2014-10-20 05:48:56 +00:00
|
|
|
return Constants.CODE_SYMBOL_SHIFT;
|
2014-08-06 01:39:26 +00:00
|
|
|
}
|
2014-10-20 05:48:56 +00:00
|
|
|
return codePoint;
|
2014-08-06 01:39:26 +00:00
|
|
|
}
|
|
|
|
|
2010-12-30 08:19:55 +00:00
|
|
|
// Implementation of {@link KeyboardActionListener}.
|
2010-12-02 09:46:21 +00:00
|
|
|
@Override
|
2014-03-31 10:43:12 +00:00
|
|
|
public void onCodeInput(final int codePoint, final int x, final int y,
|
|
|
|
final boolean isKeyRepeat) {
|
2014-08-06 01:39:26 +00:00
|
|
|
// TODO: this processing does not belong inside LatinIME, the caller should be doing this.
|
2013-12-27 07:38:13 +00:00
|
|
|
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
|
2014-08-26 09:48:18 +00:00
|
|
|
// this transformation, it should be done already before calling onEvent.
|
2013-12-27 07:43:07 +00:00
|
|
|
final int keyX = mainKeyboardView.getKeyX(x);
|
|
|
|
final int keyY = mainKeyboardView.getKeyY(y);
|
2014-08-06 01:39:26 +00:00
|
|
|
final Event event = createSoftwareKeypressEvent(getCodePointForKeyboard(codePoint),
|
|
|
|
keyX, keyY, isKeyRepeat);
|
|
|
|
onEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This method is public for testability of LatinIME, but also in the future it should
|
|
|
|
// completely replace #onCodeInput.
|
2014-10-22 05:04:07 +00:00
|
|
|
public void onEvent(@Nonnull final Event event) {
|
2014-08-26 09:48:18 +00:00
|
|
|
if (Constants.CODE_SHORTCUT == event.mKeyCode) {
|
2014-01-15 02:27:27 +00:00
|
|
|
mSubtypeSwitcher.switchToShortcutIME(this);
|
|
|
|
}
|
2014-03-04 08:28:20 +00:00
|
|
|
final InputTransaction completeInputTransaction =
|
2014-03-12 07:41:45 +00:00
|
|
|
mInputLogic.onCodeInput(mSettings.getCurrent(), event,
|
2014-06-26 09:43:14 +00:00
|
|
|
mKeyboardSwitcher.getKeyboardShiftMode(),
|
|
|
|
mKeyboardSwitcher.getCurrentKeyboardScriptId(), mHandler);
|
2014-03-05 07:37:44 +00:00
|
|
|
updateStateAfterInputTransaction(completeInputTransaction);
|
2014-08-26 09:48:18 +00:00
|
|
|
mKeyboardSwitcher.onEvent(event, getCurrentAutoCapsState(), getCurrentRecapitalizeState());
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2014-03-12 07:41:45 +00:00
|
|
|
// A helper method to split the code point and the key code. Ultimately, they should not be
|
|
|
|
// squashed into the same variable, and this method should be removed.
|
2014-08-06 01:39:26 +00:00
|
|
|
// public for testing, as we don't want to copy the same logic into test code
|
2014-10-22 05:04:07 +00:00
|
|
|
@Nonnull
|
2014-08-06 01:39:26 +00:00
|
|
|
public static Event createSoftwareKeypressEvent(final int keyCodeOrCodePoint, final int keyX,
|
2014-03-31 10:43:12 +00:00
|
|
|
final int keyY, final boolean isKeyRepeat) {
|
2014-03-12 07:41:45 +00:00
|
|
|
final int keyCode;
|
|
|
|
final int codePoint;
|
|
|
|
if (keyCodeOrCodePoint <= 0) {
|
|
|
|
keyCode = keyCodeOrCodePoint;
|
|
|
|
codePoint = Event.NOT_A_CODE_POINT;
|
|
|
|
} else {
|
|
|
|
keyCode = Event.NOT_A_KEY_CODE;
|
|
|
|
codePoint = keyCodeOrCodePoint;
|
|
|
|
}
|
2014-03-31 10:43:12 +00:00
|
|
|
return Event.createSoftwareKeypressEvent(codePoint, keyCode, keyX, keyY, isKeyRepeat);
|
2014-03-12 07:41:45 +00:00
|
|
|
}
|
|
|
|
|
2013-09-10 07:16:25 +00:00
|
|
|
// Called from PointerTracker through the KeyboardActionListener interface
|
|
|
|
@Override
|
|
|
|
public void onTextInput(final String rawText) {
|
2014-03-19 06:59:49 +00:00
|
|
|
// TODO: have the keyboard pass the correct key code when we need it.
|
2014-08-26 09:48:18 +00:00
|
|
|
final Event event = Event.createSoftwareTextEvent(rawText, Constants.CODE_OUTPUT_TEXT);
|
2014-06-27 12:38:57 +00:00
|
|
|
final InputTransaction completeInputTransaction =
|
|
|
|
mInputLogic.onTextInput(mSettings.getCurrent(), event,
|
|
|
|
mKeyboardSwitcher.getKeyboardShiftMode(), mHandler);
|
|
|
|
updateStateAfterInputTransaction(completeInputTransaction);
|
2014-08-26 09:48:18 +00:00
|
|
|
mKeyboardSwitcher.onEvent(event, getCurrentAutoCapsState(), getCurrentRecapitalizeState());
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2012-07-04 06:24:59 +00:00
|
|
|
@Override
|
|
|
|
public void onStartBatchInput() {
|
2014-02-27 13:30:46 +00:00
|
|
|
mInputLogic.onStartBatchInput(mSettings.getCurrent(), mKeyboardSwitcher, mHandler);
|
2014-09-04 20:42:10 +00:00
|
|
|
mGestureConsumer.onGestureStarted(
|
2014-10-06 12:27:16 +00:00
|
|
|
Arrays.asList(mSubtypeSwitcher.getCurrentSubtypeLocales()),
|
2014-09-04 20:42:10 +00:00
|
|
|
mKeyboardSwitcher.getKeyboard());
|
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) {
|
2014-03-03 05:19:52 +00:00
|
|
|
mInputLogic.onEndBatchInput(batchPointers);
|
2014-09-04 20:42:10 +00:00
|
|
|
mGestureConsumer.onGestureCompleted(batchPointers);
|
2013-12-20 11:45:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCancelBatchInput() {
|
2013-12-25 12:04:27 +00:00
|
|
|
mInputLogic.onCancelBatchInput(mHandler);
|
2014-09-04 20:42:10 +00:00
|
|
|
mGestureConsumer.onGestureCanceled();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-11-02 14:54:20 +00:00
|
|
|
* To be called after the InputLogic has gotten a chance to act on the suggested words by the
|
|
|
|
* IME for the full gesture, possibly updating the TextView to reflect the first suggestion.
|
2014-09-04 20:42:10 +00:00
|
|
|
* <p>
|
|
|
|
* This method must be run on the UI Thread.
|
2014-11-02 14:54:20 +00:00
|
|
|
* @param suggestedWords suggested words by the IME for the full gesture.
|
2014-09-04 20:42:10 +00:00
|
|
|
*/
|
|
|
|
public void onTailBatchInputResultShown(final SuggestedWords suggestedWords) {
|
|
|
|
mGestureConsumer.onImeSuggestionsProcessed(suggestedWords,
|
|
|
|
mInputLogic.getComposingStart(), mInputLogic.getComposingLength());
|
2012-09-12 04:03:44 +00:00
|
|
|
}
|
|
|
|
|
2013-12-24 09:07:20 +00:00
|
|
|
// This method must run on the UI Thread.
|
2014-10-29 03:56:42 +00:00
|
|
|
void showGesturePreviewAndSuggestionStrip(@Nonnull final SuggestedWords suggestedWords,
|
2012-09-12 04:03:44 +00:00
|
|
|
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();
|
2014-10-29 03:56:42 +00:00
|
|
|
mainKeyboardView.showGestureFloatingPreviewText(suggestedWords,
|
|
|
|
dismissGestureFloatingPreviewText /* dismissDelayed */);
|
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.
|
2014-04-14 08:04:50 +00:00
|
|
|
mKeyboardSwitcher.onFinishSlidingInput(getCurrentAutoCapsState(),
|
|
|
|
getCurrentRecapitalizeState());
|
2013-05-14 03:25:21 +00:00
|
|
|
}
|
|
|
|
|
2012-07-09 03:54:42 +00:00
|
|
|
// Called from PointerTracker through the KeyboardActionListener interface
|
2010-12-02 09:46:21 +00:00
|
|
|
@Override
|
2010-12-20 07:13:57 +00:00
|
|
|
public void 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-24 14:11:48 +00:00
|
|
|
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() {
|
2014-02-18 05:48:41 +00:00
|
|
|
if (!hasSuggestionStripView()) {
|
|
|
|
return;
|
2013-12-19 08:57:10 +00:00
|
|
|
}
|
2014-02-18 05:48:41 +00:00
|
|
|
mSuggestionStripView.dismissAddToDictionaryHint();
|
2013-12-19 08:57:10 +00:00
|
|
|
}
|
|
|
|
|
2014-06-05 02:25:56 +00:00
|
|
|
private void setSuggestedWords(final SuggestedWords suggestedWords) {
|
2014-08-25 03:08:55 +00:00
|
|
|
final SettingsValues currentSettingsValues = mSettings.getCurrent();
|
2014-10-07 10:29:05 +00:00
|
|
|
mInputLogic.setSuggestedWords(suggestedWords);
|
2014-02-28 07:40:16 +00:00
|
|
|
// TODO: Modify this when we support suggestions with hard keyboard
|
2014-02-18 05:48:41 +00:00
|
|
|
if (!hasSuggestionStripView()) {
|
2014-02-17 16:10:17 +00:00
|
|
|
return;
|
2014-01-24 12:50:46 +00:00
|
|
|
}
|
2014-02-28 07:40:16 +00:00
|
|
|
if (!onEvaluateInputViewShown()) {
|
|
|
|
return;
|
|
|
|
}
|
2014-06-05 09:09:24 +00:00
|
|
|
|
2014-06-05 02:25:56 +00:00
|
|
|
final boolean shouldShowImportantNotice =
|
|
|
|
ImportantNoticeUtils.shouldShowImportantNotice(this);
|
2014-06-11 01:33:31 +00:00
|
|
|
final boolean shouldShowSuggestionCandidates =
|
|
|
|
currentSettingsValues.mInputAttributes.mShouldShowSuggestions
|
2014-07-22 17:18:38 +00:00
|
|
|
&& currentSettingsValues.isSuggestionsEnabledPerUserSettings();
|
2014-06-05 02:25:56 +00:00
|
|
|
final boolean shouldShowSuggestionsStripUnlessPassword = shouldShowImportantNotice
|
|
|
|
|| currentSettingsValues.mShowsVoiceInputKey
|
2014-06-11 01:33:31 +00:00
|
|
|
|| shouldShowSuggestionCandidates
|
2014-06-05 02:25:56 +00:00
|
|
|
|| currentSettingsValues.isApplicationSpecifiedCompletionsOn();
|
|
|
|
final boolean shouldShowSuggestionsStrip = shouldShowSuggestionsStripUnlessPassword
|
|
|
|
&& !currentSettingsValues.mInputAttributes.mIsPasswordField;
|
|
|
|
mSuggestionStripView.updateVisibility(shouldShowSuggestionsStrip, isFullscreenMode());
|
|
|
|
if (!shouldShowSuggestionsStrip) {
|
2014-02-28 07:40:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-05 02:25:56 +00:00
|
|
|
final boolean isEmptyApplicationSpecifiedCompletions =
|
|
|
|
currentSettingsValues.isApplicationSpecifiedCompletionsOn()
|
|
|
|
&& suggestedWords.isEmpty();
|
2014-09-22 03:40:41 +00:00
|
|
|
final boolean noSuggestionsFromDictionaries = suggestedWords.isEmpty()
|
2014-05-23 17:28:00 +00:00
|
|
|
|| suggestedWords.isPunctuationSuggestions()
|
2014-06-05 02:25:56 +00:00
|
|
|
|| isEmptyApplicationSpecifiedCompletions;
|
2014-09-17 08:16:59 +00:00
|
|
|
final boolean isBeginningOfSentencePrediction = (suggestedWords.mInputStyle
|
|
|
|
== SuggestedWords.INPUT_STYLE_BEGINNING_OF_SENTENCE_PREDICTION);
|
|
|
|
final boolean noSuggestionsToOverrideImportantNotice = noSuggestionsFromDictionaries
|
|
|
|
|| isBeginningOfSentencePrediction;
|
|
|
|
if (shouldShowImportantNotice && noSuggestionsToOverrideImportantNotice) {
|
2014-06-11 01:33:31 +00:00
|
|
|
if (mSuggestionStripView.maybeShowImportantNoticeTitle()) {
|
|
|
|
return;
|
|
|
|
}
|
2014-02-17 16:10:17 +00:00
|
|
|
}
|
2014-06-05 02:25:56 +00:00
|
|
|
|
2014-07-22 17:18:38 +00:00
|
|
|
if (currentSettingsValues.isSuggestionsEnabledPerUserSettings()
|
2014-09-17 08:16:59 +00:00
|
|
|
|| currentSettingsValues.isApplicationSpecifiedCompletionsOn()
|
|
|
|
// We should clear the contextual strip if there is no suggestion from dictionaries.
|
|
|
|
|| noSuggestionsFromDictionaries) {
|
2014-02-17 16:10:17 +00:00
|
|
|
mSuggestionStripView.setSuggestions(suggestedWords,
|
2014-10-06 12:27:16 +00:00
|
|
|
mSubtypeSwitcher.getCurrentSubtype().isRtlSubtype());
|
2014-02-17 16:10:17 +00:00
|
|
|
}
|
2010-01-16 20:21:23 +00:00
|
|
|
}
|
|
|
|
|
2013-12-25 12:04:27 +00:00
|
|
|
// TODO[IL]: Move this out of LatinIME.
|
2014-08-14 03:48:50 +00:00
|
|
|
public void getSuggestedWords(final int inputStyle, 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();
|
2014-03-25 06:35:20 +00:00
|
|
|
if (keyboard == null) {
|
2014-09-22 03:40:41 +00:00
|
|
|
callback.onGetSuggestedWords(SuggestedWords.getEmptyInstance());
|
2013-08-29 06:15:49 +00:00
|
|
|
return;
|
2012-10-03 04:01:52 +00:00
|
|
|
}
|
2014-06-13 07:50:05 +00:00
|
|
|
mInputLogic.getSuggestedWords(mSettings.getCurrent(), keyboard.getProximityInfo(),
|
2014-08-14 03:48:50 +00:00
|
|
|
mKeyboardSwitcher.getKeyboardShiftMode(), inputStyle, sequenceNumber, callback);
|
2013-04-19 02:48:14 +00:00
|
|
|
}
|
|
|
|
|
2014-01-24 14:11:48 +00:00
|
|
|
@Override
|
2014-09-22 03:40:41 +00:00
|
|
|
public void showSuggestionStrip(final SuggestedWords suggestedWords) {
|
|
|
|
if (suggestedWords.isEmpty()) {
|
2014-02-03 06:03:41 +00:00
|
|
|
setNeutralSuggestionStrip();
|
|
|
|
} else {
|
2014-06-05 02:25:56 +00:00
|
|
|
setSuggestedWords(suggestedWords);
|
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,
|
2014-09-22 03:40:41 +00:00
|
|
|
suggestedWords.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
|
2014-06-26 09:43:14 +00:00
|
|
|
public void pickSuggestionManually(final SuggestedWordInfo suggestionInfo) {
|
2014-03-04 09:06:50 +00:00
|
|
|
final InputTransaction completeInputTransaction = mInputLogic.onPickSuggestionManually(
|
2014-06-26 09:43:14 +00:00
|
|
|
mSettings.getCurrent(), suggestionInfo,
|
|
|
|
mKeyboardSwitcher.getKeyboardShiftMode(),
|
|
|
|
mKeyboardSwitcher.getCurrentKeyboardScriptId(),
|
|
|
|
mHandler);
|
2014-03-05 07:37:44 +00:00
|
|
|
updateStateAfterInputTransaction(completeInputTransaction);
|
2014-01-29 07:15:12 +00:00
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
|
2014-01-29 07:15:12 +00:00
|
|
|
@Override
|
2014-10-08 05:40:03 +00:00
|
|
|
public void suggestAddingToDictionary(final String word, final boolean isFromSuggestionStrip) {
|
2014-02-18 05:48:41 +00:00
|
|
|
if (!hasSuggestionStripView()) {
|
|
|
|
return;
|
|
|
|
}
|
2014-08-18 11:43:40 +00:00
|
|
|
final String wordToShow;
|
|
|
|
if (CapsModeUtils.isAutoCapsMode(mInputLogic.mLastComposedWord.mCapitalizedMode)) {
|
2014-10-07 05:29:14 +00:00
|
|
|
wordToShow = word.toLowerCase(mDictionaryFacilitator.getMostProbableLocale());
|
2014-08-18 11:43:40 +00:00
|
|
|
} else {
|
|
|
|
wordToShow = word;
|
|
|
|
}
|
2014-10-08 05:40:03 +00:00
|
|
|
mSuggestionStripView.showAddToDictionaryHint(wordToShow,
|
|
|
|
isFromSuggestionStrip /* shouldShowWordToSave */);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
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();
|
2014-02-17 16:10:17 +00:00
|
|
|
final SuggestedWords neutralSuggestions = currentSettings.mBigramPredictionEnabled
|
2014-09-22 03:40:41 +00:00
|
|
|
? SuggestedWords.getEmptyInstance()
|
|
|
|
: currentSettings.mSpacingAndPunctuations.mSuggestPuncList;
|
2014-06-05 02:25:56 +00:00
|
|
|
setSuggestedWords(neutralSuggestions);
|
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.
|
2014-04-14 08:04:50 +00:00
|
|
|
mKeyboardSwitcher.loadKeyboard(getCurrentInputEditorInfo(), mSettings.getCurrent(),
|
|
|
|
getCurrentAutoCapsState(), getCurrentRecapitalizeState());
|
2011-11-04 03:36:38 +00:00
|
|
|
}
|
2009-10-12 20:48:35 +00:00
|
|
|
}
|
|
|
|
|
2014-03-05 07:37:44 +00:00
|
|
|
/**
|
|
|
|
* After an input transaction has been executed, some state must be updated. This includes
|
|
|
|
* the shift state of the keyboard and suggestions. This method looks at the finished
|
|
|
|
* inputTransaction to find out what is necessary and updates the state accordingly.
|
|
|
|
* @param inputTransaction The transaction that has been executed.
|
|
|
|
*/
|
|
|
|
private void updateStateAfterInputTransaction(final InputTransaction inputTransaction) {
|
|
|
|
switch (inputTransaction.getRequiredShiftUpdate()) {
|
2014-03-04 09:06:50 +00:00
|
|
|
case InputTransaction.SHIFT_UPDATE_LATER:
|
|
|
|
mHandler.postUpdateShiftState();
|
|
|
|
break;
|
|
|
|
case InputTransaction.SHIFT_UPDATE_NOW:
|
2014-03-27 09:37:16 +00:00
|
|
|
mKeyboardSwitcher.requestUpdatingShiftState(getCurrentAutoCapsState(),
|
|
|
|
getCurrentRecapitalizeState());
|
2014-03-04 09:06:50 +00:00
|
|
|
break;
|
|
|
|
default: // SHIFT_NO_UPDATE
|
|
|
|
}
|
2014-03-05 07:37:44 +00:00
|
|
|
if (inputTransaction.requiresUpdateSuggestions()) {
|
2014-08-14 03:48:50 +00:00
|
|
|
final int inputStyle;
|
|
|
|
if (inputTransaction.mEvent.isSuggestionStripPress()) {
|
|
|
|
// Suggestion strip press: no input.
|
|
|
|
inputStyle = SuggestedWords.INPUT_STYLE_NONE;
|
|
|
|
} else if (inputTransaction.mEvent.isGesture()) {
|
|
|
|
inputStyle = SuggestedWords.INPUT_STYLE_TAIL_BATCH;
|
|
|
|
} else {
|
|
|
|
inputStyle = SuggestedWords.INPUT_STYLE_TYPING;
|
|
|
|
}
|
|
|
|
mHandler.postUpdateSuggestionStrip(inputStyle);
|
2014-03-05 07:37:44 +00:00
|
|
|
}
|
2014-06-27 12:38:57 +00:00
|
|
|
if (inputTransaction.didAffectContents()) {
|
|
|
|
mSubtypeState.setCurrentSubtypeHasBeenUsed();
|
|
|
|
}
|
2014-03-04 09:06:50 +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) {
|
2014-04-14 08:04:50 +00:00
|
|
|
mKeyboardSwitcher.onPressKey(primaryCode, isSinglePointer, getCurrentAutoCapsState(),
|
|
|
|
getCurrentRecapitalizeState());
|
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) {
|
2014-04-14 06:33:30 +00:00
|
|
|
mKeyboardSwitcher.onReleaseKey(primaryCode, withSliding, getCurrentAutoCapsState(),
|
|
|
|
getCurrentRecapitalizeState());
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2014-03-14 11:11:01 +00:00
|
|
|
private HardwareEventDecoder getHardwareKeyEventDecoder(final int deviceId) {
|
|
|
|
final HardwareEventDecoder decoder = mHardwareEventDecoders.get(deviceId);
|
|
|
|
if (null != decoder) return decoder;
|
|
|
|
// TODO: create the decoder according to the specification
|
|
|
|
final HardwareEventDecoder newDecoder = new HardwareKeyboardEventDecoder(deviceId);
|
|
|
|
mHardwareEventDecoders.put(deviceId, newDecoder);
|
|
|
|
return newDecoder;
|
|
|
|
}
|
|
|
|
|
2012-12-06 11:35:59 +00:00
|
|
|
// Hooks for hardware keyboard
|
|
|
|
@Override
|
2014-03-14 11:11:01 +00:00
|
|
|
public boolean onKeyDown(final int keyCode, final KeyEvent keyEvent) {
|
2014-10-27 02:59:57 +00:00
|
|
|
// TODO: This should be processed in {@link InputLogic}.
|
|
|
|
mEmojiAltPhysicalKeyDetector.onKeyDown(keyEvent);
|
2014-07-17 02:22:35 +00:00
|
|
|
if (!ProductionFlags.IS_HARDWARE_KEYBOARD_SUPPORTED) {
|
2014-03-14 11:11:01 +00:00
|
|
|
return super.onKeyDown(keyCode, keyEvent);
|
|
|
|
}
|
|
|
|
final Event event = getHardwareKeyEventDecoder(
|
|
|
|
keyEvent.getDeviceId()).decodeHardwareKey(keyEvent);
|
|
|
|
// If the event is not handled by LatinIME, we just pass it to the parent implementation.
|
|
|
|
// If it's handled, we return true because we did handle it.
|
|
|
|
if (event.isHandled()) {
|
|
|
|
mInputLogic.onCodeInput(mSettings.getCurrent(), event,
|
2014-06-26 09:43:14 +00:00
|
|
|
mKeyboardSwitcher.getKeyboardShiftMode(),
|
|
|
|
// TODO: this is not necessarily correct for a hardware keyboard right now
|
|
|
|
mKeyboardSwitcher.getCurrentKeyboardScriptId(),
|
|
|
|
mHandler);
|
2013-01-17 10:27:39 +00:00
|
|
|
return true;
|
|
|
|
}
|
2014-03-14 11:11:01 +00:00
|
|
|
return super.onKeyDown(keyCode, keyEvent);
|
2012-12-06 11:35:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-08-08 07:26:25 +00:00
|
|
|
public boolean onKeyUp(final int keyCode, final KeyEvent keyEvent) {
|
2014-10-27 02:59:57 +00:00
|
|
|
// TODO: This should be processed in {@link InputLogic}.
|
|
|
|
mEmojiAltPhysicalKeyDetector.onKeyUp(keyEvent);
|
2014-08-08 07:26:25 +00:00
|
|
|
if (!ProductionFlags.IS_HARDWARE_KEYBOARD_SUPPORTED) {
|
|
|
|
return super.onKeyUp(keyCode, keyEvent);
|
|
|
|
}
|
|
|
|
final long keyIdentifier = keyEvent.getDeviceId() << 32 + keyEvent.getKeyCode();
|
2013-12-18 09:08:35 +00:00
|
|
|
if (mInputLogic.mCurrentlyPressedHardwareKeys.remove(keyIdentifier)) {
|
2013-01-17 10:27:39 +00:00
|
|
|
return true;
|
|
|
|
}
|
2014-08-08 07:26:25 +00:00
|
|
|
return super.onKeyUp(keyCode, keyEvent);
|
2012-12-06 11:35:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
2014-05-16 13:19:41 +00:00
|
|
|
private final BroadcastReceiver mConnectivityAndRingerModeChangeReceiver =
|
|
|
|
new BroadcastReceiver() {
|
2009-03-13 22:11:42 +00:00
|
|
|
@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
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-10-20 05:48:56 +00:00
|
|
|
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();
|
|
|
|
}
|
2014-07-23 21:12:27 +00:00
|
|
|
final Intent intent = new Intent();
|
|
|
|
intent.setClass(LatinIME.this, SettingsActivity.class);
|
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);
|
2014-07-23 21:12:27 +00:00
|
|
|
intent.putExtra(SettingsActivity.EXTRA_SHOW_HOME_AS_UP, false);
|
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);
|
2014-07-23 21:12:27 +00:00
|
|
|
// TODO: Should use new string "Select active input modes".
|
|
|
|
final CharSequence languageSelectionTitle = getString(R.string.language_selection_title);
|
2011-01-25 02:48:06 +00:00
|
|
|
final CharSequence[] items = new CharSequence[] {
|
2014-07-23 21:12:27 +00:00
|
|
|
languageSelectionTitle,
|
|
|
|
getString(ApplicationUtils.getActivityTitleResId(this, SettingsActivity.class))
|
2011-01-25 02:48:06 +00:00
|
|
|
};
|
2014-10-20 05:48:56 +00:00
|
|
|
final String imeId = mRichImm.getInputMethodIdOfThisIme();
|
2014-02-19 04:17:36 +00:00
|
|
|
final OnClickListener listener = new 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(
|
2014-10-20 05:48:56 +00:00
|
|
|
imeId,
|
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);
|
2014-07-23 21:12:27 +00:00
|
|
|
intent.putExtra(Intent.EXTRA_TITLE, languageSelectionTitle);
|
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
|
|
|
};
|
2014-04-04 05:14:47 +00:00
|
|
|
final AlertDialog.Builder builder = new AlertDialog.Builder(
|
|
|
|
DialogUtils.getPlatformDialogThemeContext(this));
|
|
|
|
builder.setItems(items, listener).setTitle(title);
|
2014-04-14 02:31:44 +00:00
|
|
|
final AlertDialog dialog = builder.create();
|
|
|
|
dialog.setCancelable(true /* cancelable */);
|
|
|
|
dialog.setCanceledOnTouchOutside(true /* cancelable */);
|
|
|
|
showOptionDialog(dialog);
|
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}.
|
2014-02-19 04:17:36 +00:00
|
|
|
private void showOptionDialog(final AlertDialog dialog) {
|
2012-08-07 02:48:10 +00:00
|
|
|
final IBinder windowToken = mKeyboardSwitcher.getMainKeyboardView().getWindowToken();
|
|
|
|
if (windowToken == null) {
|
|
|
|
return;
|
|
|
|
}
|
2012-04-02 13:25:08 +00:00
|
|
|
|
|
|
|
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
|
2014-02-18 08:07:46 +00:00
|
|
|
/* package for test */ SuggestedWords getSuggestedWordsForTest() {
|
2013-12-18 07:53:54 +00:00
|
|
|
// 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-02-20 13:20:43 +00:00
|
|
|
/* package for test */ void waitForLoadingDictionaries(final long timeout, final TimeUnit unit)
|
2014-01-08 09:59:43 +00:00
|
|
|
throws InterruptedException {
|
2014-05-23 00:30:55 +00:00
|
|
|
mDictionaryFacilitator.waitForLoadingDictionariesForTesting(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) {
|
2014-03-25 06:35:20 +00:00
|
|
|
final SettingsValues settingsValues = mSettings.getCurrent();
|
2014-10-07 06:56:45 +00:00
|
|
|
mDictionaryFacilitator.resetDictionaries(this, new Locale[] { locale },
|
2014-03-25 06:35:20 +00:00
|
|
|
settingsValues.mUseContactsDict, settingsValues.mUsePersonalizedDicts,
|
|
|
|
false /* forceReloadMainDictionary */, this /* listener */);
|
2013-08-15 07:31:29 +00:00
|
|
|
}
|
|
|
|
|
2014-02-20 13:20:43 +00:00
|
|
|
// DO NOT USE THIS for any other purpose than testing.
|
|
|
|
@UsedForTesting
|
|
|
|
/* package for test */ void clearPersonalizedDictionariesForTest() {
|
2014-05-23 00:30:55 +00:00
|
|
|
mDictionaryFacilitator.clearUserHistoryDictionary();
|
|
|
|
mDictionaryFacilitator.clearPersonalizationDictionary();
|
2014-02-20 13:20:43 +00:00
|
|
|
}
|
|
|
|
|
2014-04-24 22:36:21 +00:00
|
|
|
@UsedForTesting
|
2014-05-23 07:10:36 +00:00
|
|
|
/* package for test */ List<InputMethodSubtype> getEnabledSubtypesForTest() {
|
|
|
|
return (mRichImm != null) ? mRichImm.getMyEnabledInputMethodSubtypeList(
|
|
|
|
true /* allowsImplicitlySelectedSubtypes */) : new ArrayList<InputMethodSubtype>();
|
2014-04-24 22:36:21 +00:00
|
|
|
}
|
|
|
|
|
2014-02-04 12:29:09 +00:00
|
|
|
public void dumpDictionaryForDebug(final String dictName) {
|
2014-10-07 05:29:14 +00:00
|
|
|
if (!mDictionaryFacilitator.isActive()) {
|
2014-10-02 06:08:16 +00:00
|
|
|
resetDictionaryFacilitatorIfNecessary();
|
2014-02-04 12:29:09 +00:00
|
|
|
}
|
2014-05-23 00:30:55 +00:00
|
|
|
mDictionaryFacilitator.dumpDictionaryForDebug(dictName);
|
2014-02-04 12:29:09 +00:00
|
|
|
}
|
|
|
|
|
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();
|
2014-02-12 13:53:15 +00:00
|
|
|
p.println(settingsValues.dump());
|
2013-12-20 06:00:44 +00:00
|
|
|
// TODO: Dump all settings values
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2014-04-27 22:39:00 +00:00
|
|
|
|
|
|
|
public boolean shouldSwitchToOtherInputMethods() {
|
|
|
|
// TODO: Revisit here to reorganize the settings. Probably we can/should use different
|
|
|
|
// strategy once the implementation of
|
|
|
|
// {@link InputMethodManager#shouldOfferSwitchingToNextInputMethod} is defined well.
|
|
|
|
final boolean fallbackValue = mSettings.getCurrent().mIncludesOtherImesInLanguageSwitchList;
|
|
|
|
final IBinder token = getWindow().getWindow().getAttributes().token;
|
|
|
|
if (token == null) {
|
|
|
|
return fallbackValue;
|
|
|
|
}
|
|
|
|
return mRichImm.shouldOfferSwitchingToNextInputMethod(token, fallbackValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean shouldShowLanguageSwitchKey() {
|
|
|
|
// TODO: Revisit here to reorganize the settings. Probably we can/should use different
|
|
|
|
// strategy once the implementation of
|
|
|
|
// {@link InputMethodManager#shouldOfferSwitchingToNextInputMethod} is defined well.
|
|
|
|
final boolean fallbackValue = mSettings.getCurrent().isLanguageSwitchKeyEnabled();
|
|
|
|
final IBinder token = getWindow().getWindow().getAttributes().token;
|
|
|
|
if (token == null) {
|
|
|
|
return fallbackValue;
|
|
|
|
}
|
|
|
|
return mRichImm.shouldOfferSwitchingToNextInputMethod(token, fallbackValue);
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|