Methods Summary |
---|
private long | getCurrentTime()
return System.currentTimeMillis();
|
public void | handleTimerEvent(int state)
switch (mState) {
case STATE_CHECKING_LONGPRESS:
// The first key press lasts long enough to start press-and-hold.
mActionTimer.clearTimerMessage();
mState = STATE_PROCESSING_KEYCODE;
sendKeyDown(mLastKeycode);
mLastSendKeyTime = getCurrentTime();
addTimer(mState, AWAIT_RELEASE_KEY_MS);
break;
case STATE_PROCESSING_KEYCODE:
// Timeout on waiting for the release key event. Send UCR and quit the action.
sendKeyUp();
finish();
break;
default:
Slog.w(TAG, "Not in a valid state");
break;
}
|
public boolean | processCommand(HdmiCecMessage cmd)
// Send key action doesn't need any incoming CEC command, hence does not consume it.
return false;
|
void | processKeyEvent(int keycode, boolean isPressed)Called when a key event should be handled for the action.
if (mState != STATE_CHECKING_LONGPRESS && mState != STATE_PROCESSING_KEYCODE) {
Slog.w(TAG, "Not in a valid state");
return;
}
if (isPressed) {
// A new key press event that comes in with a key code different from the last
// one becomes a new key code to be used for press-and-hold operation.
if (keycode != mLastKeycode) {
sendKeyDown(keycode);
mLastSendKeyTime = getCurrentTime();
if (!HdmiCecKeycode.isRepeatableKey(keycode)) {
sendKeyUp();
finish();
return;
}
} else {
// Press-and-hold key transmission takes place if Android key inputs are
// repeatedly coming in and more than IRT_MS has passed since the last
// press-and-hold key transmission.
if (getCurrentTime() - mLastSendKeyTime >= IRT_MS) {
sendKeyDown(keycode);
mLastSendKeyTime = getCurrentTime();
}
}
mActionTimer.clearTimerMessage();
addTimer(mState, AWAIT_RELEASE_KEY_MS);
mLastKeycode = keycode;
} else {
// Key release event indicates that the action shall be finished. Send UCR
// command and terminate the action. Other release events are ignored.
if (keycode == mLastKeycode) {
sendKeyUp();
finish();
}
}
|
private void | sendKeyDown(int keycode)
byte[] cecKeycodeAndParams = HdmiCecKeycode.androidKeyToCecKey(keycode);
if (cecKeycodeAndParams == null) {
return;
}
sendCommand(HdmiCecMessageBuilder.buildUserControlPressed(getSourceAddress(),
mTargetAddress, cecKeycodeAndParams));
|
private void | sendKeyUp()
sendCommand(HdmiCecMessageBuilder.buildUserControlReleased(getSourceAddress(),
mTargetAddress));
|
public boolean | start()
sendKeyDown(mLastKeycode);
mLastSendKeyTime = getCurrentTime();
// finish action for non-repeatable key.
if (!HdmiCecKeycode.isRepeatableKey(mLastKeycode)) {
sendKeyUp();
finish();
return true;
}
mState = STATE_CHECKING_LONGPRESS;
addTimer(mState, AWAIT_LONGPRESS_MS);
return true;
|