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;
|
|
|
|
|
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;
|
|
|
|
|
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 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
|
|
|
*/
|
|
|
|
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;
|
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-02-07 08:07:23 +00:00
|
|
|
private static final int IME_ACTION_CUSTOM_LABEL = EditorInfo.IME_MASK_ACTION + 1;
|
|
|
|
|
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;
|
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;
|
|
|
|
public final boolean mHasShortcutKey;
|
2012-02-07 08:07:23 +00:00
|
|
|
public final String mCustomActionLabel;
|
2010-12-02 09:46:21 +00:00
|
|
|
|
|
|
|
private final int mHashCode;
|
|
|
|
|
2012-01-24 09:03:50 +00:00
|
|
|
public KeyboardId(int elementId, Locale locale, int orientation, int width, int mode,
|
2012-02-17 00:24:03 +00:00
|
|
|
EditorInfo editorInfo, boolean clobberSettingsKey, boolean shortcutKeyEnabled,
|
|
|
|
boolean hasShortcutKey) {
|
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;
|
2012-01-24 09:03:50 +00:00
|
|
|
this.mElementId = elementId;
|
2012-02-07 08:07:23 +00:00
|
|
|
this.mEditorInfo = editorInfo;
|
2011-06-23 12:55:56 +00:00
|
|
|
this.mClobberSettingsKey = clobberSettingsKey;
|
2011-08-01 01:34:54 +00:00
|
|
|
this.mShortcutKeyEnabled = shortcutKeyEnabled;
|
|
|
|
this.mHasShortcutKey = hasShortcutKey;
|
2012-02-07 08:07:23 +00:00
|
|
|
this.mCustomActionLabel = (editorInfo.actionLabel != null)
|
|
|
|
? editorInfo.actionLabel.toString() : null;
|
2010-12-02 09:46:21 +00:00
|
|
|
|
2011-12-13 13:43:04 +00:00
|
|
|
this.mHashCode = hashCode(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static int hashCode(KeyboardId id) {
|
|
|
|
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,
|
2011-12-13 13:53:54 +00:00
|
|
|
id.passwordInput(),
|
2011-12-13 13:43:04 +00:00
|
|
|
id.mClobberSettingsKey,
|
|
|
|
id.mShortcutKeyEnabled,
|
|
|
|
id.mHasShortcutKey,
|
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(),
|
2011-12-13 13:53:54 +00:00
|
|
|
id.mLocale
|
2010-12-02 09:46:21 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-12-13 13:43:04 +00:00
|
|
|
private boolean equals(KeyboardId other) {
|
|
|
|
if (other == this)
|
|
|
|
return true;
|
|
|
|
return other.mOrientation == this.mOrientation
|
2012-01-24 09:03:50 +00:00
|
|
|
&& other.mElementId == this.mElementId
|
2011-12-13 13:43:04 +00:00
|
|
|
&& other.mMode == this.mMode
|
|
|
|
&& other.mWidth == this.mWidth
|
2011-12-13 13:53:54 +00:00
|
|
|
&& other.passwordInput() == this.passwordInput()
|
2011-12-13 13:43:04 +00:00
|
|
|
&& other.mClobberSettingsKey == this.mClobberSettingsKey
|
|
|
|
&& other.mShortcutKeyEnabled == this.mShortcutKeyEnabled
|
|
|
|
&& other.mHasShortcutKey == this.mHasShortcutKey
|
2012-02-07 08:07:23 +00:00
|
|
|
&& other.isMultiLine() == this.isMultiLine()
|
2011-12-13 13:53:54 +00:00
|
|
|
&& other.imeAction() == this.imeAction()
|
2012-02-08 11:09:39 +00:00
|
|
|
&& TextUtils.equals(other.mCustomActionLabel, this.mCustomActionLabel)
|
2012-02-17 07:14:14 +00:00
|
|
|
&& other.navigateNext() == this.navigateNext()
|
|
|
|
&& other.navigatePrevious() == this.navigatePrevious()
|
2011-12-13 13:43:04 +00:00
|
|
|
&& other.mLocale.equals(this.mLocale);
|
|
|
|
}
|
|
|
|
|
2010-12-02 11:54:32 +00:00
|
|
|
public boolean isAlphabetKeyboard() {
|
2012-01-24 09:03:50 +00:00
|
|
|
return mElementId < ELEMENT_SYMBOLS;
|
2010-12-02 09:46:21 +00:00
|
|
|
}
|
|
|
|
|
2012-02-17 07:14:14 +00:00
|
|
|
public boolean navigateNext() {
|
|
|
|
return EditorInfoCompatUtils.hasFlagNavigateNext(mEditorInfo.imeOptions);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean navigatePrevious() {
|
|
|
|
return EditorInfoCompatUtils.hasFlagNavigatePrevious(mEditorInfo.imeOptions);
|
2011-12-13 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean passwordInput() {
|
2012-02-07 08:07:23 +00:00
|
|
|
final int inputType = mEditorInfo.inputType;
|
|
|
|
return InputTypeCompatUtils.isPasswordInputType(inputType)
|
|
|
|
|| InputTypeCompatUtils.isVisiblePasswordInputType(inputType);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isMultiLine() {
|
|
|
|
return (mEditorInfo.inputType & InputType.TYPE_TEXT_FLAG_MULTI_LINE) != 0;
|
2011-12-13 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public int imeAction() {
|
2012-02-17 07:14:14 +00:00
|
|
|
final int actionId = mEditorInfo.imeOptions & EditorInfo.IME_MASK_ACTION;
|
2012-02-07 08:07:23 +00:00
|
|
|
if ((mEditorInfo.imeOptions & EditorInfo.IME_FLAG_NO_ENTER_ACTION) != 0) {
|
|
|
|
return EditorInfo.IME_ACTION_NONE;
|
|
|
|
} else if (mEditorInfo.actionLabel != null) {
|
|
|
|
return IME_ACTION_CUSTOM_LABEL;
|
|
|
|
} else {
|
2012-02-17 07:14:14 +00:00
|
|
|
return actionId;
|
2012-02-07 08:07:23 +00:00
|
|
|
}
|
2011-12-13 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
2012-02-17 07:14:14 +00:00
|
|
|
public int imeActionId() {
|
|
|
|
final int actionId = imeAction();
|
|
|
|
return actionId == IME_ACTION_CUSTOM_LABEL ? mEditorInfo.actionId : actionId;
|
|
|
|
}
|
|
|
|
|
2010-12-02 09:46:21 +00:00
|
|
|
@Override
|
|
|
|
public boolean equals(Object other) {
|
|
|
|
return other instanceof KeyboardId && equals((KeyboardId) other);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int hashCode() {
|
|
|
|
return mHashCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
2012-02-17 07:14:14 +00:00
|
|
|
return String.format("[%s %s %s%d %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,
|
2011-05-17 10:02:32 +00:00
|
|
|
(mOrientation == 1 ? "port" : "land"), mWidth,
|
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-02-17 07:14:14 +00:00
|
|
|
(mHasShortcutKey ? " hasShortcutKey" : ""),
|
|
|
|
(isMultiLine() ? "isMultiLine" : "")
|
2011-02-20 03:54:14 +00:00
|
|
|
);
|
2010-12-02 09:46:21 +00:00
|
|
|
}
|
|
|
|
|
2011-12-07 12:27:59 +00:00
|
|
|
public static boolean equivalentEditorInfoForKeyboard(EditorInfo a, EditorInfo b) {
|
|
|
|
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-01-24 09:03:50 +00:00
|
|
|
public static String elementIdToName(int elementId) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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";
|
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-02-07 08:07:23 +00:00
|
|
|
public static String actionName(int actionId) {
|
|
|
|
return (actionId == IME_ACTION_CUSTOM_LABEL) ? "actionCustomLabel"
|
|
|
|
: EditorInfoCompatUtils.imeActionName(actionId);
|
|
|
|
}
|
2010-12-02 09:46:21 +00:00
|
|
|
}
|