From e7c0e73a19e6eb6cb9a4aded8a0a7240db544d85 Mon Sep 17 00:00:00 2001
From: "Tadashi G. Takaoka" <takaoka@google.com>
Date: Thu, 7 Apr 2011 16:12:00 +0900
Subject: [PATCH] Simplify the Key's on state transition

Because handling shift locked state of alphabet keyboard is done by
KeyboardSwitcher, there is no need to change the "on" state of Key
when releasing the key. On the other hand, symbol and symbol shifted
keyboard has fixed "on" state "ALT/MORE" key.

This change also renames the attribute "isModifier" to "isFunctional".

Change-Id: I082885bd2376ae26bdfc378c14add2b5d6be1d4e
---
 java/res/values/attrs.xml                     |  4 +-
 java/res/xml-xlarge/kbd_key_styles.xml        |  2 +-
 java/res/xml/kbd_key_styles.xml               |  2 +-
 java/res/xml/kbd_qwerty_black_symbol.xml      |  8 ++--
 java/res/xml/kbd_qwerty_f1.xml                |  8 ++--
 .../com/android/inputmethod/keyboard/Key.java | 37 +++++++------------
 .../inputmethod/keyboard/KeyStyles.java       |  2 +-
 .../inputmethod/keyboard/Keyboard.java        |  2 +-
 .../keyboard/KeyboardSwitcher.java            | 12 +++---
 .../inputmethod/keyboard/PointerTracker.java  |  4 +-
 10 files changed, 34 insertions(+), 47 deletions(-)

diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml
index f0da2744be..28c948b657 100644
--- a/java/res/values/attrs.xml
+++ b/java/res/values/attrs.xml
@@ -107,8 +107,8 @@
             <!-- Key is anchored to the right of the keyboard. -->
             <flag name="right" value="2" />
         </attr>
-        <!-- Whether this is a modifier key such as Alt or Shift. -->
-        <attr name="isModifier" format="boolean" />
+        <!-- Whether this is a functional key which has different key top than normal key. -->
+        <attr name="isFunctional" format="boolean" />
         <!-- Whether this is a toggle key. -->
         <attr name="isSticky" format="boolean" />
         <!-- Whether long-pressing on this key will make it repeat. -->
diff --git a/java/res/xml-xlarge/kbd_key_styles.xml b/java/res/xml-xlarge/kbd_key_styles.xml
index fc06d00fca..4fefe0056e 100644
--- a/java/res/xml-xlarge/kbd_key_styles.xml
+++ b/java/res/xml-xlarge/kbd_key_styles.xml
@@ -28,7 +28,7 @@
         >
             <key-style
                 latin:styleName="functionalKeyStyle"
-                latin:isModifier="true" />
+                latin:isFunctional="true" />
             <key-style
                 latin:styleName="shiftKeyStyle"
                 latin:code="@integer/key_shift"
diff --git a/java/res/xml/kbd_key_styles.xml b/java/res/xml/kbd_key_styles.xml
index 473510ec4b..ea5d4ccd2e 100644
--- a/java/res/xml/kbd_key_styles.xml
+++ b/java/res/xml/kbd_key_styles.xml
@@ -28,7 +28,7 @@
         >
             <key-style
                 latin:styleName="functionalKeyStyle"
-                latin:isModifier="true" />
+                latin:isFunctional="true" />
             <key-style
                 latin:styleName="shiftKeyStyle"
                 latin:code="@integer/key_shift"
diff --git a/java/res/xml/kbd_qwerty_black_symbol.xml b/java/res/xml/kbd_qwerty_black_symbol.xml
index 6e45c12bfb..69e7e31d2b 100644
--- a/java/res/xml/kbd_qwerty_black_symbol.xml
+++ b/java/res/xml/kbd_qwerty_black_symbol.xml
@@ -38,7 +38,7 @@
                         latin:keyIcon="@drawable/sym_bkeyboard_123_mic"
                         latin:iconPreview="@drawable/sym_keyboard_feedback_123_mic"
                         latin:keyWidth="20%p"
-                        latin:isModifier="true"
+                        latin:isFunctional="true"
                         latin:keyEdgeFlags="left" />
                 </case>
                 <default>
@@ -46,7 +46,7 @@
                         latin:code="@integer/key_switch_alpha_symbol"
                         latin:keyLabel="@string/label_to_symbol_key"
                         latin:keyWidth="20%p"
-                        latin:isModifier="true"
+                        latin:isFunctional="true"
                         latin:keyEdgeFlags="left" />
                 </default>
             </switch>
@@ -67,7 +67,7 @@
                         latin:keyIcon="@drawable/sym_bkeyboard_123_mic"
                         latin:iconPreview="@drawable/sym_keyboard_feedback_123_mic"
                         latin:keyWidth="15%p"
-                        latin:isModifier="true"
+                        latin:isFunctional="true"
                         latin:keyEdgeFlags="left" />
                 </case>
                 <default>
@@ -75,7 +75,7 @@
                         latin:code="@integer/key_switch_alpha_symbol"
                         latin:keyLabel="@string/label_to_symbol_key"
                         latin:keyWidth="15%p"
