Get rid of public reference to KeyboardIconsSet.ICON_* constants

As a consequence,
  * Add Key.iconDisabledKey has been introduced and Key.getIcon honors
    the enabled state of the key.
  * The attribute id of disabled icon for shortcut key,
    Keyboard_iconShortcutKeyDisabled, is renamed to
    Keyboard_iconDisbledShortcutKey
  * KeyboardIconsSet has getIconByIconId and getIconByAttrId methods
    instead of getIcon.

Bug: 5778201
Change-Id: Ica93b073b9a04acd18ead7a33b60e3c6d813e7a1
main
Tadashi G. Takaoka 2011-12-19 01:11:09 +09:00
parent 4e1dab8cfa
commit 42fcb2de64
13 changed files with 93 additions and 93 deletions

View File

@ -191,8 +191,8 @@
<attr name="iconShortcutKey" format="reference" /> <attr name="iconShortcutKey" format="reference" />
<attr name="iconShortcutForLabel" format="reference" /> <attr name="iconShortcutForLabel" format="reference" />
<attr name="iconSpaceKeyForNumberLayout" format="reference" /> <attr name="iconSpaceKeyForNumberLayout" format="reference" />
<attr name="iconShortcutKeyDisabled" format="reference" />
<attr name="iconShiftKeyShifted" format="reference" /> <attr name="iconShiftKeyShifted" format="reference" />
<attr name="iconDisabledShortcutKey" format="reference" />
<attr name="iconPreviewTabKey" format="reference" /> <attr name="iconPreviewTabKey" format="reference" />
</declare-styleable> </declare-styleable>
@ -245,23 +245,29 @@
</attr> </attr>
<!-- The icon to display on the key instead of the label. --> <!-- The icon to display on the key instead of the label. -->
<attr name="keyIcon" format="enum"> <attr name="keyIcon" format="enum">
<!-- This should be aligned with KeyboardIcons.ICON_* --> <!-- This should be aligned with the KeyboardIcons.ICONS_TO_ATTRS_MAP -->
<enum name="iconShiftKey" value="1" /> <enum name="iconShiftKey" value="1" />
<enum name="iconDeleteKey" value="2" /> <enum name="iconDeleteKey" value="2" />
<!-- This is also represented as "@icon/3" in keyboard layout XML. -->
<enum name="iconSettingsKey" value="3" /> <enum name="iconSettingsKey" value="3" />
<enum name="iconSpaceKey" value="4" /> <enum name="iconSpaceKey" value="4" />
<enum name="iconReturnKey" value="5" /> <enum name="iconReturnKey" value="5" />
<enum name="iconSearchKey" value="6" /> <enum name="iconSearchKey" value="6" />
<!-- This is also represented as "@icon/7" in keyboard layout XML. -->
<enum name="iconTabKey" value="7" /> <enum name="iconTabKey" value="7" />
<enum name="iconShortcutKey" value="8" /> <enum name="iconShortcutKey" value="8" />
<enum name="iconShortcutForLabel" value="9" /> <enum name="iconShortcutForLabel" value="9" />
<enum name="iconShortcutKeyDisabled" value="10" /> <enum name="iconSpaceKeyForNumberLayout" value="10" />
<enum name="iconSpaceKeyForNumberLayout" value="11" /> <enum name="iconShiftKeyShifted" value="11" />
<enum name="iconShiftKeyShifted" value="12" /> </attr>
<!-- The icon for disabled key -->
<attr name="keyIconDisabled" format="enum">
<!-- This should be aligned with the KeyboardIcons.ICONS_TO_ATTRS_MAP -->
<enum name="iconDisabledShortcutKey" value="12" />
</attr> </attr>
<!-- The icon to show in the popup preview. --> <!-- The icon to show in the popup preview. -->
<attr name="keyIconPreview" format="enum"> <attr name="keyIconPreview" format="enum">
<!-- This should be aligned with KeyboardIcons.ICON_PREVIEW_* --> <!-- This should be aligned with the KeyboardIcons.ICONS_TO_ATTRS_MAP -->
<enum name="iconPreviewTabKey" value="13" /> <enum name="iconPreviewTabKey" value="13" />
</attr> </attr>
<!-- The key style to specify a set of key attributes defined by <key_style/> --> <!-- The key style to specify a set of key attributes defined by <key_style/> -->

