1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-28 02:30:05 +00:00

Android: made sure that when the screensaver is disabled, Android-M devices don't lower the app priority

This commit is contained in:
jules 2015-11-02 16:10:49 +00:00
parent 3aa3ebff91
commit ddcd78eae8
2 changed files with 68 additions and 2 deletions

View file

@ -143,6 +143,7 @@ public class JuceDemo extends Activity
//==============================================================================
private ViewHolder viewHolder;
private boolean isScreenSaverEnabled;
private java.util.Timer keepAliveTimer;
public final ComponentPeerView createNewView (boolean opaque, long host)
{
@ -230,14 +231,39 @@ public class JuceDemo extends Activity
if (isScreenSaverEnabled != enabled)
{
isScreenSaverEnabled = enabled;
if (keepAliveTimer != null)
{
keepAliveTimer->cancel();
keepAliveTimer = null;
}
if (enabled)
{
getWindow().clearFlags (WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
else
{
getWindow().addFlags (WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
// If no user input is received after about 3 seconds, the OS will lower the
// task's priority, so this timer forces it to be kept active.
keepAliveTimer = new java.util.Timer();
keepAliveTimer.scheduleAtFixedRate (new TimerTask()
{
@Override
public void run()
{
android.app.Instrumentation instrumentation = new android.app.Instrumentation();
instrumentation.sendKeyDownUpSync (KeyEvent.KEYCODE_BREAK);
}
}, 2000, 2000);
}
}
}
public final boolean getScreenSaver ()
public final boolean getScreenSaver()
{
return isScreenSaverEnabled;
}