Shift Keys on Android
Shift Keys on Android
When you press the CAPS button, a little green dot appears. At this point, you might be wondering: why?Source code
Diving into the Keyboard.java source code, we find the following:@Override
public void onCreateInputView() {
public static final int KEYCODE_SHIFT = -1;
...
public boolean setShifted(boolean shiftState) {
for (Key shiftKey : mShiftKeys) {
if (shiftKey != null) {
shiftKey.on = shiftState;
}
}
if (mShifted != shiftState) {
mShifted = shiftState;
return true;
}
return false;
}
...
if (key.codes[0] == KEYCODE_SHIFT) {
// Find available shift key slot and put this shift key in it
for (int i = 0; i < mShiftKeys.length; i++) {
if (mShiftKeys[i] == null) {
mShiftKeys[i] = key;
mShiftKeyIndices[i] = mKeys.size()-1;
break;
}
}
mModifierKeys.add(key);
} else if (key.codes[0] == KEYCODE_ALT) {
mModifierKeys.add(key);
}
...
public int[] getCurrentDrawableState() {
int[] states = KEY_STATE_NORMAL;
if (on) {
if (pressed) {
states = KEY_STATE_PRESSED_ON;
} else {
states = KEY_STATE_NORMAL_ON;
}
} else {
if (sticky) {
if (pressed) {
states = KEY_STATE_PRESSED_OFF;
} else {
states = KEY_STATE_NORMAL_OFF;
}
} else {
if (pressed) {
states = KEY_STATE_PRESSED;
}
}
}
return states;
}
}
So if the first keyCode is equal to KEYCODE_SHIFT
, i.e. -1, then it gets turned on and rendered differently. When we look up these constants, we find that "on" corresponds to android.R.attr.state_checked
.That's all I know and understand at this point.
Comments
Post a Comment