View File

@ -30,9 +30,9 @@
<item name="iconTabKey">@drawable/sym_bkeyboard_tab</item> <item name="iconTabKey">@drawable/sym_bkeyboard_tab</item>
<item name="iconShortcutKey">@drawable/sym_bkeyboard_mic</item> <item name="iconShortcutKey">@drawable/sym_bkeyboard_mic</item>
<item name="iconShortcutForLabel">@drawable/sym_bkeyboard_label_mic</item> <item name="iconShortcutForLabel">@drawable/sym_bkeyboard_label_mic</item>
<item name="iconShortcutKeyDisabled">@drawable/sym_bkeyboard_voice_off</item>
<item name="iconSpaceKeyForNumberLayout">@drawable/sym_bkeyboard_space</item> <item name="iconSpaceKeyForNumberLayout">@drawable/sym_bkeyboard_space</item>
<item name="iconShiftKeyShifted">@drawable/sym_bkeyboard_shift_locked</item> <item name="iconShiftKeyShifted">@drawable/sym_bkeyboard_shift_locked</item>
<item name="iconDisabledShortcutKey">@drawable/sym_bkeyboard_voice_off</item>
<item name="iconPreviewTabKey">@drawable/sym_keyboard_feedback_tab</item> <item name="iconPreviewTabKey">@drawable/sym_keyboard_feedback_tab</item>
</style> </style>
</resources> </resources>

View File

@ -29,9 +29,9 @@
<item name="iconTabKey">@drawable/sym_keyboard_tab_holo</item> <item name="iconTabKey">@drawable/sym_keyboard_tab_holo</item>
<item name="iconShortcutKey">@drawable/sym_keyboard_voice_holo</item> <item name="iconShortcutKey">@drawable/sym_keyboard_voice_holo</item>
<item name="iconShortcutForLabel">@drawable/sym_keyboard_label_mic_holo</item> <item name="iconShortcutForLabel">@drawable/sym_keyboard_label_mic_holo</item>
<item name="iconShortcutKeyDisabled">@drawable/sym_keyboard_voice_off_holo</item>
<item name="iconSpaceKeyForNumberLayout">@drawable/sym_keyboard_space_holo</item> <item name="iconSpaceKeyForNumberLayout">@drawable/sym_keyboard_space_holo</item>
<item name="iconShiftKeyShifted">@drawable/sym_keyboard_shift_locked_holo</item> <item name="iconShiftKeyShifted">@drawable/sym_keyboard_shift_locked_holo</item>
<item name="iconDisabledShortcutKey">@drawable/sym_keyboard_voice_off_holo</item>
<item name="iconPreviewTabKey">@drawable/sym_keyboard_feedback_tab</item> <item name="iconPreviewTabKey">@drawable/sym_keyboard_feedback_tab</item>
</style> </style>
</resources> </resources>

View File

