Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 909b2940 authored by Tadashi G. Takaoka's avatar Tadashi G. Takaoka Committed by Android (Google) Code Review
Browse files

Merge "Get rid of Key.setIcon(Drawable)"

parents 98aa4761 e7948a86
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -281,7 +281,7 @@
        </attr>
        <!-- The icon to display on the key instead of the label. -->
        <attr name="keyIcon" format="enum">
            <!-- This should be aligned with the KeyboardIcons.ICONS_TO_ATTRS_MAP -->
            <!-- This should be aligned with the KeyboardIconsSet.ICON_* -->
            <enum name="iconShiftKey" value="1" />
            <enum name="iconDeleteKey" value="2" />
            <enum name="iconSettingsKey" value="3" />
@@ -296,12 +296,12 @@
        </attr>
        <!-- The icon for disabled key -->
        <attr name="keyIconDisabled" format="enum">
            <!-- This should be aligned with the KeyboardIcons.ICONS_TO_ATTRS_MAP -->
            <!-- This should be aligned with the KeyboardIconsSet.ICON_* -->
            <enum name="iconDisabledShortcutKey" value="12" />
        </attr>
        <!-- The icon to show in the popup preview. -->
        <attr name="keyIconPreview" format="enum">
            <!-- This should be aligned with the KeyboardIcons.ICONS_TO_ATTRS_MAP -->
            <!-- This should be aligned with the KeyboardIconsSet.ICON_* -->
            <enum name="iconPreviewTabKey" value="13" />
        </attr>
        <!-- The key style to specify a set of key attributes defined by <key_style/> -->
+35 −49
Original line number Diff line number Diff line
@@ -25,10 +25,10 @@ import android.text.TextUtils;
import android.util.Log;
import android.util.Xml;

