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
|
|
|
*
|
2013-01-21 12:52:57 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2010-12-02 11:54:32 +00:00
|
|
|
*
|
2013-01-21 12:52:57 +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
|
2013-01-21 12:52:57 +00:00
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2009-03-13 22:11:42 +00:00
|
|
|
*/
|
|
|
|
|
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;
|
2013-01-07 09:40:59 +00:00
|
|
|
import android.preference.PreferenceManager;
|
2011-05-23 09:30:21 +00:00
|
|
|
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.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.inputmethod.EditorInfo;
|
|
|
|
|
2011-05-18 00:03:25 +00:00
|
|
|
import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy;
|
2013-11-11 11:39:03 +00:00
|
|
|
import com.android.inputmethod.compat.InputMethodServiceCompatUtils;
|
2012-04-04 05:30:42 +00:00
|
|
|
import com.android.inputmethod.keyboard.KeyboardLayoutSet.KeyboardLayoutSetException;
|
2011-12-05 06:02:06 +00:00
|
|
|
import com.android.inputmethod.keyboard.internal.KeyboardState;
|
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;
|
2012-11-09 09:21:41 +00:00
|
|
|
import com.android.inputmethod.latin.RichInputMethodManager;
|
2010-12-02 11:54:32 +00:00
|
|
|
import com.android.inputmethod.latin.SubtypeSwitcher;
|
2012-08-21 10:49:25 +00:00
|
|
|
import com.android.inputmethod.latin.WordComposer;
|
2013-07-22 03:43:37 +00:00
|
|
|
import com.android.inputmethod.latin.settings.Settings;
|
|
|
|
import com.android.inputmethod.latin.settings.SettingsValues;
|
2013-08-07 07:26:10 +00:00
|
|
|
import com.android.inputmethod.latin.utils.ResourceUtils;
|
2010-12-02 09:46:21 +00:00
|
|
|
|
2012-09-27 09:16:16 +00:00
|
|
|
public final 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
|
|
|
|
2012-09-27 09:16:16 +00:00
|
|
|
static final class KeyboardTheme {
|
2012-03-08 07:20:22 +00:00
|
|
|
public final int mThemeId;
|
|
|
|
public final int mStyleId;
|
|
|
|
|
2012-08-22 03:32:47 +00:00
|
|
|
// Note: The themeId should be aligned with "themeId" attribute of Keyboard style
|
|
|
|
// in values/style.xml.
|
2013-01-07 09:40:59 +00:00
|
|
|
public KeyboardTheme(final int themeId, final int styleId) {
|
2012-03-08 07:20:22 +00:00
|
|
|
mThemeId = themeId;
|
|
|
|
mStyleId = styleId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-22 03:32:52 +00:00
|
|
|
public static final int THEME_INDEX_ICS = 0;
|
|
|
|
public static final int THEME_INDEX_GB = 1;
|
|
|
|
public static final int THEME_INDEX_KLP = 2;
|
|
|
|
public static final int THEME_INDEX_DEFAULT = THEME_INDEX_KLP;
|
|
|
|
public static final KeyboardTheme[] KEYBOARD_THEMES = {
|
|
|
|
new KeyboardTheme(THEME_INDEX_ICS, R.style.KeyboardTheme_ICS),
|
|
|
|
new KeyboardTheme(THEME_INDEX_GB, R.style.KeyboardTheme_GB),
|
|
|
|
new KeyboardTheme(THEME_INDEX_KLP, R.style.KeyboardTheme_KLP),
|
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;
|
2010-11-17 07:35:35 +00:00
|
|
|
|
2011-09-20 07:16:34 +00:00
|
|
|
private InputView mCurrentInputView;
|
2013-08-30 10:28:01 +00:00
|
|
|
private View mMainKeyboardFrame;
|
2012-07-23 01:27:14 +00:00
|
|
|
private MainKeyboardView mKeyboardView;
|
2013-10-07 02:28:57 +00:00
|
|
|
private EmojiPalettesView mEmojiPalettesView;
|
2012-05-17 03:55:01 +00:00
|
|
|
private LatinIME mLatinIME;
|
2011-07-29 23:57:07 +00:00
|
|
|
private Resources mResources;
|
2013-11-11 11:39:03 +00:00
|
|
|
private boolean mIsHardwareAcceleratedDrawingEnabled;
|
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
|
|
|
|
2013-11-22 03:32:52 +00:00
|
|
|
private KeyboardTheme mKeyboardTheme = KEYBOARD_THEMES[THEME_INDEX_DEFAULT];
|
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
|
|
|
}
|
|
|
|
|
2013-01-07 09:40:59 +00:00
|
|
|
public static void init(final LatinIME latinIme) {
|
|
|
|
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(latinIme);
|
2012-05-17 03:55:01 +00:00
|
|
|
sInstance.initInternal(latinIme, prefs);
|
2011-07-30 00:20:01 +00:00
|
|
|
}
|
|
|
|
|
2013-01-07 09:40:59 +00:00
|
|
|
private void initInternal(final LatinIME latinIme, final SharedPreferences prefs) {
|
2012-05-17 03:55:01 +00:00
|
|
|
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);
|
2013-11-11 11:39:03 +00:00
|
|
|
mIsHardwareAcceleratedDrawingEnabled =
|
|
|
|
InputMethodServiceCompatUtils.enableHardwareAcceleration(mLatinIME);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void updateKeyboardTheme() {
|
|
|
|
final boolean themeUpdated = updateKeyboardThemeAndContextThemeWrapper(
|
|
|
|
mLatinIME, getKeyboardTheme(mLatinIME, mPrefs));
|
|
|
|
if (themeUpdated && mKeyboardView != null) {
|
|
|
|
mLatinIME.setInputView(onCreateInputView(mIsHardwareAcceleratedDrawingEnabled));
|
|
|
|
}
|
2011-06-20 02:58:56 +00:00
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
|
2013-01-07 09:40:59 +00:00
|
|
|
private static KeyboardTheme getKeyboardTheme(final Context context,
|
|
|
|
final SharedPreferences prefs) {
|
2013-11-22 03:32:52 +00:00
|
|
|
final Resources res = context.getResources();
|
|
|
|
final int index = Settings.readKeyboardThemeIndex(prefs, res);
|
|
|
|
if (index >= 0 && index < KEYBOARD_THEMES.length) {
|
|
|
|
return KEYBOARD_THEMES[index];
|
2011-06-20 02:58:56 +00:00
|
|
|
}
|
2013-11-22 03:32:52 +00:00
|
|
|
final int defaultThemeIndex = Settings.resetAndGetDefaultKeyboardThemeIndex(prefs, res);
|
|
|
|
Log.w(TAG, "Illegal keyboard theme in preference: " + index + ", default to "
|
|
|
|
+ defaultThemeIndex);
|
|
|
|
return KEYBOARD_THEMES[defaultThemeIndex];
|
2011-06-20 02:58:56 +00:00
|
|
|
}
|
|
|
|
|
2013-11-11 11:39:03 +00:00
|
|
|
private boolean updateKeyboardThemeAndContextThemeWrapper(final Context context,
|
|
|
|
final KeyboardTheme keyboardTheme) {
|
2012-11-22 02:41:53 +00:00
|
|
|
if (mThemeContext == null || mKeyboardTheme.mThemeId != keyboardTheme.mThemeId) {
|
2012-03-08 07:20:22 +00:00
|
|
|
mKeyboardTheme = keyboardTheme;
|
|
|
|
mThemeContext = new ContextThemeWrapper(context, keyboardTheme.mStyleId);
|
2012-04-04 05:30:42 +00:00
|
|
|
KeyboardLayoutSet.clearKeyboardCache();
|
2013-11-11 11:39:03 +00:00
|
|
|
return true;
|
2010-12-28 11:49:58 +00:00
|
|
|
}
|
2013-11-11 11:39:03 +00:00
|
|
|
return false;
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|
|
|
|
|
2013-01-07 09:40:59 +00:00
|
|
|
public void loadKeyboard(final EditorInfo editorInfo, final SettingsValues settingsValues) {
|
2012-04-04 05:30:42 +00:00
|
|
|
final KeyboardLayoutSet.Builder builder = new KeyboardLayoutSet.Builder(
|
|
|
|
mThemeContext, editorInfo);
|
2012-07-30 04:35:06 +00:00
|
|
|
final Resources res = mThemeContext.getResources();
|
2013-08-07 07:26:10 +00:00
|
|
|
final int keyboardWidth = ResourceUtils.getDefaultKeyboardWidth(res);
|
|
|
|
final int keyboardHeight = ResourceUtils.getDefaultKeyboardHeight(res);
|
|
|
|
builder.setKeyboardGeometry(keyboardWidth, keyboardHeight);
|
2012-04-04 09:18:56 +00:00
|
|
|
builder.setSubtype(mSubtypeSwitcher.getCurrentSubtype());
|
2012-01-13 07:14:02 +00:00
|
|
|
builder.setOptions(
|
2013-12-13 08:09:16 +00:00
|
|
|
mSubtypeSwitcher.isShortcutImeEnabled(),
|
|
|
|
settingsValues.mShowsVoiceInputKey,
|
2012-11-09 09:21:41 +00:00
|
|
|
settingsValues.isLanguageSwitchKeyEnabled());
|
2012-04-04 05:30:42 +00:00
|
|
|
mKeyboardLayoutSet = builder.build();
|
2010-08-20 05:35:02 +00:00
|
|
|
try {
|
2013-01-18 09:04:24 +00:00
|
|
|
mState.onLoadKeyboard();
|
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() {
|
2013-10-11 10:15:16 +00:00
|
|
|
if (getKeyboard() != null || isShowingEmojiPalettes()) {
|
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) {
|
2013-10-07 02:28:57 +00:00
|
|
|
// Make {@link MainKeyboardView} visible and hide {@link EmojiPalettesView}.
|
2013-08-30 10:28:01 +00:00
|
|
|
setMainKeyboardFrame();
|
2012-07-23 05:59:19 +00:00
|
|
|
final MainKeyboardView keyboardView = mKeyboardView;
|
|
|
|
final Keyboard oldKeyboard = keyboardView.getKeyboard();
|
|
|
|
keyboardView.setKeyboard(keyboard);
|
2013-12-16 08:05:07 +00:00
|
|
|
mCurrentInputView.setKeyboardTopPadding(keyboard.mTopPadding);
|
2012-07-23 05:59:19 +00:00
|
|
|
keyboardView.setKeyPreviewPopupEnabled(
|
2013-01-08 09:20:31 +00:00
|
|
|
Settings.readKeyPreviewPopupEnabled(mPrefs, mResources),
|
|
|
|
Settings.readKeyPreviewPopupDismissDelay(mPrefs, mResources));
|
2012-07-23 05:59:19 +00:00
|
|
|
keyboardView.updateAutoCorrectionState(mIsAutoCorrectionActive);
|
|
|
|
keyboardView.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-07-23 05:59:19 +00:00
|
|
|
keyboardView.startDisplayLanguageOnSpacebar(subtypeChanged, needsToDisplayLanguage,
|
2012-11-09 09:21:41 +00:00
|
|
|
RichInputMethodManager.getInstance().hasMultipleEnabledIMEsOrSubtypes(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() {
|
2013-04-15 13:00:29 +00:00
|
|
|
mState.onUpdateShiftState(mLatinIME.getCurrentAutoCapsState(),
|
|
|
|
mLatinIME.getCurrentRecapitalizeState());
|
2012-01-24 03:06:49 +00:00
|
|
|
}
|
|
|
|
|
2012-11-06 07:45:44 +00:00
|
|
|
// TODO: Remove this method. Come up with a more comprehensive way to reset the keyboard layout
|
|
|
|
// when a keyboard layout set doesn't get reloaded in LatinIME.onStartInputViewInternal().
|
|
|
|
public void resetKeyboardStateToAlphabet() {
|
|
|
|
mState.onResetKeyboardStateToAlphabet();
|
|
|
|
}
|
|
|
|
|
2013-05-14 03:25:21 +00:00
|
|
|
public void onPressKey(final int code, final boolean isSinglePointer) {
|
|
|
|
mState.onPressKey(code, isSinglePointer, mLatinIME.getCurrentAutoCapsState());
|
2012-01-24 03:06:49 +00:00
|
|
|
}
|
|
|
|
|
2013-01-07 09:40:59 +00:00
|
|
|
public void onReleaseKey(final int code, final boolean withSliding) {
|
2012-01-24 03:06:49 +00:00
|
|
|
mState.onReleaseKey(code, withSliding);
|
|
|
|
}
|
|
|
|
|
2013-05-14 03:25:21 +00:00
|
|
|
public void onFinishSlidingInput() {
|
|
|
|
mState.onFinishSlidingInput();
|
2012-01-24 03:06:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
2013-08-30 10:28:01 +00:00
|
|
|
private void setMainKeyboardFrame() {
|
|
|
|
mMainKeyboardFrame.setVisibility(View.VISIBLE);
|
2013-10-07 02:28:57 +00:00
|
|
|
mEmojiPalettesView.setVisibility(View.GONE);
|
2013-10-08 11:11:35 +00:00
|
|
|
mEmojiPalettesView.stopEmojiPalettes();
|
2013-08-30 10:28:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Implements {@link KeyboardState.SwitchActions}.
|
|
|
|
@Override
|
|
|
|
public void setEmojiKeyboard() {
|
|
|
|
mMainKeyboardFrame.setVisibility(View.GONE);
|
2013-10-08 11:11:35 +00:00
|
|
|
mEmojiPalettesView.startEmojiPalettes();
|
2013-10-07 02:28:57 +00:00
|
|
|
mEmojiPalettesView.setVisibility(View.VISIBLE);
|
2013-08-30 10:28:01 +00:00
|
|
|
}
|
|
|
|
|
2013-09-04 03:57:04 +00:00
|
|
|
// Implements {@link KeyboardState.SwitchActions}.
|
|
|
|
@Override
|
|
|
|
public void setSymbolsShiftedKeyboard() {
|
|
|
|
setKeyboard(mKeyboardLayoutSet.getKeyboard(KeyboardId.ELEMENT_SYMBOLS_SHIFTED));
|
|
|
|
}
|
|
|
|
|
2012-01-13 11:15:14 +00:00
|
|
|
// Implements {@link KeyboardState.SwitchActions}.
|
|
|
|
@Override
|
|
|
|
public void requestUpdatingShiftState() {
|
2013-04-15 13:00:29 +00:00
|
|
|
mState.onUpdateShiftState(mLatinIME.getCurrentAutoCapsState(),
|
|
|
|
mLatinIME.getCurrentRecapitalizeState());
|
2012-01-13 11:15:14 +00:00
|
|
|
}
|
|
|
|
|
2012-01-31 06:54:48 +00:00
|
|
|
// Implements {@link KeyboardState.SwitchActions}.
|
|
|
|
@Override
|
2013-06-03 08:50:48 +00:00
|
|
|
public void startDoubleTapShiftKeyTimer() {
|
2012-08-07 02:48:10 +00:00
|
|
|
final MainKeyboardView keyboardView = getMainKeyboardView();
|
2012-01-31 06:54:48 +00:00
|
|
|
if (keyboardView != null) {
|
2013-08-01 07:22:53 +00:00
|
|
|
keyboardView.startDoubleTapShiftKeyTimer();
|
2012-01-31 06:54:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-16 19:45:35 +00:00
|
|
|
// Implements {@link KeyboardState.SwitchActions}.
|
|
|
|
@Override
|
2013-06-03 08:50:48 +00:00
|
|
|
public void cancelDoubleTapShiftKeyTimer() {
|
2012-08-07 02:48:10 +00:00
|
|
|
final MainKeyboardView keyboardView = getMainKeyboardView();
|
2012-02-16 19:45:35 +00:00
|
|
|
if (keyboardView != null) {
|
2013-08-01 07:22:53 +00:00
|
|
|
keyboardView.cancelDoubleTapShiftKeyTimer();
|
2012-02-16 19:45:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-31 06:54:48 +00:00
|
|
|
// Implements {@link KeyboardState.SwitchActions}.
|
|
|
|
@Override
|
2013-06-03 08:50:48 +00:00
|
|
|
public boolean isInDoubleTapShiftKeyTimeout() {
|
2012-08-07 02:48:10 +00:00
|
|
|
final MainKeyboardView keyboardView = getMainKeyboardView();
|
2013-08-01 07:22:53 +00:00
|
|
|
return keyboardView != null && keyboardView.isInDoubleTapShiftKeyTimeout();
|
2012-01-31 06:54:48 +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
|
|
|
*/
|
2013-01-07 09:40:59 +00:00
|
|
|
public void onCodeInput(final int code) {
|
2013-05-14 03:25:21 +00:00
|
|
|
mState.onCodeInput(code, mLatinIME.getCurrentAutoCapsState());
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
|
2013-10-11 10:15:16 +00:00
|
|
|
private boolean isShowingMainKeyboard() {
|
|
|
|
return null != mKeyboardView && mKeyboardView.isShown();
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isShowingEmojiPalettes() {
|
|
|
|
return mEmojiPalettesView != null && mEmojiPalettesView.isShown();
|
2013-09-05 03:19:43 +00:00
|
|
|
}
|
|
|
|
|
2013-08-29 11:43:03 +00:00
|
|
|
public boolean isShowingMoreKeysPanel() {
|
2013-10-11 10:15:16 +00:00
|
|
|
if (isShowingEmojiPalettes()) {
|
2013-08-29 11:43:03 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return mKeyboardView.isShowingMoreKeysPanel();
|
|
|
|
}
|
|
|
|
|
|
|
|
public View getVisibleKeyboardView() {
|
2013-10-11 10:15:16 +00:00
|
|
|
if (isShowingEmojiPalettes()) {
|
2013-10-07 02:28:57 +00:00
|
|
|
return mEmojiPalettesView;
|
2013-08-29 11:43:03 +00:00
|
|
|
}
|
|
|
|
return mKeyboardView;
|
|
|
|
}
|
|
|
|
|
2012-08-07 02:48:10 +00:00
|
|
|
public MainKeyboardView getMainKeyboardView() {
|
2011-05-23 09:30:21 +00:00
|
|
|
return mKeyboardView;
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|
|
|
|
|
2013-10-08 11:11:35 +00:00
|
|
|
public void deallocateMemory() {
|
|
|
|
if (mKeyboardView != null) {
|
|
|
|
mKeyboardView.cancelAllOngoingEvents();
|
|
|
|
mKeyboardView.deallocateMemory();
|
|
|
|
}
|
|
|
|
if (mEmojiPalettesView != null) {
|
|
|
|
mEmojiPalettesView.stopEmojiPalettes();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-11 10:15:16 +00:00
|
|
|
public boolean isShowingMainKeyboardOrEmojiPalettes() {
|
|
|
|
return isShowingMainKeyboard() || isShowingEmojiPalettes();
|
|
|
|
}
|
|
|
|
|
2013-01-07 09:40:59 +00:00
|
|
|
public View onCreateInputView(final boolean isHardwareAcceleratedDrawingEnabled) {
|
2011-05-24 12:37:33 +00:00
|
|
|
if (mKeyboardView != null) {
|
|
|
|
mKeyboardView.closing();
|
|
|
|
}
|
|
|
|
|
2013-11-11 11:39:03 +00:00
|
|
|
updateKeyboardThemeAndContextThemeWrapper(mLatinIME, mKeyboardTheme);
|
2012-08-22 03:32:47 +00:00
|
|
|
mCurrentInputView = (InputView)LayoutInflater.from(mThemeContext).inflate(
|
|
|
|
R.layout.input_view, null);
|
2013-08-30 10:28:01 +00:00
|
|
|
mMainKeyboardFrame = mCurrentInputView.findViewById(R.id.main_keyboard_frame);
|
2013-10-07 02:28:57 +00:00
|
|
|
mEmojiPalettesView = (EmojiPalettesView)mCurrentInputView.findViewById(
|
2013-08-30 10:28:01 +00:00
|
|
|
R.id.emoji_keyboard_view);
|
2011-05-24 12:37:33 +00:00
|
|
|
|
2012-07-23 01:27:14 +00:00
|
|
|
mKeyboardView = (MainKeyboardView) mCurrentInputView.findViewById(R.id.keyboard_view);
|
2013-08-01 15:25:05 +00:00
|
|
|
mKeyboardView.setHardwareAcceleratedDrawingEnabled(isHardwareAcceleratedDrawingEnabled);
|
2012-05-17 03:55:01 +00:00
|
|
|
mKeyboardView.setKeyboardActionListener(mLatinIME);
|
2013-10-07 02:28:57 +00:00
|
|
|
mEmojiPalettesView.setHardwareAcceleratedDrawingEnabled(
|
2013-08-30 10:28:01 +00:00
|
|
|
isHardwareAcceleratedDrawingEnabled);
|
2013-10-07 02:28:57 +00:00
|
|
|
mEmojiPalettesView.setKeyboardActionListener(mLatinIME);
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-07 09:40:59 +00:00
|
|
|
public void onAutoCorrectionStateChanged(final 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
|
|
|
}
|
|
|
|
}
|
2012-08-21 10:49:25 +00:00
|
|
|
|
2012-10-16 20:21:52 +00:00
|
|
|
public int getKeyboardShiftMode() {
|
2012-10-03 04:01:52 +00:00
|
|
|
final Keyboard keyboard = getKeyboard();
|
|
|
|
if (keyboard == null) {
|
|
|
|
return WordComposer.CAPS_MODE_OFF;
|
|
|
|
}
|
|
|
|
switch (keyboard.mId.mElementId) {
|
2012-08-21 10:49:25 +00:00
|
|
|
case KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCKED:
|
|
|
|
case KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED:
|
|
|
|
return WordComposer.CAPS_MODE_MANUAL_SHIFT_LOCKED;
|
|
|
|
case KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED:
|
|
|
|
return WordComposer.CAPS_MODE_MANUAL_SHIFTED;
|
2012-10-16 20:21:52 +00:00
|
|
|
case KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED:
|
|
|
|
return WordComposer.CAPS_MODE_AUTO_SHIFTED;
|
2012-08-21 10:49:25 +00:00
|
|
|
default:
|
|
|
|
return WordComposer.CAPS_MODE_OFF;
|
|
|
|
}
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|