Fix NPE in tabhost#onTouchModeChanged on simulator.

This commit is contained in:
Guillaume Beraudo 2011-11-15 17:01:06 +01:00
parent 0f8f0a2a2d
commit cc11c74401

View file

@ -130,12 +130,11 @@ public class LinphoneActivity extends TabActivity implements
if (LinphoneService.isReady()) { if (LinphoneService.isReady()) {
onCreateWhenServiceReady(); onCreateWhenServiceReady();
} else { } else {
if (thread != null) {
throw new RuntimeException("already waiting for Manager");
}
// start linphone as background // start linphone as background
startService(new Intent(ACTION_MAIN).setClass(this, LinphoneService.class)); startService(new Intent(ACTION_MAIN).setClass(this, LinphoneService.class));
startWaitingThreadIfNotRunning(); mDoOnCreateWhenServiceReady = true;
thread = new ServiceWaitThread();
thread.start();
} }
} }
@ -243,7 +242,7 @@ public class LinphoneActivity extends TabActivity implements
@Override @Override
protected void onPause() { protected void onPause() {
super.onPause(); super.onPause();
doResumeWhenServiceReady = false; mDoResumeWhenServiceReady = false;
if (isFinishing()) { if (isFinishing()) {
//restore audio settings //restore audio settings
LinphoneManager.removeListener(this); LinphoneManager.removeListener(this);
@ -574,26 +573,19 @@ public class LinphoneActivity extends TabActivity implements
} }
private boolean mWaitDialogPosted;
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
if (LinphoneService.isReady()) { if (LinphoneService.isReady()) {
onResumeWhenServiceReady(); onResumeWhenServiceReady();
doResumeWhenServiceReady=false;
} else { } else {
doResumeWhenServiceReady = true; if (!mWaitDialogPosted) {
startWaitingThreadIfNotRunning(); mWaitDialogPosted = true;
}
}
private void startWaitingThreadIfNotRunning() {
if (thread == null) {
thread = new ServiceWaitThread();
thread.start();
// Delay to avoid flicker
mHandler.postDelayed(new Runnable() { mHandler.postDelayed(new Runnable() {
// Delay to avoid flicker.
// Call in onResume to make sure the view (especially the tabhost) is initialized.
@Override @Override
public void run() { public void run() {
if (!LinphoneService.isReady()) { if (!LinphoneService.isReady()) {
@ -602,6 +594,12 @@ public class LinphoneActivity extends TabActivity implements
} }
}, 2000); }, 2000);
} }
mDoResumeWhenServiceReady = true;
if (thread == null) {
thread = new ServiceWaitThread();
thread.start();
}
}
} }
private void onResumeWhenServiceReady() { private void onResumeWhenServiceReady() {
@ -620,7 +618,9 @@ public class LinphoneActivity extends TabActivity implements
private synchronized void onCreateWhenServiceReady() { private boolean mDoOnCreateWhenServiceReady;
private void onCreateWhenServiceReady() {
mDoOnCreateWhenServiceReady = false;
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
@ -644,7 +644,7 @@ public class LinphoneActivity extends TabActivity implements
LinphoneManager.addListener(this); LinphoneManager.addListener(this);
} }
private boolean doResumeWhenServiceReady; private boolean mDoResumeWhenServiceReady;
private class ServiceWaitThread extends Thread { private class ServiceWaitThread extends Thread {
public void run() { public void run() {
@ -670,8 +670,10 @@ public class LinphoneActivity extends TabActivity implements
mHandler.post(new Runnable() { mHandler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
if (mDoOnCreateWhenServiceReady) {
onCreateWhenServiceReady(); onCreateWhenServiceReady();
if (doResumeWhenServiceReady) { }
if (mDoResumeWhenServiceReady) {
onResumeWhenServiceReady(); onResumeWhenServiceReady();
} }
} }
@ -679,9 +681,6 @@ public class LinphoneActivity extends TabActivity implements
thread = null; thread = null;
} }
} }
} }
interface ContactPicked { interface ContactPicked {