capacitor-plugin-vonage 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,23 +4,27 @@ package com.managemyhealth.plugin.vonage;
4
4
 
5
5
  import android.annotation.SuppressLint;
6
6
  import android.app.Activity;
7
+ import android.app.AlertDialog;
7
8
  import android.app.Application;
8
9
  import android.content.Context;
9
10
  import android.graphics.Color;
10
- import android.graphics.PorterDuff;
11
+ import android.graphics.drawable.ColorDrawable;
12
+ import android.graphics.drawable.GradientDrawable;
11
13
  import android.os.AsyncTask;
12
14
  import android.app.ActionBar;
13
15
  import android.content.Intent;
14
16
  import android.graphics.Bitmap;
15
17
  import android.graphics.BitmapFactory;
16
18
  import android.opengl.GLSurfaceView;
19
+ import android.os.Build;
17
20
  import android.os.Bundle;
18
21
  import android.os.Handler;
19
- import android.os.Looper;
22
+ import android.util.DisplayMetrics;
20
23
  import android.util.Log;
21
24
  import android.view.Gravity;
22
25
  import android.view.LayoutInflater;
23
26
  import android.view.View;
27
+ import android.view.ViewGroup;
24
28
  import android.widget.Button;
25
29
  import android.widget.FrameLayout;
26
30
  import android.widget.ImageView;
@@ -28,15 +32,10 @@ import android.widget.LinearLayout;
28
32
  import android.widget.ProgressBar;
29
33
  import android.widget.TextView;
30
34
  import android.widget.Toast;
31
-
32
35
  import androidx.annotation.NonNull;
33
36
  import androidx.appcompat.app.AppCompatActivity;
34
- import androidx.lifecycle.ViewModelProvider;
35
-
36
-
37
37
  import com.getcapacitor.Bridge;
38
- import com.google.android.material.floatingactionbutton.FloatingActionButton;
39
-
38
+ import com.google.android.gms.common.api.internal.LifecycleActivity;
40
39
  import com.opentok.android.BaseVideoRenderer;
41
40
  import com.opentok.android.OpentokError;
42
41
  import com.opentok.android.Publisher;
@@ -45,22 +44,12 @@ import com.opentok.android.Session;
45
44
  import com.opentok.android.Stream;
46
45
  import com.opentok.android.Subscriber;
47
46
  import com.opentok.android.SubscriberKit;
48
- //import com.tokbox.sample.basicvideochat.network.APIService;
49
- //import com.tokbox.sample.basicvideochat.network.GetSessionResponse;
50
-
51
47
  import java.io.InputStream;
52
48
  import java.util.List;
53
-
54
49
  import javax.annotation.Nullable;
55
-
56
- import pub.devrel.easypermissions.AfterPermissionGranted;
57
50
  import pub.devrel.easypermissions.EasyPermissions;
