From 685a971c4049f24184423adfddb24a68b3afc0aa Mon Sep 17 00:00:00 2001
From: lss <lsc@hdlchina.com.cn>
Date: 星期三, 15 六月 2022 13:54:03 +0800
Subject: [PATCH] 2022-6-15
---
HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/activity/HDLLinphoneIntercomActivity.java | 162 ++++++++++++++++++++++++++++++++++++++++--------------
1 files changed, 120 insertions(+), 42 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 a174b8b..0a48ba6 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
@@ -5,9 +5,12 @@
import android.content.Intent;
import android.content.IntentFilter;
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.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
@@ -26,6 +29,11 @@
import com.hdl.hdllinphonesdk.callback.OnLPOpenDoorCallBack;
import com.hdl.hdllinphonesdk.R;
import com.hdl.hdllinphonesdk.utils.HDLImageUtils;
+import com.hdl.hdllinphonesdk.utils.HDLLog;
+
+import org.linphone.core.Call;
+import org.linphone.core.Core;
+import org.linphone.core.CoreListenerStub;
/**
* Linphone鎺ュ惉椤甸潰
@@ -48,15 +56,23 @@
private LinearLayout ll_video_lp_rendering;
private TextureView video_lp_rendering;
private TextureView video_lp_rendering2;
-// private TextView tv_lp_calltime;
- private Chronometer timer_lp_calltime ;
+ // private TextView tv_lp_calltime;
+ private Chronometer timer_lp_calltime;
private TextView tv_lp_calltime;
//鍙傛暟
private boolean isAnswer;//鏄惁宸茬粡鎺ュ惉浜�
private int callTime;//閫氳瘽鏃堕棿
-
+ //鍊掕鏃�
private CountDownTimer mCountDownTimer;
+ /**
+ * 鎵嬫満鎸姩鍣�
+ */
+ private Vibrator mVibrator;
+
+ //Linphone
+ private CoreListenerStub mCoreListener;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -71,6 +87,7 @@
initCallBack();
initCountDownTimer();
initLinphone();
+ initVibrator();
}
@@ -80,24 +97,25 @@
@Override
protected void onDestroy() {
super.onDestroy();
-
+ //1.鎸傛柇
+ HDLLinphoneKit.getInstance().hangUp();
+ //2.鏆傚仠璁℃椂
if (null != timer_lp_calltime) {
timer_lp_calltime.stop();
}
-
+ //3.娉ㄩ攢callBack
HDLLinphoneKit.getInstance().setOpenOpenDoorCallBack(null);
-
+ //4.鍙栨秷闇囧姩鍣�
+ cancelVibrator();
+ //5.
if (mCountDownTimer != null) {
mCountDownTimer.cancel();
mCountDownTimer = null;
}
+ //5.
+ onDestroyLinphone();
- if (mReceiver != null) {
- unregisterReceiver(mReceiver);
- }
- HDLLinphoneKit.getInstance().onDestroy();
-
- Log.i(TAG,"onDestroy");
+ HDLLog.i(TAG, "onDestroy");
}
@@ -118,19 +136,19 @@
video_lp_rendering = findViewById(R.id.video_lp_rendering);
video_lp_rendering2 = findViewById(R.id.video_lp_rendering2);
// tv_lp_calltime = findViewById(R.id.tv_lp_calltime);
- timer_lp_calltime = (Chronometer)findViewById(R.id.timer_lp_calltime);
+ timer_lp_calltime = (Chronometer) findViewById(R.id.timer_lp_calltime);
tv_lp_calltime = findViewById(R.id.tv_lp_calltime);
- setWidthHeightWithRatio(ll_video_lp_rendering,16,9);
+ setWidthHeightWithRatio(ll_video_lp_rendering, 16, 9);
}
/**
* initData
*/
- private void initData(){
+ private void initData() {
Bundle extras = getIntent().getExtras();
- if(extras != null){
- String titleName = extras.getString(HDLLinphoneKit.KEY_TITLE_NAME);
- if(!TextUtils.isEmpty(titleName)){
+ if (extras != null) {
+ String titleName = extras.getString(HDLLinphoneKit.KEY_TITLE_NAME);
+ if (!TextUtils.isEmpty(titleName)) {
tv_lp_title.setText(titleName);
}
}
@@ -153,6 +171,7 @@
view.setLayoutParams(layoutParams);
}
}
+
/**
* init OnClickListener
*/
@@ -168,7 +187,7 @@
/**
* 鍒濆鍖栧紑闂ㄥ洖璋冧簨浠�
*/
- void initCallBack(){
+ void initCallBack() {
HDLLinphoneKit.getInstance().setOpenOpenDoorCallBack(new OnLPOpenDoorCallBack() {
@Override
public void onOpenSuccess() {
@@ -185,9 +204,9 @@
/**
* 鍒濆鍖栧紑閿佸睆钄藉�掕鏃�
*/
- void initCountDownTimer(){
+ void initCountDownTimer() {
- mCountDownTimer = new CountDownTimer(10*1000, 1000) {
+ mCountDownTimer = new CountDownTimer(10 * 1000, 1000) {
@Override
public void onTick(long millisUntilFinished) {
if (!HDLLinphoneIntercomActivity.this.isFinishing()) {
@@ -232,16 +251,14 @@
private void onClickScreenshot() {
// Bitmap img = HDLImageUtils.createViewBitmap(video_lp_rendering);
Bitmap img = video_lp_rendering.getBitmap();
- boolean isSuccess = HDLImageUtils.saveImageToGallery(this, img);
+ boolean isSuccess = HDLImageUtils.saveImageToGallery(this, img);
- if(isSuccess){
+ if (isSuccess) {
showToast(getString(R.string.lp_saveToTheAlbumsStr));
- }else {
+ } else {
showToast(getString(R.string.lp_operationFailedStr));
}
}
-
-
/**
* 寮�閿佺偣鍑讳簨浠�
@@ -263,7 +280,7 @@
if (isAnswer) {
//濡傛灉涔嬪墠宸茬粡鎺ュ惉浜嗭紝鍥炶皟鏄寕鏂�
callTime = getTimerCallTime();
- Log.i("callTime","callTime"+callTime);
+ HDLLog.i("callTime", "callTime" + callTime);
HDLLinphoneKit.getInstance().getOnHDLLinphoneCallListener().onHangUpAction(callTime);
} else {
//濡傛灉涔嬪墠娌℃帴鍚簡锛屽洖璋冩槸鎷掓帴
@@ -280,6 +297,9 @@
private void onClickAnswer() {
//1.鎺ュ惉
HDLLinphoneKit.getInstance().acceptCall();
+ //2.鍙栨秷闇囧姩
+ cancelVibrator();
+ //3.淇敼UI
isAnswer = true;
tv_lp_hangUp.setText(getString(R.string.lp_hangupStr));
setViewGone(rl_lp_answerView);
@@ -303,12 +323,14 @@
iv_lp_unlock.setEnabled(false);
startOpenDoorCountdown();
}
+
/**
* 寮�鍚�掕鏃�
*/
void startOpenDoorCountdown() {
mCountDownTimer.start();
}
+
/**
* 閫氳瘽璁板綍寮�鍚�掕鏃�
*/
@@ -316,12 +338,12 @@
timer_lp_calltime.setBase(SystemClock.elapsedRealtime());//璁℃椂鍣ㄦ竻闆�
timer_lp_calltime.start();
}
- int getTimerCallTime(){
+
+ int getTimerCallTime() {
int temp0 = Integer.parseInt(timer_lp_calltime.getText().toString().split(":")[0]);
- int temp1 =Integer.parseInt(timer_lp_calltime.getText().toString().split(":")[1]);
+ int temp1 = Integer.parseInt(timer_lp_calltime.getText().toString().split(":")[1]);
return temp0 * 60 + temp1;
}
-
/****************灏佽甯哥敤鏂规硶********/
@@ -351,23 +373,79 @@
}
/**********LinPhone**********/
- void initLinphone(){
- IntentFilter intentFilter = new IntentFilter(RECEIVE_FINISH_VIDEO_ACTIVITY);
- mReceiver = new FinishVideoActivityReceiver();
- registerReceiver(mReceiver, intentFilter);
- HDLLinphoneKit.getInstance().setAndroidVideoWindow(video_lp_rendering, video_lp_rendering2);
+ /**
+ * initLinphone
+ */
+ void initLinphone() {
+ mCoreListener = new CoreListenerStub() {
+ @Override
+ public void onCallStateChanged(Core core, Call call, Call.State state, String message) {
+ if (state == Call.State.End || state == Call.State.Released) {
+ // 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
+ showToast(getString(R.string.lp_endOfCallStr));
+ finish();
+ }
+ }
+ };
+
+ Core core = HDLLinphoneKit.getInstance().getCore();
+ // We need to tell the core in which to display what
+ if (core != null) {
+ core.setNativeVideoWindowId(video_lp_rendering);
+ core.setNativePreviewWindowId(video_lp_rendering2);
+ // Listen for call state changes
+ core.addListener(mCoreListener);
+ core.enableMic(true);//寮�鍚害鍏嬮
+ }
+
}
+ /**
+ * onDestroyLinphone
+ */
+ void onDestroyLinphone() {
+ Core core = HDLLinphoneKit.getInstance().getCore();
+ if (core != null) {
+ core.removeListener(mCoreListener);
+ core.setNativeVideoWindowId(null);
+ core.setNativePreviewWindowId(null);
+ }
+ video_lp_rendering = null;
+ video_lp_rendering2 = null;
+ }
- public class FinishVideoActivityReceiver extends BroadcastReceiver {
- @Override
- public void onReceive(Context context, Intent intent) {
- HDLLinphoneIntercomActivity.this.finish();
+ /**
+ * 鍒濆鍖栭渿鍔ㄥ櫒
+ */
+ 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("褰撳墠鎵嬫満娌℃湁闇囧姩鍣�");
}
}
- private FinishVideoActivityReceiver mReceiver;
- public static final String RECEIVE_FINISH_VIDEO_ACTIVITY = "receive_finish_video_activity";
+ /**
+ * 鍏抽棴闇囧姩鍣�
+ */
+ void cancelVibrator() {
+ if (mVibrator != null) {
+ mVibrator.cancel();
+ mVibrator = null;
+ }
-
+ }
}
\ No newline at end of file
--
Gitblit v1.8.0