video fix bugs

merge-requests/745/head
mosazaid 3 years ago
parent 5312c221d1
commit 0868de7961

@ -27,7 +27,6 @@
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:label="HMG Doctor">
<activity android:name=".ui.VideoCallActivity"></activity>
<activity
android:name=".MainActivity"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"

@ -3,6 +3,7 @@ package com.hmg.hmgDr
import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.widget.Toast
import androidx.annotation.NonNull
import com.google.gson.GsonBuilder
@ -73,16 +74,6 @@ class MainActivity : FlutterFragmentActivity(), MethodChannel.MethodCallHandler,
}
private fun openVideoCall(apiKey: String?, sessionId: String?, token: String?, appLang: String?, baseUrl: String?, sessionStatusModel: GetSessionStatusModel) {
// val videoCallActivity = VideoCallActivity()
// val intent = Intent(this, VideoCallActivity::class.java)
// intent.putExtra("apiKey", apiKey)
// intent.putExtra("sessionId", sessionId)
// intent.putExtra("token", token)
// intent.putExtra("appLang", appLang)
// intent.putExtra("baseUrl", baseUrl)
// intent.putExtra("sessionStatusModel", sessionStatusModel)
// startActivityForResult(intent, LAUNCH_VIDEO)
if (dialogFragment == null) {
val arguments = Bundle()
arguments.putString("apiKey", apiKey)
@ -97,7 +88,13 @@ class MainActivity : FlutterFragmentActivity(), MethodChannel.MethodCallHandler,
dialogFragment?.let {
it.setCallListener(this)
it.isCancelable = true
it.show(transaction, "dialog")
if (it.isAdded){
it.dismiss()
}else {
it.show(transaction, "dialog")
}
}
} else if (!dialogFragment!!.isVisible) {
val transaction = supportFragmentManager.beginTransaction()
@ -146,7 +143,11 @@ class MainActivity : FlutterFragmentActivity(), MethodChannel.MethodCallHandler,
val jsonRes = gson.toJson(result)
callResponse["sessionStatus"] = jsonRes
this.result?.success(callResponse)
try {
this.result?.success(callResponse)
} catch (e : Exception){
Log.e("onVideoCallFinished", "${e.message}.")
}
} else if (resultCode == Activity.RESULT_CANCELED) {
val callResponse: HashMap<String, String> = HashMap()
callResponse["callResponse"] = "CallEnd"
@ -166,5 +167,8 @@ class MainActivity : FlutterFragmentActivity(), MethodChannel.MethodCallHandler,
methodChannel.invokeMethod("onCallDisconnected", null)
}
override fun onBackPressed() {
super.onBackPressed()
}
}