58
-
59
-
60
- public class VideoCallActivity extends AppCompatActivity implements EasyPermissions.PermissionCallbacks , Application.ActivityLifecycleCallbacks{
51
+ public class VideoCallActivity extends AppCompatActivity implements EasyPermissions.PermissionCallbacks, Application.ActivityLifecycleCallbacks {
61
52
  private static final String TAG = VideoCallActivity.class.getSimpleName();
62
- private static final int PERMISSIONS_REQUEST_CODE = 124;
63
-
64
53
  public Session session;
65
54
  private static Bridge staticBridge = null;
66
55
  private String dummyProfile = "https://www.gravatar.com/avatar/?d=mp";
@@ -73,7 +62,6 @@ public class VideoCallActivity extends AppCompatActivity implements EasyPermissi
73
62
  boolean isPatientOnline = false;
74
63
  boolean isMuted = false;
75
64
  boolean isCamOff = false;
76
- private static boolean isCallinprogress = false;
77
65
  public boolean temptest = false;
78
66
  boolean isTimeron = false;
79
67
  boolean isEndall = false;
@@ -83,71 +71,37 @@ public class VideoCallActivity extends AppCompatActivity implements EasyPermissi
83
71
  private LinearLayout main;
84
72
  private ProgressBar progressBar;
85
73
  private FrameLayout subscriberViewContainer;
74
+ private FrameLayout subscribersubViewContainer;
86
75
  private TextView publisherNameTextView;
87
- private FloatingActionButton fabCameraOff;
88
76
  private ImageView imageViewEndcall;
89
77
  private ImageView imageViewMute;
90
78
  private ImageView imageViewCamOff;
91
79
  private ImageView circleAvatar;
92
- private boolean isAppInForeground;
93
-
94
80
  private ImageView imageViewCamSwitch;
95
81
  public static Button sendNotifications ;
96
82
  public static TextView patientStatus;
97
83
  public static TextView publishernameView;
98
84
  public static Button admit;
99
85
  public static Button deny ;
100
-
101
-
102
- private static final int LOG_INTERVAL_MILLIS = 1000; // Log every 100 milliseconds
103
-
104
- private final Handler handler = new Handler();
105
- private final Runnable logRunnable = new Runnable() {
106
- @Override
107
- public void run() {
108
- Log.d(TAG, "Log message");
109
- // if(temptest){
110
- // Log.d(TAG, "temptest "+ temptest);
111
- //
112
- // }else{
113
- // Log.d(TAG, "temptest "+temptest);
114
- //
115
- // }
116
- handler.postDelayed(this, LOG_INTERVAL_MILLIS);
117
- }
118
- };
119
86
  Boolean ISPROVIDER = false;
120
- // Boolean testobserver = false;
87
+ Boolean isAppinBackground = false;
121
88
  private TextView timerTextView;
122
89
  private long startTime = 0;
123
- // private List<Observer> observers;
124
- // private List<String> observers1;
125
- // public VideoCallActivity() {
126
- // observers = new ArrayList<>();
127
- // observers1 = new ArrayList<>();
128
- // }
129
-
130
90
 
131
91
  private PublisherKit.PublisherListener publisherListener = new PublisherKit.PublisherListener() {
132
92
  @Override
133
93
  public void onStreamCreated(PublisherKit publisherKit, Stream stream) {
134
94
  Log.d(TAG, "onStreamCreated: Publisher Stream Created. Own stream " + stream.getStreamId());
135
-
136
-
137
95
  }
138
-
139
96
  @Override
140
97
  public void onStreamDestroyed(PublisherKit publisherKit, Stream stream) {
141
98
  Log.d(TAG, "onStreamDestroyed: Publisher Stream Destroyed. Own stream " + stream.getStreamId());
142
99
  }
143
-
144
100
  @Override
145
101
  public void onError(PublisherKit publisherKit, OpentokError opentokError) {
146
102
  finishWithMessage("PublisherKit onError: " + opentokError.getMessage());
147
103
  }
148
-
149
104
  };
150
-
151
105
  private final Session.SessionListener sessionListener = new Session.SessionListener() {
152
106
  @Override
153
107
  public void onConnected(Session session) {
@@ -205,136 +159,150 @@ public class VideoCallActivity extends AppCompatActivity implements EasyPermissi
205
159
  }
206
160
  @Override
207
161
  public void onStreamReceived(Session session, Stream stream) {
208
- isCallinprogress = true;
209
- ProviderViewLayout = findViewById(R.id.providerViewLayout);
210
- if(ISPROVIDER) {
211
- ProviderViewLayout.setVisibility(View.VISIBLE);
212
- }
213
- circleAvatar.setVisibility(View.GONE); // Hide the view
214
- patientStatus.setVisibility(View.GONE); // Hide the view
215
- publishernameView.setVisibility(View.GONE);// Hide the view
216
- admit.setVisibility(View.GONE);
217
- deny.setVisibility(View.GONE);
218
- sendNotifications.setVisibility(View.GONE);
219
-
220
- if (subscriber == null) {
221
- subscriber = new Subscriber.Builder(VideoCallActivity.this, stream).build();
222
- subscriber.getRenderer().setStyle(BaseVideoRenderer.STYLE_VIDEO_SCALE, BaseVideoRenderer.STYLE_VIDEO_FILL);
223
- subscriber.setSubscriberListener(subscriberListener);
224
- subscriber.setVideoListener(videoListener);
225
- session.subscribe(subscriber);
226
- try {
227
- subscriberViewContainer.addView(subscriber.getView());
228
- } catch (Exception e) {}
229
- showToast(SUBSCRIBERNAME + "joined the call");
230
- }
231
- }
162
+ stream.getStreamVideoType();
163
+ Log.d("TYPE===","stream.getStreamVideoType()");
164
+ Log.d("TYPE===", String.valueOf(stream.getStreamVideoType()));
165
+ if( stream.getStreamVideoType()==Stream.StreamVideoType.StreamVideoTypeScreen)
166
+ {
167
+ subscribersubViewContainer.setVisibility(View.VISIBLE);
232
168
 
233
- @Override
234
- public void onStreamDropped(Session session, Stream stream) {
235
- circleAvatar.setVisibility(View.VISIBLE); // Show the view
236
- if(!ISPROVIDER){
237
- if(session!=null){
238
- session.disconnect();
239
- }
240
169
  if (subscriber != null) {
241
- subscriber = null;
242
- subscriberViewContainer.removeAllViews();
243
- Intent resultIntent = new Intent();
244
- String resultcode = ISPROVIDER?"999":"888";
245
- resultIntent.putExtra("result_key", resultcode);
246
- setResult(RESULT_OK, resultIntent);
247
- finish();
170
+ subscriber = null;}
171
+ ProviderViewLayout = findViewById(R.id.providerViewLayout);
172
+ if (ISPROVIDER) {
173
+ ProviderViewLayout.setVisibility(View.VISIBLE);
248
174
  }
249
- }else{
175
+ circleAvatar.setVisibility(View.GONE); // Hide the view
176
+ patientStatus.setVisibility(View.GONE); // Hide the view
177
+ publishernameView.setVisibility(View.GONE);// Hide the view
178
+ admit.setVisibility(View.GONE);
179
+ deny.setVisibility(View.GONE);
180
+ sendNotifications.setVisibility(View.GONE);
181
+ if (subscriber == null) {
182
+ subscriber = new Subscriber.Builder(VideoCallActivity.this, stream).build();
183
+ subscriber.getRenderer().setStyle(BaseVideoRenderer.STYLE_VIDEO_FIT, BaseVideoRenderer.STYLE_VIDEO_FILL);
184
+ subscriber.setSubscriberListener(subscriberListener);
185
+ subscriber.setVideoListener(videoListener);
186
+ session.subscribe(subscriber);
187
+ try {
188
+ subscribersubViewContainer.addView(subscriber.getView());
189
+ } catch (Exception e) {
190
+ }
191
+ showToast(SUBSCRIBERNAME + " joined the call");
192
+ }
193
+ }
194
+ else if( stream.getStreamVideoType()==Stream.StreamVideoType.StreamVideoTypeCamera)
195
+ {
250
196
  if (subscriber != null) {
251
- subscriber = null;
252
- subscriberViewContainer.removeAllViews();
253
- showToast(SUBSCRIBERNAME + " left the call");
254
-
197
+ subscriber = null;}
198
+ ProviderViewLayout = findViewById(R.id.providerViewLayout);
199
+ if (ISPROVIDER) {
200
+ ProviderViewLayout.setVisibility(View.VISIBLE);
201
+ }
202
+ circleAvatar.setVisibility(View.GONE); // Hide the view
203
+ patientStatus.setVisibility(View.GONE); // Hide the view
204
+ publishernameView.setVisibility(View.GONE);// Hide the view
205
+ admit.setVisibility(View.GONE);
206
+ deny.setVisibility(View.GONE);
207
+ sendNotifications.setVisibility(View.GONE);
208
+ if (subscriber == null) {
209
+ subscriber = new Subscriber.Builder(VideoCallActivity.this, stream).build();
210
+ subscriber.getRenderer().setStyle(BaseVideoRenderer.STYLE_VIDEO_SCALE, BaseVideoRenderer.STYLE_VIDEO_FILL);
211
+ subscriber.setSubscriberListener(subscriberListener);
212
+ subscriber.setVideoListener(videoListener);
213
+ session.subscribe(subscriber);
214
+ try {
215
+ subscriberViewContainer.addView(subscriber.getView());
216
+ } catch (Exception e) {
217
+ }
218
+ showToast(SUBSCRIBERNAME + " joined the call");
255
219
  }
256
220
  }
257
221
  }
222
+ @Override
223
+ public void onStreamDropped(Session session, Stream stream) {
224
+ Log.d("onStreamDropped","stream.getStreamVideoType()");
225
+ Log.d("onStreamDropped", String.valueOf(stream.getStreamVideoType()));
258
226
 
227
+ if( stream.getStreamVideoType()==Stream.StreamVideoType.StreamVideoTypeScreen){
228
+ subscribersubViewContainer.removeAllViews();
229
+ subscribersubViewContainer.setVisibility(View.GONE);
259
230
 
231
+ }
232
+ else if( stream.getStreamVideoType()==Stream.StreamVideoType.StreamVideoTypeCamera) {
233
+ circleAvatar.setVisibility(View.VISIBLE); // Show the view
234
+ publishernameView.setVisibility(View.VISIBLE);
235
+ if (!ISPROVIDER) {
236
+ if (session != null) {
237
+ session.disconnect();
238
+ }
239
+ if (subscriber != null) {
240
+ subscriber = null;
241
+ subscriberViewContainer.removeAllViews();
242
+ Intent resultIntent = new Intent();
243
+ String resultcode = ISPROVIDER ? "999" : "888";
244
+ resultIntent.putExtra("result_key", resultcode);
245
+ setResult(RESULT_OK, resultIntent);
246
+ finish();
247
+ }
248
+ } else {
249
+ if (subscriber != null) {
250
+ subscriber = null;
251
+ subscriberViewContainer.removeAllViews();
252
+ showToast(SUBSCRIBERNAME + " left the call");
253
+ }
254
+ }
255
+ }
256
+ }
260
257
  @Override
261
258
  public void onError(Session session, OpentokError opentokError) {
262
259
  finishWithMessage("Session error: " + opentokError.getMessage());
263
260
  }
261
+
264
262
  };
265
263
  SubscriberKit.AudioStatsListener aaa = new SubscriberKit.AudioStatsListener(){
266
264
  @Override
267
265
  public void onAudioStats(SubscriberKit subscriberKit, SubscriberKit.SubscriberAudioStats subscriberAudioStats) {
268
-
269
266
  }
270
267
  };
271
268
  SubscriberKit.AudioLevelListener sss = new SubscriberKit.AudioLevelListener(){
272
-
273
269
  @Override
274
- public void onAudioLevelUpdated(SubscriberKit subscriberKit, float v) {
275
-
276
- }
270
+ public void onAudioLevelUpdated(SubscriberKit subscriberKit, float v) {}
277
271
  };
278
-
279
272
  SubscriberKit.VideoListener videoListener = new SubscriberKit.VideoListener() {
280
-
281
273
  @Override
282
- public void onVideoDataReceived(SubscriberKit subscriberKit) {
283
-
284
- }
285
-
274
+ public void onVideoDataReceived(SubscriberKit subscriberKit) {}
286
275
  @Override
287
276
  public void onVideoDisabled(SubscriberKit subscriberKit, String s) {
288
277
  showToast(SUBSCRIBERNAME + " video disabled");
289
-
290
278
  circleAvatar.setVisibility(View.VISIBLE); // Show the view
291
-
292
-
293
279
  }
294
-
295
280
  @Override
296
281
  public void onVideoEnabled(SubscriberKit subscriberKit, String s) {
297
282
  showToast(SUBSCRIBERNAME + " video enabled");
298
283
  circleAvatar.setVisibility(View.GONE); // Hide the view
299
-
300
-
301
284
  }
302
-
303
285
  @Override
304
- public void onVideoDisableWarning(SubscriberKit subscriberKit) {
305
-
306
- }
307
-
286
+ public void onVideoDisableWarning(SubscriberKit subscriberKit) {}
308
287
  @Override
309
- public void onVideoDisableWarningLifted(SubscriberKit subscriberKit) {
310
-
311
- }
288
+ public void onVideoDisableWarningLifted(SubscriberKit subscriberKit) {}
312
289
  };
313
-
314
290
  SubscriberKit.SubscriberListener subscriberListener = new SubscriberKit.SubscriberListener() {
315
-
316
291
  @Override
317
292
  public void onConnected(SubscriberKit subscriberKit) {
318
293
  Log.d(TAG, "onConnected: Subscriber connected. Stream: " + subscriberKit.getStream().getStreamId());
319
294
  }
320
-
321
295
  @Override
322
296
  public void onDisconnected(SubscriberKit subscriberKit) {
323
297
  Log.d(TAG, "onDisconnected: Subscriber disconnected. Stream: " + subscriberKit.getStream().getStreamId());
324
298
  showToast(SUBSCRIBERNAME+" left the call");
325
-
326
-
327
299
  }
328
-
329
-
330
-
331
300
  @Override
332
301
  public void onError(SubscriberKit subscriberKit, OpentokError opentokError) {
333
302
  showToast(SUBSCRIBERNAME + " failed to connect to the call");
334
303
  finishWithMessage("SubscriberKit onError: " + opentokError.getMessage());
335
304
  }
336
305
  };
337
-
338
306
  @Override
339
307
  protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
340
308
  super.onActivityResult(requestCode, resultCode, data);
@@ -342,63 +310,52 @@ public class VideoCallActivity extends AppCompatActivity implements EasyPermissi
342
310
  Log.d(TAG,"code === 99 in second");
343
311
  }else{
344
312
  Log.d(TAG,"code === 98 in second");
345
-
346
313
  }
347
- }
348
-
314
+ }
349
315
  @Override
