Remove Key.isStick, use backgroundType="stick" instead

Change-Id: I50e88c0870a3fe360b81f19163ca2f64ec38d8e8
main
Tadashi G. Takaoka 2011-09-15 17:54:21 +09:00
parent a1b68eb126
commit 5b0c124ca8
7 changed files with 65 additions and 72 deletions

View File

@ -199,9 +199,8 @@
<enum name="normal" value="0" /> <enum name="normal" value="0" />
<enum name="functional" value="1" /> <enum name="functional" value="1" />
<enum name="action" value="2" /> <enum name="action" value="2" />
<enum name="sticky" value="3" />
</attr> </attr>
<!-- Whether this is a toggle key. -->
<attr name="isSticky" format="boolean" />
<!-- Whether long-pressing on this key will make it repeat. --> <!-- Whether long-pressing on this key will make it repeat. -->
<attr name="isRepeatable" format="boolean" /> <attr name="isRepeatable" format="boolean" />
<!-- The string of characters to output when this key is pressed. --> <!-- The string of characters to output when this key is pressed. -->

View File

@ -44,8 +44,7 @@
latin:code="@integer/key_shift" latin:code="@integer/key_shift"
latin:keyIcon="iconShiftKey" latin:keyIcon="iconShiftKey"
latin:keyIconShifted="iconShiftedShiftKey" latin:keyIconShifted="iconShiftedShiftKey"
latin:backgroundType="functional" latin:backgroundType="sticky" />
latin:isSticky="true" />
<key-style <key-style
latin:styleName="deleteKeyStyle" latin:styleName="deleteKeyStyle"
latin:code="@integer/key_delete" latin:code="@integer/key_delete"

View File

@ -26,8 +26,7 @@
latin:code="@integer/key_shift" latin:code="@integer/key_shift"
latin:keyIcon="iconShiftKey" latin:keyIcon="iconShiftKey"
latin:keyIconShifted="iconShiftedShiftKey" latin:keyIconShifted="iconShiftedShiftKey"
latin:backgroundType="functional" latin:backgroundType="sticky" />
latin:isSticky="true" />
<key-style <key-style
latin:styleName="deleteKeyStyle" latin:styleName="deleteKeyStyle"
latin:code="@integer/key_delete" latin:code="@integer/key_delete"

View File

@ -67,8 +67,7 @@
latin:code="@integer/key_shift" latin:code="@integer/key_shift"
latin:keyIcon="iconShiftKey" latin:keyIcon="iconShiftKey"
latin:keyIconShifted="iconShiftedShiftKey" latin:keyIconShifted="iconShiftedShiftKey"
latin:backgroundType="functional" latin:backgroundType="sticky" />
latin:isSticky="true" />
<key-style <key-style
latin:styleName="deleteKeyStyle" latin:styleName="deleteKeyStyle"
latin:code="@integer/key_delete" latin:code="@integer/key_delete"

View File