@ -1,481 +0,0 @@
package com.hmg.hmgDr.ui;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Handler;
import android.os.SystemClock;
import android.util.Log;
import android.view.View;
import android.widget.Chronometer;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.hmg.hmgDr.Model.ChangeCallStatusRequestModel;
import com.hmg.hmgDr.Model.GetSessionStatusModel;
import com.hmg.hmgDr.Model.SessionStatusModel;
import com.hmg.hmgDr.R;
import com.opentok.android.Session;
import com.opentok.android.Stream;
import com.opentok.android.Publisher;
import com.opentok.android.PublisherKit;
import com.opentok.android.Subscriber;
import com.opentok.android.BaseVideoRenderer;
import com.opentok.android.OpentokError;
import com.opentok.android.SubscriberKit;
import java.util.List;
import java.util.Objects;
import pub.devrel.easypermissions.AfterPermissionGranted;
import pub.devrel.easypermissions.AppSettingsDialog;
import pub.devrel.easypermissions.EasyPermissions;
public class VideoCallActivity extends AppCompatActivity implements EasyPermissions.PermissionCallbacks,
Session.SessionListener,
Publisher.PublisherListener,
Subscriber.VideoListener, VideoCallContract.VideoCallView {
private static final String TAG = VideoCallActivity.class.getSimpleName();
VideoCallContract.VideoCallPresenter videoCallPresenter;
private static final int RC_SETTINGS_SCREEN_PERM = 123;
private static final int RC_VIDEO_APP_PERM = 124;
private Session mSession;
private Publisher mPublisher;
private Subscriber mSubscriber;
private Handler mVolHandler, mConnectedHandler;
private Runnable mVolRunnable, mConnectedRunnable;
private FrameLayout mPublisherViewContainer;
private FrameLayout mSubscriberViewContainer;
private RelativeLayout controlPanel;
private String apiKey;
private String sessionId;
private String token;
private String appLang;
private String baseUrl;
private boolean isSwitchCameraClicked;
private boolean isCameraClicked;
private boolean isSpeckerClicked;
private boolean isMicClicked;
private TextView patientName;
private Chronometer cmTimer;
long elapsedTime;
Boolean resume = false;
private ImageView mCallBtn;
private ImageView btnMinimize;
private ImageView mCameraBtn;
private ImageView mSwitchCameraBtn;
private ImageView mspeckerBtn;
private ImageView mMicBtn;
private ProgressBar progressBar;
private CountDownTimer countDownTimer;
private TextView progressBarTextView;
private RelativeLayout progressBarLayout;
private boolean isConnected = false;
private GetSessionStatusModel sessionStatusModel;
@Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(R.style.AppTheme);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video_call);
Objects.requireNonNull(getSupportActionBar()).hide();
initUI();
requestPermissions();
}
@Override
protected void onPause() {
super.onPause();
if (mSession == null) {
return;
}
mSession.onPause();
if (isFinishing()) {
disconnectSession();
}
}
@Override
protected void onResume() {
super.onResume();
if (mSession == null) {
return;
}
mSession.onResume();
}
@Override
protected void onDestroy() {
disconnectSession();
cmTimer.stop();
super.onDestroy();
}
@SuppressLint("ClickableViewAccessibility")
private void initUI() {
mPublisherViewContainer = findViewById(R.id.local_video_view_container);
mSubscriberViewContainer = findViewById(R.id.remote_video_view_container);
apiKey = getIntent().getStringExtra("apiKey");
sessionId = getIntent().getStringExtra("sessionId");
token = getIntent().getStringExtra("token");
appLang = getIntent().getStringExtra("appLang");
baseUrl = getIntent().getStringExtra("baseUrl");
sessionStatusModel = getIntent().getParcelableExtra("sessionStatusModel");
controlPanel = findViewById(R.id.control_panel);
videoCallPresenter = new VideoCallPresenterImpl(this, baseUrl);
patientName = findViewById(R.id.patient_name);
patientName.setText(sessionStatusModel.getPatientName());
cmTimer = findViewById(R.id.cmTimer);
cmTimer.setFormat("mm:ss");
cmTimer.setOnChronometerTickListener(arg0 -> {
long minutes;
long seconds;
if (!resume) {
minutes = ((SystemClock.elapsedRealtime() - cmTimer.getBase()) / 1000) / 60;
seconds = ((SystemClock.elapsedRealtime() - cmTimer.getBase()) / 1000) % 60;
elapsedTime = SystemClock.elapsedRealtime();
} else {
minutes = ((elapsedTime - cmTimer.getBase()) / 1000) / 60;
seconds = ((elapsedTime - cmTimer.getBase()) / 1000) % 60;
elapsedTime = elapsedTime + 1000;
}
Log.d(TAG, "onChronometerTick: " + minutes + " : " + seconds);
});
mCallBtn = findViewById(R.id.btn_call);
btnMinimize = findViewById(R.id.btn_minimize);
mCameraBtn = findViewById(R.id.btn_camera);
mSwitchCameraBtn = findViewById(R.id.btn_switch_camera);
mspeckerBtn = findViewById(R.id.btn_specker);
mMicBtn = findViewById(R.id.btn_mic);
// progressBarLayout=findViewById(R.id.progressBar);
// progressBar=findViewById(R.id.progress_bar);
// progressBarTextView=findViewById(R.id.progress_bar_text);
// progressBar.setVisibility(View.GONE);
hiddenButtons();
checkClientConnected();
mSubscriberViewContainer.setOnTouchListener((v, event) -> {
controlPanel.setVisibility(View.VISIBLE);
mVolHandler.removeCallbacks(mVolRunnable);
mVolHandler.postDelayed(mVolRunnable, 5 * 1000);
return true;
});
if (appLang.equals("ar")) {
progressBarLayout.setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
}
}
private void checkClientConnected() {
mConnectedHandler = new Handler();
mConnectedRunnable = () -> {
if (!isConnected) {
videoCallPresenter.callClintConnected(sessionStatusModel);
}
};
mConnectedHandler.postDelayed(mConnectedRunnable, 55 * 1000);
}
private void hiddenButtons() {
mVolHandler = new Handler();
mVolRunnable = () -> controlPanel.setVisibility(View.GONE);
mVolHandler.postDelayed(mVolRunnable, 5 * 1000);
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
}
@Override
public void onPermissionsGranted(int requestCode, List<String> perms) {
Log.d(TAG, "onPermissionsGranted:" + requestCode + ":" + perms.size());
}
@Override
public void onPermissionsDenied(int requestCode, List<String> perms) {
Log.d(TAG, "onPermissionsDenied:" + requestCode + ":" + perms.size());
if (EasyPermissions.somePermissionPermanentlyDenied(this, perms)) {
new AppSettingsDialog.Builder(this)
.setTitle(getString(R.string.title_settings_dialog))
.setRationale(getString(R.string.rationale_ask_again))
.setPositiveButton(getString(R.string.setting))
.setNegativeButton(getString(R.string.cancel))
.setRequestCode(RC_SETTINGS_SCREEN_PERM)
.build()
.show();
}
}
@AfterPermissionGranted(RC_VIDEO_APP_PERM)
private void requestPermissions() {
String[] perms = {Manifest.permission.INTERNET, Manifest.permission.CAMERA,};
if (EasyPermissions.hasPermissions(this, perms)) {
try {
mSession = new Session.Builder(this, apiKey, sessionId).build();
mSession.setSessionListener(this);
mSession.connect(token);
} catch (Exception e) {
e.printStackTrace();
}
} else {
EasyPermissions.requestPermissions(this, getString(R.string.remaining_ar), RC_VIDEO_APP_PERM, perms);
}
}
@Override
public void onConnected(Session session) {
Log.i(TAG, "Session Connected");
mPublisher = new Publisher.Builder(this).build();
mPublisher.setPublisherListener(this);
mPublisherViewContainer.addView(mPublisher.getView());
if (mPublisher.getView() instanceof GLSurfaceView) {
((GLSurfaceView) mPublisher.getView()).setZOrderOnTop(true);
}
mSession.publish(mPublisher);
if (!resume) {
cmTimer.setBase(SystemClock.elapsedRealtime());
}
cmTimer.start();
}
@Override
public void onDisconnected(Session session) {
Log.d(TAG, "onDisconnected: disconnected from session " + session.getSessionId());
mSession = null;
cmTimer.stop();
}
@Override
public void onError(Session session, OpentokError opentokError) {
Log.d(TAG, "onError: Error (" + opentokError.getMessage() + ") in session " + session.getSessionId());
// Toast.makeText(this, "Session error. See the logcat please.", Toast.LENGTH_LONG).show();
//finish();
}
@Override
public void onStreamReceived(Session session, Stream stream) {
Log.d(TAG, "onStreamReceived: New stream " + stream.getStreamId() + " in session " + session.getSessionId());
if (mSubscriber != null) {
isConnected = true;
return;
}
isConnected = true;
subscribeToStream(stream);
if(mConnectedHandler!=null && mConnectedRunnable!=null)
mConnectedHandler.removeCallbacks(mConnectedRunnable);
videoCallPresenter.callChangeCallStatus(new ChangeCallStatusRequestModel(3,sessionStatusModel.getDoctorId(), sessionStatusModel.getGeneralid(),token,sessionStatusModel.getVCID()));
}
@Override
public void onStreamDropped(Session session, Stream stream) {
Log.d(TAG, "onStreamDropped: Stream " + stream.getStreamId() + " dropped from session " + session.getSessionId());
if (mSubscriber == null) {
return;
}
if (mSubscriber.getStream().equals(stream)) {
mSubscriberViewContainer.removeView(mSubscriber.getView());
mSubscriber.destroy();
mSubscriber = null;
}
disconnectSession();
}
@Override
public void onStreamCreated(PublisherKit publisherKit, Stream stream) {
Log.d(TAG, "onStreamCreated: Own stream " + stream.getStreamId() + " created");
}
@Override
public void onStreamDestroyed(PublisherKit publisherKit, Stream stream) {
Log.d(TAG, "onStreamDestroyed: Own stream " + stream.getStreamId() + " destroyed");
}
@Override
public void onError(PublisherKit publisherKit, OpentokError opentokError) {
Log.d(TAG, "onError: Error (" + opentokError.getMessage() + ") in publisher");
// Toast.makeText(this, "onError: Error (" + opentokError.getMessage() + ") in publisher", Toast.LENGTH_LONG).show();
// finish();
}
@Override
public void onVideoDataReceived(SubscriberKit subscriberKit) {
mSubscriber.setStyle(BaseVideoRenderer.STYLE_VIDEO_SCALE, BaseVideoRenderer.STYLE_VIDEO_FILL);
mSubscriberViewContainer.addView(mSubscriber.getView());
}
@Override
public void onVideoDisabled(SubscriberKit subscriberKit, String s) {
}
@Override
public void onVideoEnabled(SubscriberKit subscriberKit, String s) {
}
@Override
public void onVideoDisableWarning(SubscriberKit subscriberKit) {
}
@Override
public void onVideoDisableWarningLifted(SubscriberKit subscriberKit) {
}
private void subscribeToStream(Stream stream) {
mSubscriber = new Subscriber.Builder(VideoCallActivity.this, stream).build();
mSubscriber.setVideoListener(this);
mSession.subscribe(mSubscriber);
}
private void disconnectSession() {
if (mSession == null) {
setResult(Activity.RESULT_CANCELED);
finish();
return;
}
if (mSubscriber != null) {
mSubscriberViewContainer.removeView(mSubscriber.getView());
mSession.unsubscribe(mSubscriber);
mSubscriber.destroy();
mSubscriber = null;
}
if (mPublisher != null) {
mPublisherViewContainer.removeView(mPublisher.getView());
mSession.unpublish(mPublisher);
mPublisher.destroy();
mPublisher = null;
}
mSession.disconnect();
if (countDownTimer != null) {
countDownTimer.cancel();
}
videoCallPresenter.callChangeCallStatus(new ChangeCallStatusRequestModel(16,sessionStatusModel.getDoctorId(), sessionStatusModel.getGeneralid(),token,sessionStatusModel.getVCID()));
finish();
}
public void onSwitchCameraClicked(View view) {
if (mPublisher != null) {
isSwitchCameraClicked = !isSwitchCameraClicked;
mPublisher.cycleCamera();
int res = isSwitchCameraClicked ? R.drawable.camera_front : R.drawable.camera_back;
mSwitchCameraBtn.setImageResource(res);
}
}
public void onCallClicked(View view) {
disconnectSession();
}
public void onMinimizedClicked(View view) {
}
public void onCameraClicked(View view) {
if (mPublisher != null) {
isCameraClicked = !isCameraClicked;
mPublisher.setPublishVideo(!isCameraClicked);
int res = isCameraClicked ? R.drawable.video_disabled : R.drawable.video_enabled;
mCameraBtn.setImageResource(res);
}
}
public void onMicClicked(View view) {
if (mPublisher != null) {
isMicClicked = !isMicClicked;
mPublisher.setPublishAudio(!isMicClicked);
int res = isMicClicked ? R.drawable.mic_disabled : R.drawable.mic_enabled;
mMicBtn.setImageResource(res);
}
}
public void onSpeckerClicked(View view) {
if (mSubscriber != null) {
isSpeckerClicked = !isSpeckerClicked;
mSubscriber.setSubscribeToAudio(!isSpeckerClicked);
int res = isSpeckerClicked ? R.drawable.audio_disabled : R.drawable.audio_enabled;
mspeckerBtn.setImageResource(res);
}
}
@Override
public void onCallSuccessful(SessionStatusModel sessionStatusModel) {
if (sessionStatusModel.getSessionStatus() == 2 || sessionStatusModel.getSessionStatus() == 3) {
Intent returnIntent = new Intent();
returnIntent.putExtra("sessionStatusNotRespond", sessionStatusModel);
setResult(Activity.RESULT_OK, returnIntent);
finish();
} else if( sessionStatusModel.getSessionStatus() == 4 ){
isConnected = true;
if(mConnectedHandler!=null && mConnectedRunnable!=null)
mConnectedHandler.removeCallbacks(mConnectedRunnable);
}
}
@Override
public void onCallChangeCallStatusSuccessful(SessionStatusModel sessionStatusModel) {
}
@Override
public void onFailure() {
}
}

