From 1b11947cc15245ae005a7cc8cc2f93c5660b0c23 Mon Sep 17 00:00:00 2001
From: JLChen <551775569@qq.com>
Date: 星期五, 20 八月 2021 17:17:43 +0800
Subject: [PATCH] 2021-08-20 1.优化更新

---
 HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/activity/HDLLinphoneMonitorActivity.java  |   59 ++++++++++----
 HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/res/values-zh/strings.xml                                             |    1 
 HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/res/values/strings.xml                                                |    1 
 HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/activity/HDLLinphoneIntercomActivity.java |  104 ++++++++++++++++---------
 HDLLinphoneSDKDemoNew/app/src/main/java/com/example/hdllinphonesdkdemo/MainActivity.java                            |   29 +++++--
 Shared.Droid.HDLLinphone/Shared.Droid.HDLLinphone/Properties/AssemblyInfo.cs                                        |    4 
 HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/HDLLinphoneKit.java                       |    6 -
 Shared.Droid.HDLLinphone/Shared.Droid.HDLLinphone/Jars/HDLLinphoneSDK-V1.0.1.aar                                    |    0 
 HDLLinphoneSDKDemoNew/app/libs/HDLLinphoneSDK-V1.0.1.aar                                                            |    0 
 9 files changed, 135 insertions(+), 69 deletions(-)

diff --git a/HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/HDLLinphoneKit.java b/HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/HDLLinphoneKit.java
index ce44248..a421c7a 100644
--- a/HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/HDLLinphoneKit.java
+++ b/HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/HDLLinphoneKit.java
@@ -150,7 +150,7 @@
             @Override
             public void callEnd() {
                 super.callEnd();
-                context.sendBroadcast(new Intent(HDLLinphoneIntercomActivity.RECEIVE_FINISH_VIDEO_ACTIVITY));
+//                context.sendBroadcast(new Intent(HDLLinphoneIntercomActivity.RECEIVE_FINISH_VIDEO_ACTIVITY));
 
             }
         });
@@ -275,9 +275,6 @@
                         config.done();
                     }
                 }
-                core.clearAllAuthInfo();//娓呴櫎鎵�鏈夎璇佷俊鎭��
-
-//                core.clearProxyConfig();//浠庨厤缃腑鍒犻櫎鎵�鏈変唬鐞嗐�傛敞鎰忥細鐩墠涓嶈兘鐩存帴鍒犳墍鏈変唬鐞嗭紝鍥犱负鏈嶅姟鍣ㄤ笂杩樻槸鏍囪宸叉敞鍐�
             }
         } catch (Exception e) {
             e.printStackTrace();
@@ -290,6 +287,7 @@
     public void clearProxyConfig(){
         Core core = HDLLinphoneService.getCore();
         if (core != null) {
+            core.setDefaultProxyConfig(null);
             core.clearAllAuthInfo();//娓呴櫎鎵�鏈夎璇佷俊鎭��
             core.clearProxyConfig();//浠庨厤缃腑鍒犻櫎鎵�鏈変唬鐞嗐��
         }
diff --git a/HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/activity/HDLLinphoneIntercomActivity.java b/HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/activity/HDLLinphoneIntercomActivity.java
index fc949ce..03679e5 100644
--- a/HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/activity/HDLLinphoneIntercomActivity.java
+++ b/HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/activity/HDLLinphoneIntercomActivity.java
@@ -28,6 +28,10 @@
 import com.hdl.hdllinphonesdk.utils.HDLImageUtils;
 import com.hdl.hdllinphonesdk.utils.HDLLog;
 
+import org.linphone.core.Call;
+import org.linphone.core.Core;
+import org.linphone.core.CoreListenerStub;
+
 /**
  * Linphone鎺ュ惉椤甸潰
  */
@@ -49,8 +53,8 @@
     private LinearLayout ll_video_lp_rendering;
     private TextureView video_lp_rendering;
     private TextureView video_lp_rendering2;
-//    private TextView tv_lp_calltime;
-    private Chronometer timer_lp_calltime ;
+    //    private TextView tv_lp_calltime;
+    private Chronometer timer_lp_calltime;
     private TextView tv_lp_calltime;
 
     //鍙傛暟
@@ -58,6 +62,9 @@
     private int callTime;//閫氳瘽鏃堕棿
 
     private CountDownTimer mCountDownTimer;
+
+    //Linphone
+    private CoreListenerStub mCoreListener;
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
@@ -92,13 +99,9 @@
             mCountDownTimer.cancel();
             mCountDownTimer = null;
         }
+        onDestroyLinphone();
 
-        if (mReceiver != null) {
-            unregisterReceiver(mReceiver);
-        }
-        HDLLinphoneKit.getInstance().onDestroy();
-
-        HDLLog.i(TAG,"onDestroy");
+        HDLLog.i(TAG, "onDestroy");
 
     }
 
