From d227adbd1bd89be226a0a5213137e9b7bcd670d0 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Mon, 1 Dec 2014 12:38:01 +0100 Subject: [PATCH] Reworked way of using core listener --- src/org/linphone/BluetoothManager.java | 5 +- src/org/linphone/ChatFragment.java | 22 ++- src/org/linphone/InCallActivity.java | 26 +-- src/org/linphone/IncomingCallActivity.java | 17 +- src/org/linphone/LinphoneActivity.java | 41 +++-- src/org/linphone/LinphoneManager.java | 173 +----------------- src/org/linphone/LinphoneService.java | 35 ++-- src/org/linphone/LinphoneSimpleListener.java | 93 ---------- src/org/linphone/StatusFragment.java | 23 ++- .../setup/RemoteProvisioningActivity.java | 23 +-- src/org/linphone/setup/SetupActivity.java | 47 ++--- submodules/linphone | 2 +- 12 files changed, 140 insertions(+), 367 deletions(-) delete mode 100644 src/org/linphone/LinphoneSimpleListener.java diff --git a/src/org/linphone/BluetoothManager.java b/src/org/linphone/BluetoothManager.java index 5a1b49bc4..7a3de4307 100644 --- a/src/org/linphone/BluetoothManager.java +++ b/src/org/linphone/BluetoothManager.java @@ -19,7 +19,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ import java.util.List; -import org.linphone.LinphoneSimpleListener.LinphoneOnAudioChangedListener.AudioState; import org.linphone.compatibility.Compatibility; import org.linphone.mediastream.Log; @@ -277,11 +276,11 @@ public class BluetoothManager extends BroadcastReceiver { int state = intent.getIntExtra(AudioManager.EXTRA_SCO_AUDIO_STATE, 0); if (state == AudioManager.SCO_AUDIO_STATE_CONNECTED) { Log.d("Bluetooth sco state => connected"); - LinphoneManager.getInstance().audioStateChanged(AudioState.BLUETOOTH); +// LinphoneManager.getInstance().audioStateChanged(AudioState.BLUETOOTH); isScoConnected = true; } else if (state == AudioManager.SCO_AUDIO_STATE_DISCONNECTED) { Log.d("Bluetooth sco state => disconnected"); - LinphoneManager.getInstance().audioStateChanged(AudioState.SPEAKER); +// LinphoneManager.getInstance().audioStateChanged(AudioState.SPEAKER); isScoConnected = false; } else { Log.d("Bluetooth sco state => " + state); diff --git a/src/org/linphone/ChatFragment.java b/src/org/linphone/ChatFragment.java index cbfc06ca8..77549116e 100644 --- a/src/org/linphone/ChatFragment.java +++ b/src/org/linphone/ChatFragment.java @@ -33,13 +33,13 @@ import java.util.HashMap; import java.util.List; import org.apache.http.util.ByteArrayBuffer; -import org.linphone.LinphoneSimpleListener.LinphoneOnComposingReceivedListener; import org.linphone.compatibility.Compatibility; import org.linphone.core.LinphoneAddress; import org.linphone.core.LinphoneChatMessage; import org.linphone.core.LinphoneChatMessage.State; import org.linphone.core.LinphoneChatRoom; import org.linphone.core.LinphoneCore; +import org.linphone.core.LinphoneCoreListener.LinphoneComposingListener; import org.linphone.mediastream.Log; import org.linphone.ui.AvatarWithShadow; import org.linphone.ui.BubbleChat; @@ -87,7 +87,7 @@ import android.widget.Toast; /** * @author Sylvain Berfini */ -public class ChatFragment extends Fragment implements OnClickListener, LinphoneChatMessage.StateListener, LinphoneOnComposingReceivedListener { +public class ChatFragment extends Fragment implements OnClickListener, LinphoneChatMessage.StateListener, LinphoneComposingListener { private static final int ADD_PHOTO = 1337; private static final int MENU_DELETE_MESSAGE = 0; private static final int MENU_SAVE_PICTURE = 1; @@ -520,8 +520,10 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC LinphoneService.instance().removeMessageNotification(); - if (LinphoneManager.isInstanciated()) - LinphoneManager.getInstance().setOnComposingReceivedListener(null); + LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull(); + if (lc != null) { + lc.removeListener(this); + } super.onPause(); @@ -535,10 +537,12 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC message.addTextChangedListener(textWatcher); addVirtualKeyboardVisiblityListener(); - if (LinphoneManager.isInstanciated()) - LinphoneManager.getInstance().setOnComposingReceivedListener(this); - super.onResume(); + + LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull(); + if (lc != null) { + lc.addListener(this); + } if (LinphoneActivity.isInstanciated()) { LinphoneActivity.instance().selectMenu(FragmentsAvailable.CHAT); @@ -671,7 +675,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC } } - public void onMessageReceived(final int id, LinphoneAddress from, final LinphoneChatMessage message) { + public void onMessageReceived(LinphoneAddress from, final LinphoneChatMessage message) { if (from.asStringUriOnly().equals(sipUri)) { if (message.getText() != null) { mHandler.post(new Runnable() { @@ -1086,7 +1090,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC } @Override - public void onComposingReceived(LinphoneChatRoom room) { + public void isComposingReceived(LinphoneCore lc, LinphoneChatRoom room) { if (chatRoom != null && room != null && chatRoom.getPeerAddress().asStringUriOnly().equals(room.getPeerAddress().asStringUriOnly())) { mHandler.post(new Runnable() { @Override diff --git a/src/org/linphone/InCallActivity.java b/src/org/linphone/InCallActivity.java index 3798ce7bf..78583e0f6 100644 --- a/src/org/linphone/InCallActivity.java +++ b/src/org/linphone/InCallActivity.java @@ -20,8 +20,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. import java.util.Arrays; import java.util.List; -import org.linphone.LinphoneSimpleListener.LinphoneOnCallEncryptionChangedListener; -import org.linphone.LinphoneSimpleListener.LinphoneOnCallStateChangedListener; import org.linphone.core.LinphoneAddress; import org.linphone.core.LinphoneCall; import org.linphone.core.LinphoneCall.State; @@ -29,6 +27,8 @@ import org.linphone.core.LinphoneCallParams; import org.linphone.core.LinphoneCore; import org.linphone.core.LinphoneCoreException; import org.linphone.core.LinphoneCoreFactory; +import org.linphone.core.LinphoneCoreListener.LinphoneCallEncryptionStateListener; +import org.linphone.core.LinphoneCoreListener.LinphoneCallStateListener; import org.linphone.core.LinphonePlayer; import org.linphone.mediastream.Log; import org.linphone.mediastream.video.capture.hwconf.AndroidCameraConfiguration; @@ -70,10 +70,7 @@ import android.widget.Toast; /** * @author Sylvain Berfini */ -public class InCallActivity extends FragmentActivity implements - LinphoneOnCallStateChangedListener, - LinphoneOnCallEncryptionChangedListener, - OnClickListener { +public class InCallActivity extends FragmentActivity implements LinphoneCallStateListener, LinphoneCallEncryptionStateListener, OnClickListener { private final static int SECONDS_BEFORE_HIDING_CONTROLS = 3000; private final static int SECONDS_BEFORE_DENYING_CALL_UPDATE = 30000; @@ -1085,7 +1082,7 @@ public class InCallActivity extends FragmentActivity implements } @Override - public void onCallStateChanged(final LinphoneCall call, State state, String message) { + public void callState(LinphoneCore lc, final LinphoneCall call, LinphoneCall.State state, String message) { if (LinphoneManager.getLc().getCallsNb() == 0) { finish(); return; @@ -1209,7 +1206,7 @@ public class InCallActivity extends FragmentActivity implements } @Override - public void onCallEncryptionChanged(final LinphoneCall call, boolean encrypted, String authenticationToken) { + public void callEncryptionChanged(LinphoneCore lc, final LinphoneCall call, boolean encrypted, String authenticationToken) { if (status != null) { mHandler.post(new Runnable() { @Override @@ -1223,6 +1220,7 @@ public class InCallActivity extends FragmentActivity implements @Override protected void onResume() { instance = this; + if (isVideoEnabled(LinphoneManager.getLc().getCurrentCall())) { displayVideoCallControlsIfHidden(); } else { @@ -1232,7 +1230,10 @@ public class InCallActivity extends FragmentActivity implements super.onResume(); - LinphoneManager.addListener(this); + LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull(); + if (lc != null) { + lc.addListener(this); + } refreshCallList(getResources()); @@ -1273,6 +1274,11 @@ public class InCallActivity extends FragmentActivity implements @Override protected void onPause() { + LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull(); + if (lc != null) { + lc.removeListener(this); + } + super.onPause(); if (mControlsHandler != null && mControls != null) { @@ -1283,8 +1289,6 @@ public class InCallActivity extends FragmentActivity implements if (!isVideoEnabled(LinphoneManager.getLc().getCurrentCall())) { LinphoneManager.stopProximitySensorForActivity(this); } - - LinphoneManager.removeListener(this); } @Override diff --git a/src/org/linphone/IncomingCallActivity.java b/src/org/linphone/IncomingCallActivity.java index a350eef63..ca2c8c508 100644 --- a/src/org/linphone/IncomingCallActivity.java +++ b/src/org/linphone/IncomingCallActivity.java @@ -20,11 +20,12 @@ package org.linphone; import java.util.List; -import org.linphone.LinphoneSimpleListener.LinphoneOnCallStateChangedListener; import org.linphone.core.LinphoneAddress; import org.linphone.core.LinphoneCall; import org.linphone.core.LinphoneCall.State; import org.linphone.core.LinphoneCallParams; +import org.linphone.core.LinphoneCore; +import org.linphone.core.LinphoneCoreListener.LinphoneCallStateListener; import org.linphone.mediastream.Log; import org.linphone.ui.AvatarWithShadow; import org.linphone.ui.LinphoneSliders; @@ -44,7 +45,7 @@ import android.widget.Toast; * * @author Guillaume Beraudo */ -public class IncomingCallActivity extends Activity implements LinphoneOnCallStateChangedListener, LinphoneSliderTriggered { +public class IncomingCallActivity extends Activity implements LinphoneCallStateListener, LinphoneSliderTriggered { private static IncomingCallActivity instance; @@ -87,7 +88,10 @@ public class IncomingCallActivity extends Activity implements LinphoneOnCallStat protected void onResume() { super.onResume(); instance = this; - LinphoneManager.addListener(this); + LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull(); + if (lc != null) { + lc.addListener(this); + } // Only one call ringing at a time is allowed if (LinphoneManager.getLcIfManagerNotDestroyedOrNull() != null) { @@ -120,8 +124,11 @@ public class IncomingCallActivity extends Activity implements LinphoneOnCallStat @Override protected void onPause() { + LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull(); + if (lc != null) { + lc.removeListener(this); + } super.onPause(); - LinphoneManager.removeListener(this); } @Override @@ -140,7 +147,7 @@ public class IncomingCallActivity extends Activity implements LinphoneOnCallStat } @Override - public void onCallStateChanged(LinphoneCall call, State state, String msg) { + public void callState(LinphoneCore lc, LinphoneCall call, LinphoneCall.State state, String message) { if (call == mCall && State.CallEnd == state) { finish(); } diff --git a/src/org/linphone/LinphoneActivity.java b/src/org/linphone/LinphoneActivity.java index 24d7b761f..35ce49d33 100644 --- a/src/org/linphone/LinphoneActivity.java +++ b/src/org/linphone/LinphoneActivity.java @@ -27,24 +27,25 @@ import java.util.Collection; import java.util.List; import org.linphone.LinphoneManager.AddressType; -import org.linphone.LinphoneSimpleListener.LinphoneOnCallStateChangedListener; -import org.linphone.LinphoneSimpleListener.LinphoneOnMessageReceivedListener; -import org.linphone.LinphoneSimpleListener.LinphoneOnRegistrationStateChangedListener; import org.linphone.compatibility.Compatibility; import org.linphone.core.CallDirection; import org.linphone.core.LinphoneAddress; import org.linphone.core.LinphoneAuthInfo; import org.linphone.core.LinphoneCall; -import org.linphone.core.LinphoneProxyConfig; import org.linphone.core.LinphoneCall.State; import org.linphone.core.LinphoneCallLog; import org.linphone.core.LinphoneCallLog.CallStatus; import org.linphone.core.LinphoneChatMessage; +import org.linphone.core.LinphoneChatRoom; import org.linphone.core.LinphoneCore; import org.linphone.core.LinphoneCore.RegistrationState; import org.linphone.core.LinphoneCoreException; import org.linphone.core.LinphoneCoreFactory; +import org.linphone.core.LinphoneCoreListener.LinphoneCallStateListener; +import org.linphone.core.LinphoneCoreListener.LinphoneMessageListener; +import org.linphone.core.LinphoneCoreListener.LinphoneRegistrationStateListener; import org.linphone.core.LinphoneFriend; +import org.linphone.core.LinphoneProxyConfig; import org.linphone.mediastream.Log; import org.linphone.setup.RemoteProvisioningLoginActivity; import org.linphone.setup.SetupActivity; @@ -88,10 +89,7 @@ import android.widget.Toast; /** * @author Sylvain Berfini */ -public class LinphoneActivity extends FragmentActivity implements - OnClickListener, ContactPicked, LinphoneOnCallStateChangedListener, - LinphoneOnMessageReceivedListener, - LinphoneOnRegistrationStateChangedListener { +public class LinphoneActivity extends FragmentActivity implements OnClickListener, ContactPicked, LinphoneCallStateListener, LinphoneMessageListener, LinphoneRegistrationStateListener { public static final String PREF_FIRST_LAUNCH = "pref_first_launch"; private static final int SETTINGS_ACTIVITY = 123; private static final int FIRST_LOGIN_ACTIVITY = 101; @@ -735,11 +733,11 @@ public class LinphoneActivity extends FragmentActivity implements } @Override - public void onMessageReceived(LinphoneAddress from, LinphoneChatMessage message, int id) { + public void messageReceived(LinphoneCore lc, LinphoneChatRoom cr, LinphoneChatMessage message) { + LinphoneAddress from = cr.getPeerAddress(); ChatFragment chatFragment = ((ChatFragment) messageListenerFragment); if (messageListenerFragment != null && messageListenerFragment.isVisible() && chatFragment.getSipUri().equals(from.asStringUriOnly())) { - chatFragment.onMessageReceived(id, from, message); - getChatStorage().markMessageAsRead(id); + chatFragment.onMessageReceived(from, message); } else if (LinphoneService.isReady()) { displayMissedChats(getChatStorage().getUnreadMessageCount()); if (messageListFragment != null && messageListFragment.isVisible()) { @@ -770,8 +768,7 @@ public class LinphoneActivity extends FragmentActivity implements getChatStorage().updateMessageStatus(to, id, newState); } - public void onRegistrationStateChanged(LinphoneProxyConfig proxy, RegistrationState state, String message) { - LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull(); + public void registrationState(LinphoneCore lc, LinphoneProxyConfig proxy, LinphoneCore.RegistrationState state, String smessage) { if (statusFragment != null) { if (lc != null) if(lc.getDefaultProxyConfig() == null) @@ -833,7 +830,7 @@ public class LinphoneActivity extends FragmentActivity implements } @Override - public void onCallStateChanged(LinphoneCall call, State state, String message) { + public void callState(LinphoneCore lc, LinphoneCall call, LinphoneCall.State state, String message) { if (state == State.IncomingReceived) { startActivity(new Intent(this, IncomingCallActivity.class)); } else if (state == State.OutgoingInit) { @@ -1266,6 +1263,11 @@ public class LinphoneActivity extends FragmentActivity implements @Override protected void onPause() { + LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull(); + if (lc != null) { + lc.removeListener(this); + } + getIntent().putExtra("PreviousActivity", 0); super.onPause(); } @@ -1277,10 +1279,11 @@ public class LinphoneActivity extends FragmentActivity implements if (!LinphoneService.isReady()) { startService(new Intent(ACTION_MAIN).setClass(this, LinphoneService.class)); } - - // Remove to avoid duplication of the listeners - LinphoneManager.removeListener(this); - LinphoneManager.addListener(this); + + LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull(); + if (lc != null) { + lc.addListener(this); + } prepareContactsInBackground(); @@ -1310,8 +1313,6 @@ public class LinphoneActivity extends FragmentActivity implements @Override protected void onDestroy() { - LinphoneManager.removeListener(this); - if (mOrientationHelper != null) { mOrientationHelper.disable(); mOrientationHelper = null; diff --git a/src/org/linphone/LinphoneManager.java b/src/org/linphone/LinphoneManager.java index 85bac69d8..41ad91abc 100644 --- a/src/org/linphone/LinphoneManager.java +++ b/src/org/linphone/LinphoneManager.java @@ -28,22 +28,11 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; -import java.util.ArrayList; import java.util.HashSet; -import java.util.List; import java.util.Set; import java.util.Timer; import java.util.TimerTask; -import org.linphone.LinphoneSimpleListener.ConnectivityChangedListener; -import org.linphone.LinphoneSimpleListener.LinphoneOnAudioChangedListener; -import org.linphone.LinphoneSimpleListener.LinphoneOnAudioChangedListener.AudioState; -import org.linphone.LinphoneSimpleListener.LinphoneOnNotifyReceivedListener; -import org.linphone.LinphoneSimpleListener.LinphoneOnComposingReceivedListener; -import org.linphone.LinphoneSimpleListener.LinphoneOnDTMFReceivedListener; -import org.linphone.LinphoneSimpleListener.LinphoneOnMessageReceivedListener; -import org.linphone.LinphoneSimpleListener.LinphoneOnRemoteProvisioningListener; -import org.linphone.LinphoneSimpleListener.LinphoneServiceListener; import org.linphone.compatibility.Compatibility; import org.linphone.core.CallDirection; import org.linphone.core.LinphoneAddress; @@ -63,6 +52,7 @@ import org.linphone.core.LinphoneCoreException; import org.linphone.core.LinphoneCoreFactory; import org.linphone.core.LinphoneCoreFactoryImpl; import org.linphone.core.LinphoneCoreListener; +import org.linphone.core.LinphoneCoreListener.LinphoneListener; import org.linphone.core.LinphoneEvent; import org.linphone.core.LinphoneFriend; import org.linphone.core.LinphoneInfoMessage; @@ -78,7 +68,6 @@ import org.linphone.mediastream.Version; import org.linphone.mediastream.video.capture.hwconf.AndroidCameraConfiguration; import org.linphone.mediastream.video.capture.hwconf.AndroidCameraConfiguration.AndroidCamera; import org.linphone.mediastream.video.capture.hwconf.Hacks; -import org.linphone.setup.RemoteProvisioningActivity; import android.annotation.SuppressLint; import android.annotation.TargetApi; @@ -128,7 +117,7 @@ import android.widget.Toast; * @author Guillaume Beraudo * */ -public class LinphoneManager implements LinphoneCoreListener { +public class LinphoneManager implements LinphoneListener { private static LinphoneManager instance; private Context mServiceContext; @@ -148,20 +137,9 @@ public class LinphoneManager implements LinphoneCoreListener { public String wizardLoginViewDomain = null; - private static List simpleListeners = new ArrayList(); - public static void addListener(LinphoneSimpleListener listener) { - if (!simpleListeners.contains(listener)) { - simpleListeners.add(listener); - } - } - public static void removeListener(LinphoneSimpleListener listener) { - simpleListeners.remove(listener); - } - - protected LinphoneManager(final Context c, LinphoneServiceListener listener) { + protected LinphoneManager(final Context c) { sExited=false; mServiceContext = c; - mListenerDispatcher = new ListenerDispatcher(listener); basePath = c.getFilesDir().getAbsolutePath(); mLPConfigXsd = basePath + "/lpconfig.xsd"; mLinphoneFactoryConfigFile = basePath + "/linphonerc"; @@ -203,13 +181,6 @@ public class LinphoneManager implements LinphoneCoreListener { BluetoothManager.getInstance().disableBluetoothSCO(); mLc.enableSpeaker(speakerOn); - audioStateChanged(speakerOn ? AudioState.SPEAKER : AudioState.EARPIECE); - } - - public void audioStateChanged(AudioState state) { - for (LinphoneOnAudioChangedListener listener : getSimpleListeners(LinphoneOnAudioChangedListener.class)) { - listener.onAudioStateChanged(state); - } } public void routeAudioToSpeaker() { @@ -230,11 +201,11 @@ public class LinphoneManager implements LinphoneCoreListener { routeAudioToSpeakerHelper(false); } - public synchronized static final LinphoneManager createAndStart(Context c, LinphoneServiceListener listener) { + public synchronized static final LinphoneManager createAndStart(Context c) { if (instance != null) throw new RuntimeException("Linphone Manager is already initialized"); - instance = new LinphoneManager(c, listener); + instance = new LinphoneManager(c); instance.startLibLinphone(c); TelephonyManager tm = (TelephonyManager) c.getSystemService(Context.TELEPHONY_SERVICE); boolean gsmIdle = tm.getCallState() == TelephonyManager.CALL_STATE_IDLE; @@ -315,11 +286,9 @@ public class LinphoneManager implements LinphoneCoreListener { LinphoneProxyConfig lpc = mLc.getDefaultProxyConfig(); if (mR.getBoolean(R.bool.forbid_self_call) && lpc!=null && lAddress.asStringUriOnly().equals(lpc.getIdentity())) { - mListenerDispatcher.tryingNewOutgoingCallButWrongDestinationAddress(); return; } } catch (LinphoneCoreException e) { - mListenerDispatcher.tryingNewOutgoingCallButWrongDestinationAddress(); return; } lAddress.setDisplayName(displayName); @@ -338,7 +307,6 @@ public class LinphoneManager implements LinphoneCoreListener { } catch (LinphoneCoreException e) { - mListenerDispatcher.tryingNewOutgoingCallButCannotGetCallParameters(); return; } } else if (LinphoneActivity.isInstanciated()) { @@ -475,6 +443,7 @@ public class LinphoneManager implements LinphoneCoreListener { LinphoneCoreFactory.instance().setDebugMode(isDebugLogEnabled, getString(R.string.app_name)); mLc = LinphoneCoreFactory.instance().createLinphoneCore(this, mLinphoneConfigFile, mLinphoneFactoryConfigFile, null, c); + mLc.addListener((LinphoneCoreListener) c); //initLiblinphone(); TimerTask lTask = new TimerTask() { @@ -683,24 +652,13 @@ public class LinphoneManager implements LinphoneCoreListener { I/Linphone( 8397): WIFI connected: setting network reachable */ public void connectivityChanged(ConnectivityManager cm, boolean noConnectivity) { - NetworkInfo eventInfo = cm.getActiveNetworkInfo(); updateNetworkReachability(); - - if (connectivityListener != null) { - connectivityListener.onConnectivityChanged(mServiceContext, eventInfo, cm); - } - } - - private ConnectivityChangedListener connectivityListener; - public void addConnectivityChangedListener(ConnectivityChangedListener l) { - connectivityListener = l; } public interface EcCalibrationListener { void onEcCalibrationStatus(EcCalibratorStatus status, int delayMs); } - private ListenerDispatcher mListenerDispatcher; private LinphoneCall ringingCall; private MediaPlayer mRingerPlayer; @@ -713,15 +671,9 @@ public class LinphoneManager implements LinphoneCoreListener { public void show(LinphoneCore lc) {} public void newSubscriptionRequest(LinphoneCore lc, LinphoneFriend lf, String url) { - for (LinphoneSimpleListener listener : getSimpleListeners(LinphoneActivity.class)) { - ((LinphoneActivity) listener).onNewSubscriptionRequestReceived(lf, url); - } } public void notifyPresenceReceived(LinphoneCore lc, LinphoneFriend lf) { - for (LinphoneSimpleListener listener : getSimpleListeners(LinphoneActivity.class)) { - ((LinphoneActivity) listener).onNotifyPresenceReceived(lf); - } } public void textReceived(LinphoneCore lc, LinphoneChatRoom cr, @@ -732,13 +684,6 @@ public class LinphoneManager implements LinphoneCoreListener { @Override public void dtmfReceived(LinphoneCore lc, LinphoneCall call, int dtmf) { Log.d("DTMF received: " + dtmf); - if (dtmfReceivedListener != null) - dtmfReceivedListener.onDTMFReceived(call, dtmf); - } - - private LinphoneOnDTMFReceivedListener dtmfReceivedListener; - public void setOnDTMFReceivedListener(LinphoneOnDTMFReceivedListener listener) { - dtmfReceivedListener = listener; } @Override @@ -751,12 +696,10 @@ public class LinphoneManager implements LinphoneCoreListener { String textMessage = message.getText(); String url = message.getExternalBodyUrl(); - int id = -1; if (textMessage != null && textMessage.length() > 0) { - id = ChatStorage.getInstance().saveTextMessage(from.asStringUriOnly(), "", textMessage, message.getTime()); + ChatStorage.getInstance().saveTextMessage(from.asStringUriOnly(), "", textMessage, message.getTime()); } else if (url != null && url.length() > 0) { - //Bitmap bm = ChatFragment.downloadImage(url); - id = ChatStorage.getInstance().saveImageMessage(from.asStringUriOnly(), "", null, message.getExternalBodyUrl(), message.getTime()); + ChatStorage.getInstance().saveImageMessage(from.asStringUriOnly(), "", null, message.getExternalBodyUrl(), message.getTime()); } try { @@ -765,10 +708,6 @@ public class LinphoneManager implements LinphoneCoreListener { LinphoneService.instance().displayMessageNotification(from.asStringUriOnly(), from.getDisplayName(), textMessage); } } catch (Exception e) { } - - for (LinphoneSimpleListener listener : getSimpleListeners(LinphoneOnMessageReceivedListener.class)) { - ((LinphoneOnMessageReceivedListener) listener).onMessageReceived(from, message, id); - } } public String getLastLcStatusMessage() { @@ -778,7 +717,6 @@ public class LinphoneManager implements LinphoneCoreListener { public void displayStatus(final LinphoneCore lc, final String message) { Log.i(message); lastLcStatusMessage=message; - mListenerDispatcher.onDisplayStatus(message); } public void globalState(final LinphoneCore lc, final GlobalState state, final String message) { @@ -798,13 +736,10 @@ public class LinphoneManager implements LinphoneCoreListener { } }); } - - mListenerDispatcher.onGlobalStateChanged(state, message); } public void registrationState(final LinphoneCore lc, final LinphoneProxyConfig proxy,final RegistrationState state,final String message) { Log.i("new state ["+state+"]"); - mListenerDispatcher.onRegistrationStateChanged(proxy, state, message); } private int savedMaxCallWhileGsmIncall; @@ -954,14 +889,12 @@ public class LinphoneManager implements LinphoneCoreListener { Log.i("New call active while incall (CPU only) wake lock already active"); } } - mListenerDispatcher.onCallStateChanged(call, state, message); } public void callStatsUpdated(final LinphoneCore lc, final LinphoneCall call, final LinphoneCallStats stats) {} public void callEncryptionChanged(LinphoneCore lc, LinphoneCall call, boolean encrypted, String authenticationToken) { - mListenerDispatcher.onCallEncryptionChanged(call, encrypted, authenticationToken); } public void ecCalibrationStatus(final LinphoneCore lc,final EcCalibratorStatus status, final int delayMs, @@ -1246,73 +1179,6 @@ public class LinphoneManager implements LinphoneCoreListener { return getLc(); } - @SuppressWarnings("unchecked") - private List getSimpleListeners(Class clazz) { - List list = new ArrayList(); - for (LinphoneSimpleListener l : simpleListeners) { - if (clazz.isInstance(l)) list.add((T) l); - } - return list; - } - - private class ListenerDispatcher implements LinphoneServiceListener { - private LinphoneServiceListener serviceListener; - - public ListenerDispatcher(LinphoneServiceListener listener) { - this.serviceListener = listener; - } - - public void onCallEncryptionChanged(LinphoneCall call, - boolean encrypted, String authenticationToken) { - if (serviceListener != null) { - serviceListener.onCallEncryptionChanged(call, encrypted, authenticationToken); - } - for (LinphoneOnCallEncryptionChangedListener l : getSimpleListeners(LinphoneOnCallEncryptionChangedListener.class)) { - l.onCallEncryptionChanged(call, encrypted, authenticationToken); - } - } - - public void onCallStateChanged(LinphoneCall call, State state, String message) { - if (state == State.OutgoingInit || state == State.IncomingReceived) { - boolean sendCamera = mLc.getConferenceSize() == 0; - enableCamera(call, sendCamera); - } - - if (serviceListener != null) serviceListener.onCallStateChanged(call, state, message); - for (LinphoneOnCallStateChangedListener l : getSimpleListeners(LinphoneOnCallStateChangedListener.class)) { - l.onCallStateChanged(call, state, message); - } - } - - public void onDisplayStatus(String message) { - if (serviceListener != null) serviceListener.onDisplayStatus(message); - } - - public void onGlobalStateChanged(GlobalState state, String message) { - if (serviceListener != null) serviceListener.onGlobalStateChanged( state, message); - } - - public void onRegistrationStateChanged(LinphoneProxyConfig proxy, RegistrationState state, - String message) { - if (serviceListener != null) serviceListener.onRegistrationStateChanged(proxy, state, message); - for (LinphoneOnRegistrationStateChangedListener listener : getSimpleListeners(LinphoneOnRegistrationStateChangedListener.class)) { - listener.onRegistrationStateChanged(proxy, state, message); - } - } - - public void tryingNewOutgoingCallButAlreadyInCall() { - if (serviceListener != null) serviceListener.tryingNewOutgoingCallButAlreadyInCall(); - } - - public void tryingNewOutgoingCallButCannotGetCallParameters() { - if (serviceListener != null) serviceListener.tryingNewOutgoingCallButCannotGetCallParameters(); - } - - public void tryingNewOutgoingCallButWrongDestinationAddress() { - if (serviceListener != null) serviceListener.tryingNewOutgoingCallButWrongDestinationAddress(); - } - } - public static final boolean isInstanciated() { return instance != null; } @@ -1374,17 +1240,11 @@ public class LinphoneManager implements LinphoneCoreListener { Log.d("Subscription state changed to "+state+" event name is "+ev.getEventName()); } - private LinphoneOnNotifyReceivedListener notifyReceivedListener; - public void setNotifyReceivedListener(LinphoneOnNotifyReceivedListener listener) { - notifyReceivedListener = listener; - } @Override public void notifyReceived(LinphoneCore lc, LinphoneEvent ev, String eventName, LinphoneContent content) { Log.d("Notify received for event "+eventName); if (content!=null) Log.d("with content "+content.getType()+"/"+content.getSubtype()+" data:"+content.getDataAsString()); - if (notifyReceivedListener != null) - notifyReceivedListener.onNotifyReceived(ev,eventName,content); } @Override public void publishStateChanged(LinphoneCore lc, LinphoneEvent ev, @@ -1392,32 +1252,15 @@ public class LinphoneManager implements LinphoneCoreListener { Log.d("Publish state changed to " + state + " for event name " + ev.getEventName()); } - private LinphoneOnComposingReceivedListener composingReceivedListener; - public void setOnComposingReceivedListener(LinphoneOnComposingReceivedListener listener) { - composingReceivedListener = listener; - } @Override public void isComposingReceived(LinphoneCore lc, LinphoneChatRoom cr) { Log.d("Composing received for chatroom " + cr.getPeerAddress().asStringUriOnly()); - if (composingReceivedListener != null) - composingReceivedListener.onComposingReceived(cr); } - private LinphoneOnRemoteProvisioningListener remoteProvisioningListener; - public void setOnRemoteProvisioningListener(LinphoneOnRemoteProvisioningListener listener) { - remoteProvisioningListener = listener; - } @Override public void configuringStatus(LinphoneCore lc, RemoteProvisioningState state, String message) { Log.d("Remote provisioning status = " + state.toString() + " (" + message + ")"); - if (RemoteProvisioningActivity.getInstance() != null) { - RemoteProvisioningActivity.getInstance().onConfiguringStatus(state); - } - - if (remoteProvisioningListener != null) { - remoteProvisioningListener.onConfiguringStatus(state); - } if (state == RemoteProvisioningState.ConfiguringSuccessful) { if (LinphonePreferences.instance().isProvisioningLoginViewEnabled()) { diff --git a/src/org/linphone/LinphoneService.java b/src/org/linphone/LinphoneService.java index 87347186b..95aaae0d4 100644 --- a/src/org/linphone/LinphoneService.java +++ b/src/org/linphone/LinphoneService.java @@ -21,7 +21,6 @@ package org.linphone; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import org.linphone.LinphoneSimpleListener.LinphoneServiceListener; import org.linphone.compatibility.Compatibility; import org.linphone.core.LinphoneAddress; import org.linphone.core.LinphoneCall; @@ -31,6 +30,9 @@ import org.linphone.core.LinphoneCore.GlobalState; import org.linphone.core.LinphoneCore.RegistrationState; import org.linphone.core.LinphoneCoreException; import org.linphone.core.LinphoneCoreFactoryImpl; +import org.linphone.core.LinphoneCoreListener.LinphoneCallStateListener; +import org.linphone.core.LinphoneCoreListener.LinphoneGlobalStateListener; +import org.linphone.core.LinphoneCoreListener.LinphoneRegistrationStateListener; import org.linphone.core.LinphoneProxyConfig; import org.linphone.mediastream.Log; import org.linphone.mediastream.Version; @@ -71,7 +73,8 @@ import android.provider.MediaStore; * @author Guillaume Beraudo * */ -public final class LinphoneService extends Service implements LinphoneServiceListener { +public final class LinphoneService extends Service implements LinphoneCallStateListener, + LinphoneGlobalStateListener, LinphoneRegistrationStateListener { /* Listener needs to be implemented in the Service as it calls * setLatestEventInfo and startActivity() which needs a context. */ @@ -156,7 +159,7 @@ public final class LinphoneService extends Service implements LinphoneServiceLis UIThreadDispatcher.Dispatch(new Runnable() { @Override public void run() { - LinphoneManager.createAndStart(LinphoneService.this, LinphoneService.this); + LinphoneManager.createAndStart(LinphoneService.this); } }); @@ -483,6 +486,11 @@ public final class LinphoneService extends Service implements LinphoneServiceLis @Override public synchronized void onDestroy() { + LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull(); + if (lc != null) { + lc.removeListener(this); + } + instance = null; LinphoneManager.destroy(); @@ -497,18 +505,16 @@ public final class LinphoneService extends Service implements LinphoneServiceLis ((AlarmManager) this.getSystemService(Context.ALARM_SERVICE)).cancel(mkeepAlivePendingIntent); super.onDestroy(); } - - public void onDisplayStatus(final String message) { - } - public void onGlobalStateChanged(final GlobalState state, final String message) { + @Override + public void globalState(LinphoneCore lc,LinphoneCore.GlobalState state, String message) { if (state == GlobalState.GlobalOn) { sendNotification(IC_LEVEL_OFFLINE, R.string.notification_started); } } - public void onRegistrationStateChanged(final LinphoneProxyConfig proxy, final RegistrationState state, - final String message) { + @Override + public void registrationState(LinphoneCore lc, LinphoneProxyConfig cfg, LinphoneCore.RegistrationState state, String smessage) { // if (instance == null) { // Log.i("Service not ready, discarding registration state change to ",state.toString()); // return; @@ -526,14 +532,6 @@ public final class LinphoneService extends Service implements LinphoneServiceLis sendNotification(IC_LEVEL_OFFLINE, R.string.notification_started); } } - - mHandler.post(new Runnable() { - public void run() { - if (LinphoneActivity.isInstanciated()) { - LinphoneActivity.instance().onRegistrationStateChanged(proxy,state,message); - } - } - }); } public void setActivityToLaunchOnIncomingReceived(Class activity) { @@ -558,7 +556,8 @@ public final class LinphoneService extends Service implements LinphoneServiceLis .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); } - public void onCallStateChanged(final LinphoneCall call, final State state, final String message) { + @Override + public void callState(LinphoneCore lc, LinphoneCall call, LinphoneCall.State state, String message) { if (instance == null) { Log.i("Service not ready, discarding call state change to ",state.toString()); return; diff --git a/src/org/linphone/LinphoneSimpleListener.java b/src/org/linphone/LinphoneSimpleListener.java deleted file mode 100644 index d52e1998c..000000000 --- a/src/org/linphone/LinphoneSimpleListener.java +++ /dev/null @@ -1,93 +0,0 @@ -/* -LinphoneServiceListener.java -Copyright (C) 2011 Belledonne Communications, Grenoble, France - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -package org.linphone; - -import org.linphone.core.LinphoneAddress; -import org.linphone.core.LinphoneCall; -import org.linphone.core.LinphoneContent; -import org.linphone.core.LinphoneEvent; -import org.linphone.core.LinphoneProxyConfig; -import org.linphone.core.LinphoneCall.State; -import org.linphone.core.LinphoneChatMessage; -import org.linphone.core.LinphoneChatRoom; -import org.linphone.core.LinphoneCore.GlobalState; -import org.linphone.core.LinphoneCore.RegistrationState; -import org.linphone.core.LinphoneCore.RemoteProvisioningState; - -import android.content.Context; -import android.net.ConnectivityManager; -import android.net.NetworkInfo; - -public interface LinphoneSimpleListener { - - public static interface LinphoneServiceListener extends - LinphoneOnGlobalStateChangedListener, - LinphoneOnCallStateChangedListener, - LinphoneOnCallEncryptionChangedListener - { - void tryingNewOutgoingCallButCannotGetCallParameters(); - void tryingNewOutgoingCallButWrongDestinationAddress(); - void tryingNewOutgoingCallButAlreadyInCall(); - void onDisplayStatus(String message); - void onRegistrationStateChanged(LinphoneProxyConfig proxy,RegistrationState state, String message); - } - - - public static interface LinphoneOnCallEncryptionChangedListener extends LinphoneSimpleListener { - void onCallEncryptionChanged(LinphoneCall call, boolean encrypted, String authenticationToken); - } - - public static interface LinphoneOnGlobalStateChangedListener extends LinphoneSimpleListener { - void onGlobalStateChanged(GlobalState state, String message); - } - - public static interface LinphoneOnCallStateChangedListener extends LinphoneSimpleListener { - void onCallStateChanged(LinphoneCall call, State state, String message); - } - - public static interface LinphoneOnAudioChangedListener extends LinphoneSimpleListener { - public enum AudioState {EARPIECE, SPEAKER, BLUETOOTH} - void onAudioStateChanged(AudioState state); - } - - public static interface LinphoneOnMessageReceivedListener extends LinphoneSimpleListener { - void onMessageReceived(LinphoneAddress from, LinphoneChatMessage message, int id); - } - - public static interface LinphoneOnRegistrationStateChangedListener extends LinphoneSimpleListener { - void onRegistrationStateChanged(LinphoneProxyConfig proxy, RegistrationState state, String message); - } - - public static interface ConnectivityChangedListener extends LinphoneSimpleListener { - void onConnectivityChanged(Context context, NetworkInfo eventInfo, ConnectivityManager cm); - } - - public static interface LinphoneOnDTMFReceivedListener extends LinphoneSimpleListener { - void onDTMFReceived(LinphoneCall call, int dtmf); - } - public static interface LinphoneOnNotifyReceivedListener extends LinphoneSimpleListener { - void onNotifyReceived(LinphoneEvent ev,String eventName, LinphoneContent content); - } - public static interface LinphoneOnComposingReceivedListener extends LinphoneSimpleListener { - void onComposingReceived(LinphoneChatRoom room); - } - public static interface LinphoneOnRemoteProvisioningListener extends LinphoneSimpleListener { - void onConfiguringStatus(RemoteProvisioningState state); - } -} diff --git a/src/org/linphone/StatusFragment.java b/src/org/linphone/StatusFragment.java index 27b0ba329..7ef95d0ff 100644 --- a/src/org/linphone/StatusFragment.java +++ b/src/org/linphone/StatusFragment.java @@ -22,7 +22,6 @@ import java.util.List; import java.util.Timer; import java.util.TimerTask; -import org.linphone.LinphoneSimpleListener.LinphoneOnNotifyReceivedListener; import org.linphone.core.LinphoneCall; import org.linphone.core.LinphoneCallParams; import org.linphone.core.LinphoneCallStats; @@ -30,6 +29,7 @@ import org.linphone.core.LinphoneContent; import org.linphone.core.LinphoneCore; import org.linphone.core.LinphoneCore.MediaEncryption; import org.linphone.core.LinphoneCore.RegistrationState; +import org.linphone.core.LinphoneCoreListener.LinphoneNotifyListener; import org.linphone.core.LinphoneEvent; import org.linphone.core.LinphoneProxyConfig; import org.linphone.core.PayloadType; @@ -45,7 +45,6 @@ import android.os.Bundle; import android.os.Handler; import android.support.v4.app.Fragment; import android.view.LayoutInflater; -import android.view.MotionEvent; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; @@ -59,7 +58,7 @@ import android.widget.TextView; /** * @author Sylvain Berfini */ -public class StatusFragment extends Fragment implements LinphoneOnNotifyReceivedListener { +public class StatusFragment extends Fragment implements LinphoneNotifyListener { private Handler mHandler = new Handler(); private Handler refreshHandler = new Handler(); private TextView statusText, exit, voicemailCount; @@ -99,13 +98,12 @@ public class StatusFragment extends Fragment implements LinphoneOnNotifyReceived voicemailCount = (TextView) view.findViewById(R.id.voicemailCount); exit = (TextView) view.findViewById(R.id.exit); - exit.setOnTouchListener(new View.OnTouchListener() { + exit.setOnClickListener(new OnClickListener() { @Override - public boolean onTouch(View v, MotionEvent event) { + public void onClick(View v) { if (LinphoneActivity.isInstanciated()) { LinphoneActivity.instance().exit(); } - return true; } }); if (getResources().getBoolean(R.bool.exit_button_on_dialer)) @@ -327,7 +325,10 @@ public class StatusFragment extends Fragment implements LinphoneOnNotifyReceived @Override public void onResume() { super.onResume(); - LinphoneCore lc = LinphoneManager.getLc(); + LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull(); + if (lc != null) { + lc.addListener(this); + } LinphoneCall call = lc.getCurrentCall(); if (isInCall && (call != null || lc.getConferenceSize() > 1 || lc.getCallsNb() > 0)) { @@ -360,6 +361,11 @@ public class StatusFragment extends Fragment implements LinphoneOnNotifyReceived @Override public void onPause() { + LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull(); + if (lc != null) { + lc.removeListener(this); + } + super.onPause(); if (mCallQualityUpdater != null) { @@ -628,8 +634,7 @@ public class StatusFragment extends Fragment implements LinphoneOnNotifyReceived } @Override - public void onNotifyReceived(LinphoneEvent ev, String eventName, - LinphoneContent content) { + public void notifyReceived(LinphoneCore lc, LinphoneEvent ev, String eventName, LinphoneContent content) { if(!content.getType().equals("application")) return; if(!content.getSubtype().equals("imple-message-summary")) return; diff --git a/src/org/linphone/setup/RemoteProvisioningActivity.java b/src/org/linphone/setup/RemoteProvisioningActivity.java index 38f4b04d8..581fb14c3 100644 --- a/src/org/linphone/setup/RemoteProvisioningActivity.java +++ b/src/org/linphone/setup/RemoteProvisioningActivity.java @@ -25,9 +25,10 @@ import org.linphone.LinphoneLauncherActivity; import org.linphone.LinphoneManager; import org.linphone.LinphonePreferences; import org.linphone.LinphoneService; -import org.linphone.LinphoneSimpleListener.LinphoneOnRemoteProvisioningListener; import org.linphone.R; +import org.linphone.core.LinphoneCore; import org.linphone.core.LinphoneCore.RemoteProvisioningState; +import org.linphone.core.LinphoneCoreListener.LinphoneRemoteProvisioningListener; import org.linphone.mediastream.Log; import android.app.Activity; @@ -44,17 +45,11 @@ import android.widget.Toast; /** * @author Sylvain Berfini */ -public class RemoteProvisioningActivity extends Activity implements LinphoneOnRemoteProvisioningListener { - private static RemoteProvisioningActivity instance = null; - +public class RemoteProvisioningActivity extends Activity implements LinphoneRemoteProvisioningListener { private Handler mHandler = new Handler(); private String configUriParam = null; private ProgressBar spinner; - public static RemoteProvisioningActivity getInstance() { - return instance; - } - @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -65,7 +60,10 @@ public class RemoteProvisioningActivity extends Activity implements LinphoneOnRe @Override protected void onResume() { super.onResume(); - instance = this; + LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull(); + if (lc != null) { + lc.addListener(this); + } LinphonePreferences.instance().setContext(this); checkIntentForConfigUri(getIntent()); @@ -73,12 +71,15 @@ public class RemoteProvisioningActivity extends Activity implements LinphoneOnRe @Override protected void onPause() { - instance = null; + LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull(); + if (lc != null) { + lc.removeListener(this); + } super.onPause(); } @Override - public void onConfiguringStatus(final RemoteProvisioningState state) { + public void configuringStatus(LinphoneCore lc, final RemoteProvisioningState state, String message) { mHandler.post(new Runnable() { @Override public void run() { diff --git a/src/org/linphone/setup/SetupActivity.java b/src/org/linphone/setup/SetupActivity.java index a61d44404..11ce7e034 100644 --- a/src/org/linphone/setup/SetupActivity.java +++ b/src/org/linphone/setup/SetupActivity.java @@ -20,11 +20,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. import org.linphone.LinphoneManager; import org.linphone.LinphonePreferences; import org.linphone.LinphonePreferences.AccountBuilder; -import org.linphone.LinphoneSimpleListener.LinphoneOnRegistrationStateChangedListener; import org.linphone.R; import org.linphone.core.LinphoneAddress.TransportType; import org.linphone.core.LinphoneCore.RegistrationState; +import org.linphone.core.LinphoneCore; import org.linphone.core.LinphoneCoreException; +import org.linphone.core.LinphoneCoreListener; import org.linphone.core.LinphoneProxyConfig; import android.app.Activity; @@ -44,7 +45,7 @@ import android.widget.Toast; /** * @author Sylvain Berfini */ -public class SetupActivity extends FragmentActivity implements OnClickListener { +public class SetupActivity extends FragmentActivity implements OnClickListener, LinphoneCoreListener { private static SetupActivity instance; private RelativeLayout back, next, cancel; private SetupFragmentsEnum currentFragment; @@ -200,32 +201,34 @@ public class SetupActivity extends FragmentActivity implements OnClickListener { } } - - private LinphoneOnRegistrationStateChangedListener registrationListener = new LinphoneOnRegistrationStateChangedListener() { - public void onRegistrationStateChanged(LinphoneProxyConfig proxy, RegistrationState state, String message) { - if (state == RegistrationState.RegistrationOk) { - LinphoneManager.removeListener(registrationListener); - - if (LinphoneManager.getLc().getDefaultProxyConfig() != null) { - mHandler .post(new Runnable () { - public void run() { - launchEchoCancellerCalibration(true); - } - }); - } - } else if (state == RegistrationState.RegistrationFailed) { - LinphoneManager.removeListener(registrationListener); - mHandler.post(new Runnable () { + public void registrationState(LinphoneCore lc, LinphoneProxyConfig cfg, LinphoneCore.RegistrationState state, String smessage) { + if (state == RegistrationState.RegistrationOk) { + lc.removeListener(this); + + if (LinphoneManager.getLc().getDefaultProxyConfig() != null) { + mHandler .post(new Runnable () { public void run() { - Toast.makeText(SetupActivity.this, getString(R.string.first_launch_bad_login_password), Toast.LENGTH_LONG).show(); + launchEchoCancellerCalibration(true); } }); } + } else if (state == RegistrationState.RegistrationFailed) { + lc.removeListener(this); + mHandler.post(new Runnable () { + public void run() { + Toast.makeText(SetupActivity.this, getString(R.string.first_launch_bad_login_password), Toast.LENGTH_LONG).show(); + } + }); } - }; + } + public void checkAccount(String username, String password, String domain) { - LinphoneManager.removeListener(registrationListener); - LinphoneManager.addListener(registrationListener); +// LinphoneManager.removeListener(registrationListener); +// LinphoneManager.addListener(registrationListener); + LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull(); + if (lc != null) { + lc.addListener(this); + } saveCreatedAccount(username, password, domain); } diff --git a/submodules/linphone b/submodules/linphone index 1bb6ebed6..de2e98bd9 160000 --- a/submodules/linphone +++ b/submodules/linphone @@ -1 +1 @@ -Subproject commit 1bb6ebed6cc02fef789f1d1fb091cef50a9858d5 +Subproject commit de2e98bd9635c49acd45d1d5b7d2bb900383e235