Fix some issues + multiple audio calls started

This commit is contained in:
Sylvain Berfini 2012-07-10 16:10:54 +02:00
parent f487f9797c
commit ebca161b7e
17 changed files with 170 additions and 78 deletions

BIN
res/drawable/sel_call.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

View file

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@drawable/sel_call_first"
android:gravity="center_vertical">
<TextView
android:id="@+id/contactNameOrNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:gravity="left"
android:paddingLeft="20dp"
android:textColor="@android:color/white"
android:textSize="22dp" />
<Chronometer
android:id="@+id/callTimer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingRight="20dp"
android:gravity="right"
android:textColor="@android:color/white"
android:textSize="22dp" />
</LinearLayout>

View file

@ -1,46 +1,23 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/numpad_background"> android:background="@drawable/numpad_background">
<TableLayout <LinearLayout
android:id="@+id/calls"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:background="@drawable/dialer_address_background" android:layout_alignParentTop="true"
android:gravity="center_vertical" android:gravity="center_vertical"
android:stretchColumns="0" android:orientation="vertical">
android:shrinkColumns="0"
android:layout_weight="0.9">
<TableRow </LinearLayout>
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/contactNameOrNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="20dp"
android:gravity="left"
android:textColor="@android:color/white"
android:textSize="22dp" />
<Chronometer
android:id="@+id/callTimer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="20dp"
android:gravity="right"
android:textColor="@android:color/white"
android:textSize="22dp" />
</TableRow>
</TableLayout>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="0.1" android:layout_below="@id/calls"
android:orientation="vertical" android:orientation="vertical"
android:paddingTop="30dip"> android:paddingTop="30dip">
@ -58,4 +35,4 @@
</LinearLayout> </LinearLayout>
</LinearLayout> </RelativeLayout>

View file

@ -18,8 +18,8 @@
<ImageView <ImageView
android:contentDescription="@string/content_description_contact_picture" android:contentDescription="@string/content_description_contact_picture"
android:id="@+id/contactPicture" android:id="@+id/contactPicture"
android:layout_width="wrap_content" android:layout_width="100dp"
android:layout_height="wrap_content" android:layout_height="100dp"
android:src="@drawable/unknown_small" /> android:src="@drawable/unknown_small" />
<TextView <TextView

View file

@ -17,8 +17,8 @@
<ImageView <ImageView
android:contentDescription="@string/content_description_contact_picture" android:contentDescription="@string/content_description_contact_picture"
android:id="@+id/contactPicture" android:id="@+id/contactPicture"
android:layout_width="wrap_content" android:layout_width="100dp"
android:layout_height="wrap_content" android:layout_height="100dp"
android:src="@drawable/unknown_small" /> android:src="@drawable/unknown_small" />
<TextView <TextView

View file

@ -17,8 +17,8 @@
<ImageView <ImageView
android:contentDescription="@string/content_description_contact_picture" android:contentDescription="@string/content_description_contact_picture"
android:id="@+id/contactPicture" android:id="@+id/contactPicture"
android:layout_width="wrap_content" android:layout_width="100dp"
android:layout_height="wrap_content" android:layout_height="100dp"
android:src="@drawable/unknown_small" /> android:src="@drawable/unknown_small" />
<TextView <TextView

View file

@ -9,7 +9,7 @@
<bool name="hide_camera_settings">false</bool> <bool name="hide_camera_settings">false</bool>
<bool name="hide_wizard">false</bool> <bool name="hide_wizard">false</bool>
<bool name="hide_accounts">false</bool> <bool name="hide_accounts">false</bool>
<bool name="useFirstLoginActivity">true</bool> <bool name="useFirstLoginActivity">false</bool>
<bool name="disable_animations">false</bool> <bool name="disable_animations">false</bool>
<bool name="only_display_username_if_unknown">true</bool> <bool name="only_display_username_if_unknown">true</bool>
<bool name="show_full_remote_address_on_incoming_call">true</bool> <bool name="show_full_remote_address_on_incoming_call">true</bool>

View file

