From a6852b1b9788898d9697b056e11b48a3b585a690 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Tue, 18 Oct 2016 02:01:21 -0400 Subject: [PATCH] v0.4.3a: game now defaults to landscape on appropriate tablets --- core/src/main/AndroidManifest.xml | 2 +- .../shatteredpixeldungeon/Preferences.java | 4 ++++ .../ShatteredPixelDungeon.java | 21 +++++++++++-------- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/core/src/main/AndroidManifest.xml b/core/src/main/AndroidManifest.xml index 4251296c5..ad07d5c3f 100644 --- a/core/src/main/AndroidManifest.xml +++ b/core/src/main/AndroidManifest.xml @@ -31,7 +31,7 @@ android:label="@string/app_name" android:name=".ShatteredPixelDungeon" android:configChanges="keyboardHidden|orientation|screenSize" - android:screenOrientation="sensorPortrait"> + android:screenOrientation="nosensor"> diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Preferences.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Preferences.java index 33d38114a..73f803a59 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Preferences.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Preferences.java @@ -58,6 +58,10 @@ enum Preferences { return prefs; } + boolean contains( String key ){ + return get().contains( key ); + } + int getInt( String key, int defValue ) { return getInt(key, defValue, Integer.MIN_VALUE, Integer.MAX_VALUE); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ShatteredPixelDungeon.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ShatteredPixelDungeon.java index a315f5790..df78f0d75 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ShatteredPixelDungeon.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ShatteredPixelDungeon.java @@ -171,16 +171,19 @@ public class ShatteredPixelDungeon extends Game { super.onCreate(savedInstanceState); updateImmersiveMode(); - - DisplayMetrics metrics = new DisplayMetrics(); - if (immersed() && Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR1) - getWindowManager().getDefaultDisplay().getRealMetrics( metrics ); - else - getWindowManager().getDefaultDisplay().getMetrics( metrics ); - boolean landscape = metrics.widthPixels > metrics.heightPixels; - if (Preferences.INSTANCE.getBoolean( Preferences.KEY_LANDSCAPE, false ) != landscape) { - landscape( !landscape ); + if (Preferences.INSTANCE.contains( Preferences.KEY_LANDSCAPE )){ + landscape ( Preferences.INSTANCE.getBoolean( Preferences.KEY_LANDSCAPE, false)); + + } else { + DisplayMetrics metrics = new DisplayMetrics(); + if (immersed() && Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR1) + getWindowManager().getDefaultDisplay().getRealMetrics( metrics ); + else + getWindowManager().getDefaultDisplay().getMetrics( metrics ); + boolean landscape = metrics.widthPixels > metrics.heightPixels; + + landscape( landscape ); } Music.INSTANCE.enable( music() );