@ -26,10 +26,10 @@
<item name="iconTabKey">@drawable/sym_keyboard_tab</item> <item name="iconTabKey">@drawable/sym_keyboard_tab</item>
<item name="iconShortcutKey">@drawable/sym_keyboard_mic</item> <item name="iconShortcutKey">@drawable/sym_keyboard_mic</item>
<item name="iconShortcutForLabel">@drawable/sym_keyboard_label_mic</item> <item name="iconShortcutForLabel">@drawable/sym_keyboard_label_mic</item>
<!-- TODO: Needs non-holo disabled shortcut icon drawable -->
<item name="iconShortcutKeyDisabled">@drawable/sym_keyboard_voice_off_holo</item>
<item name="iconSpaceKeyForNumberLayout">@drawable/sym_keyboard_space</item> <item name="iconSpaceKeyForNumberLayout">@drawable/sym_keyboard_space</item>
<item name="iconShiftKeyShifted">@drawable/sym_keyboard_shift_locked</item> <item name="iconShiftKeyShifted">@drawable/sym_keyboard_shift_locked</item>
<!-- TODO: Needs non-holo disabled shortcut icon drawable -->
<item name="iconDisabledShortcutKey">@drawable/sym_keyboard_voice_off_holo</item>
<item name="iconPreviewTabKey">@drawable/sym_keyboard_feedback_tab</item> <item name="iconPreviewTabKey">@drawable/sym_keyboard_feedback_tab</item>
</style> </style>
</resources> </resources>

View File

@ -307,7 +307,7 @@
<item name="spacebarTextRatio">@fraction/spacebar_text_ratio</item> <item name="spacebarTextRatio">@fraction/spacebar_text_ratio</item>
<item name="spacebarTextColor">#FFC0C0C0</item> <item name="spacebarTextColor">#FFC0C0C0</item>
<item name="spacebarTextShadowColor">#80000000</item> <item name="spacebarTextShadowColor">#80000000</item>
</style> </style>
<style <style
name="MiniKeyboard.IceCreamSandwich" name="MiniKeyboard.IceCreamSandwich"
parent="Keyboard.IceCreamSandwich" parent="Keyboard.IceCreamSandwich"

View File

@ -76,6 +76,7 @@
latin:styleName="shortcutKeyStyle" latin:styleName="shortcutKeyStyle"
latin:code="@integer/key_shortcut" latin:code="@integer/key_shortcut"
latin:keyIcon="iconShortcutKey" latin:keyIcon="iconShortcutKey"
latin:keyIconDisabled="iconDisabledShortcutKey"
latin:keyActionFlags="noKeyPreview|altCodeWhileTyping" latin:keyActionFlags="noKeyPreview|altCodeWhileTyping"
latin:altCode="@integer/key_dummy" latin:altCode="@integer/key_dummy"
latin:parentStyle="f2PopupStyle" /> latin:parentStyle="f2PopupStyle" />

View File

@ -58,6 +58,7 @@
latin:styleName="shortcutKeyStyle" latin:styleName="shortcutKeyStyle"
latin:code="@integer/key_shortcut" latin:code="@integer/key_shortcut"
latin:keyIcon="iconShortcutKey" latin:keyIcon="iconShortcutKey"
latin:keyIconDisabled="iconDisabledShortcutKey"
latin:keyActionFlags="noKeyPreview|altCodeWhileTyping" latin:keyActionFlags="noKeyPreview|altCodeWhileTyping"
latin:altCode="@integer/key_dummy" latin:altCode="@integer/key_dummy"
latin:backgroundType="functional" /> latin:backgroundType="functional" />

View File

@ -162,6 +162,7 @@
latin:styleName="shortcutKeyStyle" latin:styleName="shortcutKeyStyle"
latin:code="@integer/key_shortcut" latin:code="@integer/key_shortcut"
latin:keyIcon="iconShortcutKey" latin:keyIcon="iconShortcutKey"
latin:keyIconDisabled="iconDisabledShortcutKey"
latin:keyActionFlags="noKeyPreview|altCodeWhileTyping" latin:keyActionFlags="noKeyPreview|altCodeWhileTyping"
latin:altCode="@integer/key_space" latin:altCode="@integer/key_space"
latin:parentStyle="f1PopupStyle" /> latin:parentStyle="f1PopupStyle" />

View File

