2121import android .widget .Button ;
2222import android .widget .CheckBox ;
2323import android .widget .CompoundButton ;
24+ import android .widget .LinearLayout ;
25+ import android .widget .RelativeLayout ;
2426
2527import org .mobicents .restcomm .android .client .sdk .RCClient ;
2628import org .mobicents .restcomm .android .client .sdk .RCConnection ;
3537public class CallActivity extends Activity implements RCConnectionListener , View .OnClickListener ,
3638 CompoundButton .OnCheckedChangeListener , AudioManager .OnAudioFocusChangeListener {
3739
38- private GLSurfaceView videoView ;
40+ // private GLSurfaceView videoView;
3941 private RCConnection connection , pendingConnection ;
4042 SharedPreferences prefs ;
4143 private static final String TAG = "CallActivity" ;
4244 private HashMap <String , String > connectParams = new HashMap <String , String >();
4345 private RCDevice device ;
46+ private RelativeLayout parentLayout ;
4447 MediaPlayer ringingPlayer ;
4548 MediaPlayer callingPlayer ;
4649 AudioManager audioManager ;
50+ final String TAG_LOCAL_VIDEO_VIEW = "local-video-view" ;
4751
4852 CheckBox cbMuted ;
4953 Button btnHangup ;
5054 Button btnAnswer ;
5155 Button btnDecline ;
5256 Button btnCancel ;
5357
54- String incomingCallDid = "" ;
55- // TODO: remove those when the API is structured properlu
56- // String incomingCallSdp = "";
57-
5858 @ Override
5959 protected void onCreate (Bundle savedInstanceState ) {
6060 super .onCreate (savedInstanceState );
@@ -85,7 +85,8 @@ protected void onCreate(Bundle savedInstanceState) {
8585 btnCancel .setOnClickListener (this );
8686 cbMuted = (CheckBox )findViewById (R .id .checkbox_muted );
8787 cbMuted .setOnCheckedChangeListener (this );
88- videoView = (GLSurfaceView ) findViewById (R .id .glview_call );
88+ parentLayout = (RelativeLayout ) findViewById (R .id .layout_video_call );
89+ //videoView = (GLSurfaceView) findViewById(R.id.glview_call);
8990
9091 audioManager = (AudioManager )getSystemService (Context .AUDIO_SERVICE );
9192 // volume control should be by default 'music' which will control the ringing sounds and 'voice call' when within a call
@@ -108,7 +109,7 @@ protected void onCreate(Bundle savedInstanceState) {
108109 final Intent intent = getIntent ();
109110 if (intent .getAction () == RCDevice .OUTGOING_CALL ) {
110111 connectParams .put ("username" , intent .getStringExtra (RCDevice .EXTRA_DID ));
111- connection = device .connect (connectParams , this , videoView , prefs );
112+ connection = device .connect (connectParams , this );
112113
113114 if (connection == null ) {
114115 Log .e (TAG , "Error: error connecting" );
@@ -121,21 +122,15 @@ protected void onCreate(Bundle savedInstanceState) {
121122 ringingPlayer .start ();
122123 }
123124 pendingConnection = device .incomingConnection ;
124- pendingConnection .updateListener (this );
125- pendingConnection .setupWebrtcForIncomingCall (videoView , prefs );
125+ pendingConnection .listenerReady (this );
126126
127127 // the number from which we got the call
128- incomingCallDid = intent .getStringExtra (RCDevice .EXTRA_DID );
129- //incomingCallSdp = intent.getStringExtra(RCDevice.EXTRA_SDP);
128+ String incomingCallDid = intent .getStringExtra (RCDevice .EXTRA_DID );
130129 }
131130 }
132131
133132 // UI Events
134133 public void onClick (View view ) {
135- if (view .getId () == R .id .glview_call ) {
136- //connection = device.connect(connectParams, this, videoView, prefs);
137- }
138-
139134 if (view .getId () == R .id .button_hangup ) {
140135 if (connection == null ) {
141136 Log .e (TAG , "Error: not connected" );
@@ -148,8 +143,8 @@ public void onClick(View view) {
148143 } else if (view .getId () == R .id .button_answer ) {
149144 if (pendingConnection != null ) {
150145 pendingConnection .accept ();
151- //pendingConnection.answerCall(incomingCallDid, incomingCallSdp);
152146 connection = this .pendingConnection ;
147+ pendingConnection = null ;
153148 ringingPlayer .pause ();
154149 // Abandon audio focus when playback complete
155150 audioManager .abandonAudioFocus (this );
@@ -161,6 +156,7 @@ public void onClick(View view) {
161156 ringingPlayer .pause ();
162157 // Abandon audio focus when playback complete
163158 audioManager .abandonAudioFocus (this );
159+ finish ();
164160 }
165161 } else if (view .getId () == R .id .button_cancel ) {
166162 if (connection == null ) {
@@ -173,6 +169,7 @@ public void onClick(View view) {
173169 callingPlayer .pause ();
174170 // Abandon audio focus when playback complete
175171 audioManager .abandonAudioFocus (this );
172+ finish ();
176173 }
177174 }
178175 }
@@ -202,7 +199,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
202199 @ Override
203200 public void onResume () {
204201 super .onResume ();
205- videoView .onResume ();
202+ // videoView.onResume();
206203 /*
207204 activityRunning = true;
208205 if (peerConnectionClient != null) {
@@ -256,6 +253,8 @@ public void onCancelled(RCConnection connection) {
256253
257254 this .connection = null ;
258255 pendingConnection = null ;
256+
257+ finish ();
259258 }
260259
261260 public void onDeclined (RCConnection connection ) {
@@ -267,6 +266,8 @@ public void onDeclined(RCConnection connection) {
267266
268267 this .connection = null ;
269268 pendingConnection = null ;
269+
270+ finish ();
270271 }
271272
272273 public void onDisconnected (RCConnection connection , int errorCode , String errorText ) {
@@ -290,6 +291,17 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
290291 }
291292 }
292293
294+ public void onReceiveLocalVideo (RCConnection connection , GLSurfaceView videoView ) {
295+ if (videoView != null ) {
296+ //show media on screen
297+ videoView .setTag (TAG_LOCAL_VIDEO_VIEW );
298+ if (parentLayout .findViewWithTag (TAG_LOCAL_VIDEO_VIEW ) != null ) {
299+ parentLayout .removeView (videoView );
300+ }
301+ parentLayout .addView (videoView , 0 );
302+ }
303+ }
304+
293305 // Callbacks for auio focus change events
294306 public void onAudioFocusChange (int focusChange )
295307 {
0 commit comments