Cleanup icon drawable related code

Bug: 5023981
Change-Id: I729354f32797eef354ec9af8e05f17839f0a361c
main
Tadashi G. Takaoka 2011-08-01 16:37:13 -07:00
parent cb1cc0d0de
commit b118d4cb58
3 changed files with 11 additions and 16 deletions

View File

@ -324,16 +324,13 @@ public class Key {
mPreviewIcon = iconsSet.getIcon(style.getInt(
keyAttr, R.styleable.Keyboard_Key_keyIconPreview,
KeyboardIconsSet.ICON_UNDEFINED));
Keyboard.setDefaultBounds(mPreviewIcon);
mIcon = iconsSet.getIcon(style.getInt(
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);

View File

@ -431,10 +431,4 @@ public class Keyboard {
throw new RuntimeException(e);
}
}
public static void setDefaultBounds(Drawable drawable) {
if (drawable != null)
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight());
}
}

View File

@ -21,7 +21,6 @@ import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.Log;
import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.latin.R;
public class KeyboardIconsSet {
@ -51,7 +50,7 @@ public class KeyboardIconsSet {
private final Drawable mIcons[] = new Drawable[ICON_LAST + 1];
private static final int getIconId(int attrIndex) {
private static final int getIconId(final int attrIndex) {
switch (attrIndex) {
case R.styleable.Keyboard_iconShiftKey:
return ICON_SHIFT_KEY;
@ -86,16 +85,14 @@ public class KeyboardIconsSet {
}
}
public void loadIcons(TypedArray keyboardAttrs) {
public void loadIcons(final TypedArray keyboardAttrs) {
final int count = keyboardAttrs.getIndexCount();
for (int i = 0; i < count; i++) {
final int attrIndex = keyboardAttrs.getIndex(i);
final int iconId = getIconId(attrIndex);
if (iconId != ICON_UNDEFINED) {
try {
final Drawable icon = keyboardAttrs.getDrawable(attrIndex);
Keyboard.setDefaultBounds(icon);
mIcons[iconId] = icon;
mIcons[iconId] = setDefaultBounds(keyboardAttrs.getDrawable(attrIndex));
} catch (Resources.NotFoundException e) {
Log.w(TAG, "Drawable resource for icon #" + iconId + " not found");
}
@ -103,11 +100,18 @@ public class KeyboardIconsSet {
}
}
public Drawable getIcon(int iconId) {
public Drawable getIcon(final int iconId) {
if (iconId == ICON_UNDEFINED)
return null;
if (iconId < 0 || iconId >= mIcons.length)
throw new IllegalArgumentException("icon id is out of range: " + iconId);
return mIcons[iconId];
}
private static Drawable setDefaultBounds(final Drawable icon) {
if (icon != null) {
icon.setBounds(0, 0, icon.getIntrinsicWidth(), icon.getIntrinsicHeight());
}
return icon;
}
}