From 5b0c124ca888ee4ecbde9a51f11c4e9887a96636 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Thu, 15 Sep 2011 17:54:21 +0900 Subject: [PATCH] Remove Key.isStick, use backgroundType="stick" instead Change-Id: I50e88c0870a3fe360b81f19163ca2f64ec38d8e8 --- java/res/values/attrs.xml | 3 +- java/res/xml-sw600dp/kbd_key_styles.xml | 3 +- java/res/xml-sw768dp/kbd_key_styles.xml | 3 +- java/res/xml/kbd_key_styles.xml | 3 +- .../com/android/inputmethod/keyboard/Key.java | 122 +++++++++--------- .../keyboard/internal/KeyStyles.java | 1 - .../keyboard/internal/KeyboardParams.java | 2 +- 7 files changed, 65 insertions(+), 72 deletions(-) diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml index 0451c9f94..6e9461a33 100644 --- a/java/res/values/attrs.xml +++ b/java/res/values/attrs.xml @@ -199,9 +199,8 @@ + - - diff --git a/java/res/xml-sw600dp/kbd_key_styles.xml b/java/res/xml-sw600dp/kbd_key_styles.xml index d86a01dc1..0b6d87126 100644 --- a/java/res/xml-sw600dp/kbd_key_styles.xml +++ b/java/res/xml-sw600dp/kbd_key_styles.xml @@ -44,8 +44,7 @@ latin:code="@integer/key_shift" latin:keyIcon="iconShiftKey" latin:keyIconShifted="iconShiftedShiftKey" - latin:backgroundType="functional" - latin:isSticky="true" /> + latin:backgroundType="sticky" /> + latin:backgroundType="sticky" /> + latin:backgroundType="sticky" /> sRtlParenthesisMap = new HashMap(); @@ -242,7 +192,6 @@ public class Key { mHintLabel = hintLabel; mLabelOption = 0; mBackgroundType = BACKGROUND_TYPE_NORMAL; - mSticky = false; mRepeatable = false; mMoreKeys = null; mMaxMoreKeysColumn = 0; @@ -344,7 +293,6 @@ public class Key { mBackgroundType = style.getInt( keyAttr, R.styleable.Keyboard_Key_backgroundType, BACKGROUND_TYPE_NORMAL); mRepeatable = style.getBoolean(keyAttr, R.styleable.Keyboard_Key_isRepeatable, false); - mSticky = style.getBoolean(keyAttr, R.styleable.Keyboard_Key_isSticky, false); mEnabled = style.getBoolean(keyAttr, R.styleable.Keyboard_Key_enabled, true); mEdgeFlags = 0; @@ -388,6 +336,10 @@ public class Key { mEdgeFlags |= flags; } + public boolean isSticky() { + return mBackgroundType == BACKGROUND_TYPE_STICKY; + } + public boolean isSpacer() { return false; } @@ -550,6 +502,55 @@ public class Key { return dx * dx + dy * dy; } + private final static int[] KEY_STATE_NORMAL_HIGHLIGHT_ON = { + android.R.attr.state_checkable, + android.R.attr.state_checked + }; + + private final static int[] KEY_STATE_PRESSED_HIGHLIGHT_ON = { + android.R.attr.state_pressed, + android.R.attr.state_checkable, + android.R.attr.state_checked + }; + + private final static int[] KEY_STATE_NORMAL_HIGHLIGHT_OFF = { + android.R.attr.state_checkable + }; + + private final static int[] KEY_STATE_PRESSED_HIGHLIGHT_OFF = { + android.R.attr.state_pressed, + android.R.attr.state_checkable + }; + + private final static int[] KEY_STATE_NORMAL = { + }; + + private final static int[] KEY_STATE_PRESSED = { + android.R.attr.state_pressed + }; + + // functional normal state (with properties) + private static final int[] KEY_STATE_FUNCTIONAL_NORMAL = { + android.R.attr.state_single + }; + + // functional pressed state (with properties) + private static final int[] KEY_STATE_FUNCTIONAL_PRESSED = { + android.R.attr.state_single, + android.R.attr.state_pressed + }; + + // action normal state (with properties) + private static final int[] KEY_STATE_ACTIVE_NORMAL = { + android.R.attr.state_active + }; + + // action pressed state (with properties) + private static final int[] KEY_STATE_ACTIVE_PRESSED = { + android.R.attr.state_active, + android.R.attr.state_pressed + }; + /** * Returns the drawable state for the key, based on the current state and type of the key. * @return the drawable state of the key. @@ -558,20 +559,17 @@ public class Key { public int[] getCurrentDrawableState() { final boolean pressed = mPressed; - // TODO: "Sticky" should be one of backgroundType. - if (mSticky) { - if (mHighlightOn) { - return pressed ? KEY_STATE_PRESSED_ON : KEY_STATE_NORMAL_ON; - } else { - return pressed ? KEY_STATE_PRESSED_OFF : KEY_STATE_NORMAL_OFF; - } - } - switch (mBackgroundType) { case BACKGROUND_TYPE_FUNCTIONAL: return pressed ? KEY_STATE_FUNCTIONAL_PRESSED : KEY_STATE_FUNCTIONAL_NORMAL; case BACKGROUND_TYPE_ACTION: return pressed ? KEY_STATE_ACTIVE_PRESSED : KEY_STATE_ACTIVE_NORMAL; + case BACKGROUND_TYPE_STICKY: + if (mHighlightOn) { + return pressed ? KEY_STATE_PRESSED_HIGHLIGHT_ON : KEY_STATE_NORMAL_HIGHLIGHT_ON; + } else { + return pressed ? KEY_STATE_PRESSED_HIGHLIGHT_OFF : KEY_STATE_NORMAL_HIGHLIGHT_OFF; + } default: /* BACKGROUND_TYPE_NORMAL */ return pressed ? KEY_STATE_PRESSED : KEY_STATE_NORMAL; } diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java b/java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java index 9800f245a..3d2d77cf4 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java @@ -173,7 +173,6 @@ public class KeyStyles { readInt(keyAttr, R.styleable.Keyboard_Key_keyIconShifted); readInt(keyAttr, R.styleable.Keyboard_Key_maxMoreKeysColumn); readInt(keyAttr, R.styleable.Keyboard_Key_backgroundType); - readBoolean(keyAttr, R.styleable.Keyboard_Key_isSticky); readBoolean(keyAttr, R.styleable.Keyboard_Key_isRepeatable); readBoolean(keyAttr, R.styleable.Keyboard_Key_enabled); } diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java index 4432ee121..593c3dc5b 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java @@ -78,7 +78,7 @@ public class KeyboardParams { updateHistogram(key); if (key.mCode == Keyboard.CODE_SHIFT) { mShiftKeys.add(key); - if (key.mSticky) { + if (key.isSticky()) { mShiftLockKeys.add(key); } }