From 83d5ada866a598ee868d3e23624d104d1027db29 Mon Sep 17 00:00:00 2001
From: wxr <wxr@hdlchina.com.cn>
Date: 星期二, 27 八月 2024 15:28:42 +0800
Subject: [PATCH] 增加挂断功能

---
 HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/activity/HDLLinphoneReverseCallActivity.java |   73 ++++++++++++++++++++++++++++++++++--
 1 files changed, 69 insertions(+), 4 deletions(-)

diff --git a/HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/activity/HDLLinphoneReverseCallActivity.java b/HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/activity/HDLLinphoneReverseCallActivity.java
index 362b933..7127c51 100644
--- a/HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/activity/HDLLinphoneReverseCallActivity.java
+++ b/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;
@@ -50,6 +52,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;
     private RelativeLayout rl_lp_answerView;
@@ -77,6 +83,8 @@
     private String deviceSipAccount;//璁惧SIP璐﹀彿
     private boolean enableVideo = false;
 
+    private CountDownTimer mMissedCallsTimer;
+
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
@@ -91,7 +99,10 @@
         initCountDownTimer();
         initLinphone();
 //        initVibrator();
+        initMissedCallsTimer();
+        mMissedCallsTimer.start();
     }
+
 
     /**
      * onDestroy
@@ -114,6 +125,10 @@
             mCountDownTimer.cancel();
             mCountDownTimer = null;
         }
+        if (mMissedCallsTimer != null) {
+            mMissedCallsTimer.cancel();
+            mMissedCallsTimer = null;
+        }
         onDestroyLinphone();
         HDLLog.i(TAG, "onDestroy");
     }
@@ -127,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);
@@ -184,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);
     }
 
     /**
@@ -207,7 +227,6 @@
      * 鍒濆鍖栧紑閿佸睆钄藉�掕鏃�
      */
     void initCountDownTimer() {
-
         mCountDownTimer = new CountDownTimer(10 * 1000, 1000) {
             @Override
             public void onTick(long millisUntilFinished) {
@@ -220,12 +239,40 @@
              */
             @Override
             public void onFinish() {
-//                showToast("寮�閿乷nFinish");
                 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
@@ -243,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();
         }
     }
 
@@ -320,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() {
@@ -337,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();
         //鎺ュ惉閫氱煡

--
Gitblit v1.8.0