350
316
  public void onBackPressed() {
351
317
  if(session!=null){
352
318
  session.disconnect();
353
319
  }
354
320
  }
355
-
356
-
357
321
  @SuppressLint("MissingInflatedId")
358
322
  @Override
359
323
  protected void onCreate(Bundle savedInstanceState) {
360
-
361
324
  Intent intent = getIntent();
362
-
363
325
  super.onCreate(savedInstanceState);
364
- // observers = new ArrayList<>();
365
- // observers1 = new ArrayList<>();
366
326
  instance = new VideoCallActivity();
367
- handler.post(logRunnable);
368
-
327
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
328
+ registerActivityLifecycleCallbacks(this);
329
+ }
369
330
  setContentView(R.layout.video_call_layout);
370
331
  sendNotifications = findViewById(R.id.senddata);
371
332
  main = findViewById(R.id.main);
372
333
  progressBar = findViewById(R.id.progressBar);
373
-
374
- circleAvatar = findViewById(R.id.image_view);
375
-
334
+ circleAvatar = findViewById(R.id.image_view);
376
335
  getSupportActionBar().hide();
377
336
  ActionBar actionBar = getActionBar();
378
337
  if (actionBar != null) {
379
338
  actionBar.hide();
380
339
  }
381
- patientStatus = findViewById(R.id.waiting);
340
+ patientStatus = findViewById(R.id.waiting);
382
341
  admit = findViewById(R.id.admit);
