panlili2024
2025-02-27 bca03b5f891af5966a06b1ecd00f6cd573659ce6
HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/activity/HDLLinphoneReverseCallActivity.java
@@ -1,16 +1,19 @@
package com.hdl.hdllinphonesdk.activity;
import android.Manifest;
import android.content.Context;
import android.content.DialogInterface;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.media.AudioAttributes;
import android.os.Build;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.SystemClock;
import android.os.Vibrator;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
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,6 +31,8 @@
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;
@@ -42,6 +47,7 @@
public class HDLLinphoneReverseCallActivity extends LPCheckPermissionsActivity implements View.OnClickListener {
    private static final String TAG = "HDLLinphoneReverseCallActivity";
    private RelativeLayout ll_lp_btn_back;
    //控件
    private TextView tv_lp_title;
    private ImageView iv_lp_screenshot;
@@ -53,6 +59,10 @@
    private ImageView iv_lp_answer;
    private TextView tv_lp_answer;
    private RelativeLayout rl_lp_answerView;
    private ImageView iv_lp_rejectall;
    private TextView tv_lp_rejectall;
    private RelativeLayout rl_lp_rejectallView;
    private LinearLayout ll_video_lp_rendering;
    private TextureView video_lp_rendering;
@@ -77,6 +87,11 @@
    private String deviceSipAccount;//设备SIP账号
    private boolean enableVideo = false;
    private CallBroadcastReceiver callBroadcastReceiver;
    private IntentFilter callFilter;
    private boolean callAllRejection = false;//自研门口机是否支持全部拒接
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
@@ -90,7 +105,6 @@
        initCallBack();
        initCountDownTimer();
        initLinphone();
//        initVibrator();
    }
    /**
@@ -107,14 +121,19 @@
        }
        //3.注销callBack
        HDLLinphoneKit.getInstance().setOpenOpenDoorCallBack(null);
        //4.取消震动器
        cancelVibrator();
        //5.
        //4.
        if (mCountDownTimer != null) {
            mCountDownTimer.cancel();
            mCountDownTimer = null;
        }
        onDestroyLinphone();
        if (callBroadcastReceiver != null) {
            unregisterReceiver(callBroadcastReceiver);
            callBroadcastReceiver = null;
        }
        HDLLog.i(TAG, "onDestroy");
    }
@@ -122,6 +141,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);
@@ -130,6 +150,9 @@
        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);
        iv_lp_rejectall = findViewById(R.id.iv_lp_hangUpall);
        tv_lp_rejectall = findViewById(R.id.tv_lp_hangUpall);
        rl_lp_rejectallView = findViewById(R.id.rl_lp_hangUpallView);
        ll_video_lp_rendering = findViewById(R.id.ll_video_lp_rendering);
        video_lp_rendering = findViewById(R.id.video_lp_rendering);
        video_lp_rendering2 = findViewById(R.id.video_lp_rendering2);
@@ -147,12 +170,41 @@
     */
    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);
            }
            deviceSipAccount = extras.getString(HDLLinphoneKit.KEY_SIP_ACCOUNT);
            interphoneType = extras.getString("interphoneType");
            callAllRejection = extras.getBoolean(HDLLinphoneKit.KEY_CALL_ALL_REJECTION);
        }
        rl_lp_rejectallView.setVisibility(callAllRejection ? View.VISIBLE : View.GONE);
        //监听呼叫广播
        callFilter = new IntentFilter();
        callFilter.addAction("com.hdl.homepro.call.action");
        callBroadcastReceiver = new CallBroadcastReceiver();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            registerReceiver(callBroadcastReceiver, callFilter, RECEIVER_EXPORTED);
        } else {
            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", "HDLLinphoneIntercomActivity.java:onReceived-----> " + callFrom);
                        finish();//结束当前页面
                    }
                }
            });
        }
    }
