wxr
2024-11-14 66db2477a4855f5452c45f5e5baeae2d8c3e8c05
HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/activity/HDLLinphoneReverseCallActivity.java
@@ -4,8 +4,10 @@
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.media.AudioAttributes;
import android.media.MediaPlayer;
import android.os.Build;
import android.os.CountDownTimer;
import android.os.Handler;
import android.os.SystemClock;
import android.os.Vibrator;
import android.support.v7.app.AlertDialog;
@@ -32,6 +34,7 @@
import com.hdl.hdllinphonesdk.utils.HDLLog;
import org.linphone.core.Call;
import org.linphone.core.CallParams;
import org.linphone.core.Core;
import org.linphone.core.CoreListenerStub;
@@ -48,6 +51,10 @@
    private ImageView iv_lp_hangUp;
    private TextView tv_lp_hangUp;
    private RelativeLayout rl_lp_hangUpAll;
    private ImageView iv_lp_hangUpAll;
    private TextView tv_lp_hangUpAll;
    private ImageView iv_lp_answer;
    private TextView tv_lp_answer;
@@ -74,6 +81,9 @@
    private CoreListenerStub mCoreListener;
    private String deviceSipAccount;//设备SIP账号
    private boolean enableVideo = false;
    private CountDownTimer mMissedCallsTimer;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
@@ -89,7 +99,10 @@
        initCountDownTimer();
        initLinphone();
//        initVibrator();
        initMissedCallsTimer();
        mMissedCallsTimer.start();
    }
    /**
     * onDestroy
@@ -112,6 +125,10 @@
            mCountDownTimer.cancel();
            mCountDownTimer = null;
        }
        if (mMissedCallsTimer != null) {
            mMissedCallsTimer.cancel();
            mMissedCallsTimer = null;
        }
        onDestroyLinphone();
        HDLLog.i(TAG, "onDestroy");
    }
@@ -125,6 +142,9 @@
        iv_lp_unlock = findViewById(R.id.iv_lp_unlock);
        iv_lp_hangUp = findViewById(R.id.iv_lp_hangUp);
        tv_lp_hangUp = findViewById(R.id.tv_lp_hangUp);
        rl_lp_hangUpAll = findViewById(R.id.rl_lp_hangUp_all);
        iv_lp_hangUpAll = findViewById(R.id.iv_lp_hangUp_all);
        tv_lp_hangUpAll = findViewById(R.id.tv_lp_hangUp_all);
        iv_lp_answer = findViewById(R.id.iv_lp_answer);
        tv_lp_answer = findViewById(R.id.tv_lp_answer);
        rl_lp_answerView = findViewById(R.id.rl_lp_answerView);
@@ -182,6 +202,8 @@
        tv_lp_hangUp.setOnClickListener(this);
        iv_lp_answer.setOnClickListener(this);
        tv_lp_answer.setOnClickListener(this);
        iv_lp_hangUpAll.setOnClickListener(this);
        tv_lp_hangUpAll.setOnClickListener(this);
    }
    /**
@@ -205,7 +227,6 @@
     * 初始化开锁屏蔽倒计时
     */
    void initCountDownTimer() {
        mCountDownTimer = new CountDownTimer(10 * 1000, 1000) {
            @Override
            public void onTick(long millisUntilFinished) {
@@ -218,12 +239,40 @@
             */
            @Override
            public void onFinish() {
//                showToast("开锁onFinish");
                iv_lp_unlock.setEnabled(true);
            }
        };
//
    }
    /**
     * 初始化接听计时器
     */
    void initMissedCallsTimer() {
        mMissedCallsTimer = new CountDownTimer(HDLLinphoneKit.getInstance().missedCallsTime * 1000, 1000) {
            @Override
            public void onTick(long millisUntilFinished) {
                if (!HDLLinphoneReverseCallActivity.this.isFinishing()) {
                    if(isAnswer){
                        mMissedCallsTimer.cancel();
                        mMissedCallsTimer = null;
                    }
                }
            }
            /**
             *倒计时结束后调用的
             */
            @Override
            public void onFinish() {
                if (!HDLLinphoneReverseCallActivity.this.isFinishing()) {
                    if (!isAnswer) {
                        isAnswer = true;
                        HDLLinphoneKit.getInstance().getOnHDLLinphoneCallListener().onMissedCallsAction();
                        finish();
                    }
                }
            }
        };
    }
    @Override
@@ -241,6 +290,9 @@
        } else if (id == R.id.iv_lp_answer || id == R.id.tv_lp_answer) {
            //接听
            onClickAnswer();
        } else if (id == R.id.iv_lp_hangUp_all || id == R.id.tv_lp_hangUp_all) {
            //全部挂断
            onClickHangUpAll();
        }
    }
@@ -265,7 +317,7 @@
     */
    private void onClickUnlock() {
        try {
            AlertDialog.Builder builder = new AlertDialog.Builder(this,R.style.CustomAlertDialog);
            AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.CustomAlertDialog);
            builder.setTitle(R.string.lp_tipStr);
            builder.setMessage(R.string.tip_confirm_unlock);
@@ -291,8 +343,8 @@
            AlertDialog dialog = builder.create();
            dialog.show();
        }catch (Exception exception){
            Log.e(TAG,  exception.getMessage());
        } catch (Exception exception) {
            Log.e(TAG, exception.getMessage());
        }
    }
@@ -318,6 +370,20 @@
    }
    /**
     * 全部挂断点击事件
     */
    private void onClickHangUpAll() {
        //1.挂断
        HDLLinphoneKit.getInstance().hangUp();
        //2.回调事件
        if (HDLLinphoneKit.getInstance().getOnHDLLinphoneCallListener() != null) {
            HDLLinphoneKit.getInstance().getOnHDLLinphoneCallListener().onCallAllRejection();
        }
        //3.页面关闭
        finish();
    }
    /**
     * 接听按钮点击事件
     */
    private void onClickAnswer() {
@@ -335,6 +401,7 @@
        tv_lp_hangUp.setText(getString(R.string.lp_hangupStr));
        setViewGone(rl_lp_answerView);
        setViewGone(tv_lp_calltime);
        setViewGone(rl_lp_hangUpAll);
        setViewVisible(timer_lp_calltime);
        startCallTimeCountdown();
        //接听通知
@@ -419,6 +486,13 @@
                    // we missed the first one
                    showToast(getString(R.string.lp_endOfCallStr));
                    finish();
                } else if (state == Call.State.StreamsRunning) {
                    if (HDLLinphoneKit.getInstance().getIntercomeType().equals(HDLLinphoneKit.INTER_PHONE_TYPE_HDL)) {
                        if (!enableVideo) {
                            enableVideo(core, call);
                            enableVideo = true;
                        }
                    }
                }
            }
        };
@@ -435,6 +509,21 @@
    }
    void enableVideo(Core core, Call call) {
//        Call currentCall = HDLLinphoneService.getCore().getCurrentCall();
        CallParams params = call.getCurrentParams();
        if (params == null) {
            params = core.createCallParams(call);
        }
        params.enableVideo(true);
        params.enableLowBandwidth(false);
        params.setAudioBandwidthLimit(0); // disable limitation
        call.update(params);
    }
    /**
     * onDestroyLinphone
     */