From 83d5ada866a598ee868d3e23624d104d1027db29 Mon Sep 17 00:00:00 2001 From: wxr <wxr@hdlchina.com.cn> Date: 星期二, 27 八月 2024 15:28:42 +0800 Subject: [PATCH] 增加挂断功能 --- HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/activity/HDLLinphoneReverseCallActivity.java | 103 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 96 insertions(+), 7 deletions(-) diff --git a/HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/activity/HDLLinphoneReverseCallActivity.java b/HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/activity/HDLLinphoneReverseCallActivity.java index 9420018..7127c51 100644 --- a/HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/activity/HDLLinphoneReverseCallActivity.java +++ b/HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/activity/HDLLinphoneReverseCallActivity.java @@ -4,8 +4,10 @@ import android.content.DialogInterface; import android.graphics.Bitmap; import android.media.AudioAttributes; +import android.media.MediaPlayer; import android.os.Build; import android.os.CountDownTimer; +import android.os.Handler; import android.os.SystemClock; import android.os.Vibrator; import android.support.v7.app.AlertDialog; @@ -32,6 +34,7 @@ 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; @@ -48,6 +51,10 @@ private ImageView iv_lp_hangUp; private TextView tv_lp_hangUp; + + private RelativeLayout rl_lp_hangUpAll; + private ImageView iv_lp_hangUpAll; + private TextView tv_lp_hangUpAll; private ImageView iv_lp_answer; private TextView tv_lp_answer; @@ -74,6 +81,9 @@ private CoreListenerStub mCoreListener; private String deviceSipAccount;//璁惧SIP璐﹀彿 + private boolean enableVideo = false; + + private CountDownTimer mMissedCallsTimer; @Override protected void onCreate(Bundle savedInstanceState) { @@ -89,7 +99,10 @@ initCountDownTimer(); initLinphone(); // initVibrator(); + initMissedCallsTimer(); + mMissedCallsTimer.start(); } + /** * onDestroy @@ -112,6 +125,10 @@ mCountDownTimer.cancel(); mCountDownTimer = null; } + if (mMissedCallsTimer != null) { + mMissedCallsTimer.cancel(); + mMissedCallsTimer = null; + } onDestroyLinphone(); HDLLog.i(TAG, "onDestroy"); } @@ -125,6 +142,9 @@ iv_lp_unlock = findViewById(R.id.iv_lp_unlock); iv_lp_hangUp = findViewById(R.id.iv_lp_hangUp); tv_lp_hangUp = findViewById(R.id.tv_lp_hangUp); + rl_lp_hangUpAll = findViewById(R.id.rl_lp_hangUp_all); + iv_lp_hangUpAll = findViewById(R.id.iv_lp_hangUp_all); + tv_lp_hangUpAll = findViewById(R.id.tv_lp_hangUp_all); 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); @@ -182,6 +202,8 @@ tv_lp_hangUp.setOnClickListener(this); iv_lp_answer.setOnClickListener(this); tv_lp_answer.setOnClickListener(this); + iv_lp_hangUpAll.setOnClickListener(this); + tv_lp_hangUpAll.setOnClickListener(this); } /** @@ -205,7 +227,6 @@ * 鍒濆鍖栧紑閿佸睆钄藉�掕鏃� */ void initCountDownTimer() { - mCountDownTimer = new CountDownTimer(10 * 1000, 1000) { @Override public void onTick(long millisUntilFinished) { @@ -218,12 +239,40 @@ */ @Override public void onFinish() { -// showToast("寮�閿乷nFinish"); iv_lp_unlock.setEnabled(true); } - }; -// + } + + /** + * 鍒濆鍖栨帴鍚鏃跺櫒 + */ + void initMissedCallsTimer() { + mMissedCallsTimer = new CountDownTimer(HDLLinphoneKit.getInstance().missedCallsTime * 1000, 1000) { + @Override + public void onTick(long millisUntilFinished) { + if (!HDLLinphoneReverseCallActivity.this.isFinishing()) { + if(isAnswer){ + mMissedCallsTimer.cancel(); + mMissedCallsTimer = null; + } + } + } + + /** + *鍊掕鏃剁粨鏉熷悗璋冪敤鐨� + */ + @Override + public void onFinish() { + if (!HDLLinphoneReverseCallActivity.this.isFinishing()) { + if (!isAnswer) { + isAnswer = true; + HDLLinphoneKit.getInstance().getOnHDLLinphoneCallListener().onMissedCallsAction(); + finish(); + } + } + } + }; } @Override @@ -241,6 +290,9 @@ } else if (id == R.id.iv_lp_answer || id == R.id.tv_lp_answer) { //鎺ュ惉 onClickAnswer(); + } else if (id == R.id.iv_lp_hangUp_all || id == R.id.tv_lp_hangUp_all) { + //鍏ㄩ儴鎸傛柇 + onClickHangUpAll(); } } @@ -265,7 +317,7 @@ */ private void onClickUnlock() { try { - AlertDialog.Builder builder = new AlertDialog.Builder(this,R.style.CustomAlertDialog); + AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.CustomAlertDialog); builder.setTitle(R.string.lp_tipStr); builder.setMessage(R.string.tip_confirm_unlock); @@ -291,8 +343,8 @@ AlertDialog dialog = builder.create(); dialog.show(); - }catch (Exception exception){ - Log.e(TAG, exception.getMessage()); + } catch (Exception exception) { + Log.e(TAG, exception.getMessage()); } } @@ -318,6 +370,20 @@ } /** + * 鍏ㄩ儴鎸傛柇鐐瑰嚮浜嬩欢 + */ + private void onClickHangUpAll() { + //1.鎸傛柇 + HDLLinphoneKit.getInstance().hangUp(); + //2.鍥炶皟浜嬩欢 + if (HDLLinphoneKit.getInstance().getOnHDLLinphoneCallListener() != null) { + HDLLinphoneKit.getInstance().getOnHDLLinphoneCallListener().onCallAllRejection(); + } + //3.椤甸潰鍏抽棴 + finish(); + } + + /** * 鎺ュ惉鎸夐挳鐐瑰嚮浜嬩欢 */ private void onClickAnswer() { @@ -335,6 +401,7 @@ tv_lp_hangUp.setText(getString(R.string.lp_hangupStr)); setViewGone(rl_lp_answerView); setViewGone(tv_lp_calltime); + setViewGone(rl_lp_hangUpAll); setViewVisible(timer_lp_calltime); startCallTimeCountdown(); //鎺ュ惉閫氱煡 @@ -419,6 +486,13 @@ // we missed the first one 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; + } + } } } }; @@ -435,6 +509,21 @@ } + + 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 */ -- Gitblit v1.8.0