import com.android.inputmethod.keyboard.internal.KeySpecParser;
import com.android.inputmethod.keyboard.internal.KeyStyles;
import com.android.inputmethod.keyboard.internal.KeyStyles.KeyStyle;
import com.android.inputmethod.keyboard.internal.KeyboardIconsSet;
import com.android.inputmethod.keyboard.internal.KeySpecParser;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.Utils;
import com.android.inputmethod.latin.XmlParseUtils;
@@ -74,13 +74,11 @@ public class Key {
    private static final int LABEL_FLAGS_SHIFTED_LETTER_ACTIVATED = 0x10000;

    /** 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 final int mIconId;
    /** Icon for disabled state */
    private final int mDisabledIconAttrId;
    private final int mDisabledIconId;
    /** Preview version of the icon, for the preview popup */
    public final int mPreviewIconAttrId;
    private final int mPreviewIconId;

    /** Width of the key, not including the gap */
    public final int mWidth;
@@ -128,21 +126,13 @@ public class Key {
    /** Key is enabled and responds on press */
    private boolean mEnabled = true;

    private static Drawable getIcon(Keyboard.Params params, String moreKeySpec) {
        final int iconAttrId = KeySpecParser.getIconAttrId(moreKeySpec);
        if (iconAttrId == KeyboardIconsSet.ICON_UNDEFINED) {
            return null;
        } else {
            return params.mIconsSet.getIconByAttrId(iconAttrId);
        }
    }

    /**
     * This constructor is being used only for key in more keys keyboard.
     */
    public Key(Resources res, Keyboard.Params params, String moreKeySpec,
            int x, int y, int width, int height) {
        this(params, KeySpecParser.getLabel(moreKeySpec), null, getIcon(params, moreKeySpec),
        this(params, KeySpecParser.getLabel(moreKeySpec), null,
                KeySpecParser.getIconId(moreKeySpec),
                KeySpecParser.getCode(res, moreKeySpec),
                KeySpecParser.getOutputText(moreKeySpec),
                x, y, width, height);
@@ -151,7 +141,7 @@ public class Key {
    /**
     * This constructor is being used only for key in popup suggestions pane.
     */
    public Key(Keyboard.Params params, String label, String hintLabel, Drawable icon,
    public Key(Keyboard.Params params, String label, String hintLabel, int iconId,
            int code, CharSequence outputText, int x, int y, int width, int height) {
        mHeight = height - params.mVerticalGap;
        mHorizontalGap = params.mHorizontalGap;
@@ -168,10 +158,9 @@ public class Key {
        mOutputText = outputText;
        mCode = code;
        mAltCode = Keyboard.CODE_UNSPECIFIED;
        mIconAttrId = KeyboardIconsSet.ATTR_UNDEFINED;
        mIcon = icon;
        mDisabledIconAttrId = KeyboardIconsSet.ATTR_UNDEFINED;
        mPreviewIconAttrId = KeyboardIconsSet.ATTR_UNDEFINED;
        mIconId = iconId;
        mDisabledIconId = KeyboardIconsSet.ICON_UNDEFINED;
        mPreviewIconId = KeyboardIconsSet.ICON_UNDEFINED;
        // Horizontal gap is divided equally to both sides of the key.
        mX = x + mHorizontalGap / 2;
        mY = y;
@@ -228,18 +217,16 @@ public class Key {
        mBackgroundType = style.getInt(keyAttr,
                R.styleable.Keyboard_Key_backgroundType, BACKGROUND_TYPE_NORMAL);

        final KeyboardIconsSet iconsSet = params.mIconsSet;
        mVisualInsetsLeft = (int) Keyboard.Builder.getDimensionOrFraction(keyAttr,
                R.styleable.Keyboard_Key_visualInsetsLeft, params.mBaseWidth, 0);
        mVisualInsetsRight = (int) Keyboard.Builder.getDimensionOrFraction(keyAttr,
                R.styleable.Keyboard_Key_visualInsetsRight, params.mBaseWidth, 0);
        mPreviewIconAttrId = KeyboardIconsSet.getIconAttrId(style.getInt(keyAttr,
                R.styleable.Keyboard_Key_keyIconPreview, KeyboardIconsSet.ICON_UNDEFINED));
        mIconAttrId = KeyboardIconsSet.getIconAttrId(style.getInt(keyAttr,
                R.styleable.Keyboard_Key_keyIcon, KeyboardIconsSet.ICON_UNDEFINED));
        mIcon = iconsSet.getIconByAttrId(mIconAttrId);
        mDisabledIconAttrId = KeyboardIconsSet.getIconAttrId(style.getInt(keyAttr,
                R.styleable.Keyboard_Key_keyIconDisabled, KeyboardIconsSet.ICON_UNDEFINED));
        mPreviewIconId = style.getInt(keyAttr,
                R.styleable.Keyboard_Key_keyIconPreview, KeyboardIconsSet.ICON_UNDEFINED);
        mIconId = style.getInt(keyAttr,
                R.styleable.Keyboard_Key_keyIcon, KeyboardIconsSet.ICON_UNDEFINED);
        mDisabledIconId = style.getInt(keyAttr,
                R.styleable.Keyboard_Key_keyIconDisabled, KeyboardIconsSet.ICON_UNDEFINED);

        mLabelFlags = style.getFlag(keyAttr, R.styleable.Keyboard_Key_keyLabelFlags, 0);
        final boolean preserveCase = (mLabelFlags & LABEL_FLAGS_PRESERVE_CASE) != 0;
@@ -336,16 +323,15 @@ public class Key {
                key.mCode,
                key.mLabel,
                key.mHintLabel,
                key.mIconAttrId,
                key.mIconId,
                key.mBackgroundType,
                // Key can be distinguishable without the following members.
                // key.mAltCode,
                // key.mOutputText,
                // key.mActionFlags,
                // key.mLabelFlags,
                // key.mIcon,
                // key.mDisabledIconAttrId,
                // key.mPreviewIconAttrId,
                // key.mDisabledIconId,
                // key.mPreviewIconId,
                // key.mHorizontalGap,
                // key.mVerticalGap,
                // key.mVisualInsetLeft,
@@ -364,7 +350,7 @@ public class Key {
                && o.mCode == mCode
                && TextUtils.equals(o.mLabel, mLabel)
                && TextUtils.equals(o.mHintLabel, mHintLabel)
                && o.mIconAttrId == mIconAttrId
                && o.mIconId == mIconId
                && o.mBackgroundType == mBackgroundType;
    }

@@ -382,7 +368,7 @@ public class Key {
    public String toString() {
        return String.format("%s/%s %d,%d %dx%d %s/%s/%s",
                Keyboard.printableCode(mCode), mLabel, mX, mY, mWidth, mHeight, mHintLabel,
                KeyboardIconsSet.getIconName(mIconAttrId), backgroundName(mBackgroundType));
                KeyboardIconsSet.getIconName(mIconId), backgroundName(mBackgroundType));
    }

    private static String backgroundName(int backgroundType) {
@@ -412,8 +398,8 @@ public class Key {
        mHitBox.bottom = params.mOccupiedHeight + params.mBottomPadding;
    }

    public boolean isSpacer() {
        return false;
    public final boolean isSpacer() {
        return this instanceof Spacer;
    }

    public boolean isShift() {
@@ -507,14 +493,18 @@ public class Key {
        return (mLabelFlags & LABEL_FLAGS_SHIFTED_LETTER_ACTIVATED) != 0;
    }

    // TODO: Get rid of this method.
    public Drawable getIcon(KeyboardIconsSet iconSet) {
        return mEnabled ? mIcon : iconSet.getIconByAttrId(mDisabledIconAttrId);
        return iconSet.getIconDrawable(mIconId);
    }

    // TODO: Get rid of this method.
    public void setIcon(Drawable icon) {
        mIcon = icon;
    public Drawable getDisabledIcon(KeyboardIconsSet iconSet) {
        return iconSet.getIconDrawable(mDisabledIconId);
    }

    public Drawable getPreviewIcon(KeyboardIconsSet iconSet) {
        return mPreviewIconId != KeyboardIconsSet.ICON_UNDEFINED
                ? iconSet.getIconDrawable(mPreviewIconId)
                : iconSet.getIconDrawable(mIconId);
    }

    /**
@@ -651,13 +641,9 @@ public class Key {
        /**
         * This constructor is being used only for divider in more keys keyboard.
         */
        public Spacer(Keyboard.Params params, Drawable icon, int x, int y, int width, int height) {
            super(params, null, null, icon, Keyboard.CODE_UNSPECIFIED, null, x, y, width, height);
        }

        @Override
        public boolean isSpacer() {
            return true;
        protected Spacer(Keyboard.Params params, int x, int y, int width, int height) {
            super(params, null, null, KeyboardIconsSet.ICON_UNDEFINED, Keyboard.CODE_UNSPECIFIED,
                    null, x, y, width, height);
        }
    }
}
+5 −6
Original line number Diff line number Diff line
@@ -185,7 +185,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
        public final int mKeyShiftedLetterHintInactivatedColor;
        public final int mKeyShiftedLetterHintActivatedColor;

        private final float mKeyLetterRatio;
        /* package */ final float mKeyLetterRatio;
        private final float mKeyLargeLetterRatio;
        private final float mKeyLabelRatio;
        private final float mKeyHintLetterRatio;
@@ -486,8 +486,9 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
    }

    private void onDrawKey(Key key, Canvas canvas, Paint paint, KeyDrawParams params) {
        if (key.isSpacer()) return;
        if (!key.isSpacer()) {
            onDrawKeyBackground(key, canvas, params);
        }
        onDrawKeyTopVisuals(key, canvas, paint, params);
    }

@@ -861,10 +862,8 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
            }
            previewText.setText(key.mLabel);
        } else {
            final Drawable previewIcon = mKeyboard.mIconsSet.getIconByAttrId(
                    key.mPreviewIconAttrId);
            previewText.setCompoundDrawables(null, null, null,
                    previewIcon != null ? previewIcon : key.getIcon(mKeyboard.mIconsSet));
                    key.getPreviewIcon(mKeyboard.mIconsSet));
            previewText.setText(null);
        }
        previewText.setBackgroundDrawable(params.mPreviewBackground);
+2 −1
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy;
import com.android.inputmethod.deprecated.VoiceProxy;
import com.android.inputmethod.keyboard.PointerTracker.DrawingProxy;
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.LatinImeLogger;
import com.android.inputmethod.latin.R;
@@ -393,7 +394,7 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
        mMoreKeysPanelCache.clear();

        mSpaceKey = keyboard.getKey(Keyboard.CODE_SPACE);
        mSpaceIcon = keyboard.mIconsSet.getIconByAttrId(R.styleable.Keyboard_iconSpaceKey);
        mSpaceIcon = keyboard.mIconsSet.getIconDrawable(KeyboardIconsSet.ICON_SPACE);
        final int keyHeight = keyboard.mMostCommonKeyHeight - keyboard.mVerticalGap;
        mSpacebarTextSize = keyHeight * mSpacebarTextRatio;
        mSpacebarLocale = keyboard.mId.mLocale;
+2 −2
Original line number Diff line number Diff line
@@ -179,11 +179,11 @@ public class KeySpecParser {
        return Keyboard.CODE_OUTPUT_TEXT;
    }

    public static int getIconAttrId(String moreKeySpec) {
    public static int getIconId(String moreKeySpec) {
        if (hasIcon(moreKeySpec)) {
            final int end = moreKeySpec.indexOf(LABEL_END, PREFIX_ICON.length());
            final String name = moreKeySpec.substring(PREFIX_ICON.length(), end);
            return KeyboardIconsSet.getIconAttrId(name);
            return KeyboardIconsSet.getIconId(name);
        }
        return KeyboardIconsSet.ICON_UNDEFINED;
    }
Loading