diff --git a/modules/mogo-module-carchatting/src/main/java/com/mogo/module/carchatting/view/CallingWindowManager.kt b/modules/mogo-module-carchatting/src/main/java/com/mogo/module/carchatting/view/CallingWindowManager.kt index 8021797f80..40659b9208 100644 --- a/modules/mogo-module-carchatting/src/main/java/com/mogo/module/carchatting/view/CallingWindowManager.kt +++ b/modules/mogo-module-carchatting/src/main/java/com/mogo/module/carchatting/view/CallingWindowManager.kt @@ -3,6 +3,7 @@ package com.mogo.module.carchatting.view import android.annotation.SuppressLint import android.content.Context import android.media.AudioManager +import android.os.Handler import android.view.LayoutInflater import android.view.View import android.widget.FrameLayout @@ -35,6 +36,9 @@ class CallingWindowManager private constructor() : IVoiceIntentListener { companion object { + const val MSG_DIALING_TIME_OUT = 1001 + const val DEFAULT_MAX_DIALING_TIME = 30 * 1000L + val callingWindowManager by lazy(LazyThreadSafetyMode.SYNCHRONIZED) { CallingWindowManager() } @@ -84,6 +88,8 @@ class CallingWindowManager private constructor() : IVoiceIntentListener { private var agreeIncomingBack: (() -> Unit)? = null private var hangUpIncomingBack: (() -> Unit)? = null + private var handler: Handler? = null + @SuppressLint("InflateParams") fun init( context: Context, serviceApi: IMogoServiceApis, @@ -101,6 +107,16 @@ class CallingWindowManager private constructor() : IVoiceIntentListener { this.showVehicleTeamView = showVehicleTeamView this.quitVehicleTeam = quitVehicleTeam this.moveToCenter = moveToCenter + handler = Handler(context.mainLooper) { + log(TAG, "times up ,ready to refuse call ") + when (it.what) { + MSG_DIALING_TIME_OUT -> { + releaseAudioAndVoice() + hangUpIncomingBack?.invoke() + } + } + true + } hideIncomingView() } @@ -210,6 +226,7 @@ class CallingWindowManager private constructor() : IVoiceIntentListener { this.agreeIncomingBack = agreeIncomingBack this.hangUpIncomingBack = hangUpIncomingBack if (!isLauncherCallingViewShown) { + handler?.sendEmptyMessageDelayed(MSG_DIALING_TIME_OUT, DEFAULT_MAX_DIALING_TIME) IMVoiceClient.speakAndRegisterCall({ _ -> if (isLauncherCallingViewShown) { log(TAG, "speakAndRegisterCall") @@ -246,8 +263,10 @@ class CallingWindowManager private constructor() : IVoiceIntentListener { mContext!!.resources.getDimension(R.dimen.module_call_chat_state_incoming_hawk_eye_height) .toInt() ) - val x = mContext!!.resources.getDimension(R.dimen.module_call_chat_state_location_hawk_eye_x) - val y = mContext!!.resources.getDimension(R.dimen.module_call_chat_state_location_hawk_eye_y) + val x = + mContext!!.resources.getDimension(R.dimen.module_call_chat_state_location_hawk_eye_x) + val y = + mContext!!.resources.getDimension(R.dimen.module_call_chat_state_location_hawk_eye_y) params.leftMargin = x.toInt() params.topMargin = y.toInt() serviceApi?.windowManagerApi?.addView(launcherIncomingView, params, true) @@ -329,6 +348,7 @@ class CallingWindowManager private constructor() : IVoiceIntentListener { return } Logger.d(TAG, "隐藏Launcher来电浮窗===$isLauncherCallingViewShown") + handler?.removeMessages(MSG_DIALING_TIME_OUT) releaseAudioAndVoice() if (isLauncherIncomingViewShown) { isLauncherIncomingViewShown = false