@ -22,13 +22,13 @@ import org.linphone.core.LinphoneCall;
import org.linphone.core.LinphoneCoreFactory; import org.linphone.core.LinphoneCoreFactory;
import android.app.Activity; import android.app.Activity;
import android.net.Uri; import android.content.res.Resources;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageView; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
/** /**
@ -36,47 +36,86 @@ import android.widget.TextView;
*/ */
public class AudioCallFragment extends Fragment { public class AudioCallFragment extends Fragment {
private static AudioCallFragment instance; private static AudioCallFragment instance;
// private Chronometer timer; private LinearLayout callsList;
private LayoutInflater inflater;
private ViewGroup container;
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
instance = this; instance = this;
this.inflater = inflater;
this.container = container;
View view = inflater.inflate(R.layout.audio, container, false); View view = inflater.inflate(R.layout.audio, container, false);
// timer = (Chronometer) view.findViewById(R.id.callTimer); callsList = (LinearLayout) view.findViewById(R.id.calls);
LinphoneCall currentCall;
do {
currentCall = LinphoneManager.getLc().getCurrentCall();
} while (currentCall == null);
String sipUri = currentCall.getRemoteAddress().asStringUriOnly();
LinphoneAddress lAddress = LinphoneCoreFactory.instance().createLinphoneAddress(sipUri);
Uri pictureUri = LinphoneUtils.findUriPictureOfContactAndSetDisplayName(lAddress, view.getContext().getContentResolver());
TextView contact = (TextView) view.findViewById(R.id.contactNameOrNumber);
contact.setText(lAddress.getDisplayName() == null ? sipUri : lAddress.getDisplayName());
ImageView contactPicture = (ImageView) view.findViewById(R.id.contactPicture);
if (pictureUri != null) {
LinphoneUtils.setImagePictureFromUri(view.getContext(), contactPicture, Uri.parse(pictureUri.toString()), R.drawable.unknown_small);
}
return view; return view;
} }
private void displayCall(Resources resources, LinearLayout callView, LinphoneCall call) {
String sipUri = call.getRemoteAddress().asStringUriOnly();
LinphoneAddress lAddress = LinphoneCoreFactory.instance().createLinphoneAddress(sipUri);
// Uri pictureUri = LinphoneUtils.findUriPictureOfContactAndSetDisplayName(lAddress, callView.getContext().getContentResolver());
TextView contact = (TextView) callView.findViewById(R.id.contactNameOrNumber);
if (lAddress.getDisplayName() == null) {
if (resources.getBoolean(R.bool.only_display_username_if_unknown) && LinphoneUtils.isSipAddress(sipUri)) {
contact.setText(LinphoneUtils.getUsernameFromAddress(sipUri));
} else {
contact.setText(sipUri);
}
} else {
contact.setText(lAddress.getDisplayName());
}
// ImageView contactPicture = (ImageView) callView.findViewById(R.id.contactPicture);
// if (pictureUri != null) {
// LinphoneUtils.setImagePictureFromUri(callView.getContext(), contactPicture, Uri.parse(pictureUri.toString()), R.drawable.unknown_small);
// }
}
@Override @Override
public void onAttach(Activity activity) { public void onAttach(Activity activity) {
super.onAttach(activity); super.onAttach(activity);
InCallActivity.instance().bindAudioFragment(this);
// Just to be sure we have incall controls // Just to be sure we have incall controls
InCallActivity.instance().setCallControlsVisibleAndRemoveCallbacks(); InCallActivity.instance().setCallControlsVisibleAndRemoveCallbacks();
} }
@Override
public void onResume() {
super.onResume();
// Add calls
refreshCallList(getResources());
}
/** /**
* @return null if not ready yet * @return null if not ready yet
*/ */
public static AudioCallFragment instance() { public static AudioCallFragment instance() {
return instance; return instance;
} }
public void refreshCallList(Resources resources) {
callsList.removeAllViews();
boolean first = true;
for (LinphoneCall call : LinphoneManager.getLc().getCalls()) {
LinearLayout callView = (LinearLayout) inflater.inflate(R.layout.active_call, container, false);
displayCall(resources, callView, call);
if (first) {
callView.setBackgroundResource(R.drawable.sel_call_first);
first = false;
} else {
callView.setBackgroundResource(R.drawable.sel_call);
}
callsList.addView(callView);
}
callsList.invalidate();
}
} }

View file

@ -85,7 +85,7 @@ public class ContactFragment extends Fragment {
return new OnClickListener() { return new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
LinphoneActivity.instance().setAddressAndGoToDialer(v.getTag().toString(), contact.getName(), contact.getPhotoUri()); LinphoneActivity.instance().setAddresGoToDialerAndCall(v.getTag().toString(), contact.getName(), contact.getPhotoUri());
} }
}; };
} }

View file