@ -82,8 +82,6 @@ public class Key {
/** The visual insets */ /** The visual insets */
public final int mVisualInsetsLeft; public final int mVisualInsetsLeft;
public final int mVisualInsetsRight; public final int mVisualInsetsRight;
/** Whether this key is sticky, i.e., a toggle key */
public final boolean mSticky;
/** X coordinate of the key in the keyboard layout */ /** X coordinate of the key in the keyboard layout */
public final int mX; public final int mX;
/** Y coordinate of the key in the keyboard layout */ /** Y coordinate of the key in the keyboard layout */
@ -108,6 +106,7 @@ public class Key {
public static final int BACKGROUND_TYPE_NORMAL = 0; public static final int BACKGROUND_TYPE_NORMAL = 0;
public static final int BACKGROUND_TYPE_FUNCTIONAL = 1; public static final int BACKGROUND_TYPE_FUNCTIONAL = 1;
public static final int BACKGROUND_TYPE_ACTION = 2; public static final int BACKGROUND_TYPE_ACTION = 2;
public static final int BACKGROUND_TYPE_STICKY = 3;
/** Whether this key repeats itself when held down */ /** Whether this key repeats itself when held down */
public final boolean mRepeatable; public final boolean mRepeatable;
@ -126,55 +125,6 @@ public class Key {
private static final int KEYWIDTH_FILL_RIGHT = -1; private static final int KEYWIDTH_FILL_RIGHT = -1;
private static final int KEYWIDTH_FILL_BOTH = -2; private static final int KEYWIDTH_FILL_BOTH = -2;
private final static int[] KEY_STATE_NORMAL_ON = {
android.R.attr.state_checkable,
android.R.attr.state_checked
};
private final static int[] KEY_STATE_PRESSED_ON = {
android.R.attr.state_pressed,
android.R.attr.state_checkable,
android.R.attr.state_checked
};
private final static int[] KEY_STATE_NORMAL_OFF = {
android.R.attr.state_checkable
};
private final static int[] KEY_STATE_PRESSED_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
};
// RTL parenthesis character swapping map. // RTL parenthesis character swapping map.
private static final Map<Integer, Integer> sRtlParenthesisMap = new HashMap<Integer, Integer>(); private static final Map<Integer, Integer> sRtlParenthesisMap = new HashMap<Integer, Integer>();
@ -242,7 +192,6 @@ public class Key {
mHintLabel = hintLabel; mHintLabel = hintLabel;
mLabelOption = 0; mLabelOption = 0;
mBackgroundType = BACKGROUND_TYPE_NORMAL; mBackgroundType = BACKGROUND_TYPE_NORMAL;
mSticky = false;
mRepeatable = false; mRepeatable = false;
mMoreKeys = null; mMoreKeys = null;
mMaxMoreKeysColumn = 0; mMaxMoreKeysColumn = 0;
@ -344,7 +293,6 @@ public class Key {
mBackgroundType = style.getInt( mBackgroundType = style.getInt(
keyAttr, R.styleable.Keyboard_Key_backgroundType, BACKGROUND_TYPE_NORMAL); keyAttr, R.styleable.Keyboard_Key_backgroundType, BACKGROUND_TYPE_NORMAL);
mRepeatable = style.getBoolean(keyAttr, R.styleable.Keyboard_Key_isRepeatable, false); 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); mEnabled = style.getBoolean(keyAttr, R.styleable.Keyboard_Key_enabled, true);
mEdgeFlags = 0; mEdgeFlags = 0;
@ -388,6 +336,10 @@ public class Key {
mEdgeFlags |= flags; mEdgeFlags |= flags;
} }
public boolean isSticky() {
return mBackgroundType == BACKGROUND_TYPE_STICKY;
}
public boolean isSpacer() { public boolean isSpacer() {
return false; return false;
} }
@ -550,6 +502,55 @@ public class Key {
return dx * dx + dy * dy; 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. * Returns the drawable state for the key, based on the current state and type of the key.
* @return the drawable state of the key. * @return the drawable state of the key.
@ -558,20 +559,17 @@ public class Key {
public int[] getCurrentDrawableState() { public int[] getCurrentDrawableState() {
final boolean pressed = mPressed; 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) { switch (mBackgroundType) {
case BACKGROUND_TYPE_FUNCTIONAL: case BACKGROUND_TYPE_FUNCTIONAL:
return pressed ? KEY_STATE_FUNCTIONAL_PRESSED : KEY_STATE_FUNCTIONAL_NORMAL; return pressed ? KEY_STATE_FUNCTIONAL_PRESSED : KEY_STATE_FUNCTIONAL_NORMAL;
case BACKGROUND_TYPE_ACTION: case BACKGROUND_TYPE_ACTION:
return pressed ? KEY_STATE_ACTIVE_PRESSED : KEY_STATE_ACTIVE_NORMAL; 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 */ default: /* BACKGROUND_TYPE_NORMAL */
return pressed ? KEY_STATE_PRESSED : KEY_STATE_NORMAL; return pressed ? KEY_STATE_PRESSED : KEY_STATE_NORMAL;
} }

View File

@ -173,7 +173,6 @@ public class KeyStyles {
readInt(keyAttr, R.styleable.Keyboard_Key_keyIconShifted); readInt(keyAttr, R.styleable.Keyboard_Key_keyIconShifted);
readInt(keyAttr, R.styleable.Keyboard_Key_maxMoreKeysColumn); readInt(keyAttr, R.styleable.Keyboard_Key_maxMoreKeysColumn);
readInt(keyAttr, R.styleable.Keyboard_Key_backgroundType); 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_isRepeatable);
readBoolean(keyAttr, R.styleable.Keyboard_Key_enabled); readBoolean(keyAttr, R.styleable.Keyboard_Key_enabled);
} }

View File

@ -78,7 +78,7 @@ public class KeyboardParams {
updateHistogram(key); updateHistogram(key);
if (key.mCode == Keyboard.CODE_SHIFT) { if (key.mCode == Keyboard.CODE_SHIFT) {
mShiftKeys.add(key); mShiftKeys.add(key);
if (key.mSticky) { if (key.isSticky()) {
mShiftLockKeys.add(key); mShiftLockKeys.add(key);
} }
} }