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
|
|
|
*
|
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 09:46:21 +00:00
|
|
|
*
|
2013-01-21 12:52:57 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2010-12-02 09:46:21 +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.
|
2010-12-02 09:46:21 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
package com.android.inputmethod.keyboard;
|
|
|
|
|
2012-04-19 03:42:13 +00:00
|
|
|
import static com.android.inputmethod.latin.Constants.Subtype.ExtraValue.KEYBOARD_LAYOUT_SET;
|
|
|
|
|
2013-01-29 07:11:52 +00:00
|
|
|
import android.content.res.Configuration;
|
2012-02-07 08:07:23 +00:00
|
|
|
import android.text.InputType;
|
2011-12-07 12:27:59 +00:00
|
|
|
import android.text.TextUtils;
|
2011-06-17 11:55:46 +00:00
|
|
|
import android.view.inputmethod.EditorInfo;
|
2012-04-11 09:21:10 +00:00
|
|
|
import android.view.inputmethod.InputMethodSubtype;
|
2011-06-17 11:55:46 +00:00
|
|
|
|
2011-03-25 19:40:57 +00:00
|
|
|
import com.android.inputmethod.compat.EditorInfoCompatUtils;
|
2012-04-11 09:21:10 +00:00
|
|
|
import com.android.inputmethod.latin.SubtypeLocale;
|
2013-06-23 16:11:32 +00:00
|
|
|
import com.android.inputmethod.latin.utils.InputTypeUtils;
|
2010-12-02 09:46:21 +00:00
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Locale;
|
|
|
|
|
|
|
|
/**
|
2012-02-07 08:07:23 +00:00
|
|
|
* Unique identifier for each keyboard type.
|
2010-12-02 09:46:21 +00:00
|
|
|
*/
|
2012-09-27 09:16:16 +00:00
|
|
|
public final class KeyboardId {
|
2010-12-02 09:46:21 +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;
|
2011-05-27 12:41:13 +00:00
|
|
|
public static final int MODE_PHONE = 4;
|
|
|
|
public static final int MODE_NUMBER = 5;
|
2012-02-27 07:16:24 +00:00
|
|
|
public static final int MODE_DATE = 6;
|
|
|
|
public static final int MODE_TIME = 7;
|
|
|
|
public static final int MODE_DATETIME = 8;
|
2010-12-02 09:46:21 +00:00
|
|
|
|
2011-12-13 08:30:51 +00:00
|
|
|
public static final int ELEMENT_ALPHABET = 0;
|
2012-01-24 09:03:50 +00:00
|
|
|
public static final int ELEMENT_ALPHABET_MANUAL_SHIFTED = 1;
|
|
|
|
public static final int ELEMENT_ALPHABET_AUTOMATIC_SHIFTED = 2;
|
|
|
|
public static final int ELEMENT_ALPHABET_SHIFT_LOCKED = 3;
|
|
|
|
public static final int ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED = 4;
|
2011-12-13 08:30:51 +00:00
|
|
|
public static final int ELEMENT_SYMBOLS = 5;
|
2012-01-24 09:03:50 +00:00
|
|
|
public static final int ELEMENT_SYMBOLS_SHIFTED = 6;
|
2011-12-13 08:30:51 +00:00
|
|
|
public static final int ELEMENT_PHONE = 7;
|
2012-02-01 06:07:25 +00:00
|
|
|
public static final int ELEMENT_PHONE_SYMBOLS = 8;
|
2011-12-13 08:30:51 +00:00
|
|
|
public static final int ELEMENT_NUMBER = 9;
|
|
|
|
|
2012-04-11 09:21:10 +00:00
|
|
|
public final InputMethodSubtype mSubtype;
|
2010-12-02 09:46:21 +00:00
|
|
|
public final Locale mLocale;
|
2013-01-29 07:11:52 +00:00
|
|
|
// TODO: Remove this member. It is used only for logging purpose.
|
2010-12-02 09:46:21 +00:00
|
|
|
public final int mOrientation;
|
2011-05-17 10:02:32 +00:00
|
|
|
public final int mWidth;
|
2013-01-29 07:11:52 +00:00
|
|
|
public final int mHeight;
|
2010-12-02 09:46:21 +00:00
|
|
|
public final int mMode;
|
2012-01-24 09:03:50 +00:00
|
|
|
public final int mElementId;
|
2012-02-07 08:07:23 +00:00
|
|
|
private final EditorInfo mEditorInfo;
|
2011-06-23 12:55:56 +00:00
|
|
|
public final boolean mClobberSettingsKey;
|
2011-08-01 01:34:54 +00:00
|
|
|
public final boolean mShortcutKeyEnabled;
|
2012-12-11 03:46:23 +00:00
|
|
|
public final boolean mShortcutKeyOnSymbols;
|
2012-02-18 01:46:01 +00:00
|
|
|
public final boolean mLanguageSwitchKeyEnabled;
|
2012-02-07 08:07:23 +00:00
|
|
|
public final String mCustomActionLabel;
|
2012-12-11 03:46:23 +00:00
|
|
|
public final boolean mHasShortcutKey;
|
2010-12-02 09:46:21 +00:00
|
|
|
|
|
|
|
private final int mHashCode;
|
|
|
|
|
2012-12-11 03:46:23 +00:00
|
|
|
public KeyboardId(final int elementId, final KeyboardLayoutSet.Params params) {
|
|
|
|
mSubtype = params.mSubtype;
|
|
|
|
mLocale = SubtypeLocale.getSubtypeLocale(mSubtype);
|
|
|
|
mOrientation = params.mOrientation;
|
2013-01-29 07:11:52 +00:00
|
|
|
mWidth = params.mKeyboardWidth;
|
|
|
|
mHeight = params.mKeyboardHeight;
|
2012-12-11 03:46:23 +00:00
|
|
|
mMode = params.mMode;
|
2012-03-22 09:09:19 +00:00
|
|
|
mElementId = elementId;
|
2012-12-11 03:46:23 +00:00
|
|
|
mEditorInfo = params.mEditorInfo;
|
|
|
|
mClobberSettingsKey = params.mNoSettingsKey;
|
|
|
|
mShortcutKeyEnabled = params.mVoiceKeyEnabled;
|
|
|
|
mShortcutKeyOnSymbols = mShortcutKeyEnabled && !params.mVoiceKeyOnMain;
|
|
|
|
mLanguageSwitchKeyEnabled = params.mLanguageSwitchKeyEnabled;
|
|
|
|
mCustomActionLabel = (mEditorInfo.actionLabel != null)
|
|
|
|
? mEditorInfo.actionLabel.toString() : null;
|
|
|
|
final boolean alphabetMayHaveShortcutKey = isAlphabetKeyboard(elementId)
|
|
|
|
&& !mShortcutKeyOnSymbols;
|
|
|
|
final boolean symbolsMayHaveShortcutKey = (elementId == KeyboardId.ELEMENT_SYMBOLS)
|
|
|
|
&& mShortcutKeyOnSymbols;
|
|
|
|
mHasShortcutKey = mShortcutKeyEnabled
|
|
|
|
&& (alphabetMayHaveShortcutKey || symbolsMayHaveShortcutKey);
|
2010-12-02 09:46:21 +00:00
|
|
|
|
2012-03-22 09:09:19 +00:00
|
|
|
mHashCode = computeHashCode(this);
|
2011-12-13 13:43:04 +00:00
|
|
|
}
|
|
|
|
|
2012-12-11 03:46:23 +00:00
|
|
|
private static int computeHashCode(final KeyboardId id) {
|
2011-12-13 13:43:04 +00:00
|
|
|
return Arrays.hashCode(new Object[] {
|
|
|
|
id.mOrientation,
|
2012-01-24 09:03:50 +00:00
|
|
|
id.mElementId,
|
2011-12-13 13:43:04 +00:00
|
|
|
id.mMode,
|
|
|
|
id.mWidth,
|
2013-01-29 07:11:52 +00:00
|
|
|
id.mHeight,
|
2011-12-13 13:53:54 +00:00
|
|
|
id.passwordInput(),
|
2011-12-13 13:43:04 +00:00
|
|
|
id.mClobberSettingsKey,
|
|
|
|
id.mShortcutKeyEnabled,
|
2012-12-11 03:46:23 +00:00
|
|
|
id.mShortcutKeyOnSymbols,
|
2012-02-18 01:46:01 +00:00
|
|
|
id.mLanguageSwitchKeyEnabled,
|
2012-02-07 08:07:23 +00:00
|
|
|
id.isMultiLine(),
|
2011-12-13 13:53:54 +00:00
|
|
|
id.imeAction(),
|
2012-02-08 11:09:39 +00:00
|
|
|
id.mCustomActionLabel,
|
2012-02-17 07:14:14 +00:00
|
|
|
id.navigateNext(),
|
|
|
|
id.navigatePrevious(),
|
2012-04-11 09:21:10 +00:00
|
|
|
id.mSubtype
|
2010-12-02 09:46:21 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-12-11 03:46:23 +00:00
|
|
|
private boolean equals(final KeyboardId other) {
|
2011-12-13 13:43:04 +00:00
|
|
|
if (other == this)
|
|
|
|
return true;
|
2013-05-07 09:52:22 +00:00
|
|
|
return other.mOrientation == mOrientation
|
2012-03-22 09:09:19 +00:00
|
|
|
&& other.mElementId == mElementId
|
|
|
|
&& other.mMode == mMode
|
|
|
|
&& other.mWidth == mWidth
|
2013-01-29 07:11:52 +00:00
|
|
|
&& other.mHeight == mHeight
|
2012-03-22 09:09:19 +00:00
|
|
|
&& other.passwordInput() == passwordInput()
|
|
|
|
&& other.mClobberSettingsKey == mClobberSettingsKey
|
|
|
|
&& other.mShortcutKeyEnabled == mShortcutKeyEnabled
|
2012-12-11 03:46:23 +00:00
|
|
|
&& other.mShortcutKeyOnSymbols == mShortcutKeyOnSymbols
|
2012-03-22 09:09:19 +00:00
|
|
|
&& other.mLanguageSwitchKeyEnabled == mLanguageSwitchKeyEnabled
|
|
|
|
&& other.isMultiLine() == isMultiLine()
|
|
|
|
&& other.imeAction() == imeAction()
|
|
|
|
&& TextUtils.equals(other.mCustomActionLabel, mCustomActionLabel)
|
|
|
|
&& other.navigateNext() == navigateNext()
|
|
|
|
&& other.navigatePrevious() == navigatePrevious()
|
2012-04-11 09:21:10 +00:00
|
|
|
&& other.mSubtype.equals(mSubtype);
|
2011-12-13 13:43:04 +00:00
|
|
|
}
|
|
|
|
|
2012-12-11 03:46:23 +00:00
|
|
|
private static boolean isAlphabetKeyboard(final int elementId) {
|
|
|
|
return elementId < ELEMENT_SYMBOLS;
|
|
|
|
}
|
|
|
|
|
2010-12-02 11:54:32 +00:00
|
|
|
public boolean isAlphabetKeyboard() {
|
2012-12-11 03:46:23 +00:00
|
|
|
return isAlphabetKeyboard(mElementId);
|
2010-12-02 09:46:21 +00:00
|
|
|
}
|
|
|
|
|
2012-02-17 07:14:14 +00:00
|
|
|
public boolean navigateNext() {
|
2012-07-05 05:50:10 +00:00
|
|
|
return (mEditorInfo.imeOptions & EditorInfo.IME_FLAG_NAVIGATE_NEXT) != 0
|
|
|
|
|| imeAction() == EditorInfo.IME_ACTION_NEXT;
|
2012-02-17 07:14:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean navigatePrevious() {
|
2012-07-05 05:50:10 +00:00
|
|
|
return (mEditorInfo.imeOptions & EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS) != 0
|
|
|
|
|| imeAction() == EditorInfo.IME_ACTION_PREVIOUS;
|
2011-12-13 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean passwordInput() {
|
2012-02-07 08:07:23 +00:00
|
|
|
final int inputType = mEditorInfo.inputType;
|
2012-04-02 13:43:38 +00:00
|
|
|
return InputTypeUtils.isPasswordInputType(inputType)
|
|
|
|
|| InputTypeUtils.isVisiblePasswordInputType(inputType);
|
2012-02-07 08:07:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isMultiLine() {
|
|
|
|
return (mEditorInfo.inputType & InputType.TYPE_TEXT_FLAG_MULTI_LINE) != 0;
|
2011-12-13 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public int imeAction() {
|
2013-01-15 08:56:37 +00:00
|
|
|
return InputTypeUtils.getImeOptionsActionIdFromEditorInfo(mEditorInfo);
|
2012-02-17 07:14:14 +00:00
|
|
|
}
|
|
|
|
|
2010-12-02 09:46:21 +00:00
|
|
|
@Override
|
2012-12-11 03:46:23 +00:00
|
|
|
public boolean equals(final Object other) {
|
2010-12-02 09:46:21 +00:00
|
|
|
return other instanceof KeyboardId && equals((KeyboardId) other);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int hashCode() {
|
|
|
|
return mHashCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
2013-01-29 07:11:52 +00:00
|
|
|
final String orientation = (mOrientation == Configuration.ORIENTATION_PORTRAIT)
|
|
|
|
? "port" : "land";
|
2013-05-24 19:06:02 +00:00
|
|
|
return String.format(Locale.ROOT, "[%s %s:%s %s:%dx%d %s %s %s%s%s%s%s%s%s%s%s]",
|
2012-01-24 09:03:50 +00:00
|
|
|
elementIdToName(mElementId),
|
2010-12-02 09:46:21 +00:00
|
|
|
mLocale,
|
2012-04-19 03:42:13 +00:00
|
|
|
mSubtype.getExtraValueOf(KEYBOARD_LAYOUT_SET),
|
2013-05-07 09:52:22 +00:00
|
|
|
orientation, mWidth, mHeight,
|
2010-12-02 09:46:21 +00:00
|
|
|
modeName(mMode),
|
2012-02-07 08:07:23 +00:00
|
|
|
imeAction(),
|
2012-02-17 07:14:14 +00:00
|
|
|
(navigateNext() ? "navigateNext" : ""),
|
|
|
|
(navigatePrevious() ? "navigatePrevious" : ""),
|
2011-06-23 12:55:56 +00:00
|
|
|
(mClobberSettingsKey ? " clobberSettingsKey" : ""),
|
2011-12-13 13:53:54 +00:00
|
|
|
(passwordInput() ? " passwordInput" : ""),
|
2011-08-01 01:34:54 +00:00
|
|
|
(mShortcutKeyEnabled ? " shortcutKeyEnabled" : ""),
|
2012-12-11 03:46:23 +00:00
|
|
|
(mShortcutKeyOnSymbols ? " shortcutKeyOnSymbols" : ""),
|
2012-02-17 07:14:14 +00:00
|
|
|
(mHasShortcutKey ? " hasShortcutKey" : ""),
|
2012-02-18 01:46:01 +00:00
|
|
|
(mLanguageSwitchKeyEnabled ? " languageSwitchKeyEnabled" : ""),
|
2012-02-17 07:14:14 +00:00
|
|
|
(isMultiLine() ? "isMultiLine" : "")
|
2011-02-20 03:54:14 +00:00
|
|
|
);
|
2010-12-02 09:46:21 +00:00
|
|
|
}
|
|
|
|
|
2012-12-11 03:46:23 +00:00
|
|
|
public static boolean equivalentEditorInfoForKeyboard(final EditorInfo a, final EditorInfo b) {
|
2011-12-07 12:27:59 +00:00
|
|
|
if (a == null && b == null) return true;
|
|
|
|
if (a == null || b == null) return false;
|
|
|
|
return a.inputType == b.inputType
|
|
|
|
&& a.imeOptions == b.imeOptions
|
|
|
|
&& TextUtils.equals(a.privateImeOptions, b.privateImeOptions);
|
|
|
|
}
|
|
|
|
|
2012-12-11 03:46:23 +00:00
|
|
|
public static String elementIdToName(final int elementId) {
|
2012-01-24 09:03:50 +00:00
|
|
|
switch (elementId) {
|
2011-12-13 08:30:51 +00:00
|
|
|
case ELEMENT_ALPHABET: return "alphabet";
|
2012-01-24 09:03:50 +00:00
|
|
|
case ELEMENT_ALPHABET_MANUAL_SHIFTED: return "alphabetManualShifted";
|
|
|
|
case ELEMENT_ALPHABET_AUTOMATIC_SHIFTED: return "alphabetAutomaticShifted";
|
|
|
|
case ELEMENT_ALPHABET_SHIFT_LOCKED: return "alphabetShiftLocked";
|
|
|
|
case ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED: return "alphabetShiftLockShifted";
|
2011-12-13 08:30:51 +00:00
|
|
|
case ELEMENT_SYMBOLS: return "symbols";
|
2012-01-24 09:03:50 +00:00
|
|
|
case ELEMENT_SYMBOLS_SHIFTED: return "symbolsShifted";
|
2011-12-13 08:30:51 +00:00
|
|
|
case ELEMENT_PHONE: return "phone";
|
2012-02-01 06:07:25 +00:00
|
|
|
case ELEMENT_PHONE_SYMBOLS: return "phoneSymbols";
|
2011-12-13 08:30:51 +00:00
|
|
|
case ELEMENT_NUMBER: return "number";
|
|
|
|
default: return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-11 03:46:23 +00:00
|
|
|
public static String modeName(final 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";
|
2012-02-27 07:16:24 +00:00
|
|
|
case MODE_DATE: return "date";
|
|
|
|
case MODE_TIME: return "time";
|
|
|
|
case MODE_DATETIME: return "datetime";
|
2011-06-23 12:55:56 +00:00
|
|
|
default: return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-11 03:46:23 +00:00
|
|
|
public static String actionName(final int actionId) {
|
2013-01-09 12:58:32 +00:00
|
|
|
return (actionId == InputTypeUtils.IME_ACTION_CUSTOM_LABEL) ? "actionCustomLabel"
|
2012-02-07 08:07:23 +00:00
|
|
|
: EditorInfoCompatUtils.imeActionName(actionId);
|
|
|
|
}
|
2010-12-02 09:46:21 +00:00
|
|
|
}
|