2010-12-02 09:46:21 +00:00
|
|
|
/*
|
2011-05-20 03:09:57 +00:00
|
|
|
* Copyright (C) 2010 The Android Open Source Project
|
2010-12-02 09:46:21 +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.keyboard;
|
|
|
|
|
2011-03-25 19:40:57 +00:00
|
|
|
import com.android.inputmethod.compat.EditorInfoCompatUtils;
|
2011-03-25 06:28:29 +00:00
|
|
|
import com.android.inputmethod.compat.InputTypeCompatUtils;
|
2010-12-02 09:46:21 +00:00
|
|
|
import com.android.inputmethod.latin.R;
|
|
|
|
|
|
|
|
import android.view.inputmethod.EditorInfo;
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Locale;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Represents the parameters necessary to construct a new LatinKeyboard,
|
|
|
|
* which also serve as a unique identifier for each keyboard type.
|
|
|
|
*/
|
|
|
|
public class KeyboardId {
|
|
|
|
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;
|
2011-05-27 12:41:13 +00:00
|
|
|
public static final int MODE_PHONE = 4;
|
|
|
|
public static final int MODE_NUMBER = 5;
|
2010-12-02 09:46:21 +00:00
|
|
|
|
|
|
|
public final Locale mLocale;
|
|
|
|
public final int mOrientation;
|
2011-05-17 10:02:32 +00:00
|
|
|
public final int mWidth;
|
2010-12-02 09:46:21 +00:00
|
|
|
public final int mMode;
|
|
|
|
public final int mXmlId;
|
|
|
|
public final int mColorScheme;
|
2011-06-17 09:25:54 +00:00
|
|
|
public final boolean mNavigateAction;
|
2011-02-20 03:54:14 +00:00
|
|
|
public final boolean mPasswordInput;
|
2010-12-02 09:46:21 +00:00
|
|
|
public final boolean mHasSettingsKey;
|
|
|
|
public final boolean mVoiceKeyEnabled;
|
|
|
|
public final boolean mHasVoiceKey;
|
2011-02-18 05:16:29 +00:00
|
|
|
public final int mImeAction;
|
2010-12-02 09:46:21 +00:00
|
|
|
public final boolean mEnableShiftLock;
|
2011-05-17 10:02:32 +00:00
|
|
|
|
2010-12-14 06:31:47 +00:00
|
|
|
public final String mXmlName;
|
2011-05-17 10:02:32 +00:00
|
|
|
public final EditorInfo mAttribute;
|
2010-12-02 09:46:21 +00:00
|
|
|
|
|
|
|
private final int mHashCode;
|
|
|
|
|
2011-02-20 03:54:14 +00:00
|
|
|
public KeyboardId(String xmlName, int xmlId, int colorScheme, Locale locale, int orientation,
|
2011-05-17 10:02:32 +00:00
|
|
|
int width, int mode, EditorInfo attribute, boolean hasSettingsKey,
|
|
|
|
boolean voiceKeyEnabled, boolean hasVoiceKey, boolean enableShiftLock) {
|
2011-02-20 03:54:14 +00:00
|
|
|
final int inputType = (attribute != null) ? attribute.inputType : 0;
|
|
|
|
final int imeOptions = (attribute != null) ? attribute.imeOptions : 0;
|
2010-12-02 09:46:21 +00:00
|
|
|
this.mLocale = locale;
|
|
|
|
this.mOrientation = orientation;
|
2011-05-17 10:02:32 +00:00
|
|
|
this.mWidth = width;
|
2010-12-02 09:46:21 +00:00
|
|
|
this.mMode = mode;
|
|
|
|
this.mXmlId = xmlId;
|
|
|
|
this.mColorScheme = colorScheme;
|
2011-06-17 09:25:54 +00:00
|
|
|
this.mNavigateAction = InputTypeCompatUtils.isWebInputType(inputType)
|
|
|
|
|| EditorInfoCompatUtils.hasFlagNavigateNext(imeOptions)
|
|
|
|
|| EditorInfoCompatUtils.hasFlagNavigatePrevious(imeOptions);
|
2011-03-25 06:28:29 +00:00
|
|
|
this.mPasswordInput = InputTypeCompatUtils.isPasswordInputType(inputType)
|
|
|
|
|| InputTypeCompatUtils.isVisiblePasswordInputType(inputType);
|
2010-12-02 09:46:21 +00:00
|
|
|
this.mHasSettingsKey = hasSettingsKey;
|
|
|
|
this.mVoiceKeyEnabled = voiceKeyEnabled;
|
|
|
|
this.mHasVoiceKey = hasVoiceKey;
|
2011-02-18 05:16:29 +00:00
|
|
|
// We are interested only in {@link EditorInfo#IME_MASK_ACTION} enum value and
|
|
|
|
// {@link EditorInfo#IME_FLAG_NO_ENTER_ACTION}.
|
2011-02-20 03:54:14 +00:00
|
|
|
this.mImeAction = imeOptions & (
|
|
|
|
EditorInfo.IME_MASK_ACTION | EditorInfo.IME_FLAG_NO_ENTER_ACTION);
|
2010-12-02 09:46:21 +00:00
|
|
|
this.mEnableShiftLock = enableShiftLock;
|
2011-05-17 10:02:32 +00:00
|
|
|
|
2010-12-14 06:31:47 +00:00
|
|
|
this.mXmlName = xmlName;
|
2011-05-17 10:02:32 +00:00
|
|
|
this.mAttribute = attribute;
|
2010-12-02 09:46:21 +00:00
|
|
|
|
|
|
|
this.mHashCode = Arrays.hashCode(new Object[] {
|
|
|
|
locale,
|
|
|
|
orientation,
|
2011-05-17 10:02:32 +00:00
|
|
|
width,
|
2010-12-02 09:46:21 +00:00
|
|
|
mode,
|
|
|
|
xmlId,
|
|
|
|
colorScheme,
|
2011-06-17 09:25:54 +00:00
|
|
|
mNavigateAction,
|
2011-02-20 03:54:14 +00:00
|
|
|
mPasswordInput,
|
2010-12-02 09:46:21 +00:00
|
|
|
hasSettingsKey,
|
|
|
|
voiceKeyEnabled,
|
|
|
|
hasVoiceKey,
|
2011-02-18 05:16:29 +00:00
|
|
|
mImeAction,
|
2010-12-02 09:46:21 +00:00
|
|
|
enableShiftLock,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-05-17 10:02:32 +00:00
|
|
|
public KeyboardId cloneWithNewLayout(String xmlName, int xmlId) {
|
|
|
|
return new KeyboardId(xmlName, xmlId, mColorScheme, mLocale, mOrientation, mWidth, mMode,
|
|
|
|
mAttribute, mHasSettingsKey, mVoiceKeyEnabled, mHasVoiceKey, mEnableShiftLock);
|
|
|
|
}
|
|
|
|
|
|
|
|
public KeyboardId cloneWithNewGeometry(int width) {
|
|
|
|
if (mWidth == width)
|
|
|
|
return this;
|
|
|
|
return new KeyboardId(mXmlName, mXmlId, mColorScheme, mLocale, mOrientation, width, mMode,
|
|
|
|
mAttribute, mHasSettingsKey, mVoiceKeyEnabled, mHasVoiceKey, mEnableShiftLock);
|
|
|
|
}
|
|
|
|
|
2010-12-02 09:46:21 +00:00
|
|
|
public int getXmlId() {
|
|
|
|
return mXmlId;
|
|
|
|
}
|
|
|
|
|
2010-12-02 11:54:32 +00:00
|
|
|
public boolean isAlphabetKeyboard() {
|
2010-12-02 09:46:21 +00:00
|
|
|
return mXmlId == R.xml.kbd_qwerty;
|
|
|
|
}
|
|
|
|
|
2010-12-17 07:56:15 +00:00
|
|
|
public boolean isSymbolsKeyboard() {
|
|
|
|
return mXmlId == R.xml.kbd_symbols;
|
|
|
|
}
|
|
|
|
|
2010-12-02 11:54:32 +00:00
|
|
|
public boolean isPhoneKeyboard() {
|
|
|
|
return mMode == MODE_PHONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isNumberKeyboard() {
|
|
|
|
return mMode == MODE_NUMBER;
|
|
|
|
}
|
|
|
|
|
2010-12-02 09:46:21 +00:00
|
|
|
@Override
|
|
|
|
public boolean equals(Object other) {
|
|
|
|
return other instanceof KeyboardId && equals((KeyboardId) other);
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean equals(KeyboardId other) {
|
|
|
|
return other.mLocale.equals(this.mLocale)
|
|
|
|
&& other.mOrientation == this.mOrientation
|
2011-05-17 10:02:32 +00:00
|
|
|
&& other.mWidth == this.mWidth
|
2010-12-02 09:46:21 +00:00
|
|
|
&& other.mMode == this.mMode
|
|
|
|
&& other.mXmlId == this.mXmlId
|
|
|
|
&& other.mColorScheme == this.mColorScheme
|
2011-06-17 09:25:54 +00:00
|
|
|
&& other.mNavigateAction == this.mNavigateAction
|
2011-02-20 03:54:14 +00:00
|
|
|
&& other.mPasswordInput == this.mPasswordInput
|
2010-12-02 09:46:21 +00:00
|
|
|
&& other.mHasSettingsKey == this.mHasSettingsKey
|
|
|
|
&& other.mVoiceKeyEnabled == this.mVoiceKeyEnabled
|
|
|
|
&& other.mHasVoiceKey == this.mHasVoiceKey
|
2011-02-18 05:16:29 +00:00
|
|
|
&& other.mImeAction == this.mImeAction
|
2010-12-02 09:46:21 +00:00
|
|
|
&& other.mEnableShiftLock == this.mEnableShiftLock;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int hashCode() {
|
|
|
|
return mHashCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
2011-05-30 11:05:50 +00:00
|
|
|
return String.format("[%s.xml %s %s%d %s %s %s%s%s%s%s%s%s]",
|
2010-12-14 06:31:47 +00:00
|
|
|
mXmlName,
|
2010-12-02 09:46:21 +00:00
|
|
|
mLocale,
|
2011-05-17 10:02:32 +00:00
|
|
|
(mOrientation == 1 ? "port" : "land"), mWidth,
|
2010-12-02 09:46:21 +00:00
|
|
|
modeName(mMode),
|
2011-03-25 19:40:57 +00:00
|
|
|
EditorInfoCompatUtils.imeOptionsName(mImeAction),
|
2011-05-27 12:41:13 +00:00
|
|
|
colorSchemeName(mColorScheme),
|
2011-06-17 09:25:54 +00:00
|
|
|
(mNavigateAction ? " navigateAction" : ""),
|
2011-02-20 03:54:14 +00:00
|
|
|
(mPasswordInput ? " passwordInput" : ""),
|
2010-12-02 09:46:21 +00:00
|
|
|
(mHasSettingsKey ? " hasSettingsKey" : ""),
|
|
|
|
(mVoiceKeyEnabled ? " voiceKeyEnabled" : ""),
|
|
|
|
(mHasVoiceKey ? " hasVoiceKey" : ""),
|
2011-05-27 12:41:13 +00:00
|
|
|
(mEnableShiftLock ? " enableShiftLock" : "")
|
2011-02-20 03:54:14 +00:00
|
|
|
);
|
2010-12-02 09:46:21 +00:00
|
|
|
}
|
|
|
|
|
2010-12-14 06:31:47 +00:00
|
|
|
public static String modeName(int mode) {
|
2010-12-02 09:46:21 +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_PHONE: return "phone";
|
|
|
|
case MODE_NUMBER: return "number";
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2010-12-14 06:31:47 +00:00
|
|
|
public static String colorSchemeName(int colorScheme) {
|
2010-12-02 09:46:21 +00:00
|
|
|
switch (colorScheme) {
|
|
|
|
case KeyboardView.COLOR_SCHEME_WHITE: return "white";
|
|
|
|
case KeyboardView.COLOR_SCHEME_BLACK: return "black";
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|