Merge "Remove enableShiftLock attribute from KeyboardId"

main
Tadashi G. Takaoka 2011-07-28 17:38:50 -07:00 committed by Android (Google) Code Review
commit 5b3c834a9c
6 changed files with 46 additions and 65 deletions

View File

@ -325,6 +325,13 @@ public class Key {
keyAttr, R.styleable.Keyboard_Key_keyIcon,
KeyboardIconsSet.ICON_UNDEFINED));
Keyboard.setDefaultBounds(mIcon);
final int shiftedIconId = style.getInt(keyAttr, R.styleable.Keyboard_Key_keyIconShifted,
KeyboardIconsSet.ICON_UNDEFINED);
if (shiftedIconId != KeyboardIconsSet.ICON_UNDEFINED) {
final Drawable shiftedIcon = iconsSet.getIcon(shiftedIconId);
Keyboard.setDefaultBounds(shiftedIcon);
mKeyboard.addShiftedIcon(this, shiftedIcon);
}
mHintLabel = style.getText(keyAttr, R.styleable.Keyboard_Key_keyHintLabel);
mLabel = style.getText(keyAttr, R.styleable.Keyboard_Key_keyLabel);
@ -342,12 +349,9 @@ public class Key {
} else {
mCode = Keyboard.CODE_DUMMY;
}
final Drawable shiftedIcon = iconsSet.getIcon(style.getInt(
keyAttr, R.styleable.Keyboard_Key_keyIconShifted,
KeyboardIconsSet.ICON_UNDEFINED));
if (shiftedIcon != null)
mKeyboard.getShiftedIcons().put(this, shiftedIcon);
if (mCode == Keyboard.CODE_SHIFT) {
mKeyboard.addShiftKey(this);
}
} finally {
keyAttr.recycle();
}

View File

