diff --git a/SPD-classes/src/main/java/com/watabou/utils/GameSettings.java b/SPD-classes/src/main/java/com/watabou/utils/GameSettings.java index 0dfed0458..188e8e827 100644 --- a/SPD-classes/src/main/java/com/watabou/utils/GameSettings.java +++ b/SPD-classes/src/main/java/com/watabou/utils/GameSettings.java @@ -21,21 +21,29 @@ package com.watabou.utils; +import com.badlogic.gdx.Application; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Preferences; public class GameSettings { + //TODO might want to rename this file. this is the auto-generated name for android atm + public static final String PREFS_FILE = "ShatteredPixelDungeon"; + private static Preferences prefs; private static Preferences get() { if (prefs == null) { - //TODO might want to rename this file. this is the auto-generated name for android atm - prefs = Gdx.app.getPreferences("ShatteredPixelDungeon"); + prefs = Gdx.app.getPreferences(PREFS_FILE); } return prefs; } + //allows setting up of preferences without Gdx.app being initialized + public static void setPrefsFromInstance (Application instance){ + prefs = instance.getPreferences(PREFS_FILE); + } + public static boolean contains( String key ){ return get().contains( key ); } diff --git a/android/src/main/java/com/shatteredpixel/shatteredpixeldungeon/android/AndroidLauncher.java b/android/src/main/java/com/shatteredpixel/shatteredpixeldungeon/android/AndroidLauncher.java index a7f22a5c0..7052261fc 100644 --- a/android/src/main/java/com/shatteredpixel/shatteredpixeldungeon/android/AndroidLauncher.java +++ b/android/src/main/java/com/shatteredpixel/shatteredpixeldungeon/android/AndroidLauncher.java @@ -32,6 +32,7 @@ import android.telephony.TelephonyManager; import com.badlogic.gdx.backends.android.AndroidApplication; import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration; +import com.shatteredpixel.shatteredpixeldungeon.SPDSettings; import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon; import com.watabou.noosa.Game; import com.watabou.noosa.audio.Music; @@ -60,9 +61,13 @@ public class AndroidLauncher extends AndroidApplication { Game.versionCode = 0; } + // grab preferences directly using our instance first + // so that we don't need to rely on Gdx.app, which isn't initialized yet. + SPDSettings.setPrefsFromInstance(instance); + //set desired orientation (if it exists) before initializing the app. - if (getPreferences("ShatteredPixelDungeon").contains("landscape")) { - if (getPreferences("ShatteredPixelDungeon").getBoolean("landscape")){ + if (SPDSettings.landscapeFromSettings() != null) { + if (SPDSettings.landscapeFromSettings()){ instance.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); } else { instance.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT); @@ -83,6 +88,8 @@ public class AndroidLauncher extends AndroidApplication { support = new AndroidPlatformSupport(); + support.updateSystemUI(); + initialize(new ShatteredPixelDungeon(support), config); view = (GLSurfaceView)graphics.getView(); @@ -115,4 +122,10 @@ public class AndroidLauncher extends AndroidApplication { super.onWindowFocusChanged(hasFocus); support.updateSystemUI(); } + + @Override + public void onMultiWindowModeChanged(boolean isInMultiWindowMode) { + super.onMultiWindowModeChanged(isInMultiWindowMode); + support.updateSystemUI(); + } } \ No newline at end of file diff --git a/android/src/main/java/com/shatteredpixel/shatteredpixeldungeon/android/AndroidPlatformSupport.java b/android/src/main/java/com/shatteredpixel/shatteredpixeldungeon/android/AndroidPlatformSupport.java index 95c485d80..47c98fdfe 100644 --- a/android/src/main/java/com/shatteredpixel/shatteredpixeldungeon/android/AndroidPlatformSupport.java +++ b/android/src/main/java/com/shatteredpixel/shatteredpixeldungeon/android/AndroidPlatformSupport.java @@ -115,7 +115,7 @@ public class AndroidPlatformSupport extends PlatformSupport { WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); } - if (DeviceCompat.supportsFullScreen()){ + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){ if (SPDSettings.fullscreen()) { AndroidLauncher.instance.getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/SPDSettings.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/SPDSettings.java index 89695ca57..04b41e5d4 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/SPDSettings.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/SPDSettings.java @@ -76,6 +76,14 @@ public class SPDSettings extends GameSettings { return getBoolean(KEY_LANDSCAPE, Game.dispWidth > Game.dispHeight); } + public static Boolean landscapeFromSettings(){ + if (contains(KEY_LANDSCAPE)){ + return getBoolean(KEY_LANDSCAPE, false); + } else { + return null; + } + } + public static void powerSaver( boolean value ){ put( KEY_POWER_SAVER, value ); ((ShatteredPixelDungeon)ShatteredPixelDungeon.instance).updateDisplaySize(); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ShatteredPixelDungeon.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ShatteredPixelDungeon.java index 7fefebcb8..7e232d1db 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ShatteredPixelDungeon.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ShatteredPixelDungeon.java @@ -104,7 +104,6 @@ public class ShatteredPixelDungeon extends Game { super.create(); updateSystemUI(); - SPDSettings.landscape ( SPDSettings.landscape() ); Music.INSTANCE.enable( SPDSettings.music() ); Music.INSTANCE.volume( SPDSettings.musicVol()/10f ); @@ -220,10 +219,4 @@ public class ShatteredPixelDungeon extends Game { public static void updateSystemUI() { platform.updateSystemUI(); } - - @Override - public void resume() { - super.resume(); - updateSystemUI(); - } } \ No newline at end of file