Move some callbacks + auto start video on share.

This commit is contained in:
Guillaume Beraudo 2011-10-20 14:29:35 +02:00
parent 6b52e92224
commit 23ddab7710
8 changed files with 88 additions and 53 deletions

View file

@ -179,6 +179,11 @@ public class ConferenceActivity extends ListActivity implements
if (multipleCallsLimit > 0) {
updateAddCallButton();
}
LinphoneCall currentCall = LinphoneManager.getLc().getCurrentCall();
if (currentCall != null) {
tryToStartVideoActivity(currentCall, currentCall.getState());
}
}
private void updateAddCallButton() {
@ -193,9 +198,9 @@ public class ConferenceActivity extends ListActivity implements
protected void registerLinphoneListener(boolean register) {
if (register)
LinphoneManager.getInstance().addListener(this);
LinphoneManager.addListener(this);
else
LinphoneManager.getInstance().removeListener(this);
LinphoneManager.removeListener(this);
}
@ -670,10 +675,23 @@ public class ConferenceActivity extends ListActivity implements
controlLayout.setVisibility(hide ? GONE : VISIBLE);
}
private void tryToStartVideoActivity(LinphoneCall call, State state) {
if (State.StreamsRunning == state && call.getCurrentParamsCopy().getVideoEnabled()) {
if (call.cameraEnabled() ) {
LinphoneActivity.instance().startVideoActivity();
} else {
Log.i("Not starting video call activity as the camera is disabled");
}
}
}
public void onCallStateChanged(final LinphoneCall call, final State state,
final String message) {
final String stateStr = call + " " + state.toString();
Log.d("ConferenceActivity received state ",stateStr);
tryToStartVideoActivity(call, state);
mHandler.post(new Runnable() {
public void run() {
CalleeListAdapter adapter = (CalleeListAdapter) getListAdapter();

View file

@ -87,8 +87,6 @@ public class DialerActivity extends Activity implements LinphoneGuiListener, Lin
private static final String CURRENT_ADDRESS = "org.linphone.current-address";
private static final String CURRENT_DISPLAYNAME = "org.linphone.current-displayname";
private static final int INCOMING_CALL_ACTIVITY = 10;
/**
* @return null if not ready yet
*/
@ -159,13 +157,11 @@ public class DialerActivity extends Activity implements LinphoneGuiListener, Lin
@Override
public void onCreateWhenManagerReady() {
LinphoneCore lc = LinphoneManager.getLc();
if (lc.isIncall()) {
if(lc.isInComingInvitePending()) {
callPending(lc.getCurrentCall());
} else {
enterIncallMode(lc);
}
LinphoneCall pendingCall = LinphoneManager.getInstance().getPendingIncomingCall();
if (pendingCall != null) {
LinphoneActivity.instance().startIncomingCallActivity(pendingCall);
} else if (LinphoneManager.getLc().isIncall()) {
enterIncallMode();
}
}
@ -226,8 +222,9 @@ public class DialerActivity extends Activity implements LinphoneGuiListener, Lin
private void enterIncallMode(LinphoneCore lc) {
LinphoneAddress address = LinphoneManager.getLc().getRemoteAddress();
private void enterIncallMode() {
LinphoneCore lc = LinphoneManager.getLc();
LinphoneAddress address = lc.getRemoteAddress();
mDisplayNameView.setText(LinphoneManager.extractADisplayName(getResources(), address));
// setVolumeControlStream(AudioManager.STREAM_VOICE_CALL);
@ -280,8 +277,6 @@ public class DialerActivity extends Activity implements LinphoneGuiListener, Lin
private void exitCallMode() {
finishActivity(INCOMING_CALL_ACTIVITY);
if (useIncallActivity) {
LinphoneActivity.instance().closeIncallActivity();
} else if(useConferenceActivity) {
@ -306,14 +301,6 @@ public class DialerActivity extends Activity implements LinphoneGuiListener, Lin
}
private void callPending(final LinphoneCall call) {
Intent intent = new Intent()
.setClass(this, IncomingCallActivity.class)
.putExtra("stringUri", call.getRemoteAddress().asStringUriOnly());
startActivityForResult(intent, INCOMING_CALL_ACTIVITY);
}
@Override
protected Dialog onCreateDialog(int id) {
if (id == LinphoneManagerWaitHelper.DIALOG_ID) {
@ -379,29 +366,21 @@ public class DialerActivity extends Activity implements LinphoneGuiListener, Lin
return;
}
if (state==LinphoneCall.State.OutgoingInit){
call.enableCamera(LinphoneManager.getInstance().shareMyCamera());
enterIncallMode(lc);
LinphoneActivity.instance().startOrientationSensor();
}else if (state==LinphoneCall.State.IncomingReceived){
callPending(call);
call.enableCamera(LinphoneManager.getInstance().shareMyCamera());
LinphoneActivity.instance().startOrientationSensor();
}else if (state==LinphoneCall.State.Connected){
if (state==State.OutgoingInit){
enterIncallMode();
}else if (state==State.Connected){
if (call.getDirection() == CallDirection.Incoming) {
enterIncallMode(lc);
enterIncallMode();
}
}else if (state==LinphoneCall.State.Error){
}else if (state==State.Error){
showToast(R.string.call_error, message);
if (lc.getCallsNb() == 0){
if (mWakeLock.isHeld()) mWakeLock.release();
exitCallMode();
LinphoneActivity.instance().stopOrientationSensor();
}
}else if (state==LinphoneCall.State.CallEnd){
}else if (state==State.CallEnd){
if (lc.getCallsNb() == 0){
exitCallMode();
LinphoneActivity.instance().stopOrientationSensor();
}
}

View file

@ -96,7 +96,7 @@ public class IncomingCallActivity extends Activity implements LinphoneManagerRea
@Override
public void onResumeWhenManagerReady() {
LinphoneManager.getInstance().addListener(this);
LinphoneManager.addListener(this);
findIncomingCall(getIntent());
if (mCall == null) {
finish();
@ -125,7 +125,7 @@ public class IncomingCallActivity extends Activity implements LinphoneManagerRea
@Override
protected void onPause() {
super.onPause();
LinphoneManager.getInstance().removeListener(this);
LinphoneManager.removeListener(this);
}
@Override

View file

@ -22,10 +22,13 @@ package org.linphone;
import static android.content.Intent.ACTION_MAIN;
import org.linphone.LinphoneManager.EcCalibrationListener;
import org.linphone.LinphoneSimpleListener.LinphoneOnCallStateChangedListener;
import org.linphone.core.LinphoneAddress;
import org.linphone.core.LinphoneCall;
import org.linphone.core.LinphoneCore;
import org.linphone.core.LinphoneCoreException;
import org.linphone.core.Log;
import org.linphone.core.LinphoneCall.State;
import org.linphone.core.LinphoneCore.EcCalibratorStatus;
import org.linphone.core.LinphoneCore.RegistrationState;
import org.linphone.mediastream.Version;
@ -50,13 +53,12 @@ import android.text.Html;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.FrameLayout;
import android.widget.TabWidget;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.TabHost.TabSpec;
public class LinphoneActivity extends TabActivity implements SensorEventListener, ContactPicked {
public class LinphoneActivity extends TabActivity implements SensorEventListener, ContactPicked, LinphoneOnCallStateChangedListener {
public static final String DIALER_TAB = "dialer";
public static final String PREF_FIRST_LAUNCH = "pref_first_launch";
private static final int video_activity = 100;
@ -69,12 +71,10 @@ public class LinphoneActivity extends TabActivity implements SensorEventListener
private static LinphoneActivity instance;
private FrameLayout mMainFrame;
private SensorManager mSensorManager;
private Sensor mAccelerometer;
private int previousRotation = -1;
private static final String SCREEN_IS_HIDDEN = "screen_is_hidden";
private Handler mHandler = new Handler();
@ -110,7 +110,6 @@ public class LinphoneActivity extends TabActivity implements SensorEventListener
startService(new Intent(ACTION_MAIN).setClass(this, LinphoneService.class));
mMainFrame = (FrameLayout) findViewById(R.id.main_frame);
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
@ -131,6 +130,7 @@ public class LinphoneActivity extends TabActivity implements SensorEventListener
}
}
LinphoneManager.addListener(this);
}
@ -254,11 +254,11 @@ public class LinphoneActivity extends TabActivity implements SensorEventListener
@Override
protected void onPause() {
super.onPause();
if (isFinishing()) {
//restore audio settings
boolean isUserRequest = false;
LinphoneManager.getInstance().routeAudioToReceiver(isUserRequest);
LinphoneManager.removeListener(this);
LinphoneManager.stopProximitySensorForActivity(this);
instance = null;
}
@ -488,7 +488,14 @@ public class LinphoneActivity extends TabActivity implements SensorEventListener
}
});
}
public void startIncomingCallActivity(LinphoneCall pendingCall) {
Intent intent = new Intent()
.setClass(this, IncomingCallActivity.class)
.putExtra("stringUri", pendingCall.getRemoteAddress().asStringUriOnly());
startActivityForResult(intent, INCOMING_CALL_ACTIVITY);
}
public void finishVideoActivity() {
mHandler.post(new Runnable() {
public void run() {
@ -496,6 +503,21 @@ public class LinphoneActivity extends TabActivity implements SensorEventListener
}
});
}
@Override
public void onCallStateChanged(LinphoneCall call, State state,
String message) {
if (state==State.IncomingReceived) {
startIncomingCallActivity(call);
}
if (state==State.OutgoingInit || state==State.IncomingReceived) {
startOrientationSensor();
} else if (state==State.Error || state==State.CallEnd){
stopOrientationSensor();
finishActivity(INCOMING_CALL_ACTIVITY);
}
}
}

View file

@ -49,6 +49,7 @@ import java.util.TimerTask;
import org.linphone.LinphoneSimpleListener.LinphoneOnAudioChangedListener;
import org.linphone.LinphoneSimpleListener.LinphoneServiceListener;
import org.linphone.LinphoneSimpleListener.LinphoneOnAudioChangedListener.AudioState;
import org.linphone.core.CallDirection;
import org.linphone.core.LinphoneAddress;
import org.linphone.core.LinphoneAuthInfo;
import org.linphone.core.LinphoneCall;
@ -133,13 +134,13 @@ public final class LinphoneManager implements LinphoneCoreListener {
private WakeLock mIncallWakeLock;
private List<LinphoneSimpleListener> simpleListeners = new ArrayList<LinphoneSimpleListener>();
public void addListener(LinphoneSimpleListener listener) {
private static List<LinphoneSimpleListener> simpleListeners = new ArrayList<LinphoneSimpleListener>();
public static void addListener(LinphoneSimpleListener listener) {
if (!simpleListeners.contains(listener)) {
simpleListeners.add(listener);
}
}
public void removeListener(LinphoneSimpleListener listener) {
public static void removeListener(LinphoneSimpleListener listener) {
simpleListeners.remove(listener);
}
@ -1139,6 +1140,10 @@ public final class LinphoneManager implements LinphoneCoreListener {
public void onCallStateChanged(LinphoneCall call, State state,
String message) {
if (state==State.OutgoingInit || state==State.IncomingReceived) {
boolean sendCamera = shareMyCamera() && mLc.getConferenceSize() == 0;
call.enableCamera(sendCamera);
}
if (state == State.CallEnd && call == requestedVideoCall) {
requestedVideoCall = null; // drop reference
}
@ -1190,5 +1195,16 @@ public final class LinphoneManager implements LinphoneCoreListener {
public static final boolean isInstanciated() {
return instance != null;
}
public synchronized LinphoneCall getPendingIncomingCall() {
LinphoneCall currentCall = mLc.getCurrentCall();
if (currentCall == null) return null;
LinphoneCall.State state = currentCall.getState();
boolean incomingPending = currentCall.getDirection() == CallDirection.Incoming
&& (state == State.IncomingReceived || state == State.CallIncomingEarlyMedia);
return incomingPending ? currentCall : null;
}
}

View file

@ -100,7 +100,7 @@ public final class LinphoneService extends Service implements LinphoneServiceLis
@Override
public void onCreate() {
super.onCreate();
// In case restart after a crash. Main in LinphoneActivity
LinphonePreferenceManager.getInstance(this);

View file

@ -169,7 +169,7 @@ public class VideoCallActivity extends Activity implements LinphoneOnCallStateCh
if (mVideoViewReady != null)
((GLSurfaceView)mVideoViewReady).onResume();
launched=true;
LinphoneManager.getInstance().addListener(this);
LinphoneManager.addListener(this);
refreshHandler.postDelayed(mCallQualityUpdater=new Runnable(){
LinphoneCall mCurrentCall=LinphoneManager.getLc().getCurrentCall();
public void run() {
@ -282,7 +282,7 @@ public class VideoCallActivity extends Activity implements LinphoneOnCallStateCh
@Override
protected void onPause() {
Log.d("onPause VideoCallActivity (isFinishing:", isFinishing(), ", inCall:", LinphoneManager.getLc().isIncall(), ", changingConf:", getChangingConfigurations());
LinphoneManager.getInstance().removeListener(this);
LinphoneManager.removeListener(this);
if (isFinishing()) {
videoCall = null; // release reference
}

@ -1 +1 @@
Subproject commit 324551708e89dde781dc93a1eeae05532c8717f8
Subproject commit 973953df07d1c435bd738024400e0ab4603a4fba