-                        latin:isModifier="true"
+                        latin:isFunctional="true"
                         latin:keyEdgeFlags="left" />
                 </default>
             </switch>
diff --git a/java/res/xml/kbd_qwerty_f1.xml b/java/res/xml/kbd_qwerty_f1.xml
index 6bb96c0a0c..008448b26f 100644
--- a/java/res/xml/kbd_qwerty_f1.xml
+++ b/java/res/xml/kbd_qwerty_f1.xml
@@ -29,7 +29,7 @@
                 latin:keyLabel="/"
                 latin:keyHintIcon="@drawable/hint_popup"
                 latin:popupCharacters="@string/alternates_for_settings_slash"
-                latin:isModifier="true" />
+                latin:isFunctional="true" />
         </case>
         <case
             latin:mode="email"
@@ -38,7 +38,7 @@
                 latin:keyLabel="\@"
                 latin:keyHintIcon="@drawable/hint_popup"
                 latin:popupCharacters="@string/alternates_for_settings_at"
-                latin:isModifier="true" />
+                latin:isFunctional="true" />
         </case>
         <default>
             <switch>
@@ -57,7 +57,7 @@
                         >
                             <Key
                                 latin:keyLabel=","
-                                latin:isModifier="true" />
+                                latin:isFunctional="true" />
                         </case>
                         <case
                             latin:hasSettingsKey="false"
@@ -66,7 +66,7 @@
                                 latin:keyLabel=","
                                 latin:keyHintIcon="@drawable/hint_popup"
                                 latin:popupCharacters="@string/alternates_for_settings_comma"
-                                latin:isModifier="true" />
+                                latin:isFunctional="true" />
                         </case>
                     </switch>
                 </case>
diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java
index 7396f0518f..f578bd6130 100644
--- a/java/src/com/android/inputmethod/keyboard/Key.java
+++ b/java/src/com/android/inputmethod/keyboard/Key.java
@@ -83,8 +83,8 @@ public class Key {
      * {@link Keyboard#EDGE_TOP} and {@link Keyboard#EDGE_BOTTOM}.
      */
     public final int mEdgeFlags;
-    /** Whether this is a modifier key, such as Shift or Alt */
-    public final boolean mModifier;
+    /** Whether this is a functional key which has different key top than normal key */
+    public final boolean mFunctional;
     /** Whether this key repeats itself when held down */
     public final boolean mRepeatable;
 
@@ -93,8 +93,8 @@ public class Key {
 
     /** The current pressed state of this key */
     public boolean mPressed;
-    /** If this is a sticky key, is it on? */
-    public boolean mOn;
+    /** If this is a sticky key, is its highlight on? */
+    public boolean mHighlightOn;
     /** Key is enabled and responds on press */
     public boolean mEnabled = true;
 
@@ -150,7 +150,7 @@ public class Key {
         mManualTemporaryUpperCaseHintIcon = null;
         mManualTemporaryUpperCaseCode = Keyboard.CODE_DUMMY;
         mLabelOption = 0;
-        mModifier = false;
+        mFunctional = false;
         mSticky = false;
         mRepeatable = false;
         mPopupCharacters = null;
@@ -224,7 +224,7 @@ public class Key {
                     mKeyboard.getMaxPopupKeyboardColumn());
 
             mRepeatable = style.getBoolean(keyAttr, R.styleable.Keyboard_Key_isRepeatable, false);
-            mModifier = style.getBoolean(keyAttr, R.styleable.Keyboard_Key_isModifier, false);
+            mFunctional = style.getBoolean(keyAttr, R.styleable.Keyboard_Key_isFunctional, false);
             mSticky = style.getBoolean(keyAttr, R.styleable.Keyboard_Key_isSticky, false);
             mEnabled = style.getBoolean(keyAttr, R.styleable.Keyboard_Key_enabled, true);
             mEdgeFlags = style.getFlag(keyAttr, R.styleable.Keyboard_Key_keyEdgeFlags, 0)
@@ -315,22 +315,19 @@ public class Key {
     /**
      * Informs the key that it has been pressed, in case it needs to change its appearance or
      * state.
-     * @see #onReleased(boolean)
+     * @see #onReleased()
      */
     public void onPressed() {
-        mPressed = !mPressed;
+        mPressed = true;
     }
 
     /**
-     * Changes the pressed state of the key. If it is a sticky key, it will also change the
-     * toggled state of the key if the finger was release inside.
-     * @param inside whether the finger was released inside the key
+     * Informs the key that it has been released, in case it needs to change its appearance or
+     * state.
      * @see #onPressed()
      */
-    public void onReleased(boolean inside) {
-        mPressed = !mPressed;
-        if (mSticky && !mKeyboard.isShiftLockEnabled(this))
-            mOn = !mOn;
+    public void onReleased() {
+        mPressed = false;
     }
 
     public boolean isInside(int x, int y) {
@@ -376,12 +373,6 @@ public class Key {
         return dx * dx + dy * dy;
     }
 
-    // sticky is used for shift key.  If a key is not sticky and is modifier,
-    // the key will be treated as functional.
-    private boolean isFunctionalKey() {
-        return !mSticky && mModifier;
-    }
-
     /**
      * Returns the drawable state for the key, based on the current state and type of the key.
      * @return the drawable state of the key.
@@ -389,7 +380,7 @@ public class Key {
      */
     public int[] getCurrentDrawableState() {
         final boolean pressed = mEnabled && mPressed;
-        if (isFunctionalKey()) {
+        if (!mSticky && mFunctional) {
             if (pressed) {
                 return KEY_STATE_FUNCTIONAL_PRESSED;
             } else {
@@ -399,7 +390,7 @@ public class Key {
 
         int[] states = KEY_STATE_NORMAL;
 
-        if (mOn) {
+        if (mHighlightOn) {
             if (pressed) {
                 states = KEY_STATE_PRESSED_ON;
             } else {
diff --git a/java/src/com/android/inputmethod/keyboard/KeyStyles.java b/java/src/com/android/inputmethod/keyboard/KeyStyles.java
index 169f2e6c3e..d464c2029f 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyStyles.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyStyles.java
@@ -185,7 +185,7 @@ public class KeyStyles {
             readDrawable(keyAttr, R.styleable.Keyboard_Key_iconPreview);
             readDrawable(keyAttr, R.styleable.Keyboard_Key_keyHintIcon);
             readDrawable(keyAttr, R.styleable.Keyboard_Key_shiftedIcon);
-            readBoolean(keyAttr, R.styleable.Keyboard_Key_isModifier);
+            readBoolean(keyAttr, R.styleable.Keyboard_Key_isFunctional);
             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/Keyboard.java b/java/src/com/android/inputmethod/keyboard/Keyboard.java
index 06d44680d6..418188209c 100644
--- a/java/src/com/android/inputmethod/keyboard/Keyboard.java
+++ b/java/src/com/android/inputmethod/keyboard/Keyboard.java
@@ -293,7 +293,7 @@ public class Keyboard {
     public boolean setShiftLocked(boolean newShiftLockState) {
         final Map<Key, Drawable> shiftedIcons = getShiftedIcons();
         for (final Key key : getShiftKeys()) {
-            key.mOn = newShiftLockState;
+            key.mHighlightOn = newShiftLockState;
             key.setIcon(newShiftLockState ? shiftedIcons.get(key) : mNormalShiftIcons.get(key));
         }
         mShiftState.setShiftLocked(newShiftLockState);
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
index cfa3c446e6..dd25b34278 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
@@ -263,10 +263,10 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
         int xmlId = mode == KeyboardId.MODE_PHONE ? R.xml.kbd_phone : R.xml.kbd_symbols;
         final String xmlName = res.getResourceEntryName(xmlId);
         mSymbolsId = new KeyboardId(xmlName, xmlId, colorScheme, locale, orientation, mode,
-                attribute, hasSettingsKey, mVoiceKeyEnabled, hasVoiceKey, true);
+                attribute, hasSettingsKey, mVoiceKeyEnabled, hasVoiceKey, false);
         xmlId = mode == KeyboardId.MODE_PHONE ? R.xml.kbd_phone_symbols : R.xml.kbd_symbols_shift;
         mSymbolsShiftedId = new KeyboardId(xmlName, xmlId, colorScheme, locale, orientation, mode,
-                attribute, hasSettingsKey, mVoiceKeyEnabled, hasVoiceKey, true);
+                attribute, hasSettingsKey, mVoiceKeyEnabled, hasVoiceKey, false);
     }
 
     public int getKeyboardMode() {
@@ -565,16 +565,14 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
             mCurrentId = mSymbolsShiftedId;
             keyboard = getKeyboard(mCurrentId);
             // Symbol shifted keyboard has an ALT key that has a caps lock style indicator. To
-            // enable the indicator, we need to call enableShiftLock() and setShiftLocked(true).
-            // Thus we can keep the ALT key's Key.on value true while LatinKey.onRelease() is
-            // called.
+            // enable the indicator, we need to call setShiftLocked(true).
             keyboard.setShiftLocked(true);
         } else {
             mCurrentId = mSymbolsId;
             keyboard = getKeyboard(mCurrentId);
             // Symbol keyboard has an ALT key that has a caps lock style indicator. To disable the
-            // indicator, we need to call enableShiftLock() and setShiftLocked(false).
-            keyboard.setShifted(false);
+            // indicator, we need to call setShiftLocked(false).
+            keyboard.setShiftLocked(false);
         }
         setKeyboard(keyboard);
     }
diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
index 1c918b9952..c28197014a 100644
--- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java
+++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
@@ -258,9 +258,7 @@ public class PointerTracker {
         mPreviousKey = keyIndex;
         if (keyIndex != oldKeyIndex) {
             if (isValidKeyIndex(oldKeyIndex)) {
-                // if new key index is not a key, old key was just released inside of the key.
-                final boolean inside = (keyIndex == NOT_A_KEY);
-                mKeys[oldKeyIndex].onReleased(inside);
+                mKeys[oldKeyIndex].onReleased();
                 mProxy.invalidateKey(mKeys[oldKeyIndex]);
             }
             if (isValidKeyIndex(keyIndex)) {
-- 
GitLab