am bcf2b793: Prepare to get rid of Drawable reference from Key

* commit 'bcf2b79365d7b655e973809c775772479dd8dff5':
  Prepare to get rid of Drawable reference from Key
main
Tadashi G. Takaoka 2012-01-25 03:29:15 -08:00 committed by Android Git Automerger
commit bf57d2c802
3 changed files with 24 additions and 19 deletions

View File

@ -72,13 +72,14 @@ 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: 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 final int mIconAttrId;
// TODO: Remove this variable.
private Drawable mIcon; private Drawable mIcon;
/** Icon for disabled state */ /** Icon for disabled state */
private Drawable mDisabledIcon; private final int mDisabledIconAttrId;
/** Preview version of the icon, for the preview popup */ /** Preview version of the icon, for the preview popup */
public final Drawable mPreviewIcon; public final int mPreviewIconAttrId;
/** Width of the key, not including the gap */ /** Width of the key, not including the gap */
public final int mWidth; public final int mWidth;
@ -204,9 +205,10 @@ public class Key {
mOutputText = outputText; mOutputText = outputText;
mCode = code; mCode = code;
mAltCode = Keyboard.CODE_UNSPECIFIED; mAltCode = Keyboard.CODE_UNSPECIFIED;
mIconAttrId = KeyboardIconsSet.ATTR_UNDEFINED;
mIcon = icon; mIcon = icon;
mDisabledIcon = null; mDisabledIconAttrId = KeyboardIconsSet.ATTR_UNDEFINED;
mPreviewIcon = null; mPreviewIconAttrId = KeyboardIconsSet.ATTR_UNDEFINED;
// 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;
mY = y; mY = y;
@ -282,18 +284,16 @@ 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);
final int previewIconAttrId = KeyboardIconsSet.getIconAttrId(style.getInt(keyAttr, mPreviewIconAttrId = KeyboardIconsSet.getIconAttrId(style.getInt(keyAttr,
R.styleable.Keyboard_Key_keyIconPreview, KeyboardIconsSet.ICON_UNDEFINED)); R.styleable.Keyboard_Key_keyIconPreview, KeyboardIconsSet.ICON_UNDEFINED));
mPreviewIcon = iconsSet.getIconByAttrId(previewIconAttrId); mIconAttrId = KeyboardIconsSet.getIconAttrId(style.getInt(keyAttr,
final int iconAttrId = KeyboardIconsSet.getIconAttrId(style.getInt(keyAttr,
R.styleable.Keyboard_Key_keyIcon, KeyboardIconsSet.ICON_UNDEFINED)); R.styleable.Keyboard_Key_keyIcon, KeyboardIconsSet.ICON_UNDEFINED));
mIcon = iconsSet.getIconByAttrId(iconAttrId); mIcon = iconsSet.getIconByAttrId(mIconAttrId);
final int disabledIconAttrId = KeyboardIconsSet.getIconAttrId(style.getInt(keyAttr, mDisabledIconAttrId = KeyboardIconsSet.getIconAttrId(style.getInt(keyAttr,
R.styleable.Keyboard_Key_keyIconDisabled, KeyboardIconsSet.ICON_UNDEFINED)); R.styleable.Keyboard_Key_keyIconDisabled, KeyboardIconsSet.ICON_UNDEFINED));
mDisabledIcon = iconsSet.getIconByAttrId(disabledIconAttrId);
mHintLabel = style.getString(keyAttr, R.styleable.Keyboard_Key_keyHintLabel);
mLabel = style.getString(keyAttr, R.styleable.Keyboard_Key_keyLabel); mLabel = style.getString(keyAttr, R.styleable.Keyboard_Key_keyLabel);
mHintLabel = style.getString(keyAttr, R.styleable.Keyboard_Key_keyHintLabel);
mLabelFlags = style.getFlag(keyAttr, R.styleable.Keyboard_Key_keyLabelFlags, 0); mLabelFlags = style.getFlag(keyAttr, R.styleable.Keyboard_Key_keyLabelFlags, 0);
mOutputText = style.getString(keyAttr, R.styleable.Keyboard_Key_keyOutputText); mOutputText = style.getString(keyAttr, R.styleable.Keyboard_Key_keyOutputText);
// Choose the first letter of the label as primary code if not // Choose the first letter of the label as primary code if not
@ -328,13 +328,15 @@ public class Key {
key.mCode, key.mCode,
key.mLabel, key.mLabel,
key.mHintLabel, key.mHintLabel,
key.mIconAttrId,
// Key can be distinguishable without the following members. // Key can be distinguishable without the following members.
// key.mAltCode, // key.mAltCode,
// key.mOutputText, // key.mOutputText,
// key.mActionFlags, // key.mActionFlags,
// key.mLabelFlags, // key.mLabelFlags,
// key.mIcon, // key.mIcon,
// key.mPreviewIcon, // key.mDisabledIconAttrId,
// key.mPreviewIconAttrId,
// key.mBackgroundType, // key.mBackgroundType,
// key.mHorizontalGap, // key.mHorizontalGap,
// key.mVerticalGap, // key.mVerticalGap,
@ -471,8 +473,9 @@ public class Key {
return (mLabelFlags & LABEL_FLAGS_AUTO_X_SCALE) != 0; return (mLabelFlags & LABEL_FLAGS_AUTO_X_SCALE) != 0;
} }
public Drawable getIcon() { // TODO: Get rid of this method.
return mEnabled ? mIcon : mDisabledIcon; public Drawable getIcon(KeyboardIconsSet iconSet) {
return mEnabled ? mIcon : iconSet.getIconByAttrId(mDisabledIconAttrId);
} }
// TODO: Get rid of this method. // TODO: Get rid of this method.

