public void handleMessage(Message msg) { switch (msg.what) { case MSG_ANSWER: if (Receiver.call_state == UserAgent.UA_STATE_INCOMING_CALL) answer(); break; case MSG_ANSWER_SPEAKER: if (Receiver.call_state == UserAgent.UA_STATE_INCOMING_CALL) { answer(); Receiver.engine(mContext).speaker(AudioManager.MODE_NORMAL); } break; case MSG_BACK: moveBack(); break; case MSG_TICK: mCodec.setText(RtpStreamReceiver.getCodec()); if (RtpStreamReceiver.good != 0) { if (RtpStreamReceiver.timeout != 0) mStats.setText("no data"); else if (RtpStreamSender.m == 2) mStats.setText( Math.round(RtpStreamReceiver.loss / RtpStreamReceiver.good * 100) + "%loss, " + Math.round(RtpStreamReceiver.lost / RtpStreamReceiver.good * 100) + "%lost, " + Math.round(RtpStreamReceiver.late / RtpStreamReceiver.good * 100) + "%late (>" + (RtpStreamReceiver.jitter - 250 * RtpStreamReceiver.mu) / 8 / RtpStreamReceiver.mu + "ms)"); else mStats.setText( Math.round(RtpStreamReceiver.lost / RtpStreamReceiver.good * 100) + "%lost, " + Math.round(RtpStreamReceiver.late / RtpStreamReceiver.good * 100) + "%late (>" + (RtpStreamReceiver.jitter - 250 * RtpStreamReceiver.mu) / 8 / RtpStreamReceiver.mu + "ms)"); mStats.setVisibility(View.VISIBLE); } else mStats.setVisibility(View.GONE); break; } }
@Override public void onResume() { super.onResume(); if (!Sipdroid.release) Log.i("SipUA:", "on resume"); switch (Receiver.call_state) { case UserAgent.UA_STATE_INCOMING_CALL: if (Receiver.pstn_state == null || Receiver.pstn_state.equals("IDLE")) if (PreferenceManager.getDefaultSharedPreferences(mContext) .getBoolean( org.sipdroid.sipua.ui.Settings.PREF_AUTO_ON, org.sipdroid.sipua.ui.Settings.DEFAULT_AUTO_ON) && !mKeyguardManager.inKeyguardRestrictedInputMode()) mHandler.sendEmptyMessageDelayed(MSG_ANSWER, 1000); else if ((PreferenceManager.getDefaultSharedPreferences(mContext) .getBoolean( org.sipdroid.sipua.ui.Settings.PREF_AUTO_ONDEMAND, org.sipdroid.sipua.ui.Settings.DEFAULT_AUTO_ONDEMAND) && PreferenceManager.getDefaultSharedPreferences(mContext) .getBoolean( org.sipdroid.sipua.ui.Settings.PREF_AUTO_DEMAND, org.sipdroid.sipua.ui.Settings.DEFAULT_AUTO_DEMAND)) || (PreferenceManager.getDefaultSharedPreferences(mContext) .getBoolean( org.sipdroid.sipua.ui.Settings.PREF_AUTO_HEADSET, org.sipdroid.sipua.ui.Settings.DEFAULT_AUTO_HEADSET) && Receiver.headset > 0)) mHandler.sendEmptyMessageDelayed(MSG_ANSWER_SPEAKER, 10000); break; case UserAgent.UA_STATE_INCALL: if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { mDialerDrawer.close(); mDialerDrawer.setVisibility(View.GONE); } else mDialerDrawer.setVisibility(View.VISIBLE); if (Receiver.docked <= 0) screenOff(true); break; case UserAgent.UA_STATE_IDLE: if (!mHandler.hasMessages(MSG_BACK)) moveBack(); break; } if (Receiver.call_state != UserAgent.UA_STATE_INCALL) { mDialerDrawer.close(); mDialerDrawer.setVisibility(View.GONE); } if (Receiver.ccCall != null) mCallCard.displayMainCallStatus(ccPhone, Receiver.ccCall); if (mSlidingCardManager != null) mSlidingCardManager.showPopup(); mHandler.sendEmptyMessage(MSG_TICK); if (t == null && Receiver.call_state != UserAgent.UA_STATE_IDLE) { mDigits.setText(""); running = true; (t = new Thread() { public void run() { int len = 0; long time; ToneGenerator tg = null; if (Settings.System.getInt( getContentResolver(), Settings.System.DTMF_TONE_WHEN_DIALING, 1) == 1) tg = new ToneGenerator( AudioManager.STREAM_VOICE_CALL, (int) (ToneGenerator.MAX_VOLUME * 2 * org.sipdroid.sipua.ui.Settings.getEarGain())); for (; ; ) { if (!running) { t = null; break; } if (len != mDigits.getText().length()) { time = SystemClock.elapsedRealtime(); if (tg != null) tg.startTone(mToneMap.get(mDigits.getText().charAt(len))); Receiver.engine(Receiver.mContext).info(mDigits.getText().charAt(len++), 250); time = 250 - (SystemClock.elapsedRealtime() - time); try { if (time > 0) sleep(time); } catch (InterruptedException e) { } if (tg != null) tg.stopTone(); try { if (running) sleep(250); } catch (InterruptedException e) { } continue; } mHandler.sendEmptyMessage(MSG_TICK); try { sleep(1000); } catch (InterruptedException e) { } } if (tg != null) tg.release(); } }) .start(); } }