2009-03-13 22:11:42 +00:00
|
|
|
/*
|
2010-03-26 22:07:10 +00:00
|
|
|
* Copyright (C) 2008 The Android Open Source Project
|
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
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* 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;
|
|
|
|
|
2010-11-11 07:03:19 +00:00
|
|
|
import android.content.Context;
|
2010-08-20 05:35:02 +00:00
|
|
|
import android.content.SharedPreferences;
|
2009-10-12 20:48:35 +00:00
|
|
|
import android.content.res.Resources;
|
2010-08-20 05:35:02 +00:00
|
|
|
import android.preference.PreferenceManager;
|
2010-11-11 07:03:19 +00:00
|
|
|
import android.util.Log;
|
2010-08-20 05:35:02 +00:00
|
|
|
import android.view.InflateException;
|
2010-11-20 00:04:52 +00:00
|
|
|
import android.view.inputmethod.EditorInfo;
|
2009-10-12 20:48:35 +00:00
|
|
|
|
2010-09-08 16:41:58 +00:00
|
|
|
import java.lang.ref.SoftReference;
|
2010-10-08 13:17:16 +00:00
|
|
|
import java.util.Arrays;
|
2010-09-06 05:50:50 +00:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Locale;
|
|
|
|
|
2010-08-20 05:35:02 +00:00
|
|
|
public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceChangeListener {
|
2010-11-11 07:03:19 +00:00
|
|
|
private static final String TAG = "KeyboardSwitcher";
|
|
|
|
private static final boolean DEBUG = false;
|
2010-11-13 08:16:34 +00:00
|
|
|
public static final boolean DEBUG_STATE = false;
|
2009-03-13 22:11:42 +00:00
|
|
|
|
2010-10-19 15:18:50 +00:00
|
|
|
public static final int MODE_TEXT = 0;
|
|
|
|
public static final int MODE_URL = 1;
|
|
|
|
public static final int MODE_EMAIL = 2;
|
|
|
|
public static final int MODE_IM = 3;
|
|
|
|
public static final int MODE_WEB = 4;
|
|
|
|
public static final int MODE_PHONE = 5;
|
2010-11-24 01:55:22 +00:00
|
|
|
public static final int MODE_NUMBER = 6;
|
2010-10-19 15:18:50 +00:00
|
|
|
|
2010-11-19 08:31:20 +00:00
|
|
|
// Changing DEFAULT_LAYOUT_ID also requires prefs_for_debug.xml to be matched with.
|
|
|
|
public static final String DEFAULT_LAYOUT_ID = "5";
|
2010-09-02 04:48:48 +00:00
|
|
|
public static final String PREF_KEYBOARD_LAYOUT = "pref_keyboard_layout_20100902";
|
2010-08-20 05:35:02 +00:00
|
|
|
private static final int[] THEMES = new int [] {
|
2010-11-19 08:31:20 +00:00
|
|
|
R.layout.input_basic,
|
|
|
|
R.layout.input_basic_highcontrast,
|
|
|
|
R.layout.input_stone_normal,
|
|
|
|
R.layout.input_stone_bold,
|
|
|
|
R.layout.input_gingerbread,
|
|
|
|
R.layout.input_honeycomb, // DEFAULT_LAYOUT_ID
|
|
|
|
};
|
2010-08-20 05:35:02 +00:00
|
|
|
|
2009-07-21 22:47:11 +00:00
|
|
|
private static final int SYMBOLS_MODE_STATE_NONE = 0;
|
|
|
|
private static final int SYMBOLS_MODE_STATE_BEGIN = 1;
|
|
|
|
private static final int SYMBOLS_MODE_STATE_SYMBOL = 2;
|
|
|
|
|
2010-11-17 07:35:35 +00:00
|
|
|
private SubtypeSwitcher mSubtypeSwitcher;
|
|
|
|
|
2010-09-21 07:55:18 +00:00
|
|
|
private LatinKeyboardView mInputView;
|
2010-11-17 07:35:35 +00:00
|
|
|
private LatinIME mInputMethodService;
|
2010-09-01 06:45:20 +00:00
|
|
|
|
2010-11-13 08:16:34 +00:00
|
|
|
private ShiftKeyState mShiftKeyState = new ShiftKeyState("Shift");
|
|
|
|
private ModifierKeyState mSymbolKeyState = new ModifierKeyState("Symbol");
|
2010-11-16 09:47:39 +00:00
|
|
|
|
2009-04-16 19:56:10 +00:00
|
|
|
private KeyboardId mSymbolsId;
|
|
|
|
private KeyboardId mSymbolsShiftedId;
|
|
|
|
|
|
|
|
private KeyboardId mCurrentId;
|
2010-11-11 07:03:19 +00:00
|
|
|
private final HashMap<KeyboardId, SoftReference<LatinKeyboard>> mKeyboardCache =
|
|
|
|
new HashMap<KeyboardId, SoftReference<LatinKeyboard>>();
|
2010-01-16 20:21:23 +00:00
|
|
|
|
2010-11-11 07:03:19 +00:00
|
|
|
private int mMode = MODE_TEXT; /* default value */
|
2009-03-13 22:11:42 +00:00
|
|
|
private int mImeOptions;
|
2009-04-16 19:56:10 +00:00
|
|
|
private boolean mIsSymbols;
|
2010-09-02 13:54:37 +00:00
|
|
|
/** mIsAutoCompletionActive indicates that auto completed word will be input instead of
|
|
|
|
* what user actually typed. */
|
|
|
|
private boolean mIsAutoCompletionActive;
|
2010-11-20 02:45:30 +00:00
|
|
|
private boolean mVoiceKeyEnabled;
|
2010-11-11 00:10:10 +00:00
|
|
|
private boolean mVoiceButtonOnPrimary;
|
2009-07-21 22:47:11 +00:00
|
|
|
private int mSymbolsModeState = SYMBOLS_MODE_STATE_NONE;
|
2009-03-13 22:11:42 +00:00
|
|
|
|
2010-09-15 04:37:52 +00:00
|
|
|
// Indicates whether or not we have the settings key
|
2010-09-21 07:55:18 +00:00
|
|
|
private boolean mHasSettingsKey;
|
2010-09-15 04:37:52 +00:00
|
|
|
private static final int SETTINGS_KEY_MODE_AUTO = R.string.settings_key_mode_auto;
|
2010-10-22 05:28:12 +00:00
|
|
|
private static final int SETTINGS_KEY_MODE_ALWAYS_SHOW =
|
|
|
|
R.string.settings_key_mode_always_show;
|
2010-11-02 09:55:20 +00:00
|
|
|
// NOTE: No need to have SETTINGS_KEY_MODE_ALWAYS_HIDE here because it's not being referred to
|
|
|
|
// in the source code now.
|
|
|
|
// Default is SETTINGS_KEY_MODE_AUTO.
|
|
|
|
private static final int DEFAULT_SETTINGS_KEY_MODE = SETTINGS_KEY_MODE_AUTO;
|
2010-09-15 04:37:52 +00:00
|
|
|
|
2010-08-20 05:35:02 +00:00
|
|
|
private int mLayoutId;
|
|
|
|
|
2010-11-17 07:35:35 +00:00
|
|
|
private static final KeyboardSwitcher sInstance = new KeyboardSwitcher();
|
|
|
|
|
|
|
|
public static KeyboardSwitcher getInstance() {
|
|
|
|
return sInstance;
|
|
|
|
}
|
|
|
|
|
|
|
|
private KeyboardSwitcher() {
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void init(LatinIME ims) {
|
|
|
|
sInstance.mInputMethodService = ims;
|
|
|
|
sInstance.mSubtypeSwitcher = SubtypeSwitcher.getInstance();
|
2010-08-20 05:35:02 +00:00
|
|
|
|
|
|
|
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ims);
|
2010-11-17 07:35:35 +00:00
|
|
|
sInstance.mLayoutId = Integer.valueOf(
|
|
|
|
prefs.getString(PREF_KEYBOARD_LAYOUT, DEFAULT_LAYOUT_ID));
|
|
|
|
prefs.registerOnSharedPreferenceChangeListener(sInstance);
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|
|
|
|
|
2010-10-19 15:18:50 +00:00
|
|
|
private void makeSymbolsKeyboardIds() {
|
2010-11-17 07:35:35 +00:00
|
|
|
final Locale locale = mSubtypeSwitcher.getInputLocale();
|
2010-11-11 07:03:19 +00:00
|
|
|
final int orientation = mInputMethodService.getResources().getConfiguration().orientation;
|
|
|
|
final int mode = mMode;
|
2010-11-22 00:40:38 +00:00
|
|
|
final int colorScheme = getColorScheme();
|
2010-11-11 07:03:19 +00:00
|
|
|
final boolean hasSettingsKey = mHasSettingsKey;
|
2010-11-20 02:45:30 +00:00
|
|
|
final boolean voiceKeyEnabled = mVoiceKeyEnabled;
|
|
|
|
final boolean hasVoiceKey = voiceKeyEnabled && !mVoiceButtonOnPrimary;
|
2010-11-11 07:03:19 +00:00
|
|
|
final int imeOptions = mImeOptions;
|
2010-11-23 09:36:33 +00:00
|
|
|
// Note: This comment is only applied for phone number keyboard layout.
|
|
|
|
// On non-xlarge device, "@integer/key_switch_alpha_symbol" key code is used to switch
|
|
|
|
// between "phone keyboard" and "phone symbols keyboard". But on xlarge device,
|
|
|
|
// "@integer/key_shift" key code is used for that purpose in order to properly display
|
|
|
|
// "more" and "locked more" key labels. To achieve these behavior, we should initialize
|
|
|
|
// mSymbolsId and mSymbolsShiftedId to "phone keyboard" and "phone symbols keyboard"
|
|
|
|
// respectively here for xlarge device's layout switching.
|
|
|
|
mSymbolsId = new KeyboardId(locale, orientation, mode,
|
2010-11-22 00:40:38 +00:00
|
|
|
mode == MODE_PHONE ? R.xml.kbd_phone : R.xml.kbd_symbols,
|
2010-11-20 02:45:30 +00:00
|
|
|
colorScheme, hasSettingsKey, voiceKeyEnabled, hasVoiceKey, imeOptions, true);
|
2010-11-23 09:36:33 +00:00
|
|
|
mSymbolsShiftedId = new KeyboardId(locale, orientation, mode,
|
2010-11-22 00:40:38 +00:00
|
|
|
mode == MODE_PHONE ? R.xml.kbd_phone_symbols : R.xml.kbd_symbols_shift,
|
2010-11-20 02:45:30 +00:00
|
|
|
colorScheme, hasSettingsKey, voiceKeyEnabled, hasVoiceKey, imeOptions, true);
|
2009-04-16 19:56:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Represents the parameters necessary to construct a new LatinKeyboard,
|
|
|
|
* which also serve as a unique identifier for each keyboard type.
|
|
|
|
*/
|
2010-11-11 23:28:14 +00:00
|
|
|
public static class KeyboardId {
|
2010-11-11 02:57:33 +00:00
|
|
|
public final Locale mLocale;
|
|
|
|
public final int mOrientation;
|
|
|
|
public final int mMode;
|
2010-11-22 00:40:38 +00:00
|
|
|
public final int mXmlId;
|
2010-11-11 02:57:33 +00:00
|
|
|
public final int mColorScheme;
|
2010-11-11 07:03:19 +00:00
|
|
|
public final boolean mHasSettingsKey;
|
2010-11-20 02:45:30 +00:00
|
|
|
public final boolean mVoiceKeyEnabled;
|
2010-11-11 07:03:19 +00:00
|
|
|
public final boolean mHasVoiceKey;
|
|
|
|
public final int mImeOptions;
|
2010-11-11 02:57:33 +00:00
|
|
|
public final boolean mEnableShiftLock;
|
2009-04-16 19:56:10 +00:00
|
|
|
|
2010-10-08 13:17:16 +00:00
|
|
|
private final int mHashCode;
|
|
|
|
|
2010-11-11 23:28:14 +00:00
|
|
|
public KeyboardId(Locale locale, int orientation, int mode,
|
2010-11-22 00:40:38 +00:00
|
|
|
int xmlId, int colorScheme, boolean hasSettingsKey, boolean voiceKeyEnabled,
|
2010-11-20 02:45:30 +00:00
|
|
|
boolean hasVoiceKey, int imeOptions, boolean enableShiftLock) {
|
2010-11-11 02:57:33 +00:00
|
|
|
this.mLocale = locale;
|
|
|
|
this.mOrientation = orientation;
|
|
|
|
this.mMode = mode;
|
2010-11-22 00:40:38 +00:00
|
|
|
this.mXmlId = xmlId;
|
2010-11-11 02:57:33 +00:00
|
|
|
this.mColorScheme = colorScheme;
|
2010-11-11 07:03:19 +00:00
|
|
|
this.mHasSettingsKey = hasSettingsKey;
|
2010-11-20 02:45:30 +00:00
|
|
|
this.mVoiceKeyEnabled = voiceKeyEnabled;
|
2010-11-11 07:03:19 +00:00
|
|
|
this.mHasVoiceKey = hasVoiceKey;
|
2010-11-20 00:04:52 +00:00
|
|
|
// We are interested only in IME_MASK_ACTION enum value and IME_FLAG_NO_ENTER_ACTION.
|
|
|
|
this.mImeOptions = imeOptions
|
|
|
|
& (EditorInfo.IME_MASK_ACTION | EditorInfo.IME_FLAG_NO_ENTER_ACTION);
|
2010-11-11 02:57:33 +00:00
|
|
|
this.mEnableShiftLock = enableShiftLock;
|
2010-10-08 13:17:16 +00:00
|
|
|
|
|
|
|
this.mHashCode = Arrays.hashCode(new Object[] {
|
2010-11-11 07:03:19 +00:00
|
|
|
locale,
|
|
|
|
orientation,
|
|
|
|
mode,
|
2010-11-22 00:40:38 +00:00
|
|
|
xmlId,
|
2010-11-11 07:03:19 +00:00
|
|
|
colorScheme,
|
|
|
|
hasSettingsKey,
|
2010-11-20 02:45:30 +00:00
|
|
|
voiceKeyEnabled,
|
2010-11-11 07:03:19 +00:00
|
|
|
hasVoiceKey,
|
|
|
|
imeOptions,
|
|
|
|
enableShiftLock,
|
2010-10-08 13:17:16 +00:00
|
|
|
});
|
2009-04-16 19:56:10 +00:00
|
|
|
}
|
|
|
|
|
2010-11-11 23:28:14 +00:00
|
|
|
public int getXmlId() {
|
2010-11-22 00:40:38 +00:00
|
|
|
return mXmlId;
|
2010-11-11 23:28:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isAlphabetMode() {
|
2010-11-22 00:40:38 +00:00
|
|
|
return mXmlId == R.xml.kbd_qwerty;
|
2010-11-11 23:28:14 +00:00
|
|
|
}
|
|
|
|
|
2010-08-20 05:35:02 +00:00
|
|
|
@Override
|
2009-04-16 19:56:10 +00:00
|
|
|
public boolean equals(Object other) {
|
|
|
|
return other instanceof KeyboardId && equals((KeyboardId) other);
|
|
|
|
}
|
|
|
|
|
2010-09-08 16:41:58 +00:00
|
|
|
private boolean equals(KeyboardId other) {
|
2010-11-11 02:57:33 +00:00
|
|
|
return other.mLocale.equals(this.mLocale)
|
|
|
|
&& other.mOrientation == this.mOrientation
|
|
|
|
&& other.mMode == this.mMode
|
2010-11-22 00:40:38 +00:00
|
|
|
&& other.mXmlId == this.mXmlId
|
2010-11-11 02:57:33 +00:00
|
|
|
&& other.mColorScheme == this.mColorScheme
|
2010-11-11 07:03:19 +00:00
|
|
|
&& other.mHasSettingsKey == this.mHasSettingsKey
|
2010-11-20 02:45:30 +00:00
|
|
|
&& other.mVoiceKeyEnabled == this.mVoiceKeyEnabled
|
2010-11-11 07:03:19 +00:00
|
|
|
&& other.mHasVoiceKey == this.mHasVoiceKey
|
|
|
|
&& other.mImeOptions == this.mImeOptions
|
2010-11-11 02:57:33 +00:00
|
|
|
&& other.mEnableShiftLock == this.mEnableShiftLock;
|
2009-04-16 19:56:10 +00:00
|
|
|
}
|
|
|
|
|
2010-08-20 05:35:02 +00:00
|
|
|
@Override
|
2009-04-16 19:56:10 +00:00
|
|
|
public int hashCode() {
|
2010-10-08 13:17:16 +00:00
|
|
|
return mHashCode;
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-11-11 07:03:19 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
2010-11-20 02:45:30 +00:00
|
|
|
return String.format("[%s %s %5s imeOptions=0x%08x xml=0x%08x %s%s%s%s%s]",
|
2010-11-11 23:28:14 +00:00
|
|
|
mLocale,
|
|
|
|
(mOrientation == 1 ? "port" : "land"),
|
|
|
|
modeName(mMode),
|
|
|
|
mImeOptions,
|
2010-11-22 00:40:38 +00:00
|
|
|
mXmlId,
|
|
|
|
colorSchemeName(mColorScheme),
|
2010-11-11 23:28:14 +00:00
|
|
|
(mHasSettingsKey ? " hasSettingsKey" : ""),
|
2010-11-20 02:45:30 +00:00
|
|
|
(mVoiceKeyEnabled ? " voiceKeyEnabled" : ""),
|
2010-11-11 23:28:14 +00:00
|
|
|
(mHasVoiceKey ? " hasVoiceKey" : ""),
|
|
|
|
(mEnableShiftLock ? " enableShiftLock" : ""));
|
2010-11-11 07:03:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private static String modeName(int mode) {
|
2010-11-11 23:28:14 +00:00
|
|
|
switch (mode) {
|
|
|
|
case MODE_TEXT: return "text";
|
|
|
|
case MODE_URL: return "url";
|
|
|
|
case MODE_EMAIL: return "email";
|
|
|
|
case MODE_IM: return "im";
|
|
|
|
case MODE_WEB: return "web";
|
|
|
|
case MODE_PHONE: return "phone";
|
2010-11-24 01:55:22 +00:00
|
|
|
case MODE_NUMBER: return "number";
|
2010-11-11 07:03:19 +00:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2010-11-22 00:40:38 +00:00
|
|
|
|
|
|
|
private static String colorSchemeName(int colorScheme) {
|
|
|
|
switch (colorScheme) {
|
|
|
|
case BaseKeyboardView.COLOR_SCHEME_WHITE: return "white";
|
|
|
|
case BaseKeyboardView.COLOR_SCHEME_BLACK: return "black";
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2010-11-11 07:03:19 +00:00
|
|
|
private boolean hasVoiceKey(boolean isSymbols) {
|
2010-11-20 02:45:30 +00:00
|
|
|
return mVoiceKeyEnabled && (isSymbols != mVoiceButtonOnPrimary);
|
2010-01-16 20:21:23 +00:00
|
|
|
}
|
|
|
|
|
2010-11-20 02:45:30 +00:00
|
|
|
public void loadKeyboard(int mode, int imeOptions, boolean voiceKeyEnabled,
|
2010-11-11 00:10:10 +00:00
|
|
|
boolean voiceButtonOnPrimary) {
|
2009-09-01 21:05:19 +00:00
|
|
|
mSymbolsModeState = SYMBOLS_MODE_STATE_NONE;
|
2010-08-20 05:35:02 +00:00
|
|
|
try {
|
2010-11-20 02:45:30 +00:00
|
|
|
loadKeyboardInternal(mode, imeOptions, voiceKeyEnabled, voiceButtonOnPrimary,
|
2010-11-11 00:10:10 +00:00
|
|
|
false);
|
2010-08-20 05:35:02 +00:00
|
|
|
} catch (RuntimeException e) {
|
2010-11-11 23:28:14 +00:00
|
|
|
Log.w(TAG, e);
|
2010-10-19 15:18:50 +00:00
|
|
|
LatinImeLogger.logOnException(mode + "," + imeOptions, e);
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|
2009-04-16 19:56:10 +00:00
|
|
|
}
|
|
|
|
|
2010-11-11 07:03:19 +00:00
|
|
|
private void loadKeyboardInternal(int mode, int imeOptions, boolean voiceButtonEnabled,
|
2010-11-11 00:10:10 +00:00
|
|
|
boolean voiceButtonOnPrimary, boolean isSymbols) {
|
2010-02-24 03:01:43 +00:00
|
|
|
if (mInputView == null) return;
|
2010-11-11 07:03:19 +00:00
|
|
|
mInputView.setPreviewEnabled(mInputMethodService.getPopupOn());
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
mMode = mode;
|
|
|
|
mImeOptions = imeOptions;
|
2010-11-20 02:45:30 +00:00
|
|
|
mVoiceKeyEnabled = voiceButtonEnabled;
|
2010-11-11 07:03:19 +00:00
|
|
|
mVoiceButtonOnPrimary = voiceButtonOnPrimary;
|
2009-04-28 18:38:42 +00:00
|
|
|
mIsSymbols = isSymbols;
|
2010-11-11 07:03:19 +00:00
|
|
|
// Update the settings key state because number of enabled IMEs could have been changed
|
|
|
|
mHasSettingsKey = getSettingsKeyMode(
|
|
|
|
PreferenceManager.getDefaultSharedPreferences(mInputMethodService),
|
|
|
|
mInputMethodService);
|
|
|
|
makeSymbolsKeyboardIds();
|
2010-01-16 20:21:23 +00:00
|
|
|
|
2009-04-16 19:56:10 +00:00
|
|
|
KeyboardId id = getKeyboardId(mode, imeOptions, isSymbols);
|
2010-11-11 07:03:19 +00:00
|
|
|
LatinKeyboard keyboard = getKeyboard(id);
|
2009-04-16 19:56:10 +00:00
|
|
|
|
|
|
|
mCurrentId = id;
|
|
|
|
mInputView.setKeyboard(keyboard);
|
|
|
|
}
|
|
|
|
|
|
|
|
private LatinKeyboard getKeyboard(KeyboardId id) {
|
2010-11-11 07:03:19 +00:00
|
|
|
final SoftReference<LatinKeyboard> ref = mKeyboardCache.get(id);
|
2010-09-08 16:41:58 +00:00
|
|
|
LatinKeyboard keyboard = (ref == null) ? null : ref.get();
|
|
|
|
if (keyboard == null) {
|
2010-11-11 07:03:19 +00:00
|
|
|
final Resources res = mInputMethodService.getResources();
|
2010-11-17 07:35:35 +00:00
|
|
|
final Locale savedLocale = mSubtypeSwitcher.changeSystemLocale(
|
|
|
|
mSubtypeSwitcher.getInputLocale());
|
2010-11-11 07:03:19 +00:00
|
|
|
|
2010-11-11 23:28:14 +00:00
|
|
|
keyboard = new LatinKeyboard(mInputMethodService, id);
|
2009-10-22 21:51:39 +00:00
|
|
|
|
2009-04-16 19:56:10 +00:00
|
|
|
if (id.mEnableShiftLock) {
|
|
|
|
keyboard.enableShiftLock();
|
|
|
|
}
|
2010-11-11 07:03:19 +00:00
|
|
|
|
|
|
|
mKeyboardCache.put(id, new SoftReference<LatinKeyboard>(keyboard));
|
|
|
|
if (DEBUG)
|
|
|
|
Log.d(TAG, "keyboard cache size=" + mKeyboardCache.size() + ": "
|
|
|
|
+ ((ref == null) ? "LOAD" : "GCed") + " id=" + id);
|
2009-10-12 20:48:35 +00:00
|
|
|
|
2010-11-17 07:35:35 +00:00
|
|
|
mSubtypeSwitcher.changeSystemLocale(savedLocale);
|
2010-11-11 07:03:19 +00:00
|
|
|
} else if (DEBUG) {
|
|
|
|
Log.d(TAG, "keyboard cache size=" + mKeyboardCache.size() + ": HIT id=" + id);
|
2009-04-16 19:56:10 +00:00
|
|
|
}
|
2010-11-11 07:03:19 +00:00
|
|
|
|
|
|
|
keyboard.onAutoCompletionStateChanged(mIsAutoCompletionActive);
|
|
|
|
keyboard.setShifted(false);
|
2010-09-08 16:41:58 +00:00
|
|
|
return keyboard;
|
2009-04-16 19:56:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private KeyboardId getKeyboardId(int mode, int imeOptions, boolean isSymbols) {
|
2010-11-11 07:03:19 +00:00
|
|
|
final boolean hasVoiceKey = hasVoiceKey(isSymbols);
|
2010-11-22 00:40:38 +00:00
|
|
|
final int charColorId = getColorScheme();
|
|
|
|
final int xmlId;
|
2010-10-19 15:18:50 +00:00
|
|
|
final boolean enableShiftLock;
|
|
|
|
|
|
|
|
if (isSymbols) {
|
2010-11-24 01:55:22 +00:00
|
|
|
if (mode == MODE_PHONE) {
|
|
|
|
xmlId = R.xml.kbd_phone_symbols;
|
|
|
|
} else if (mode == MODE_NUMBER) {
|
|
|
|
// Note: MODE_NUMBER keyboard layout has no "switch alpha symbol" key.
|
|
|
|
xmlId = R.xml.kbd_number;
|
|
|
|
} else {
|
|
|
|
xmlId = R.xml.kbd_symbols;
|
|
|
|
}
|
2010-10-19 15:18:50 +00:00
|
|
|
enableShiftLock = false;
|
2010-11-24 01:55:22 +00:00
|
|
|
} else {
|
|
|
|
if (mode == MODE_PHONE) {
|
|
|
|
xmlId = R.xml.kbd_phone;
|
|
|
|
enableShiftLock = false;
|
|
|
|
} else if (mode == MODE_NUMBER) {
|
|
|
|
xmlId = R.xml.kbd_number;
|
|
|
|
enableShiftLock = false;
|
|
|
|
} else {
|
|
|
|
xmlId = R.xml.kbd_qwerty;
|
|
|
|
enableShiftLock = true;
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-11-11 07:03:19 +00:00
|
|
|
final int orientation = mInputMethodService.getResources().getConfiguration().orientation;
|
2010-11-17 07:35:35 +00:00
|
|
|
final Locale locale = mSubtypeSwitcher.getInputLocale();
|
2010-11-22 00:40:38 +00:00
|
|
|
return new KeyboardId(locale, orientation, mode, xmlId, charColorId,
|
2010-11-20 02:45:30 +00:00
|
|
|
mHasSettingsKey, mVoiceKeyEnabled, hasVoiceKey, imeOptions, enableShiftLock);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2010-09-21 07:55:18 +00:00
|
|
|
public int getKeyboardMode() {
|
2009-03-13 22:11:42 +00:00
|
|
|
return mMode;
|
|
|
|
}
|
2010-11-13 08:01:13 +00:00
|
|
|
|
2010-09-21 07:55:18 +00:00
|
|
|
public boolean isAlphabetMode() {
|
2010-11-11 23:28:14 +00:00
|
|
|
return mCurrentId != null && mCurrentId.isAlphabetMode();
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2010-11-13 08:01:13 +00:00
|
|
|
public boolean isInputViewShown() {
|
|
|
|
return mInputView != null && mInputView.isShown();
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isKeyboardAvailable() {
|
2010-11-13 08:16:34 +00:00
|
|
|
if (mInputView != null)
|
|
|
|
return mInputView.getLatinKeyboard() != null;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private LatinKeyboard getLatinKeyboard() {
|
|
|
|
if (mInputView != null)
|
|
|
|
return mInputView.getLatinKeyboard();
|
|
|
|
return null;
|
2010-11-13 08:01:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setPreferredLetters(int[] frequencies) {
|
2010-11-13 08:16:34 +00:00
|
|
|
LatinKeyboard latinKeyboard = getLatinKeyboard();
|
|
|
|
if (latinKeyboard != null)
|
2010-11-13 08:01:13 +00:00
|
|
|
latinKeyboard.setPreferredLetters(frequencies);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void keyReleased() {
|
2010-11-13 08:16:34 +00:00
|
|
|
LatinKeyboard latinKeyboard = getLatinKeyboard();
|
|
|
|
if (latinKeyboard != null)
|
2010-11-13 08:01:13 +00:00
|
|
|
latinKeyboard.keyReleased();
|
|
|
|
}
|
|
|
|
|
2010-11-13 08:16:34 +00:00
|
|
|
public boolean isShiftedOrShiftLocked() {
|
2010-11-13 08:16:34 +00:00
|
|
|
LatinKeyboard latinKeyboard = getLatinKeyboard();
|
|
|
|
if (latinKeyboard != null)
|
2010-11-13 08:16:34 +00:00
|
|
|
return latinKeyboard.isShiftedOrShiftLocked();
|
2010-11-13 08:16:34 +00:00
|
|
|
return false;
|
2010-11-13 08:01:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isShiftLocked() {
|
2010-11-13 08:16:34 +00:00
|
|
|
LatinKeyboard latinKeyboard = getLatinKeyboard();
|
|
|
|
if (latinKeyboard != null)
|
|
|
|
return latinKeyboard.isShiftLocked();
|
|
|
|
return false;
|
2010-11-13 08:01:13 +00:00
|
|
|
}
|
|
|
|
|
2010-11-13 08:16:34 +00:00
|
|
|
public boolean isAutomaticTemporaryUpperCase() {
|
|
|
|
LatinKeyboard latinKeyboard = getLatinKeyboard();
|
|
|
|
if (latinKeyboard != null)
|
|
|
|
return latinKeyboard.isAutomaticTemporaryUpperCase();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isManualTemporaryUpperCase() {
|
|
|
|
LatinKeyboard latinKeyboard = getLatinKeyboard();
|
|
|
|
if (latinKeyboard != null)
|
|
|
|
return latinKeyboard.isManualTemporaryUpperCase();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setManualTemporaryUpperCase(boolean shifted) {
|
2010-11-13 08:16:34 +00:00
|
|
|
LatinKeyboard latinKeyboard = getLatinKeyboard();
|
2010-11-23 01:20:48 +00:00
|
|
|
if (latinKeyboard != null) {
|
|
|
|
// On non-distinct multi touch panel device, we should also turn off the shift locked
|
|
|
|
// state when shift key is pressed to go to normal mode.
|
|
|
|
// On the other hand, on distinct multi touch panel device, turning off the shift locked
|
|
|
|
// state with shift key pressing is handled by onReleaseShift().
|
|
|
|
if (!hasDistinctMultitouch() && !shifted && latinKeyboard.isShiftLocked()) {
|
|
|
|
latinKeyboard.setShiftLocked(false);
|
|
|
|
}
|
|
|
|
if (latinKeyboard.setShifted(shifted)) {
|
|
|
|
mInputView.invalidateAllKeys();
|
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-13 08:16:34 +00:00
|
|
|
private void setShiftLocked(boolean shiftLocked) {
|
|
|
|
LatinKeyboard latinKeyboard = getLatinKeyboard();
|
|
|
|
if (latinKeyboard != null && latinKeyboard.setShiftLocked(shiftLocked)) {
|
|
|
|
mInputView.invalidateAllKeys();
|
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|
|
|
|
|
2010-11-23 01:20:48 +00:00
|
|
|
/**
|
|
|
|
* Toggle keyboard shift state triggered by user touch event.
|
|
|
|
*/
|
2010-11-13 08:16:34 +00:00
|
|
|
public void toggleShift() {
|
|
|
|
mInputMethodService.mHandler.cancelUpdateShiftState();
|
2010-11-13 08:16:34 +00:00
|
|
|
if (DEBUG_STATE)
|
|
|
|
Log.d(TAG, "toggleShift:"
|
|
|
|
+ " keyboard=" + getLatinKeyboard().getKeyboardShiftState()
|
|
|
|
+ " shiftKeyState=" + mShiftKeyState);
|
2010-11-13 08:16:34 +00:00
|
|
|
if (isAlphabetMode()) {
|
2010-11-13 08:16:34 +00:00
|
|
|
setManualTemporaryUpperCase(!isShiftedOrShiftLocked());
|
2010-11-13 08:16:34 +00:00
|
|
|
} else {
|
|
|
|
toggleShiftInSymbol();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void toggleCapsLock() {
|
|
|
|
mInputMethodService.mHandler.cancelUpdateShiftState();
|
2010-11-13 08:16:34 +00:00
|
|
|
if (DEBUG_STATE)
|
|
|
|
Log.d(TAG, "toggleCapsLock:"
|
|
|
|
+ " keyboard=" + getLatinKeyboard().getKeyboardShiftState()
|
|
|
|
+ " shiftKeyState=" + mShiftKeyState);
|
2010-11-13 08:16:34 +00:00
|
|
|
if (isAlphabetMode()) {
|
|
|
|
if (isShiftLocked()) {
|
2010-11-13 08:16:34 +00:00
|
|
|
// Shift key is long pressed while caps lock state, we will toggle back to normal
|
|
|
|
// state. And mark as if shift key is released.
|
|
|
|
setShiftLocked(false);
|
|
|
|
mShiftKeyState.onRelease();
|
2010-11-13 08:16:34 +00:00
|
|
|
} else {
|
|
|
|
setShiftLocked(true);
|
|
|
|
}
|
|
|
|
}
|
2010-11-16 09:47:39 +00:00
|
|
|
}
|
|
|
|
|
2010-11-13 08:16:34 +00:00
|
|
|
private void setAutomaticTemporaryUpperCase() {
|
|
|
|
LatinKeyboard latinKeyboard = getLatinKeyboard();
|
|
|
|
if (latinKeyboard != null) {
|
|
|
|
latinKeyboard.setAutomaticTemporaryUpperCase();
|
|
|
|
mInputView.invalidateAllKeys();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-23 01:20:48 +00:00
|
|
|
/**
|
|
|
|
* Update keyboard shift state triggered by connected EditText status change.
|
|
|
|
*/
|
2010-11-13 08:16:34 +00:00
|
|
|
public void updateShiftState() {
|
2010-11-12 23:49:56 +00:00
|
|
|
final ShiftKeyState shiftKeyState = mShiftKeyState;
|
2010-11-13 08:16:34 +00:00
|
|
|
if (DEBUG_STATE)
|
|
|
|
Log.d(TAG, "updateShiftState:"
|
|
|
|
+ " autoCaps=" + mInputMethodService.getCurrentAutoCapsState()
|
|
|
|
+ " keyboard=" + getLatinKeyboard().getKeyboardShiftState()
|
2010-11-12 23:49:56 +00:00
|
|
|
+ " shiftKeyState=" + shiftKeyState);
|
|
|
|
if (isAlphabetMode()) {
|
|
|
|
if (!isShiftLocked() && !shiftKeyState.isIgnoring()) {
|
|
|
|
if (shiftKeyState.isReleasing() && mInputMethodService.getCurrentAutoCapsState()) {
|
|
|
|
// Only when shift key is releasing, automatic temporary upper case will be set.
|
|
|
|
setAutomaticTemporaryUpperCase();
|
|
|
|
} else {
|
|
|
|
setManualTemporaryUpperCase(shiftKeyState.isMomentary());
|
|
|
|
}
|
2010-11-13 08:16:34 +00:00
|
|
|
}
|
2010-11-12 23:49:56 +00:00
|
|
|
} else {
|
|
|
|
// In symbol keyboard mode, we should clear shift key state because only alphabet
|
|
|
|
// keyboard has shift key.
|
|
|
|
shiftKeyState.onRelease();
|
2010-11-13 08:16:34 +00:00
|
|
|
}
|
2010-11-16 09:47:39 +00:00
|
|
|
}
|
|
|
|
|
2010-11-13 08:16:34 +00:00
|
|
|
public void changeKeyboardMode() {
|
2010-11-13 08:16:34 +00:00
|
|
|
if (DEBUG_STATE)
|
|
|
|
Log.d(TAG, "changeKeyboardMode:"
|
|
|
|
+ " keyboard=" + getLatinKeyboard().getKeyboardShiftState()
|
|
|
|
+ " shiftKeyState=" + mShiftKeyState);
|
2010-11-13 08:16:34 +00:00
|
|
|
toggleKeyboardMode();
|
|
|
|
if (isShiftLocked() && isAlphabetMode())
|
|
|
|
setShiftLocked(true);
|
|
|
|
updateShiftState();
|
2010-11-16 09:47:39 +00:00
|
|
|
}
|
|
|
|
|
2010-11-13 08:16:34 +00:00
|
|
|
public void onPressShift() {
|
|
|
|
if (!isKeyboardAvailable())
|
|
|
|
return;
|
2010-11-13 08:16:34 +00:00
|
|
|
ShiftKeyState shiftKeyState = mShiftKeyState;
|
|
|
|
if (DEBUG_STATE)
|
|
|
|
Log.d(TAG, "onPressShift:"
|
|
|
|
+ " keyboard=" + getLatinKeyboard().getKeyboardShiftState()
|
|
|
|
+ " shiftKeyState=" + shiftKeyState);
|
|
|
|
if (isAlphabetMode()) {
|
|
|
|
if (isShiftLocked()) {
|
|
|
|
// Shift key is pressed while caps lock state, we will treat this state as shifted
|
|
|
|
// caps lock state and mark as if shift key pressed while normal state.
|
|
|
|
shiftKeyState.onPress();
|
2010-11-19 21:52:58 +00:00
|
|
|
setManualTemporaryUpperCase(true);
|
2010-11-13 08:16:34 +00:00
|
|
|
} else if (isAutomaticTemporaryUpperCase()) {
|
|
|
|
// Shift key is pressed while automatic temporary upper case, we have to move to
|
|
|
|
// manual temporary upper case.
|
2010-11-19 21:52:58 +00:00
|
|
|
shiftKeyState.onPress();
|
2010-11-13 08:16:34 +00:00
|
|
|
setManualTemporaryUpperCase(true);
|
|
|
|
} else if (isShiftedOrShiftLocked()) {
|
|
|
|
// In manual upper case state, we just record shift key has been pressing while
|
|
|
|
// shifted state.
|
|
|
|
shiftKeyState.onPressOnShifted();
|
|
|
|
} else {
|
|
|
|
// In base layout, chording or manual temporary upper case mode is started.
|
|
|
|
shiftKeyState.onPress();
|
2010-11-19 21:52:58 +00:00
|
|
|
toggleShift();
|
2010-11-13 08:16:34 +00:00
|
|
|
}
|
2010-11-13 08:16:34 +00:00
|
|
|
} else {
|
2010-11-13 08:16:34 +00:00
|
|
|
// In symbol mode, just toggle symbol and symbol more keyboard.
|
|
|
|
shiftKeyState.onPress();
|
2010-11-19 21:52:58 +00:00
|
|
|
toggleShift();
|
2010-11-13 08:16:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onReleaseShift() {
|
|
|
|
if (!isKeyboardAvailable())
|
|
|
|
return;
|
2010-11-13 08:16:34 +00:00
|
|
|
ShiftKeyState shiftKeyState = mShiftKeyState;
|
|
|
|
if (DEBUG_STATE)
|
|
|
|
Log.d(TAG, "onReleaseShift:"
|
|
|
|
+ " keyboard=" + getLatinKeyboard().getKeyboardShiftState()
|
|
|
|
+ " shiftKeyState=" + shiftKeyState);
|
2010-11-13 08:16:34 +00:00
|
|
|
if (isAlphabetMode()) {
|
2010-11-13 08:16:34 +00:00
|
|
|
if (shiftKeyState.isMomentary()) {
|
|
|
|
// After chording input while normal state.
|
|
|
|
toggleShift();
|
|
|
|
} else if (isShiftLocked() && !shiftKeyState.isIgnoring()) {
|
|
|
|
// Shift has been pressed without chording while caps lock state.
|
|
|
|
toggleCapsLock();
|
|
|
|
} else if (isShiftedOrShiftLocked() && shiftKeyState.isPressingOnShifted()) {
|
|
|
|
// Shift has been pressed without chording while shifted state.
|
2010-11-13 08:16:34 +00:00
|
|
|
toggleShift();
|
|
|
|
}
|
|
|
|
}
|
2010-11-13 08:16:34 +00:00
|
|
|
shiftKeyState.onRelease();
|
2010-11-16 09:47:39 +00:00
|
|
|
}
|
|
|
|
|
2010-11-16 08:28:50 +00:00
|
|
|
public void onPressSymbol() {
|
2010-11-13 08:16:34 +00:00
|
|
|
if (DEBUG_STATE)
|
|
|
|
Log.d(TAG, "onReleaseShift:"
|
|
|
|
+ " keyboard=" + getLatinKeyboard().getKeyboardShiftState()
|
|
|
|
+ " symbolKeyState=" + mSymbolKeyState);
|
2010-11-13 08:16:34 +00:00
|
|
|
changeKeyboardMode();
|
2010-11-16 08:28:50 +00:00
|
|
|
mSymbolKeyState.onPress();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onReleaseSymbol() {
|
2010-11-13 08:16:34 +00:00
|
|
|
if (DEBUG_STATE)
|
|
|
|
Log.d(TAG, "onReleaseShift:"
|
|
|
|
+ " keyboard=" + getLatinKeyboard().getKeyboardShiftState()
|
|
|
|
+ " symbolKeyState=" + mSymbolKeyState);
|
2010-11-13 08:16:34 +00:00
|
|
|
if (mSymbolKeyState.isMomentary())
|
|
|
|
changeKeyboardMode();
|
2010-11-16 08:28:50 +00:00
|
|
|
mSymbolKeyState.onRelease();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onOtherKeyPressed() {
|
2010-11-12 23:49:56 +00:00
|
|
|
if (DEBUG_STATE)
|
|
|
|
Log.d(TAG, "onOtherKeyPressed:"
|
|
|
|
+ " keyboard=" + getLatinKeyboard().getKeyboardShiftState()
|
|
|
|
+ " shiftKeyState=" + mShiftKeyState
|
|
|
|
+ " symbolKeyState=" + mSymbolKeyState);
|
2010-11-13 08:16:34 +00:00
|
|
|
mShiftKeyState.onOtherKeyPressed();
|
2010-11-16 08:28:50 +00:00
|
|
|
mSymbolKeyState.onOtherKeyPressed();
|
|
|
|
}
|
|
|
|
|
2010-11-13 08:16:34 +00:00
|
|
|
private void toggleShiftInSymbol() {
|
2010-10-08 13:17:16 +00:00
|
|
|
if (isAlphabetMode())
|
|
|
|
return;
|
2010-11-11 07:03:19 +00:00
|
|
|
final LatinKeyboard keyboard;
|
2010-10-08 13:17:16 +00:00
|
|
|
if (mCurrentId.equals(mSymbolsId) || !mCurrentId.equals(mSymbolsShiftedId)) {
|
2009-04-16 19:56:10 +00:00
|
|
|
mCurrentId = mSymbolsShiftedId;
|
2010-11-11 07:03:19 +00:00
|
|
|
keyboard = getKeyboard(mCurrentId);
|
2010-09-06 05:50:50 +00:00
|
|
|
// Symbol shifted keyboard has an ALT key that has a caps lock style indicator. To
|
|
|
|
// enable the indicator, we need to call enableShiftLock() and setShiftLocked(true).
|
|
|
|
// Thus we can keep the ALT key's Key.on value true while LatinKey.onRelease() is
|
|
|
|
// called.
|
2010-11-11 07:03:19 +00:00
|
|
|
keyboard.setShiftLocked(true);
|
2010-10-08 13:17:16 +00:00
|
|
|
} else {
|
2009-04-16 19:56:10 +00:00
|
|
|
mCurrentId = mSymbolsId;
|
2010-11-11 07:03:19 +00:00
|
|
|
keyboard = getKeyboard(mCurrentId);
|
2010-09-06 05:50:50 +00:00
|
|
|
// Symbol keyboard has an ALT key that has a caps lock style indicator. To disable the
|
|
|
|
// indicator, we need to call enableShiftLock() and setShiftLocked(false).
|
2010-11-11 07:03:19 +00:00
|
|
|
keyboard.setShifted(false);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-11-11 07:03:19 +00:00
|
|
|
mInputView.setKeyboard(keyboard);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2010-11-13 08:16:34 +00:00
|
|
|
private void toggleKeyboardMode() {
|
2010-11-20 02:45:30 +00:00
|
|
|
loadKeyboardInternal(mMode, mImeOptions, mVoiceKeyEnabled, mVoiceButtonOnPrimary,
|
2010-11-11 00:10:10 +00:00
|
|
|
!mIsSymbols);
|
2010-10-19 15:18:50 +00:00
|
|
|
if (mIsSymbols) {
|
2009-07-21 22:47:11 +00:00
|
|
|
mSymbolsModeState = SYMBOLS_MODE_STATE_BEGIN;
|
|
|
|
} else {
|
|
|
|
mSymbolsModeState = SYMBOLS_MODE_STATE_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-06 05:26:46 +00:00
|
|
|
public boolean hasDistinctMultitouch() {
|
|
|
|
return mInputView != null && mInputView.hasDistinctMultitouch();
|
|
|
|
}
|
|
|
|
|
2009-07-21 22:47:11 +00:00
|
|
|
/**
|
|
|
|
* Updates state machine to figure out when to automatically switch back to alpha mode.
|
|
|
|
*/
|
2010-11-13 08:16:34 +00:00
|
|
|
public void onKey(int key) {
|
|
|
|
// Switch back to alpha mode if user types one or more non-space/enter
|
|
|
|
// characters followed by a space/enter
|
2009-07-21 22:47:11 +00:00
|
|
|
switch (mSymbolsModeState) {
|
2010-11-13 08:16:34 +00:00
|
|
|
case SYMBOLS_MODE_STATE_BEGIN:
|
|
|
|
if (key != LatinIME.KEYCODE_SPACE && key != LatinIME.KEYCODE_ENTER && key > 0) {
|
|
|
|
mSymbolsModeState = SYMBOLS_MODE_STATE_SYMBOL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SYMBOLS_MODE_STATE_SYMBOL:
|
|
|
|
if (key == LatinIME.KEYCODE_ENTER || key == LatinIME.KEYCODE_SPACE) {
|
|
|
|
changeKeyboardMode();
|
|
|
|
}
|
|
|
|
break;
|
2009-07-21 22:47:11 +00:00
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
|
|
|
|
public LatinKeyboardView getInputView() {
|
|
|
|
return mInputView;
|
|
|
|
}
|
|
|
|
|
2010-11-11 07:03:19 +00:00
|
|
|
public void loadKeyboardView() {
|
|
|
|
loadKeyboardViewInternal(mLayoutId, true);
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|
|
|
|
|
2010-11-11 07:03:19 +00:00
|
|
|
private void loadKeyboardViewInternal(int newLayout, boolean forceReset) {
|
2010-08-20 05:35:02 +00:00
|
|
|
if (mLayoutId != newLayout || mInputView == null || forceReset) {
|
|
|
|
if (mInputView != null) {
|
|
|
|
mInputView.closing();
|
|
|
|
}
|
|
|
|
if (THEMES.length <= newLayout) {
|
|
|
|
newLayout = Integer.valueOf(DEFAULT_LAYOUT_ID);
|
|
|
|
}
|
|
|
|
|
|
|
|
LatinIMEUtil.GCUtils.getInstance().reset();
|
|
|
|
boolean tryGC = true;
|
|
|
|
for (int i = 0; i < LatinIMEUtil.GCUtils.GC_TRY_LOOP_MAX && tryGC; ++i) {
|
|
|
|
try {
|
|
|
|
mInputView = (LatinKeyboardView) mInputMethodService.getLayoutInflater(
|
|
|
|
).inflate(THEMES[newLayout], null);
|
|
|
|
tryGC = false;
|
|
|
|
} catch (OutOfMemoryError e) {
|
|
|
|
tryGC = LatinIMEUtil.GCUtils.getInstance().tryGCOrWait(
|
|
|
|
mLayoutId + "," + newLayout, e);
|
|
|
|
} catch (InflateException e) {
|
|
|
|
tryGC = LatinIMEUtil.GCUtils.getInstance().tryGCOrWait(
|
|
|
|
mLayoutId + "," + newLayout, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mInputView.setOnKeyboardActionListener(mInputMethodService);
|
|
|
|
mLayoutId = newLayout;
|
|
|
|
}
|
|
|
|
mInputMethodService.mHandler.post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
if (mInputView != null) {
|
|
|
|
mInputMethodService.setInputView(mInputView);
|
|
|
|
}
|
|
|
|
mInputMethodService.updateInputViewShown();
|
|
|
|
}});
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
|
|
|
if (PREF_KEYBOARD_LAYOUT.equals(key)) {
|
2010-11-11 07:03:19 +00:00
|
|
|
final int layoutId = Integer.valueOf(
|
|
|
|
sharedPreferences.getString(key, DEFAULT_LAYOUT_ID));
|
|
|
|
loadKeyboardViewInternal(layoutId, false);
|
2010-09-15 04:37:52 +00:00
|
|
|
} else if (LatinIMESettings.PREF_SETTINGS_KEY.equals(key)) {
|
2010-11-11 07:03:19 +00:00
|
|
|
mHasSettingsKey = getSettingsKeyMode(sharedPreferences, mInputMethodService);
|
|
|
|
loadKeyboardViewInternal(mLayoutId, true);
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-22 00:40:38 +00:00
|
|
|
private int getColorScheme() {
|
|
|
|
return (mInputView != null)
|
|
|
|
? mInputView.getColorScheme() : BaseKeyboardView.COLOR_SCHEME_WHITE;
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|
|
|
|
|
2010-09-02 13:54:37 +00:00
|
|
|
public void onAutoCompletionStateChanged(boolean isAutoCompletion) {
|
|
|
|
if (isAutoCompletion != mIsAutoCompletionActive) {
|
|
|
|
LatinKeyboardView keyboardView = getInputView();
|
|
|
|
mIsAutoCompletionActive = isAutoCompletion;
|
|
|
|
keyboardView.invalidateKey(((LatinKeyboard) keyboardView.getKeyboard())
|
|
|
|
.onAutoCompletionStateChanged(isAutoCompletion));
|
|
|
|
}
|
|
|
|
}
|
2010-09-15 04:37:52 +00:00
|
|
|
|
2010-11-11 07:03:19 +00:00
|
|
|
private static boolean getSettingsKeyMode(SharedPreferences prefs, Context context) {
|
|
|
|
Resources resources = context.getResources();
|
2010-10-22 05:28:12 +00:00
|
|
|
final boolean showSettingsKeyOption = resources.getBoolean(
|
|
|
|
R.bool.config_enable_show_settings_key_option);
|
2010-11-02 09:55:20 +00:00
|
|
|
if (showSettingsKeyOption) {
|
|
|
|
final String settingsKeyMode = prefs.getString(LatinIMESettings.PREF_SETTINGS_KEY,
|
|
|
|
resources.getString(DEFAULT_SETTINGS_KEY_MODE));
|
|
|
|
// We show the settings key when 1) SETTINGS_KEY_MODE_ALWAYS_SHOW or
|
|
|
|
// 2) SETTINGS_KEY_MODE_AUTO and there are two or more enabled IMEs on the system
|
|
|
|
if (settingsKeyMode.equals(resources.getString(SETTINGS_KEY_MODE_ALWAYS_SHOW))
|
|
|
|
|| (settingsKeyMode.equals(resources.getString(SETTINGS_KEY_MODE_AUTO))
|
2010-11-11 07:03:19 +00:00
|
|
|
&& LatinIMEUtil.hasMultipleEnabledIMEs(context))) {
|
|
|
|
return true;
|
2010-11-02 09:55:20 +00:00
|
|
|
}
|
2010-09-15 04:37:52 +00:00
|
|
|
}
|
2010-11-11 07:03:19 +00:00
|
|
|
return false;
|
2010-09-15 04:37:52 +00:00
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|