@ -72,9 +72,11 @@ public class Key {
private static final int LABEL_FLAGS_WITH_ICON_RIGHT = 0x2000; private static final int LABEL_FLAGS_WITH_ICON_RIGHT = 0x2000;
private static final int LABEL_FLAGS_AUTO_X_SCALE = 0x4000; private static final int LABEL_FLAGS_AUTO_X_SCALE = 0x4000;
// TODO: This should be public final // TODO: These icon references could be int (icon attribute id)
/** Icon to display instead of a label. Icon takes precedence over a label */ /** Icon to display instead of a label. Icon takes precedence over a label */
private Drawable mIcon; private Drawable mIcon;
/** Icon for disabled state */
private Drawable mDisabledIcon;
/** Preview version of the icon, for the preview popup */ /** Preview version of the icon, for the preview popup */
public final Drawable mPreviewIcon; public final Drawable mPreviewIcon;
@ -164,7 +166,7 @@ public class Key {
} }
private static Drawable getIcon(Keyboard.Params params, String moreKeySpec) { private static Drawable getIcon(Keyboard.Params params, String moreKeySpec) {
return params.mIconsSet.getIcon(MoreKeySpecParser.getIconId(moreKeySpec)); return params.mIconsSet.getIconByIconId(MoreKeySpecParser.getIconId(moreKeySpec));
} }
/** /**
@ -198,6 +200,7 @@ public class Key {
mCode = code; mCode = code;
mAltCode = Keyboard.CODE_DUMMY; mAltCode = Keyboard.CODE_DUMMY;
mIcon = icon; mIcon = icon;
mDisabledIcon = null;
mPreviewIcon = null; mPreviewIcon = null;
// Horizontal gap is divided equally to both sides of the key. // Horizontal gap is divided equally to both sides of the key.
mX = x + mHorizontalGap / 2; mX = x + mHorizontalGap / 2;
@ -274,10 +277,12 @@ public class Key {
R.styleable.Keyboard_Key_visualInsetsLeft, params.mBaseWidth, 0); R.styleable.Keyboard_Key_visualInsetsLeft, params.mBaseWidth, 0);
mVisualInsetsRight = (int) Keyboard.Builder.getDimensionOrFraction(keyAttr, mVisualInsetsRight = (int) Keyboard.Builder.getDimensionOrFraction(keyAttr,
R.styleable.Keyboard_Key_visualInsetsRight, params.mBaseWidth, 0); R.styleable.Keyboard_Key_visualInsetsRight, params.mBaseWidth, 0);
mPreviewIcon = iconsSet.getIcon(style.getInt(keyAttr, mPreviewIcon = iconsSet.getIconByIconId(style.getInt(keyAttr,
R.styleable.Keyboard_Key_keyIconPreview, KeyboardIconsSet.ICON_UNDEFINED)); R.styleable.Keyboard_Key_keyIconPreview, KeyboardIconsSet.ICON_UNDEFINED));
mIcon = iconsSet.getIcon(style.getInt(keyAttr, R.styleable.Keyboard_Key_keyIcon, mIcon = iconsSet.getIconByIconId(style.getInt(keyAttr,
KeyboardIconsSet.ICON_UNDEFINED)); R.styleable.Keyboard_Key_keyIcon, KeyboardIconsSet.ICON_UNDEFINED));
mDisabledIcon = iconsSet.getIconByIconId(style.getInt(keyAttr,
R.styleable.Keyboard_Key_keyIconDisabled, KeyboardIconsSet.ICON_UNDEFINED));
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);
@ -459,7 +464,7 @@ public class Key {
} }
public Drawable getIcon() { public Drawable getIcon() {
return mIcon; return mEnabled ? mIcon : mDisabledIcon;
} }
// TODO: Get rid of this method. // TODO: Get rid of this method.

View File

@ -192,9 +192,10 @@ public class Keyboard {
// To represent "shift locked" state. The highlight is handled by background image that // To represent "shift locked" state. The highlight is handled by background image that
// might be a StateListDrawable. // might be a StateListDrawable.
key.setHighlightOn(newShiftLockState); key.setHighlightOn(newShiftLockState);
final int iconId = newShiftLockState ? KeyboardIconsSet.ICON_SHIFT_KEY_SHIFTED final int attrId = newShiftLockState
: KeyboardIconsSet.ICON_SHIFT_KEY; ? R.styleable.Keyboard_iconShiftKeyShifted
key.setIcon(mIconsSet.getIcon(iconId)); : R.styleable.Keyboard_iconShiftKey;
key.setIcon(mIconsSet.getIconByAttrId(attrId));
} }
mShiftState.setShiftLocked(newShiftLockState); mShiftState.setShiftLocked(newShiftLockState);
} }
@ -208,9 +209,10 @@ public class Keyboard {
void setShifted(boolean newShiftState) { void setShifted(boolean newShiftState) {
if (!mShiftState.isShiftLocked()) { if (!mShiftState.isShiftLocked()) {
for (final Key key : mShiftKeys) { for (final Key key : mShiftKeys) {
final int iconId = newShiftState ? KeyboardIconsSet.ICON_SHIFT_KEY_SHIFTED final int attrId = newShiftState
: KeyboardIconsSet.ICON_SHIFT_KEY; ? R.styleable.Keyboard_iconShiftKeyShifted
key.setIcon(mIconsSet.getIcon(iconId)); : R.styleable.Keyboard_iconShiftKey;
key.setIcon(mIconsSet.getIconByAttrId(attrId));
} }
} }
mShiftState.setShifted(newShiftState); mShiftState.setShifted(newShiftState);

View File

@ -47,7 +47,6 @@ import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy;
import com.android.inputmethod.deprecated.VoiceProxy; import com.android.inputmethod.deprecated.VoiceProxy;
import com.android.inputmethod.keyboard.PointerTracker.DrawingProxy; import com.android.inputmethod.keyboard.PointerTracker.DrawingProxy;
import com.android.inputmethod.keyboard.PointerTracker.TimerProxy; import com.android.inputmethod.keyboard.PointerTracker.TimerProxy;
import com.android.inputmethod.keyboard.internal.KeyboardIconsSet;
import com.android.inputmethod.latin.LatinIME; import com.android.inputmethod.latin.LatinIME;
import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.R;
@ -357,7 +356,7 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
mMoreKeysPanelCache.clear(); mMoreKeysPanelCache.clear();
mSpaceKey = keyboard.getKey(Keyboard.CODE_SPACE); mSpaceKey = keyboard.getKey(Keyboard.CODE_SPACE);
mSpaceIcon = keyboard.mIconsSet.getIcon(KeyboardIconsSet.ICON_SPACE_KEY); mSpaceIcon = keyboard.mIconsSet.getIconByAttrId(R.styleable.Keyboard_iconSpaceKey);
final int keyHeight = keyboard.mMostCommonKeyHeight - keyboard.mVerticalGap; final int keyHeight = keyboard.mMostCommonKeyHeight - keyboard.mVerticalGap;
mSpacebarTextSize = keyHeight * mSpacebarTextRatio; mSpacebarTextSize = keyHeight * mSpacebarTextRatio;
mSpacebarLocale = keyboard.mId.mLocale; mSpacebarLocale = keyboard.mId.mLocale;
@ -750,9 +749,6 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
final Key shortcutKey = keyboard.getKey(Keyboard.CODE_SHORTCUT); final Key shortcutKey = keyboard.getKey(Keyboard.CODE_SHORTCUT);
if (shortcutKey == null) return; if (shortcutKey == null) return;
shortcutKey.setEnabled(available); shortcutKey.setEnabled(available);
final int iconId = available ? KeyboardIconsSet.ICON_SHORTCUT_KEY
: KeyboardIconsSet.ICON_SHORTCUT_KEY_DISABLED;
shortcutKey.setIcon(keyboard.mIconsSet.getIcon(iconId));
invalidateKey(shortcutKey); invalidateKey(shortcutKey);
} }

View File

@ -161,6 +161,7 @@ public class KeyStyles {
readTextArray(keyAttr, R.styleable.Keyboard_Key_moreKeys); readTextArray(keyAttr, R.styleable.Keyboard_Key_moreKeys);
readFlag(keyAttr, R.styleable.Keyboard_Key_keyLabelFlags); readFlag(keyAttr, R.styleable.Keyboard_Key_keyLabelFlags);
readInt(keyAttr, R.styleable.Keyboard_Key_keyIcon); readInt(keyAttr, R.styleable.Keyboard_Key_keyIcon);
readInt(keyAttr, R.styleable.Keyboard_Key_keyIconDisabled);
readInt(keyAttr, R.styleable.Keyboard_Key_keyIconPreview); readInt(keyAttr, R.styleable.Keyboard_Key_keyIconPreview);
readInt(keyAttr, R.styleable.Keyboard_Key_maxMoreKeysColumn); readInt(keyAttr, R.styleable.Keyboard_Key_maxMoreKeysColumn);
readInt(keyAttr, R.styleable.Keyboard_Key_backgroundType); readInt(keyAttr, R.styleable.Keyboard_Key_backgroundType);

View File

@ -23,88 +23,75 @@ import android.util.Log;
import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.R;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
public class KeyboardIconsSet { public class KeyboardIconsSet {
private static final String TAG = KeyboardIconsSet.class.getSimpleName(); private static final String TAG = KeyboardIconsSet.class.getSimpleName();
public static final int ICON_UNDEFINED = 0; public static final int ICON_UNDEFINED = 0;
// TODO: Make all enums private private final Map<Integer, Drawable> mIcons = new HashMap<Integer, Drawable>();
// This should be aligned with Keyboard.keyIcon enum.
public static final int ICON_SHIFT_KEY = 1;
private static final int ICON_DELETE_KEY = 2;
// This is also represented as "@icon/3" in keyboard layout XML.
private static final int ICON_SETTINGS_KEY = 3;
public static final int ICON_SPACE_KEY = 4;
private static final int ICON_RETURN_KEY = 5;
private static final int ICON_SEARCH_KEY = 6;
// This is also represented as "@icon/7" in keyboard layout XML.
private static final int ICON_TAB_KEY = 7;
public static final int ICON_SHORTCUT_KEY = 8;
private static final int ICON_SHORTCUT_FOR_LABEL = 9;
public static final int ICON_SHORTCUT_KEY_DISABLED = 10;
private static final int ICON_SPACE_KEY_FOR_NUMBER_LAYOUT = 11;
public static final int ICON_SHIFT_KEY_SHIFTED = 12;
// This should be aligned with Keyboard.keyIconPreview enum.
private static final int ICON_PREVIEW_TAB_KEY = 13;
private static final int ICON_LAST = 13; // The key value should be aligned with the enum value of Keyboard.icon*.
private static final Map<Integer, Integer> ICONS_TO_ATTRS_MAP = new HashMap<Integer, Integer>();
private static final Collection<Integer> VALID_ATTRS;
private final Drawable mIcons[] = new Drawable[ICON_LAST + 1]; static {
addIconIdMap(1, R.styleable.Keyboard_iconShiftKey);
addIconIdMap(2, R.styleable.Keyboard_iconDeleteKey);
// This is also represented as "@icon/3" in keyboard layout XML.
addIconIdMap(3, R.styleable.Keyboard_iconSettingsKey);
addIconIdMap(4, R.styleable.Keyboard_iconSpaceKey);
addIconIdMap(5, R.styleable.Keyboard_iconReturnKey);
addIconIdMap(6, R.styleable.Keyboard_iconSearchKey);
// This is also represented as "@icon/7" in keyboard layout XML.
addIconIdMap(7, R.styleable.Keyboard_iconTabKey);
addIconIdMap(8, R.styleable.Keyboard_iconShortcutKey);
addIconIdMap(9, R.styleable.Keyboard_iconShortcutForLabel);
addIconIdMap(10, R.styleable.Keyboard_iconSpaceKeyForNumberLayout);
addIconIdMap(11, R.styleable.Keyboard_iconShiftKeyShifted);
addIconIdMap(12, R.styleable.Keyboard_iconDisabledShortcutKey);
addIconIdMap(13, R.styleable.Keyboard_iconPreviewTabKey);
VALID_ATTRS = ICONS_TO_ATTRS_MAP.values();
}
private static final int getIconId(final int attrIndex) { private static void addIconIdMap(int iconId, int attrId) {
switch (attrIndex) { ICONS_TO_ATTRS_MAP.put(iconId, attrId);
case R.styleable.Keyboard_iconShiftKey:
return ICON_SHIFT_KEY;
case R.styleable.Keyboard_iconDeleteKey:
return ICON_DELETE_KEY;
case R.styleable.Keyboard_iconSettingsKey:
return ICON_SETTINGS_KEY;
case R.styleable.Keyboard_iconSpaceKey:
return ICON_SPACE_KEY;
case R.styleable.Keyboard_iconReturnKey:
return ICON_RETURN_KEY;
case R.styleable.Keyboard_iconSearchKey:
return ICON_SEARCH_KEY;
case R.styleable.Keyboard_iconTabKey:
return ICON_TAB_KEY;
case R.styleable.Keyboard_iconShortcutKey:
return ICON_SHORTCUT_KEY;
case R.styleable.Keyboard_iconShortcutForLabel:
return ICON_SHORTCUT_FOR_LABEL;
case R.styleable.Keyboard_iconShortcutKeyDisabled:
return ICON_SHORTCUT_KEY_DISABLED;
case R.styleable.Keyboard_iconSpaceKeyForNumberLayout:
return ICON_SPACE_KEY_FOR_NUMBER_LAYOUT;
case R.styleable.Keyboard_iconShiftKeyShifted:
return ICON_SHIFT_KEY_SHIFTED;
case R.styleable.Keyboard_iconPreviewTabKey:
return ICON_PREVIEW_TAB_KEY;
default:
return ICON_UNDEFINED;
}
} }
public void loadIcons(final TypedArray keyboardAttrs) { public void loadIcons(final TypedArray keyboardAttrs) {
final int count = keyboardAttrs.getIndexCount(); for (final Integer attrId : VALID_ATTRS) {
for (int i = 0; i < count; i++) { try {
final int attrIndex = keyboardAttrs.getIndex(i); final Drawable icon = keyboardAttrs.getDrawable(attrId);
final int iconId = getIconId(attrIndex); if (icon == null) continue;
if (iconId != ICON_UNDEFINED) { setDefaultBounds(icon);
try { mIcons.put(attrId, icon);
mIcons[iconId] = setDefaultBounds(keyboardAttrs.getDrawable(attrIndex)); } catch (Resources.NotFoundException e) {
} catch (Resources.NotFoundException e) { Log.w(TAG, "Drawable resource for icon #"
Log.w(TAG, "Drawable resource for icon #" + iconId + " not found"); + keyboardAttrs.getResources().getResourceEntryName(attrId)
} + " not found");
} }
} }
} }
public Drawable getIcon(final int iconId) { public Drawable getIconByIconId(final Integer iconId) {
if (iconId == ICON_UNDEFINED) if (iconId == ICON_UNDEFINED) {
return null; return null;
if (iconId < 0 || iconId >= mIcons.length) }
final Integer attrId = ICONS_TO_ATTRS_MAP.get(iconId);
if (attrId == null) {
throw new IllegalArgumentException("icon id is out of range: " + iconId); throw new IllegalArgumentException("icon id is out of range: " + iconId);
return mIcons[iconId]; }
return getIconByAttrId(attrId);
}
public Drawable getIconByAttrId(final Integer attrId) {
if (!VALID_ATTRS.contains(attrId)) {
throw new IllegalArgumentException("unknown icon attribute id: " + attrId);
}
return mIcons.get(attrId);
} }
private static Drawable setDefaultBounds(final Drawable icon) { private static Drawable setDefaultBounds(final Drawable icon) {