diff --git a/sample/app/src/main/java/org/linphone/sample/CallActivity.java b/sample/app/src/main/java/org/linphone/sample/CallActivity.java index aa54854f9..e4c981749 100644 --- a/sample/app/src/main/java/org/linphone/sample/CallActivity.java +++ b/sample/app/src/main/java/org/linphone/sample/CallActivity.java @@ -7,6 +7,7 @@ import android.content.res.Configuration; import android.os.Bundle; import android.util.DisplayMetrics; import android.view.TextureView; +import android.view.View; import android.widget.RelativeLayout; import androidx.annotation.Nullable; @@ -42,7 +43,7 @@ public class CallActivity extends Activity { // Listen for call state changes mCoreListener = new CoreListenerStub() { @Override - public void onCallStateChanged(Core lc, Call call, Call.State state, String message) { + public void onCallStateChanged(Core core, Call call, Call.State state, String message) { if (state == Call.State.End || state == Call.State.Released) { // Once call is finished (end state), terminate the activity // We also check for released state (called a few seconds later) just in case @@ -51,6 +52,21 @@ public class CallActivity extends Activity { } } }; + + findViewById(R.id.terminate_call).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Core core = LinphoneService.getCore(); + if (core.getCallsNb() > 0) { + Call call = core.getCurrentCall(); + if (call == null) { + // Current call can be null if paused for example + call = core.getCalls()[0]; + } + call.terminate(); + } + } + }); } @Override diff --git a/sample/app/src/main/java/org/linphone/sample/LinphoneService.java b/sample/app/src/main/java/org/linphone/sample/LinphoneService.java index 5b933c9fd..6f0dad902 100644 --- a/sample/app/src/main/java/org/linphone/sample/LinphoneService.java +++ b/sample/app/src/main/java/org/linphone/sample/LinphoneService.java @@ -7,6 +7,7 @@ import android.content.pm.PackageManager; import android.os.Build; import android.os.Handler; import android.os.IBinder; +import android.widget.Toast; import androidx.annotation.Nullable; @@ -76,7 +77,9 @@ public class LinphoneService extends Service { // This will be our main Core listener, it will change activities depending on events mCoreListener = new CoreListenerStub() { @Override - public void onCallStateChanged(Core lc, Call call, Call.State state, String message) { + public void onCallStateChanged(Core core, Call call, Call.State state, String message) { + Toast.makeText(LinphoneService.this, message, Toast.LENGTH_SHORT).show(); + if (state == Call.State.IncomingReceived) { // For this sample we will automatically answer incoming calls CallParams params = getCore().createCallParams(call); diff --git a/sample/app/src/main/java/org/linphone/sample/MainActivity.java b/sample/app/src/main/java/org/linphone/sample/MainActivity.java index 3d6298c84..e9a5c9dc9 100644 --- a/sample/app/src/main/java/org/linphone/sample/MainActivity.java +++ b/sample/app/src/main/java/org/linphone/sample/MainActivity.java @@ -5,11 +5,21 @@ import android.app.Activity; import android.content.Intent; import android.content.pm.PackageManager; import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; import android.widget.ImageView; +import android.widget.RadioButton; +import android.widget.Switch; +import android.widget.TextView; +import android.widget.Toast; import androidx.annotation.Nullable; import androidx.core.app.ActivityCompat; +import org.linphone.core.Address; +import org.linphone.core.Call; +import org.linphone.core.CallParams; import org.linphone.core.Core; import org.linphone.core.CoreListenerStub; import org.linphone.core.ProxyConfig; @@ -22,6 +32,8 @@ public class MainActivity extends Activity { private ImageView mLed; private CoreListenerStub mCoreListener; + private EditText mSipAddressToCall; + @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -37,6 +49,25 @@ public class MainActivity extends Activity { updateLed(state); } }; + + mSipAddressToCall = findViewById(R.id.address_to_call); + + Button callButton = findViewById(R.id.call_button); + callButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Core core = LinphoneService.getCore(); + Address addressToCall = core.interpretUrl(mSipAddressToCall.getText().toString()); + CallParams params = core.createCallParams(null); + + Switch videoEnabled = findViewById(R.id.call_with_video); + params.enableVideo(videoEnabled.isChecked()); + + if (addressToCall != null) { + core.inviteAddressWithParams(addressToCall, params); + } + } + }); } @Override diff --git a/sample/app/src/main/res/layout/call.xml b/sample/app/src/main/res/layout/call.xml index 1ab7d6c83..498d59d25 100644 --- a/sample/app/src/main/res/layout/call.xml +++ b/sample/app/src/main/res/layout/call.xml @@ -16,4 +16,12 @@ android:layout_alignParentRight="true" android:layout_alignParentBottom="true" /> +