Search in sources :

Example 1 with EMCallStateChangeListener

use of com.easemob.chat.EMCallStateChangeListener in project wechat by motianhuo.

the class VoiceCallActivity method addCallStateListener.

/**
	 * 设置电话监听
	 */
void addCallStateListener() {
    EMChatManager.getInstance().addVoiceCallStateChangeListener(new EMCallStateChangeListener() {

        @Override
        public void onCallStateChanged(CallState callState, CallError error) {
            // Message msg = handler.obtainMessage();
            switch(callState) {
                case // 正在连接对方
                CONNECTING:
                    runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            // TODO Auto-generated method stub
                            callStateTextView.setText(st1);
                        }
                    });
                    break;
                case // 双方已经建立连接
                CONNECTED:
                    runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            // TODO Auto-generated method stub
                            String st3 = getResources().getString(R.string.have_connected_with);
                            callStateTextView.setText(st3);
                        }
                    });
                    break;
                case // 电话接通成功
                ACCEPTED:
                    runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            try {
                                if (soundPool != null)
                                    soundPool.stop(streamID);
                            } catch (Exception e) {
                            }
                            closeSpeakerOn();
                            chronometer.setVisibility(View.VISIBLE);
                            chronometer.setBase(SystemClock.elapsedRealtime());
                            // 开始记时
                            chronometer.start();
                            String str4 = getResources().getString(R.string.In_the_call);
                            callStateTextView.setText(str4);
                            callingState = CallingState.NORMAL;
                        }
                    });
                    break;
                case // 电话断了
                DISCONNNECTED:
                    final CallError fError = error;
                    runOnUiThread(new Runnable() {

                        private void postDelayedCloseMsg() {
                            handler.postDelayed(new Runnable() {

                                @Override
                                public void run() {
                                    saveCallRecord(0);
                                    Animation animation = new AlphaAnimation(1.0f, 0.0f);
                                    animation.setDuration(800);
                                    findViewById(R.id.root_layout).startAnimation(animation);
                                    finish();
                                }
                            }, 200);
                        }

                        @Override
                        public void run() {
                            chronometer.stop();
                            callDruationText = chronometer.getText().toString();
                            String st2 = getResources().getString(R.string.The_other_party_refused_to_accept);
                            String st3 = getResources().getString(R.string.Connection_failure);
                            String st4 = getResources().getString(R.string.The_other_party_is_not_online);
                            String st5 = getResources().getString(R.string.The_other_is_on_the_phone_please);
                            String st6 = getResources().getString(R.string.The_other_party_did_not_answer_new);
                            String st7 = getResources().getString(R.string.hang_up);
                            String st8 = getResources().getString(R.string.The_other_is_hang_up);
                            String st9 = getResources().getString(R.string.did_not_answer);
                            String st10 = getResources().getString(R.string.Has_been_cancelled);
                            String st11 = getResources().getString(R.string.hang_up);
                            if (fError == CallError.REJECTED) {
                                callingState = CallingState.BEREFUESD;
                                callStateTextView.setText(st2);
                            } else if (fError == CallError.ERROR_TRANSPORT) {
                                callStateTextView.setText(st3);
                            } else if (fError == CallError.ERROR_INAVAILABLE) {
                                callingState = CallingState.OFFLINE;
                                callStateTextView.setText(st4);
                            } else if (fError == CallError.ERROR_BUSY) {
                                callingState = CallingState.BUSY;
                                callStateTextView.setText(st5);
                            } else if (fError == CallError.ERROR_NORESPONSE) {
                                callingState = CallingState.NORESPONSE;
                                callStateTextView.setText(st6);
                            } else {
                                if (isAnswered) {
                                    callingState = CallingState.NORMAL;
                                    if (endCallTriggerByMe) {
                                        callStateTextView.setText(st7);
                                    } else {
                                        callStateTextView.setText(st8);
                                    }
                                } else {
                                    if (isInComingCall) {
                                        callingState = CallingState.UNANSWERED;
                                        callStateTextView.setText(st9);
                                    } else {
                                        if (callingState != CallingState.NORMAL) {
                                            callingState = CallingState.CANCED;
                                            callStateTextView.setText(st10);
                                        } else {
                                            callStateTextView.setText(st11);
                                        }
                                    }
                                }
                            }
                            postDelayedCloseMsg();
                        }
                    });
                    break;
                default:
                    break;
            }
        }
    });
}
Also used : EMCallStateChangeListener(com.easemob.chat.EMCallStateChangeListener) AlphaAnimation(android.view.animation.AlphaAnimation) Animation(android.view.animation.Animation) EMServiceNotReadyException(com.easemob.exceptions.EMServiceNotReadyException) AlphaAnimation(android.view.animation.AlphaAnimation)

Example 2 with EMCallStateChangeListener

use of com.easemob.chat.EMCallStateChangeListener in project wechat by motianhuo.

the class VideoCallActivity method addCallStateListener.