@@ -119,19 +122,19 @@
         video_lp_rendering = findViewById(R.id.video_lp_rendering);
         video_lp_rendering2 = findViewById(R.id.video_lp_rendering2);
 //        tv_lp_calltime = findViewById(R.id.tv_lp_calltime);
-        timer_lp_calltime = (Chronometer)findViewById(R.id.timer_lp_calltime);
+        timer_lp_calltime = (Chronometer) findViewById(R.id.timer_lp_calltime);
         tv_lp_calltime = findViewById(R.id.tv_lp_calltime);
-        setWidthHeightWithRatio(ll_video_lp_rendering,16,9);
+        setWidthHeightWithRatio(ll_video_lp_rendering, 16, 9);
     }
 
     /**
      * initData
      */
-    private void initData(){
+    private void initData() {
         Bundle extras = getIntent().getExtras();
-        if(extras != null){
-            String titleName =  extras.getString(HDLLinphoneKit.KEY_TITLE_NAME);
-            if(!TextUtils.isEmpty(titleName)){
+        if (extras != null) {
+            String titleName = extras.getString(HDLLinphoneKit.KEY_TITLE_NAME);
+            if (!TextUtils.isEmpty(titleName)) {
                 tv_lp_title.setText(titleName);
             }
         }
@@ -154,6 +157,7 @@
             view.setLayoutParams(layoutParams);
         }
     }
+
     /**
      * init OnClickListener
      */
@@ -169,7 +173,7 @@
     /**
      * 鍒濆鍖栧紑闂ㄥ洖璋冧簨浠�
      */
-    void initCallBack(){
+    void initCallBack() {
         HDLLinphoneKit.getInstance().setOpenOpenDoorCallBack(new OnLPOpenDoorCallBack() {
             @Override
             public void onOpenSuccess() {
@@ -186,9 +190,9 @@
     /**
      * 鍒濆鍖栧紑閿佸睆钄藉�掕鏃�
      */
-    void initCountDownTimer(){
+    void initCountDownTimer() {
 
-        mCountDownTimer = new CountDownTimer(10*1000, 1000) {
+        mCountDownTimer = new CountDownTimer(10 * 1000, 1000) {
             @Override
             public void onTick(long millisUntilFinished) {
                 if (!HDLLinphoneIntercomActivity.this.isFinishing()) {
@@ -233,15 +237,14 @@
     private void onClickScreenshot() {
 //        Bitmap img = HDLImageUtils.createViewBitmap(video_lp_rendering);
         Bitmap img = video_lp_rendering.getBitmap();
-        boolean isSuccess =  HDLImageUtils.saveImageToGallery(this, img);
+        boolean isSuccess = HDLImageUtils.saveImageToGallery(this, img);
 
-        if(isSuccess){
+        if (isSuccess) {
             showToast(getString(R.string.lp_saveToTheAlbumsStr));
-        }else {
+        } else {
             showToast(getString(R.string.lp_operationFailedStr));
         }
     }
-
 
 
     /**
@@ -264,7 +267,7 @@
             if (isAnswer) {
                 //濡傛灉涔嬪墠宸茬粡鎺ュ惉浜嗭紝鍥炶皟鏄寕鏂�
                 callTime = getTimerCallTime();
-                HDLLog.i("callTime","callTime"+callTime);
+                HDLLog.i("callTime", "callTime" + callTime);
                 HDLLinphoneKit.getInstance().getOnHDLLinphoneCallListener().onHangUpAction(callTime);
             } else {
                 //濡傛灉涔嬪墠娌℃帴鍚簡锛屽洖璋冩槸鎷掓帴
@@ -304,12 +307,14 @@
         iv_lp_unlock.setEnabled(false);
         startOpenDoorCountdown();
     }
+
     /**
      * 寮�鍚�掕鏃�
      */
     void startOpenDoorCountdown() {
         mCountDownTimer.start();
     }
+
     /**
      * 閫氳瘽璁板綍寮�鍚�掕鏃�
      */
@@ -317,12 +322,12 @@
         timer_lp_calltime.setBase(SystemClock.elapsedRealtime());//璁℃椂鍣ㄦ竻闆�
         timer_lp_calltime.start();
     }
-    int getTimerCallTime(){
+
+    int getTimerCallTime() {
         int temp0 = Integer.parseInt(timer_lp_calltime.getText().toString().split(":")[0]);
-        int temp1 =Integer.parseInt(timer_lp_calltime.getText().toString().split(":")[1]);
+        int temp1 = Integer.parseInt(timer_lp_calltime.getText().toString().split(":")[1]);
         return temp0 * 60 + temp1;
     }
-
 
 
     /****************灏佽甯哥敤鏂规硶********/
@@ -352,23 +357,46 @@
     }
 
     /**********LinPhone**********/
-    void initLinphone(){
-        IntentFilter intentFilter = new IntentFilter(RECEIVE_FINISH_VIDEO_ACTIVITY);
-        mReceiver = new FinishVideoActivityReceiver();
-        registerReceiver(mReceiver, intentFilter);
-        HDLLinphoneKit.getInstance().setAndroidVideoWindow(video_lp_rendering, video_lp_rendering2);
-    }
+    /**
+     * initLinphone
+     */
+    void initLinphone() {
+        mCoreListener = new CoreListenerStub() {
+            @Override
+            public void onCallStateChanged(Core core, Call call, Call.State state, String message) {
+                if (state == Call.State.End || state == Call.State.Released) {
+                    // Once call is finished (end state), terminate the activity
+                    // We also check for released state (called a few seconds later) just in case
+                    // we missed the first one
+                    showToast(getString(R.string.lp_endOfCallStr));
+                    finish();
+                }
+            }
+        };
 
-
-    public class FinishVideoActivityReceiver extends BroadcastReceiver {
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            HDLLinphoneIntercomActivity.this.finish();
+        Core core = HDLLinphoneKit.getInstance().getCore();
+        // We need to tell the core in which to display what
+        if (core != null) {
+            core.setNativeVideoWindowId(video_lp_rendering);
+            core.setNativePreviewWindowId(video_lp_rendering2);
+            // Listen for call state changes
+            core.addListener(mCoreListener);
         }
     }
 
-    private FinishVideoActivityReceiver mReceiver;
-    public static final String RECEIVE_FINISH_VIDEO_ACTIVITY = "receive_finish_video_activity";
+    /**
+     * onDestroyLinphone
+     */
+    void onDestroyLinphone(){
+        Core core = HDLLinphoneKit.getInstance().getCore();
+        if (core != null) {
+            core.removeListener(mCoreListener);
+            core.setNativeVideoWindowId(null);
+            core.setNativePreviewWindowId(null);
+        }
+        video_lp_rendering = null;
+        video_lp_rendering2 = null;
+    }
 
 
 }
\ No newline at end of file
diff --git a/HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/activity/HDLLinphoneMonitorActivity.java b/HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/activity/HDLLinphoneMonitorActivity.java
index a5c8cb3..5b86194 100644
--- a/HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/activity/HDLLinphoneMonitorActivity.java
+++ b/HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/activity/HDLLinphoneMonitorActivity.java
@@ -27,6 +27,10 @@
 import com.hdl.hdllinphonesdk.utils.HDLImageUtils;
 import com.hdl.hdllinphonesdk.utils.HDLLog;
 
+import org.linphone.core.Call;
+import org.linphone.core.Core;
+import org.linphone.core.CoreListenerStub;
+
 /**
 *鐩戣椤甸潰
  */
@@ -47,6 +51,9 @@
     private TextureView video_lp_rendering2;
 
     private CountDownTimer mCountDownTimer;
+
+    //Linphone
+    private CoreListenerStub mCoreListener;
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
@@ -79,10 +86,7 @@
             mCountDownTimer = null;
         }
 
-        if (mReceiver != null) {
-            unregisterReceiver(mReceiver);
-        }
-        HDLLinphoneKit.getInstance().onDestroy();
+        onDestroyLinphone();
 
         HDLLog.i(TAG,"onDestroy");
 
@@ -287,23 +291,44 @@
     }
 
     /**********LinPhone**********/
-    void initLinphone(){
-        IntentFilter intentFilter = new IntentFilter(RECEIVE_FINISH_VIDEO_ACTIVITY);
-        mReceiver = new HDLLinphoneMonitorActivity.FinishVideoActivityReceiver();
-        registerReceiver(mReceiver, intentFilter);
-        HDLLinphoneKit.getInstance().setAndroidVideoWindow(video_lp_rendering, video_lp_rendering2);
+    /**
+     * initLinphone
+     */
+    void initLinphone() {
+        mCoreListener = new CoreListenerStub() {
+            @Override
+            public void onCallStateChanged(Core core, Call call, Call.State state, String message) {
+                if (state == Call.State.End || state == Call.State.Released) {
+                    // Once call is finished (end state), terminate the activity
+                    // We also check for released state (called a few seconds later) just in case
+                    // we missed the first one
+                    showToast(getString(R.string.lp_endMonitoringStr));
+                    finish();
+                }
+            }
+        };
+
+        Core core = HDLLinphoneKit.getInstance().getCore();
+        // We need to tell the core in which to display what
+        if (core != null) {
+            core.setNativeVideoWindowId(video_lp_rendering);
+            core.setNativePreviewWindowId(video_lp_rendering2);
+            // Listen for call state changes
+            core.addListener(mCoreListener);
+        }
     }
 
     /**
-     * 椤甸潰鍏抽棴骞挎挱鐩戝惉
+     * onDestroyLinphone
      */
-    public class FinishVideoActivityReceiver extends BroadcastReceiver {
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            HDLLinphoneMonitorActivity.this.finish();
+    void onDestroyLinphone(){
+        Core core = HDLLinphoneKit.getInstance().getCore();
+        if (core != null) {
+            core.removeListener(mCoreListener);
+            core.setNativeVideoWindowId(null);
+            core.setNativePreviewWindowId(null);
         }
+        video_lp_rendering = null;
+        video_lp_rendering2 = null;
     }
-    private HDLLinphoneMonitorActivity.FinishVideoActivityReceiver mReceiver;
-    public static final String RECEIVE_FINISH_VIDEO_ACTIVITY = "receive_finish_video_activity";
-
 }
\ No newline at end of file
diff --git a/HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/res/values-zh/strings.xml b/HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/res/values-zh/strings.xml
index b7c194e..d0ee279 100644
--- a/HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/res/values-zh/strings.xml
+++ b/HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/res/values-zh/strings.xml
@@ -12,6 +12,7 @@
     <string name="lp_unlockfailureStr">寮�閿佸け璐�</string>
     <string name="lp_callingStr">鏉ョ數涓�...</string>
     <string name="lp_endOfCallStr">閫氳瘽缁撴潫</string>
+    <string name="lp_endMonitoringStr">鐩戣缁撴潫</string>
     <string name="lp_screenshotStr">鎴浘</string>
     <string name="lp_unlockStr">寮�閿�</string>
     <string name="lp_outdoorUnitStr">瀹ゅ鏈�</string>
diff --git a/HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/res/values/strings.xml b/HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/res/values/strings.xml
index 66a6997..8269c55 100644
--- a/HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/res/values/strings.xml
+++ b/HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/res/values/strings.xml
@@ -11,6 +11,7 @@
     <string name="lp_unlockfailureStr">Unlock failure</string>
     <string name="lp_callingStr">Incoming call</string>
     <string name="lp_endOfCallStr">End of call</string>
+    <string name="lp_endMonitoringStr">End of the monitor</string>
     <string name="lp_screenshotStr">Screenshot</string>
     <string name="lp_unlockStr">Unlock</string>
     <string name="lp_outdoorUnitStr">Outdoor unit</string>
diff --git a/HDLLinphoneSDKDemoNew/app/libs/HDLLinphoneSDK-V1.0.1.aar b/HDLLinphoneSDKDemoNew/app/libs/HDLLinphoneSDK-V1.0.1.aar
index f9b1d2e..8bb3e19 100644
--- a/HDLLinphoneSDKDemoNew/app/libs/HDLLinphoneSDK-V1.0.1.aar
+++ b/HDLLinphoneSDKDemoNew/app/libs/HDLLinphoneSDK-V1.0.1.aar
Binary files differ
diff --git a/HDLLinphoneSDKDemoNew/app/src/main/java/com/example/hdllinphonesdkdemo/MainActivity.java b/HDLLinphoneSDKDemoNew/app/src/main/java/com/example/hdllinphonesdkdemo/MainActivity.java
index f17663c..ab92dee 100644
--- a/HDLLinphoneSDKDemoNew/app/src/main/java/com/example/hdllinphonesdkdemo/MainActivity.java
+++ b/HDLLinphoneSDKDemoNew/app/src/main/java/com/example/hdllinphonesdkdemo/MainActivity.java
@@ -66,6 +66,7 @@
         mTextView4.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
+                clearProxyConfig();
                 HDLLinphoneKit.getInstance().setAccountAndLogin("5555", "85521566", "test-gz.hdlcontrol.com:5060");
             }
         });
@@ -74,12 +75,12 @@
             @Override
             public void onClick(View v) {
 
-                logoutLog();
-                return;
-////                HDLLinphoneKit.getInstance().callTo("61723164995779",true);
-////                HDLcallTo("61723164995779",true);
-//                HDLLinphoneKit.getInstance().callTo("1427186301744910338",true);
-//                startActivity(HDLLinphoneMonitorActivity.class);
+//                logoutLog();
+//                return;
+//                HDLLinphoneKit.getInstance().callTo("61723164995779",true);
+//                HDLcallTo("61723164995779",true);
+                HDLLinphoneKit.getInstance().callTo("1427186301744910338",true);
+                startActivity(HDLLinphoneMonitorActivity.class);
 
 
             }
@@ -88,7 +89,7 @@
         mTextView3.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
-                HDLLinphoneKit.getInstance().logout();
+                logout();
             }
         });
 
@@ -115,7 +116,7 @@
                         config.done();
                     }
                 }
-                core.clearAllAuthInfo();//娓呴櫎鎵�鏈夎璇佷俊鎭��
+//                core.clearAllAuthInfo();//娓呴櫎鎵�鏈夎璇佷俊鎭��
 //                core.clearProxyConfig();//浠庨厤缃腑鍒犻櫎鎵�鏈変唬鐞嗐��
             }
         } catch (Exception e) {
@@ -123,6 +124,18 @@
         }
     }
 
+    public void clearProxyConfig() {
+        Core core = HDLLinphoneService.getCore();
+        if (core != null) {
+            core.setDefaultProxyConfig(null);
+            core.clearAllAuthInfo();
+            core.clearProxyConfig();
+//            core.refreshRegisters();//寮哄埗鍦ㄤ笅涓�娆¤凯浠f椂鍚姩娉ㄥ唽鍒锋柊
+//            core.ensureRegistered();
+        }
+
+    }
+
     public void logoutLog() {
         try {
             Core core = HDLLinphoneService.getCore();
diff --git a/Shared.Droid.HDLLinphone/Shared.Droid.HDLLinphone/Jars/HDLLinphoneSDK-V1.0.1.aar b/Shared.Droid.HDLLinphone/Shared.Droid.HDLLinphone/Jars/HDLLinphoneSDK-V1.0.1.aar
index f9b1d2e..638dc95 100644
--- a/Shared.Droid.HDLLinphone/Shared.Droid.HDLLinphone/Jars/HDLLinphoneSDK-V1.0.1.aar
+++ b/Shared.Droid.HDLLinphone/Shared.Droid.HDLLinphone/Jars/HDLLinphoneSDK-V1.0.1.aar
Binary files differ
diff --git a/Shared.Droid.HDLLinphone/Shared.Droid.HDLLinphone/Properties/AssemblyInfo.cs b/Shared.Droid.HDLLinphone/Shared.Droid.HDLLinphone/Properties/AssemblyInfo.cs
index b8df56d..c883909 100644
--- a/Shared.Droid.HDLLinphone/Shared.Droid.HDLLinphone/Properties/AssemblyInfo.cs
+++ b/Shared.Droid.HDLLinphone/Shared.Droid.HDLLinphone/Properties/AssemblyInfo.cs
@@ -22,5 +22,5 @@
 //      Minor Version 
 //      Build Number
 //      Revision
-[assembly: AssemblyVersion("1.0.1.3")]
-[assembly: AssemblyFileVersion("1.0.1.3")]
+[assembly: AssemblyVersion("1.0.1.5")]
+[assembly: AssemblyFileVersion("1.0.1.5")]

--
Gitblit v1.8.0