2009-03-13 22:11:42 +00:00
|
|
|
/*
|
2010-03-26 22:07:10 +00:00
|
|
|
* Copyright (C) 2008 The Android Open Source Project
|
2010-09-15 04:03:34 +00:00
|
|
|
*
|
2009-03-13 22:11:42 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
|
|
* use this file except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at
|
2010-01-28 18:09:44 +00:00
|
|
|
*
|
2009-03-13 22:11:42 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2010-01-28 18:09:44 +00:00
|
|
|
*
|
2009-03-13 22:11:42 +00:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations under
|
|
|
|
* the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package com.android.inputmethod.latin;
|
|
|
|
|
|
|
|
import android.app.AlertDialog;
|
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.DialogInterface;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.IntentFilter;
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.content.res.Configuration;
|
2009-10-12 20:48:35 +00:00
|
|
|
import android.content.res.Resources;
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.inputmethodservice.InputMethodService;
|
|
|
|
import android.media.AudioManager;
|
2011-01-26 14:13:18 +00:00
|
|
|
import android.net.ConnectivityManager;
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.os.Debug;
|
|
|
|
import android.os.Message;
|
|
|
|
import android.os.SystemClock;
|
2010-09-27 03:55:21 +00:00
|
|
|
import android.preference.PreferenceActivity;
|
2009-03-13 22:11:42 +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;
|
2010-02-11 01:45:35 +00:00
|
|
|
import android.view.HapticFeedbackConstants;
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.view.KeyEvent;
|
|
|
|
import android.view.View;
|
2010-11-21 03:43:10 +00:00
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.view.ViewParent;
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.view.inputmethod.CompletionInfo;
|
|
|
|
import android.view.inputmethod.EditorInfo;
|
2010-01-16 20:21:23 +00:00
|
|
|
import android.view.inputmethod.ExtractedText;
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.view.inputmethod.InputConnection;
|
2011-05-23 09:30:21 +00:00
|
|
|
|
2011-05-18 00:03:25 +00:00
|
|
|
import com.android.inputmethod.accessibility.AccessibilityUtils;
|
2011-05-23 09:30:21 +00:00
|
|
|
import com.android.inputmethod.compat.CompatUtils;
|
|
|
|
import com.android.inputmethod.compat.EditorInfoCompatUtils;
|
|
|
|
import com.android.inputmethod.compat.InputConnectionCompatUtils;
|
|
|
|
import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
|
|
|
|
import com.android.inputmethod.compat.InputMethodServiceCompatWrapper;
|
|
|
|
import com.android.inputmethod.compat.InputTypeCompatUtils;
|
2011-05-24 11:30:30 +00:00
|
|
|
import com.android.inputmethod.compat.SuggestionSpanUtils;
|
2011-09-19 05:51:31 +00:00
|
|
|
import com.android.inputmethod.compat.VibratorCompatWrapper;
|
2011-05-23 09:30:21 +00:00
|
|
|
import com.android.inputmethod.deprecated.LanguageSwitcherProxy;
|
|
|
|
import com.android.inputmethod.deprecated.VoiceProxy;
|
2011-07-25 22:55:12 +00:00
|
|
|
import com.android.inputmethod.keyboard.Key;
|
2011-05-23 09:30:21 +00:00
|
|
|
import com.android.inputmethod.keyboard.Keyboard;
|
|
|
|
import com.android.inputmethod.keyboard.KeyboardActionListener;
|
2011-12-07 12:27:59 +00:00
|
|
|
import com.android.inputmethod.keyboard.KeyboardId;
|
2011-05-23 09:30:21 +00:00
|
|
|
import com.android.inputmethod.keyboard.KeyboardSwitcher;
|
2011-07-04 11:58:58 +00:00
|
|
|
import com.android.inputmethod.keyboard.KeyboardView;
|
2011-08-23 08:57:02 +00:00
|
|
|
import com.android.inputmethod.keyboard.LatinKeyboardView;
|
2011-12-16 02:26:14 +00:00
|
|
|
import com.android.inputmethod.latin.suggestions.SuggestionsView;
|
2009-03-13 22:11:42 +00:00
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
import java.io.FileDescriptor;
|
|
|
|
import java.io.PrintWriter;
|
|
|
|
import java.util.Locale;
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
/**
|
|
|
|
* Input method implementation for Qwerty'ish keyboard.
|
|
|
|
*/
|
2011-06-09 05:22:37 +00:00
|
|
|
public class LatinIME extends InputMethodServiceCompatWrapper implements KeyboardActionListener,
|
2011-09-01 05:54:28 +00:00
|
|
|
SuggestionsView.Listener {
|
2011-02-23 08:23:29 +00:00
|
|
|
private static final String TAG = LatinIME.class.getSimpleName();
|
2010-11-21 01:36:37 +00:00
|
|
|
private static final boolean TRACE = false;
|
2011-05-27 12:41:13 +00:00
|
|
|
private static boolean DEBUG;
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2011-02-23 08:23:29 +00:00
|
|
|
/**
|
|
|
|
* The private IME option used to indicate that no microphone should be
|
|
|
|
* shown for a given text field. For instance, this is specified by the
|
|
|
|
* search dialog when the dialog is already showing a voice search button.
|
|
|
|
*
|
|
|
|
* @deprecated Use {@link LatinIME#IME_OPTION_NO_MICROPHONE} with package name prefixed.
|
|
|
|
*/
|
2011-03-19 04:22:28 +00:00
|
|
|
@SuppressWarnings("dep-ann")
|
2011-02-23 08:23:29 +00:00
|
|
|
public static final String IME_OPTION_NO_MICROPHONE_COMPAT = "nm";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The private IME option used to indicate that no microphone should be
|
|
|
|
* shown for a given text field. For instance, this is specified by the
|
|
|
|
* search dialog when the dialog is already showing a voice search button.
|
|
|
|
*/
|
2011-02-23 11:31:08 +00:00
|
|
|
public static final String IME_OPTION_NO_MICROPHONE = "noMicrophoneKey";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The private IME option used to indicate that no settings key should be
|
|
|
|
* shown for a given text field.
|
|
|
|
*/
|
|
|
|
public static final String IME_OPTION_NO_SETTINGS_KEY = "noSettingsKey";
|
2011-02-23 08:23:29 +00:00
|
|
|
|
2011-08-23 08:27:48 +00:00
|
|
|
/**
|
|
|
|
* The private IME option used to indicate that the given text field needs
|
|
|
|
* ASCII code points input.
|
2012-01-17 05:38:00 +00:00
|
|
|
*
|
|
|
|
* @deprecated Use {@link EditorInfo#IME_FLAG_FORCE_ASCII}.
|
2011-08-23 08:27:48 +00:00
|
|
|
*/
|
2012-01-17 05:38:00 +00:00
|
|
|
@SuppressWarnings("dep-ann")
|
2011-08-23 08:27:48 +00:00
|
|
|
public static final String IME_OPTION_FORCE_ASCII = "forceAscii";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The subtype extra value used to indicate that the subtype keyboard layout is capable for
|
|
|
|
* typing ASCII characters.
|
|
|
|
*/
|
|
|
|
public static final String SUBTYPE_EXTRA_VALUE_ASCII_CAPABLE = "AsciiCapable";
|
|
|
|
|
2011-10-03 09:34:34 +00:00
|
|
|
/**
|
|
|
|
* The subtype extra value used to indicate that the subtype keyboard layout supports touch
|
|
|
|
* position correction.
|
|
|
|
*/
|
|
|
|
public static final String SUBTYPE_EXTRA_VALUE_SUPPORT_TOUCH_POSITION_CORRECTION =
|
|
|
|
"SupportTouchPositionCorrection";
|
2011-08-31 12:20:52 +00:00
|
|
|
/**
|
|
|
|
* The subtype extra value used to indicate that the subtype keyboard layout should be loaded
|
|
|
|
* from the specified locale.
|
|
|
|
*/
|
|
|
|
public static final String SUBTYPE_EXTRA_VALUE_KEYBOARD_LOCALE = "KeyboardLocale";
|
|
|
|
|
2011-01-21 10:04:00 +00:00
|
|
|
private static final int EXTENDED_TOUCHABLE_REGION_HEIGHT = 100;
|
2010-10-27 09:05:27 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
// How many continuous deletes at which to start deleting at a higher speed.
|
|
|
|
private static final int DELETE_ACCELERATE_AT = 20;
|
|
|
|
// Key events coming any faster than this are long-presses.
|
2009-07-28 23:33:36 +00:00
|
|
|
private static final int QUICK_PRESS = 200;
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2011-09-29 08:27:48 +00:00
|
|
|
private static final int PENDING_IMS_CALLBACK_DURATION = 800;
|
2011-07-29 17:45:37 +00:00
|
|
|
|
2011-03-14 18:46:15 +00:00
|
|
|
/**
|
|
|
|
* The name of the scheme used by the Package Manager to warn of a new package installation,
|
|
|
|
* replacement or removal.
|
|
|
|
*/
|
|
|
|
private static final String SCHEME_PACKAGE = "package";
|
|
|
|
|
2011-12-09 11:16:57 +00:00
|
|
|
// TODO: migrate this to SettingsValues
|
2010-11-13 10:09:30 +00:00
|
|
|
private int mSuggestionVisibility;
|
|
|
|
private static final int SUGGESTION_VISIBILILTY_SHOW_VALUE
|
|
|
|
= R.string.prefs_suggestion_visibility_show_value;
|
|
|
|
private static final int SUGGESTION_VISIBILILTY_SHOW_ONLY_PORTRAIT_VALUE
|
|
|
|
= R.string.prefs_suggestion_visibility_show_only_portrait_value;
|
|
|
|
private static final int SUGGESTION_VISIBILILTY_HIDE_VALUE
|
|
|
|
= R.string.prefs_suggestion_visibility_hide_value;
|
|
|
|
|
|
|
|
private static final int[] SUGGESTION_VISIBILITY_VALUE_ARRAY = new int[] {
|
|
|
|
SUGGESTION_VISIBILILTY_SHOW_VALUE,
|
|
|
|
SUGGESTION_VISIBILILTY_SHOW_ONLY_PORTRAIT_VALUE,
|
|
|
|
SUGGESTION_VISIBILILTY_HIDE_VALUE
|
|
|
|
};
|
|
|
|
|
2011-10-25 12:14:33 +00:00
|
|
|
// Magic space: a space that should disappear on space/apostrophe insertion, move after the
|
|
|
|
// punctuation on punctuation insertion, and become a real space on alpha char insertion.
|
2011-11-14 09:59:17 +00:00
|
|
|
// Weak space: a space that should be swapped only by suggestion strip punctuation.
|
2011-10-25 12:14:33 +00:00
|
|
|
// Double space: the state where the user pressed space twice quickly, which LatinIME
|
|
|
|
// resolved as period-space. Undoing this converts the period to a space.
|
|
|
|
// Swap punctuation: the state where a (weak or magic) space and a punctuation from the
|
|
|
|
// suggestion strip have just been swapped. Undoing this swaps them back.
|
|
|
|
private static final int SPACE_STATE_NONE = 0;
|
|
|
|
private static final int SPACE_STATE_DOUBLE = 1;
|
|
|
|
private static final int SPACE_STATE_SWAP_PUNCTUATION = 2;
|
|
|
|
private static final int SPACE_STATE_MAGIC = 3;
|
|
|
|
private static final int SPACE_STATE_WEAK = 4;
|
|
|
|
|
|
|
|
// Current space state of the input method. This can be any of the above constants.
|
|
|
|
private int mSpaceState;
|
2011-10-24 09:00:05 +00:00
|
|
|
|
2011-12-08 13:10:40 +00:00
|
|
|
private SettingsValues mSettingsValues;
|
2011-12-16 05:21:50 +00:00
|
|
|
private InputAttributes mInputAttributes;
|
2011-05-10 06:51:43 +00:00
|
|
|
|
2011-10-12 09:50:51 +00:00
|
|
|
private View mExtractArea;
|
2011-09-02 12:03:18 +00:00
|
|
|
private View mKeyPreviewBackingView;
|
2011-09-01 05:54:28 +00:00
|
|
|
private View mSuggestionsContainer;
|
|
|
|
private SuggestionsView mSuggestionsView;
|
2009-03-13 22:11:42 +00:00
|
|
|
private Suggest mSuggest;
|
2010-12-11 08:06:24 +00:00
|
|
|
private CompletionInfo[] mApplicationSpecifiedCompletions;
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2011-03-18 05:49:06 +00:00
|
|
|
private InputMethodManagerCompatWrapper mImm;
|
2011-01-20 13:52:02 +00:00
|
|
|
private Resources mResources;
|
|
|
|
private SharedPreferences mPrefs;
|
2010-11-13 08:46:45 +00:00
|
|
|
private KeyboardSwitcher mKeyboardSwitcher;
|
2010-11-17 07:35:35 +00:00
|
|
|
private SubtypeSwitcher mSubtypeSwitcher;
|
2011-03-25 00:42:09 +00:00
|
|
|
private VoiceProxy mVoiceProxy;
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
private UserDictionary mUserDictionary;
|
2010-08-20 05:35:02 +00:00
|
|
|
private UserBigramDictionary mUserBigramDictionary;
|
2011-07-14 22:57:26 +00:00
|
|
|
private UserUnigramDictionary mUserUnigramDictionary;
|
2011-11-18 06:24:49 +00:00
|
|
|
private boolean mIsUserDictionaryAvailable;
|
2009-10-12 20:48:35 +00:00
|
|
|
|
2012-01-26 07:37:47 +00:00
|
|
|
private LastComposedWord mLastComposedWord = LastComposedWord.NOT_A_COMPOSED_WORD;
|
2011-07-12 01:29:29 +00:00
|
|
|
private WordComposer mWordComposer = new WordComposer();
|
2010-11-21 01:36:37 +00:00
|
|
|
|
2010-11-25 00:20:28 +00:00
|
|
|
private int mCorrectionMode;
|
2012-01-24 06:45:32 +00:00
|
|
|
|
2010-08-20 05:35:02 +00:00
|
|
|
// Keep track of the last selection range to decide if we need to show word alternatives
|
2012-01-24 06:45:32 +00:00
|
|
|
private static final int NOT_A_CURSOR_POSITION = -1;
|
|
|
|
private int mLastSelectionStart = NOT_A_CURSOR_POSITION;
|
|
|
|
private int mLastSelectionEnd = NOT_A_CURSOR_POSITION;
|
2010-08-20 05:35:02 +00:00
|
|
|
|
2011-06-08 07:47:19 +00:00
|
|
|
// Whether we are expecting an onUpdateSelection event to fire. If it does when we don't
|
|
|
|
// "expect" it, it means the user actually moved the cursor.
|
|
|
|
private boolean mExpectingUpdateSelection;
|
2009-03-13 22:11:42 +00:00
|
|
|
private int mDeleteCount;
|
|
|
|
private long mLastKeyTime;
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
private AudioManager mAudioManager;
|
2011-05-10 06:51:43 +00:00
|
|
|
private boolean mSilentModeOn; // System-wide current configuration
|
2009-03-13 22:11:42 +00:00
|
|
|
|
2011-09-19 05:51:31 +00:00
|
|
|
private VibratorCompatWrapper mVibrator;
|
|
|
|
|
2011-03-25 00:42:09 +00:00
|
|
|
// TODO: Move this flag to VoiceProxy
|
2010-03-07 15:27:05 +00:00
|
|
|
private boolean mConfigurationChanging;
|
2010-01-16 20:21:23 +00:00
|
|
|
|
2011-07-21 06:57:00 +00:00
|
|
|
// Member variables for remembering the current device orientation.
|
|
|
|
private int mDisplayOrientation;
|
|
|
|
|
2011-03-14 18:46:15 +00:00
|
|
|
// Object for reacting to adding/removing a dictionary pack.
|
|
|
|
private BroadcastReceiver mDictionaryPackInstallReceiver =
|
|
|
|
new DictionaryPackInstallBroadcastReceiver(this);
|
|
|
|
|
2010-04-01 13:28:52 +00:00
|
|
|
// Keeps track of most recently inserted text (multi-character key) for reverting
|
|
|
|
private CharSequence mEnteredText;
|
|
|
|
|
2011-10-12 09:07:09 +00:00
|
|
|
private final ComposingStateManager mComposingStateManager =
|
2011-10-17 02:27:31 +00:00
|
|
|
ComposingStateManager.getInstance();
|
2011-10-12 09:07:09 +00:00
|
|
|
|
2011-06-24 18:54:11 +00:00
|
|
|
public final UIHandler mHandler = new UIHandler(this);
|
2010-11-16 09:07:06 +00:00
|
|
|
|
2011-06-24 18:54:11 +00:00
|
|
|
public static class UIHandler extends StaticInnerHandlerWrapper<LatinIME> {
|
2010-11-16 09:07:06 +00:00
|
|
|
private static final int MSG_UPDATE_SUGGESTIONS = 0;
|
2011-10-03 09:12:53 +00:00
|
|
|
private static final int MSG_UPDATE_SHIFT_STATE = 1;
|
|
|
|
private static final int MSG_VOICE_RESULTS = 2;
|
|
|
|
private static final int MSG_FADEOUT_LANGUAGE_ON_SPACEBAR = 3;
|
|
|
|
private static final int MSG_DISMISS_LANGUAGE_ON_SPACEBAR = 4;
|
|
|
|
private static final int MSG_SPACE_TYPED = 5;
|
2011-11-22 00:41:01 +00:00
|
|
|
private static final int MSG_SET_BIGRAM_PREDICTIONS = 6;
|
|
|
|
private static final int MSG_PENDING_IMS_CALLBACK = 7;
|
2011-11-16 23:58:42 +00:00
|
|
|
|
2011-11-18 05:45:49 +00:00
|
|
|
private int mDelayBeforeFadeoutLanguageOnSpacebar;
|
|
|
|
private int mDelayUpdateSuggestions;
|
|
|
|
private int mDelayUpdateShiftState;
|
|
|
|
private int mDurationOfFadeoutLanguageOnSpacebar;
|
|
|
|
private float mFinalFadeoutFactorOfLanguageOnSpacebar;
|
|
|
|
private long mDoubleSpacesTurnIntoPeriodTimeout;
|
2011-07-21 06:57:00 +00:00
|
|
|
|
2011-06-24 18:54:11 +00:00
|
|
|
public UIHandler(LatinIME outerInstance) {
|
|
|
|
super(outerInstance);
|
2011-11-18 05:45:49 +00:00
|
|
|
}
|
2011-11-16 23:58:42 +00:00
|
|
|
|
2011-11-18 05:45:49 +00:00
|
|
|
public void onCreate() {
|
|
|
|
final Resources res = getOuterInstance().getResources();
|
2011-11-16 23:58:42 +00:00
|
|
|
mDelayBeforeFadeoutLanguageOnSpacebar = res.getInteger(
|
|
|
|
R.integer.config_delay_before_fadeout_language_on_spacebar);
|
|
|
|
mDelayUpdateSuggestions =
|
|
|
|
res.getInteger(R.integer.config_delay_update_suggestions);
|
|
|
|
mDelayUpdateShiftState =
|
|
|
|
res.getInteger(R.integer.config_delay_update_shift_state);
|
|
|
|
mDurationOfFadeoutLanguageOnSpacebar = res.getInteger(
|
|
|
|
R.integer.config_duration_of_fadeout_language_on_spacebar);
|
|
|
|
mFinalFadeoutFactorOfLanguageOnSpacebar = res.getInteger(
|
|
|
|
R.integer.config_final_fadeout_percentage_of_language_on_spacebar) / 100.0f;
|
|
|
|
mDoubleSpacesTurnIntoPeriodTimeout = res.getInteger(
|
|
|
|
R.integer.config_double_spaces_turn_into_period_timeout);
|
2011-06-24 18:54:11 +00:00
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
@Override
|
|
|
|
public void handleMessage(Message msg) {
|
2011-06-24 18:54:11 +00:00
|
|
|
final LatinIME latinIme = getOuterInstance();
|
|
|
|
final KeyboardSwitcher switcher = latinIme.mKeyboardSwitcher;
|
2011-08-23 08:57:02 +00:00
|
|
|
final LatinKeyboardView inputView = switcher.getKeyboardView();
|
2009-03-13 22:11:42 +00:00
|
|
|
switch (msg.what) {
|
2010-11-16 09:07:06 +00:00
|
|
|
case MSG_UPDATE_SUGGESTIONS:
|
2011-06-24 18:54:11 +00:00
|
|
|
latinIme.updateSuggestions();
|
2010-11-16 09:07:06 +00:00
|
|
|
break;
|
|
|
|
case MSG_UPDATE_SHIFT_STATE:
|
2011-01-12 11:33:54 +00:00
|
|
|
switcher.updateShiftState();
|
2010-11-16 09:07:06 +00:00
|
|
|
break;
|
2011-04-22 07:16:30 +00:00
|
|
|
case MSG_SET_BIGRAM_PREDICTIONS:
|
2011-06-24 18:54:11 +00:00
|
|
|
latinIme.updateBigramPredictions();
|
2011-04-20 02:50:05 +00:00
|
|
|
break;
|
2010-11-16 09:07:06 +00:00
|
|
|
case MSG_VOICE_RESULTS:
|
2011-06-24 18:54:11 +00:00
|
|
|
latinIme.mVoiceProxy.handleVoiceResults(latinIme.preferCapitalization()
|
2011-01-12 11:33:54 +00:00
|
|
|
|| (switcher.isAlphabetMode() && switcher.isShiftedOrShiftLocked()));
|
|
|
|
break;
|
|
|
|
case MSG_FADEOUT_LANGUAGE_ON_SPACEBAR:
|
2011-12-15 07:09:42 +00:00
|
|
|
setSpacebarTextFadeFactor(inputView,
|
|
|
|
(1.0f + mFinalFadeoutFactorOfLanguageOnSpacebar) / 2,
|
2011-12-17 23:36:16 +00:00
|
|
|
(Keyboard)msg.obj);
|
2011-01-12 11:33:54 +00:00
|
|
|
sendMessageDelayed(obtainMessage(MSG_DISMISS_LANGUAGE_ON_SPACEBAR, msg.obj),
|
2011-11-16 23:58:42 +00:00
|
|
|
mDurationOfFadeoutLanguageOnSpacebar);
|
2011-01-12 11:33:54 +00:00
|
|
|
break;
|
|
|
|
case MSG_DISMISS_LANGUAGE_ON_SPACEBAR:
|
2011-12-15 07:09:42 +00:00
|
|
|
setSpacebarTextFadeFactor(inputView, mFinalFadeoutFactorOfLanguageOnSpacebar,
|
2011-12-17 23:36:16 +00:00
|
|
|
(Keyboard)msg.obj);
|
2010-11-16 09:07:06 +00:00
|
|
|
break;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
}
|
2010-11-16 09:07:06 +00:00
|
|
|
|
|
|
|
public void postUpdateSuggestions() {
|
|
|
|
removeMessages(MSG_UPDATE_SUGGESTIONS);
|
2011-11-16 23:58:42 +00:00
|
|
|
sendMessageDelayed(obtainMessage(MSG_UPDATE_SUGGESTIONS), mDelayUpdateSuggestions);
|
2010-11-16 09:07:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void cancelUpdateSuggestions() {
|
|
|
|
removeMessages(MSG_UPDATE_SUGGESTIONS);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasPendingUpdateSuggestions() {
|
|
|
|
return hasMessages(MSG_UPDATE_SUGGESTIONS);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void postUpdateShiftKeyState() {
|
|
|
|
removeMessages(MSG_UPDATE_SHIFT_STATE);
|
2011-11-16 23:58:42 +00:00
|
|
|
sendMessageDelayed(obtainMessage(MSG_UPDATE_SHIFT_STATE), mDelayUpdateShiftState);
|
2010-11-16 09:07:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void cancelUpdateShiftState() {
|
|
|
|
removeMessages(MSG_UPDATE_SHIFT_STATE);
|
|
|
|
}
|
|
|
|
|
2011-04-22 07:16:30 +00:00
|
|
|
public void postUpdateBigramPredictions() {
|
|
|
|
removeMessages(MSG_SET_BIGRAM_PREDICTIONS);
|
2011-11-16 23:58:42 +00:00
|
|
|
sendMessageDelayed(obtainMessage(MSG_SET_BIGRAM_PREDICTIONS), mDelayUpdateSuggestions);
|
2011-04-20 02:50:05 +00:00
|
|
|
}
|
|
|
|
|
2011-04-22 07:16:30 +00:00
|
|
|
public void cancelUpdateBigramPredictions() {
|
|
|
|
removeMessages(MSG_SET_BIGRAM_PREDICTIONS);
|
2011-04-20 02:50:05 +00:00
|
|
|
}
|
|
|
|
|
2010-11-16 09:07:06 +00:00
|
|
|
public void updateVoiceResults() {
|
|
|
|
sendMessage(obtainMessage(MSG_VOICE_RESULTS));
|
|
|
|
}
|
2011-01-12 11:33:54 +00:00
|
|
|
|
2011-12-15 07:09:42 +00:00
|
|
|
private static void setSpacebarTextFadeFactor(LatinKeyboardView inputView,
|
2011-12-17 23:36:16 +00:00
|
|
|
float fadeFactor, Keyboard oldKeyboard) {
|
2011-12-15 07:09:42 +00:00
|
|
|
if (inputView == null) return;
|
|
|
|
final Keyboard keyboard = inputView.getKeyboard();
|
2011-12-17 23:36:16 +00:00
|
|
|
if (keyboard == oldKeyboard) {
|
2011-12-17 23:13:36 +00:00
|
|
|
inputView.updateSpacebar(fadeFactor,
|
|
|
|
SubtypeSwitcher.getInstance().needsToDisplayLanguage(
|
|
|
|
keyboard.mId.mLocale));
|
2011-12-15 07:09:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-17 14:47:52 +00:00
|
|
|
public void startDisplayLanguageOnSpacebar(boolean localeChanged) {
|
2011-06-24 18:54:11 +00:00
|
|
|
final LatinIME latinIme = getOuterInstance();
|
2011-01-12 11:33:54 +00:00
|
|
|
removeMessages(MSG_FADEOUT_LANGUAGE_ON_SPACEBAR);
|
|
|
|
removeMessages(MSG_DISMISS_LANGUAGE_ON_SPACEBAR);
|
2011-08-23 08:57:02 +00:00
|
|
|
final LatinKeyboardView inputView = latinIme.mKeyboardSwitcher.getKeyboardView();
|
2011-01-12 11:33:54 +00:00
|
|
|
if (inputView != null) {
|
2011-12-17 23:36:16 +00:00
|
|
|
final Keyboard keyboard = latinIme.mKeyboardSwitcher.getKeyboard();
|
2011-04-22 02:09:48 +00:00
|
|
|
// The language is always displayed when the delay is negative.
|
|
|
|
final boolean needsToDisplayLanguage = localeChanged
|
2011-11-16 23:58:42 +00:00
|
|
|
|| mDelayBeforeFadeoutLanguageOnSpacebar < 0;
|
2011-01-12 11:33:54 +00:00
|
|
|
// The language is never displayed when the delay is zero.
|
2011-11-16 23:58:42 +00:00
|
|
|
if (mDelayBeforeFadeoutLanguageOnSpacebar != 0) {
|
2011-12-15 07:09:42 +00:00
|
|
|
setSpacebarTextFadeFactor(inputView,
|
|
|
|
needsToDisplayLanguage ? 1.0f : mFinalFadeoutFactorOfLanguageOnSpacebar,
|
|
|
|
keyboard);
|
2011-05-10 06:51:43 +00:00
|
|
|
}
|
2011-04-22 02:09:48 +00:00
|
|
|
// The fadeout animation will start when the delay is positive.
|
2011-11-16 23:58:42 +00:00
|
|
|
if (localeChanged && mDelayBeforeFadeoutLanguageOnSpacebar > 0) {
|
2011-01-12 11:33:54 +00:00
|
|
|
sendMessageDelayed(obtainMessage(MSG_FADEOUT_LANGUAGE_ON_SPACEBAR, keyboard),
|
2011-11-16 23:58:42 +00:00
|
|
|
mDelayBeforeFadeoutLanguageOnSpacebar);
|
2011-01-12 11:33:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-03-02 07:40:10 +00:00
|
|
|
|
|
|
|
public void startDoubleSpacesTimer() {
|
|
|
|
removeMessages(MSG_SPACE_TYPED);
|
2011-11-16 23:58:42 +00:00
|
|
|
sendMessageDelayed(obtainMessage(MSG_SPACE_TYPED), mDoubleSpacesTurnIntoPeriodTimeout);
|
2011-03-02 07:40:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void cancelDoubleSpacesTimer() {
|
|
|
|
removeMessages(MSG_SPACE_TYPED);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isAcceptingDoubleSpaces() {
|
|
|
|
return hasMessages(MSG_SPACE_TYPED);
|
|
|
|
}
|
2011-07-21 06:57:00 +00:00
|
|
|
|
2011-09-29 08:27:48 +00:00
|
|
|
// Working variables for the following methods.
|
|
|
|
private boolean mIsOrientationChanging;
|
2012-01-24 02:58:07 +00:00
|
|
|
private boolean mPendingSuccessiveImsCallback;
|
2011-09-29 08:27:48 +00:00
|
|
|
private boolean mHasPendingStartInput;
|
|
|
|
private boolean mHasPendingFinishInputView;
|
|
|
|
private boolean mHasPendingFinishInput;
|
2011-11-21 22:58:32 +00:00
|
|
|
private EditorInfo mAppliedEditorInfo;
|
2011-09-29 08:27:48 +00:00
|
|
|
|
|
|
|
public void startOrientationChanging() {
|
2011-10-27 08:03:03 +00:00
|
|
|
removeMessages(MSG_PENDING_IMS_CALLBACK);
|
|
|
|
resetPendingImsCallback();
|
2011-09-29 08:27:48 +00:00
|
|
|
mIsOrientationChanging = true;
|
2011-07-29 17:45:37 +00:00
|
|
|
final LatinIME latinIme = getOuterInstance();
|
2011-11-29 05:12:49 +00:00
|
|
|
if (latinIme.isInputViewShown()) {
|
|
|
|
latinIme.mKeyboardSwitcher.saveKeyboardState();
|
|
|
|
}
|
2011-09-29 08:27:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void resetPendingImsCallback() {
|
|
|
|
mHasPendingFinishInputView = false;
|
|
|
|
mHasPendingFinishInput = false;
|
|
|
|
mHasPendingStartInput = false;
|
|
|
|
}
|
|
|
|
|
2011-11-21 22:58:32 +00:00
|
|
|
private void executePendingImsCallback(LatinIME latinIme, EditorInfo editorInfo,
|
2011-09-29 08:27:48 +00:00
|
|
|
boolean restarting) {
|
|
|
|
if (mHasPendingFinishInputView)
|
|
|
|
latinIme.onFinishInputViewInternal(mHasPendingFinishInput);
|
|
|
|
if (mHasPendingFinishInput)
|
|
|
|
latinIme.onFinishInputInternal();
|
|
|
|
if (mHasPendingStartInput)
|
2011-11-21 22:58:32 +00:00
|
|
|
latinIme.onStartInputInternal(editorInfo, restarting);
|
2011-09-29 08:27:48 +00:00
|
|
|
resetPendingImsCallback();
|
|
|
|
}
|
|
|
|
|
2011-11-21 22:58:32 +00:00
|
|
|
public void onStartInput(EditorInfo editorInfo, boolean restarting) {
|
2011-09-29 08:27:48 +00:00
|
|
|
if (hasMessages(MSG_PENDING_IMS_CALLBACK)) {
|
|
|
|
// Typically this is the second onStartInput after orientation changed.
|
|
|
|
mHasPendingStartInput = true;
|
|
|
|
} else {
|
|
|
|
if (mIsOrientationChanging && restarting) {
|
|
|
|
// This is the first onStartInput after orientation changed.
|
|
|
|
mIsOrientationChanging = false;
|
2012-01-24 02:58:07 +00:00
|
|
|
mPendingSuccessiveImsCallback = true;
|
2011-09-29 08:27:48 +00:00
|
|
|
}
|
|
|
|
final LatinIME latinIme = getOuterInstance();
|
2011-11-21 22:58:32 +00:00
|
|
|
executePendingImsCallback(latinIme, editorInfo, restarting);
|
|
|
|
latinIme.onStartInputInternal(editorInfo, restarting);
|
2011-07-29 17:45:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-21 22:58:32 +00:00
|
|
|
public void onStartInputView(EditorInfo editorInfo, boolean restarting) {
|
2011-12-07 12:27:59 +00:00
|
|
|
if (hasMessages(MSG_PENDING_IMS_CALLBACK)
|
|
|
|
&& KeyboardId.equivalentEditorInfoForKeyboard(editorInfo, mAppliedEditorInfo)) {
|
2011-11-21 22:58:32 +00:00
|
|
|
// Typically this is the second onStartInputView after orientation changed.
|
|
|
|
resetPendingImsCallback();
|
|
|
|
} else {
|
2012-01-24 02:58:07 +00:00
|
|
|
if (mPendingSuccessiveImsCallback) {
|
2011-11-21 22:58:32 +00:00
|
|
|
// This is the first onStartInputView after orientation changed.
|
2012-01-24 02:58:07 +00:00
|
|
|
mPendingSuccessiveImsCallback = false;
|
2011-11-21 22:58:32 +00:00
|
|
|
resetPendingImsCallback();
|
|
|
|
sendMessageDelayed(obtainMessage(MSG_PENDING_IMS_CALLBACK),
|
|
|
|
PENDING_IMS_CALLBACK_DURATION);
|
|
|
|
}
|
|
|
|
final LatinIME latinIme = getOuterInstance();
|
|
|
|
executePendingImsCallback(latinIme, editorInfo, restarting);
|
|
|
|
latinIme.onStartInputViewInternal(editorInfo, restarting);
|
|
|
|
mAppliedEditorInfo = editorInfo;
|
|
|
|
}
|
2011-09-29 08:27:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void onFinishInputView(boolean finishingInput) {
|
|
|
|
if (hasMessages(MSG_PENDING_IMS_CALLBACK)) {
|
|
|
|
// Typically this is the first onFinishInputView after orientation changed.
|
|
|
|
mHasPendingFinishInputView = true;
|
|
|
|
} else {
|
|
|
|
final LatinIME latinIme = getOuterInstance();
|
|
|
|
latinIme.onFinishInputViewInternal(finishingInput);
|
2011-11-21 22:58:32 +00:00
|
|
|
mAppliedEditorInfo = null;
|
2011-07-21 06:57:00 +00:00
|
|
|
}
|
|
|
|
}
|
2011-09-27 09:47:54 +00:00
|
|
|
|
2011-09-29 08:27:48 +00:00
|
|
|
public void onFinishInput() {
|
|
|
|
if (hasMessages(MSG_PENDING_IMS_CALLBACK)) {
|
|
|
|
// Typically this is the first onFinishInput after orientation changed.
|
|
|
|
mHasPendingFinishInput = true;
|
|
|
|
} else {
|
|
|
|
final LatinIME latinIme = getOuterInstance();
|
|
|
|
executePendingImsCallback(latinIme, null, false);
|
|
|
|
latinIme.onFinishInputInternal();
|
2011-09-27 09:47:54 +00:00
|
|
|
}
|
|
|
|
}
|
2011-07-21 06:57:00 +00:00
|
|
|
}
|
|
|
|
|
2010-10-08 13:17:16 +00:00
|
|
|
@Override
|
|
|
|
public void onCreate() {
|
2010-11-26 04:08:36 +00:00
|
|
|
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
|
|
|
mPrefs = prefs;
|
|
|
|
LatinImeLogger.init(this, prefs);
|
2011-04-14 02:42:08 +00:00
|
|
|
LanguageSwitcherProxy.init(this, prefs);
|
2011-07-18 04:18:47 +00:00
|
|
|
InputMethodManagerCompatWrapper.init(this);
|
2011-07-17 22:23:52 +00:00
|
|
|
SubtypeSwitcher.init(this);
|
2010-11-26 04:08:36 +00:00
|
|
|
KeyboardSwitcher.init(this, prefs);
|
2011-12-15 10:32:11 +00:00
|
|
|
AccessibilityUtils.init(this);
|
2010-12-23 03:24:27 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
super.onCreate();
|
2010-12-23 03:24:27 +00:00
|
|
|
|
2011-07-18 04:18:47 +00:00
|
|
|
mImm = InputMethodManagerCompatWrapper.getInstance();
|
2010-11-17 07:35:35 +00:00
|
|
|
mSubtypeSwitcher = SubtypeSwitcher.getInstance();
|
|
|
|
mKeyboardSwitcher = KeyboardSwitcher.getInstance();
|
2011-09-19 05:51:31 +00:00
|
|
|
mVibrator = VibratorCompatWrapper.getInstance(this);
|
2011-11-18 05:45:49 +00:00
|
|
|
mHandler.onCreate();
|
2011-05-27 12:41:13 +00:00
|
|
|
DEBUG = LatinImeLogger.sDBG;
|
2010-12-23 03:24:27 +00:00
|
|
|
|
|
|
|
final Resources res = getResources();
|
|
|
|
mResources = res;
|
2011-01-18 08:45:22 +00:00
|
|
|
|
2011-09-19 05:51:31 +00:00
|
|
|
loadSettings();
|
|
|
|
|
2011-12-16 03:57:27 +00:00
|
|
|
// TODO: remove the following when it's not needed by updateCorrectionMode() any more
|
2011-12-16 05:13:08 +00:00
|
|
|
mInputAttributes = new InputAttributes(null, false /* isFullscreenMode */);
|
2010-12-09 12:06:26 +00:00
|
|
|
Utils.GCUtils.getInstance().reset();
|
2010-08-20 05:35:02 +00:00
|
|
|
boolean tryGC = true;
|
2010-12-09 12:06:26 +00:00
|
|
|
for (int i = 0; i < Utils.GCUtils.GC_TRY_LOOP_MAX && tryGC; ++i) {
|
2010-08-20 05:35:02 +00:00
|
|
|
try {
|
2010-11-17 07:35:35 +00:00
|
|
|
initSuggest();
|
2010-08-20 05:35:02 +00:00
|
|
|
tryGC = false;
|
|
|
|
} catch (OutOfMemoryError e) {
|
2010-12-09 12:06:26 +00:00
|
|
|
tryGC = Utils.GCUtils.getInstance().tryGCOrWait("InitSuggest", e);
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-23 05:58:45 +00:00
|
|
|
mDisplayOrientation = res.getConfiguration().orientation;
|
2009-07-21 22:47:11 +00:00
|
|
|
|
2011-03-14 18:46:15 +00:00
|
|
|
// Register to receive ringer mode change and network state change.
|
|
|
|
// Also receive installation and removal of a dictionary pack.
|
2011-01-26 14:13:18 +00:00
|
|
|
final IntentFilter filter = new IntentFilter();
|
|
|
|
filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);
|
|
|
|
filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
|
2009-03-13 22:11:42 +00:00
|
|
|
registerReceiver(mReceiver, filter);
|
2011-03-25 00:42:09 +00:00
|
|
|
mVoiceProxy = VoiceProxy.init(this, prefs, mHandler);
|
2011-03-14 18:46:15 +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);
|
2011-04-14 11:45:47 +00:00
|
|
|
|
|
|
|
final IntentFilter newDictFilter = new IntentFilter();
|
|
|
|
newDictFilter.addAction(
|
|
|
|
DictionaryPackInstallBroadcastReceiver.NEW_DICTIONARY_INTENT_ACTION);
|
|
|
|
registerReceiver(mDictionaryPackInstallReceiver, newDictFilter);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2009-10-12 20:48:35 +00:00
|
|
|
|
2011-05-10 06:51:43 +00:00
|
|
|
// Has to be package-visible for unit tests
|
|
|
|
/* package */ void loadSettings() {
|
|
|
|
if (null == mPrefs) mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
|
|
|
|
if (null == mSubtypeSwitcher) mSubtypeSwitcher = SubtypeSwitcher.getInstance();
|
2011-12-08 13:10:40 +00:00
|
|
|
mSettingsValues = new SettingsValues(mPrefs, this, mSubtypeSwitcher.getInputLocaleStr());
|
2011-08-09 02:54:10 +00:00
|
|
|
resetContactsDictionary(null == mSuggest ? null : mSuggest.getContactsDictionary());
|
2011-05-10 06:51:43 +00:00
|
|
|
}
|
|
|
|
|
2010-11-17 07:35:35 +00:00
|
|
|
private void initSuggest() {
|
2011-03-14 18:46:15 +00:00
|
|
|
final String localeStr = mSubtypeSwitcher.getInputLocaleStr();
|
2011-08-26 11:22:47 +00:00
|
|
|
final Locale keyboardLocale = LocaleUtils.constructLocaleFromString(localeStr);
|
2009-10-12 20:48:35 +00:00
|
|
|
|
2011-04-27 06:43:03 +00:00
|
|
|
final Resources res = mResources;
|
2011-08-26 11:22:47 +00:00
|
|
|
final Locale savedLocale = LocaleUtils.setSystemLocale(res, keyboardLocale);
|
2011-08-09 02:54:10 +00:00
|
|
|
final ContactsDictionary oldContactsDictionary;
|
2009-10-12 20:48:35 +00:00
|
|
|
if (mSuggest != null) {
|
2011-08-09 02:54:10 +00:00
|
|
|
oldContactsDictionary = mSuggest.getContactsDictionary();
|
2009-10-12 20:48:35 +00:00
|
|
|
mSuggest.close();
|
2011-08-09 02:54:10 +00:00
|
|
|
} else {
|
|
|
|
oldContactsDictionary = null;
|
2009-10-12 20:48:35 +00:00
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
|
2011-02-23 08:23:29 +00:00
|
|
|
int mainDicResId = Utils.getMainDictionaryResourceId(res);
|
2011-03-14 18:46:15 +00:00
|
|
|
mSuggest = new Suggest(this, mainDicResId, keyboardLocale);
|
2011-05-10 06:51:43 +00:00
|
|
|
if (mSettingsValues.mAutoCorrectEnabled) {
|
|
|
|
mSuggest.setAutoCorrectionThreshold(mSettingsValues.mAutoCorrectionThreshold);
|
|
|
|
}
|
2011-01-07 06:01:51 +00:00
|
|
|
|
2011-03-14 18:46:15 +00:00
|
|
|
mUserDictionary = new UserDictionary(this, localeStr);
|
2009-03-13 22:11:42 +00:00
|
|
|
mSuggest.setUserDictionary(mUserDictionary);
|
2011-11-18 06:24:49 +00:00
|
|
|
mIsUserDictionaryAvailable = mUserDictionary.isEnabled();
|
2011-01-07 06:01:51 +00:00
|
|
|
|
2011-08-09 02:54:10 +00:00
|
|
|
resetContactsDictionary(oldContactsDictionary);
|
2011-01-07 06:01:51 +00:00
|
|
|
|
2011-07-14 22:57:26 +00:00
|
|
|
mUserUnigramDictionary
|
|
|
|
= new UserUnigramDictionary(this, this, localeStr, Suggest.DIC_USER_UNIGRAM);
|
|
|
|
mSuggest.setUserUnigramDictionary(mUserUnigramDictionary);
|
2011-01-07 06:01:51 +00:00
|
|
|
|
2011-07-14 22:57:26 +00:00
|
|
|
mUserBigramDictionary
|
|
|
|
= new UserBigramDictionary(this, this, localeStr, Suggest.DIC_USER_BIGRAM);
|
2011-01-07 06:01:51 +00:00
|
|
|
mSuggest.setUserBigramDictionary(mUserBigramDictionary);
|
|
|
|
|
2009-12-18 21:39:18 +00:00
|
|
|
updateCorrectionMode();
|
2009-10-12 20:48:35 +00:00
|
|
|
|
2011-08-26 11:22:47 +00:00
|
|
|
LocaleUtils.setSystemLocale(res, savedLocale);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2009-10-12 20:48:35 +00:00
|
|
|
|
2011-08-09 02:54:10 +00:00
|
|
|
/**
|
|
|
|
* Resets the contacts dictionary in mSuggest according to the user settings.
|
|
|
|
*
|
|
|
|
* This method takes an optional contacts dictionary to use. Since the contacts dictionary
|
|
|
|
* does not depend on the locale, it can be reused across different instances of Suggest.
|
|
|
|
* The dictionary will also be opened or closed as necessary depending on the settings.
|
|
|
|
*
|
|
|
|
* @param oldContactsDictionary an optional dictionary to use, or null
|
|
|
|
*/
|
|
|
|
private void resetContactsDictionary(final ContactsDictionary oldContactsDictionary) {
|
|
|
|
final boolean shouldSetDictionary = (null != mSuggest && mSettingsValues.mUseContactsDict);
|
|
|
|
|
|
|
|
final ContactsDictionary dictionaryToUse;
|
|
|
|
if (!shouldSetDictionary) {
|
|
|
|
// Make sure the dictionary is closed. If it is already closed, this is a no-op,
|
|
|
|
// so it's safe to call it anyways.
|
|
|
|
if (null != oldContactsDictionary) oldContactsDictionary.close();
|
|
|
|
dictionaryToUse = null;
|
|
|
|
} else if (null != oldContactsDictionary) {
|
|
|
|
// Make sure the old contacts dictionary is opened. If it is already open, this is a
|
|
|
|
// no-op, so it's safe to call it anyways.
|
|
|
|
oldContactsDictionary.reopen(this);
|
|
|
|
dictionaryToUse = oldContactsDictionary;
|
|
|
|
} else {
|
|
|
|
dictionaryToUse = new ContactsDictionary(this, Suggest.DIC_CONTACTS);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (null != mSuggest) {
|
|
|
|
mSuggest.setContactsDictionary(dictionaryToUse);
|
|
|
|
}
|
2011-06-10 09:16:21 +00:00
|
|
|
}
|
|
|
|
|
2011-03-14 18:46:15 +00:00
|
|
|
/* package private */ void resetSuggestMainDict() {
|
|
|
|
final String localeStr = mSubtypeSwitcher.getInputLocaleStr();
|
2011-08-26 11:22:47 +00:00
|
|
|
final Locale keyboardLocale = LocaleUtils.constructLocaleFromString(localeStr);
|
2011-03-14 18:46:15 +00:00
|
|
|
int mainDicResId = Utils.getMainDictionaryResourceId(mResources);
|
|
|
|
mSuggest.resetMainDict(this, mainDicResId, keyboardLocale);
|
|
|
|
}
|
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
@Override
|
|
|
|
public void onDestroy() {
|
2011-01-07 06:01:51 +00:00
|
|
|
if (mSuggest != null) {
|
|
|
|
mSuggest.close();
|
|
|
|
mSuggest = null;
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
unregisterReceiver(mReceiver);
|
2011-03-14 18:46:15 +00:00
|
|
|
unregisterReceiver(mDictionaryPackInstallReceiver);
|
2011-03-25 00:42:09 +00:00
|
|
|
mVoiceProxy.destroy();
|
2010-08-20 05:35:02 +00:00
|
|
|
LatinImeLogger.commit();
|
|
|
|
LatinImeLogger.onDestroy();
|
2009-03-13 22:11:42 +00:00
|
|
|
super.onDestroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onConfigurationChanged(Configuration conf) {
|
2011-01-17 08:52:15 +00:00
|
|
|
mSubtypeSwitcher.onConfigurationChanged(conf);
|
2011-10-12 09:07:09 +00:00
|
|
|
mComposingStateManager.onFinishComposingText();
|
2009-07-21 22:47:11 +00:00
|
|
|
// If orientation changed while predicting, commit the change
|
2011-08-23 05:58:45 +00:00
|
|
|
if (mDisplayOrientation != conf.orientation) {
|
|
|
|
mDisplayOrientation = conf.orientation;
|
|
|
|
mHandler.startOrientationChanging();
|
2011-07-31 02:28:15 +00:00
|
|
|
final InputConnection ic = getCurrentInputConnection();
|
2010-01-16 20:21:23 +00:00
|
|
|
commitTyped(ic);
|
|
|
|
if (ic != null) ic.finishComposingText(); // For voice input
|
2011-01-20 13:52:02 +00:00
|
|
|
if (isShowingOptionDialog())
|
|
|
|
mOptionsDialog.dismiss();
|
2009-07-21 22:47:11 +00:00
|
|
|
}
|
2010-11-11 07:03:19 +00:00
|
|
|
|
2010-03-07 15:27:05 +00:00
|
|
|
mConfigurationChanging = true;
|
2009-03-13 22:11:42 +00:00
|
|
|
super.onConfigurationChanged(conf);
|
2011-03-25 00:42:09 +00:00
|
|
|
mVoiceProxy.onConfigurationChanged(conf);
|
2010-03-07 15:27:05 +00:00
|
|
|
mConfigurationChanging = false;
|
2011-04-08 10:57:13 +00:00
|
|
|
|
|
|
|
// This will work only when the subtype is not supported.
|
|
|
|
LanguageSwitcherProxy.onConfigurationChanged(conf);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2009-07-21 22:47:11 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
@Override
|
|
|
|
public View onCreateInputView() {
|
2011-05-25 09:28:03 +00:00
|
|
|
return mKeyboardSwitcher.onCreateInputView();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setInputView(View view) {
|
|
|
|
super.setInputView(view);
|
2011-10-12 09:50:51 +00:00
|
|
|
mExtractArea = getWindow().getWindow().getDecorView()
|
|
|
|
.findViewById(android.R.id.extractArea);
|
2011-09-02 12:03:18 +00:00
|
|
|
mKeyPreviewBackingView = view.findViewById(R.id.key_preview_backing);
|
2011-09-01 05:54:28 +00:00
|
|
|
mSuggestionsContainer = view.findViewById(R.id.suggestions_container);
|
|
|
|
mSuggestionsView = (SuggestionsView) view.findViewById(R.id.suggestions_view);
|
|
|
|
if (mSuggestionsView != null)
|
|
|
|
mSuggestionsView.setListener(this, view);
|
2011-09-21 01:41:31 +00:00
|
|
|
if (LatinImeLogger.sVISUALDEBUG) {
|
|
|
|
mKeyPreviewBackingView.setBackgroundColor(0x10FF0000);
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2011-05-23 09:30:21 +00:00
|
|
|
public void setCandidatesView(View view) {
|
|
|
|
// 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
|
2011-11-21 22:58:32 +00:00
|
|
|
public void onStartInput(EditorInfo editorInfo, boolean restarting) {
|
|
|
|
mHandler.onStartInput(editorInfo, restarting);
|
2011-09-29 08:27:48 +00:00
|
|
|
}
|
|
|
|
|
2010-01-28 18:09:44 +00:00
|
|
|
@Override
|
2011-11-21 22:58:32 +00:00
|
|
|
public void onStartInputView(EditorInfo editorInfo, boolean restarting) {
|
|
|
|
mHandler.onStartInputView(editorInfo, restarting);
|
2011-09-29 08:27:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFinishInputView(boolean finishingInput) {
|
|
|
|
mHandler.onFinishInputView(finishingInput);
|
|
|
|
}
|
2011-07-21 06:57:00 +00:00
|
|
|
|
2011-09-29 08:27:48 +00:00
|
|
|
@Override
|
|
|
|
public void onFinishInput() {
|
|
|
|
mHandler.onFinishInput();
|
|
|
|
}
|
|
|
|
|
2011-11-21 22:58:32 +00:00
|
|
|
private void onStartInputInternal(EditorInfo editorInfo, boolean restarting) {
|
|
|
|
super.onStartInput(editorInfo, restarting);
|
2011-09-29 08:27:48 +00:00
|
|
|
}
|
|
|
|
|
2011-11-21 22:58:32 +00:00
|
|
|
private void onStartInputViewInternal(EditorInfo editorInfo, boolean restarting) {
|
|
|
|
super.onStartInputView(editorInfo, restarting);
|
2010-11-12 23:49:56 +00:00
|
|
|
final KeyboardSwitcher switcher = mKeyboardSwitcher;
|
2011-08-23 08:57:02 +00:00
|
|
|
LatinKeyboardView inputView = switcher.getKeyboardView();
|
2010-11-21 03:43:10 +00:00
|
|
|
|
2011-04-20 02:50:05 +00:00
|
|
|
if (DEBUG) {
|
2011-11-21 22:58:32 +00:00
|
|
|
Log.d(TAG, "onStartInputView: editorInfo:" + ((editorInfo == null) ? "none"
|
2011-06-17 11:55:46 +00:00
|
|
|
: String.format("inputType=0x%08x imeOptions=0x%08x",
|
2011-11-21 22:58:32 +00:00
|
|
|
editorInfo.inputType, editorInfo.imeOptions)));
|
2011-01-22 20:46:30 +00:00
|
|
|
}
|
2012-01-25 11:54:00 +00:00
|
|
|
if (Utils.inPrivateImeOptions(null, IME_OPTION_NO_MICROPHONE_COMPAT, editorInfo)) {
|
|
|
|
Log.w(TAG, "Deprecated private IME option specified: "
|
|
|
|
+ editorInfo.privateImeOptions);
|
|
|
|
Log.w(TAG, "Use " + getPackageName() + "." + IME_OPTION_NO_MICROPHONE + " instead");
|
|
|
|
}
|
|
|
|
if (Utils.inPrivateImeOptions(getPackageName(), IME_OPTION_FORCE_ASCII, editorInfo)) {
|
|
|
|
Log.w(TAG, "Deprecated private IME option specified: "
|
|
|
|
+ editorInfo.privateImeOptions);
|
|
|
|
Log.w(TAG, "Use EditorInfo.IME_FLAG_FORCE_ASCII flag instead");
|
|
|
|
}
|
|
|
|
|
2011-12-14 05:53:28 +00:00
|
|
|
LatinImeLogger.onStartInputView(editorInfo);
|
2009-03-13 22:11:42 +00:00
|
|
|
// In landscape mode, this method gets called without the input view being created.
|
2010-08-20 05:35:02 +00:00
|
|
|
if (inputView == null) {
|
2009-03-13 22:11:42 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-10-05 23:59:31 +00:00
|
|
|
// Forward this event to the accessibility utilities, if enabled.
|
|
|
|
final AccessibilityUtils accessUtils = AccessibilityUtils.getInstance();
|
|
|
|
if (accessUtils.isTouchExplorationEnabled()) {
|
2011-11-21 22:58:32 +00:00
|
|
|
accessUtils.onStartInputViewInternal(editorInfo, restarting);
|
2011-10-05 23:59:31 +00:00
|
|
|
}
|
|
|
|
|
2010-11-25 01:02:50 +00:00
|
|
|
mSubtypeSwitcher.updateParametersOnStartInputView();
|
2010-11-18 00:55:23 +00:00
|
|
|
|
2011-07-21 09:18:35 +00:00
|
|
|
// Most such things we decide below in initializeInputAttributesAndGetMode, but we need to
|
|
|
|
// know now whether this is a password text field, because we need to know now whether we
|
|
|
|
// want to enable the voice button.
|
|
|
|
final VoiceProxy voiceIme = mVoiceProxy;
|
2011-11-21 22:58:32 +00:00
|
|
|
final int inputType = (editorInfo != null) ? editorInfo.inputType : 0;
|
2011-07-21 09:27:27 +00:00
|
|
|
voiceIme.resetVoiceStates(InputTypeCompatUtils.isPasswordInputType(inputType)
|
|
|
|
|| InputTypeCompatUtils.isVisiblePasswordInputType(inputType));
|
2011-01-18 06:28:21 +00:00
|
|
|
|
2011-10-24 06:26:53 +00:00
|
|
|
// The EditorInfo might have a flag that affects fullscreen mode.
|
|
|
|
// Note: This call should be done by InputMethodService?
|
|
|
|
updateFullscreenMode();
|
2011-12-16 05:21:50 +00:00
|
|
|
mInputAttributes = new InputAttributes(editorInfo, isFullscreenMode());
|
2011-12-16 05:01:42 +00:00
|
|
|
mApplicationSpecifiedCompletions = null;
|
2011-01-18 06:28:21 +00:00
|
|
|
|
|
|
|
inputView.closing();
|
|
|
|
mEnteredText = null;
|
2012-01-26 07:37:47 +00:00
|
|
|
resetComposingState(true /* alsoResetLastComposedWord */);
|
2011-01-18 06:28:21 +00:00
|
|
|
mDeleteCount = 0;
|
2011-10-25 12:14:33 +00:00
|
|
|
mSpaceState = SPACE_STATE_NONE;
|
2011-01-18 06:28:21 +00:00
|
|
|
|
2011-05-10 06:51:43 +00:00
|
|
|
loadSettings();
|
|
|
|
updateCorrectionMode();
|
2011-12-15 10:32:11 +00:00
|
|
|
updateSuggestionVisibility(mResources);
|
2011-05-10 06:51:43 +00:00
|
|
|
|
|
|
|
if (mSuggest != null && mSettingsValues.mAutoCorrectEnabled) {
|
|
|
|
mSuggest.setAutoCorrectionThreshold(mSettingsValues.mAutoCorrectionThreshold);
|
2011-11-15 17:11:11 +00:00
|
|
|
}
|
2011-11-21 22:58:32 +00:00
|
|
|
mVoiceProxy.loadSettings(editorInfo, mPrefs);
|
2011-05-10 06:51:43 +00:00
|
|
|
// This will work only when the subtype is not supported.
|
|
|
|
LanguageSwitcherProxy.loadSettings();
|
|
|
|
|
2011-01-18 06:28:21 +00:00
|
|
|
if (mSubtypeSwitcher.isKeyboardMode()) {
|
2011-11-21 22:58:32 +00:00
|
|
|
switcher.loadKeyboard(editorInfo, mSettingsValues);
|
2011-01-18 06:28:21 +00:00
|
|
|
}
|
|
|
|
|
2011-09-01 05:54:28 +00:00
|
|
|
if (mSuggestionsView != null)
|
|
|
|
mSuggestionsView.clear();
|
|
|
|
setSuggestionStripShownInternal(
|
|
|
|
isSuggestionsStripVisible(), /* needsInputViewShown */ false);
|
2011-01-18 06:28:21 +00:00
|
|
|
// Delay updating suggestions because keyboard input view may not be shown at this point.
|
|
|
|
mHandler.postUpdateSuggestions();
|
2011-11-14 09:59:17 +00:00
|
|
|
mHandler.cancelDoubleSpacesTimer();
|
2011-01-18 06:28:21 +00:00
|
|
|
|
2011-05-11 11:51:07 +00:00
|
|
|
inputView.setKeyPreviewPopupEnabled(mSettingsValues.mKeyPreviewPopupOn,
|
|
|
|
mSettingsValues.mKeyPreviewPopupDismissDelay);
|
2011-01-18 06:28:21 +00:00
|
|
|
inputView.setProximityCorrectionEnabled(true);
|
|
|
|
|
2011-07-21 09:18:35 +00:00
|
|
|
voiceIme.onStartInputView(inputView.getWindowToken());
|
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();
|
2011-07-04 11:58:58 +00:00
|
|
|
KeyboardView inputView = mKeyboardSwitcher.getKeyboardView();
|
2011-05-17 10:02:32 +00:00
|
|
|
if (inputView != null) inputView.closing();
|
|
|
|
}
|
|
|
|
|
2011-09-29 08:27:48 +00:00
|
|
|
private void onFinishInputInternal() {
|
2009-03-13 22:11:42 +00:00
|
|
|
super.onFinishInput();
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-08-20 05:35:02 +00:00
|
|
|
LatinImeLogger.commit();
|
|
|
|
|
2011-03-25 00:42:09 +00:00
|
|
|
mVoiceProxy.flushVoiceInputLogs(mConfigurationChanging);
|
2010-11-21 01:36:37 +00:00
|
|
|
|
2011-07-04 11:58:58 +00:00
|
|
|
KeyboardView inputView = mKeyboardSwitcher.getKeyboardView();
|
2010-12-03 10:40:31 +00:00
|
|
|
if (inputView != null) inputView.closing();
|
2011-07-14 22:57:26 +00:00
|
|
|
if (mUserUnigramDictionary != null) mUserUnigramDictionary.flushPendingWrites();
|
2010-08-20 05:35:02 +00:00
|
|
|
if (mUserBigramDictionary != null) mUserBigramDictionary.flushPendingWrites();
|
2010-01-16 20:21:23 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 08:27:48 +00:00
|
|
|
private void onFinishInputViewInternal(boolean finishingInput) {
|
2010-10-06 09:39:47 +00:00
|
|
|
super.onFinishInputView(finishingInput);
|
2011-07-29 17:45:37 +00:00
|
|
|
mKeyboardSwitcher.onFinishInputView();
|
2011-07-04 11:58:58 +00:00
|
|
|
KeyboardView inputView = mKeyboardSwitcher.getKeyboardView();
|
2011-07-01 04:07:59 +00:00
|
|
|
if (inputView != null) inputView.cancelAllMessages();
|
2010-11-16 09:07:06 +00:00
|
|
|
// Remove pending messages related to update suggestions
|
|
|
|
mHandler.cancelUpdateSuggestions();
|
2010-10-06 09:39:47 +00:00
|
|
|
}
|
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
@Override
|
|
|
|
public void onUpdateExtractedText(int token, ExtractedText text) {
|
|
|
|
super.onUpdateExtractedText(token, text);
|
2011-03-25 00:42:09 +00:00
|
|
|
mVoiceProxy.showPunctuationHintIfNecessary();
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onUpdateSelection(int oldSelStart, int oldSelEnd,
|
|
|
|
int newSelStart, int newSelEnd,
|
|
|
|
int candidatesStart, int candidatesEnd) {
|
|
|
|
super.onUpdateSelection(oldSelStart, oldSelEnd, newSelStart, newSelEnd,
|
|
|
|
candidatesStart, candidatesEnd);
|
2010-01-16 20:21:23 +00:00
|
|
|
|
|
|
|
if (DEBUG) {
|
|
|
|
Log.i(TAG, "onUpdateSelection: oss=" + oldSelStart
|
|
|
|
+ ", ose=" + oldSelEnd
|
2011-02-25 09:11:18 +00:00
|
|
|
+ ", lss=" + mLastSelectionStart
|
|
|
|
+ ", lse=" + mLastSelectionEnd
|
2010-01-16 20:21:23 +00:00
|
|
|
+ ", nss=" + newSelStart
|
|
|
|
+ ", nse=" + newSelEnd
|
|
|
|
+ ", cs=" + candidatesStart
|
|
|
|
+ ", ce=" + candidatesEnd);
|
|
|
|
}
|
|
|
|
|
2011-03-25 00:42:09 +00:00
|
|
|
mVoiceProxy.setCursorAndSelection(newSelEnd, newSelStart);
|
2010-03-04 14:34:21 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
// If the current selection in the text view changes, we should
|
|
|
|
// clear whatever candidate text we have.
|
2011-02-25 09:11:18 +00:00
|
|
|
final boolean selectionChanged = (newSelStart != candidatesEnd
|
|
|
|
|| newSelEnd != candidatesEnd) && mLastSelectionStart != newSelStart;
|
|
|
|
final boolean candidatesCleared = candidatesStart == -1 && candidatesEnd == -1;
|
2011-06-08 07:47:19 +00:00
|
|
|
if (!mExpectingUpdateSelection) {
|
2012-01-12 02:01:01 +00:00
|
|
|
// TAKE CARE: there is a race condition when we enter this test even when the user
|
|
|
|
// did not explicitly move the cursor. This happens when typing fast, where two keys
|
|
|
|
// turn this flag on in succession and both onUpdateSelection() calls arrive after
|
|
|
|
// the second one - the first call successfully avoids this test, but the second one
|
|
|
|
// enters. For the moment we rely on candidatesCleared to further reduce the impact.
|
2011-10-25 12:14:33 +00:00
|
|
|
if (SPACE_STATE_WEAK == mSpaceState) {
|
|
|
|
// Test for no WEAK_SPACE action because there is a race condition that may end up
|
|
|
|
// in coming here on a normal key press. We set this to NONE because after
|
|
|
|
// a cursor move, we don't want the suggestion strip to swap the space with the
|
|
|
|
// newly inserted punctuation.
|
|
|
|
mSpaceState = SPACE_STATE_NONE;
|
2011-10-24 09:00:05 +00:00
|
|
|
}
|
2011-12-13 14:24:37 +00:00
|
|
|
if (((mWordComposer.isComposingWord())
|
2011-10-03 05:58:34 +00:00
|
|
|
|| mVoiceProxy.isVoiceInputHighlighted())
|
|
|
|
&& (selectionChanged || candidatesCleared)) {
|
2012-01-26 07:37:47 +00:00
|
|
|
resetComposingState(true /* alsoResetLastComposedWord */);
|
2011-10-03 06:50:11 +00:00
|
|
|
updateSuggestions();
|
2011-10-03 05:58:34 +00:00
|
|
|
final InputConnection ic = getCurrentInputConnection();
|
|
|
|
if (ic != null) {
|
|
|
|
ic.finishComposingText();
|
|
|
|
}
|
2011-10-12 09:07:09 +00:00
|
|
|
mComposingStateManager.onFinishComposingText();
|
2011-10-03 05:58:34 +00:00
|
|
|
mVoiceProxy.setVoiceInputHighlighted(false);
|
2011-12-13 14:24:37 +00:00
|
|
|
} else if (!mWordComposer.isComposingWord()) {
|
2012-01-26 07:37:47 +00:00
|
|
|
// TODO: is the following reset still needed, given that we are not composing
|
|
|
|
// a word?
|
|
|
|
resetComposingState(true /* alsoResetLastComposedWord */);
|
2011-10-03 06:50:11 +00:00
|
|
|
updateSuggestions();
|
2011-10-03 05:58:34 +00:00
|
|
|
}
|
2011-06-08 07:47:19 +00:00
|
|
|
}
|
|
|
|
mExpectingUpdateSelection = false;
|
2010-11-16 09:07:06 +00:00
|
|
|
mHandler.postUpdateShiftKeyState();
|
2011-11-22 02:35:40 +00:00
|
|
|
// TODO: Decide to call restartSuggestionsOnWordBeforeCursorIfAtEndOfWord() or not
|
|
|
|
// here. It would probably be too expensive to call directly here but we may want to post a
|
|
|
|
// message to delay it. The point would be to unify behavior between backspace to the
|
|
|
|
// end of a word and manually put the pointer at the end of the word.
|
2010-01-16 20:21:23 +00:00
|
|
|
|
2010-08-20 05:35:02 +00:00
|
|
|
// Make a note of the cursor position
|
|
|
|
mLastSelectionStart = newSelStart;
|
|
|
|
mLastSelectionEnd = newSelEnd;
|
2011-05-06 09:27:24 +00:00
|
|
|
}
|
|
|
|
|
2010-09-15 04:03:34 +00:00
|
|
|
/**
|
|
|
|
* This is called when the user has clicked on the extracted text view,
|
|
|
|
* when running in fullscreen mode. The default implementation hides
|
2011-09-01 05:54:28 +00:00
|
|
|
* the suggestions view when this happens, but only if the extracted text
|
2010-09-15 04:03:34 +00:00
|
|
|
* editor has a vertical scroll bar because its text doesn't fit.
|
|
|
|
* Here we override the behavior due to the possibility that a re-correction could
|
2011-09-01 05:54:28 +00:00
|
|
|
* cause the suggestions strip to disappear and re-appear.
|
2010-09-15 04:03:34 +00:00
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public void onExtractedTextClicked() {
|
2011-10-03 08:45:45 +00:00
|
|
|
if (isSuggestionsRequested()) return;
|
2010-09-15 04:03:34 +00:00
|
|
|
|
|
|
|
super.onExtractedTextClicked();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is called when the user has performed a cursor movement in the
|
|
|
|
* extracted text view, when it is running in fullscreen mode. The default
|
2011-09-01 05:54:28 +00:00
|
|
|
* implementation hides the suggestions view when a vertical movement
|
2010-09-15 04:03:34 +00:00
|
|
|
* happens, but only if the extracted text editor has a vertical scroll bar
|
|
|
|
* because its text doesn't fit.
|
|
|
|
* Here we override the behavior due to the possibility that a re-correction could
|
2011-09-01 05:54:28 +00:00
|
|
|
* cause the suggestions strip to disappear and re-appear.
|
2010-09-15 04:03:34 +00:00
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public void onExtractedCursorMovement(int dx, int dy) {
|
2011-10-03 08:45:45 +00:00
|
|
|
if (isSuggestionsRequested()) return;
|
2010-09-15 04:03:34 +00:00
|
|
|
|
|
|
|
super.onExtractedCursorMovement(dx, dy);
|
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
@Override
|
|
|
|
public void hideWindow() {
|
2010-08-20 05:35:02 +00:00
|
|
|
LatinImeLogger.commit();
|
2011-07-27 22:32:25 +00:00
|
|
|
mKeyboardSwitcher.onHideWindow();
|
2010-08-20 05:35:02 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
if (TRACE) Debug.stopMethodTracing();
|
2009-03-26 00:39:38 +00:00
|
|
|
if (mOptionsDialog != null && mOptionsDialog.isShowing()) {
|
|
|
|
mOptionsDialog.dismiss();
|
|
|
|
mOptionsDialog = null;
|
|
|
|
}
|
2011-03-25 00:42:09 +00:00
|
|
|
mVoiceProxy.hideVoiceWindow(mConfigurationChanging);
|
2009-03-13 22:11:42 +00:00
|
|
|
super.hideWindow();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2010-12-11 08:06:24 +00:00
|
|
|
public void onDisplayCompletions(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
|
|
|
}
|
|
|
|
}
|
2011-12-16 03:57:27 +00:00
|
|
|
if (mInputAttributes.mApplicationSpecifiedCompletionOn) {
|
2010-12-11 08:06:24 +00:00
|
|
|
mApplicationSpecifiedCompletions = applicationSpecifiedCompletions;
|
|
|
|
if (applicationSpecifiedCompletions == null) {
|
2010-08-26 19:22:58 +00:00
|
|
|
clearSuggestions();
|
2009-03-13 22:11:42 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-12-10 11:50:30 +00:00
|
|
|
SuggestedWords.Builder builder = new SuggestedWords.Builder()
|
2010-12-11 08:06:24 +00:00
|
|
|
.setApplicationSpecifiedCompletions(applicationSpecifiedCompletions)
|
2011-07-04 07:21:32 +00:00
|
|
|
.setTypedWordValid(false)
|
|
|
|
.setHasMinimalSuggestion(false);
|
2010-08-20 05:35:02 +00:00
|
|
|
// When in fullscreen mode, show completions generated by the application
|
2010-12-10 11:50:30 +00:00
|
|
|
setSuggestions(builder.build());
|
2012-01-26 08:16:40 +00:00
|
|
|
// TODO: is this the right thing to do? What should we auto-correct to in
|
|
|
|
// this case? This says to keep whatever the user typed.
|
|
|
|
mWordComposer.setAutoCorrection(mWordComposer.getTypedWord());
|
2011-05-23 09:30:21 +00:00
|
|
|
setSuggestionStripShown(true);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-23 09:30:21 +00:00
|
|
|
private void setSuggestionStripShownInternal(boolean shown, boolean needsInputViewShown) {
|
2011-09-01 05:54:28 +00:00
|
|
|
// TODO: Modify this if we support suggestions with hard keyboard
|
|
|
|
if (onEvaluateInputViewShown() && mSuggestionsContainer != null) {
|
|
|
|
final boolean shouldShowSuggestions = shown
|
2011-04-13 05:12:24 +00:00
|
|
|
&& (needsInputViewShown ? mKeyboardSwitcher.isInputViewShown() : true);
|
2011-07-28 22:06:15 +00:00
|
|
|
if (isFullscreenMode()) {
|
2011-09-01 05:54:28 +00:00
|
|
|
mSuggestionsContainer.setVisibility(
|
|
|
|
shouldShowSuggestions ? View.VISIBLE : View.GONE);
|
2011-04-13 05:12:24 +00:00
|
|
|
} else {
|
2011-09-01 05:54:28 +00:00
|
|
|
mSuggestionsContainer.setVisibility(
|
|
|
|
shouldShowSuggestions ? View.VISIBLE : View.INVISIBLE);
|
2011-04-13 05:12:24 +00:00
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2011-05-23 09:30:21 +00:00
|
|
|
private void setSuggestionStripShown(boolean shown) {
|
|
|
|
setSuggestionStripShownInternal(shown, /* needsInputViewShown */true);
|
2010-08-31 09:00:09 +00:00
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
@Override
|
|
|
|
public void onComputeInsets(InputMethodService.Insets outInsets) {
|
|
|
|
super.onComputeInsets(outInsets);
|
2011-07-04 11:58:58 +00:00
|
|
|
final KeyboardView inputView = mKeyboardSwitcher.getKeyboardView();
|
2011-09-01 05:54:28 +00:00
|
|
|
if (inputView == null || mSuggestionsContainer == null)
|
2011-04-21 05:51:53 +00:00
|
|
|
return;
|
2011-10-12 09:50:51 +00:00
|
|
|
// In fullscreen mode, the height of the extract area managed by InputMethodService should
|
|
|
|
// be considered.
|
|
|
|
// See {@link android.inputmethodservice.InputMethodService#onComputeInsets}.
|
|
|
|
final int extractHeight = isFullscreenMode() ? mExtractArea.getHeight() : 0;
|
2011-09-02 12:03:18 +00:00
|
|
|
final int backingHeight = (mKeyPreviewBackingView.getVisibility() == View.GONE) ? 0
|
|
|
|
: mKeyPreviewBackingView.getHeight();
|
2011-09-20 05:57:31 +00:00
|
|
|
final int suggestionsHeight = (mSuggestionsContainer.getVisibility() == View.GONE) ? 0
|
|
|
|
: mSuggestionsContainer.getHeight();
|
2011-10-12 09:50:51 +00:00
|
|
|
final int extraHeight = extractHeight + backingHeight + suggestionsHeight;
|
2011-09-02 12:03:18 +00:00
|
|
|
int touchY = extraHeight;
|
2011-01-21 10:04:00 +00:00
|
|
|
// Need to set touchable region only if input view is being shown
|
2011-04-21 05:51:53 +00:00
|
|
|
if (mKeyboardSwitcher.isInputViewShown()) {
|
2011-09-01 05:54:28 +00:00
|
|
|
if (mSuggestionsContainer.getVisibility() == View.VISIBLE) {
|
2011-09-20 05:57:31 +00:00
|
|
|
touchY -= suggestionsHeight;
|
2011-01-21 10:04:00 +00:00
|
|
|
}
|
2011-04-13 05:12:24 +00:00
|
|
|
final int touchWidth = inputView.getWidth();
|
2011-09-02 12:03:18 +00:00
|
|
|
final int touchHeight = inputView.getHeight() + extraHeight
|
2011-04-13 05:12:24 +00:00
|
|
|
// Extend touchable region below the keyboard.
|
|
|
|
+ EXTENDED_TOUCHABLE_REGION_HEIGHT;
|
2011-01-21 10:04:00 +00:00
|
|
|
if (DEBUG) {
|
2011-04-13 05:12:24 +00:00
|
|
|
Log.d(TAG, "Touchable region: y=" + touchY + " width=" + touchWidth
|
|
|
|
+ " height=" + touchHeight);
|
2011-01-21 10:04:00 +00:00
|
|
|
}
|
2011-04-13 05:12:24 +00:00
|
|
|
setTouchableRegionCompat(outInsets, 0, touchY, touchWidth, touchHeight);
|
2011-01-21 10:04:00 +00:00
|
|
|
}
|
2011-04-21 05:51:53 +00:00
|
|
|
outInsets.contentTopInsets = touchY;
|
|
|
|
outInsets.visibleTopInsets = touchY;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-08-20 05:35:02 +00:00
|
|
|
@Override
|
|
|
|
public boolean onEvaluateFullscreenMode() {
|
2012-01-16 02:32:49 +00:00
|
|
|
// Reread resource value here, because this method is called by framework anytime as needed.
|
|
|
|
final boolean isFullscreenModeAllowed =
|
|
|
|
mSettingsValues.isFullscreenModeAllowed(getResources());
|
|
|
|
return super.onEvaluateFullscreenMode() && isFullscreenModeAllowed;
|
2011-09-20 05:57:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void updateFullscreenMode() {
|
|
|
|
super.updateFullscreenMode();
|
2011-09-07 03:50:48 +00:00
|
|
|
|
2011-09-20 05:57:31 +00:00
|
|
|
if (mKeyPreviewBackingView == null) return;
|
2011-11-15 17:11:11 +00:00
|
|
|
// In fullscreen mode, no need to have extra space to show the key preview.
|
2011-09-20 05:57:31 +00:00
|
|
|
// If not, we should have extra space above the keyboard to show the key preview.
|
2011-11-15 17:11:11 +00:00
|
|
|
mKeyPreviewBackingView.setVisibility(isFullscreenMode() ? View.GONE : View.VISIBLE);
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
@Override
|
|
|
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
|
|
|
switch (keyCode) {
|
2010-12-10 06:24:28 +00:00
|
|
|
case KeyEvent.KEYCODE_BACK:
|
2011-09-09 00:33:35 +00:00
|
|
|
if (event.getRepeatCount() == 0) {
|
|
|
|
if (mSuggestionsView != null && mSuggestionsView.handleBack()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
final LatinKeyboardView keyboardView = mKeyboardSwitcher.getKeyboardView();
|
|
|
|
if (keyboardView != null && keyboardView.handleBack()) {
|
2009-03-26 00:39:38 +00:00
|
|
|
return true;
|
|
|
|
}
|
2010-12-10 06:24:28 +00:00
|
|
|
}
|
|
|
|
break;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
return super.onKeyDown(keyCode, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
|
|
|
switch (keyCode) {
|
2010-12-10 06:24:28 +00:00
|
|
|
case KeyEvent.KEYCODE_DPAD_DOWN:
|
|
|
|
case KeyEvent.KEYCODE_DPAD_UP:
|
|
|
|
case KeyEvent.KEYCODE_DPAD_LEFT:
|
|
|
|
case KeyEvent.KEYCODE_DPAD_RIGHT:
|
|
|
|
// Enable shift key and DPAD to do selections
|
|
|
|
if (mKeyboardSwitcher.isInputViewShown()
|
|
|
|
&& mKeyboardSwitcher.isShiftedOrShiftLocked()) {
|
|
|
|
KeyEvent newEvent = new KeyEvent(event.getDownTime(), event.getEventTime(),
|
|
|
|
event.getAction(), event.getKeyCode(), event.getRepeatCount(),
|
|
|
|
event.getDeviceId(), event.getScanCode(),
|
|
|
|
KeyEvent.META_SHIFT_LEFT_ON | KeyEvent.META_SHIFT_ON);
|
2011-07-31 02:28:15 +00:00
|
|
|
final InputConnection ic = getCurrentInputConnection();
|
2010-12-10 06:24:28 +00:00
|
|
|
if (ic != null)
|
|
|
|
ic.sendKeyEvent(newEvent);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
return super.onKeyUp(keyCode, event);
|
|
|
|
}
|
|
|
|
|
2012-01-26 07:37:47 +00:00
|
|
|
private void resetComposingState(final boolean alsoResetLastComposedWord) {
|
|
|
|
mWordComposer.reset();
|
|
|
|
if (alsoResetLastComposedWord)
|
|
|
|
mLastComposedWord = LastComposedWord.NOT_A_COMPOSED_WORD;
|
|
|
|
}
|
|
|
|
|
2011-07-31 02:28:15 +00:00
|
|
|
public void commitTyped(final InputConnection ic) {
|
2011-12-13 14:24:37 +00:00
|
|
|
if (!mWordComposer.isComposingWord()) return;
|
2011-12-09 14:15:49 +00:00
|
|
|
final CharSequence typedWord = mWordComposer.getTypedWord();
|
2012-01-26 07:37:47 +00:00
|
|
|
mLastComposedWord = mWordComposer.commitWord(LastComposedWord.COMMIT_TYPE_USER_TYPED_WORD);
|
2011-12-09 14:15:49 +00:00
|
|
|
if (typedWord.length() > 0) {
|
2011-07-31 02:28:15 +00:00
|
|
|
if (ic != null) {
|
2011-12-09 14:15:49 +00:00
|
|
|
ic.commitText(typedWord, 1);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2011-12-09 14:15:49 +00:00
|
|
|
addToUserUnigramAndBigramDictionaries(typedWord,
|
2011-07-14 22:57:26 +00:00
|
|
|
UserUnigramDictionary.FREQUENCY_FOR_TYPED);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2011-07-12 07:47:08 +00:00
|
|
|
updateSuggestions();
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2010-11-13 08:16:34 +00:00
|
|
|
public boolean getCurrentAutoCapsState() {
|
2011-07-31 02:28:15 +00:00
|
|
|
final InputConnection ic = getCurrentInputConnection();
|
2010-01-24 15:34:07 +00:00
|
|
|
EditorInfo ei = getCurrentInputEditorInfo();
|
2011-05-10 06:51:43 +00:00
|
|
|
if (mSettingsValues.mAutoCap && ic != null && ei != null
|
|
|
|
&& ei.inputType != InputType.TYPE_NULL) {
|
2010-11-13 08:16:34 +00:00
|
|
|
return ic.getCursorCapsMode(ei.inputType) != 0;
|
2010-01-24 15:34:07 +00:00
|
|
|
}
|
2010-11-13 08:16:34 +00:00
|
|
|
return false;
|
2010-01-24 15:34:07 +00:00
|
|
|
}
|
|
|
|
|
2011-10-25 08:32:04 +00:00
|
|
|
// "ic" may be null
|
|
|
|
private void swapSwapperAndSpaceWhileInBatchEdit(final InputConnection ic) {
|
|
|
|
if (null == ic) return;
|
2009-03-13 22:11:42 +00:00
|
|
|
CharSequence lastTwo = ic.getTextBeforeCursor(2, 0);
|
2011-05-09 07:54:07 +00:00
|
|
|
// It is guaranteed lastTwo.charAt(1) is a swapper - else this method is not called.
|
2009-03-13 22:11:42 +00:00
|
|
|
if (lastTwo != null && lastTwo.length() == 2
|
2011-05-09 07:54:07 +00:00
|
|
|
&& lastTwo.charAt(0) == Keyboard.CODE_SPACE) {
|
2009-03-13 22:11:42 +00:00
|
|
|
ic.deleteSurroundingText(2, 0);
|
|
|
|
ic.commitText(lastTwo.charAt(1) + " ", 1);
|
2010-11-13 08:16:34 +00:00
|
|
|
mKeyboardSwitcher.updateShiftState();
|
2010-02-22 14:55:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-25 12:14:33 +00:00
|
|
|
private boolean maybeDoubleSpaceWhileInBatchEdit(final InputConnection ic) {
|
|
|
|
if (mCorrectionMode == Suggest.CORRECTION_NONE) return false;
|
|
|
|
if (ic == null) return false;
|
2011-07-14 05:15:01 +00:00
|
|
|
final CharSequence lastThree = ic.getTextBeforeCursor(3, 0);
|
2009-03-13 22:11:42 +00:00
|
|
|
if (lastThree != null && lastThree.length() == 3
|
2011-07-31 02:28:15 +00:00
|
|
|
&& Utils.canBeFollowedByPeriod(lastThree.charAt(0))
|
2010-12-02 11:54:32 +00:00
|
|
|
&& lastThree.charAt(1) == Keyboard.CODE_SPACE
|
2011-03-02 07:40:10 +00:00
|
|
|
&& lastThree.charAt(2) == Keyboard.CODE_SPACE
|
|
|
|
&& mHandler.isAcceptingDoubleSpaces()) {
|
|
|
|
mHandler.cancelDoubleSpacesTimer();
|
2009-03-13 22:11:42 +00:00
|
|
|
ic.deleteSurroundingText(2, 0);
|
|
|
|
ic.commitText(". ", 1);
|
2010-11-13 08:16:34 +00:00
|
|
|
mKeyboardSwitcher.updateShiftState();
|
2011-10-25 12:14:33 +00:00
|
|
|
return true;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2011-10-25 12:14:33 +00:00
|
|
|
return false;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2011-10-25 08:32:04 +00:00
|
|
|
// "ic" must not be null
|
2011-10-28 04:31:31 +00:00
|
|
|
private static void maybeRemovePreviousPeriod(final InputConnection ic, CharSequence text) {
|
2010-01-31 16:34:55 +00:00
|
|
|
// When the text's first character is '.', remove the previous period
|
|
|
|
// if there is one.
|
2011-10-25 08:32:04 +00:00
|
|
|
final CharSequence lastOne = ic.getTextBeforeCursor(1, 0);
|
2010-02-22 14:55:45 +00:00
|
|
|
if (lastOne != null && lastOne.length() == 1
|
2010-12-02 11:54:32 +00:00
|
|
|
&& lastOne.charAt(0) == Keyboard.CODE_PERIOD
|
|
|
|
&& text.charAt(0) == Keyboard.CODE_PERIOD) {
|
2010-01-31 16:34:55 +00:00
|
|
|
ic.deleteSurroundingText(1, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-25 08:32:04 +00:00
|
|
|
// "ic" may be null
|
2011-10-28 04:31:31 +00:00
|
|
|
private static void removeTrailingSpaceWhileInBatchEdit(final InputConnection ic) {
|
2010-02-07 00:34:43 +00:00
|
|
|
if (ic == null) return;
|
2011-10-25 08:32:04 +00:00
|
|
|
final CharSequence lastOne = ic.getTextBeforeCursor(1, 0);
|
2010-02-07 00:34:43 +00:00
|
|
|
if (lastOne != null && lastOne.length() == 1
|
2010-12-02 11:54:32 +00:00
|
|
|
&& lastOne.charAt(0) == Keyboard.CODE_SPACE) {
|
2010-02-07 00:34:43 +00:00
|
|
|
ic.deleteSurroundingText(1, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-09 05:22:37 +00:00
|
|
|
@Override
|
2009-03-13 22:11:42 +00:00
|
|
|
public boolean addWordToDictionary(String word) {
|
|
|
|
mUserDictionary.addWord(word, 128);
|
2010-08-03 18:47:42 +00:00
|
|
|
// Suggestion strip should be updated after the operation of adding word to the
|
|
|
|
// user dictionary
|
2010-11-16 09:07:06 +00:00
|
|
|
mHandler.postUpdateSuggestions();
|
2009-03-13 22:11:42 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-10-28 04:31:31 +00:00
|
|
|
private static boolean isAlphabet(int code) {
|
|
|
|
return Character.isLetter(code);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-12-06 03:12:27 +00:00
|
|
|
private void onSettingsKeyPressed() {
|
2011-08-06 01:45:19 +00:00
|
|
|
if (isShowingOptionDialog()) return;
|
2011-05-20 03:36:10 +00:00
|
|
|
if (InputMethodServiceCompatWrapper.CAN_HANDLE_ON_CURRENT_INPUT_METHOD_SUBTYPE_CHANGED) {
|
|
|
|
showSubtypeSelectorAndSettings();
|
2011-12-15 07:09:42 +00:00
|
|
|
} else if (Utils.hasMultipleEnabledIMEsOrSubtypes(false /* exclude aux subtypes */)) {
|
2011-05-20 03:36:10 +00:00
|
|
|
showOptionsMenu();
|
|
|
|
} else {
|
|
|
|
launchSettings();
|
2010-09-02 19:25:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-06 01:45:19 +00:00
|
|
|
// Virtual codes representing custom requests. These are used in onCustomRequest() below.
|
|
|
|
public static final int CODE_SHOW_INPUT_METHOD_PICKER = 1;
|
2011-10-26 11:49:57 +00:00
|
|
|
public static final int CODE_HAPTIC_AND_AUDIO_FEEDBACK = 2;
|
2011-08-06 01:45:19 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onCustomRequest(int requestCode) {
|
|
|
|
if (isShowingOptionDialog()) return false;
|
|
|
|
switch (requestCode) {
|
|
|
|
case CODE_SHOW_INPUT_METHOD_PICKER:
|
2011-12-15 07:09:42 +00:00
|
|
|
if (Utils.hasMultipleEnabledIMEsOrSubtypes(true /* include aux subtypes */)) {
|
2010-11-25 00:20:28 +00:00
|
|
|
mImm.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;
|
2011-10-26 11:49:57 +00:00
|
|
|
case CODE_HAPTIC_AND_AUDIO_FEEDBACK:
|
|
|
|
hapticAndAudioFeedback(Keyboard.CODE_UNSPECIFIED);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
private boolean isShowingOptionDialog() {
|
|
|
|
return mOptionsDialog != null && mOptionsDialog.isShowing();
|
|
|
|
}
|
|
|
|
|
2011-10-25 12:14:33 +00:00
|
|
|
private void insertPunctuationFromSuggestionStrip(final InputConnection ic, final int code) {
|
|
|
|
final CharSequence beforeText = ic != null ? ic.getTextBeforeCursor(1, 0) : null;
|
|
|
|
final int toLeft = TextUtils.isEmpty(beforeText) ? 0 : beforeText.charAt(0);
|
|
|
|
final boolean shouldRegisterSwapPunctuation;
|
|
|
|
// If we have a space left of the cursor and it's a weak or a magic space, then we should
|
|
|
|
// swap it, and override the space state with SPACESTATE_SWAP_PUNCTUATION.
|
|
|
|
// To swap it, we fool handleSeparator to think the previous space state was a
|
|
|
|
// magic space.
|
2012-01-12 02:09:10 +00:00
|
|
|
if (Keyboard.CODE_SPACE == toLeft && mSpaceState == SPACE_STATE_WEAK
|
2012-01-12 05:07:56 +00:00
|
|
|
&& mSettingsValues.isMagicSpaceSwapper(code)) {
|
2011-10-25 12:14:33 +00:00
|
|
|
mSpaceState = SPACE_STATE_MAGIC;
|
|
|
|
shouldRegisterSwapPunctuation = true;
|
|
|
|
} else {
|
|
|
|
shouldRegisterSwapPunctuation = false;
|
|
|
|
}
|
|
|
|
onCodeInput(code, new int[] { code },
|
|
|
|
KeyboardActionListener.NOT_A_TOUCH_COORDINATE,
|
|
|
|
KeyboardActionListener.NOT_A_TOUCH_COORDINATE);
|
|
|
|
if (shouldRegisterSwapPunctuation) {
|
|
|
|
mSpaceState = SPACE_STATE_SWAP_PUNCTUATION;
|
|
|
|
}
|
2011-10-24 09:00:05 +00:00
|
|
|
}
|
|
|
|
|
2010-12-30 08:19:55 +00:00
|
|
|
// Implementation of {@link KeyboardActionListener}.
|
2010-12-02 09:46:21 +00:00
|
|
|
@Override
|
2010-12-20 07:13:57 +00:00
|
|
|
public void onCodeInput(int primaryCode, int[] keyCodes, int x, int y) {
|
2011-11-16 23:58:42 +00:00
|
|
|
final long when = SystemClock.uptimeMillis();
|
2010-12-02 11:54:32 +00:00
|
|
|
if (primaryCode != Keyboard.CODE_DELETE || when > mLastKeyTime + QUICK_PRESS) {
|
2009-03-13 22:11:42 +00:00
|
|
|
mDeleteCount = 0;
|
|
|
|
}
|
|
|
|
mLastKeyTime = when;
|
2011-11-16 23:58:42 +00:00
|
|
|
final KeyboardSwitcher switcher = mKeyboardSwitcher;
|
2011-10-25 12:14:33 +00:00
|
|
|
// The space state depends only on the last character pressed and its own previous
|
|
|
|
// state. Here, we revert the space state to neutral if the key is actually modifying
|
|
|
|
// the input contents (any non-shift key), which is what we should do for
|
|
|
|
// all inputs that do not result in a special state. Each character handling is then
|
|
|
|
// free to override the state as they see fit.
|
|
|
|
final int spaceState = mSpaceState;
|
2011-11-14 09:59:17 +00:00
|
|
|
|
|
|
|
// TODO: Consolidate the double space timer, mLastKeyTime, and the space state.
|
|
|
|
if (primaryCode != Keyboard.CODE_SPACE) {
|
|
|
|
mHandler.cancelDoubleSpacesTimer();
|
|
|
|
}
|
|
|
|
|
2012-01-26 08:20:51 +00:00
|
|
|
boolean didAutoCorrect = false;
|
2009-03-13 22:11:42 +00:00
|
|
|
switch (primaryCode) {
|
2010-12-02 11:54:32 +00:00
|
|
|
case Keyboard.CODE_DELETE:
|
2011-10-25 12:14:33 +00:00
|
|
|
mSpaceState = SPACE_STATE_NONE;
|
|
|
|
handleBackspace(spaceState);
|
2010-10-22 10:35:23 +00:00
|
|
|
mDeleteCount++;
|
2011-06-08 07:47:19 +00:00
|
|
|
mExpectingUpdateSelection = true;
|
2010-10-22 10:35:23 +00:00
|
|
|
LatinImeLogger.logOnDelete();
|
|
|
|
break;
|
2010-12-02 11:54:32 +00:00
|
|
|
case Keyboard.CODE_SHIFT:
|
2010-12-06 03:12:27 +00:00
|
|
|
case Keyboard.CODE_SWITCH_ALPHA_SYMBOL:
|
2012-01-17 08:08:26 +00:00
|
|
|
// Shift and symbol key is handled in onPressKey() and onReleaseKey().
|
2010-10-22 10:35:23 +00:00
|
|
|
break;
|
2010-12-06 03:12:27 +00:00
|
|
|
case Keyboard.CODE_SETTINGS:
|
2011-11-22 00:41:01 +00:00
|
|
|
onSettingsKeyPressed();
|
2010-10-22 10:35:23 +00:00
|
|
|
break;
|
2010-12-02 11:54:32 +00:00
|
|
|
case Keyboard.CODE_CAPSLOCK:
|
2012-01-17 09:45:04 +00:00
|
|
|
// Caps lock code is handled in KeyboardSwitcher.onCodeInput() below.
|
2011-10-26 11:49:57 +00:00
|
|
|
hapticAndAudioFeedback(primaryCode);
|
2010-10-22 10:35:23 +00:00
|
|
|
break;
|
2011-04-21 10:43:20 +00:00
|
|
|
case Keyboard.CODE_SHORTCUT:
|
2011-11-22 00:41:01 +00:00
|
|
|
mSubtypeSwitcher.switchToShortcutIME();
|
2010-10-22 10:35:23 +00:00
|
|
|
break;
|
2010-12-02 11:54:32 +00:00
|
|
|
case Keyboard.CODE_TAB:
|
2010-11-12 23:49:56 +00:00
|
|
|
handleTab();
|
2011-06-08 07:47:19 +00:00
|
|
|
// There are two cases for tab. Either we send a "next" event, that may change the
|
|
|
|
// focus but will never move the cursor. Or, we send a real tab keycode, which some
|
|
|
|
// applications may accept or ignore, and we don't know whether this will move the
|
|
|
|
// cursor or not. So actually, we don't really know.
|
|
|
|
// So to go with the safer option, we'd rather behave as if the user moved the
|
|
|
|
// cursor when they didn't than the opposite. We also expect that most applications
|
|
|
|
// will actually use tab only for focus movement.
|
|
|
|
// To sum it up: do not update mExpectingUpdateSelection here.
|
2010-10-22 10:35:23 +00:00
|
|
|
break;
|
|
|
|
default:
|
2011-10-25 12:14:33 +00:00
|
|
|
mSpaceState = SPACE_STATE_NONE;
|
2011-05-10 06:51:43 +00:00
|
|
|
if (mSettingsValues.isWordSeparator(primaryCode)) {
|
2012-01-26 08:20:51 +00:00
|
|
|
didAutoCorrect = handleSeparator(primaryCode, x, y, spaceState);
|
2010-10-22 10:35:23 +00:00
|
|
|
} else {
|
2011-10-25 12:14:33 +00:00
|
|
|
handleCharacter(primaryCode, keyCodes, x, y, spaceState);
|
2010-10-22 10:35:23 +00:00
|
|
|
}
|
2011-06-08 07:47:19 +00:00
|
|
|
mExpectingUpdateSelection = true;
|
|
|
|
break;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2011-12-07 10:31:11 +00:00
|
|
|
switcher.onCodeInput(primaryCode);
|
2010-04-01 13:28:52 +00:00
|
|
|
// Reset after any single keystroke
|
2012-01-26 08:20:51 +00:00
|
|
|
if (!didAutoCorrect)
|
|
|
|
mLastComposedWord.deactivate();
|
2010-04-01 13:28:52 +00:00
|
|
|
mEnteredText = null;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-12-02 09:46:21 +00:00
|
|
|
@Override
|
2010-12-20 07:13:57 +00:00
|
|
|
public void onTextInput(CharSequence text) {
|
2011-03-25 00:42:09 +00:00
|
|
|
mVoiceProxy.commitVoiceInput();
|
2011-07-31 02:28:15 +00:00
|
|
|
final InputConnection ic = getCurrentInputConnection();
|
2009-03-13 22:11:42 +00:00
|
|
|
if (ic == null) return;
|
|
|
|
ic.beginBatchEdit();
|
2010-12-09 07:36:45 +00:00
|
|
|
commitTyped(ic);
|
2011-07-31 02:28:15 +00:00
|
|
|
maybeRemovePreviousPeriod(ic, text);
|
2009-03-13 22:11:42 +00:00
|
|
|
ic.commitText(text, 1);
|
|
|
|
ic.endBatchEdit();
|
2010-11-13 08:16:34 +00:00
|
|
|
mKeyboardSwitcher.updateShiftState();
|
2012-01-10 08:24:00 +00:00
|
|
|
mKeyboardSwitcher.onCodeInput(Keyboard.CODE_OUTPUT_TEXT);
|
2011-10-25 12:14:33 +00:00
|
|
|
mSpaceState = SPACE_STATE_NONE;
|
2010-04-01 13:28:52 +00:00
|
|
|
mEnteredText = text;
|
2012-01-26 07:37:47 +00:00
|
|
|
resetComposingState(true /* alsoResetLastComposedWord */);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2010-12-02 09:46:21 +00:00
|
|
|
@Override
|
2010-12-20 07:13:57 +00:00
|
|
|
public void onCancelInput() {
|
2010-09-07 06:37:59 +00:00
|
|
|
// User released a finger outside any key
|
2010-12-30 08:19:55 +00:00
|
|
|
mKeyboardSwitcher.onCancelInput();
|
2010-09-07 06:37:59 +00:00
|
|
|
}
|
|
|
|
|
2011-10-25 12:14:33 +00:00
|
|
|
private void handleBackspace(final int spaceState) {
|
2011-03-25 00:42:09 +00:00
|
|
|
if (mVoiceProxy.logAndRevertVoiceInput()) return;
|
2011-01-13 08:14:27 +00:00
|
|
|
final InputConnection ic = getCurrentInputConnection();
|
|
|
|
if (ic == null) return;
|
2010-08-20 05:35:02 +00:00
|
|
|
ic.beginBatchEdit();
|
2011-12-13 06:14:02 +00:00
|
|
|
handleBackspaceWhileInBatchEdit(spaceState, ic);
|
|
|
|
ic.endBatchEdit();
|
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
|
2011-12-13 06:14:02 +00:00
|
|
|
// "ic" may not be null.
|
|
|
|
private void handleBackspaceWhileInBatchEdit(final int spaceState, final InputConnection ic) {
|
2011-03-25 00:42:09 +00:00
|
|
|
mVoiceProxy.handleBackspace();
|
2010-03-04 14:34:21 +00:00
|
|
|
|
2011-12-13 06:17:57 +00:00
|
|
|
// In many cases, we may have to put the keyboard in auto-shift state again.
|
|
|
|
mHandler.postUpdateShiftKeyState();
|
|
|
|
|
2011-12-12 11:30:23 +00:00
|
|
|
if (mEnteredText != null && sameAsTextBeforeCursor(ic, mEnteredText)) {
|
|
|
|
// Cancel multi-character input: remove the text we just entered.
|
|
|
|
// This is triggered on backspace after a key that inputs multiple characters,
|
|
|
|
// like the smiley key or the .com key.
|
|
|
|
ic.deleteSurroundingText(mEnteredText.length(), 0);
|
|
|
|
// If we have mEnteredText, then we know that mHasUncommittedTypedChars == false.
|
|
|
|
// In addition we know that spaceState is false, and that we should not be
|
|
|
|
// reverting any autocorrect at this point. So we can safely return.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-13 14:24:37 +00:00
|
|
|
if (mWordComposer.isComposingWord()) {
|
2011-12-09 14:15:49 +00:00
|
|
|
final int length = mWordComposer.size();
|
2009-03-13 22:11:42 +00:00
|
|
|
if (length > 0) {
|
2011-07-12 01:29:29 +00:00
|
|
|
mWordComposer.deleteLast();
|
2011-12-13 07:11:50 +00:00
|
|
|
ic.setComposingText(getTextWithUnderline(mWordComposer.getTypedWord()), 1);
|
2011-12-13 14:24:37 +00:00
|
|
|
// If we have deleted the last remaining character of a word, then we are not
|
|
|
|
// isComposingWord() any more.
|
|
|
|
if (!mWordComposer.isComposingWord()) {
|
|
|
|
// Not composing word any more, so we can show bigrams.
|
2011-04-22 07:16:30 +00:00
|
|
|
mHandler.postUpdateBigramPredictions();
|
2011-04-20 02:50:05 +00:00
|
|
|
} else {
|
2011-12-13 14:24:37 +00:00
|
|
|
// Still composing a word, so we still have letters to deduce a suggestion from.
|
2011-04-20 02:50:05 +00:00
|
|
|
mHandler.postUpdateSuggestions();
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
} else {
|
|
|
|
ic.deleteSurroundingText(1, 0);
|
|
|
|
}
|
2011-12-12 06:09:17 +00:00
|
|
|
} else {
|
2012-01-17 01:28:05 +00:00
|
|
|
// We should be very careful about auto-correction cancellation and suggestion
|
|
|
|
// resuming here. The behavior needs to be different according to text field types,
|
|
|
|
// and it would be much clearer to test for them explicitly here rather than
|
|
|
|
// relying on implicit values like "whether the suggestion strip is displayed".
|
2012-01-26 08:16:40 +00:00
|
|
|
if (mLastComposedWord.canCancelAutoCorrect()) {
|
2011-12-13 06:20:36 +00:00
|
|
|
Utils.Stats.onAutoCorrectionCancellation();
|
|
|
|
cancelAutoCorrect(ic);
|
2011-10-25 12:14:33 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-12-13 06:20:36 +00:00
|
|
|
|
|
|
|
if (SPACE_STATE_DOUBLE == spaceState) {
|
|
|
|
if (revertDoubleSpace(ic)) {
|
|
|
|
// No need to reset mSpaceState, it has already be done (that's why we
|
|
|
|
// receive it as a parameter)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (SPACE_STATE_SWAP_PUNCTUATION == spaceState) {
|
|
|
|
if (revertSwapPunctuation(ic)) {
|
|
|
|
// Likewise
|
|
|
|
return;
|
|
|
|
}
|
2011-06-08 07:47:19 +00:00
|
|
|
}
|
2011-01-13 08:14:27 +00:00
|
|
|
|
2012-01-17 01:28:05 +00:00
|
|
|
// See the comment above: must be careful about resuming auto-suggestion.
|
2011-09-01 05:54:28 +00:00
|
|
|
if (mSuggestionsView != null && mSuggestionsView.dismissAddToDictionaryHint()) {
|
2010-08-03 18:47:42 +00:00
|
|
|
// Go back to the suggestion mode if the user canceled the
|
2010-10-05 13:51:59 +00:00
|
|
|
// "Touch again to save".
|
2012-01-17 02:55:23 +00:00
|
|
|
// NOTE: In general, we don't revert the word when backspacing
|
2010-08-03 18:47:42 +00:00
|
|
|
// from a manual suggestion pick. We deliberately chose a
|
|
|
|
// different behavior only in the case of picking the first
|
|
|
|
// suggestion (typed word). It's intentional to have made this
|
|
|
|
// inconsistent with backspacing after selecting other suggestions.
|
2011-12-12 06:09:17 +00:00
|
|
|
restartSuggestionsOnManuallyPickedTypedWord(ic);
|
2010-08-03 18:47:42 +00:00
|
|
|
} else {
|
2012-01-24 06:45:32 +00:00
|
|
|
// Here we must check whether there is a selection. If so we should remove the
|
|
|
|
// selected text, otherwise we should just delete the character before the cursor.
|
|
|
|
if (mLastSelectionStart != mLastSelectionEnd) {
|
|
|
|
final int lengthToDelete = mLastSelectionEnd - mLastSelectionStart;
|
|
|
|
ic.setSelection(mLastSelectionEnd, mLastSelectionEnd);
|
|
|
|
ic.deleteSurroundingText(lengthToDelete, 0);
|
|
|
|
} else {
|
|
|
|
if (NOT_A_CURSOR_POSITION == mLastSelectionEnd) {
|
|
|
|
// We don't know whether there is a selection or not. We just send a false
|
|
|
|
// hardware key event and let TextView sort it out for us. The problem
|
|
|
|
// here is, this is asynchronous with respect to the input connection
|
|
|
|
// batch edit, so it may flicker. But this only ever happens if backspace
|
|
|
|
// is pressed just after the IME is invoked, and then again only once.
|
|
|
|
// TODO: add an API call that gets the selection indices. This is available
|
|
|
|
// to the IME in the general case via onUpdateSelection anyway, and would
|
|
|
|
// allow us to remove this race condition.
|
|
|
|
sendDownUpKeyEvents(KeyEvent.KEYCODE_DEL);
|
|
|
|
} else {
|
|
|
|
ic.deleteSurroundingText(1, 0);
|
|
|
|
}
|
|
|
|
if (mDeleteCount > DELETE_ACCELERATE_AT) {
|
|
|
|
ic.deleteSurroundingText(1, 0);
|
|
|
|
}
|
2010-08-03 18:47:42 +00:00
|
|
|
}
|
2012-01-17 06:17:17 +00:00
|
|
|
if (isSuggestionsRequested()) {
|
|
|
|
restartSuggestionsOnWordBeforeCursorIfAtEndOfWord(ic);
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-12 23:49:56 +00:00
|
|
|
private void handleTab() {
|
|
|
|
final int imeOptions = getCurrentInputEditorInfo().imeOptions;
|
2011-03-24 06:18:49 +00:00
|
|
|
if (!EditorInfoCompatUtils.hasFlagNavigateNext(imeOptions)
|
|
|
|
&& !EditorInfoCompatUtils.hasFlagNavigatePrevious(imeOptions)) {
|
2010-11-12 23:49:56 +00:00
|
|
|
sendDownUpKeyEvents(KeyEvent.KEYCODE_TAB);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
final InputConnection ic = getCurrentInputConnection();
|
|
|
|
if (ic == null)
|
|
|
|
return;
|
|
|
|
|
2012-01-26 09:03:30 +00:00
|
|
|
final Keyboard keyboard = mKeyboardSwitcher.getKeyboard();
|
|
|
|
// True if keyboard is in either shift chording or manual shifted state.
|
|
|
|
final boolean isManualShifted = (keyboard != null && keyboard.isManualShifted());
|
|
|
|
if (EditorInfoCompatUtils.hasFlagNavigateNext(imeOptions) && !isManualShifted) {
|
2011-03-24 06:18:49 +00:00
|
|
|
EditorInfoCompatUtils.performEditorActionNext(ic);
|
2012-01-26 09:03:30 +00:00
|
|
|
} else if (EditorInfoCompatUtils.hasFlagNavigatePrevious(imeOptions) && isManualShifted) {
|
2011-03-24 06:18:49 +00:00
|
|
|
EditorInfoCompatUtils.performEditorActionPrevious(ic);
|
2010-11-12 23:49:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-25 12:14:33 +00:00
|
|
|
private void handleCharacter(final int primaryCode, final int[] keyCodes, final int x,
|
|
|
|
final int y, final int spaceState) {
|
2011-03-25 00:42:09 +00:00
|
|
|
mVoiceProxy.handleCharacter();
|
2011-10-25 08:32:04 +00:00
|
|
|
final InputConnection ic = getCurrentInputConnection();
|
2011-12-13 12:12:07 +00:00
|
|
|
if (null != ic) ic.beginBatchEdit();
|
|
|
|
// TODO: if ic is null, does it make any sense to call this?
|
|
|
|
handleCharacterWhileInBatchEdit(primaryCode, keyCodes, x, y, spaceState, ic);
|
|
|
|
if (null != ic) ic.endBatchEdit();
|
|
|
|
}
|
|
|
|
|
|
|
|
// "ic" may be null without this crashing, but the behavior will be really strange
|
|
|
|
private void handleCharacterWhileInBatchEdit(final int primaryCode, final int[] keyCodes,
|
|
|
|
final int x, final int y, final int spaceState, final InputConnection ic) {
|
2011-10-25 12:14:33 +00:00
|
|
|
if (SPACE_STATE_MAGIC == spaceState
|
2011-10-24 09:00:05 +00:00
|
|
|
&& mSettingsValues.isMagicSpaceStripper(primaryCode)) {
|
2011-12-13 12:12:07 +00:00
|
|
|
if (null != ic) removeTrailingSpaceWhileInBatchEdit(ic);
|
2011-04-28 06:39:39 +00:00
|
|
|
}
|
|
|
|
|
2011-12-13 14:24:37 +00:00
|
|
|
boolean isComposingWord = mWordComposer.isComposingWord();
|
2010-12-10 06:24:28 +00:00
|
|
|
int code = primaryCode;
|
2011-08-03 15:23:17 +00:00
|
|
|
if ((isAlphabet(code) || mSettingsValues.isSymbolExcludedFromWordSeparators(code))
|
|
|
|
&& isSuggestionsRequested() && !isCursorTouchingWord()) {
|
2011-12-13 13:06:02 +00:00
|
|
|
if (!isComposingWord) {
|
2011-11-22 09:29:51 +00:00
|
|
|
// Reset entirely the composing state anyway, then start composing a new word unless
|
2011-12-13 13:06:02 +00:00
|
|
|
// the character is a single quote. The idea here is, single quote is not a
|
|
|
|
// separator and it should be treated as a normal character, except in the first
|
|
|
|
// position where it should not start composing a word.
|
|
|
|
isComposingWord = (Keyboard.CODE_SINGLE_QUOTE != code);
|
2012-01-26 07:37:47 +00:00
|
|
|
// Here we don't need to reset the last composed word. It will be reset
|
|
|
|
// when we commit this one, if we ever do; if on the other hand we backspace
|
|
|
|
// it entirely and resume suggestions on the previous word, we'd like to still
|
|
|
|
// have touch coordinates for it.
|
|
|
|
resetComposingState(false /* alsoResetLastComposedWord */);
|
2011-03-02 06:56:17 +00:00
|
|
|
clearSuggestions();
|
2011-10-12 09:07:09 +00:00
|
|
|
mComposingStateManager.onFinishComposingText();
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
}
|
2011-12-13 13:06:02 +00:00
|
|
|
if (isComposingWord) {
|
2011-07-12 01:29:29 +00:00
|
|
|
mWordComposer.add(code, keyCodes, x, y);
|
2009-03-13 22:11:42 +00:00
|
|
|
if (ic != null) {
|
2010-01-24 15:34:07 +00:00
|
|
|
// If it's the first letter, make note of auto-caps state
|
2011-07-12 01:29:29 +00:00
|
|
|
if (mWordComposer.size() == 1) {
|
|
|
|
mWordComposer.setAutoCapitalized(getCurrentAutoCapsState());
|
2011-10-12 09:07:09 +00:00
|
|
|
mComposingStateManager.onStartComposingText();
|
2010-01-24 15:34:07 +00:00
|
|
|
}
|
2011-12-13 07:11:50 +00:00
|
|
|
ic.setComposingText(getTextWithUnderline(mWordComposer.getTypedWord()), 1);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-11-16 09:07:06 +00:00
|
|
|
mHandler.postUpdateSuggestions();
|
2009-03-13 22:11:42 +00:00
|
|
|
} else {
|
2010-12-10 06:24:28 +00:00
|
|
|
sendKeyChar((char)code);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2011-10-25 12:14:33 +00:00
|
|
|
if (SPACE_STATE_MAGIC == spaceState
|
2011-10-24 09:00:05 +00:00
|
|
|
&& mSettingsValues.isMagicSpaceSwapper(primaryCode)) {
|
2011-10-25 08:32:04 +00:00
|
|
|
if (null != ic) swapSwapperAndSpaceWhileInBatchEdit(ic);
|
2011-05-09 07:54:07 +00:00
|
|
|
}
|
|
|
|
|
2011-12-12 07:22:07 +00:00
|
|
|
if (mSettingsValues.isWordSeparator(code)) {
|
|
|
|
Utils.Stats.onSeparator((char)code, x, y);
|
|
|
|
} else {
|
|
|
|
Utils.Stats.onNonSeparator((char)code, x, y);
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2012-01-26 08:20:51 +00:00
|
|
|
// Returns true if we did an autocorrection, false otherwise.
|
|
|
|
private boolean handleSeparator(final int primaryCode, final int x, final int y,
|
2011-10-25 12:14:33 +00:00
|
|
|
final int spaceState) {
|
2011-03-25 00:42:09 +00:00
|
|
|
mVoiceProxy.handleSeparator();
|
2011-10-12 09:07:09 +00:00
|
|
|
mComposingStateManager.onFinishComposingText();
|
2010-03-04 14:34:21 +00:00
|
|
|
|
2010-10-05 13:51:59 +00:00
|
|
|
// Should dismiss the "Touch again to save" message when handling separator
|
2011-09-01 05:54:28 +00:00
|
|
|
if (mSuggestionsView != null && mSuggestionsView.dismissAddToDictionaryHint()) {
|
2011-04-22 07:16:30 +00:00
|
|
|
mHandler.cancelUpdateBigramPredictions();
|
2010-11-16 09:07:06 +00:00
|
|
|
mHandler.postUpdateSuggestions();
|
2010-08-03 18:47:42 +00:00
|
|
|
}
|
|
|
|
|
2012-01-26 08:20:51 +00:00
|
|
|
boolean didAutoCorrect = false;
|
2009-03-13 22:11:42 +00:00
|
|
|
// Handle separator
|
2010-12-11 08:06:24 +00:00
|
|
|
final InputConnection ic = getCurrentInputConnection();
|
2009-03-13 22:11:42 +00:00
|
|
|
if (ic != null) {
|
|
|
|
ic.beginBatchEdit();
|
|
|
|
}
|
2011-12-13 14:24:37 +00:00
|
|
|
if (mWordComposer.isComposingWord()) {
|
2009-03-13 22:11:42 +00:00
|
|
|
// In certain languages where single quote is a separator, it's better
|
2010-01-28 18:09:44 +00:00
|
|
|
// not to auto correct, but accept the typed word. For instance,
|
2009-03-13 22:11:42 +00:00
|
|
|
// in Italian dov' should not be expanded to dove' because the elision
|
|
|
|
// requires the last vowel to be removed.
|
2011-07-25 13:44:52 +00:00
|
|
|
final boolean shouldAutoCorrect = mSettingsValues.mAutoCorrectEnabled
|
2011-12-16 03:57:27 +00:00
|
|
|
&& !mInputAttributes.mInputTypeNoAutoCorrect;
|
2011-05-10 06:51:43 +00:00
|
|
|
if (shouldAutoCorrect && primaryCode != Keyboard.CODE_SINGLE_QUOTE) {
|
2011-12-14 08:59:01 +00:00
|
|
|
commitCurrentAutoCorrection(primaryCode, ic);
|
2012-01-26 08:20:51 +00:00
|
|
|
didAutoCorrect = true;
|
2009-03-13 22:11:42 +00:00
|
|
|
} else {
|
|
|
|
commitTyped(ic);
|
|
|
|
}
|
|
|
|
}
|
2010-02-22 14:55:45 +00:00
|
|
|
|
2011-10-25 12:14:33 +00:00
|
|
|
final boolean swapMagicSpace;
|
2011-10-26 11:59:17 +00:00
|
|
|
if (Keyboard.CODE_ENTER == primaryCode && (SPACE_STATE_MAGIC == spaceState
|
|
|
|
|| SPACE_STATE_SWAP_PUNCTUATION == spaceState)) {
|
|
|
|
removeTrailingSpaceWhileInBatchEdit(ic);
|
|
|
|
swapMagicSpace = false;
|
|
|
|
} else if (SPACE_STATE_MAGIC == spaceState) {
|
2011-05-10 06:51:43 +00:00
|
|
|
if (mSettingsValues.isMagicSpaceSwapper(primaryCode)) {
|
2011-10-25 12:14:33 +00:00
|
|
|
swapMagicSpace = true;
|
2011-05-09 07:54:07 +00:00
|
|
|
} else {
|
2011-10-25 12:14:33 +00:00
|
|
|
swapMagicSpace = false;
|
2011-10-25 08:32:04 +00:00
|
|
|
if (mSettingsValues.isMagicSpaceStripper(primaryCode)) {
|
|
|
|
removeTrailingSpaceWhileInBatchEdit(ic);
|
|
|
|
}
|
2011-05-09 07:54:07 +00:00
|
|
|
}
|
2011-04-28 06:39:39 +00:00
|
|
|
} else {
|
2011-10-25 12:14:33 +00:00
|
|
|
swapMagicSpace = false;
|
2011-05-09 07:54:07 +00:00
|
|
|
}
|
|
|
|
|
2011-10-25 12:14:33 +00:00
|
|
|
sendKeyChar((char)primaryCode);
|
2011-04-20 02:50:05 +00:00
|
|
|
|
|
|
|
if (Keyboard.CODE_SPACE == primaryCode) {
|
2011-10-25 12:14:33 +00:00
|
|
|
if (isSuggestionsRequested()) {
|
|
|
|
if (maybeDoubleSpaceWhileInBatchEdit(ic)) {
|
|
|
|
mSpaceState = SPACE_STATE_DOUBLE;
|
|
|
|
} else if (!isShowingPunctuationList()) {
|
|
|
|
mSpaceState = SPACE_STATE_WEAK;
|
|
|
|
}
|
2011-10-24 09:00:05 +00:00
|
|
|
}
|
2011-10-25 12:14:33 +00:00
|
|
|
|
|
|
|
mHandler.startDoubleSpacesTimer();
|
2011-04-20 02:50:05 +00:00
|
|
|
if (!isCursorTouchingWord()) {
|
|
|
|
mHandler.cancelUpdateSuggestions();
|
2011-04-22 07:16:30 +00:00
|
|
|
mHandler.postUpdateBigramPredictions();
|
2011-04-20 02:50:05 +00:00
|
|
|
}
|
|
|
|
} else {
|
2011-10-25 12:14:33 +00:00
|
|
|
if (swapMagicSpace) {
|
|
|
|
swapSwapperAndSpaceWhileInBatchEdit(ic);
|
|
|
|
mSpaceState = SPACE_STATE_MAGIC;
|
|
|
|
}
|
|
|
|
|
2011-04-20 02:50:05 +00:00
|
|
|
// Set punctuation right away. onUpdateSelection will fire but tests whether it is
|
|
|
|
// already displayed or not, so it's okay.
|
2010-12-09 07:36:45 +00:00
|
|
|
setPunctuationSuggestions();
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2011-10-25 12:14:33 +00:00
|
|
|
|
2011-12-12 07:22:07 +00:00
|
|
|
Utils.Stats.onSeparator((char)primaryCode, x, y);
|
2011-10-25 12:14:33 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
if (ic != null) {
|
|
|
|
ic.endBatchEdit();
|
|
|
|
}
|
2012-01-26 08:20:51 +00:00
|
|
|
return didAutoCorrect;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-01-16 20:21:23 +00:00
|
|
|
|
2011-12-13 07:11:50 +00:00
|
|
|
private CharSequence getTextWithUnderline(final CharSequence text) {
|
|
|
|
return mComposingStateManager.isAutoCorrectionIndicatorOn()
|
|
|
|
? SuggestionSpanUtils.getTextWithAutoCorrectionIndicatorUnderline(this, text)
|
2012-01-26 02:40:16 +00:00
|
|
|
: text;
|
2011-12-13 07:11:50 +00:00
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
private void handleClose() {
|
|
|
|
commitTyped(getCurrentInputConnection());
|
2011-03-25 00:42:09 +00:00
|
|
|
mVoiceProxy.handleClose();
|
2009-03-13 22:11:42 +00:00
|
|
|
requestHideSelf(0);
|
2011-08-23 08:57:02 +00:00
|
|
|
LatinKeyboardView inputView = mKeyboardSwitcher.getKeyboardView();
|
2010-11-13 08:01:13 +00:00
|
|
|
if (inputView != null)
|
|
|
|
inputView.closing();
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2011-05-06 09:27:24 +00:00
|
|
|
public boolean isSuggestionsRequested() {
|
2011-12-16 03:57:27 +00:00
|
|
|
return mInputAttributes.mIsSettingsSuggestionStripOn
|
2011-01-18 06:28:21 +00:00
|
|
|
&& (mCorrectionMode > 0 || isShowingSuggestionsStrip());
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2011-05-06 09:27:24 +00:00
|
|
|
public boolean isShowingPunctuationList() {
|
2011-10-25 17:35:44 +00:00
|
|
|
if (mSuggestionsView == null) return false;
|
2011-09-01 05:54:28 +00:00
|
|
|
return mSettingsValues.mSuggestPuncList == mSuggestionsView.getSuggestions();
|
2010-11-13 10:09:30 +00:00
|
|
|
}
|
|
|
|
|
2011-05-06 09:27:24 +00:00
|
|
|
public boolean isShowingSuggestionsStrip() {
|
2010-11-13 10:09:30 +00:00
|
|
|
return (mSuggestionVisibility == SUGGESTION_VISIBILILTY_SHOW_VALUE)
|
|
|
|
|| (mSuggestionVisibility == SUGGESTION_VISIBILILTY_SHOW_ONLY_PORTRAIT_VALUE
|
2011-07-21 06:57:00 +00:00
|
|
|
&& mDisplayOrientation == Configuration.ORIENTATION_PORTRAIT);
|
2010-11-13 10:09:30 +00:00
|
|
|
}
|
|
|
|
|
2011-09-01 05:54:28 +00:00
|
|
|
public boolean isSuggestionsStripVisible() {
|
|
|
|
if (mSuggestionsView == null)
|
2011-01-26 16:33:02 +00:00
|
|
|
return false;
|
2011-10-25 12:54:35 +00:00
|
|
|
if (mSuggestionsView.isShowingAddToDictionaryHint())
|
2010-12-19 08:32:26 +00:00
|
|
|
return true;
|
|
|
|
if (!isShowingSuggestionsStrip())
|
|
|
|
return false;
|
2011-12-16 03:57:27 +00:00
|
|
|
if (mInputAttributes.mApplicationSpecifiedCompletionOn)
|
2010-12-19 08:32:26 +00:00
|
|
|
return true;
|
|
|
|
return isSuggestionsRequested();
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2010-11-21 01:36:37 +00:00
|
|
|
public void switchToKeyboardView() {
|
2011-02-17 08:45:46 +00:00
|
|
|
if (DEBUG) {
|
|
|
|
Log.d(TAG, "Switch to keyboard view.");
|
|
|
|
}
|
2011-05-23 09:30:21 +00:00
|
|
|
View v = mKeyboardSwitcher.getKeyboardView();
|
2011-02-17 08:45:46 +00:00
|
|
|
if (v != null) {
|
|
|
|
// Confirms that the keyboard view doesn't have parent view.
|
|
|
|
ViewParent p = v.getParent();
|
|
|
|
if (p != null && p instanceof ViewGroup) {
|
|
|
|
((ViewGroup) p).removeView(v);
|
2010-12-02 09:46:21 +00:00
|
|
|
}
|
2011-02-17 08:45:46 +00:00
|
|
|
setInputView(v);
|
|
|
|
}
|
2011-09-01 05:54:28 +00:00
|
|
|
setSuggestionStripShown(isSuggestionsStripVisible());
|
2011-02-17 08:45:46 +00:00
|
|
|
updateInputViewShown();
|
|
|
|
mHandler.postUpdateSuggestions();
|
2010-01-16 20:21:23 +00:00
|
|
|
}
|
|
|
|
|
2010-11-21 01:36:37 +00:00
|
|
|
public void clearSuggestions() {
|
2010-12-10 11:50:30 +00:00
|
|
|
setSuggestions(SuggestedWords.EMPTY);
|
2010-01-16 20:21:23 +00:00
|
|
|
}
|
|
|
|
|
2010-12-10 11:50:30 +00:00
|
|
|
public void setSuggestions(SuggestedWords words) {
|
2011-09-01 05:54:28 +00:00
|
|
|
if (mSuggestionsView != null) {
|
|
|
|
mSuggestionsView.setSuggestions(words);
|
2011-06-18 04:33:48 +00:00
|
|
|
mKeyboardSwitcher.onAutoCorrectionStateChanged(
|
|
|
|
words.hasWordAboveAutoCorrectionScoreThreshold());
|
2010-01-16 20:21:23 +00:00
|
|
|
}
|
2011-09-28 06:59:11 +00:00
|
|
|
|
|
|
|
// Put a blue underline to a word in TextView which will be auto-corrected.
|
|
|
|
final InputConnection ic = getCurrentInputConnection();
|
2011-10-12 09:07:09 +00:00
|
|
|
if (ic != null) {
|
|
|
|
final boolean oldAutoCorrectionIndicator =
|
|
|
|
mComposingStateManager.isAutoCorrectionIndicatorOn();
|
|
|
|
final boolean newAutoCorrectionIndicator = Utils.willAutoCorrect(words);
|
|
|
|
if (oldAutoCorrectionIndicator != newAutoCorrectionIndicator) {
|
2011-12-13 07:11:50 +00:00
|
|
|
mComposingStateManager.setAutoCorrectionIndicatorOn(newAutoCorrectionIndicator);
|
|
|
|
if (DEBUG) {
|
2011-10-17 02:27:31 +00:00
|
|
|
Log.d(TAG, "Flip the indicator. " + oldAutoCorrectionIndicator
|
|
|
|
+ " -> " + newAutoCorrectionIndicator);
|
2012-01-25 09:11:26 +00:00
|
|
|
if (mComposingStateManager.isComposing() && newAutoCorrectionIndicator
|
2011-12-13 07:11:50 +00:00
|
|
|
!= mComposingStateManager.isAutoCorrectionIndicatorOn()) {
|
2012-01-25 09:11:26 +00:00
|
|
|
throw new RuntimeException("Couldn't flip the indicator!");
|
2011-12-13 07:11:50 +00:00
|
|
|
}
|
2011-10-17 02:27:31 +00:00
|
|
|
}
|
2011-12-13 07:11:50 +00:00
|
|
|
final CharSequence textWithUnderline =
|
|
|
|
getTextWithUnderline(mWordComposer.getTypedWord());
|
2011-10-12 09:07:09 +00:00
|
|
|
if (!TextUtils.isEmpty(textWithUnderline)) {
|
|
|
|
ic.setComposingText(textWithUnderline, 1);
|
|
|
|
}
|
2011-09-28 06:59:11 +00:00
|
|
|
}
|
|
|
|
}
|
2010-01-16 20:21:23 +00:00
|
|
|
}
|
|
|
|
|
2010-11-21 01:36:37 +00:00
|
|
|
public void updateSuggestions() {
|
2009-03-13 22:11:42 +00:00
|
|
|
// Check if we have a suggestion engine attached.
|
2010-12-19 08:32:26 +00:00
|
|
|
if ((mSuggest == null || !isSuggestionsRequested())
|
2011-03-25 00:42:09 +00:00
|
|
|
&& !mVoiceProxy.isVoiceInputHighlighted()) {
|
2012-01-17 06:17:17 +00:00
|
|
|
if (mWordComposer.isComposingWord()) {
|
|
|
|
Log.w(TAG, "Called updateSuggestions but suggestions were not requested!");
|
|
|
|
mWordComposer.setAutoCorrection(mWordComposer.getTypedWord());
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-01-16 20:21:23 +00:00
|
|
|
|
2011-10-03 06:50:11 +00:00
|
|
|
mHandler.cancelUpdateSuggestions();
|
|
|
|
mHandler.cancelUpdateBigramPredictions();
|
|
|
|
|
2011-12-13 14:24:37 +00:00
|
|
|
if (!mWordComposer.isComposingWord()) {
|
2010-11-11 04:37:18 +00:00
|
|
|
setPunctuationSuggestions();
|
2009-03-13 22:11:42 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
|
2011-03-02 06:40:08 +00:00
|
|
|
// TODO: May need a better way of retrieving previous word
|
2011-07-19 09:59:12 +00:00
|
|
|
final InputConnection ic = getCurrentInputConnection();
|
|
|
|
final CharSequence prevWord;
|
|
|
|
if (null == ic) {
|
|
|
|
prevWord = null;
|
|
|
|
} else {
|
|
|
|
prevWord = EditingUtils.getPreviousWord(ic, mSettingsValues.mWordSeparators);
|
|
|
|
}
|
|
|
|
// getSuggestedWordBuilder handles gracefully a null value of prevWord
|
2011-12-13 14:08:12 +00:00
|
|
|
final SuggestedWords.Builder builder = mSuggest.getSuggestedWordBuilder(mWordComposer,
|
2011-12-17 23:36:16 +00:00
|
|
|
prevWord, mKeyboardSwitcher.getKeyboard().getProximityInfo(), mCorrectionMode);
|
2009-03-13 22:11:42 +00:00
|
|
|
|
2011-12-16 03:57:27 +00:00
|
|
|
boolean autoCorrectionAvailable = !mInputAttributes.mInputTypeNoAutoCorrect
|
|
|
|
&& mSuggest.hasAutoCorrection();
|
2011-12-13 14:08:12 +00:00
|
|
|
final CharSequence typedWord = mWordComposer.getTypedWord();
|
2011-03-04 07:56:10 +00:00
|
|
|
// Here, we want to promote a whitelisted word if exists.
|
2011-10-07 07:34:19 +00:00
|
|
|
// TODO: Change this scheme - a boolean is not enough. A whitelisted word may be "valid"
|
|
|
|
// but still autocorrected from - in the case the whitelist only capitalizes the word.
|
|
|
|
// The whitelist should be case-insensitive, so it's not possible to be consistent with
|
|
|
|
// a boolean flag. Right now this is handled with a slight hack in
|
|
|
|
// WhitelistDictionary#shouldForciblyAutoCorrectFrom.
|
2011-12-13 14:08:12 +00:00
|
|
|
final int quotesCount = mWordComposer.trailingSingleQuotesCount();
|
2011-10-07 07:34:19 +00:00
|
|
|
final boolean allowsToBeAutoCorrected = AutoCorrection.allowsToBeAutoCorrected(
|
2011-11-18 11:03:38 +00:00
|
|
|
mSuggest.getUnigramDictionaries(),
|
|
|
|
// If the typed string ends with a single quote, for dictionary lookup purposes
|
|
|
|
// we behave as if the single quote was not here. Here, we are looking up the
|
|
|
|
// typed string in the dictionary (to avoid autocorrecting from an existing
|
|
|
|
// word, so for consistency this lookup should be made WITHOUT the trailing
|
|
|
|
// single quote.
|
2011-11-29 05:15:41 +00:00
|
|
|
quotesCount > 0
|
|
|
|
? typedWord.subSequence(0, typedWord.length() - quotesCount) : typedWord,
|
2011-11-18 11:03:38 +00:00
|
|
|
preferCapitalization());
|
2010-08-20 05:35:02 +00:00
|
|
|
if (mCorrectionMode == Suggest.CORRECTION_FULL
|
|
|
|
|| mCorrectionMode == Suggest.CORRECTION_FULL_BIGRAM) {
|
2011-10-07 07:34:19 +00:00
|
|
|
autoCorrectionAvailable |= (!allowsToBeAutoCorrected);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2009-07-23 19:17:48 +00:00
|
|
|
// Don't auto-correct words with multiple capital letter
|
2011-12-13 14:08:12 +00:00
|
|
|
autoCorrectionAvailable &= !mWordComposer.isMostlyCaps();
|
2010-08-20 05:35:02 +00:00
|
|
|
|
2011-01-10 02:59:46 +00:00
|
|
|
// Basically, we update the suggestion strip only when suggestion count > 1. However,
|
|
|
|
// there is an exception: We update the suggestion strip whenever typed word's length
|
2011-01-21 06:03:09 +00:00
|
|
|
// is 1 or typed word is found in dictionary, regardless of suggestion count. Actually,
|
|
|
|
// in most cases, suggestion count is 1 when typed word's length is 1, but we do always
|
|
|
|
// need to clear the previous state when the user starts typing a word (i.e. typed word's
|
|
|
|
// length == 1).
|
2011-05-13 11:27:01 +00:00
|
|
|
if (typedWord != null) {
|
2011-10-07 07:34:19 +00:00
|
|
|
if (builder.size() > 1 || typedWord.length() == 1 || (!allowsToBeAutoCorrected)
|
2011-09-01 05:54:28 +00:00
|
|
|
|| mSuggestionsView.isShowingAddToDictionaryHint()) {
|
2011-10-07 07:34:19 +00:00
|
|
|
builder.setTypedWordValid(!allowsToBeAutoCorrected).setHasMinimalSuggestion(
|
2011-07-12 07:47:08 +00:00
|
|
|
autoCorrectionAvailable);
|
2011-05-13 11:27:01 +00:00
|
|
|
} else {
|
2011-09-29 06:58:58 +00:00
|
|
|
SuggestedWords previousSuggestions = mSuggestionsView.getSuggestions();
|
|
|
|
if (previousSuggestions == mSettingsValues.mSuggestPuncList) {
|
|
|
|
if (builder.size() == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
previousSuggestions = SuggestedWords.EMPTY;
|
|
|
|
}
|
2011-05-13 11:27:01 +00:00
|
|
|
builder.addTypedWordAndPreviousSuggestions(typedWord, previousSuggestions);
|
|
|
|
}
|
2010-12-19 08:32:26 +00:00
|
|
|
}
|
2010-12-10 11:50:30 +00:00
|
|
|
showSuggestions(builder.build(), typedWord);
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|
2009-07-23 19:17:48 +00:00
|
|
|
|
2011-05-10 07:40:28 +00:00
|
|
|
public void showSuggestions(SuggestedWords suggestedWords, CharSequence typedWord) {
|
2011-10-13 05:25:26 +00:00
|
|
|
final boolean shouldBlockAutoCorrectionBySafetyNet =
|
|
|
|
Utils.shouldBlockAutoCorrectionBySafetyNet(suggestedWords, mSuggest);
|
|
|
|
if (shouldBlockAutoCorrectionBySafetyNet) {
|
|
|
|
suggestedWords.setShouldBlockAutoCorrection();
|
|
|
|
}
|
2010-12-10 11:50:30 +00:00
|
|
|
setSuggestions(suggestedWords);
|
|
|
|
if (suggestedWords.size() > 0) {
|
2011-10-13 05:25:26 +00:00
|
|
|
if (shouldBlockAutoCorrectionBySafetyNet) {
|
2011-12-13 10:38:36 +00:00
|
|
|
mWordComposer.setAutoCorrection(typedWord);
|
2011-01-18 08:22:01 +00:00
|
|
|
} else if (suggestedWords.hasAutoCorrectionWord()) {
|
2011-12-13 10:38:36 +00:00
|
|
|
mWordComposer.setAutoCorrection(suggestedWords.getWord(1));
|
2009-03-13 22:11:42 +00:00
|
|
|
} else {
|
2011-12-13 10:38:36 +00:00
|
|
|
mWordComposer.setAutoCorrection(typedWord);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
} else {
|
2011-12-13 10:38:36 +00:00
|
|
|
// TODO: replace with mWordComposer.deleteAutoCorrection()?
|
|
|
|
mWordComposer.setAutoCorrection(null);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2011-09-01 05:54:28 +00:00
|
|
|
setSuggestionStripShown(isSuggestionsStripVisible());
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2011-12-14 08:59:01 +00:00
|
|
|
private void commitCurrentAutoCorrection(final int separatorCodePoint,
|
|
|
|
final InputConnection ic) {
|
2011-09-01 05:54:28 +00:00
|
|
|
// Complete any pending suggestions query first
|
2010-11-16 09:07:06 +00:00
|
|
|
if (mHandler.hasPendingUpdateSuggestions()) {
|
|
|
|
mHandler.cancelUpdateSuggestions();
|
2009-03-13 22:11:42 +00:00
|
|
|
updateSuggestions();
|
|
|
|
}
|
2011-12-13 10:38:36 +00:00
|
|
|
final CharSequence autoCorrection = mWordComposer.getAutoCorrectionOrNull();
|
|
|
|
if (autoCorrection != null) {
|
|
|
|
final String typedWord = mWordComposer.getTypedWord();
|
2011-12-14 08:54:18 +00:00
|
|
|
if (TextUtils.isEmpty(typedWord)) {
|
|
|
|
throw new RuntimeException("We have an auto-correction but the typed word "
|
|
|
|
+ "is empty? Impossible! I must commit suicide.");
|
|
|
|
}
|
2011-12-14 08:59:01 +00:00
|
|
|
Utils.Stats.onAutoCorrection(typedWord, autoCorrection.toString(), separatorCodePoint);
|
2011-06-08 07:47:19 +00:00
|
|
|
mExpectingUpdateSelection = true;
|
2012-01-26 06:52:55 +00:00
|
|
|
commitChosenWord(autoCorrection, LastComposedWord.COMMIT_TYPE_DECIDED_WORD);
|
2011-07-14 22:57:26 +00:00
|
|
|
// Add the word to the user unigram dictionary if it's not a known word
|
2011-12-13 10:38:36 +00:00
|
|
|
addToUserUnigramAndBigramDictionaries(autoCorrection,
|
2011-07-14 22:57:26 +00:00
|
|
|
UserUnigramDictionary.FREQUENCY_FOR_TYPED);
|
2011-12-14 08:59:01 +00:00
|
|
|
if (!typedWord.equals(autoCorrection) && null != ic) {
|
2011-12-14 08:56:57 +00:00
|
|
|
// This will make the correction flash for a short while as a visual clue
|
|
|
|
// to the user that auto-correction happened.
|
|
|
|
InputConnectionCompatUtils.commitCorrection(ic,
|
|
|
|
mLastSelectionEnd - typedWord.length(), typedWord, autoCorrection);
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-09 05:22:37 +00:00
|
|
|
@Override
|
2009-03-13 22:11:42 +00:00
|
|
|
public void pickSuggestionManually(int index, CharSequence suggestion) {
|
2011-10-12 09:07:09 +00:00
|
|
|
mComposingStateManager.onFinishComposingText();
|
2011-09-01 05:54:28 +00:00
|
|
|
SuggestedWords suggestions = mSuggestionsView.getSuggestions();
|
2011-05-10 06:51:43 +00:00
|
|
|
mVoiceProxy.flushAndLogAllTextModificationCounters(index, suggestion,
|
|
|
|
mSettingsValues.mWordSeparators);
|
2010-03-04 14:34:21 +00:00
|
|
|
|
2011-07-31 02:28:15 +00:00
|
|
|
final InputConnection ic = getCurrentInputConnection();
|
2010-02-07 00:34:43 +00:00
|
|
|
if (ic != null) {
|
|
|
|
ic.beginBatchEdit();
|
|
|
|
}
|
2011-12-16 03:57:27 +00:00
|
|
|
if (mInputAttributes.mApplicationSpecifiedCompletionOn
|
|
|
|
&& mApplicationSpecifiedCompletions != null
|
2010-12-11 08:06:24 +00:00
|
|
|
&& index >= 0 && index < mApplicationSpecifiedCompletions.length) {
|
2009-03-13 22:11:42 +00:00
|
|
|
if (ic != null) {
|
2011-07-31 02:28:15 +00:00
|
|
|
final CompletionInfo completionInfo = mApplicationSpecifiedCompletions[index];
|
|
|
|
ic.commitCompletion(completionInfo);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2011-09-01 05:54:28 +00:00
|
|
|
if (mSuggestionsView != null) {
|
|
|
|
mSuggestionsView.clear();
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-11-13 08:16:34 +00:00
|
|
|
mKeyboardSwitcher.updateShiftState();
|
2010-02-07 00:34:43 +00:00
|
|
|
if (ic != null) {
|
|
|
|
ic.endBatchEdit();
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-02-03 23:35:49 +00:00
|
|
|
|
|
|
|
// If this is a punctuation, apply it through the normal key press
|
2011-05-10 06:51:43 +00:00
|
|
|
if (suggestion.length() == 1 && (mSettingsValues.isWordSeparator(suggestion.charAt(0))
|
|
|
|
|| mSettingsValues.isSuggestedPunctuation(suggestion.charAt(0)))) {
|
2010-08-20 05:35:02 +00:00
|
|
|
// Word separators are suggested before the user inputs something.
|
|
|
|
// So, LatinImeLogger logs "" as a user's input.
|
|
|
|
LatinImeLogger.logOnManualSuggestion(
|
2010-12-10 11:50:30 +00:00
|
|
|
"", suggestion.toString(), index, suggestions.mWords);
|
2011-05-09 07:54:07 +00:00
|
|
|
// Find out whether the previous character is a space. If it is, as a special case
|
2011-10-25 12:14:33 +00:00
|
|
|
// for punctuation entered through the suggestion strip, it should be swapped
|
|
|
|
// if it was a magic or a weak space. This is meant to help in case the user
|
2011-05-09 07:54:07 +00:00
|
|
|
// pressed space on purpose of displaying the suggestion strip punctuation.
|
2011-07-25 22:55:12 +00:00
|
|
|
final int rawPrimaryCode = suggestion.charAt(0);
|
|
|
|
// Maybe apply the "bidi mirrored" conversions for parentheses
|
2011-12-17 23:36:16 +00:00
|
|
|
final Keyboard keyboard = mKeyboardSwitcher.getKeyboard();
|
2011-10-20 11:31:17 +00:00
|
|
|
final boolean isRtl = keyboard != null && keyboard.mIsRtlKeyboard;
|
|
|
|
final int primaryCode = Key.getRtlParenthesisCode(rawPrimaryCode, isRtl);
|
2011-07-25 22:55:12 +00:00
|
|
|
|
2011-10-25 12:14:33 +00:00
|
|
|
insertPunctuationFromSuggestionStrip(ic, primaryCode);
|
|
|
|
// TODO: the following endBatchEdit seems useless, check
|
2010-02-07 00:34:43 +00:00
|
|
|
if (ic != null) {
|
|
|
|
ic.endBatchEdit();
|
|
|
|
}
|
2010-02-03 23:35:49 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-01-20 06:39:06 +00:00
|
|
|
// We need to log before we commit, because the word composer will store away the user
|
|
|
|
// typed word.
|
|
|
|
LatinImeLogger.logOnManualSuggestion(mWordComposer.getTypedWord().toString(),
|
|
|
|
suggestion.toString(), index, suggestions.mWords);
|
2011-06-08 07:47:19 +00:00
|
|
|
mExpectingUpdateSelection = true;
|
2012-01-26 06:52:55 +00:00
|
|
|
commitChosenWord(suggestion, LastComposedWord.COMMIT_TYPE_MANUAL_PICK);
|
2010-02-25 18:37:19 +00:00
|
|
|
// Add the word to the auto dictionary if it's not a known word
|
2010-03-24 23:44:31 +00:00
|
|
|
if (index == 0) {
|
2011-07-14 22:57:26 +00:00
|
|
|
addToUserUnigramAndBigramDictionaries(suggestion,
|
|
|
|
UserUnigramDictionary.FREQUENCY_FOR_PICKED);
|
2010-08-20 05:35:02 +00:00
|
|
|
} else {
|
2011-03-04 07:56:10 +00:00
|
|
|
addToOnlyBigramDictionary(suggestion, 1);
|
2010-03-24 23:44:31 +00:00
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
// Follow it with a space
|
2011-12-16 03:57:27 +00:00
|
|
|
if (mInputAttributes.mInsertSpaceOnPickSuggestionManually) {
|
2011-04-28 06:39:39 +00:00
|
|
|
sendMagicSpace();
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
|
2011-08-08 09:33:56 +00:00
|
|
|
// We should show the "Touch again to save" hint if the user pressed the first entry
|
|
|
|
// AND either:
|
2011-02-23 13:04:47 +00:00
|
|
|
// - There is no dictionary (we know that because we tried to load it => null != mSuggest
|
2011-08-08 09:33:56 +00:00
|
|
|
// AND mSuggest.hasMainDictionary() is false)
|
2011-02-23 13:04:47 +00:00
|
|
|
// - There is a dictionary and the word is not in it
|
|
|
|
// Please note that if mSuggest is null, it means that everything is off: suggestion
|
|
|
|
// and correction, so we shouldn't try to show the hint
|
|
|
|
// We used to look at mCorrectionMode here, but showing the hint should have nothing
|
|
|
|
// to do with the autocorrection setting.
|
2011-03-04 07:56:10 +00:00
|
|
|
final boolean showingAddToDictionaryHint = index == 0 && mSuggest != null
|
|
|
|
// If there is no dictionary the hint should be shown.
|
2011-08-08 09:33:56 +00:00
|
|
|
&& (!mSuggest.hasMainDictionary()
|
2011-03-04 07:56:10 +00:00
|
|
|
// If "suggestion" is not in the dictionary, the hint should be shown.
|
|
|
|
|| !AutoCorrection.isValidWord(
|
|
|
|
mSuggest.getUnigramDictionaries(), suggestion, true));
|
2010-08-26 19:22:58 +00:00
|
|
|
|
2011-12-12 07:22:07 +00:00
|
|
|
Utils.Stats.onSeparator((char)Keyboard.CODE_SPACE, WordComposer.NOT_A_COORDINATE,
|
|
|
|
WordComposer.NOT_A_COORDINATE);
|
2011-05-13 10:33:33 +00:00
|
|
|
if (!showingAddToDictionaryHint) {
|
2010-10-10 17:52:08 +00:00
|
|
|
// If we're not showing the "Touch again to save", then show corrections again.
|
2010-08-20 05:35:02 +00:00
|
|
|
// In case the cursor position doesn't change, make sure we show the suggestions again.
|
2011-05-26 03:31:52 +00:00
|
|
|
updateBigramPredictions();
|
|
|
|
// Updating the predictions right away may be slow and feel unresponsive on slower
|
|
|
|
// terminals. On the other hand if we just postUpdateBigramPredictions() it will
|
|
|
|
// take a noticeable delay to update them which may feel uneasy.
|
2012-01-19 09:03:45 +00:00
|
|
|
} else {
|
2011-11-18 06:24:49 +00:00
|
|
|
if (mIsUserDictionaryAvailable) {
|
2011-10-27 15:33:15 +00:00
|
|
|
mSuggestionsView.showAddToDictionaryHint(
|
|
|
|
suggestion, mSettingsValues.mHintToSaveText);
|
2011-07-22 05:32:36 +00:00
|
|
|
} else {
|
|
|
|
mHandler.postUpdateSuggestions();
|
|
|
|
}
|
2010-02-11 01:45:35 +00:00
|
|
|
}
|
2010-02-07 00:34:43 +00:00
|
|
|
if (ic != null) {
|
|
|
|
ic.endBatchEdit();
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-08-20 05:35:02 +00:00
|
|
|
/**
|
2011-07-12 07:47:08 +00:00
|
|
|
* Commits the chosen word to the text field and saves it for later retrieval.
|
2010-08-20 05:35:02 +00:00
|
|
|
*/
|
2011-12-20 08:52:29 +00:00
|
|
|
private void commitChosenWord(final CharSequence bestWord, final int commitType) {
|
2011-07-31 02:28:15 +00:00
|
|
|
final InputConnection ic = getCurrentInputConnection();
|
2009-03-13 22:11:42 +00:00
|
|
|
if (ic != null) {
|
2011-05-24 11:30:30 +00:00
|
|
|
mVoiceProxy.rememberReplacedWord(bestWord, mSettingsValues.mWordSeparators);
|
2011-09-02 05:09:10 +00:00
|
|
|
if (mSettingsValues.mEnableSuggestionSpanInsertion) {
|
|
|
|
final SuggestedWords suggestedWords = mSuggestionsView.getSuggestions();
|
|
|
|
ic.commitText(SuggestionSpanUtils.getTextWithSuggestionSpan(
|
|
|
|
this, bestWord, suggestedWords), 1);
|
|
|
|
} else {
|
|
|
|
ic.commitText(bestWord, 1);
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2011-12-20 08:52:29 +00:00
|
|
|
// TODO: figure out here if this is an auto-correct or if the best word is actually
|
|
|
|
// what user typed. Note: currently this is done much later in
|
2012-01-26 08:16:40 +00:00
|
|
|
// LastComposedWord#canCancelAutoCorrect by string equality of the remembered
|
2011-12-20 08:52:29 +00:00
|
|
|
// strings.
|
2012-01-26 07:37:47 +00:00
|
|
|
mLastComposedWord = mWordComposer.commitWord(commitType);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2011-04-20 02:50:05 +00:00
|
|
|
private static final WordComposer sEmptyWordComposer = new WordComposer();
|
2011-05-26 03:31:52 +00:00
|
|
|
public void updateBigramPredictions() {
|
2011-04-20 02:50:05 +00:00
|
|
|
if (mSuggest == null || !isSuggestionsRequested())
|
|
|
|
return;
|
|
|
|
|
2011-05-10 06:51:43 +00:00
|
|
|
if (!mSettingsValues.mBigramPredictionEnabled) {
|
2011-04-22 07:16:30 +00:00
|
|
|
setPunctuationSuggestions();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-04-20 02:50:05 +00:00
|
|
|
final CharSequence prevWord = EditingUtils.getThisWord(getCurrentInputConnection(),
|
2011-05-10 06:51:43 +00:00
|
|
|
mSettingsValues.mWordSeparators);
|
2011-10-03 05:28:40 +00:00
|
|
|
SuggestedWords.Builder builder = mSuggest.getSuggestedWordBuilder(sEmptyWordComposer,
|
2011-12-17 23:36:16 +00:00
|
|
|
prevWord, mKeyboardSwitcher.getKeyboard().getProximityInfo(), mCorrectionMode);
|
2011-04-20 02:50:05 +00:00
|
|
|
|
|
|
|
if (builder.size() > 0) {
|
|
|
|
// Explicitly supply an empty typed word (the no-second-arg version of
|
|
|
|
// showSuggestions will retrieve the word near the cursor, we don't want that here)
|
|
|
|
showSuggestions(builder.build(), "");
|
|
|
|
} else {
|
|
|
|
if (!isShowingPunctuationList()) setPunctuationSuggestions();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-06 09:27:24 +00:00
|
|
|
public void setPunctuationSuggestions() {
|
2011-05-10 06:51:43 +00:00
|
|
|
setSuggestions(mSettingsValues.mSuggestPuncList);
|
2011-09-01 05:54:28 +00:00
|
|
|
setSuggestionStripShown(isSuggestionsStripVisible());
|
2010-02-03 23:35:49 +00:00
|
|
|
}
|
|
|
|
|
2011-07-14 22:57:26 +00:00
|
|
|
private void addToUserUnigramAndBigramDictionaries(CharSequence suggestion,
|
|
|
|
int frequencyDelta) {
|
2010-08-20 05:35:02 +00:00
|
|
|
checkAddToDictionary(suggestion, frequencyDelta, false);
|
|
|
|
}
|
|
|
|
|
2011-03-04 07:56:10 +00:00
|
|
|
private void addToOnlyBigramDictionary(CharSequence suggestion, int frequencyDelta) {
|
2010-08-20 05:35:02 +00:00
|
|
|
checkAddToDictionary(suggestion, frequencyDelta, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-07-14 22:57:26 +00:00
|
|
|
* Adds to the UserBigramDictionary and/or UserUnigramDictionary
|
2011-03-04 07:56:10 +00:00
|
|
|
* @param selectedANotTypedWord true if it should be added to bigram dictionary if possible
|
2010-08-20 05:35:02 +00:00
|
|
|
*/
|
|
|
|
private void checkAddToDictionary(CharSequence suggestion, int frequencyDelta,
|
2011-03-04 07:56:10 +00:00
|
|
|
boolean selectedANotTypedWord) {
|
2010-08-20 05:35:02 +00:00
|
|
|
if (suggestion == null || suggestion.length() < 1) return;
|
2011-03-04 07:56:10 +00:00
|
|
|
|
2010-03-24 23:44:31 +00:00
|
|
|
// Only auto-add to dictionary if auto-correct is ON. Otherwise we'll be
|
|
|
|
// adding words in situations where the user or application really didn't
|
|
|
|
// want corrections enabled or learned.
|
2010-08-20 05:35:02 +00:00
|
|
|
if (!(mCorrectionMode == Suggest.CORRECTION_FULL
|
|
|
|
|| mCorrectionMode == Suggest.CORRECTION_FULL_BIGRAM)) {
|
|
|
|
return;
|
|
|
|
}
|
2011-03-04 07:56:10 +00:00
|
|
|
|
2011-09-09 09:08:53 +00:00
|
|
|
if (null != mSuggest && null != mUserUnigramDictionary) {
|
|
|
|
final boolean selectedATypedWordAndItsInUserUnigramDic =
|
|
|
|
!selectedANotTypedWord && mUserUnigramDictionary.isValidWord(suggestion);
|
|
|
|
final boolean isValidWord = AutoCorrection.isValidWord(
|
|
|
|
mSuggest.getUnigramDictionaries(), suggestion, true);
|
|
|
|
final boolean needsToAddToUserUnigramDictionary =
|
|
|
|
selectedATypedWordAndItsInUserUnigramDic || !isValidWord;
|
|
|
|
if (needsToAddToUserUnigramDictionary) {
|
|
|
|
mUserUnigramDictionary.addWord(suggestion.toString(), frequencyDelta);
|
|
|
|
}
|
2010-12-10 06:24:28 +00:00
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
|
2010-12-10 06:24:28 +00:00
|
|
|
if (mUserBigramDictionary != null) {
|
2011-05-09 07:54:07 +00:00
|
|
|
// We don't want to register as bigrams words separated by a separator.
|
|
|
|
// For example "I will, and you too" : we don't want the pair ("will" "and") to be
|
|
|
|
// a bigram.
|
2011-07-19 09:59:12 +00:00
|
|
|
final InputConnection ic = getCurrentInputConnection();
|
|
|
|
if (null != ic) {
|
|
|
|
final CharSequence prevWord =
|
|
|
|
EditingUtils.getPreviousWord(ic, mSettingsValues.mWordSeparators);
|
|
|
|
if (!TextUtils.isEmpty(prevWord)) {
|
|
|
|
mUserBigramDictionary.addBigrams(prevWord.toString(), suggestion.toString());
|
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|
2010-02-20 00:38:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-06 09:27:24 +00:00
|
|
|
public boolean isCursorTouchingWord() {
|
2011-07-31 02:28:15 +00:00
|
|
|
final InputConnection ic = getCurrentInputConnection();
|
2009-03-13 22:11:42 +00:00
|
|
|
if (ic == null) return false;
|
|
|
|
CharSequence toLeft = ic.getTextBeforeCursor(1, 0);
|
|
|
|
CharSequence toRight = ic.getTextAfterCursor(1, 0);
|
|
|
|
if (!TextUtils.isEmpty(toLeft)
|
2011-05-10 06:51:43 +00:00
|
|
|
&& !mSettingsValues.isWordSeparator(toLeft.charAt(0))
|
|
|
|
&& !mSettingsValues.isSuggestedPunctuation(toLeft.charAt(0))) {
|
2009-03-13 22:11:42 +00:00
|
|
|
return true;
|
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
if (!TextUtils.isEmpty(toRight)
|
2011-05-10 06:51:43 +00:00
|
|
|
&& !mSettingsValues.isWordSeparator(toRight.charAt(0))
|
|
|
|
&& !mSettingsValues.isSuggestedPunctuation(toRight.charAt(0))) {
|
2009-03-13 22:11:42 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2011-10-25 12:14:33 +00:00
|
|
|
// "ic" must not be null
|
2011-10-28 04:31:31 +00:00
|
|
|
private static boolean sameAsTextBeforeCursor(final InputConnection ic, CharSequence text) {
|
2010-04-01 13:28:52 +00:00
|
|
|
CharSequence beforeText = ic.getTextBeforeCursor(text.length(), 0);
|
|
|
|
return TextUtils.equals(text, beforeText);
|
|
|
|
}
|
|
|
|
|
2011-11-22 02:35:40 +00:00
|
|
|
// "ic" must not be null
|
|
|
|
/**
|
|
|
|
* Check if the cursor is actually at the end of a word. If so, restart suggestions on this
|
|
|
|
* word, else do nothing.
|
|
|
|
*/
|
|
|
|
private void restartSuggestionsOnWordBeforeCursorIfAtEndOfWord(
|
|
|
|
final InputConnection ic) {
|
|
|
|
// Bail out if the cursor is not at the end of a word (cursor must be preceded by
|
|
|
|
// non-whitespace, non-separator, non-start-of-text)
|
|
|
|
// Example ("|" is the cursor here) : <SOL>"|a" " |a" " | " all get rejected here.
|
|
|
|
final CharSequence textBeforeCursor = ic.getTextBeforeCursor(1, 0);
|
|
|
|
if (TextUtils.isEmpty(textBeforeCursor)
|
|
|
|
|| mSettingsValues.isWordSeparator(textBeforeCursor.charAt(0))) return;
|
|
|
|
|
|
|
|
// Bail out if the cursor is in the middle of a word (cursor must be followed by whitespace,
|
|
|
|
// separator or end of line/text)
|
|
|
|
// Example: "test|"<EOL> "te|st" get rejected here
|
|
|
|
final CharSequence textAfterCursor = ic.getTextAfterCursor(1, 0);
|
|
|
|
if (!TextUtils.isEmpty(textAfterCursor)
|
|
|
|
&& !mSettingsValues.isWordSeparator(textAfterCursor.charAt(0))) return;
|
|
|
|
|
|
|
|
// Bail out if word before cursor is 0-length or a single non letter (like an apostrophe)
|
2012-01-17 05:58:27 +00:00
|
|
|
// Example: " -|" gets rejected here but "e-|" and "e|" are okay
|
|
|
|
CharSequence word = EditingUtils.getWordAtCursor(ic, mSettingsValues.mWordSeparators);
|
|
|
|
// We don't suggest on leading single quotes, so we have to remove them from the word if
|
|
|
|
// it starts with single quotes.
|
|
|
|
while (!TextUtils.isEmpty(word) && Keyboard.CODE_SINGLE_QUOTE == word.charAt(0)) {
|
|
|
|
word = word.subSequence(1, word.length());
|
|
|
|
}
|
2011-11-22 02:35:40 +00:00
|
|
|
if (TextUtils.isEmpty(word)) return;
|
2012-01-17 05:58:27 +00:00
|
|
|
final char firstChar = word.charAt(0); // we just tested that word is not empty
|
|
|
|
if (word.length() == 1 && !Character.isLetter(firstChar)) return;
|
|
|
|
|
|
|
|
// We only suggest on words that start with a letter or a symbol that is excluded from
|
|
|
|
// word separators (see #handleCharacterWhileInBatchEdit).
|
|
|
|
if (!(isAlphabet(firstChar)
|
|
|
|
|| mSettingsValues.isSymbolExcludedFromWordSeparators(firstChar))) {
|
|
|
|
return;
|
|
|
|
}
|
2011-11-22 02:35:40 +00:00
|
|
|
|
|
|
|
// Okay, we are at the end of a word. Restart suggestions.
|
|
|
|
restartSuggestionsOnWordBeforeCursor(ic, word);
|
|
|
|
}
|
|
|
|
|
|
|
|
// "ic" must not be null
|
|
|
|
private void restartSuggestionsOnWordBeforeCursor(final InputConnection ic,
|
|
|
|
final CharSequence word) {
|
2011-12-17 23:36:16 +00:00
|
|
|
mWordComposer.setComposingWord(word, mKeyboardSwitcher.getKeyboard());
|
2011-11-22 02:35:40 +00:00
|
|
|
mComposingStateManager.onStartComposingText();
|
|
|
|
ic.deleteSurroundingText(word.length(), 0);
|
|
|
|
ic.setComposingText(word, 1);
|
|
|
|
mHandler.postUpdateSuggestions();
|
|
|
|
}
|
|
|
|
|
2011-10-25 12:14:33 +00:00
|
|
|
// "ic" must not be null
|
2011-12-12 06:09:17 +00:00
|
|
|
private void cancelAutoCorrect(final InputConnection ic) {
|
2012-01-26 08:16:40 +00:00
|
|
|
final String originallyTypedWord = mLastComposedWord.mTypedWord;
|
|
|
|
final CharSequence autoCorrectedTo = mLastComposedWord.mAutoCorrection;
|
2011-12-14 11:13:16 +00:00
|
|
|
final int cancelLength = autoCorrectedTo.length();
|
2011-12-12 06:09:17 +00:00
|
|
|
final CharSequence separator = ic.getTextBeforeCursor(1, 0);
|
|
|
|
if (DEBUG) {
|
2012-01-26 08:16:40 +00:00
|
|
|
if (mWordComposer.isComposingWord()) {
|
|
|
|
throw new RuntimeException("cancelAutoCorrect, but we are composing a word");
|
|
|
|
}
|
2011-12-12 06:09:17 +00:00
|
|
|
final String wordBeforeCursor =
|
|
|
|
ic.getTextBeforeCursor(cancelLength + 1, 0).subSequence(0, cancelLength)
|
|
|
|
.toString();
|
2012-01-20 08:55:03 +00:00
|
|
|
if (!TextUtils.equals(autoCorrectedTo, wordBeforeCursor)) {
|
2011-12-12 06:09:17 +00:00
|
|
|
throw new RuntimeException("cancelAutoCorrect check failed: we thought we were "
|
2011-12-14 11:13:16 +00:00
|
|
|
+ "reverting \"" + autoCorrectedTo
|
2011-12-12 06:09:17 +00:00
|
|
|
+ "\", but before the cursor we found \"" + wordBeforeCursor + "\"");
|
|
|
|
}
|
2012-01-20 08:55:03 +00:00
|
|
|
if (TextUtils.equals(originallyTypedWord, wordBeforeCursor)) {
|
2011-12-12 06:09:17 +00:00
|
|
|
throw new RuntimeException("cancelAutoCorrect check failed: we wanted to cancel "
|
2011-12-14 11:13:16 +00:00
|
|
|
+ "auto correction and revert to \"" + originallyTypedWord
|
2011-12-12 06:09:17 +00:00
|
|
|
+ "\" but we found this very string before the cursor");
|
|
|
|
}
|
2011-07-12 07:47:08 +00:00
|
|
|
}
|
2011-12-12 06:09:17 +00:00
|
|
|
ic.deleteSurroundingText(cancelLength + 1, 0);
|
2011-12-14 11:13:16 +00:00
|
|
|
ic.commitText(originallyTypedWord, 1);
|
2011-12-13 14:12:22 +00:00
|
|
|
// Re-insert the separator
|
2011-12-12 06:09:17 +00:00
|
|
|
ic.commitText(separator, 1);
|
2012-01-26 08:16:40 +00:00
|
|
|
mLastComposedWord = LastComposedWord.NOT_A_COMPOSED_WORD;
|
2011-12-12 07:22:07 +00:00
|
|
|
Utils.Stats.onSeparator(separator.charAt(0), WordComposer.NOT_A_COORDINATE,
|
|
|
|
WordComposer.NOT_A_COORDINATE);
|
2011-12-12 06:09:17 +00:00
|
|
|
mHandler.cancelUpdateBigramPredictions();
|
|
|
|
mHandler.postUpdateSuggestions();
|
|
|
|
}
|
|
|
|
|
|
|
|
// "ic" must not be null
|
|
|
|
private void restartSuggestionsOnManuallyPickedTypedWord(final InputConnection ic) {
|
2012-01-19 09:39:37 +00:00
|
|
|
// Note: this relies on the last word still being held in the WordComposer, in
|
|
|
|
// the field for suggestion resuming.
|
|
|
|
// Note: in the interest of code simplicity, we may want to just call
|
|
|
|
// restartSuggestionsOnWordBeforeCursorIfAtEndOfWord instead, but retrieving
|
|
|
|
// the old WordComposer allows to reuse the actual typed coordinates.
|
2012-01-26 07:53:38 +00:00
|
|
|
mWordComposer.resumeSuggestionOnLastComposedWord(mLastComposedWord);
|
2012-01-19 09:39:37 +00:00
|
|
|
// We resume suggestion, and then we want to set the composing text to the content
|
|
|
|
// of the word composer again. But since we just manually picked a word, there is
|
|
|
|
// no composing text at the moment, so we have to delete the word before we set a
|
|
|
|
// new composing text.
|
2011-12-12 06:52:51 +00:00
|
|
|
final int restartLength = mWordComposer.size();
|
2011-12-12 06:09:17 +00:00
|
|
|
if (DEBUG) {
|
|
|
|
final String wordBeforeCursor =
|
|
|
|
ic.getTextBeforeCursor(restartLength + 1, 0).subSequence(0, restartLength)
|
|
|
|
.toString();
|
2012-01-20 08:55:03 +00:00
|
|
|
if (!TextUtils.equals(mWordComposer.getTypedWord(), wordBeforeCursor)) {
|
2011-12-12 06:09:17 +00:00
|
|
|
throw new RuntimeException("restartSuggestionsOnManuallyPickedTypedWord "
|
|
|
|
+ "check failed: we thought we were reverting \""
|
|
|
|
+ mWordComposer.getTypedWord()
|
|
|
|
+ "\", but before the cursor we found \""
|
|
|
|
+ wordBeforeCursor + "\"");
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2012-01-19 09:39:37 +00:00
|
|
|
// Warning: this +1 takes into account the extra space added by the manual pick process.
|
2011-12-12 06:09:17 +00:00
|
|
|
ic.deleteSurroundingText(restartLength + 1, 0);
|
|
|
|
ic.setComposingText(mWordComposer.getTypedWord(), 1);
|
2011-07-12 07:47:08 +00:00
|
|
|
mHandler.cancelUpdateBigramPredictions();
|
|
|
|
mHandler.postUpdateSuggestions();
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2011-10-25 12:14:33 +00:00
|
|
|
// "ic" must not be null
|
2011-07-31 02:28:15 +00:00
|
|
|
private boolean revertDoubleSpace(final InputConnection ic) {
|
2011-06-08 07:47:19 +00:00
|
|
|
mHandler.cancelDoubleSpacesTimer();
|
|
|
|
// Here we test whether we indeed have a period and a space before us. This should not
|
|
|
|
// be needed, but it's there just in case something went wrong.
|
|
|
|
final CharSequence textBeforeCursor = ic.getTextBeforeCursor(2, 0);
|
2011-12-13 08:40:06 +00:00
|
|
|
if (!". ".equals(textBeforeCursor)) {
|
|
|
|
// We should not have come here if we aren't just after a ". ".
|
|
|
|
throw new RuntimeException("Tried to revert double-space combo but we didn't find "
|
|
|
|
+ "\". \" just before the cursor.");
|
|
|
|
}
|
2011-06-08 07:47:19 +00:00
|
|
|
ic.beginBatchEdit();
|
|
|
|
ic.deleteSurroundingText(2, 0);
|
|
|
|
ic.commitText(" ", 1);
|
|
|
|
ic.endBatchEdit();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-10-28 04:31:31 +00:00
|
|
|
private static boolean revertSwapPunctuation(final InputConnection ic) {
|
2011-10-25 12:14:33 +00:00
|
|
|
// Here we test whether we indeed have a space and something else before us. This should not
|
|
|
|
// be needed, but it's there just in case something went wrong.
|
|
|
|
final CharSequence textBeforeCursor = ic.getTextBeforeCursor(2, 0);
|
|
|
|
// NOTE: This does not work with surrogate pairs. Hopefully when the keyboard is able to
|
|
|
|
// enter surrogate pairs this code will have been removed.
|
2012-01-26 04:15:25 +00:00
|
|
|
if (TextUtils.isEmpty(textBeforeCursor)
|
|
|
|
|| (Keyboard.CODE_SPACE != textBeforeCursor.charAt(1))) {
|
|
|
|
// We may only come here if the application is changing the text while we are typing.
|
|
|
|
// This is quite a broken case, but not logically impossible, so we shouldn't crash,
|
|
|
|
// but some debugging log may be in order.
|
|
|
|
Log.d(TAG, "Tried to revert a swap of punctuation but we didn't "
|
2011-12-13 08:40:06 +00:00
|
|
|
+ "find a space just before the cursor.");
|
2012-01-26 04:15:25 +00:00
|
|
|
return false;
|
2011-12-13 08:40:06 +00:00
|
|
|
}
|
2011-10-25 12:14:33 +00:00
|
|
|
ic.beginBatchEdit();
|
|
|
|
ic.deleteSurroundingText(2, 0);
|
|
|
|
ic.commitText(" " + textBeforeCursor.subSequence(0, 1), 1);
|
|
|
|
ic.endBatchEdit();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
public boolean isWordSeparator(int code) {
|
2011-05-10 06:51:43 +00:00
|
|
|
return mSettingsValues.isWordSeparator(code);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2011-04-28 06:39:39 +00:00
|
|
|
private void sendMagicSpace() {
|
2010-12-02 11:54:32 +00:00
|
|
|
sendKeyChar((char)Keyboard.CODE_SPACE);
|
2011-10-25 12:14:33 +00:00
|
|
|
mSpaceState = SPACE_STATE_MAGIC;
|
2010-11-13 08:16:34 +00:00
|
|
|
mKeyboardSwitcher.updateShiftState();
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean preferCapitalization() {
|
2011-07-12 01:29:29 +00:00
|
|
|
return mWordComposer.isFirstCharCapitalized();
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2011-04-08 10:57:13 +00:00
|
|
|
// Notify that language or mode have been changed and toggleLanguage will update KeyboardID
|
2011-01-18 06:28:21 +00:00
|
|
|
// according to new language or mode.
|
|
|
|
public void onRefreshKeyboard() {
|
2011-06-27 14:30:37 +00:00
|
|
|
if (!CAN_HANDLE_ON_CURRENT_INPUT_METHOD_SUBTYPE_CHANGED) {
|
|
|
|
// Before Honeycomb, Voice IME is in LatinIME and it changes the current input view,
|
|
|
|
// so that we need to re-create the keyboard input view here.
|
|
|
|
setInputView(mKeyboardSwitcher.onCreateInputView());
|
|
|
|
}
|
2011-11-04 03:36:38 +00:00
|
|
|
// When the device locale is changed in SetupWizard etc., this method may get called via
|
|
|
|
// onConfigurationChanged before SoftInputWindow is shown.
|
|
|
|
if (mKeyboardSwitcher.getKeyboardView() != null) {
|
|
|
|
// Reload keyboard because the current language has been changed.
|
|
|
|
mKeyboardSwitcher.loadKeyboard(getCurrentInputEditorInfo(), mSettingsValues);
|
|
|
|
}
|
2010-11-17 07:35:35 +00:00
|
|
|
initSuggest();
|
2011-05-10 06:51:43 +00:00
|
|
|
loadSettings();
|
2009-10-12 20:48:35 +00:00
|
|
|
}
|
|
|
|
|
2011-10-26 11:49:57 +00:00
|
|
|
private void hapticAndAudioFeedback(int primaryCode) {
|
|
|
|
vibrate();
|
|
|
|
playKeyClick(primaryCode);
|
|
|
|
}
|
|
|
|
|
2010-12-02 09:46:21 +00:00
|
|
|
@Override
|
2012-01-17 08:08:26 +00:00
|
|
|
public void onPressKey(int primaryCode) {
|
2011-07-29 17:45:37 +00:00
|
|
|
final KeyboardSwitcher switcher = mKeyboardSwitcher;
|
|
|
|
if (switcher.isVibrateAndSoundFeedbackRequired()) {
|
2011-10-26 11:49:57 +00:00
|
|
|
hapticAndAudioFeedback(primaryCode);
|
2010-12-20 07:21:54 +00:00
|
|
|
}
|
2012-01-17 08:08:26 +00:00
|
|
|
switcher.onPressKey(primaryCode);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2010-12-02 09:46:21 +00:00
|
|
|
@Override
|
2012-01-17 08:08:26 +00:00
|
|
|
public void onReleaseKey(int primaryCode, boolean withSliding) {
|
|
|
|
mKeyboardSwitcher.onReleaseKey(primaryCode, withSliding);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
|
|
|
|
2011-01-26 14:13:18 +00:00
|
|
|
// receive ringer mode change and network state change.
|
2009-03-13 22:11:42 +00:00
|
|
|
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
2011-01-26 14:13:18 +00:00
|
|
|
final String action = intent.getAction();
|
|
|
|
if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) {
|
|
|
|
updateRingerMode();
|
|
|
|
} else if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
|
|
|
|
mSubtypeSwitcher.onNetworkStateChanged(intent);
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// update flags for silent mode
|
|
|
|
private void updateRingerMode() {
|
|
|
|
if (mAudioManager == null) {
|
|
|
|
mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
|
2011-08-11 15:58:07 +00:00
|
|
|
if (mAudioManager == null) return;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2011-08-11 15:58:07 +00:00
|
|
|
mSilentModeOn = (mAudioManager.getRingerMode() != AudioManager.RINGER_MODE_NORMAL);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void playKeyClick(int primaryCode) {
|
|
|
|
// if mAudioManager is null, we don't have the ringer state yet
|
|
|
|
// mAudioManager will be set by updateRingerMode
|
|
|
|
if (mAudioManager == null) {
|
2011-05-23 09:30:21 +00:00
|
|
|
if (mKeyboardSwitcher.getKeyboardView() != null) {
|
2009-03-13 22:11:42 +00:00
|
|
|
updateRingerMode();
|
|
|
|
}
|
|
|
|
}
|
2011-05-10 06:51:43 +00:00
|
|
|
if (isSoundOn()) {
|
2011-09-20 10:52:21 +00:00
|
|
|
final int sound;
|
2009-03-13 22:11:42 +00:00
|
|
|
switch (primaryCode) {
|
2011-09-20 10:52:21 +00:00
|
|
|
case Keyboard.CODE_DELETE:
|
|
|
|
sound = AudioManager.FX_KEYPRESS_DELETE;
|
|
|
|
break;
|
|
|
|
case Keyboard.CODE_ENTER:
|
|
|
|
sound = AudioManager.FX_KEYPRESS_RETURN;
|
|
|
|
break;
|
|
|
|
case Keyboard.CODE_SPACE:
|
|
|
|
sound = AudioManager.FX_KEYPRESS_SPACEBAR;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sound = AudioManager.FX_KEYPRESS_STANDARD;
|
|
|
|
break;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2011-12-08 13:21:26 +00:00
|
|
|
mAudioManager.playSoundEffect(sound, mSettingsValues.mFxVolume);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-21 01:36:37 +00:00
|
|
|
public void vibrate() {
|
2011-05-10 06:51:43 +00:00
|
|
|
if (!mSettingsValues.mVibrateOn) {
|
2009-03-13 22:11:42 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-12-08 13:21:26 +00:00
|
|
|
if (mSettingsValues.mKeypressVibrationDuration < 0) {
|
2011-09-19 05:51:31 +00:00
|
|
|
// Go ahead with the system default
|
|
|
|
LatinKeyboardView inputView = mKeyboardSwitcher.getKeyboardView();
|
|
|
|
if (inputView != null) {
|
|
|
|
inputView.performHapticFeedback(
|
|
|
|
HapticFeedbackConstants.KEYBOARD_TAP,
|
|
|
|
HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
|
|
|
|
}
|
|
|
|
} else if (mVibrator != null) {
|
2011-12-08 13:21:26 +00:00
|
|
|
mVibrator.vibrate(mSettingsValues.mKeypressVibrationDuration);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-13 14:08:12 +00:00
|
|
|
public boolean isAutoCapitalized() {
|
|
|
|
return mWordComposer.isAutoCapitalized();
|
2010-02-24 03:01:43 +00:00
|
|
|
}
|
|
|
|
|
2011-05-10 06:51:43 +00:00
|
|
|
boolean isSoundOn() {
|
|
|
|
return mSettingsValues.mSoundOn && !mSilentModeOn;
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|
|
|
|
|
2009-12-18 21:39:18 +00:00
|
|
|
private void updateCorrectionMode() {
|
2011-03-02 06:40:08 +00:00
|
|
|
// TODO: cleanup messy flags
|
2011-07-25 13:44:52 +00:00
|
|
|
final boolean shouldAutoCorrect = mSettingsValues.mAutoCorrectEnabled
|
2011-12-16 03:57:27 +00:00
|
|
|
&& !mInputAttributes.mInputTypeNoAutoCorrect;
|
2011-12-08 12:37:15 +00:00
|
|
|
mCorrectionMode = shouldAutoCorrect ? Suggest.CORRECTION_FULL : Suggest.CORRECTION_NONE;
|
|
|
|
mCorrectionMode = (mSettingsValues.mBigramSuggestionEnabled && shouldAutoCorrect)
|
2010-08-20 05:35:02 +00:00
|
|
|
? Suggest.CORRECTION_FULL_BIGRAM : mCorrectionMode;
|
2009-12-18 21:39:18 +00:00
|
|
|
}
|
|
|
|
|
2011-12-15 10:32:11 +00:00
|
|
|
private void updateSuggestionVisibility(final Resources res) {
|
2011-12-09 11:16:57 +00:00
|
|
|
final String suggestionVisiblityStr = mSettingsValues.mShowSuggestionsSetting;
|
2010-11-13 10:09:30 +00:00
|
|
|
for (int visibility : SUGGESTION_VISIBILITY_VALUE_ARRAY) {
|
2011-01-04 15:39:41 +00:00
|
|
|
if (suggestionVisiblityStr.equals(res.getString(visibility))) {
|
2010-11-13 10:09:30 +00:00
|
|
|
mSuggestionVisibility = visibility;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
protected void launchSettings() {
|
2011-08-06 01:45:19 +00:00
|
|
|
launchSettingsClass(Settings.class);
|
2010-01-16 20:21:23 +00:00
|
|
|
}
|
|
|
|
|
2010-09-27 03:55:21 +00:00
|
|
|
public void launchDebugSettings() {
|
2011-08-06 01:45:19 +00:00
|
|
|
launchSettingsClass(DebugSettings.class);
|
2010-09-27 03:55:21 +00:00
|
|
|
}
|
|
|
|
|
2011-08-06 01:45:19 +00:00
|
|
|
protected void launchSettingsClass(Class<? extends PreferenceActivity> settingsClass) {
|
2009-03-13 22:11:42 +00:00
|
|
|
handleClose();
|
|
|
|
Intent intent = new Intent();
|
2010-01-16 20:21:23 +00:00
|
|
|
intent.setClass(LatinIME.this, settingsClass);
|
2009-03-13 22:11:42 +00:00
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
startActivity(intent);
|
|
|
|
}
|
|
|
|
|
2011-01-20 13:52:02 +00:00
|
|
|
private void showSubtypeSelectorAndSettings() {
|
2011-01-25 02:48:06 +00:00
|
|
|
final CharSequence title = getString(R.string.english_ime_input_options);
|
|
|
|
final CharSequence[] items = new CharSequence[] {
|
|
|
|
// TODO: Should use new string "Select active input modes".
|
|
|
|
getString(R.string.language_selection_title),
|
|
|
|
getString(R.string.english_ime_settings),
|
|
|
|
};
|
|
|
|
final DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
|
2011-01-20 13:52:02 +00:00
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface di, int position) {
|
|
|
|
di.dismiss();
|
|
|
|
switch (position) {
|
2011-01-25 02:48:06 +00:00
|
|
|
case 0:
|
2011-03-17 02:37:51 +00:00
|
|
|
Intent intent = CompatUtils.getInputLanguageSelectionIntent(
|
2011-12-12 10:55:42 +00:00
|
|
|
Utils.getInputMethodId(mImm, getPackageName()),
|
|
|
|
Intent.FLAG_ACTIVITY_NEW_TASK
|
2011-01-20 13:52:02 +00:00
|
|
|
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
|
|
|
|
| Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
|
|
startActivity(intent);
|
|
|
|
break;
|
2011-01-25 17:56:09 +00:00
|
|
|
case 1:
|
|
|
|
launchSettings();
|
|
|
|
break;
|
2011-01-20 13:52:02 +00:00
|
|
|
}
|
|
|
|
}
|
2011-01-25 02:48:06 +00:00
|
|
|
};
|
2011-07-18 04:18:47 +00:00
|
|
|
final AlertDialog.Builder builder = new AlertDialog.Builder(this)
|
|
|
|
.setItems(items, listener)
|
|
|
|
.setTitle(title);
|
|
|
|
showOptionDialogInternal(builder.create());
|
2011-01-20 13:52:02 +00:00
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
|
2011-01-20 13:52:02 +00:00
|
|
|
private void showOptionsMenu() {
|
2011-01-25 02:48:06 +00:00
|
|
|
final CharSequence title = getString(R.string.english_ime_input_options);
|
|
|
|
final CharSequence[] items = new CharSequence[] {
|
|
|
|
getString(R.string.selectInputMethod),
|
|
|
|
getString(R.string.english_ime_settings),
|
|
|
|
};
|
|
|
|
final DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
|
2010-12-02 09:46:21 +00:00
|
|
|
@Override
|
2009-03-13 22:11:42 +00:00
|
|
|
public void onClick(DialogInterface di, int position) {
|
|
|
|
di.dismiss();
|
|
|
|
switch (position) {
|
2011-01-25 02:48:06 +00:00
|
|
|
case 0:
|
2011-02-03 06:56:01 +00:00
|
|
|
mImm.showInputMethodPicker();
|
2011-01-20 13:52:02 +00:00
|
|
|
break;
|
2011-01-25 02:48:06 +00:00
|
|
|
case 1:
|
2011-02-03 06:56:01 +00:00
|
|
|
launchSettings();
|
2011-01-20 13:52:02 +00:00
|
|
|
break;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
}
|
2011-01-25 02:48:06 +00:00
|
|
|
};
|
2011-07-18 04:18:47 +00:00
|
|
|
final AlertDialog.Builder builder = new AlertDialog.Builder(this)
|
|
|
|
.setItems(items, listener)
|
|
|
|
.setTitle(title);
|
|
|
|
showOptionDialogInternal(builder.create());
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2010-10-08 13:17:16 +00:00
|
|
|
@Override
|
|
|
|
protected void dump(FileDescriptor fd, PrintWriter fout, String[] args) {
|
2009-03-13 22:11:42 +00:00
|
|
|
super.dump(fd, fout, args);
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
final Printer p = new PrintWriterPrinter(fout);
|
|
|
|
p.println("LatinIME state :");
|
2011-12-17 23:36:16 +00:00
|
|
|
final Keyboard keyboard = mKeyboardSwitcher.getKeyboard();
|
2011-12-09 10:53:36 +00:00
|
|
|
final int keyboardMode = keyboard != null ? keyboard.mId.mMode : -1;
|
|
|
|
p.println(" Keyboard mode = " + keyboardMode);
|
2011-12-16 03:57:27 +00:00
|
|
|
p.println(" mIsSuggestionsRequested=" + mInputAttributes.mIsSettingsSuggestionStripOn);
|
2009-03-13 22:11:42 +00:00
|
|
|
p.println(" mCorrectionMode=" + mCorrectionMode);
|
2011-12-14 10:01:17 +00:00
|
|
|
p.println(" isComposingWord=" + mWordComposer.isComposingWord());
|
2011-05-10 06:51:43 +00:00
|
|
|
p.println(" mAutoCorrectEnabled=" + mSettingsValues.mAutoCorrectEnabled);
|
|
|
|
p.println(" mSoundOn=" + mSettingsValues.mSoundOn);
|
|
|
|
p.println(" mVibrateOn=" + mSettingsValues.mVibrateOn);
|
2011-05-11 11:51:07 +00:00
|
|
|
p.println(" mKeyPreviewPopupOn=" + mSettingsValues.mKeyPreviewPopupOn);
|
2011-12-16 05:28:50 +00:00
|
|
|
p.println(" mInputAttributes=" + mInputAttributes.toString());
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
}
|