/**
	 * 设置通话状态监听
	 */
void addCallStateListener() {
    EMChatManager.getInstance().addVoiceCallStateChangeListener(new EMCallStateChangeListener() {

        @Override
        public void onCallStateChanged(CallState callState, CallError error) {
            // Message msg = handler.obtainMessage();
            switch(callState) {
                case // 正在连接对方
                CONNECTING:
                    runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            String st2 = getResources().getString(R.string.Are_connected_to_each_other);
                            callStateTextView.setText(st2);
                        }
                    });
                    break;
                case // 双方已经建立连接
                CONNECTED:
                    runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            String st3 = getResources().getString(R.string.have_connected_with);
                            callStateTextView.setText(st3);
                        }
                    });
                    break;
                case // 电话接通成功
                ACCEPTED:
                    runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            try {
                                if (soundPool != null)
                                    soundPool.stop(streamID);
                            } catch (Exception e) {
                            }
                            openSpeakerOn();
                            handsFreeImage.setImageResource(R.drawable.icon_speaker_on);
                            isHandsfreeState = true;
                            chronometer.setVisibility(View.VISIBLE);
                            chronometer.setBase(SystemClock.elapsedRealtime());
                            // 开始记时
                            chronometer.start();
                            nickTextView.setVisibility(View.INVISIBLE);
                            String st5 = getResources().getString(R.string.In_the_call);
                            callStateTextView.setText(st5);
                            callingState = CallingState.NORMAL;
                        }
                    });
                    break;
                case // 电话断了
                DISCONNNECTED:
                    final CallError fError = error;
                    runOnUiThread(new Runnable() {

                        private void postDelayedCloseMsg() {
                            handler.postDelayed(new Runnable() {

                                @Override
                                public void run() {
                                    saveCallRecord(1);
                                    Animation animation = new AlphaAnimation(1.0f, 0.0f);
                                    animation.setDuration(800);
                                    rootContainer.startAnimation(animation);
                                    finish();
                                }
                            }, 200);
                        }

                        @Override
                        public void run() {
                            chronometer.stop();
                            callDruationText = chronometer.getText().toString();
                            String s1 = getResources().getString(R.string.The_other_party_refused_to_accept);
                            String s2 = getResources().getString(R.string.Connection_failure);
                            String s3 = getResources().getString(R.string.The_other_party_is_not_online);
                            String s4 = getResources().getString(R.string.The_other_is_on_the_phone_please);
                            String s5 = getResources().getString(R.string.The_other_party_did_not_answer);
                            String s6 = getResources().getString(R.string.hang_up);
                            String s7 = getResources().getString(R.string.The_other_is_hang_up);
                            String s8 = getResources().getString(R.string.did_not_answer);
                            String s9 = getResources().getString(R.string.Has_been_cancelled);
                            if (fError == CallError.REJECTED) {
                                callingState = CallingState.BEREFUESD;
                                callStateTextView.setText(s1);
                            } else if (fError == CallError.ERROR_TRANSPORT) {
                                callStateTextView.setText(s2);
                            } else if (fError == CallError.ERROR_INAVAILABLE) {
                                callingState = CallingState.OFFLINE;
                                callStateTextView.setText(s3);
                            } else if (fError == CallError.ERROR_BUSY) {
                                callingState = CallingState.BUSY;
                                callStateTextView.setText(s4);
                            } else if (fError == CallError.ERROR_NORESPONSE) {
                                callingState = CallingState.NORESPONSE;
                                callStateTextView.setText(s5);
                            } else {
                                if (isAnswered) {
                                    callingState = CallingState.NORMAL;
                                    if (endCallTriggerByMe) {
                                        callStateTextView.setText(s6);
                                    } else {
                                        callStateTextView.setText(s7);
                                    }
                                } else {
                                    if (isInComingCall) {
                                        callingState = CallingState.UNANSWERED;
                                        callStateTextView.setText(s8);
                                    } else {
                                        if (callingState != CallingState.NORMAL) {
                                            callingState = CallingState.CANCED;
                                            callStateTextView.setText(s9);
                                        } else {
                                            callStateTextView.setText(s6);
                                        }
                                    }
                                }
                            }
                            postDelayedCloseMsg();
                        }
                    });
                    break;
                default:
                    break;
            }
        }
    });
}
Also used : EMCallStateChangeListener(com.easemob.chat.EMCallStateChangeListener) Animation(android.view.animation.Animation) AlphaAnimation(android.view.animation.AlphaAnimation) EMServiceNotReadyException(com.easemob.exceptions.EMServiceNotReadyException) AlphaAnimation(android.view.animation.AlphaAnimation)

Aggregations

AlphaAnimation (android.view.animation.AlphaAnimation)2 Animation (android.view.animation.Animation)2 EMCallStateChangeListener (com.easemob.chat.EMCallStateChangeListener)2 EMServiceNotReadyException (com.easemob.exceptions.EMServiceNotReadyException)2