|
|
@@ -5,16 +5,16 @@ import android.content.Context.WINDOW_SERVICE
|
|
|
import android.content.res.Configuration
|
|
|
import android.graphics.PixelFormat
|
|
|
import android.os.Build
|
|
|
+import android.util.AttributeSet
|
|
|
import android.view.Gravity
|
|
|
import android.view.LayoutInflater
|
|
|
import android.view.View
|
|
|
import android.view.WindowManager
|
|
|
-import android.widget.ImageView
|
|
|
-import android.widget.RelativeLayout
|
|
|
-import android.widget.TextView
|
|
|
+import androidx.constraintlayout.widget.ConstraintLayout
|
|
|
import com.adealink.frame.log.Log
|
|
|
import com.adealink.weparty.call.R
|
|
|
import com.adealink.weparty.call.constant.TAG_CALL_INCOMING_VIEW
|
|
|
+import com.adealink.weparty.call.databinding.CallIncomingFloatViewBinding
|
|
|
import com.tencent.cloud.tuikit.engine.call.TUICallDefine
|
|
|
import com.tencent.qcloud.tuicore.TUICore
|
|
|
import com.tencent.qcloud.tuicore.interfaces.ITUINotification
|
|
|
@@ -24,26 +24,26 @@ import com.tencent.qcloud.tuikit.tuicallkit.data.Constants
|
|
|
import com.tencent.qcloud.tuikit.tuicallkit.data.User
|
|
|
import com.tencent.qcloud.tuikit.tuicallkit.manager.EngineManager
|
|
|
import com.tencent.qcloud.tuikit.tuicallkit.state.TUICallState
|
|
|
-import com.tencent.qcloud.tuikit.tuicallkit.utils.ImageLoader
|
|
|
import com.tencent.qcloud.tuikit.tuicallkit.utils.PermissionRequest
|
|
|
import com.tencent.qcloud.tuikit.tuicallkit.view.component.videolayout.VideoViewFactory
|
|
|
import com.trtc.tuikit.common.livedata.Observer
|
|
|
|
|
|
-class IncomingFloatView(context: Context) : RelativeLayout(context) {
|
|
|
+
|
|
|
+class IncomingFloatView @JvmOverloads constructor(
|
|
|
+ context: Context,
|
|
|
+ attrs: AttributeSet? = null,
|
|
|
+ defStyleAttr: Int = 0,
|
|
|
+) : ConstraintLayout(context, attrs, defStyleAttr) {
|
|
|
+
|
|
|
+ private val binding = CallIncomingFloatViewBinding.inflate(LayoutInflater.from(context), this, true)
|
|
|
|
|
|
private var appContext: Context = context.applicationContext
|
|
|
private var caller: User? = null
|
|
|
|
|
|
+ private lateinit var windowView: View
|
|
|
private var windowManager: WindowManager? = null
|
|
|
private var windowLayoutParams: WindowManager.LayoutParams? = null
|
|
|
|
|
|
- private lateinit var layoutView: View
|
|
|
- private var imageFloatAvatar: ImageView? = null
|
|
|
- private var textFloatTitle: TextView? = null
|
|
|
- private var textFloatDescription: TextView? = null
|
|
|
- private var imageReject: ImageView? = null
|
|
|
- private var imageAccept: ImageView? = null
|
|
|
-
|
|
|
private val padding = 40
|
|
|
|
|
|
private var callStatusObserver = Observer<TUICallDefine.Status> {
|
|
|
@@ -54,7 +54,8 @@ class IncomingFloatView(context: Context) : RelativeLayout(context) {
|
|
|
|
|
|
private val notification = ITUINotification { key, subKey, param ->
|
|
|
if (key == Constants.EVENT_VIEW_STATE_CHANGED &&
|
|
|
- (subKey == Constants.EVENT_SHOW_FULL_VIEW || subKey == Constants.EVENT_SHOW_FLOAT_VIEW)) {
|
|
|
+ (subKey == Constants.EVENT_SHOW_FULL_VIEW || subKey == Constants.EVENT_SHOW_FLOAT_VIEW)
|
|
|
+ ) {
|
|
|
cancelIncomingView()
|
|
|
}
|
|
|
}
|
|
|
@@ -68,8 +69,8 @@ class IncomingFloatView(context: Context) : RelativeLayout(context) {
|
|
|
|
|
|
fun cancelIncomingView() {
|
|
|
Log.d(TAG_CALL_INCOMING_VIEW, "cancelIncomingView")
|
|
|
- if (layoutView.isAttachedToWindow) {
|
|
|
- windowManager?.removeView(layoutView)
|
|
|
+ if (isAttachedToWindow) {
|
|
|
+ windowManager?.removeView(this)
|
|
|
}
|
|
|
removeObserver()
|
|
|
}
|
|
|
@@ -86,38 +87,32 @@ class IncomingFloatView(context: Context) : RelativeLayout(context) {
|
|
|
}
|
|
|
|
|
|
private fun initWindow() {
|
|
|
- layoutView = LayoutInflater.from(context).inflate(R.layout.tuicallkit_incoming_float_view, this)
|
|
|
- imageFloatAvatar = layoutView.findViewById(R.id.img_float_avatar)
|
|
|
- textFloatTitle = layoutView.findViewById(R.id.tv_float_title)
|
|
|
- textFloatDescription = layoutView.findViewById(R.id.tv_float_desc)
|
|
|
- imageReject = layoutView.findViewById(R.id.btn_float_decline)
|
|
|
- imageAccept = layoutView.findViewById(R.id.btn_float_accept)
|
|
|
-
|
|
|
-// ImageLoader.loadImage(appContext, imageFloatAvatar, caller?.avatar?.get(), R.drawable.tuicallkit_ic_avatar)
|
|
|
-// textFloatTitle?.text = caller?.nickname?.get()
|
|
|
-
|
|
|
- textFloatDescription?.text = if (TUICallState.instance.mediaType.get() == TUICallDefine.MediaType.Video) {
|
|
|
- appContext.resources.getString(R.string.tuicallkit_invite_video_call)
|
|
|
+ windowView = binding.root
|
|
|
+ // TODO: zhangfei
|
|
|
+ //caller?.avatar?.get()
|
|
|
+ //binding.ivAvatar.setImageUrl()
|
|
|
+
|
|
|
+ binding.tvTips.text = if (TUICallState.instance.mediaType.get() == TUICallDefine.MediaType.Video) {
|
|
|
+ appContext.resources.getString(R.string.call_invite_video_call)
|
|
|
} else {
|
|
|
- appContext.resources.getString(R.string.tuicallkit_invite_audio_call)
|
|
|
+ appContext.resources.getString(R.string.call_invite_audio_call)
|
|
|
}
|
|
|
|
|
|
- imageReject?.setOnClickListener {
|
|
|
- EngineManager.instance.reject(null)
|
|
|
+ binding.root.setOnClickListener {
|
|
|
cancelIncomingView()
|
|
|
+ TUICore.notifyEvent(Constants.EVENT_TUICALLKIT_CHANGED, Constants.EVENT_START_ACTIVITY, HashMap())
|
|
|
}
|
|
|
|
|
|
- layoutView.setOnClickListener {
|
|
|
+ binding.rejectBtn.setOnClickListener {
|
|
|
+ EngineManager.instance.reject(null)
|
|
|
cancelIncomingView()
|
|
|
- TUICore.notifyEvent(Constants.EVENT_TUICALLKIT_CHANGED, Constants.EVENT_START_ACTIVITY, HashMap())
|
|
|
}
|
|
|
-
|
|
|
if (TUICallState.instance.mediaType.get() == TUICallDefine.MediaType.Video) {
|
|
|
- imageAccept?.setBackgroundResource(R.drawable.tuicallkit_ic_dialing_video)
|
|
|
+ binding.acceptBtn.setImageResource(R.drawable.call_video_accept_ic)
|
|
|
} else {
|
|
|
- imageAccept?.setBackgroundResource(R.drawable.tuicallkit_bg_dialing)
|
|
|
+ binding.acceptBtn.setImageResource(R.drawable.call_chat_accept_ic)
|
|
|
}
|
|
|
- imageAccept?.setOnClickListener {
|
|
|
+ binding.acceptBtn.setOnClickListener {
|
|
|
if (TUICallState.instance.selfUser.get().callStatus.get() == TUICallDefine.Status.None) {
|
|
|
Log.w(TAG_CALL_INCOMING_VIEW, "current status is None, ignore")
|
|
|
cancelIncomingView()
|
|
|
@@ -158,31 +153,32 @@ class IncomingFloatView(context: Context) : RelativeLayout(context) {
|
|
|
}
|
|
|
|
|
|
windowManager = appContext.getSystemService(WINDOW_SERVICE) as WindowManager
|
|
|
- windowManager?.addView(layoutView, viewParams)
|
|
|
+ windowManager?.addView(windowView, viewParams)
|
|
|
}
|
|
|
|
|
|
private val viewParams: WindowManager.LayoutParams
|
|
|
get() {
|
|
|
- windowLayoutParams = WindowManager.LayoutParams()
|
|
|
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
- windowLayoutParams!!.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY
|
|
|
- } else {
|
|
|
- windowLayoutParams!!.type = WindowManager.LayoutParams.TYPE_PHONE
|
|
|
+ windowLayoutParams = WindowManager.LayoutParams().apply {
|
|
|
+ type = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
+ WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY
|
|
|
+ } else {
|
|
|
+ WindowManager.LayoutParams.TYPE_PHONE
|
|
|
+ }
|
|
|
+ flags = (WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
|
|
|
+ or WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
|
|
|
+ or WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
|
|
|
+ gravity = Gravity.START or Gravity.TOP
|
|
|
+ x = padding
|
|
|
+ y = 0
|
|
|
+ width = ScreenUtil.getScreenWidth(appContext) - padding * 2
|
|
|
+ height = WindowManager.LayoutParams.WRAP_CONTENT
|
|
|
+ format = PixelFormat.TRANSPARENT
|
|
|
}
|
|
|
- windowLayoutParams!!.flags = (WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
|
|
|
- or WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
|
|
|
- or WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
|
|
|
- windowLayoutParams!!.gravity = Gravity.START or Gravity.TOP
|
|
|
- windowLayoutParams!!.x = padding
|
|
|
- windowLayoutParams!!.y = 0
|
|
|
- windowLayoutParams!!.width = ScreenUtil.getScreenWidth(appContext) - padding * 2
|
|
|
- windowLayoutParams!!.height = WindowManager.LayoutParams.WRAP_CONTENT
|
|
|
- windowLayoutParams!!.format = PixelFormat.TRANSPARENT
|
|
|
return windowLayoutParams as WindowManager.LayoutParams
|
|
|
}
|
|
|
|
|
|
override fun onConfigurationChanged(newConfig: Configuration?) {
|
|
|
super.onConfigurationChanged(newConfig)
|
|
|
- layoutView?.let { windowManager?.updateViewLayout(layoutView, viewParams) }
|
|
|
+ windowView?.let { windowManager?.updateViewLayout(windowView, viewParams) }
|
|
|
}
|
|
|
}
|