383
342
  deny = findViewById(R.id.deny);
384
-
385
343
  if (intent != null) {
386
- // Retrieve the data using the same key you used to put it in the Intent
387
344
  String TOKEN = intent.getStringExtra("token");
388
345
  String SESSION_ID = intent.getStringExtra("sessionId");
389
346
  String API_KEY = intent.getStringExtra("apiKey");
390
- SUBSCRIBERNAME = intent.getStringExtra("subscriberName");
391
- PUBLISHERNAME = intent.getStringExtra("publisherName");
347
+ SUBSCRIBERNAME = intent.getStringExtra("subscriberName");
348
+ PUBLISHERNAME = intent.getStringExtra("publisherName");
392
349
  profilePicApiUrl = intent.getStringExtra("profilePicApiUrl");
393
- Log.d("profilePicApiUrl",profilePicApiUrl);
394
350
  isPatientOnline = intent.getBooleanExtra("isPatientOnline",false);
395
351
  ISPROVIDER = intent.getBooleanExtra("isProvider",false);
396
352
  publisherViewContainer = findViewById(R.id.publisher_container);
397
353
  subscriberViewContainer = findViewById(R.id.subscriber_container);
354
+ subscribersubViewContainer = findViewById(R.id.subscriber_subcontainer);
355
+ subscribersubViewContainer.setVisibility(View.GONE);
398
356
  publisherNameTextView = findViewById(R.id.publisherName);
399
357
  publishernameView = findViewById(R.id.publisherNameView);
400
358
  TextView subscriberNameTextView = findViewById(R.id.subscriberName);
401
-
402
359
  if(ISPROVIDER){
403
360
  if (isPatientOnline) {
404
361
  patientStatus.setText("WAITING");
@@ -413,8 +370,6 @@ public class VideoCallActivity extends AppCompatActivity implements EasyPermissi
413
370
  patientStatus.setText("OFFLINE");
414
371
  patientStatus.setBackgroundColor(getResources().getColor(R.color.offline));
415
372
  }
416
- }else{
417
-
418
373
  }
419
374
  publisherNameTextView.setText(SUBSCRIBERNAME);
420
375
  publishernameView.setText(SUBSCRIBERNAME);
@@ -423,7 +378,6 @@ public class VideoCallActivity extends AppCompatActivity implements EasyPermissi
423
378
  timerTextView = findViewById(R.id.timerTextView);
424
379
  startTime = System.currentTimeMillis();
425
380
  isTimeron =true;
426
- // startTimer();
427
381
  ProviderViewLayout = findViewById(R.id.providerViewLayout);
428
382
  if(ISPROVIDER){
429
383
  ProviderViewLayout.setVisibility(View.VISIBLE);
@@ -433,27 +387,17 @@ public class VideoCallActivity extends AppCompatActivity implements EasyPermissi
433
387
  String dummyImage = profilePicApiUrl.length()>10?profilePicApiUrl:dummyProfile;
434
388
  new urltoSource((ImageView) findViewById(R.id.image_view)).execute(dummyImage);
435
389
  initializeSession(API_KEY,SESSION_ID , TOKEN);
436
-
437
-
438
390
  }
439
-
440
-
441
-
442
391
  imageViewEndcall = findViewById(R.id.imageView1);
443
392
  imageViewMute = findViewById(R.id.imageView2);
444
393
  imageViewCamOff = findViewById(R.id.imageView3);
445
394
  imageViewCamSwitch = findViewById(R.id.imageView4);
446
-
447
-
448
-
449
395
  sendNotifications.setOnClickListener(new View.OnClickListener() {
450
396
  @Override
451
397
  public void onClick(View v) {
452
-
453
398
  notifyObservers("send");
454
399
  sendNotifications.setVisibility(View.GONE);
455
-
456
-
400
+ // showToast("Notification has been sent");
457
401
  }
458
402
  });
459
403
  admit.setOnClickListener(new View.OnClickListener() {
@@ -470,10 +414,11 @@ public class VideoCallActivity extends AppCompatActivity implements EasyPermissi
470
414
  deny.setOnClickListener(new View.OnClickListener() {
471
415
  @Override
472
416
  public void onClick(View v) {
473
- notifyObservers("deny");
474
- session.disconnect();
475
- admit.setVisibility(View.GONE);
476
- deny.setVisibility(View.GONE);
417
+ // notifyObservers("deny");
418
+ // session.disconnect();
419
+ // admit.setVisibility(View.GONE);
420
+ // deny.setVisibility(View.GONE);
421
+ showCustomAlertDialog();
477
422
  }
478
423
  });
479
424
  imageViewEndcall.setOnClickListener(new View.OnClickListener() {
@@ -484,11 +429,9 @@ public class VideoCallActivity extends AppCompatActivity implements EasyPermissi
484
429
  }
485
430
  }
486
431
  });
487
-
488
432
  imageViewMute.setOnClickListener(new View.OnClickListener() {//mute and unmute audio
489
433
  @Override
490
434
  public void onClick(View v) {
491
-
492
435
  if(publisher!=null) {
493
436
  if (!isMuted) {
494
437
  publisher.setPublishAudio(false);
@@ -506,21 +449,14 @@ public class VideoCallActivity extends AppCompatActivity implements EasyPermissi
506
449
  @Override
507
450
  public void onClick(View v) {
508
451
  if(publisher!=null) {
509
-
510
452
  if (!isCamOff) {
511
453
  publisher.setPublishVideo(false);
512
454
  imageViewCamOff.setImageResource(R.drawable.cameraoff);
513
- // imageViewCamSwitch.setVisibility(View.GONE);
514
-
515
-
516
455
  } else {
517
456
  publisher.setPublishVideo(true);
518
457
  imageViewCamOff.setImageResource(R.drawable.cameraonwhite);
519
- // imageViewCamSwitch.setVisibility(View.VISIBLE);
520
-
521
458
  }
522
459
  isCamOff = !isCamOff;
523
-
524
460
  }
525
461
  }
526
462
  });
@@ -532,11 +468,7 @@ public class VideoCallActivity extends AppCompatActivity implements EasyPermissi
532
468
  }
533
469
  }
534
470
  });