@ -119,6 +119,7 @@ public class DialerFragment extends Fragment {
public void resetLayout() { public void resetLayout() {
if (LinphoneActivity.instance().isInCallLayout()) { if (LinphoneActivity.instance().isInCallLayout()) {
mCall.setImageResource(R.drawable.plus); mCall.setImageResource(R.drawable.plus);
mAddress.setText("");
mAddContact.setImageResource(R.drawable.cancel); mAddContact.setImageResource(R.drawable.cancel);
mAddContact.setOnClickListener(cancelListener); mAddContact.setOnClickListener(cancelListener);
} else { } else {

View file

@ -98,7 +98,7 @@ public class HistoryDetailFragment extends Fragment implements OnClickListener {
int id = v.getId(); int id = v.getId();
if (id == R.id.dialBack) { if (id == R.id.dialBack) {
LinphoneActivity.instance().setAddressAndGoToDialer(sipUri, displayName, pictureUri == null ? null : Uri.parse(pictureUri)); LinphoneActivity.instance().setAddresGoToDialerAndCall(sipUri, displayName, pictureUri == null ? null : Uri.parse(pictureUri));
} else if (id == R.id.chat) { } else if (id == R.id.chat) {
LinphoneActivity.instance().displayChat(sipUri); LinphoneActivity.instance().displayChat(sipUri);
} else if (id == R.id.addToContacts) { } else if (id == R.id.addToContacts) {

View file

@ -83,6 +83,15 @@ public class InCallActivity extends FragmentActivity implements
} }
initUI(); initUI();
if (LinphoneManager.getLc().getCallsNb() > 0) {
LinphoneCall call = LinphoneManager.getLc().getCalls()[0];
if (isCallEstablished(call)) {
enableAndRefreshInCallActions();
isVideoEnabled = call.getCurrentParamsCopy().getVideoEnabled();
}
}
Fragment callFragment; Fragment callFragment;
if (isVideoEnabled) { if (isVideoEnabled) {
callFragment = new VideoCallFragment(); callFragment = new VideoCallFragment();
@ -400,12 +409,22 @@ public class InCallActivity extends FragmentActivity implements
state == LinphoneCall.State.StreamsRunning || state == LinphoneCall.State.StreamsRunning ||
state == LinphoneCall.State.Resuming; state == LinphoneCall.State.Resuming;
} }
private boolean isCallEstablished(LinphoneCall call) {
LinphoneCall.State state = call.getState();
return isCallRunning(call) ||
state == LinphoneCall.State.Paused ||
state == LinphoneCall.State.PausedByRemote ||
state == LinphoneCall.State.Pausing;
}
@Override @Override
public void onCallStateChanged(LinphoneCall call, State state, public void onCallStateChanged(LinphoneCall call, State state,
String message) { String message) {
if (LinphoneManager.getLc().getCallsNb() == 0) { if (LinphoneManager.getLc().getCallsNb() == 0) {
finish(); finish();
return;
} }
if (state == State.StreamsRunning) { if (state == State.StreamsRunning) {
@ -418,6 +437,17 @@ public class InCallActivity extends FragmentActivity implements
isMicMuted = LinphoneManager.getLc().isMicMuted(); isMicMuted = LinphoneManager.getLc().isMicMuted();
enableAndRefreshInCallActions(); enableAndRefreshInCallActions();
} }
if (state == State.CallEnd || state == State.CallReleased || state == State.Error) {
if (audioCallFragment != null) {
mHandler.post(new Runnable() {
@Override
public void run() {
audioCallFragment.refreshCallList(getResources());
}
});
}
}
} }
@Override @Override
@ -452,4 +482,8 @@ public class InCallActivity extends FragmentActivity implements
if (LinphoneUtils.onKeyBackGoHome(this, keyCode, event)) return true; if (LinphoneUtils.onKeyBackGoHome(this, keyCode, event)) return true;
return super.onKeyDown(keyCode, event); return super.onKeyDown(keyCode, event);
} }
public void bindAudioFragment(AudioCallFragment fragment) {
audioCallFragment = fragment;
}
} }

View file

@ -24,6 +24,7 @@ import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.List; import java.util.List;
import org.linphone.LinphoneManager.AddressType;
import org.linphone.LinphoneSimpleListener.LinphoneOnCallStateChangedListener; import org.linphone.LinphoneSimpleListener.LinphoneOnCallStateChangedListener;
import org.linphone.LinphoneSimpleListener.LinphoneOnMessageReceived; import org.linphone.LinphoneSimpleListener.LinphoneOnMessageReceived;
import org.linphone.LinphoneSimpleListener.LinphoneOnRegistrationStateChangedListener; import org.linphone.LinphoneSimpleListener.LinphoneOnRegistrationStateChangedListener;
@ -38,6 +39,7 @@ import org.linphone.core.LinphoneCore.RegistrationState;
import org.linphone.core.LinphoneCoreFactory; import org.linphone.core.LinphoneCoreFactory;
import org.linphone.core.Log; import org.linphone.core.Log;
import org.linphone.setup.SetupActivity; import org.linphone.setup.SetupActivity;
import org.linphone.ui.AddressText;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; import android.content.Intent;
@ -466,12 +468,17 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
} }
@Override @Override
public void setAddressAndGoToDialer(String number, String name, Uri photo) { public void setAddresGoToDialerAndCall(String number, String name, Uri photo) {
Bundle extras = new Bundle(); Bundle extras = new Bundle();
extras.putString("SipUri", number); extras.putString("SipUri", number);
extras.putString("DisplayName", name); extras.putString("DisplayName", name);
extras.putString("Photo", photo == null ? null : photo.toString()); extras.putString("Photo", photo == null ? null : photo.toString());
changeCurrentFragment(FragmentsAvailable.DIALER, extras); changeCurrentFragment(FragmentsAvailable.DIALER, extras);
AddressType address = new AddressText(this, null);
address.setDisplayedName(name);
address.setText(number);
LinphoneManager.getInstance().newOutgoingCall(address);
} }
public void setAddressAndGoToDialer(String number) { public void setAddressAndGoToDialer(String number) {
@ -603,6 +610,6 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
} }
interface ContactPicked { interface ContactPicked {
void setAddressAndGoToDialer(String number, String name, Uri photo); void setAddresGoToDialerAndCall(String number, String name, Uri photo);
void goToDialer(); void goToDialer();
} }

