@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); }
/** Overrides the superclass's lookup method to prefer the number field from the KeyEvent. */ protected int lookup(KeyEvent event, Spannable content) { int meta = event.getMetaState() | getMetaState(content); int number = event.getNumber(); /* * Prefer number if no meta key is active, or if it produces something * valid and the meta lookup does not. */ if ((meta & (MetaKeyKeyListener.META_ALT_ON | MetaKeyKeyListener.META_SHIFT_ON)) == 0) { if (number != 0) { return number; } } int match = super.lookup(event, content); if (match != 0) { return match; } else { /* * If a meta key is active but the lookup with the meta key * did not produce anything, try some other meta keys, because * the user might have pressed SHIFT when they meant ALT, * or vice versa. */ if (meta != 0) { KeyData kd = new KeyData(); char[] accepted = getAcceptedChars(); if (event.getKeyData(kd)) { for (int i = 1; i < kd.meta.length; i++) { if (ok(accepted, kd.meta[i])) { return kd.meta[i]; } } } } /* * Otherwise, use the number associated with the key, since * whatever they wanted to do with the meta key does not * seem to be valid here. */ return number; } }
@Override public void onTrigger(int keyCode, int dialTone) { if (dialPadTextView != null) { // Update text view KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN, keyCode); char nbr = event.getNumber(); StringBuilder sb = new StringBuilder(dialPadTextView.getText()); sb.append(nbr); dialPadTextView.setText(sb.toString()); } if (getSherlockActivity() instanceof OnDtmfListener) { Integer callId = getArguments().getInt(EXTRA_CALL_ID); if (callId != null) { ((OnDtmfListener) getSherlockActivity()).OnDtmf(callId, keyCode, dialTone); } else { Log.w(THIS_FILE, "Impossible to find the call associated to this view"); } } }