Permalink
Browse files

Keep screen on while playing

  • Loading branch information...
1 parent efa1c2e commit 17ceb10bb6f151bcab1b8e13a9c5ad7c1645b017 Sam Steele committed Dec 30, 2011
Showing with 11 additions and 0 deletions.
  1. +1 −0 AndroidManifest.xml
  2. +10 −0 src/org/nushackers/Minicraft/MinicraftActivity.java
View
@@ -4,6 +4,7 @@
android:versionCode="1"
android:versionName="1.0" >
+ <uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-sdk android:minSdkVersion="8" />
<application
@@ -3,14 +3,18 @@
import com.mojang.ld22.Game;
import android.app.Activity;
+import android.content.Context;
import android.os.Bundle;
+import android.os.PowerManager;
import android.util.DisplayMetrics;
import android.view.Window;
import android.view.WindowManager;
public class MinicraftActivity extends Activity {
/** Called when the activity is first created. */
Game game;
+ private PowerManager.WakeLock wakelock = null;
+
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -38,12 +42,18 @@ public void onCreate(Bundle savedInstanceState) {
pad.setJoystickListener(game.getInput());
pad.setButton1Listener(game.getInput().atkListener);
pad.setButton2Listener(game.getInput().menuListener);
+
+ PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
+ wakelock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "Minicraft");
+ wakelock.acquire();
game.start();
}
@Override
protected void onPause() {
super.onPause();
game.stop();
+ if(wakelock != null && wakelock.isHeld())
+ wakelock.release();
}
}

0 comments on commit 17ceb10

Please sign in to comment.