@Override public boolean onKeyDown(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_MENU: if (Receiver.call_state == UserAgent.UA_STATE_INCOMING_CALL && mSlidingCardManager == null) { answer(); return true; } break; case KeyEvent.KEYCODE_CALL: switch (Receiver.call_state) { case UserAgent.UA_STATE_INCOMING_CALL: answer(); break; case UserAgent.UA_STATE_INCALL: case UserAgent.UA_STATE_HOLD: Receiver.engine(this).togglehold(); break; } // consume KEYCODE_CALL so PhoneWindow doesn't do anything with it return true; case KeyEvent.KEYCODE_BACK: if (mDialerDrawer.isOpened()) mDialerDrawer.animateClose(); else if (Receiver.call_state == UserAgent.UA_STATE_INCOMING_CALL) reject(); return true; case KeyEvent.KEYCODE_CAMERA: // Disable the CAMERA button while in-call since it's too // easy to press accidentally. return true; case KeyEvent.KEYCODE_VOLUME_DOWN: case KeyEvent.KEYCODE_VOLUME_UP: if (Receiver.call_state == UserAgent.UA_STATE_INCOMING_CALL) { Receiver.stopRingtone(); return true; } RtpStreamReceiver.adjust(keyCode, true); return true; } if (Receiver.call_state == UserAgent.UA_STATE_INCALL) { char number = event.getNumber(); if (Character.isDigit(number) || number == '*' || number == '#') { appendDigit(number); return true; } } return super.onKeyDown(keyCode, event); }
@Override public boolean onKeyUp(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_VOLUME_DOWN: case KeyEvent.KEYCODE_VOLUME_UP: RtpStreamReceiver.adjust(keyCode, false); return true; case KeyEvent.KEYCODE_ENDCALL: if (Receiver.pstn_state == null || (Receiver.pstn_state.equals("IDLE") && (SystemClock.elapsedRealtime() - Receiver.pstn_time) > 3000)) { reject(); return true; } break; } Receiver.pstn_time = 0; return false; }