From 017e9f7e7fa45add58af80165902843fe1e8dedb Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Wed, 6 Aug 2014 17:23:14 +0900 Subject: [PATCH] Add dedicated background for custom action label key Bug: 15526978 Change-Id: Ia73d825c7e00097018822704e61272d0e448f39a --- .../drawable/btn_keyboard_key_lxx_dark.xml | 5 + .../drawable/btn_keyboard_key_lxx_light.xml | 5 + java/res/values/attrs.xml | 7 +- java/res/xml-sw600dp/key_styles_enter.xml | 1 + java/res/xml/key_styles_enter.xml | 1 + .../com/android/inputmethod/keyboard/Key.java | 100 +++++++----------- 6 files changed, 52 insertions(+), 67 deletions(-) diff --git a/java/res/drawable/btn_keyboard_key_lxx_dark.xml b/java/res/drawable/btn_keyboard_key_lxx_dark.xml index bb1789ae3..c82c13829 100644 --- a/java/res/drawable/btn_keyboard_key_lxx_dark.xml +++ b/java/res/drawable/btn_keyboard_key_lxx_dark.xml @@ -15,6 +15,11 @@ --> + + + diff --git a/java/res/drawable/btn_keyboard_key_lxx_light.xml b/java/res/drawable/btn_keyboard_key_lxx_light.xml index 60fe02dd2..f237fbea9 100644 --- a/java/res/drawable/btn_keyboard_key_lxx_light.xml +++ b/java/res/drawable/btn_keyboard_key_lxx_light.xml @@ -15,6 +15,11 @@ --> + + + diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml index 9a2227321..e6215c254 100644 --- a/java/res/values/attrs.xml +++ b/java/res/values/attrs.xml @@ -270,9 +270,10 @@ - - - + + + + diff --git a/java/res/xml-sw600dp/key_styles_enter.xml b/java/res/xml-sw600dp/key_styles_enter.xml index 740bf3543..d0167d336 100644 --- a/java/res/xml-sw600dp/key_styles_enter.xml +++ b/java/res/xml-sw600dp/key_styles_enter.xml @@ -230,6 +230,7 @@ latin:styleName="enterKeyStyle" latin:keySpec="dummy_label|!code/key_enter" latin:keyLabelFlags="fromCustomActionLabel" + latin:backgroundType="customAction" latin:parentStyle="defaultEnterKeyStyle" /> diff --git a/java/res/xml/key_styles_enter.xml b/java/res/xml/key_styles_enter.xml index 770bf3876..960c79c18 100644 --- a/java/res/xml/key_styles_enter.xml +++ b/java/res/xml/key_styles_enter.xml @@ -398,6 +398,7 @@ latin:styleName="enterKeyStyle" latin:keySpec="dummy_label|!code/key_enter" latin:keyLabelFlags="fromCustomActionLabel" + latin:backgroundType="customAction" latin:parentStyle="defaultEnterKeyStyle" /> diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java index af54fb674..55ce7dd34 100644 --- a/java/src/com/android/inputmethod/keyboard/Key.java +++ b/java/src/com/android/inputmethod/keyboard/Key.java @@ -123,9 +123,10 @@ public class Key implements Comparable { public static final int BACKGROUND_TYPE_EMPTY = 0; public static final int BACKGROUND_TYPE_NORMAL = 1; public static final int BACKGROUND_TYPE_FUNCTIONAL = 2; - public static final int BACKGROUND_TYPE_ACTION = 3; - public static final int BACKGROUND_TYPE_STICKY_OFF = 4; - public static final int BACKGROUND_TYPE_STICKY_ON = 5; + public static final int BACKGROUND_TYPE_STICKY_OFF = 3; + public static final int BACKGROUND_TYPE_STICKY_ON = 4; + public static final int BACKGROUND_TYPE_ACTION = 5; + public static final int BACKGROUND_TYPE_CUSTOM_ACTION = 6; private final int mActionFlags; private static final int ACTION_FLAGS_IS_REPEATABLE = 0x01; @@ -483,9 +484,10 @@ public class Key implements Comparable { case BACKGROUND_TYPE_EMPTY: return "empty"; case BACKGROUND_TYPE_NORMAL: return "normal"; case BACKGROUND_TYPE_FUNCTIONAL: return "functional"; - case BACKGROUND_TYPE_ACTION: return "action"; case BACKGROUND_TYPE_STICKY_OFF: return "stickyOff"; case BACKGROUND_TYPE_STICKY_ON: return "stickyOn"; + case BACKGROUND_TYPE_ACTION: return "action"; + case BACKGROUND_TYPE_CUSTOM_ACTION: return "customAction"; default: return null; } } @@ -814,47 +816,37 @@ public class Key implements Comparable { return dx * dx + dy * dy; } - private final static int[] KEY_STATE_NORMAL_HIGHLIGHT_ON = { - android.R.attr.state_checkable, - android.R.attr.state_checked - }; + static class KeyBackgroundState { + private final int[] mReleasedState; + private final int[] mPressedState; - 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 KeyBackgroundState(final int ... attrs) { + mReleasedState = attrs; + mPressedState = Arrays.copyOf(attrs, attrs.length + 1); + mPressedState[attrs.length] = android.R.attr.state_pressed; + } - private final static int[] KEY_STATE_NORMAL_HIGHLIGHT_OFF = { - android.R.attr.state_checkable - }; + public int[] getState(final boolean pressed) { + return pressed ? mPressedState : mReleasedState; + } - 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 - }; - - private final static int[] KEY_STATE_EMPTY = { - android.R.attr.state_empty - }; - - // 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 - }; + public static final KeyBackgroundState[] STATES = { + // 0: BACKGROUND_TYPE_EMPTY + new KeyBackgroundState(android.R.attr.state_empty), + // 1: BACKGROUND_TYPE_NORMAL + new KeyBackgroundState(), + // 2: BACKGROUND_TYPE_FUNCTIONAL + new KeyBackgroundState(), + // 3: BACKGROUND_TYPE_STICKY_OFF + new KeyBackgroundState(android.R.attr.state_checkable), + // 4: BACKGROUND_TYPE_STICKY_ON + new KeyBackgroundState(android.R.attr.state_checkable, android.R.attr.state_checked), + // 5: BACKGROUND_TYPE_ACTION + new KeyBackgroundState(android.R.attr.state_active), + // 6: BACKGROUND_TYPE_CUSTOM_ACTION + new KeyBackgroundState(android.R.attr.state_active, android.R.attr.state_checked) + }; + } /** * Returns the background drawable for the key, based on the current state and type of the key. @@ -871,28 +863,8 @@ public class Key implements Comparable { } else { background = keyBackground; } - final int[] stateSet; - switch (mBackgroundType) { - case BACKGROUND_TYPE_ACTION: - stateSet = mPressed ? KEY_STATE_ACTIVE_PRESSED : KEY_STATE_ACTIVE_NORMAL; - break; - case BACKGROUND_TYPE_STICKY_OFF: - stateSet = mPressed ? KEY_STATE_PRESSED_HIGHLIGHT_OFF : KEY_STATE_NORMAL_HIGHLIGHT_OFF; - break; - case BACKGROUND_TYPE_STICKY_ON: - stateSet = mPressed ? KEY_STATE_PRESSED_HIGHLIGHT_ON : KEY_STATE_NORMAL_HIGHLIGHT_ON; - break; - case BACKGROUND_TYPE_EMPTY: - stateSet = mPressed ? KEY_STATE_PRESSED : KEY_STATE_EMPTY; - break; - case BACKGROUND_TYPE_FUNCTIONAL: - stateSet = mPressed ? KEY_STATE_PRESSED : KEY_STATE_NORMAL; - break; - default: /* BACKGROUND_TYPE_NORMAL */ - stateSet = mPressed ? KEY_STATE_PRESSED : KEY_STATE_NORMAL; - break; - } - background.setState(stateSet); + final int[] state = KeyBackgroundState.STATES[mBackgroundType].getState(mPressed); + background.setState(state); return background; }