| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | 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; |
| | | |
| | |
| | | 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; |
| | |
| | | |
| | | //Linphone |
| | | private CoreListenerStub mCoreListener; |
| | | private boolean enableVideo = false; |
| | | |
| | | private CallBroadcastReceiver callBroadcastReceiver; |
| | | private IntentFilter callFilter; |
| | | |
| | | @Override |
| | | protected void onCreate(Bundle savedInstanceState) { |
| | |
| | | //5. |
| | | onDestroyLinphone(); |
| | | |
| | | if (callBroadcastReceiver != null) { |
| | | unregisterReceiver(callBroadcastReceiver); |
| | | callBroadcastReceiver = null; |
| | | } |
| | | |
| | | HDLLog.i(TAG, "onDestroy"); |
| | | |
| | | } |
| | |
| | | * 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); |
| | |
| | | */ |
| | | 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", "HDLLinphoneIntercomActivity.java:onReceived-----> " + callFrom); |
| | | finish();//结束当前页面 |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | |
| | |
| | | * 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); |
| | |
| | | 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(); |
| | |
| | | } 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: |
| | | } |
| | | } |
| | | |
| | |
| | | * 开锁点击事件 |
| | | */ |
| | | 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()); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | // 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(); |
| | | } |
| | |
| | | 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); |
| | | } |
| | | |
| | | /** |