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/HDLLinphoneIntercomActivity.java | 121 +++++++++++++++++++++++++++++----------- 1 files changed, 88 insertions(+), 33 deletions(-) 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 df27cb0..d5aa789 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 @@ -1,10 +1,9 @@ package com.hdl.hdllinphonesdk.activity; -import android.content.BroadcastReceiver; +import android.Manifest; 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.media.AudioAttributes; import android.os.Build; @@ -12,7 +11,9 @@ import android.os.CountDownTimer; import android.os.SystemClock; import android.os.Vibrator; -import android.support.v7.app.AlertDialog; +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; @@ -28,12 +29,15 @@ import android.widget.Toast; import com.hdl.hdllinphonesdk.HDLLinphoneKit; -import com.hdl.hdllinphonesdk.callback.OnLPOpenDoorCallBack; 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; @@ -43,6 +47,7 @@ public class HDLLinphoneIntercomActivity extends LPCheckPermissionsActivity implements View.OnClickListener { private static final String TAG = "HDLLinphoneIntercomActivity"; + private RelativeLayout ll_lp_btn_back; //鎺т欢 private TextView tv_lp_title; private ImageView iv_lp_screenshot; @@ -74,7 +79,10 @@ //Linphone private CoreListenerStub mCoreListener; + private boolean enableVideo = false; + private CallBroadcastReceiver callBroadcastReceiver; + private IntentFilter callFilter; @Override protected void onCreate(Bundle savedInstanceState) { @@ -117,6 +125,11 @@ //5. onDestroyLinphone(); + if (callBroadcastReceiver != null) { + unregisterReceiver(callBroadcastReceiver); + callBroadcastReceiver = null; + } + HDLLog.i(TAG, "onDestroy"); } @@ -126,6 +139,7 @@ * initView */ private void initView() { + 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); iv_lp_unlock = findViewById(R.id.iv_lp_unlock); @@ -151,11 +165,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", "HDLLinphoneIntercomActivity.java:onReceived-----> " + callFrom); + finish();//缁撴潫褰撳墠椤甸潰 + } + } + }); } } @@ -181,6 +217,7 @@ * init OnClickListener */ private void initOnClick() { + ll_lp_btn_back.setOnClickListener(this); iv_lp_screenshot.setOnClickListener(this); iv_lp_unlock.setOnClickListener(this); iv_lp_hangUp.setOnClickListener(this); @@ -232,8 +269,14 @@ public void onClick(View view) { int id = view.getId(); if (id == R.id.iv_lp_screenshot) { - //鎴浘 - onClickScreenshot(); + //鍔ㄦ�佹潈闄愮敵璇� + if (ContextCompat.checkSelfPermission(HDLLinphoneIntercomActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED + && ActivityCompat.checkSelfPermission(HDLLinphoneIntercomActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { + ActivityCompat.requestPermissions(HDLLinphoneIntercomActivity.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(); @@ -243,6 +286,28 @@ } else if (id == R.id.iv_lp_answer || id == R.id.tv_lp_answer) { //鎺ュ惉 onClickAnswer(); + } else if (id == R.id.ll_lp_btn_back) { + //杩斿洖鎸夐挳 鎸傛柇 + if (isAnswer) { + HDLLinphoneKit.getInstance().hangUp(); + } + 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(HDLLinphoneIntercomActivity.this, getString(R.string.open_save_permission)); + } + break; + default: } } @@ -265,38 +330,14 @@ * 寮�閿佺偣鍑讳簨浠� */ 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() { + LinphoneCommonDialog.getInstance().showDialog(HDLLinphoneIntercomActivity.this, getString(R.string.tip_confirm_unlock), getString(R.string.lp_confirm), new LinphoneCommonDialog.OnOKClickListener() { @Override - public void onClick(DialogInterface dialog, int which) { - // 鍦ㄧ‘瀹氭寜閽鐐瑰嚮鏃舵墽琛岀殑鎿嶄綔 - // 鍙互鍦ㄨ繖閲屾坊鍔犱綘鎯宠鎵ц鐨勯�昏緫 + public void onOKClick() { if (HDLLinphoneKit.getInstance().getOnHDLLinphoneCallListener() != null) { HDLLinphoneKit.getInstance().getOnHDLLinphoneCallListener().onUnlockAction(); } - dialog.dismiss(); // 鍏抽棴寮圭獥 } }); - 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()); - } - - } /** @@ -417,6 +458,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_endOfCallStr)); finish(); } @@ -432,7 +474,20 @@ core.addListener(mCoreListener); core.enableMic(true);//寮�鍚害鍏嬮 } + } + 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); } /** -- Gitblit v1.8.0