panlili2024
2024-11-13 848cbfebefab08cc49b0285155edb84463aed862
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) {
                    //如果收到推送通知把监视页面finish
                    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
     */