535
-
536
-
537
-
538
471
  }
539
-
540
472
  @Override
541
473
  protected void onPause() {
542
474
  super.onPause();
@@ -544,11 +476,9 @@ public class VideoCallActivity extends AppCompatActivity implements EasyPermissi
544
476
  session.onPause();
545
477
  }
546
478
  }
547
-
548
479
  @Override
549
480
  protected void onResume() {
550
481
  super.onResume();
551
-
552
482
  if (session != null) {
553
483
  session.onResume();
554
484
  }
@@ -557,23 +487,8 @@ public class VideoCallActivity extends AppCompatActivity implements EasyPermissi
557
487
  if(session!=null){
558
488
  session.disconnect();
559
489
  }
560
-
561
490
  isEndall =true;
562
- // killvc();
563
-
564
491
  }
565
- // public void killvc(){
566
- // runOnUiThread(new Runnable() {
567
- // @Override
568
- // public void run() {
569
- // Log.d("endVideoCall","PluginMethodendVideoCall");
570
- // Log.d("endVideoCall",session.toString());
571
- //
572
- // }
573
- // });
574
- //
575
- //
576
- // }
577
492
  private void startTimer() {
578
493
  Handler handler = new Handler();
579
494
  handler.postDelayed(new Runnable() {
@@ -585,14 +500,9 @@ public class VideoCallActivity extends AppCompatActivity implements EasyPermissi
585
500
  int hours = minutes / 60;
586
501
  seconds %= 60;
587
502
  minutes %= 60;
588
-
589
503
  String timeString = String.format("%02d:%02d:%02d", hours, minutes, seconds);
590
- // Log.d(TAG, String.valueOf(currentTime));
591
-
592
504
  // Update the TextView with the formatted time
593
505
  timerTextView.setText(timeString);
594
-
595
- // Continue updating the timer
596
506
  if(isTimeron)
597
507
  startTimer();
598
508
  }
@@ -603,54 +513,15 @@ public class VideoCallActivity extends AppCompatActivity implements EasyPermissi
603
513
  super.onRequestPermissionsResult(requestCode, permissions, grantResults);
604
514
  EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
605
515
  }
606
-
607
516
  @Override
608
517
  public void onPermissionsGranted(int requestCode, List<String> perms) {
609
518
  Log.d(TAG, "onPermissionsGranted:" + requestCode + ": " + perms);
610
519
  }
611
-
612
520
  @Override
613
521
  public void onPermissionsDenied(int requestCode, List<String> perms) {
614
522
  finishWithMessage("onPermissionsDenied: " + requestCode + ": " + perms);
615
523
  }
616
-
617
- @AfterPermissionGranted(PERMISSIONS_REQUEST_CODE)
618
- // private void requestPermissions() {
619
- // String[] perms = {Manifest.permission.INTERNET, Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO};
620
- //
621
- // if (EasyPermissions.hasPermissions(this, perms)) {
622
- //
623
- // if (ServerConfig.hasChatServerUrl()) {
624
- // // Custom server URL exists - retrieve session config
625
- // if(!ServerConfig.isValid()) {
626
- // finishWithMessage("Invalid chat server url: " + ServerConfig.CHAT_SERVER_URL);
627
- // return;
628
- // }
629
- //
630
- // initRetrofit();
631
- //// getSession();
632
- // } else {
633
- // // Use hardcoded session config
634
- // if(!OpenTokConfig.isValid()) {
635
- // finishWithMessage("Invalid OpenTokConfig. " + OpenTokConfig.getDescription());
636
- // return;
637
- // }
638
- //
639
- // initializeSession(OpenTokConfig.API_KEY, OpenTokConfig.SESSION_ID, OpenTokConfig.TOKEN);
640
- // }
641
- // } else {
642
- // EasyPermissions.requestPermissions(this, getString(R.string.rationale_video_app), PERMISSIONS_REQUEST_CODE, perms);
643
- // }
644
- // }
645
-
646
-
647
-
648
524
  private void initializeSession(String apiKey, String sessionId, String token) {
649
- instance.isCallinprogress= false;
650
- Log.i(TAG, "initializeSession: " + "initializeSession");
651
- Log.i(TAG, "apiKey: " + apiKey);
652
- Log.i(TAG, "sessionId: " + sessionId);
653
- Log.i(TAG, "token: " + token);
654
525
  /*
655
526
  The context used depends on the specific use case, but usually, it is desired for the session to
656
527
  live outside of the Activity e.g: live between activities. For a production applications,
@@ -659,51 +530,16 @@ public class VideoCallActivity extends AppCompatActivity implements EasyPermissi
659
530
  session = new Session.Builder(this, apiKey, sessionId).build();
660
531
  session.setSessionListener(sessionListener);
661
532
  session.connect(token);
662
- // circleAvatar.setVisibility(View.GONE); // Hide the view
663
-
664
- Log.d("initializeSession","session.toString()");
665
- Log.d("initializeSession",session.toString());
666
533
  }
667
534
 
668
- // private void initRetrofit() {
669
- // HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
670
- // logging.setLevel(Level.BODY);
671
- //
672
- // OkHttpClient client = new OkHttpClient.Builder()
673
- // .addInterceptor(logging)
674
- // .build();
675
- //
676
- // retrofit = new Retrofit.Builder()
677
- // .baseUrl(ServerConfig.CHAT_SERVER_URL)
678
- // .addConverterFactory(MoshiConverterFactory.create())
679
- // .client(client)
680
- // .build();
681
- //
682
- //// apiService = retrofit.create(APIService.class);
683
- // }
684
535
 
685
536
  private void showToast(String message) {
686
- // try{
687
- // if(isAppInForeground()){
688
- showGreenToast(getApplicationContext(),message);
689
- // }
690
- // Toast toast = Toast.makeText(this, message, Toast.LENGTH_LONG);
691
- // View view = toast.getView();
692
- // int color = Color.parseColor("#1fc600");
693
- // int colorText = Color.parseColor("#ffffff");
694
- // view.getBackground().setColorFilter(Color.GREEN, PorterDuff.Mode.SRC_IN);
695
- // TextView text = view.findViewById(android.R.id.message);
696
- // text.setTextColor(Color.BLACK);
697
- // toast.setGravity(Gravity.TOP, 0, 0);
698
- // toast.show();
699
- // }catch(Exception e){
700
- // Log.d("toastlogex",e.toString());
701
- // }
537
+ if(!isAppinBackground){
538
+ showGreenToast(getApplicationContext(), message);
539
+ }
702
540
  }
703
-
704
541
  private void finishWithMessage(String message) {
705
542
  Log.e(TAG, message);
706
- // Toast.makeText(this, message, Toast.LENGTH_LONG).show();
707
543
  if(session!=null){
708
544
  session.disconnect();
709
545
  }
@@ -714,16 +550,20 @@ public class VideoCallActivity extends AppCompatActivity implements EasyPermissi
714
550
  this.finish();
715
551
  }
716
552
 
717
-
718
-
719
-
720
-
553
+ public void showSentEmailtoast(Boolean isSuccess) {
554
+ if(isSuccess){
555
+ showToast("Notification has been sent");
556
+ }
557
+ }
721
558
  public void patientStatusChanged(Boolean isOnline) {
722
559
  Log.d("patientStatusChanged", String.valueOf(isOnline));
723
560
  Log.d("patientStatusChanged2", String.valueOf(isOnline));
724
561
  Log.d("patientStatusChanged2", String.valueOf(isOnline));
562
+ Log.d("patientStatusChanged2", String.valueOf(instance.ISPROVIDER));
563
+
564
+ // if(instance.ISPROVIDER){
565
+ Log.d("patientStatuISPROVIDER", String.valueOf(isOnline));
725
566
 
726
- if(!instance.isCallinprogress){
727
567
  runOnUiThread(new Runnable() {
728
568
  @Override
729
569
  public void run() {
@@ -735,44 +575,60 @@ public class VideoCallActivity extends AppCompatActivity implements EasyPermissi
735
575
  sendNotifications.setVisibility(View.GONE);
736
576
  admit.setVisibility(View.VISIBLE);
737
577
  deny.setVisibility(View.VISIBLE);
578
+ publishernameView.setVisibility(View.VISIBLE);
579
+
738
580
  patientStatus.setBackgroundResource(R.color.waiting);
739
- // patientStatus.setBackgroundColor(getResources().getColor(R.color.waiting));
740
581
  } else {
741
582
  Log.d("OFFLINE", String.valueOf(isOnline));
742
583
  patientStatus.setText("OFFLINE");
743
584
  admit.setVisibility(View.GONE);
744
585
  deny.setVisibility(View.GONE);
586
+ publishernameView.setVisibility(View.VISIBLE);
745
587
  sendNotifications.setVisibility(View.VISIBLE);
746
588
  patientStatus.setText("OFFLINE");
747
589
  patientStatus.setBackgroundResource(R.color.offline);
748
- // patientStatus.setBackgroundColor(getResources().getColor(R.color.offline));
749
590
  }
750
591
 
751
592
 
752
593
  }
753
594
  });
754
- }
595
+ // }
755
596
  }
756
597
  public static void showGreenToast(Context context, String message) {
757
598
  LayoutInflater inflater = LayoutInflater.from(context);
758
599
  View layout = inflater.inflate(R.layout.custom_toast_green_layout, null);
759
-
760
600
  TextView text = layout.findViewById(R.id.toastView);
761
601
  text.setText(message);
762
-
763
602
  Toast toast = new Toast(context);
764
603
  toast.setDuration(Toast.LENGTH_SHORT);
765
604
  toast.setView(layout);
766
-
767
- // Set toast position to top right corner
768
605
  toast.setGravity(Gravity.TOP | Gravity.END, 0, 0);
606
+ int desiredWidth = isTablet(context) ? getScreenWidth(context) - dpToPx(context, 250) :
607
+ getScreenWidth(context) - dpToPx(context, 100);
769
608
 
609
+ // Set the width of the Toast
610
+ toast.setMargin(0, 0);
611
+ ViewGroup.LayoutParams params = new LinearLayout.LayoutParams(desiredWidth, ViewGroup.LayoutParams.WRAP_CONTENT);
612
+ layout.setLayoutParams(params);
770
613
  toast.show();
771
614
  }
772
- private boolean isAppInForeground() {
773
- return isAppInForeground;
615
+ private static boolean isTablet(Context context) {
616
+ return (context.getResources().getConfiguration().screenLayout &
617
+ android.content.res.Configuration.SCREENLAYOUT_SIZE_MASK) >=
618
+ android.content.res.Configuration.SCREENLAYOUT_SIZE_LARGE;
619
+ }
620
+
621
+ private static int getScreenWidth(Context context) {
622
+ DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
623
+ return displayMetrics.widthPixels;
624
+ }
625
+
626
+ private static int dpToPx(Context context, int dp) {
627
+ float density = context.getResources().getDisplayMetrics().density;
628
+ return Math.round(dp * density);
774
629
  }
775
630
 
631
+
776
632
  public void notifyObservers(String value) {
777
633
  vonagePlugin temp = new vonagePlugin();
778
634
  temp.update(value);
@@ -785,24 +641,22 @@ public class VideoCallActivity extends AppCompatActivity implements EasyPermissi
785
641
 
786
642
  @Override
787
643
  public void onActivityStarted(@NonNull Activity activity) {
788
-
644
+ isAppinBackground= false;
789
645
  }
790
646
 
791
647
  @Override
792
648
  public void onActivityResumed(@NonNull Activity activity) {
793
- Log.d("isAppInForeground", String.valueOf(isAppInForeground));
794
- isAppInForeground = true;
649
+ isAppinBackground= false;
795
650
  }
796
651
 
797
652
  @Override
798
653
  public void onActivityPaused(@NonNull Activity activity) {
799
- Log.d("isAppInForeground", String.valueOf(isAppInForeground));
800
- isAppInForeground = false;
654
+ isAppinBackground =true;
801
655
  }
802
656
 
803
657
  @Override
804
658
  public void onActivityStopped(@NonNull Activity activity) {
805
-
659
+ isAppinBackground= true;
806
660
  }
807
661
 
808
662
  @Override
@@ -812,14 +666,13 @@ public class VideoCallActivity extends AppCompatActivity implements EasyPermissi
812
666
 
813
667
  @Override
814
668
  public void onActivityDestroyed(@NonNull Activity activity) {
815
-
669
+ isAppinBackground= true;
816
670
  }
817
671
 
818
672
  private class urltoSource extends AsyncTask<String, Void, Bitmap> {
819
673
  ImageView imageView;
820
674
  public urltoSource(ImageView imageView) {
821
675
  this.imageView=imageView;
822
- // Toast.makeText(getApplicationContext(), "Please wait, it may take a few minute...",Toast.LENGTH_SHORT).show();
823
676
  }
824
677
  protected Bitmap doInBackground(String... urls) {
825
678
  String imageURL=urls[0];
@@ -828,7 +681,6 @@ public class VideoCallActivity extends AppCompatActivity implements EasyPermissi
828
681
  InputStream in=new java.net.URL(imageURL).openStream();
829
682
  bimage= BitmapFactory.decodeStream(in);
830
683
  } catch (Exception e) {
831
- Log.e("Error Message", e.getMessage());
832
684
  e.printStackTrace();
833
685
  }
834
686
  return bimage;
@@ -837,4 +689,71 @@ public class VideoCallActivity extends AppCompatActivity implements EasyPermissi
837
689
  imageView.setImageBitmap(result);
838
690
  }
839
691
  }
692
+ private void showCustomAlertDialog() {
693
+ // Get the layout inflater
694
+ LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
695
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
696
+ View layout = inflater.inflate(R.layout.custom_dialog_layout, null);
697
+
698
+ builder.setView(layout);
699
+ final AlertDialog customDialog = builder.create();
700
+ Button yesButton = layout.findViewById(R.id.yesButton);
701
+ LinearLayout alertLayout = layout.findViewById(R.id.alert);
702
+ // int backgroundColor = Color.parseColor("#FFFFFF"); // Replace with your desired color
703
+ // alertLayout.setBackgroundColor(backgroundColor);
704
+ // float cornerRadius = 20f; // Replace with your desired corner radius
705
+
706
+ // Create a GradientDrawable with a solid color and corner radius
707
+ // GradientDrawable gradientDrawable = new GradientDrawable();
708
+ // gradientDrawable.setShape(GradientDrawable.RECTANGLE);
709
+ // gradientDrawable.setColor(backgroundColor);
710
+ // gradientDrawable.setCornerRadius(cornerRadius);
711
+
712
+ // Set the GradientDrawable as the background
713
+ // alertLayout.setBackground(gradientDrawable);
714
+ // float screenWidthPercentage = 0.6f;
715
+ // float screenHeightPercentage = 0.4f;
716
+ // int screenWidth = getScreenWidth(getApplicationContext());
717
+ // int desiredWidth = (int) (screenWidth * screenWidthPercentage);
718
+ // int screenHeight = getScreenWidth(getApplicationContext());
719
+ // int desiredHeight = (int) (screenHeight * screenHeightPercentage);
720
+ // LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
721
+ // desiredWidth,
722
+ // desiredHeight
723
+ // );
724
+ // alertLayout.setLayoutParams(layoutParams);
725
+ // GradientDrawable gradientDrawable = new GradientDrawable();
726
+ // gradientDrawable.setShape(GradientDrawable.RECTANGLE);
727
+ // gradientDrawable.setColor(Color.WHITE); // Set your desired background color
728
+ // gradientDrawable.setCornerRadius(16f); // Set your desired corner radius
729
+ //
730
+ // // Set the border if needed
731
+ // gradientDrawable.setStroke(2, Color.BLACK); // Set border width and color
732
+ //
733
+ // // Apply the drawable as the background
734
+ // alertLayout.setBackground(gradientDrawable);
735
+ yesButton.setOnClickListener(new View.OnClickListener() {
736
+ @Override
737
+ public void onClick(View view) {
738
+ notifyObservers("deny");
739
+ session.disconnect();
740
+ admit.setVisibility(View.GONE);
741
+ deny.setVisibility(View.GONE);
742
+ // customDialog.dismiss();
743
+ }
744
+ });
745
+ Button noButton = layout.findViewById(R.id.noButton);
746
+ noButton.setOnClickListener(new View.OnClickListener() {
747
+ @Override
748
+ public void onClick(View view) {
749
+ customDialog.dismiss();
750
+ }
751
+ });
752
+
753
+ // Show the AlertDialog
754
+ customDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
755
+
756
+ customDialog.show();
757
+ customDialog.getWindow().setLayout(800,480);
758
+ }
840
759
  }