Improved sample
This commit is contained in:
parent
2f4b5f961d
commit
81588d6906
5 changed files with 95 additions and 6 deletions
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -16,4 +16,12 @@
|
|||
android:layout_alignParentRight="true"
|
||||
android:layout_alignParentBottom="true" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/terminate_call"
|
||||
android:text="Terminate call"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</RelativeLayout>
|
|
@ -13,10 +13,41 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<ImageView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
<LinearLayout
|
||||
android:id="@+id/call_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_centerInParent="true"
|
||||
android:src="@drawable/banner"/>
|
||||
android:layout_margin="20dp"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:text="Enter SIP address"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/address_to_call"
|
||||
android:hint="SIP address"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<Switch
|
||||
android:id="@+id/call_with_video"
|
||||
android:text="Call with video"
|
||||
android:checked="true"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/call_button"
|
||||
android:text="Call"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</RelativeLayout>
|
Loading…
Reference in a new issue