Allow the display to go off if the stream disconnects

This commit is contained in:
Cameron Gutman 2018-06-09 17:48:07 -07:00
parent e0a7ff1880
commit 3a868045d7

View File

@ -146,10 +146,8 @@ public class Game extends Activity implements SurfaceHolder.Callback,
// We don't want a title bar // We don't want a title bar
requestWindowFeature(Window.FEATURE_NO_TITLE); requestWindowFeature(Window.FEATURE_NO_TITLE);
// Full-screen and don't let the display go off // Full-screen
getWindow().addFlags( getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
WindowManager.LayoutParams.FLAG_FULLSCREEN |
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
// If we're going to use immersive mode, we want to have // If we're going to use immersive mode, we want to have
// the entire screen // the entire screen
@ -1169,11 +1167,16 @@ public class Game extends Activity implements SurfaceHolder.Callback,
} }
@Override @Override
public void stageStarting(String stage) { public void stageStarting(final String stage) {
runOnUiThread(new Runnable() {
@Override
public void run() {
if (spinner != null) { if (spinner != null) {
spinner.setMessage(getResources().getString(R.string.conn_starting)+" "+stage); spinner.setMessage(getResources().getString(R.string.conn_starting) + " " + stage);
} }
} }
});
}
@Override @Override
public void stageComplete(String stage) { public void stageComplete(String stage) {
@ -1197,51 +1200,59 @@ public class Game extends Activity implements SurfaceHolder.Callback,
} }
@Override @Override
public void stageFailed(String stage, long errorCode) { public void stageFailed(final String stage, final long errorCode) {
runOnUiThread(new Runnable() {
@Override
public void run() {
if (spinner != null) { if (spinner != null) {
spinner.dismiss(); spinner.dismiss();
spinner = null; spinner = null;
} }
// Enable cursor visibility again
inputCaptureProvider.disableCapture();
if (!displayedFailureDialog) { if (!displayedFailureDialog) {
displayedFailureDialog = true; displayedFailureDialog = true;
LimeLog.severe(stage+" failed: "+errorCode); LimeLog.severe(stage + " failed: " + errorCode);
// If video initialization failed and the surface is still valid, display extra information for the user // If video initialization failed and the surface is still valid, display extra information for the user
if (stage.contains("video") && streamView.getHolder().getSurface().isValid()) { if (stage.contains("video") && streamView.getHolder().getSurface().isValid()) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(Game.this, "Video decoder failed to initialize. Your device may not support the selected resolution.", Toast.LENGTH_LONG).show(); Toast.makeText(Game.this, "Video decoder failed to initialize. Your device may not support the selected resolution.", Toast.LENGTH_LONG).show();
} }
Dialog.displayDialog(Game.this, getResources().getString(R.string.conn_error_title),
getResources().getString(R.string.conn_error_msg) + " " + stage, true);
}
}
}); });
} }
Dialog.displayDialog(this, getResources().getString(R.string.conn_error_title),
getResources().getString(R.string.conn_error_msg)+" "+stage, true);
}
}
@Override @Override
public void connectionTerminated(long errorCode) { public void connectionTerminated(final long errorCode) {
runOnUiThread(new Runnable() {
@Override
public void run() {
// Let the display go to sleep now
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
// Enable cursor visibility again // Enable cursor visibility again
inputCaptureProvider.disableCapture(); inputCaptureProvider.disableCapture();
if (!displayedFailureDialog) { if (!displayedFailureDialog) {
displayedFailureDialog = true; displayedFailureDialog = true;
LimeLog.severe("Connection terminated: "+errorCode); LimeLog.severe("Connection terminated: " + errorCode);
stopConnection(); stopConnection();
Dialog.displayDialog(this, getResources().getString(R.string.conn_terminated_title), Dialog.displayDialog(Game.this, getResources().getString(R.string.conn_terminated_title),
getResources().getString(R.string.conn_terminated_msg), true); getResources().getString(R.string.conn_terminated_msg), true);
} }
} }
});
}
@Override @Override
public void connectionStarted() { public void connectionStarted() {
runOnUiThread(new Runnable() {
@Override
public void run() {
if (spinner != null) { if (spinner != null) {
spinner.dismiss(); spinner.dismiss();
spinner = null; spinner = null;
@ -1250,18 +1261,18 @@ public class Game extends Activity implements SurfaceHolder.Callback,
connected = true; connected = true;
connecting = false; connecting = false;
runOnUiThread(new Runnable() {
@Override
public void run() {
// Hide the mouse cursor now. Doing it before // Hide the mouse cursor now. Doing it before
// dismissing the spinner seems to be undone // dismissing the spinner seems to be undone
// when the spinner gets displayed. // when the spinner gets displayed.
inputCaptureProvider.enableCapture(); inputCaptureProvider.enableCapture();
}
}); // Keep the display on
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
hideSystemUi(1000); hideSystemUi(1000);
} }
});
}
@Override @Override
public void displayMessage(final String message) { public void displayMessage(final String message) {