@@ -178,12 +230,15 @@
     * 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);
        tv_lp_hangUp.setOnClickListener(this);
        iv_lp_answer.setOnClickListener(this);
        tv_lp_answer.setOnClickListener(this);
        iv_lp_rejectall.setOnClickListener(this);
        tv_lp_rejectall.setOnClickListener(this);
    }
    /**
@@ -232,8 +287,14 @@
    public void onClick(View view) {
        int id = view.getId();
        if (id == R.id.iv_lp_screenshot) {
            //截图
            onClickScreenshot();
            //动态权限申请
            if (ContextCompat.checkSelfPermission(HDLLinphoneReverseCallActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED
                    && ActivityCompat.checkSelfPermission(HDLLinphoneReverseCallActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
                ActivityCompat.requestPermissions(HDLLinphoneReverseCallActivity.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 +304,31 @@
        } else if (id == R.id.iv_lp_answer || id == R.id.tv_lp_answer) {
            //接听
            onClickAnswer();
        } else if (id == R.id.iv_lp_hangUpall || id == R.id.tv_lp_hangUpall) {
            //拒接全部
            onClickRejectAll();
        } 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(HDLLinphoneReverseCallActivity.this, getString(R.string.open_save_permission));
                }
                break;
            default:
        }
    }
@@ -266,37 +352,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() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // 在确定按钮被点击时执行的操作
                    // 可以在这里添加你想要执行的逻辑
                    if (HDLLinphoneKit.getInstance().getOnHDLLinphoneCallListener() != null) {
                        HDLLinphoneKit.getInstance().getOnHDLLinphoneCallListener().onUnlockAction();
                    }
                    dialog.dismiss(); // 关闭弹窗
        LinphoneCommonDialog.getInstance().showDialog(HDLLinphoneReverseCallActivity.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());
        }
            }
        });
    }
    /**
@@ -319,6 +382,19 @@
        finish();
    }
    /**
     * 拒接全部点击事件
     */
    private void onClickRejectAll() {
        //1.回调事件
        if (HDLLinphoneKit.getInstance().getOnHDLLinphoneCallListener() != null) {
            HDLLinphoneKit.getInstance().getOnHDLLinphoneCallListener().onRejectCallAllAction();
        }
        //2.页面关闭
        finish();
    }
    /**
     * 接听按钮点击事件
     */
@@ -330,12 +406,11 @@
        }
        HDLLinphoneKit.getInstance().callTo(deviceSipAccount, true);
        //2.取消震动
        cancelVibrator();
        //3.修改UI
        //2.修改UI
        isAnswer = true;
        tv_lp_hangUp.setText(getString(R.string.lp_hangupStr));
        setViewGone(rl_lp_answerView);
        setViewGone(rl_lp_rejectallView);
        setViewGone(tv_lp_calltime);
        setViewVisible(timer_lp_calltime);
        startCallTimeCountdown();
@@ -419,15 +494,9 @@
                    // 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();
                } else if (state == Call.State.StreamsRunning) {
                    if (HDLLinphoneKit.getInstance().getIntercomeType().equals(HDLLinphoneKit.INTER_PHONE_TYPE_HDL)) {
                        if (!enableVideo) {
                            enableVideo(core, call);
                            enableVideo = true;
                        }
                    }
                }
            }
        };
@@ -473,36 +542,4 @@
        video_lp_rendering2 = null;
    }
    /**
     * 初始化震动器
     */
    void initVibrator() {
        mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
        if (mVibrator.hasVibrator()) {
            long[] patern = {0, 1000, 1000};
            AudioAttributes audioAttributes = null;
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                audioAttributes = new AudioAttributes.Builder()
                        .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
                        .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE) //key
                        .build();
                mVibrator.vibrate(patern, 1, audioAttributes);
            } else {
                mVibrator.vibrate(patern, 1);
            }
        } else {
            HDLLog.E("当前手机没有震动器");
        }
    }
    /**
     * 关闭震动器
     */
    void cancelVibrator() {
        if (mVibrator != null) {
            mVibrator.cancel();
            mVibrator = null;
        }
    }
}