@ -9,4 +9,6 @@ interface VideoCallResponseListener {
fun errorHandle(message: String)
fun minimizeVideoEvent(isMinimize : Boolean)
fun onBackHandle(){}
}

@ -16,7 +16,6 @@ import android.view.*
import android.widget.*
import androidx.annotation.Nullable
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.constraintlayout.widget.ConstraintSet
import androidx.core.view.GestureDetectorCompat
import androidx.fragment.app.DialogFragment
import com.hmg.hmgDr.Model.ChangeCallStatusRequestModel
@ -39,7 +38,7 @@ import kotlin.math.ceil
class VideoCallFragment : DialogFragment(), PermissionCallbacks, Session.SessionListener, PublisherListener,
SubscriberKit.VideoListener, VideoCallView {
var isFullScreen: Boolean = true
private var isFullScreen: Boolean = true
private var x_init_cord = 0
private var y_init_cord: Int = 0
private var x_init_margin: Int = 0
@ -48,7 +47,7 @@ class VideoCallFragment : DialogFragment(), PermissionCallbacks, Session.Session
private lateinit var mWindowManager: WindowManager
private var isLeft = true
lateinit var videoCallPresenter: VideoCallPresenter
private lateinit var videoCallPresenter: VideoCallPresenter
private var mSession: Session? = null
private var mPublisher: Publisher? = null
@ -88,8 +87,8 @@ class VideoCallFragment : DialogFragment(), PermissionCallbacks, Session.Session
private lateinit var patientName: TextView
private lateinit var cmTimer: Chronometer
var elapsedTime: Long = 0
var resume = false
private var elapsedTime: Long = 0
private var resume = false
private val progressBar: ProgressBar? = null
private val countDownTimer: CountDownTimer? = null
@ -122,6 +121,18 @@ class VideoCallFragment : DialogFragment(), PermissionCallbacks, Session.Session
override fun onCreateDialog(@Nullable savedInstanceState: Bundle?): Dialog {
val dialog: Dialog = super.onCreateDialog(savedInstanceState)
// Add back button listener
// Add back button listener
dialog.setOnKeyListener { _, keyCode, keyEvent ->
// getAction to make sure this doesn't double fire
if (keyCode == KeyEvent.KEYCODE_BACK && keyEvent.action == KeyEvent.ACTION_UP) {
videoCallResponseListener?.onBackHandle()
false // Capture onKey
} else true
// Don't capture
}
return dialog
}
@ -438,7 +449,6 @@ class VideoCallFragment : DialogFragment(), PermissionCallbacks, Session.Session
dialog?.dismiss()
}
override fun onCallSuccessful(sessionStatusModel: SessionStatusModel) {
if (sessionStatusModel.sessionStatus == 2 || sessionStatusModel.sessionStatus == 3) {
val returnIntent = Intent()
@ -523,7 +533,7 @@ class VideoCallFragment : DialogFragment(), PermissionCallbacks, Session.Session
//// localPreviewLayoutParam = RelativeLayout.LayoutParams(localPreviewWidth, localPreviewHeight)
localPreviewLayoutParam.width = localPreviewWidth
localPreviewLayoutParam.height = localPreviewHeight
localPreviewLayoutParam.setMargins(0,localPreviewMargin, localPreviewMargin, 0)
localPreviewLayoutParam.setMargins(0, localPreviewMargin, localPreviewMargin, 0)
// remotePreviewLayoutParam = FrameLayout.LayoutParams(remotePreviewIconSize, remotePreviewIconSize)
remotePreviewLayoutParam.width = remotePreviewIconSize
remotePreviewLayoutParam.height = remotePreviewIconSize
@ -544,7 +554,7 @@ class VideoCallFragment : DialogFragment(), PermissionCallbacks, Session.Session
localPreviewLayoutParam.width = 0
localPreviewLayoutParam.height = 0
localPreviewLayoutParam.setMargins(0,localPreviewMargin / 2, localPreviewMargin/ 2, 0)
localPreviewLayoutParam.setMargins(0, localPreviewMargin / 2, localPreviewMargin / 2, 0)
// localPreviewLayoutIconParam = FrameLayout.LayoutParams(localPreviewIconSmall, localPreviewIconSmall)
//// localPreviewLayoutParam = RelativeLayout.LayoutParams(localPreviewWidthSmall, localPreviewHeightSmall)
// localPreviewLayoutParam.width = localPreviewWidthSmall
@ -591,7 +601,7 @@ class VideoCallFragment : DialogFragment(), PermissionCallbacks, Session.Session
}
@SuppressLint("ClickableViewAccessibility")
fun handleDragDialog() {
private fun handleDragDialog() {
mWindowManager = requireActivity().getSystemService(Context.WINDOW_SERVICE) as WindowManager
getWindowManagerDefaultDisplay()
@ -600,7 +610,7 @@ class VideoCallFragment : DialogFragment(), PermissionCallbacks, Session.Session
}
@SuppressLint("ClickableViewAccessibility")
val dragListener: View.OnTouchListener = View.OnTouchListener { _, event ->
private val dragListener: View.OnTouchListener = View.OnTouchListener { _, event ->
mDetector.onTouchEvent(event)
//Get Floating widget view params
@ -631,10 +641,10 @@ class VideoCallFragment : DialogFragment(), PermissionCallbacks, Session.Session
// y_cord_Destination = 0
// y_cord_Destination =
// -(szWindow.y - (videoCallContainer.height /*+ barHeight*/))
y_cord_Destination = - (szWindow.y/2)
y_cord_Destination = -(szWindow.y / 2)
} else if (y_cord_Destination + (videoCallContainer.height + barHeight) > szWindow.y) {
// y_cord_Destination = szWindow.y - (videoCallContainer.height + barHeight)
y_cord_Destination = (szWindow.y/2)
y_cord_Destination = (szWindow.y / 2)
}
layoutParams.y = y_cord_Destination

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<!-- <solid-->
<!-- android:color="#666666"/>-->
<stroke android:width="2dp" android:color="@color/white" />
<size
android:width="120dp"
android:height="120dp"/>
</shape>

@ -1,7 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/text_color"/>
<stroke android:width="3dp" android:color="@color/text_color" />
<corners android:radius="10dp"/>
<padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" />
<solid android:color="@color/text_color" />
<stroke
android:width="3dp"
android:color="@color/text_color" />
<corners android:radius="10dp" />
<padding
android:bottom="0dp"
android:left="0dp"
android:right="0dp"
android:top="0dp" />
</shape>

Loading…
Cancel
Save