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-12-02 11:54:32 +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-12-02 11:54:32 +00:00
|
|
|
*
|
2009-03-13 22:11:42 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2010-12-02 11:54:32 +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.
|
|
|
|
*/
|
|
|
|
|
2010-12-02 11:54:32 +00:00
|
|
|
package com.android.inputmethod.keyboard;
|
2009-03-13 22:11:42 +00:00
|
|
|
|
2011-05-23 09:30:21 +00:00
|
|
|
import android.content.Context;
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.content.res.Resources;
|
|
|
|
import android.util.Log;
|
2011-05-24 12:08:20 +00:00
|
|
|
import android.view.ContextThemeWrapper;
|
2011-05-23 09:30:21 +00:00
|
|
|
import android.view.InflateException;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.inputmethod.EditorInfo;
|
|
|
|
|
2011-05-18 00:03:25 +00:00
|
|
|
import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy;
|
2012-04-04 05:30:42 +00:00
|
|
|
import com.android.inputmethod.keyboard.KeyboardLayoutSet.KeyboardLayoutSetException;
|
2012-01-31 06:54:48 +00:00
|
|
|
import com.android.inputmethod.keyboard.PointerTracker.TimerProxy;
|
2011-12-05 06:02:06 +00:00
|
|
|
import com.android.inputmethod.keyboard.internal.KeyboardState;
|
2012-01-16 08:18:40 +00:00
|
|
|
import com.android.inputmethod.latin.DebugSettings;
|
2012-05-24 09:20:26 +00:00
|
|
|
import com.android.inputmethod.latin.ImfUtils;
|
2011-09-20 07:16:34 +00:00
|
|
|
import com.android.inputmethod.latin.InputView;
|
2010-12-02 11:54:32 +00:00
|
|
|
import com.android.inputmethod.latin.LatinIME;
|
|
|
|
import com.android.inputmethod.latin.LatinImeLogger;
|
|
|
|
import com.android.inputmethod.latin.R;
|
2011-12-08 13:10:40 +00:00
|
|
|
import com.android.inputmethod.latin.SettingsValues;
|
2010-12-02 11:54:32 +00:00
|
|
|
import com.android.inputmethod.latin.SubtypeSwitcher;
|
2011-01-25 03:13:35 +00:00
|
|
|
import com.android.inputmethod.latin.Utils;
|
2010-12-02 09:46:21 +00:00
|
|
|
|
2012-03-08 06:07:00 +00:00
|
|
|
public class KeyboardSwitcher implements KeyboardState.SwitchActions {
|
2011-05-28 14:47:21 +00:00
|
|
|
private static final String TAG = KeyboardSwitcher.class.getSimpleName();
|
2009-03-13 22:11:42 +00:00
|
|
|
|
2011-09-16 11:18:46 +00:00
|
|
|
public static final String PREF_KEYBOARD_LAYOUT = "pref_keyboard_layout_20110916";
|
2012-03-08 07:20:22 +00:00
|
|
|
|
|
|
|
static class KeyboardTheme {
|
|
|
|
public final String mName;
|
|
|
|
public final int mThemeId;
|
|
|
|
public final int mStyleId;
|
|
|
|
|
|
|
|
public KeyboardTheme(String name, int themeId, int styleId) {
|
|
|
|
mName = name;
|
|
|
|
mThemeId = themeId;
|
|
|
|
mStyleId = styleId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static final KeyboardTheme[] KEYBOARD_THEMES = {
|
|
|
|
new KeyboardTheme("Basic", 0, R.style.KeyboardTheme),
|
|
|
|
new KeyboardTheme("HighContrast", 1, R.style.KeyboardTheme_HighContrast),
|
|
|
|
new KeyboardTheme("Stone", 6, R.style.KeyboardTheme_Stone),
|
|
|
|
new KeyboardTheme("Stne.Bold", 7, R.style.KeyboardTheme_Stone_Bold),
|
|
|
|
new KeyboardTheme("GingerBread", 8, R.style.KeyboardTheme_Gingerbread),
|
|
|
|
new KeyboardTheme("IceCreamSandwich", 5, R.style.KeyboardTheme_IceCreamSandwich),
|
2010-11-19 08:31:20 +00:00
|
|
|
};
|
2010-08-20 05:35:02 +00:00
|
|
|
|
2010-11-17 07:35:35 +00:00
|
|
|
private SubtypeSwitcher mSubtypeSwitcher;
|
2010-11-26 04:08:36 +00:00
|
|
|
private SharedPreferences mPrefs;
|
2012-01-16 08:18:40 +00:00
|
|
|
private boolean mForceNonDistinctMultitouch;
|
2010-11-17 07:35:35 +00:00
|
|
|
|
2011-09-20 07:16:34 +00:00
|
|
|
private InputView mCurrentInputView;
|
2011-08-23 08:57:02 +00:00
|
|
|
private LatinKeyboardView mKeyboardView;
|
2012-05-17 03:55:01 +00:00
|
|
|
private LatinIME mLatinIME;
|
2011-07-29 23:57:07 +00:00
|
|
|
private Resources mResources;
|
2010-09-01 06:45:20 +00:00
|
|
|
|
2011-12-05 06:02:06 +00:00
|
|
|
private KeyboardState mState;
|
2010-11-16 09:47:39 +00:00
|
|
|
|
2012-04-04 05:30:42 +00:00
|
|
|
private KeyboardLayoutSet mKeyboardLayoutSet;
|
2009-04-16 19:56:10 +00:00
|
|
|
|
2010-12-11 08:06:24 +00:00
|
|
|
/** mIsAutoCorrectionActive indicates that auto corrected word will be input instead of
|
2010-09-02 13:54:37 +00:00
|
|
|
* what user actually typed. */
|
2010-12-11 08:06:24 +00:00
|
|
|
private boolean mIsAutoCorrectionActive;
|
2010-12-17 07:56:15 +00:00
|
|
|
|
2012-03-08 07:20:22 +00:00
|
|
|
private KeyboardTheme mKeyboardTheme = KEYBOARD_THEMES[0];
|
2011-06-20 02:58:56 +00:00
|
|
|
private Context mThemeContext;
|
2010-08-20 05:35:02 +00:00
|
|
|
|
2010-11-17 07:35:35 +00:00
|
|
|
private static final KeyboardSwitcher sInstance = new KeyboardSwitcher();
|
|
|
|
|
|
|
|
public static KeyboardSwitcher getInstance() {
|
|
|
|
return sInstance;
|
|
|
|
}
|
|
|
|
|
|
|
|
private KeyboardSwitcher() {
|
2010-12-10 06:24:28 +00:00
|
|
|
// Intentional empty constructor for singleton.
|
2010-11-17 07:35:35 +00:00
|
|
|
}
|
|
|
|
|
2012-05-17 03:55:01 +00:00
|
|
|
public static void init(LatinIME latinIme, SharedPreferences prefs) {
|
|
|
|
sInstance.initInternal(latinIme, prefs);
|
2011-07-30 00:20:01 +00:00
|
|
|
}
|
|
|
|
|
2012-05-17 03:55:01 +00:00
|
|
|
private void initInternal(LatinIME latinIme, SharedPreferences prefs) {
|
|
|
|
mLatinIME = latinIme;
|
|
|
|
mResources = latinIme.getResources();
|
2011-07-30 00:20:01 +00:00
|
|
|
mPrefs = prefs;
|
|
|
|
mSubtypeSwitcher = SubtypeSwitcher.getInstance();
|
2011-12-07 10:31:11 +00:00
|
|
|
mState = new KeyboardState(this);
|
2012-05-17 03:55:01 +00:00
|
|
|
setContextThemeWrapper(latinIme, getKeyboardTheme(latinIme, prefs));
|
2012-01-16 08:18:40 +00:00
|
|
|
mForceNonDistinctMultitouch = prefs.getBoolean(
|
|
|
|
DebugSettings.FORCE_NON_DISTINCT_MULTITOUCH_KEY, false);
|
2011-06-20 02:58:56 +00:00
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
|
2012-03-08 07:20:22 +00:00
|
|
|
private static KeyboardTheme getKeyboardTheme(Context context, SharedPreferences prefs) {
|
|
|
|
final String defaultIndex = context.getString(R.string.config_default_keyboard_theme_index);
|
|
|
|
final String themeIndex = prefs.getString(PREF_KEYBOARD_LAYOUT, defaultIndex);
|
2010-12-28 11:49:58 +00:00
|
|
|
try {
|
2012-03-08 07:20:22 +00:00
|
|
|
final int index = Integer.valueOf(themeIndex);
|
|
|
|
if (index >= 0 && index < KEYBOARD_THEMES.length) {
|
|
|
|
return KEYBOARD_THEMES[index];
|
|
|
|
}
|
2010-12-28 11:49:58 +00:00
|
|
|
} catch (NumberFormatException e) {
|
2011-06-20 02:58:56 +00:00
|
|
|
// Format error, keyboard theme is default to 0.
|
|
|
|
}
|
2012-03-08 07:20:22 +00:00
|
|
|
Log.w(TAG, "Illegal keyboard theme in preference: " + themeIndex + ", default to 0");
|
|
|
|
return KEYBOARD_THEMES[0];
|
2011-06-20 02:58:56 +00:00
|
|
|
}
|
|
|
|
|
2012-03-08 07:20:22 +00:00
|
|
|
private void setContextThemeWrapper(Context context, KeyboardTheme keyboardTheme) {
|
|
|
|
if (mKeyboardTheme.mThemeId != keyboardTheme.mThemeId) {
|
|
|
|
mKeyboardTheme = keyboardTheme;
|
|
|
|
mThemeContext = new ContextThemeWrapper(context, keyboardTheme.mStyleId);
|
2012-04-04 05:30:42 +00:00
|
|
|
KeyboardLayoutSet.clearKeyboardCache();
|
2010-12-28 11:49:58 +00:00
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|
|
|
|
|
2011-12-08 13:10:40 +00:00
|
|
|
public void loadKeyboard(EditorInfo editorInfo, SettingsValues settingsValues) {
|
2012-04-04 05:30:42 +00:00
|
|
|
final KeyboardLayoutSet.Builder builder = new KeyboardLayoutSet.Builder(
|
|
|
|
mThemeContext, editorInfo);
|
2012-01-13 07:14:02 +00:00
|
|
|
builder.setScreenGeometry(mThemeContext.getResources().getConfiguration().orientation,
|
|
|
|
mThemeContext.getResources().getDisplayMetrics().widthPixels);
|
2012-04-04 09:18:56 +00:00
|
|
|
builder.setSubtype(mSubtypeSwitcher.getCurrentSubtype());
|
2012-01-13 07:14:02 +00:00
|
|
|
builder.setOptions(
|
|
|
|
settingsValues.isVoiceKeyEnabled(editorInfo),
|
2012-02-18 01:46:01 +00:00
|
|
|
settingsValues.isVoiceKeyOnMain(),
|
|
|
|
settingsValues.isLanguageSwitchKeyEnabled(mThemeContext));
|
2012-04-04 05:30:42 +00:00
|
|
|
mKeyboardLayoutSet = builder.build();
|
2010-08-20 05:35:02 +00:00
|
|
|
try {
|
2012-01-18 09:01:53 +00:00
|
|
|
mState.onLoadKeyboard(mResources.getString(R.string.layout_switch_back_symbols));
|
2012-04-04 05:30:42 +00:00
|
|
|
} catch (KeyboardLayoutSetException e) {
|
2012-01-31 08:15:24 +00:00
|
|
|
Log.w(TAG, "loading keyboard failed: " + e.mKeyboardId, e.getCause());
|
|
|
|
LatinImeLogger.logOnException(e.mKeyboardId.toString(), e.getCause());
|
2011-12-15 05:45:14 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-04-16 19:56:10 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 08:27:48 +00:00
|
|
|
public void saveKeyboardState() {
|
2012-01-26 09:03:30 +00:00
|
|
|
if (getKeyboard() != null) {
|
2011-12-09 07:09:16 +00:00
|
|
|
mState.onSaveKeyboardState();
|
2011-12-07 03:53:51 +00:00
|
|
|
}
|
2011-07-29 17:45:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void onFinishInputView() {
|
|
|
|
mIsAutoCorrectionActive = false;
|
|
|
|
}
|
|
|
|
|
2011-07-27 22:32:25 +00:00
|
|
|
public void onHideWindow() {
|
|
|
|
mIsAutoCorrectionActive = false;
|
|
|
|
}
|
|
|
|
|
2011-07-29 17:45:37 +00:00
|
|
|
private void setKeyboard(final Keyboard keyboard) {
|
2011-05-23 09:30:21 +00:00
|
|
|
final Keyboard oldKeyboard = mKeyboardView.getKeyboard();
|
2011-07-29 17:45:37 +00:00
|
|
|
mKeyboardView.setKeyboard(keyboard);
|
2011-09-20 07:16:34 +00:00
|
|
|
mCurrentInputView.setKeyboardGeometry(keyboard.mTopPadding);
|
2011-05-23 09:30:21 +00:00
|
|
|
mKeyboardView.setKeyPreviewPopupEnabled(
|
2011-12-08 13:10:40 +00:00
|
|
|
SettingsValues.isKeyPreviewPopupEnabled(mPrefs, mResources),
|
|
|
|
SettingsValues.getKeyPreviewPopupDismissDelay(mPrefs, mResources));
|
2011-12-17 23:13:36 +00:00
|
|
|
mKeyboardView.updateAutoCorrectionState(mIsAutoCorrectionActive);
|
2011-12-17 19:55:17 +00:00
|
|
|
mKeyboardView.updateShortcutKey(mSubtypeSwitcher.isShortcutImeReady());
|
2012-03-13 05:15:39 +00:00
|
|
|
final boolean subtypeChanged = (oldKeyboard == null)
|
|
|
|
|| !keyboard.mId.mLocale.equals(oldKeyboard.mId.mLocale);
|
2012-03-13 03:44:03 +00:00
|
|
|
final boolean needsToDisplayLanguage = mSubtypeSwitcher.needsToDisplayLanguage(
|
|
|
|
keyboard.mId.mLocale);
|
2012-05-24 09:20:26 +00:00
|
|
|
mKeyboardView.startDisplayLanguageOnSpacebar(subtypeChanged, needsToDisplayLanguage,
|
|
|
|
ImfUtils.hasMultipleEnabledIMEsOrSubtypes(mLatinIME, true));
|
2009-04-16 19:56:10 +00:00
|
|
|
}
|
|
|
|
|
2011-12-17 23:36:16 +00:00
|
|
|
public Keyboard getKeyboard() {
|
2011-05-23 09:30:21 +00:00
|
|
|
if (mKeyboardView != null) {
|
2011-12-17 23:36:16 +00:00
|
|
|
return mKeyboardView.getKeyboard();
|
2011-02-20 12:12:51 +00:00
|
|
|
}
|
2010-11-13 08:16:34 +00:00
|
|
|
return null;
|
2010-11-13 08:01:13 +00:00
|
|
|
}
|
|
|
|
|
2012-01-24 03:06:49 +00:00
|
|
|
/**
|
|
|
|
* Update keyboard shift state triggered by connected EditText status change.
|
|
|
|
*/
|
|
|
|
public void updateShiftState() {
|
2012-05-17 03:55:01 +00:00
|
|
|
mState.onUpdateShiftState(mLatinIME.getCurrentAutoCapsState());
|
2012-01-24 03:06:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void onPressKey(int code) {
|
2012-02-01 06:07:25 +00:00
|
|
|
if (isVibrateAndSoundFeedbackRequired()) {
|
2012-05-17 03:55:01 +00:00
|
|
|
mLatinIME.hapticAndAudioFeedback(code);
|
2012-02-01 06:07:25 +00:00
|
|
|
}
|
2012-05-17 03:55:01 +00:00
|
|
|
mState.onPressKey(code, isSinglePointer(), mLatinIME.getCurrentAutoCapsState());
|
2012-01-24 03:06:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void onReleaseKey(int code, boolean withSliding) {
|
|
|
|
mState.onReleaseKey(code, withSliding);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onCancelInput() {
|
|
|
|
mState.onCancelInput(isSinglePointer());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Implements {@link KeyboardState.SwitchActions}.
|
|
|
|
@Override
|
|
|
|
public void setAlphabetKeyboard() {
|
2012-04-04 05:30:42 +00:00
|
|
|
setKeyboard(mKeyboardLayoutSet.getKeyboard(KeyboardId.ELEMENT_ALPHABET));
|
2010-11-13 08:16:34 +00:00
|
|
|
}
|
|
|
|
|
2012-01-24 03:06:49 +00:00
|
|
|
// Implements {@link KeyboardState.SwitchActions}.
|
|
|
|
@Override
|
|
|
|
public void setAlphabetManualShiftedKeyboard() {
|
2012-04-04 05:30:42 +00:00
|
|
|
setKeyboard(mKeyboardLayoutSet.getKeyboard(KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED));
|
2010-11-16 08:28:50 +00:00
|
|
|
}
|
|
|
|
|
2012-01-24 03:06:49 +00:00
|
|
|
// Implements {@link KeyboardState.SwitchActions}.
|
|
|
|
@Override
|
|
|
|
public void setAlphabetAutomaticShiftedKeyboard() {
|
2012-04-04 05:30:42 +00:00
|
|
|
setKeyboard(mKeyboardLayoutSet.getKeyboard(KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED));
|
2010-12-30 08:19:55 +00:00
|
|
|
}
|
|
|
|
|
2011-12-07 10:31:11 +00:00
|
|
|
// Implements {@link KeyboardState.SwitchActions}.
|
|
|
|
@Override
|
2012-01-24 03:06:49 +00:00
|
|
|
public void setAlphabetShiftLockedKeyboard() {
|
2012-04-04 05:30:42 +00:00
|
|
|
setKeyboard(mKeyboardLayoutSet.getKeyboard(KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCKED));
|
2011-12-06 08:43:01 +00:00
|
|
|
}
|
|
|
|
|
2012-01-26 09:25:48 +00:00
|
|
|
// Implements {@link KeyboardState.SwitchActions}.
|
|
|
|
@Override
|
|
|
|
public void setAlphabetShiftLockShiftedKeyboard() {
|
2012-04-04 05:30:42 +00:00
|
|
|
setKeyboard(mKeyboardLayoutSet.getKeyboard(KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED));
|
2012-01-26 09:25:48 +00:00
|
|
|
}
|
|
|
|
|
2011-12-07 10:31:11 +00:00
|
|
|
// Implements {@link KeyboardState.SwitchActions}.
|
|
|
|
@Override
|
2012-01-24 03:06:49 +00:00
|
|
|
public void setSymbolsKeyboard() {
|
2012-04-04 05:30:42 +00:00
|
|
|
setKeyboard(mKeyboardLayoutSet.getKeyboard(KeyboardId.ELEMENT_SYMBOLS));
|
2011-12-05 07:35:32 +00:00
|
|
|
}
|
|
|
|
|
2011-12-07 10:31:11 +00:00
|
|
|
// Implements {@link KeyboardState.SwitchActions}.
|
|
|
|
@Override
|
|
|
|
public void setSymbolsShiftedKeyboard() {
|
2012-04-04 05:30:42 +00:00
|
|
|
setKeyboard(mKeyboardLayoutSet.getKeyboard(KeyboardId.ELEMENT_SYMBOLS_SHIFTED));
|
2011-12-06 08:43:01 +00:00
|
|
|
}
|
|
|
|
|
2012-01-13 11:15:14 +00:00
|
|
|
// Implements {@link KeyboardState.SwitchActions}.
|
|
|
|
@Override
|
|
|
|
public void requestUpdatingShiftState() {
|
2012-05-17 03:55:01 +00:00
|
|
|
mState.onUpdateShiftState(mLatinIME.getCurrentAutoCapsState());
|
2012-01-13 11:15:14 +00:00
|
|
|
}
|
|
|
|
|
2012-01-31 06:54:48 +00:00
|
|
|
// Implements {@link KeyboardState.SwitchActions}.
|
|
|
|
@Override
|
|
|
|
public void startDoubleTapTimer() {
|
|
|
|
final LatinKeyboardView keyboardView = getKeyboardView();
|
|
|
|
if (keyboardView != null) {
|
|
|
|
final TimerProxy timer = keyboardView.getTimerProxy();
|
|
|
|
timer.startDoubleTapTimer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-16 19:45:35 +00:00
|
|
|
// Implements {@link KeyboardState.SwitchActions}.
|
|
|
|
@Override
|
|
|
|
public void cancelDoubleTapTimer() {
|
|
|
|
final LatinKeyboardView keyboardView = getKeyboardView();
|
|
|
|
if (keyboardView != null) {
|
|
|
|
final TimerProxy timer = keyboardView.getTimerProxy();
|
|
|
|
timer.cancelDoubleTapTimer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-31 06:54:48 +00:00
|
|
|
// Implements {@link KeyboardState.SwitchActions}.
|
|
|
|
@Override
|
|
|
|
public boolean isInDoubleTapTimeout() {
|
|
|
|
final LatinKeyboardView keyboardView = getKeyboardView();
|
|
|
|
return (keyboardView != null)
|
|
|
|
? keyboardView.getTimerProxy().isInDoubleTapTimeout() : false;
|
|
|
|
}
|
|
|
|
|
2012-02-01 06:07:25 +00:00
|
|
|
// Implements {@link KeyboardState.SwitchActions}.
|
|
|
|
@Override
|
|
|
|
public void startLongPressTimer(int code) {
|
|
|
|
final LatinKeyboardView keyboardView = getKeyboardView();
|
|
|
|
if (keyboardView != null) {
|
|
|
|
final TimerProxy timer = keyboardView.getTimerProxy();
|
|
|
|
timer.startLongPressTimer(code);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-16 19:45:35 +00:00
|
|
|
// Implements {@link KeyboardState.SwitchActions}.
|
|
|
|
@Override
|
|
|
|
public void cancelLongPressTimer() {
|
|
|
|
final LatinKeyboardView keyboardView = getKeyboardView();
|
|
|
|
if (keyboardView != null) {
|
|
|
|
final TimerProxy timer = keyboardView.getTimerProxy();
|
|
|
|
timer.cancelLongPressTimer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-01 06:07:25 +00:00
|
|
|
// Implements {@link KeyboardState.SwitchActions}.
|
|
|
|
@Override
|
|
|
|
public void hapticAndAudioFeedback(int code) {
|
2012-05-17 03:55:01 +00:00
|
|
|
mLatinIME.hapticAndAudioFeedback(code);
|
2012-02-01 06:07:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void onLongPressTimeout(int code) {
|
|
|
|
mState.onLongPressTimeout(code);
|
|
|
|
}
|
|
|
|
|
2011-04-26 05:27:35 +00:00
|
|
|
public boolean isInMomentarySwitchState() {
|
2011-12-07 10:31:11 +00:00
|
|
|
return mState.isInMomentarySwitchState();
|
2010-12-17 07:56:15 +00:00
|
|
|
}
|
|
|
|
|
2012-02-01 06:07:25 +00:00
|
|
|
private boolean isVibrateAndSoundFeedbackRequired() {
|
2011-10-07 02:46:06 +00:00
|
|
|
return mKeyboardView != null && !mKeyboardView.isInSlidingKeyInput();
|
2010-12-20 07:21:54 +00:00
|
|
|
}
|
|
|
|
|
2011-12-05 07:35:32 +00:00
|
|
|
private boolean isSinglePointer() {
|
|
|
|
return mKeyboardView != null && mKeyboardView.getPointerCount() == 1;
|
2009-07-21 22:47:11 +00:00
|
|
|
}
|
|
|
|
|
2010-09-06 05:26:46 +00:00
|
|
|
public boolean hasDistinctMultitouch() {
|
2011-05-23 09:30:21 +00:00
|
|
|
return mKeyboardView != null && mKeyboardView.hasDistinctMultitouch();
|
2010-09-06 05:26:46 +00:00
|
|
|
}
|
|
|
|
|
2009-07-21 22:47:11 +00:00
|
|
|
/**
|
2012-01-18 07:40:28 +00:00
|
|
|
* Updates state machine to figure out when to automatically switch back to the previous mode.
|
2009-07-21 22:47:11 +00:00
|
|
|
*/
|
2011-12-07 10:31:11 +00:00
|
|
|
public void onCodeInput(int code) {
|
2012-05-17 03:55:01 +00:00
|
|
|
mState.onCodeInput(code, isSinglePointer(), mLatinIME.getCurrentAutoCapsState());
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
|
2011-08-23 08:57:02 +00:00
|
|
|
public LatinKeyboardView getKeyboardView() {
|
2011-05-23 09:30:21 +00:00
|
|
|
return mKeyboardView;
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|
|
|
|
|
2011-05-23 09:30:21 +00:00
|
|
|
public View onCreateInputView() {
|
2011-05-24 12:37:33 +00:00
|
|
|
if (mKeyboardView != null) {
|
|
|
|
mKeyboardView.closing();
|
|
|
|
}
|
|
|
|
|
|
|
|
Utils.GCUtils.getInstance().reset();
|
|
|
|
boolean tryGC = true;
|
|
|
|
for (int i = 0; i < Utils.GCUtils.GC_TRY_LOOP_MAX && tryGC; ++i) {
|
|
|
|
try {
|
2012-05-17 03:55:01 +00:00
|
|
|
setContextThemeWrapper(mLatinIME, mKeyboardTheme);
|
2011-09-20 07:16:34 +00:00
|
|
|
mCurrentInputView = (InputView)LayoutInflater.from(mThemeContext).inflate(
|
2011-05-24 12:08:20 +00:00
|
|
|
R.layout.input_view, null);
|
2011-05-24 12:37:33 +00:00
|
|
|
tryGC = false;
|
|
|
|
} catch (OutOfMemoryError e) {
|
|
|
|
Log.w(TAG, "load keyboard failed: " + e);
|
2012-03-08 07:20:22 +00:00
|
|
|
tryGC = Utils.GCUtils.getInstance().tryGCOrWait(mKeyboardTheme.mName, e);
|
2011-05-24 12:37:33 +00:00
|
|
|
} catch (InflateException e) {
|
|
|
|
Log.w(TAG, "load keyboard failed: " + e);
|
2012-03-08 07:20:22 +00:00
|
|
|
tryGC = Utils.GCUtils.getInstance().tryGCOrWait(mKeyboardTheme.mName, e);
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|
|
|
|
}
|
2011-05-24 12:37:33 +00:00
|
|
|
|
2011-08-23 08:57:02 +00:00
|
|
|
mKeyboardView = (LatinKeyboardView) mCurrentInputView.findViewById(R.id.keyboard_view);
|
2012-05-17 03:55:01 +00:00
|
|
|
mKeyboardView.setKeyboardActionListener(mLatinIME);
|
2012-01-16 08:18:40 +00:00
|
|
|
if (mForceNonDistinctMultitouch) {
|
|
|
|
mKeyboardView.setDistinctMultitouch(false);
|
|
|
|
}
|
2011-05-18 00:03:25 +00:00
|
|
|
|
|
|
|
// This always needs to be set since the accessibility state can
|
|
|
|
// potentially change without the input view being re-created.
|
2012-02-28 18:01:40 +00:00
|
|
|
AccessibleKeyboardViewProxy.getInstance().setView(mKeyboardView);
|
2011-05-18 00:03:25 +00:00
|
|
|
|
2011-05-24 12:37:33 +00:00
|
|
|
return mCurrentInputView;
|
2010-11-25 01:02:50 +00:00
|
|
|
}
|
|
|
|
|
2011-12-15 07:09:42 +00:00
|
|
|
public void onNetworkStateChanged() {
|
2011-12-17 19:55:17 +00:00
|
|
|
if (mKeyboardView != null) {
|
2012-04-04 09:18:56 +00:00
|
|
|
mKeyboardView.updateShortcutKey(mSubtypeSwitcher.isShortcutImeReady());
|
2011-12-15 07:09:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-11 08:06:24 +00:00
|
|
|
public void onAutoCorrectionStateChanged(boolean isAutoCorrection) {
|
2011-06-18 04:33:48 +00:00
|
|
|
if (mIsAutoCorrectionActive != isAutoCorrection) {
|
2010-12-11 08:06:24 +00:00
|
|
|
mIsAutoCorrectionActive = isAutoCorrection;
|
2011-12-17 23:13:36 +00:00
|
|
|
if (mKeyboardView != null) {
|
|
|
|
mKeyboardView.updateAutoCorrectionState(isAutoCorrection);
|
2011-06-18 04:33:48 +00:00
|
|
|
}
|
2010-09-02 13:54:37 +00:00
|
|
|
}
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|