From 848cbfebefab08cc49b0285155edb84463aed862 Mon Sep 17 00:00:00 2001 From: panlili2024 <14743743+panlili2024@user.noreply.gitee.com> Date: 星期三, 13 十一月 2024 17:19:53 +0800 Subject: [PATCH] 提交home项目所用可视对讲sdk --- HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/activity/HDLLinphoneMonitorActivity.java | 147 +++++++++++++++++++++++++++++------------------- 1 files changed, 89 insertions(+), 58 deletions(-) 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 8f32b3e..a339f9c 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 @@ -1,15 +1,15 @@ package com.hdl.hdllinphonesdk.activity; +import android.Manifest; import android.annotation.SuppressLint; -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.DialogInterface; -import android.content.Intent; import android.content.IntentFilter; +import android.content.pm.PackageManager; import android.graphics.Bitmap; -import android.os.CountDownTimer; import android.os.Bundle; -import android.support.v7.app.AlertDialog; +import android.os.CountDownTimer; +import android.support.annotation.NonNull; +import android.support.v4.app.ActivityCompat; +import android.support.v4.content.ContextCompat; import android.text.TextUtils; import android.util.DisplayMetrics; import android.util.Log; @@ -26,10 +26,13 @@ import com.hdl.hdllinphonesdk.HDLLinphoneKit; import com.hdl.hdllinphonesdk.R; import com.hdl.hdllinphonesdk.callback.OnLPOpenDoorCallBack; +import com.hdl.hdllinphonesdk.dialog.LinphoneCommonDialog; +import com.hdl.hdllinphonesdk.receiver.CallBroadcastReceiver; import com.hdl.hdllinphonesdk.utils.HDLImageUtils; 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; @@ -42,11 +45,9 @@ private RelativeLayout ll_lp_btn_back; //鎺т欢 private TextView tv_lp_title; - private ImageView iv_lp_screenshot; - private TextView tv_lp_screenshot; + private ImageView iv_lp_screenshot; private ImageView iv_lp_unlock; - private TextView tv_lp_unlock; private LinearLayout ll_video_lp_rendering; private TextureView video_lp_rendering; @@ -56,6 +57,10 @@ //Linphone private CoreListenerStub mCoreListener; + private boolean enableVideo = false; + + private CallBroadcastReceiver callBroadcastReceiver; + private IntentFilter callFilter; @Override protected void onCreate(Bundle savedInstanceState) { @@ -92,6 +97,11 @@ onDestroyLinphone(); + if (callBroadcastReceiver != null) { + unregisterReceiver(callBroadcastReceiver); + callBroadcastReceiver = null; + } + HDLLog.i(TAG, "onDestroy"); } @@ -103,10 +113,7 @@ ll_lp_btn_back = findViewById(R.id.ll_lp_btn_back); tv_lp_title = findViewById(R.id.tv_lp_title); iv_lp_screenshot = findViewById(R.id.iv_lp_screenshot); - tv_lp_screenshot = findViewById(R.id.tv_lp_screenshot); - iv_lp_unlock = findViewById(R.id.iv_lp_unlock); - tv_lp_unlock = findViewById(R.id.tv_lp_unlock); ll_video_lp_rendering = findViewById(R.id.ll_video_lp_rendering); video_lp_rendering = findViewById(R.id.video_lp_rendering); @@ -120,11 +127,33 @@ */ private void initData() { Bundle extras = getIntent().getExtras(); + String interphoneType = ""; if (extras != null) { String titleName = extras.getString(HDLLinphoneKit.KEY_TITLE_NAME); if (!TextUtils.isEmpty(titleName)) { tv_lp_title.setText(titleName); } + interphoneType = extras.getString("interphoneType"); + } + + //鐩戝惉鍛煎彨骞挎挱 + callFilter = new IntentFilter(); + callFilter.addAction("com.hdl.homepro.call.action"); + callBroadcastReceiver = new CallBroadcastReceiver(); + registerReceiver(callBroadcastReceiver, callFilter); + + if (callBroadcastReceiver != null) { + String finalInterphoneType = interphoneType; + callBroadcastReceiver.setOnReceivedCallBroadcastListener(new CallBroadcastReceiver.CallBroadcastListener() { + @Override + public void onReceived(String callFrom) { + //濡傛灉鏀跺埌鎺ㄩ�侀�氱煡鎶婄洃瑙嗛〉闈inish + if (!TextUtils.isEmpty(callFrom) && !finalInterphoneType.equals(callFrom)) { + Log.d("panlili", "HDLLinphoneMonitorActivity finish-----> "); + finish();//缁撴潫褰撳墠椤甸潰 + } + } + }); } } @@ -151,12 +180,8 @@ */ private void initOnClick() { ll_lp_btn_back.setOnClickListener(this); - iv_lp_screenshot.setOnClickListener(this); - tv_lp_screenshot.setOnClickListener(this); - iv_lp_unlock.setOnClickListener(this); - tv_lp_unlock.setOnClickListener(this); } /** @@ -204,14 +229,36 @@ public void onClick(View view) { int id = view.getId(); if (id == R.id.iv_lp_screenshot) { - //鎴浘 - onClickScreenshot(); + //鍔ㄦ�佹潈闄愮敵璇� + if (ContextCompat.checkSelfPermission(HDLLinphoneMonitorActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED + && ActivityCompat.checkSelfPermission(HDLLinphoneMonitorActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { + ActivityCompat.requestPermissions(HDLLinphoneMonitorActivity.this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1); + } else { + //鎴浘 + onClickScreenshot(); + } } else if (id == R.id.iv_lp_unlock) { //寮�閿� onClickUnlock(); } else if (id == R.id.ll_lp_btn_back) { - //杩斿洖鎸夐挳 鎸傛柇 - onClickHangUp(); + //杩斿洖鎸夐挳 + finish(); + } + } + + @Override + public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { + super.onRequestPermissionsResult(requestCode, permissions, grantResults); + switch (requestCode) { + case 1: + if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { + //鎴浘 + onClickScreenshot(); + } else { + LinphoneCommonDialog.getInstance().showSettingPermissionDialog(HDLLinphoneMonitorActivity.this, getString(R.string.open_save_permission)); + } + break; + default: } } @@ -234,47 +281,16 @@ * 寮�閿佺偣鍑讳簨浠� */ private void onClickUnlock() { - try { - AlertDialog.Builder builder = new AlertDialog.Builder(this,R.style.CustomAlertDialog); - builder.setTitle(R.string.lp_tipStr); - builder.setMessage(R.string.tip_confirm_unlock); - builder.setPositiveButton(R.string.lp_confirm, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - // 鍦ㄧ‘瀹氭寜閽鐐瑰嚮鏃舵墽琛岀殑鎿嶄綔 - // 鍙互鍦ㄨ繖閲屾坊鍔犱綘鎯宠鎵ц鐨勯�昏緫 - if (HDLLinphoneKit.getInstance().getOnHDLLinphoneCallListener() != null) { - HDLLinphoneKit.getInstance().getOnHDLLinphoneCallListener().onUnlockAction(); - } - dialog.dismiss(); // 鍏抽棴寮圭獥 + LinphoneCommonDialog.getInstance().showDialog(HDLLinphoneMonitorActivity.this, getString(R.string.tip_confirm_unlock), getString(R.string.lp_confirm), new LinphoneCommonDialog.OnOKClickListener() { + @Override + public void onOKClick() { + if (HDLLinphoneKit.getInstance().getOnHDLLinphoneCallListener() != null) { + HDLLinphoneKit.getInstance().getOnHDLLinphoneCallListener().onUnlockAction(); } - }); - builder.setNegativeButton(R.string.lp_cancel, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - // 鍦ㄥ彇娑堟寜閽鐐瑰嚮鏃舵墽琛岀殑鎿嶄綔 - // 鍙互鍦ㄨ繖閲屾坊鍔犱綘鎯宠鎵ц鐨勯�昏緫 - dialog.dismiss(); // 鍏抽棴寮圭獥 - } - }); + } + }); - AlertDialog dialog = builder.create(); - dialog.show(); - }catch (Exception exception){ - Log.e(TAG, exception.getMessage()); - } - - } - - /** - * 鎸傛柇鐐瑰嚮浜嬩欢 - */ - private void onClickHangUp() { - //1.鎸傛柇 - HDLLinphoneKit.getInstance().hangUp(); - //2.椤甸潰鍏抽棴 - finish(); } /****************寮�閿佹垚鍔�********/ @@ -333,6 +349,7 @@ // 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 + enableVideo = false; showToast(getString(R.string.lp_endMonitoringStr)); finish(); } @@ -350,6 +367,20 @@ } } + 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 */ -- Gitblit v1.8.0