View File

@ -39,6 +39,7 @@ import android.widget.RelativeLayout;
import android.widget.TextView; import android.widget.TextView;
import com.android.inputmethod.compat.FrameLayoutCompatUtils; import com.android.inputmethod.compat.FrameLayoutCompatUtils;
import com.android.inputmethod.keyboard.internal.KeyboardIconsSet;
import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.StaticInnerHandlerWrapper; import com.android.inputmethod.latin.StaticInnerHandlerWrapper;
@ -552,7 +553,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
} }
// Draw key label. // Draw key label.
final Drawable icon = key.getIcon(); final Drawable icon = key.getIcon(mKeyboard.mIconsSet);
float positionX = centerX; float positionX = centerX;
if (key.mLabel != null) { if (key.mLabel != null) {
// Switch the character to uppercase if shift is pressed // Switch the character to uppercase if shift is pressed
@ -898,9 +899,10 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
} }
previewText.setText(mKeyboard.adjustLabelCase(key.mLabel)); previewText.setText(mKeyboard.adjustLabelCase(key.mLabel));
} else { } else {
final Drawable previewIcon = key.mPreviewIcon; final Drawable previewIcon = mKeyboard.mIconsSet.getIconByAttrId(
key.mPreviewIconAttrId);
previewText.setCompoundDrawables(null, null, null, previewText.setCompoundDrawables(null, null, null,
previewIcon != null ? previewIcon : key.getIcon()); previewIcon != null ? previewIcon : key.getIcon(mKeyboard.mIconsSet));
previewText.setText(null); previewText.setText(null);
} }
previewText.setBackgroundDrawable(params.mPreviewBackground); previewText.setBackgroundDrawable(params.mPreviewBackground);

View File

@ -31,7 +31,7 @@ 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;
private static final int ATTR_UNDEFINED = 0; public static final int ATTR_UNDEFINED = 0;
private final Map<Integer, Drawable> mIcons = new HashMap<Integer, Drawable>(); private final Map<Integer, Drawable> mIcons = new HashMap<Integer, Drawable>();