mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-11 23:54:18 +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:
parent
3aa3ebff91
commit
ddcd78eae8
2 changed files with 68 additions and 2 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,6 +43,13 @@ import android.text.ClipboardManager;
|
|||
import android.text.InputType;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import java.lang.Runnable;
|
||||
import java.util.List;
|
||||
import java.util.Arrays;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Hashtable;
|
||||
import java.util.TimerTask;
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
import java.net.HttpURLConnection;
|
||||
|
|
@ -143,6 +150,7 @@ public class JuceAppActivity extends Activity
|
|||
//==============================================================================
|
||||
private ViewHolder viewHolder;
|
||||
private boolean isScreenSaverEnabled;
|
||||
private java.util.Timer keepAliveTimer;
|
||||
|
||||
public final ComponentPeerView createNewView (boolean opaque, long host)
|
||||
{
|
||||
|
|
@ -230,14 +238,46 @@ public class JuceAppActivity 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();
|
||||
|
||||
try
|
||||
{
|
||||
instrumentation.sendKeyDownUpSync (KeyEvent.KEYCODE_BREAK);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
}
|
||||
}, 2000, 2000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final boolean getScreenSaver ()
|
||||
public final boolean getScreenSaver()
|
||||
{
|
||||
return isScreenSaverEnabled;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue