make floating video screen

video-stream-floating
mosazaid 5 years ago
parent 7cc25f6101
commit 23ccbbe806

@ -86,9 +86,6 @@ class MainActivity : FlutterFragmentActivity(), MethodChannel.MethodCallHandler,
} }
"closeVideoCall" -> { "closeVideoCall" -> {
videoStreamService?.closeVideoCall() videoStreamService?.closeVideoCall()
}
"onCallConnected" -> {
} }
else -> { else -> {
result.notImplemented() result.notImplemented()
@ -214,15 +211,17 @@ class MainActivity : FlutterFragmentActivity(), MethodChannel.MethodCallHandler,
} }
stopService(serviceIntent) stopService(serviceIntent)
unbindService()
videoStreamService!!.serviceRunning = false
} }
override fun minimizeVideoEvent(isMinimize: Boolean) { override fun minimizeVideoEvent(isMinimize: Boolean) {
if (isMinimize) if (isMinimize)
methodChannel.invokeMethod("onCallConnected", null) methodChannel.invokeMethod("onCallConnected", null)
else else {
methodChannel.invokeMethod("onCallDisconnected", null) methodChannel.invokeMethod("onCallDisconnected", null)
unbindService()
videoStreamService!!.serviceRunning = false
videoStreamService = null
}
} }
override fun onBackPressed() { override fun onBackPressed() {

@ -1,6 +1,5 @@
package com.hmg.hmgDr.Service package com.hmg.hmgDr.Service
import android.Manifest
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.app.Activity import android.app.Activity
import android.app.Service import android.app.Service
@ -23,13 +22,9 @@ import com.hmg.hmgDr.R
import com.hmg.hmgDr.ui.VideoCallContract import com.hmg.hmgDr.ui.VideoCallContract
import com.hmg.hmgDr.ui.VideoCallPresenterImpl import com.hmg.hmgDr.ui.VideoCallPresenterImpl
import com.hmg.hmgDr.ui.VideoCallResponseListener import com.hmg.hmgDr.ui.VideoCallResponseListener
import com.hmg.hmgDr.ui.fragment.VideoCallFragment
import com.hmg.hmgDr.util.DynamicVideoRenderer import com.hmg.hmgDr.util.DynamicVideoRenderer
import com.hmg.hmgDr.util.ViewsUtil import com.hmg.hmgDr.util.ViewsUtil
import com.opentok.android.* import com.opentok.android.*
import pub.devrel.easypermissions.AfterPermissionGranted
import pub.devrel.easypermissions.AppSettingsDialog
import pub.devrel.easypermissions.EasyPermissions
import kotlin.math.ceil import kotlin.math.ceil
class VideoStreamFloatingWidgetService : Service(), Session.SessionListener, class VideoStreamFloatingWidgetService : Service(), Session.SessionListener,
@ -46,7 +41,7 @@ class VideoStreamFloatingWidgetService : Service(), Session.SessionListener,
} }
private lateinit var windowManagerParams : WindowManager.LayoutParams private lateinit var windowManagerParams: WindowManager.LayoutParams
private var mWindowManager: WindowManager? = null private var mWindowManager: WindowManager? = null
private val szWindow = Point() private val szWindow = Point()
private var floatingWidgetView: View? = null private var floatingWidgetView: View? = null
@ -116,7 +111,7 @@ class VideoStreamFloatingWidgetService : Service(), Session.SessionListener,
private val serviceBinder: IBinder = VideoStreamBinder() private val serviceBinder: IBinder = VideoStreamBinder()
override fun onBind(intent: Intent?): IBinder? { override fun onBind(intent: Intent?): IBinder {
return serviceBinder return serviceBinder
} }
@ -157,7 +152,8 @@ class VideoStreamFloatingWidgetService : Service(), Session.SessionListener,
override fun onDestroy() { override fun onDestroy() {
disconnectSession() mWindowManager?.removeView(floatingWidgetView)
// disconnectSession()
cmTimer.stop() cmTimer.stop()
super.onDestroy() super.onDestroy()
} }
@ -196,7 +192,7 @@ class VideoStreamFloatingWidgetService : Service(), Session.SessionListener,
init(floatingWidgetView!!) init(floatingWidgetView!!)
//Add the view to the window //Add the view to the window
mWindowManager!!.addView(floatingWidgetView, windowManagerParams) mWindowManager?.addView(floatingWidgetView, windowManagerParams)
} }
@SuppressLint("ClickableViewAccessibility") @SuppressLint("ClickableViewAccessibility")
@ -312,7 +308,7 @@ class VideoStreamFloatingWidgetService : Service(), Session.SessionListener,
videoCallPresenter.callClintConnected(sessionStatusModel) videoCallPresenter.callClintConnected(sessionStatusModel)
} }
} }
mConnectedHandler!!.postDelayed(mConnectedRunnable!!, (55 * 1000).toLong()) mConnectedHandler!!.postDelayed(mConnectedRunnable!!, (10 * 1000).toLong()) // TODO MOSA return from 10 to 55
} }
private fun handleVideoViewHeight() { private fun handleVideoViewHeight() {
@ -511,13 +507,13 @@ class VideoStreamFloatingWidgetService : Service(), Session.SessionListener,
windowManagerParams.width = 400 windowManagerParams.width = 400
windowManagerParams.height = 600 windowManagerParams.height = 600
mWindowManager!!.updateViewLayout(floatingWidgetView, windowManagerParams) mWindowManager?.updateViewLayout(floatingWidgetView, windowManagerParams)
recordContainer.visibility = View.GONE recordContainer.visibility = View.GONE
} else { } else {
windowManagerParams.width = WindowManager.LayoutParams.MATCH_PARENT windowManagerParams.width = WindowManager.LayoutParams.MATCH_PARENT
windowManagerParams.height = WindowManager.LayoutParams.MATCH_PARENT windowManagerParams.height = WindowManager.LayoutParams.MATCH_PARENT
mWindowManager!!.updateViewLayout(floatingWidgetView, windowManagerParams) mWindowManager?.updateViewLayout(floatingWidgetView, windowManagerParams)
if (isRecording) { if (isRecording) {
recordContainer.visibility = View.VISIBLE recordContainer.visibility = View.VISIBLE
@ -583,12 +579,12 @@ class VideoStreamFloatingWidgetService : Service(), Session.SessionListener,
windowManagerParams.width = 400 windowManagerParams.width = 400
windowManagerParams.height = 600 windowManagerParams.height = 600
mWindowManager!!.updateViewLayout(floatingWidgetView, windowManagerParams) mWindowManager?.updateViewLayout(floatingWidgetView, windowManagerParams)
} else { } else {
windowManagerParams.width = 300 windowManagerParams.width = 300
windowManagerParams.height = 300 windowManagerParams.height = 300
mWindowManager!!.updateViewLayout(floatingWidgetView, windowManagerParams) mWindowManager?.updateViewLayout(floatingWidgetView, windowManagerParams)
} }
isCircle = !isCircle isCircle = !isCircle
@ -642,7 +638,7 @@ class VideoStreamFloatingWidgetService : Service(), Session.SessionListener,
} }
} }
fun closeVideoCall(){ fun closeVideoCall() {
onCallClicked() onCallClicked()
} }
@ -730,7 +726,6 @@ class VideoStreamFloatingWidgetService : Service(), Session.SessionListener,
private fun disconnectSession() { private fun disconnectSession() {
if (mSession == null) { if (mSession == null) {
videoCallResponseListener?.onCallFinished(Activity.RESULT_CANCELED) videoCallResponseListener?.onCallFinished(Activity.RESULT_CANCELED)
// requireActivity().setResult(Activity.RESULT_CANCELED)
stopSelf() stopSelf()
return return
} }
@ -867,8 +862,8 @@ class VideoStreamFloatingWidgetService : Service(), Session.SessionListener,
if (sessionStatusModel.sessionStatus == 2 || sessionStatusModel.sessionStatus == 3) { if (sessionStatusModel.sessionStatus == 2 || sessionStatusModel.sessionStatus == 3) {
val returnIntent = Intent() val returnIntent = Intent()
returnIntent.putExtra("sessionStatusNotRespond", sessionStatusModel) returnIntent.putExtra("sessionStatusNotRespond", sessionStatusModel)
disconnectSession()
videoCallResponseListener?.onCallFinished(Activity.RESULT_OK, returnIntent) videoCallResponseListener?.onCallFinished(Activity.RESULT_OK, returnIntent)
// requireActivity().setResult(Activity.RESULT_OK, returnIntent)
stopSelf() stopSelf()
} }
} }
@ -929,12 +924,13 @@ class VideoStreamFloatingWidgetService : Service(), Session.SessionListener,
mDetector.onTouchEvent(event) mDetector.onTouchEvent(event)
if(floatingWidgetView!!.layoutParams is WindowManager.LayoutParams){ if (floatingWidgetView!!.layoutParams is WindowManager.LayoutParams) {
var asd = ""; var asd = "";
} }
//Get Floating widget view params //Get Floating widget view params
val layoutParams: WindowManager.LayoutParams = floatingWidgetView!!.layoutParams as WindowManager.LayoutParams val layoutParams: WindowManager.LayoutParams =
floatingWidgetView!!.layoutParams as WindowManager.LayoutParams
//get the touch location coordinates //get the touch location coordinates
val x_cord = event.rawX.toInt() val x_cord = event.rawX.toInt()
val y_cord = event.rawY.toInt() val y_cord = event.rawY.toInt()
@ -981,7 +977,7 @@ class VideoStreamFloatingWidgetService : Service(), Session.SessionListener,
layoutParams.y = y_cord_Destination layoutParams.y = y_cord_Destination
//Update the layout with new X & Y coordinate //Update the layout with new X & Y coordinate
mWindowManager!!.updateViewLayout(floatingWidgetView, layoutParams) mWindowManager?.updateViewLayout(floatingWidgetView, layoutParams)
} }
} }
true true
@ -999,16 +995,18 @@ class VideoStreamFloatingWidgetService : Service(), Session.SessionListener,
/* Method to move the Floating widget view to Left */ /* Method to move the Floating widget view to Left */
private fun moveToLeft(current_x_cord: Int) { private fun moveToLeft(current_x_cord: Int) {
val mParams: WindowManager.LayoutParams = floatingWidgetView!!.layoutParams as WindowManager.LayoutParams val mParams: WindowManager.LayoutParams =
floatingWidgetView!!.layoutParams as WindowManager.LayoutParams
mParams.x = mParams.x =
(szWindow.x - current_x_cord * current_x_cord - videoCallContainer.width).toInt() (szWindow.x - current_x_cord * current_x_cord - videoCallContainer.width).toInt()
mWindowManager!!.updateViewLayout(floatingWidgetView, mParams) mWindowManager?.updateViewLayout(floatingWidgetView, mParams)
val x = szWindow.x - current_x_cord val x = szWindow.x - current_x_cord
object : CountDownTimer(500, 5) { object : CountDownTimer(500, 5) {
//get params of Floating Widget view //get params of Floating Widget view
val mParams: WindowManager.LayoutParams = floatingWidgetView!!.layoutParams as WindowManager.LayoutParams val mParams: WindowManager.LayoutParams =
floatingWidgetView!!.layoutParams as WindowManager.LayoutParams
override fun onTick(t: Long) { override fun onTick(t: Long) {
val step = (500 - t) / 5 val step = (500 - t) / 5
@ -1016,13 +1014,13 @@ class VideoStreamFloatingWidgetService : Service(), Session.SessionListener,
mParams.x = mParams.x =
(szWindow.x - current_x_cord * current_x_cord * step - videoCallContainer.width).toInt() (szWindow.x - current_x_cord * current_x_cord * step - videoCallContainer.width).toInt()
mWindowManager!!.updateViewLayout(floatingWidgetView, mParams) mWindowManager?.updateViewLayout(floatingWidgetView, mParams)
} }
override fun onFinish() { override fun onFinish() {
mParams.x = -(szWindow.x - videoCallContainer.width) mParams.x = -(szWindow.x - videoCallContainer.width)
mWindowManager!!.updateViewLayout(floatingWidgetView, mParams) mWindowManager?.updateViewLayout(floatingWidgetView, mParams)
} }
}.start() }.start()
} }
@ -1036,19 +1034,21 @@ class VideoStreamFloatingWidgetService : Service(), Session.SessionListener,
// dialog!!.window!!.attributes = mParams // dialog!!.window!!.attributes = mParams
object : CountDownTimer(500, 5) { object : CountDownTimer(500, 5) {
//get params of Floating Widget view //get params of Floating Widget view
val mParams: WindowManager.LayoutParams = floatingWidgetView!!.layoutParams as WindowManager.LayoutParams val mParams: WindowManager.LayoutParams =
floatingWidgetView!!.layoutParams as WindowManager.LayoutParams
override fun onTick(t: Long) { override fun onTick(t: Long) {
val step = (500 - t) / 5 val step = (500 - t) / 5
mParams.x = mParams.x =
(szWindow.x + current_x_cord * current_x_cord * step - videoCallContainer.width).toInt() (szWindow.x + current_x_cord * current_x_cord * step - videoCallContainer.width).toInt()
mWindowManager!!.updateViewLayout(floatingWidgetView, mParams) mWindowManager?.updateViewLayout(floatingWidgetView, mParams)
} }
override fun onFinish() { override fun onFinish() {
mParams.x = szWindow.x - videoCallContainer.width mParams.x = szWindow.x - videoCallContainer.width
mWindowManager!!.updateViewLayout(floatingWidgetView, mParams) mWindowManager?.updateViewLayout(floatingWidgetView, mParams)
} }
}.start() }.start()
} }

@ -468,10 +468,7 @@ class VideoCallFragment : DialogFragment(), PermissionCallbacks, Session.Session
} }
override fun onStreamReceived(session: Session, stream: Stream) { override fun onStreamReceived(session: Session, stream: Stream) {
Log.d( Log.d(TAG, "onStreamReceived: New stream " + stream.streamId + " in session " + session.sessionId)
TAG,
"onStreamReceived: New stream " + stream.streamId + " in session " + session.sessionId
)
if (mSubscriber != null) { if (mSubscriber != null) {
isConnected = true isConnected = true
return return

Loading…
Cancel
Save