Remove enableShiftLock attribute from KeyboardId

This change is a follow up of Ia72de236.

Bug: 4311428
Change-Id: I0ad0f1fb93545ceb40df8dffe377240b020c2602
This commit is contained in:
Tadashi G. Takaoka 2011-07-27 17:20:06 -07:00
parent 60ccbe16ee
commit 6d9bcd5e13
6 changed files with 46 additions and 65 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -42,7 +42,7 @@ public class SuggestTestsBase extends AndroidTestCase {
return new KeyboardId(locale.toString() + " keyboard", return new KeyboardId(locale.toString() + " keyboard",
com.android.inputmethod.latin.R.xml.kbd_qwerty, locale, com.android.inputmethod.latin.R.xml.kbd_qwerty, locale,
Configuration.ORIENTATION_LANDSCAPE, displayWidth, KeyboardId.MODE_TEXT, 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) { protected InputStream openTestRawResource(int resIdInTest) {