Fixed setting of screen saver state crashing on some version of Android.
Setting Window flags seems to affect Views and must be handled on UI thread.
This commit is contained in:
parent
79035b393a
commit
5f193f0c60
2 changed files with 21 additions and 17 deletions
|
@ -187,13 +187,6 @@ public class SDLActivity extends Activity {
|
|||
return super.dispatchKeyEvent(event);
|
||||
}
|
||||
|
||||
public static void suspendScreenSaver(boolean suspend) {
|
||||
if (suspend)
|
||||
mSingleton.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
else
|
||||
mSingleton.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
}
|
||||
|
||||
/** Called by onPause or surfaceDestroyed. Even if surfaceDestroyed
|
||||
* is the first to be called, mIsSurfaceReady should still be set
|
||||
* to 'true' during the call to onPause (in a usual scenario).
|
||||
|
@ -229,6 +222,7 @@ public class SDLActivity extends Activity {
|
|||
static final int COMMAND_CHANGE_TITLE = 1;
|
||||
static final int COMMAND_UNUSED = 2;
|
||||
static final int COMMAND_TEXTEDIT_HIDE = 3;
|
||||
static final int COMMAND_SET_KEEP_SCREEN_ON = 5;
|
||||
|
||||
protected static final int COMMAND_USER = 0x8000;
|
||||
|
||||
|
@ -273,7 +267,18 @@ public class SDLActivity extends Activity {
|
|||
imm.hideSoftInputFromWindow(mTextEdit.getWindowToken(), 0);
|
||||
}
|
||||
break;
|
||||
|
||||
case COMMAND_SET_KEEP_SCREEN_ON:
|
||||
{
|
||||
Window window = ((Activity) context).getWindow();
|
||||
if (window != null) {
|
||||
if ((msg.obj instanceof Integer) && (((Integer) msg.obj).intValue() != 0)) {
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
} else {
|
||||
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
if ((context instanceof SDLActivity) && !((SDLActivity) context).onUnhandledMessage(msg.arg1, msg.obj)) {
|
||||
Log.e(TAG, "error handling message, command is " + msg.arg1);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue