mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 10:48:00 +00:00
WIP: Partial fix on preventsleep when downloading resource.
This commit is contained in:
committed by
Anthony Calosa
parent
f077e59745
commit
9d63eac89a
@@ -17,6 +17,8 @@ import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.os.PowerManager;
|
||||
import android.provider.Settings;
|
||||
import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT;
|
||||
import android.view.WindowManager;
|
||||
import android.webkit.MimeTypeMap;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
@@ -35,6 +37,8 @@ import java.io.OutputStream;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
public class Main extends AndroidApplication {
|
||||
public int time = -2;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -235,13 +239,17 @@ public class Main extends AndroidApplication {
|
||||
|
||||
@Override
|
||||
public void preventSystemSleep(final boolean preventSleep) {
|
||||
if (time == -2)
|
||||
time = Settings.System.getInt(getContentResolver(), SCREEN_OFF_TIMEOUT, 0);
|
||||
FThreads.invokeInEdtNowOrLater(new Runnable() { //must set window flags from EDT thread
|
||||
@Override
|
||||
public void run() {
|
||||
if (preventSleep) {
|
||||
Settings.System.putInt(getContentResolver(), SCREEN_OFF_TIMEOUT, Integer.MAX_VALUE);
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
}
|
||||
else {
|
||||
Settings.System.putInt(getContentResolver(), SCREEN_OFF_TIMEOUT, time);
|
||||
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user