@ -34,7 +34,6 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
/**
* Loads an XML description of a keyboard and stores the attributes of the keys. A keyboard
@ -118,8 +117,8 @@ public class Keyboard {
/** List of shift keys in this keyboard and its icons and state */
private final List<Key> mShiftKeys = new ArrayList<Key>();
private final HashMap<Key, Drawable> mShiftedIcons = new HashMap<Key, Drawable>();
private final HashMap<Key, Drawable> mNormalShiftIcons = new HashMap<Key, Drawable>();
private final HashSet<Key> mShiftLockEnabled = new HashSet<Key>();
private final HashMap<Key, Drawable> mUnshiftedIcons = new HashMap<Key, Drawable>();
private final HashSet<Key> mShiftLockKeys = new HashSet<Key>();
private final KeyboardShiftState mShiftState = new KeyboardShiftState();
/** Total height of the keyboard, including the padding and keys */
@ -286,30 +285,35 @@ public class Keyboard {
mMaxPopupColumn = column;
}
public List<Key> getShiftKeys() {
return mShiftKeys;
}
public Map<Key, Drawable> getShiftedIcons() {
return mShiftedIcons;
}
public void enableShiftLock() {
for (final Key key : getShiftKeys()) {
mShiftLockEnabled.add(key);
mNormalShiftIcons.put(key, key.getIcon());
public void addShiftKey(Key key) {
if (key == null) return;
mShiftKeys.add(key);
if (key.mSticky) {
mShiftLockKeys.add(key);
}
}
public boolean isShiftLockEnabled(Key key) {
return mShiftLockEnabled.contains(key);
public void addShiftedIcon(Key key, Drawable icon) {
if (key == null) return;
mUnshiftedIcons.put(key, key.getIcon());
mShiftedIcons.put(key, icon);
}
public boolean hasShiftLockKey() {
return !mShiftLockKeys.isEmpty();
}
public boolean setShiftLocked(boolean newShiftLockState) {
final Map<Key, Drawable> shiftedIcons = getShiftedIcons();
for (final Key key : getShiftKeys()) {
for (final Key key : mShiftLockKeys) {
// To represent "shift locked" state. The highlight is handled by background image that
// might be a StateListDrawable.
key.setHighlightOn(newShiftLockState);
key.setIcon(newShiftLockState ? shiftedIcons.get(key) : mNormalShiftIcons.get(key));
// To represent "shifted" state. The key might have a shifted icon.
if (newShiftLockState && mShiftedIcons.containsKey(key)) {
key.setIcon(mShiftedIcons.get(key));
} else {
key.setIcon(mUnshiftedIcons.get(key));
}
}
mShiftState.setShiftLocked(newShiftLockState);
return true;
@ -320,12 +324,11 @@ public class Keyboard {
}
public boolean setShifted(boolean newShiftState) {
final Map<Key, Drawable> shiftedIcons = getShiftedIcons();
for (final Key key : getShiftKeys()) {
for (final Key key : mShiftKeys) {
if (!newShiftState && !mShiftState.isShiftLocked()) {
key.setIcon(mNormalShiftIcons.get(key));
key.setIcon(mUnshiftedIcons.get(key));
} else if (newShiftState && !mShiftState.isShiftedOrShiftLocked()) {
key.setIcon(shiftedIcons.get(key));
key.setIcon(mShiftedIcons.get(key));
}
}
return mShiftState.setShifted(newShiftState);

View File

@ -58,7 +58,6 @@ public class KeyboardId {
public final boolean mVoiceKeyEnabled;
public final boolean mHasVoiceKey;
public final int mImeAction;
public final boolean mEnableShiftLock;
public final String mXmlName;
public final EditorInfo mAttribute;
@ -67,8 +66,7 @@ public class KeyboardId {
public KeyboardId(String xmlName, int xmlId, Locale locale, int orientation, int width,
int mode, EditorInfo attribute, boolean hasSettingsKey, int f2KeyMode,
boolean clobberSettingsKey, boolean voiceKeyEnabled, boolean hasVoiceKey,
boolean enableShiftLock) {
boolean clobberSettingsKey, boolean voiceKeyEnabled, boolean hasVoiceKey) {
final int inputType = (attribute != null) ? attribute.inputType : 0;
final int imeOptions = (attribute != null) ? attribute.imeOptions : 0;
this.mLocale = locale;
@ -91,7 +89,6 @@ public class KeyboardId {
// {@link EditorInfo#IME_FLAG_NO_ENTER_ACTION}.
this.mImeAction = imeOptions & (
EditorInfo.IME_MASK_ACTION | EditorInfo.IME_FLAG_NO_ENTER_ACTION);
this.mEnableShiftLock = enableShiftLock;
this.mXmlName = xmlName;
this.mAttribute = attribute;
@ -110,21 +107,19 @@ public class KeyboardId {
voiceKeyEnabled,
hasVoiceKey,
mImeAction,
enableShiftLock,
});
}
public KeyboardId cloneAsMiniKeyboard() {
return new KeyboardId("mini popup keyboard", MINI_KEYBOARD_ID_MARKER, mLocale, mOrientation,
mWidth, mMode, mAttribute, false, F2KEY_MODE_NONE, false, false, false, false);
mWidth, mMode, mAttribute, false, F2KEY_MODE_NONE, false, false, false);
}
public KeyboardId cloneWithNewGeometry(int orientation, int width) {
if (mWidth == width)
return this;
return new KeyboardId(mXmlName, mXmlId, mLocale, orientation, width, mMode, mAttribute,
mHasSettingsKey, mF2KeyMode, mClobberSettingsKey, mVoiceKeyEnabled, mHasVoiceKey,
mEnableShiftLock);
mHasSettingsKey, mF2KeyMode, mClobberSettingsKey, mVoiceKeyEnabled, mHasVoiceKey);
}
public int getXmlId() {
@ -173,8 +168,7 @@ public class KeyboardId {
&& other.mClobberSettingsKey == this.mClobberSettingsKey
&& other.mVoiceKeyEnabled == this.mVoiceKeyEnabled
&& other.mHasVoiceKey == this.mHasVoiceKey
&& other.mImeAction == this.mImeAction
&& other.mEnableShiftLock == this.mEnableShiftLock;
&& other.mImeAction == this.mImeAction;
}
@Override
@ -184,7 +178,7 @@ public class KeyboardId {
@Override
public String toString() {
return String.format("[%s.xml %s %s%d %s %s %s%s%s%s%s%s%s%s]",
return String.format("[%s.xml %s %s%d %s %s %s%s%s%s%s%s%s]",
mXmlName,
mLocale,
(mOrientation == 1 ? "port" : "land"), mWidth,
@ -196,8 +190,7 @@ public class KeyboardId {
(mPasswordInput ? " passwordInput" : ""),
(mHasSettingsKey ? " hasSettingsKey" : ""),
(mVoiceKeyEnabled ? " voiceKeyEnabled" : ""),
(mHasVoiceKey ? " hasVoiceKey" : ""),
(mEnableShiftLock ? " enableShiftLock" : "")
(mHasVoiceKey ? " hasVoiceKey" : "")
);
}

View File

@ -205,11 +205,6 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
mSubtypeSwitcher.getInputLocale());
keyboard = new LatinKeyboard(mThemeContext, id, id.mWidth);
if (id.mEnableShiftLock) {
keyboard.enableShiftLock();
}
mKeyboardCache.put(id, new SoftReference<LatinKeyboard>(keyboard));
if (DEBUG_CACHE)
Log.d(TAG, "keyboard cache size=" + mKeyboardCache.size() + ": "
@ -242,16 +237,13 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
final int mode = Utils.getKeyboardMode(attribute);
final boolean hasVoiceKey = voiceKeyEnabled && (isSymbols != voiceKeyOnMain);
final int xmlId;
final boolean enableShiftLock;
switch (mode) {
case KeyboardId.MODE_PHONE:
xmlId = (isSymbols && isShift) ? R.xml.kbd_phone_shift : R.xml.kbd_phone;
enableShiftLock = true;
break;
case KeyboardId.MODE_NUMBER:
xmlId = R.xml.kbd_number;
enableShiftLock = false;
break;
default:
if (isSymbols) {
@ -259,7 +251,6 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
} else {
xmlId = R.xml.kbd_qwerty;
}
enableShiftLock = true;
break;
}
@ -276,7 +267,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
return new KeyboardId(
res.getResourceEntryName(xmlId), xmlId, locale, orientation, mWindowWidth,
mode, attribute, hasSettingsKey, f2KeyMode, clobberSettingsKey, voiceKeyEnabled,
hasVoiceKey, enableShiftLock);
hasVoiceKey);
}
public int getKeyboardMode() {
@ -572,7 +563,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
// Symbol keyboard may have an ALT key that has a caps lock style indicator (a.k.a.
// sticky shift key). To show or dismiss the indicator, we need to call setShiftLocked()
// that takes care of the current keyboard having such ALT key or not.
keyboard.setShiftLocked(hasStickyShiftKey(keyboard));
keyboard.setShiftLocked(keyboard.hasShiftLockKey());
} else {
keyboard = getKeyboard(mSymbolsKeyboardId);
// Symbol keyboard has an ALT key that has a caps lock style indicator. To disable the
@ -582,14 +573,6 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
setKeyboard(keyboard);
}
private static boolean hasStickyShiftKey(Keyboard keyboard) {
for (final Key shiftKey : keyboard.getShiftKeys()) {
if (shiftKey.mSticky)
return true;
}
return false;
}
public boolean isInMomentarySwitchState() {
return mSwitchState == SWITCH_STATE_MOMENTARY_ALPHA_AND_SYMBOL
|| mSwitchState == SWITCH_STATE_MOMENTARY_SYMBOL_AND_MORE;

View File

@ -338,8 +338,6 @@ public class KeyboardParser {
Arrays.toString(key.mPopupCharacters)));
checkEndTag(TAG_KEY, parser);
keys.add(key);
if (key.mCode == Keyboard.CODE_SHIFT)
mKeyboard.getShiftKeys().add(key);
endKey(key);
}
}

View File

@ -42,7 +42,7 @@ public class SuggestTestsBase extends AndroidTestCase {
return new KeyboardId(locale.toString() + " keyboard",
com.android.inputmethod.latin.R.xml.kbd_qwerty, locale,
Configuration.ORIENTATION_LANDSCAPE, displayWidth, KeyboardId.MODE_TEXT,
new EditorInfo(), false, KeyboardId.F2KEY_MODE_NONE, false, false, false, false);
new EditorInfo(), false, KeyboardId.F2KEY_MODE_NONE, false, false, false);
}
protected InputStream openTestRawResource(int resIdInTest) {