Wait for service in main Activity; removed elsewhere
This commit is contained in:
parent
982b383ffd
commit
0f8f0a2a2d
9 changed files with 150 additions and 287 deletions
|
@ -4,5 +4,5 @@
|
|||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent">
|
||||
<ProgressBar android:layout_height="wrap_content" android:layout_width="wrap_content"/>
|
||||
<TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="waiting"/>
|
||||
<TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="@string/wait_dialog_text"/>
|
||||
</LinearLayout>
|
||||
|
|
|
@ -18,7 +18,7 @@ default_proxy=0
|
|||
auto_net_state_mon=0
|
||||
keepalive_period=30000
|
||||
auto_answer_replacing_calls=1
|
||||
media_encryption=none
|
||||
media_encryption=zrtp
|
||||
media_encryption_mandatory=0
|
||||
|
||||
[rtp]
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
<string name="app_name">Linphone</string>
|
||||
<string name="notification_title">Linphone</string>
|
||||
<string name="wait_dialog_text">Starting up</string>
|
||||
<string name="notification_registered">Registered to %s </string>
|
||||
<string name="notification_register_failure">Fails to register to %s</string>
|
||||
<string name="about_text">Linphone %s SIP (rfc 3261) compatible phone under GNU Public License V2\n http://www.linphone.org\n\nInstructions\nhttp://www.linphone.org/m/help\n\n© 2011 Belledonne Communications</string>
|
||||
|
|
|
@ -19,7 +19,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
package org.linphone;
|
||||
|
||||
import org.linphone.LinphoneManager.NewOutgoingCallUiListener;
|
||||
import org.linphone.LinphoneManagerWaitHelper.LinphoneManagerReadyListener;
|
||||
import org.linphone.LinphoneService.LinphoneGuiListener;
|
||||
import org.linphone.core.LinphoneCall;
|
||||
import org.linphone.core.Log;
|
||||
|
@ -30,7 +29,6 @@ import org.linphone.ui.CallButton;
|
|||
import org.linphone.ui.EraseButton;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
|
@ -51,7 +49,7 @@ import android.widget.Toast;
|
|||
* </ul>
|
||||
*
|
||||
*/
|
||||
public class DialerActivity extends Activity implements LinphoneGuiListener, LinphoneManagerReadyListener, NewOutgoingCallUiListener {
|
||||
public class DialerActivity extends Activity implements LinphoneGuiListener, NewOutgoingCallUiListener {
|
||||
|
||||
private TextView mStatus;
|
||||
private Handler mHandler;
|
||||
|
@ -71,7 +69,6 @@ public class DialerActivity extends Activity implements LinphoneGuiListener, Lin
|
|||
return instance;
|
||||
}
|
||||
|
||||
private LinphoneManagerWaitHelper waitHelper;
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
setContentView(R.layout.dialer);
|
||||
|
||||
|
@ -96,8 +93,6 @@ public class DialerActivity extends Activity implements LinphoneGuiListener, Lin
|
|||
|
||||
checkIfOutgoingCallIntentReceived();
|
||||
|
||||
waitHelper = new LinphoneManagerWaitHelper(this, this);
|
||||
waitHelper.doManagerDependentOnCreate();
|
||||
instance = this;
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
@ -153,22 +148,11 @@ public class DialerActivity extends Activity implements LinphoneGuiListener, Lin
|
|||
super.onDestroy();
|
||||
instance=null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected Dialog onCreateDialog(int id) {
|
||||
if (id == LinphoneManagerWaitHelper.DIALOG_ID) {
|
||||
return waitHelper.createWaitDialog();
|
||||
} else {
|
||||
return super.onCreateDialog(id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public void newOutgoingCall(Intent intent) {
|
||||
if (Intent.ACTION_CALL.equalsIgnoreCase(intent.getAction())) {
|
||||
mAddress.setText(intent.getData().getSchemeSpecificPart());
|
||||
|
@ -241,12 +225,9 @@ public class DialerActivity extends Activity implements LinphoneGuiListener, Lin
|
|||
// done in incall view
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateWhenManagerReady() {}
|
||||
|
||||
@Override
|
||||
public void onResumeWhenManagerReady() {
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
// When coming back from a video call, if the phone orientation is different
|
||||
// Android will destroy the previous Dialer and create a new one.
|
||||
// Unfortunately the "call end" status event is received in the meanwhile
|
||||
|
@ -267,11 +248,6 @@ public class DialerActivity extends Activity implements LinphoneGuiListener, Lin
|
|||
};
|
||||
mHandler.postDelayed(r, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
waitHelper.doManagerDependentOnResume();
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,6 @@ import java.util.Collections;
|
|||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import org.linphone.LinphoneManagerWaitHelper.LinphoneManagerReadyListener;
|
||||
import org.linphone.LinphoneSimpleListener.LinphoneOnAudioChangedListener;
|
||||
import org.linphone.LinphoneSimpleListener.LinphoneOnCallEncryptionChangedListener;
|
||||
import org.linphone.LinphoneSimpleListener.LinphoneOnCallStateChangedListener;
|
||||
|
@ -66,7 +65,6 @@ import android.widget.ToggleButton;
|
|||
* @author Guillaume Beraudo
|
||||
*/
|
||||
public class IncallActivity extends ListActivity implements
|
||||
LinphoneManagerReadyListener,
|
||||
LinphoneOnAudioChangedListener,
|
||||
LinphoneOnCallStateChangedListener,
|
||||
LinphoneOnCallEncryptionChangedListener,
|
||||
|
@ -110,7 +108,6 @@ public class IncallActivity extends ListActivity implements
|
|||
lc().leaveConference();
|
||||
}
|
||||
|
||||
private LinphoneManagerWaitHelper waitHelper;
|
||||
private ToggleButton mMuteMicButton;
|
||||
private ToggleButton mSpeakerButton;
|
||||
private int multipleCallsLimit;
|
||||
|
@ -142,40 +139,14 @@ public class IncallActivity extends ListActivity implements
|
|||
mSpeakerButton = (ToggleButton) findViewById(R.id.toggleSpeaker);
|
||||
mSpeakerButton.setOnClickListener(this);
|
||||
|
||||
waitHelper = new LinphoneManagerWaitHelper(this, this);
|
||||
waitHelper.doManagerDependentOnCreate();
|
||||
|
||||
// workaroundStatusBarBug();
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateWhenManagerReady() {
|
||||
List<LinphoneCall> calls = getInitialCalls();
|
||||
setListAdapter(new CalleeListAdapter(calls));
|
||||
|
||||
findViewById(R.id.incallHang).setOnClickListener(this);
|
||||
multipleCallsLimit = lc().getMaxCalls();
|
||||
}
|
||||
@Override
|
||||
public void onResumeWhenManagerReady() {
|
||||
registerLinphoneListener(true);
|
||||
updateCalleeImage();
|
||||
updateConfState();
|
||||
updateSimpleControlButtons();
|
||||
updateSoundLock();
|
||||
updateDtmfButton();
|
||||
CalleeListAdapter adapter = (CalleeListAdapter) getListAdapter();
|
||||
if (adapter.linphoneCalls.size() != lc().getCallsNb()) {
|
||||
adapter.linphoneCalls.clear();
|
||||
adapter.linphoneCalls.addAll(getInitialCalls());
|
||||
}
|
||||
recreateActivity(adapter);
|
||||
LinphoneManager.startProximitySensorForActivity(this);
|
||||
mSpeakerButton.setChecked(LinphoneManager.getInstance().isSpeakerOn());
|
||||
mMuteMicButton.setChecked(LinphoneManager.getLc().isMicMuted());
|
||||
|
||||
updateAddCallButton();
|
||||
// workaroundStatusBarBug();
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
private void updateSoundLock() {
|
||||
|
@ -216,7 +187,23 @@ public class IncallActivity extends ListActivity implements
|
|||
@Override
|
||||
protected void onResume() {
|
||||
active=true;
|
||||
waitHelper.doManagerDependentOnResume();
|
||||
registerLinphoneListener(true);
|
||||
updateCalleeImage();
|
||||
updateConfState();
|
||||
updateSimpleControlButtons();
|
||||
updateSoundLock();
|
||||
updateDtmfButton();
|
||||
CalleeListAdapter adapter = (CalleeListAdapter) getListAdapter();
|
||||
if (adapter.linphoneCalls.size() != lc().getCallsNb()) {
|
||||
adapter.linphoneCalls.clear();
|
||||
adapter.linphoneCalls.addAll(getInitialCalls());
|
||||
}
|
||||
recreateActivity(adapter);
|
||||
LinphoneManager.startProximitySensorForActivity(this);
|
||||
mSpeakerButton.setChecked(LinphoneManager.getInstance().isSpeakerOn());
|
||||
mMuteMicButton.setChecked(LinphoneManager.getLc().isMicMuted());
|
||||
|
||||
updateAddCallButton();
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
|
@ -250,10 +237,6 @@ public class IncallActivity extends ListActivity implements
|
|||
}
|
||||
@Override
|
||||
protected Dialog onCreateDialog(final int id) {
|
||||
if (id == LinphoneManagerWaitHelper.DIALOG_ID) {
|
||||
return waitHelper.createWaitDialog();
|
||||
}
|
||||
|
||||
switch (id) {
|
||||
case numpad_dialog_id:
|
||||
Numpad numpad = new Numpad(this, true);
|
||||
|
|
|
@ -20,7 +20,6 @@ package org.linphone;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.linphone.LinphoneManagerWaitHelper.LinphoneManagerReadyListener;
|
||||
import org.linphone.LinphoneSimpleListener.LinphoneOnCallStateChangedListener;
|
||||
import org.linphone.core.LinphoneAddress;
|
||||
import org.linphone.core.LinphoneCall;
|
||||
|
@ -45,13 +44,12 @@ import android.widget.Toast;
|
|||
*
|
||||
* @author Guillaume Beraudo
|
||||
*/
|
||||
public class IncomingCallActivity extends Activity implements LinphoneManagerReadyListener, LinphoneOnCallStateChangedListener, OnTriggerListener {
|
||||
public class IncomingCallActivity extends Activity implements LinphoneOnCallStateChangedListener, OnTriggerListener {
|
||||
|
||||
private TextView mNameView;
|
||||
private TextView mNumberView;
|
||||
private ImageView mPictureView;
|
||||
private LinphoneCall mCall;
|
||||
private LinphoneManagerWaitHelper mHelper;
|
||||
private SlidingTab mIncomingCallWidget;
|
||||
|
||||
@Override
|
||||
|
@ -79,15 +77,12 @@ public class IncomingCallActivity extends Activity implements LinphoneManagerRea
|
|||
mIncomingCallWidget.setOnTriggerListener(this);
|
||||
|
||||
|
||||
mHelper = new LinphoneManagerWaitHelper(this, this);
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateWhenManagerReady() {}
|
||||
|
||||
@Override
|
||||
public void onResumeWhenManagerReady() {
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
LinphoneManager.addListener(this);
|
||||
// Only one call ringing at a time is allowed
|
||||
List<LinphoneCall> calls = LinphoneUtils.getLinphoneCalls(LinphoneManager.getLc());
|
||||
|
@ -115,12 +110,6 @@ public class IncomingCallActivity extends Activity implements LinphoneManagerRea
|
|||
mNumberView.setText(address.getUserName());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
mHelper.doManagerDependentOnResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
|
|
|
@ -22,7 +22,6 @@ package org.linphone;
|
|||
import static android.content.Intent.ACTION_MAIN;
|
||||
|
||||
import org.linphone.LinphoneManager.EcCalibrationListener;
|
||||
import org.linphone.LinphoneManagerWaitHelper.LinphoneManagerReadyListener;
|
||||
import org.linphone.LinphoneSimpleListener.LinphoneOnCallStateChangedListener;
|
||||
import org.linphone.core.CallDirection;
|
||||
import org.linphone.core.LinphoneCall;
|
||||
|
@ -57,6 +56,7 @@ import android.text.Html;
|
|||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.TabWidget;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
@ -66,7 +66,6 @@ public class LinphoneActivity extends TabActivity implements
|
|||
SensorEventListener
|
||||
, ContactPicked
|
||||
, LinphoneOnCallStateChangedListener
|
||||
, LinphoneManagerReadyListener
|
||||
{
|
||||
public static final String DIALER_TAB = "dialer";
|
||||
public static final String PREF_FIRST_LAUNCH = "pref_first_launch";
|
||||
|
@ -83,16 +82,17 @@ public class LinphoneActivity extends TabActivity implements
|
|||
private SensorManager mSensorManager;
|
||||
private Sensor mAccelerometer;
|
||||
private int previousRotation = -1;
|
||||
|
||||
|
||||
private Handler mHandler = new Handler();
|
||||
|
||||
|
||||
|
||||
private static final int waitDialogId = 1;
|
||||
private ServiceWaitThread thread;
|
||||
|
||||
// Customization
|
||||
private static boolean useFirstLoginActivity;
|
||||
private static boolean useMenuSettings;
|
||||
private static boolean useMenuAbout;
|
||||
private boolean checkAccount;
|
||||
private LinphoneManagerWaitHelper waitHelper;
|
||||
|
||||
static final boolean isInstanciated() {
|
||||
return instance != null;
|
||||
|
@ -106,8 +106,9 @@ public class LinphoneActivity extends TabActivity implements
|
|||
|
||||
@Override
|
||||
protected Dialog onCreateDialog(final int id) {
|
||||
if (id == LinphoneManagerWaitHelper.DIALOG_ID) {
|
||||
return waitHelper.createWaitDialog();
|
||||
if (id == waitDialogId) {
|
||||
View v = getLayoutInflater().inflate((R.layout.wait_service_dialog), null);
|
||||
return new AlertDialog.Builder(this).setView(v).setCancelable(false).create();
|
||||
}
|
||||
return super.onCreateDialog(id);
|
||||
}
|
||||
|
@ -123,36 +124,19 @@ public class LinphoneActivity extends TabActivity implements
|
|||
useMenuAbout = getResources().getBoolean(R.bool.useMenuAbout);
|
||||
checkAccount = !useFirstLoginActivity;
|
||||
|
||||
// start linphone as background
|
||||
startService(new Intent(ACTION_MAIN).setClass(this, LinphoneService.class));
|
||||
|
||||
|
||||
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
|
||||
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
|
||||
if (!useFirstLoginActivity || pref.getBoolean(getString(R.string.first_launch_suceeded_once_key), false)) {
|
||||
fillTabHost();
|
||||
} else {
|
||||
startActivityForResult(new Intent().setClass(this, FirstLoginActivity.class), FIRST_LOGIN_ACTIVITY);
|
||||
}
|
||||
|
||||
if (checkAccount && !useFirstLoginActivity) {
|
||||
if (pref.getBoolean(PREF_FIRST_LAUNCH, true)) {
|
||||
onFirstLaunch();
|
||||
} else if (!pref.getBoolean(PREF_CHECK_CONFIG, false)
|
||||
&& !checkDefined(pref, R.string.pref_username_key, R.string.pref_domain_key)) {
|
||||
onBadSettings(pref);
|
||||
} else {
|
||||
checkAccount = false;
|
||||
}
|
||||
}
|
||||
|
||||
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
|
||||
mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK|PowerManager.ON_AFTER_RELEASE,Log.TAG+"#"+getClass().getName());
|
||||
|
||||
LinphoneManager.addListener(this);
|
||||
waitHelper = new LinphoneManagerWaitHelper(this, this);
|
||||
waitHelper.doManagerDependentOnCreate();
|
||||
if (LinphoneService.isReady()) {
|
||||
onCreateWhenServiceReady();
|
||||
} else {
|
||||
if (thread != null) {
|
||||
throw new RuntimeException("already waiting for Manager");
|
||||
}
|
||||
// start linphone as background
|
||||
startService(new Intent(ACTION_MAIN).setClass(this, LinphoneService.class));
|
||||
startWaitingThreadIfNotRunning();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -259,9 +243,9 @@ public class LinphoneActivity extends TabActivity implements
|
|||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
doResumeWhenServiceReady = false;
|
||||
if (isFinishing()) {
|
||||
//restore audio settings
|
||||
boolean isUserRequest = false;
|
||||
LinphoneManager.removeListener(this);
|
||||
LinphoneManager.stopProximitySensorForActivity(this);
|
||||
instance = null;
|
||||
|
@ -273,7 +257,6 @@ public class LinphoneActivity extends TabActivity implements
|
|||
// Inflate the currently selected menu XML resource.
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
inflater.inflate(R.menu.linphone_activity_menu, menu);
|
||||
|
||||
menu.findItem(R.id.menu_settings).setVisible(useMenuSettings);
|
||||
menu.findItem(R.id.menu_about).setVisible(useMenuAbout);
|
||||
return true;
|
||||
|
@ -563,9 +546,6 @@ public class LinphoneActivity extends TabActivity implements
|
|||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateWhenManagerReady() {}
|
||||
|
||||
private void enterIncallMode() {
|
||||
LinphoneManager.startProximitySensorForActivity(this);
|
||||
if (!mWakeLock.isHeld()) mWakeLock.acquire();
|
||||
|
@ -587,7 +567,44 @@ public class LinphoneActivity extends TabActivity implements
|
|||
|
||||
|
||||
@Override
|
||||
public void onResumeWhenManagerReady() {
|
||||
protected void onDestroy() {
|
||||
if (mWakeLock.isHeld()) mWakeLock.release();
|
||||
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
if (LinphoneService.isReady()) {
|
||||
onResumeWhenServiceReady();
|
||||
doResumeWhenServiceReady=false;
|
||||
} else {
|
||||
doResumeWhenServiceReady = true;
|
||||
startWaitingThreadIfNotRunning();
|
||||
}
|
||||
}
|
||||
|
||||
private void startWaitingThreadIfNotRunning() {
|
||||
if (thread == null) {
|
||||
thread = new ServiceWaitThread();
|
||||
thread.start();
|
||||
|
||||
// Delay to avoid flicker
|
||||
mHandler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!LinphoneService.isReady()) {
|
||||
showDialog(waitDialogId);
|
||||
}
|
||||
}
|
||||
}, 2000);
|
||||
}
|
||||
}
|
||||
|
||||
private void onResumeWhenServiceReady() {
|
||||
LinphoneCall pendingCall = LinphoneManager.getInstance().getPendingIncomingCall();
|
||||
if (pendingCall != null) {
|
||||
LinphoneActivity.instance().startIncomingCallActivity(pendingCall);
|
||||
|
@ -600,19 +617,71 @@ public class LinphoneActivity extends TabActivity implements
|
|||
// removing is done directly in LinphoneActivity.onPause()
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
if (mWakeLock.isHeld()) mWakeLock.release();
|
||||
|
||||
super.onDestroy();
|
||||
|
||||
|
||||
private synchronized void onCreateWhenServiceReady() {
|
||||
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
|
||||
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
|
||||
if (!useFirstLoginActivity || pref.getBoolean(getString(R.string.first_launch_suceeded_once_key), false)) {
|
||||
fillTabHost();
|
||||
} else {
|
||||
startActivityForResult(new Intent().setClass(this, FirstLoginActivity.class), FIRST_LOGIN_ACTIVITY);
|
||||
}
|
||||
|
||||
if (checkAccount && !useFirstLoginActivity) {
|
||||
if (pref.getBoolean(PREF_FIRST_LAUNCH, true)) {
|
||||
onFirstLaunch();
|
||||
} else if (!pref.getBoolean(PREF_CHECK_CONFIG, false)
|
||||
&& !checkDefined(pref, R.string.pref_username_key, R.string.pref_domain_key)) {
|
||||
onBadSettings(pref);
|
||||
} else {
|
||||
checkAccount = false;
|
||||
}
|
||||
}
|
||||
|
||||
LinphoneManager.addListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
waitHelper.doManagerDependentOnResume();
|
||||
super.onResume();
|
||||
|
||||
private boolean doResumeWhenServiceReady;
|
||||
|
||||
private class ServiceWaitThread extends Thread {
|
||||
public void run() {
|
||||
while (!LinphoneService.isReady()) {
|
||||
try {
|
||||
sleep(30);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException("waiting thread sleep() has been interrupted");
|
||||
}
|
||||
}
|
||||
|
||||
mHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
dismissDialog(waitDialogId);
|
||||
} catch (Throwable e) {
|
||||
// Discarding exception which may be thrown if the dialog wasn't showing.
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
mHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
onCreateWhenServiceReady();
|
||||
if (doResumeWhenServiceReady) {
|
||||
onResumeWhenServiceReady();
|
||||
}
|
||||
}
|
||||
});
|
||||
thread = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
interface ContactPicked {
|
||||
|
|
|
@ -1,154 +0,0 @@
|
|||
/*
|
||||
LinphoneManagerWaitActivity.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.Log;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.os.Handler;
|
||||
import android.view.View;
|
||||
|
||||
/**
|
||||
* Activity requiring access to LinphoneManager should use this helper class.
|
||||
*
|
||||
* @author Guillaume Beraudo
|
||||
*
|
||||
*/
|
||||
public final class LinphoneManagerWaitHelper {
|
||||
|
||||
public static final int DIALOG_ID = 314159265;
|
||||
private Handler mHandler = new Handler();
|
||||
private LinphoneManagerReadyListener listener;
|
||||
private Activity activity;
|
||||
private boolean dialogIsShowing;
|
||||
private boolean notifyOnCreate;
|
||||
private boolean notifyOnResume;
|
||||
static boolean disabled;
|
||||
|
||||
public LinphoneManagerWaitHelper(Activity activity, LinphoneManagerReadyListener listener) {
|
||||
this.listener = listener;
|
||||
this.activity = activity;
|
||||
}
|
||||
|
||||
private ServiceWaitThread thread;
|
||||
|
||||
public Dialog createWaitDialog() {
|
||||
View v = activity.getLayoutInflater().inflate((R.layout.wait_service_dialog), null);
|
||||
return new AlertDialog.Builder(activity).setView(v).setCancelable(false).create();
|
||||
}
|
||||
|
||||
|
||||
public synchronized void doManagerDependentOnCreate() {
|
||||
if (disabled || LinphoneService.isReady()) {
|
||||
listener.onCreateWhenManagerReady();
|
||||
return;
|
||||
}
|
||||
if (thread != null) {
|
||||
throw new RuntimeException("already waiting for Manager");
|
||||
}
|
||||
|
||||
notifyOnCreate = true;
|
||||
|
||||
thread = new ServiceWaitThread();
|
||||
thread.start();
|
||||
|
||||
if (!dialogIsShowing) {
|
||||
activity.showDialog(LinphoneManagerWaitHelper.DIALOG_ID);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void doManagerDependentOnResume() {
|
||||
if (disabled || LinphoneService.isReady()) {
|
||||
listener.onResumeWhenManagerReady();
|
||||
return;
|
||||
}
|
||||
notifyOnResume = true;
|
||||
if (thread == null) {
|
||||
thread = new ServiceWaitThread();
|
||||
thread.start();
|
||||
}
|
||||
if (!dialogIsShowing) {
|
||||
activity.showDialog(LinphoneManagerWaitHelper.DIALOG_ID);
|
||||
}
|
||||
}
|
||||
|
||||
private void dismissDialogFromThread(final int id) {
|
||||
mHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
activity.dismissDialog(id);
|
||||
} catch (Throwable e) {
|
||||
// Discarding exception which may be thrown if the dialog wasn't showing.
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private class ServiceWaitThread extends Thread {
|
||||
private void onCreateWhenManagerReady() {
|
||||
mHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
listener.onCreateWhenManagerReady();
|
||||
}
|
||||
});
|
||||
}
|
||||
private void onResumeWhenManagerReady() {
|
||||
mHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
listener.onResumeWhenManagerReady();
|
||||
}
|
||||
});
|
||||
}
|
||||
@Override
|
||||
public void run() {
|
||||
while (!LinphoneService.isReady()) {
|
||||
try {
|
||||
sleep(30);
|
||||
} catch (InterruptedException e) {
|
||||
Log.e("waiting thread sleep() has been interrupted, exiting as requested");
|
||||
dismissDialogFromThread(DIALOG_ID); // FIXME, may not be the best thing to do
|
||||
thread = null;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (notifyOnCreate) {
|
||||
onCreateWhenManagerReady();
|
||||
notifyOnCreate=false;
|
||||
}
|
||||
if (notifyOnResume) {
|
||||
onResumeWhenManagerReady();
|
||||
notifyOnResume=false;
|
||||
}
|
||||
thread = null;
|
||||
dismissDialogFromThread(DIALOG_ID);
|
||||
super.run();
|
||||
}
|
||||
}
|
||||
|
||||
public interface LinphoneManagerReadyListener {
|
||||
void onCreateWhenManagerReady();
|
||||
void onResumeWhenManagerReady();
|
||||
}
|
||||
|
||||
}
|
|
@ -94,7 +94,6 @@ public class TestConferenceActivity extends IncallActivity {
|
|||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
LinphoneManagerWaitHelper.disabled=true;
|
||||
//if (!serviceStarted) startService(new Intent(ACTION_MAIN).setClass(this, LinphoneService.class));
|
||||
|
||||
findViewById(R.id.toggleMuteMic).setOnClickListener(null);
|
||||
|
|
Loading…
Reference in a new issue