Commit 147cf600 authored by Michael Kamensky's avatar Michael Kamensky

Merge branch 'master' into 'master'

Fix FLAG_KEEP_SCREEN_ON

See merge request !2132
parents e529765c 72079ad6
......@@ -7,8 +7,7 @@
<uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <!-- This one needs Android Runtime Permission for Android 6+ -->
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
......
......@@ -17,13 +17,10 @@ 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;
import com.badlogic.gdx.backends.android.AndroidApplication;
import forge.FThreads;
import forge.Forge;
import forge.interfaces.IDeviceAdapter;
import forge.model.FModel;
......@@ -37,7 +34,6 @@ import java.io.OutputStream;
import java.util.concurrent.Callable;
public class Main extends AndroidApplication {
public int time = -2;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -239,17 +235,16 @@ 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
// Setting getWindow() Flags needs to run on UI thread.
// Should fix android.view.ViewRoot$CalledFromWrongThreadException:
// Only the original thread that created a view hierarchy can touch its views.
runOnUiThread(new Runnable() {
@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);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment