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.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.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.inputmethod.EditorInfo;
|
|
|
|
|
2013-11-11 11:39:03 +00:00
|
|
|
import com.android.inputmethod.compat.InputMethodServiceCompatUtils;
|
2014-08-26 09:48:18 +00:00
|
|
|
import com.android.inputmethod.event.Event;
|
2012-04-04 05:30:42 +00:00
|
|
|
import com.android.inputmethod.keyboard.KeyboardLayoutSet.KeyboardLayoutSetException;
|
2014-05-14 10:32:00 +00:00
|
|
|
import com.android.inputmethod.keyboard.emoji.EmojiPalettesView;
|
2011-12-05 06:02:06 +00:00
|
|
|
import com.android.inputmethod.keyboard.internal.KeyboardState;
|
2014-02-24 08:24:49 +00:00
|
|
|
import com.android.inputmethod.keyboard.internal.KeyboardTextsSet;
|
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.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;
|
2014-09-03 10:36:35 +00:00
|
|
|
import com.android.inputmethod.latin.settings.Settings;
|
2013-07-22 03:43:37 +00:00
|
|
|
import com.android.inputmethod.latin.settings.SettingsValues;
|
2013-08-07 07:26:10 +00:00
|
|
|
import com.android.inputmethod.latin.utils.ResourceUtils;
|
2014-06-30 11:59:18 +00:00
|
|
|
import com.android.inputmethod.latin.utils.ScriptUtils;
|
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
|
|
|
|
2010-11-17 07:35:35 +00:00
|
|
|
private SubtypeSwitcher mSubtypeSwitcher;
|
|
|
|
|
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;
|
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;
|
2014-02-24 08:24:49 +00:00
|
|
|
// TODO: The following {@link KeyboardTextsSet} should be in {@link KeyboardLayoutSet}.
|
|
|
|
private final KeyboardTextsSet mKeyboardTextsSet = new KeyboardTextsSet();
|
2009-04-16 19:56:10 +00:00
|
|
|
|
2014-05-08 03:04:36 +00:00
|
|
|
private KeyboardTheme mKeyboardTheme;
|
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) {
|
2014-09-17 10:06:07 +00:00
|
|
|
sInstance.initInternal(latinIme);
|
2011-07-30 00:20:01 +00:00
|
|
|
}
|
|
|
|
|
2014-09-17 10:06:07 +00:00
|
|
|
private void initInternal(final LatinIME latinIme) {
|
2012-05-17 03:55:01 +00:00
|
|
|
mLatinIME = latinIme;
|
2011-07-30 00:20:01 +00:00
|
|
|
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(
|
2014-09-17 10:06:07 +00:00
|
|
|
mLatinIME, KeyboardTheme.getKeyboardTheme(mLatinIME /* context */));
|
2013-11-11 11:39:03 +00:00
|
|
|
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-11-11 11:39:03 +00:00
|
|
|
private boolean updateKeyboardThemeAndContextThemeWrapper(final Context context,
|
|
|
|
final KeyboardTheme keyboardTheme) {
|
2014-05-08 03:04:36 +00:00
|
|
|
if (mThemeContext == null || !keyboardTheme.equals(mKeyboardTheme)) {
|
2012-03-08 07:20:22 +00:00
|
|
|
mKeyboardTheme = keyboardTheme;
|
|
|
|
mThemeContext = new ContextThemeWrapper(context, keyboardTheme.mStyleId);
|
2014-08-28 09:17:51 +00:00
|
|
|
KeyboardLayoutSet.onKeyboardThemeChanged();
|
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
|
|
|
}
|
|
|
|
|
2014-04-14 08:04:50 +00:00
|
|
|
public void loadKeyboard(final EditorInfo editorInfo, final SettingsValues settingsValues,
|
|
|
|
final int currentAutoCapsState, final int currentRecapitalizeState) {
|
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());
|
2014-06-05 09:09:24 +00:00
|
|
|
builder.setVoiceInputKeyEnabled(settingsValues.mShowsVoiceInputKey);
|
2014-06-05 16:41:42 +00:00
|
|
|
builder.setLanguageSwitchKeyEnabled(mLatinIME.shouldShowLanguageSwitchKey());
|
2012-04-04 05:30:42 +00:00
|
|
|
mKeyboardLayoutSet = builder.build();
|
2010-08-20 05:35:02 +00:00
|
|
|
try {
|
2014-04-14 08:04:50 +00:00
|
|
|
mState.onLoadKeyboard(currentAutoCapsState, currentRecapitalizeState);
|
2014-03-20 08:02:12 +00:00
|
|
|
mKeyboardTextsSet.setLocale(mSubtypeSwitcher.getCurrentSubtypeLocale(), mThemeContext);
|
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());
|
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
|
|
|
}
|
|
|
|
|
2011-07-27 22:32:25 +00:00
|
|
|
public void onHideWindow() {
|
2014-05-02 15:33:41 +00:00
|
|
|
if (mKeyboardView != null) {
|
|
|
|
mKeyboardView.onHideWindow();
|
|
|
|
}
|
2011-07-27 22:32:25 +00:00
|
|
|
}
|
|
|
|
|
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}.
|
2014-09-03 10:36:35 +00:00
|
|
|
final SettingsValues currentSettingsValues = Settings.getInstance().getCurrent();
|
|
|
|
setMainKeyboardFrame(currentSettingsValues);
|
|
|
|
// TODO: pass this object to setKeyboard instead of getting the current values.
|
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(
|
2014-09-03 10:36:35 +00:00
|
|
|
currentSettingsValues.mKeyPreviewPopupOn,
|
|
|
|
currentSettingsValues.mKeyPreviewPopupDismissDelay);
|
2014-02-07 06:25:50 +00:00
|
|
|
keyboardView.setKeyPreviewAnimationParams(
|
2014-09-03 10:36:35 +00:00
|
|
|
currentSettingsValues.mHasCustomKeyPreviewAnimationParams,
|
|
|
|
currentSettingsValues.mKeyPreviewShowUpStartXScale,
|
|
|
|
currentSettingsValues.mKeyPreviewShowUpStartYScale,
|
|
|
|
currentSettingsValues.mKeyPreviewShowUpDuration,
|
|
|
|
currentSettingsValues.mKeyPreviewDismissEndXScale,
|
|
|
|
currentSettingsValues.mKeyPreviewDismissEndYScale,
|
|
|
|
currentSettingsValues.mKeyPreviewDismissDuration);
|
2012-07-23 05:59:19 +00:00
|
|
|
keyboardView.updateShortcutKey(mSubtypeSwitcher.isShortcutImeReady());
|
2012-03-13 05:15:39 +00:00
|
|
|
final boolean subtypeChanged = (oldKeyboard == null)
|
|
|
|
|| !keyboard.mId.mLocale.equals(oldKeyboard.mId.mLocale);
|
2014-03-28 07:03:00 +00:00
|
|
|
final int languageOnSpacebarFormatType = mSubtypeSwitcher.getLanguageOnSpacebarFormatType(
|
2014-03-28 07:29:56 +00:00
|
|
|
keyboard.mId.mSubtype);
|
2014-03-28 07:03:00 +00:00
|
|
|
final boolean hasMultipleEnabledIMEsOrSubtypes = RichInputMethodManager.getInstance()
|
|
|
|
.hasMultipleEnabledIMEsOrSubtypes(true /* shouldIncludeAuxiliarySubtypes */);
|
|
|
|
keyboardView.startDisplayLanguageOnSpacebar(subtypeChanged, languageOnSpacebarFormatType,
|
|
|
|
hasMultipleEnabledIMEsOrSubtypes);
|
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-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().
|
2014-04-14 08:04:50 +00:00
|
|
|
public void resetKeyboardStateToAlphabet(final int currentAutoCapsState,
|
|
|
|
final int currentRecapitalizeState) {
|
|
|
|
mState.onResetKeyboardStateToAlphabet(currentAutoCapsState, currentRecapitalizeState);
|
2012-11-06 07:45:44 +00:00
|
|
|
}
|
|
|
|
|
2014-03-27 09:26:36 +00:00
|
|
|
public void onPressKey(final int code, final boolean isSinglePointer,
|
2014-04-14 08:04:50 +00:00
|
|
|
final int currentAutoCapsState, final int currentRecapitalizeState) {
|
|
|
|
mState.onPressKey(code, isSinglePointer, currentAutoCapsState, currentRecapitalizeState);
|
2012-01-24 03:06:49 +00:00
|
|
|
}
|
|
|
|
|
2014-04-14 06:33:30 +00:00
|
|
|
public void onReleaseKey(final int code, final boolean withSliding,
|
|
|
|
final int currentAutoCapsState, final int currentRecapitalizeState) {
|
|
|
|
mState.onReleaseKey(code, withSliding, currentAutoCapsState, currentRecapitalizeState);
|
2012-01-24 03:06:49 +00:00
|
|
|
}
|
|
|
|
|
2014-04-14 08:04:50 +00:00
|
|
|
public void onFinishSlidingInput(final int currentAutoCapsState,
|
|
|
|
final int currentRecapitalizeState) {
|
|
|
|
mState.onFinishSlidingInput(currentAutoCapsState, currentRecapitalizeState);
|
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
|
|
|
}
|
|
|
|
|
2014-09-03 10:36:35 +00:00
|
|
|
private void setMainKeyboardFrame(final SettingsValues settingsValues) {
|
|
|
|
mMainKeyboardFrame.setVisibility(
|
|
|
|
settingsValues.mHasHardwareKeyboard ? View.GONE : 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() {
|
2014-05-15 07:07:15 +00:00
|
|
|
final Keyboard keyboard = mKeyboardLayoutSet.getKeyboard(KeyboardId.ELEMENT_ALPHABET);
|
2013-08-30 10:28:01 +00:00
|
|
|
mMainKeyboardFrame.setVisibility(View.GONE);
|
2014-02-06 09:14:26 +00:00
|
|
|
mEmojiPalettesView.startEmojiPalettes(
|
2014-02-24 08:24:49 +00:00
|
|
|
mKeyboardTextsSet.getText(KeyboardTextsSet.SWITCH_TO_ALPHA_KEY_LABEL),
|
2014-05-14 07:47:12 +00:00
|
|
|
mKeyboardView.getKeyVisualAttribute(), keyboard.mIconsSet);
|
2013-10-07 02:28:57 +00:00
|
|
|
mEmojiPalettesView.setVisibility(View.VISIBLE);
|
2013-08-30 10:28:01 +00:00
|
|
|
}
|
|
|
|
|
2014-08-08 07:26:25 +00:00
|
|
|
public void onToggleEmojiKeyboard() {
|
2014-09-08 08:56:19 +00:00
|
|
|
if (mKeyboardLayoutSet == null || !isShowingEmojiPalettes()) {
|
|
|
|
mLatinIME.startShowingInputView();
|
2014-08-08 07:26:25 +00:00
|
|
|
setEmojiKeyboard();
|
2014-09-08 08:56:19 +00:00
|
|
|
} else {
|
|
|
|
mLatinIME.stopShowingInputView();
|
|
|
|
setAlphabetKeyboard();
|
2014-08-08 07:26:25 +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));
|
|
|
|
}
|
|
|
|
|
2014-03-27 09:37:16 +00:00
|
|
|
// Future method for requesting an updating to the shift state.
|
|
|
|
public void requestUpdatingShiftState(final int currentAutoCapsState,
|
|
|
|
final int currentRecapitalizeState) {
|
|
|
|
mState.onUpdateShiftState(currentAutoCapsState, currentRecapitalizeState);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
*/
|
2014-08-26 09:48:18 +00:00
|
|
|
public void onEvent(final Event event, final int currentAutoCapsState,
|
2014-04-14 08:04:50 +00:00
|
|
|
final int currentRecapitalizeState) {
|
2014-08-26 09:48:18 +00:00
|
|
|
mState.onEvent(event, currentAutoCapsState, currentRecapitalizeState);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
|
2013-10-11 10:15:16 +00:00
|
|
|
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-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();
|
|
|
|
}
|
|
|
|
|
2014-05-08 03:04:36 +00:00
|
|
|
updateKeyboardThemeAndContextThemeWrapper(
|
2014-09-17 10:06:07 +00:00
|
|
|
mLatinIME, KeyboardTheme.getKeyboardTheme(mLatinIME /* context */));
|
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(
|
2014-08-25 09:26:11 +00:00
|
|
|
R.id.emoji_palettes_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-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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2014-06-26 09:43:14 +00:00
|
|
|
|
|
|
|
public int getCurrentKeyboardScriptId() {
|
2014-06-30 11:59:18 +00:00
|
|
|
if (null == mKeyboardLayoutSet) {
|
|
|
|
return ScriptUtils.SCRIPT_UNKNOWN;
|
|
|
|
}
|
2014-06-26 09:43:14 +00:00
|
|
|
return mKeyboardLayoutSet.getScriptId();
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|