View file

@ -181,8 +181,8 @@ public class StatusFragment extends Fragment {
} }
public void refreshEncryptionIcon() { public void refreshEncryptionIcon() {
if (encryption != null) { LinphoneCall call = LinphoneManager.getLc().getCurrentCall();
LinphoneCall call = LinphoneManager.getLc().getCurrentCall(); if (call != null && encryption != null) {
MediaEncryption mediaEncryption = call.getCurrentParamsCopy().getMediaEncryption(); MediaEncryption mediaEncryption = call.getCurrentParamsCopy().getMediaEncryption();
encryption.setVisibility(View.VISIBLE); encryption.setVisibility(View.VISIBLE);

View file

@ -22,6 +22,7 @@ import org.linphone.core.Log;
import org.linphone.mediastream.video.AndroidVideoWindowImpl; import org.linphone.mediastream.video.AndroidVideoWindowImpl;
import org.linphone.mediastream.video.capture.hwconf.AndroidCameraConfiguration; import org.linphone.mediastream.video.capture.hwconf.AndroidCameraConfiguration;
import android.annotation.TargetApi;
import android.content.Context; import android.content.Context;
import android.opengl.GLSurfaceView; import android.opengl.GLSurfaceView;
import android.os.Bundle; import android.os.Bundle;
@ -39,6 +40,7 @@ import android.view.ViewGroup;
/** /**
* @author Sylvain Berfini * @author Sylvain Berfini
*/ */
@TargetApi(5)
public class VideoCallFragment extends Fragment { public class VideoCallFragment extends Fragment {
private static VideoCallFragment instance; private static VideoCallFragment instance;
private WakeLock mWakeLock; private WakeLock mWakeLock;
@ -113,15 +115,19 @@ public class VideoCallFragment extends Fragment {
} }
public void switchCamera() { public void switchCamera() {
int videoDeviceId = LinphoneManager.getLc().getVideoDevice(); try {
videoDeviceId = (videoDeviceId + 1) % AndroidCameraConfiguration.retrieveCameras().length; int videoDeviceId = LinphoneManager.getLc().getVideoDevice();
LinphoneManager.getLc().setVideoDevice(videoDeviceId); videoDeviceId = (videoDeviceId + 1) % AndroidCameraConfiguration.retrieveCameras().length;
CallManager.getInstance().updateCall(); LinphoneManager.getLc().setVideoDevice(videoDeviceId);
CallManager.getInstance().updateCall();
// previous call will cause graph reconstruction -> regive preview
// window // previous call will cause graph reconstruction -> regive preview
if (mCaptureView != null) { // window
LinphoneManager.getLc().setPreviewWindow(mCaptureView); if (mCaptureView != null) {
LinphoneManager.getLc().setPreviewWindow(mCaptureView);
}
} catch (ArithmeticException ae) {
Log.e("Cannot swtich camera : no camera");
} }
} }

View file

@ -48,7 +48,7 @@ public class CallButton extends ImageView implements OnClickListener, AddressAwa
public void onClick(View v) { public void onClick(View v) {
try { try {
if (!LinphoneManager.getInstance().acceptCallIfIncomingPending()) { if (!LinphoneManager.getInstance().acceptCallIfIncomingPending()) {
if (mAddress.getText().length() >0) { if (mAddress.getText().length() > 0) {
LinphoneManager.getInstance().newOutgoingCall(mAddress); LinphoneManager.getInstance().newOutgoingCall(mAddress);
} }
} }