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;
|
|
|
|
|
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;
|
2013-06-23 16:11:32 +00:00
|
|
|
import com.android.inputmethod.latin.utils.InputTypeUtils;
|
2013-07-24 01:37:07 +00:00
|
|
|
import com.android.inputmethod.latin.utils.SubtypeLocaleUtils;
|
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;
|
2013-09-04 03:57:04 +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;
|
2013-08-26 03:27:38 +00:00
|
|
|
public static final int ELEMENT_EMOJI_RECENTS = 10;
|
|
|
|
public static final int ELEMENT_EMOJI_CATEGORY1 = 11;
|
|
|
|
public static final int ELEMENT_EMOJI_CATEGORY2 = 12;
|
|
|
|
public static final int ELEMENT_EMOJI_CATEGORY3 = 13;
|
|
|
|
public static final int ELEMENT_EMOJI_CATEGORY4 = 14;
|
|
|
|
public static final int ELEMENT_EMOJI_CATEGORY5 = 15;
|
|
|
|
public static final int ELEMENT_EMOJI_CATEGORY6 = 16;
|
2011-12-13 08:30:51 +00:00
|
|
|
|
2012-04-11 09:21:10 +00:00
|
|
|
public final InputMethodSubtype mSubtype;
|
2010-12-02 09:46:21 +00:00
|
|
|
public final Locale mLocale;
|
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;
|
2014-04-25 21:56:30 +00:00
|
|
|
public final EditorInfo mEditorInfo;
|
2011-06-23 12:55:56 +00:00
|
|
|
public final boolean mClobberSettingsKey;
|
2013-12-13 08:09:16 +00:00
|
|
|
public final boolean mSupportsSwitchingToShortcutIme;
|
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;
|
2013-07-24 01:37:07 +00:00
|
|
|
mLocale = SubtypeLocaleUtils.getSubtypeLocale(mSubtype);
|
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;
|
2013-12-13 08:09:16 +00:00
|
|
|
mSupportsSwitchingToShortcutIme = params.mSupportsSwitchingToShortcutIme;
|
2012-12-11 03:46:23 +00:00
|
|
|
mLanguageSwitchKeyEnabled = params.mLanguageSwitchKeyEnabled;
|
|
|
|
mCustomActionLabel = (mEditorInfo.actionLabel != null)
|
|
|
|
? mEditorInfo.actionLabel.toString() : null;
|
2013-12-13 08:09:16 +00:00
|
|
|
mHasShortcutKey = mSupportsSwitchingToShortcutIme && params.mShowsVoiceInputKey;
|
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[] {
|
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,
|
2013-12-13 08:09:16 +00:00
|
|
|
id.mSupportsSwitchingToShortcutIme,
|
|
|
|
id.mHasShortcutKey,
|
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-08-07 07:03:57 +00:00
|
|
|
return other.mElementId == mElementId
|
2012-03-22 09:09:19 +00:00
|
|
|
&& 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
|
2013-12-13 08:09:16 +00:00
|
|
|
&& other.mSupportsSwitchingToShortcutIme == mSupportsSwitchingToShortcutIme
|
|
|
|
&& other.mHasShortcutKey == mHasShortcutKey
|
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-12-13 08:09:16 +00:00
|
|
|
return String.format(Locale.ROOT, "[%s %s:%s %dx%d %s %s%s%s%s%s%s%s%s%s]",
|
2012-01-24 09:03:50 +00:00
|
|
|
elementIdToName(mElementId),
|
2013-08-07 07:03:57 +00:00
|
|
|
mLocale, mSubtype.getExtraValueOf(KEYBOARD_LAYOUT_SET),
|
|
|
|
mWidth, mHeight,
|
2010-12-02 09:46:21 +00:00
|
|
|
modeName(mMode),
|
2013-12-13 08:09:16 +00:00
|
|
|
actionName(imeAction()),
|
|
|
|
(navigateNext() ? " navigateNext" : ""),
|
|
|
|
(navigatePrevious() ? " navigatePrevious" : ""),
|
2011-06-23 12:55:56 +00:00
|
|
|
(mClobberSettingsKey ? " clobberSettingsKey" : ""),
|
2011-12-13 13:53:54 +00:00
|
|
|
(passwordInput() ? " passwordInput" : ""),
|
2013-12-13 08:09:16 +00:00
|
|
|
(mSupportsSwitchingToShortcutIme ? " supportsSwitchingToShortcutIme" : ""),
|
2012-02-17 07:14:14 +00:00
|
|
|
(mHasShortcutKey ? " hasShortcutKey" : ""),
|
2012-02-18 01:46:01 +00:00
|
|
|
(mLanguageSwitchKeyEnabled ? " languageSwitchKeyEnabled" : ""),
|
2013-12-13 08:09:16 +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";
|
2013-09-04 03:57:04 +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";
|
2013-08-26 03:27:38 +00:00
|
|
|
case ELEMENT_EMOJI_RECENTS: return "emojiRecents";
|
|
|
|
case ELEMENT_EMOJI_CATEGORY1: return "emojiCategory1";
|
|
|
|
case ELEMENT_EMOJI_CATEGORY2: return "emojiCategory2";
|
|
|
|
case ELEMENT_EMOJI_CATEGORY3: return "emojiCategory3";
|
|
|
|
case ELEMENT_EMOJI_CATEGORY4: return "emojiCategory4";
|
|
|
|
case ELEMENT_EMOJI_CATEGORY5: return "emojiCategory5";
|
|
|
|
case ELEMENT_EMOJI_CATEGORY6: return "emojiCategory6";
|
2011-12-13 08:30:51 +00:00
|
|
|
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
|
|
|
}
|