Use a common cleanup function and stop input capturing after closing the connection to allow captured devices to accept the "Connection Failed" dialog

This commit is contained in:
Cameron Gutman 2014-09-27 19:32:10 -07:00
parent 6677949614
commit 13b80eda8a

View File

@ -286,7 +286,7 @@ public class Game extends Activity implements SurfaceHolder.Callback,
Dialog.closeDialogs();
displayedFailureDialog = true;
conn.stop();
stopConnection();
int averageEndToEndLat = decoderRenderer.getAverageEndToEndLatency();
int averageDecoderLat = decoderRenderer.getAverageDecoderLatency();
@ -305,10 +305,6 @@ public class Game extends Activity implements SurfaceHolder.Callback,
Toast.makeText(this, message, Toast.LENGTH_LONG).show();
}
if (evdevWatcher != null) {
evdevWatcher.shutdown();
}
finish();
}
@ -573,6 +569,19 @@ public class Game extends Activity implements SurfaceHolder.Callback,
public void stageComplete(Stage stage) {
}
private void stopConnection() {
if (connecting || connected) {
conn.stop();
connecting = connected = false;
}
// Close the Evdev watcher to allow use of captured input devices
if (evdevWatcher != null) {
evdevWatcher.shutdown();
evdevWatcher = null;
}
}
@Override
public void stageFailed(Stage stage) {
if (spinner != null) {
@ -583,8 +592,7 @@ public class Game extends Activity implements SurfaceHolder.Callback,
if (!displayedFailureDialog) {
displayedFailureDialog = true;
Dialog.displayDialog(this, "Connection Error", "Starting "+stage.getName()+" failed", true);
conn.stop();
connecting = false;
stopConnection();
}
}
@ -593,9 +601,9 @@ public class Game extends Activity implements SurfaceHolder.Callback,
if (!displayedFailureDialog) {
displayedFailureDialog = true;
e.printStackTrace();
Dialog.displayDialog(this, "Connection Terminated", "The connection failed unexpectedly", true);
conn.stop();
connected = false;
stopConnection();
}
}
@ -657,8 +665,7 @@ public class Game extends Activity implements SurfaceHolder.Callback,
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
if (connected) {
conn.stop();
connected = false;
stopConnection();
}
}