v0.7.4b: fixed additional rare system UI issues

This commit is contained in:
Evan Debenham 2019-08-05 14:44:31 -04:00
parent c93bc9784b
commit a3e04de98c
5 changed files with 34 additions and 12 deletions

View File

@ -21,21 +21,29 @@
package com.watabou.utils; package com.watabou.utils;
import com.badlogic.gdx.Application;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Preferences; import com.badlogic.gdx.Preferences;
public class GameSettings { 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 prefs;
private static Preferences get() { private static Preferences get() {
if (prefs == null) { if (prefs == null) {
//TODO might want to rename this file. this is the auto-generated name for android atm prefs = Gdx.app.getPreferences(PREFS_FILE);
prefs = Gdx.app.getPreferences("ShatteredPixelDungeon");
} }
return prefs; 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 ){ public static boolean contains( String key ){
return get().contains( key ); return get().contains( key );
} }

View File

@ -32,6 +32,7 @@ import android.telephony.TelephonyManager;
import com.badlogic.gdx.backends.android.AndroidApplication; import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration; import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
import com.shatteredpixel.shatteredpixeldungeon.SPDSettings;
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon; import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
import com.watabou.noosa.Game; import com.watabou.noosa.Game;
import com.watabou.noosa.audio.Music; import com.watabou.noosa.audio.Music;
@ -60,9 +61,13 @@ public class AndroidLauncher extends AndroidApplication {
Game.versionCode = 0; 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. //set desired orientation (if it exists) before initializing the app.
if (getPreferences("ShatteredPixelDungeon").contains("landscape")) { if (SPDSettings.landscapeFromSettings() != null) {
if (getPreferences("ShatteredPixelDungeon").getBoolean("landscape")){ if (SPDSettings.landscapeFromSettings()){
instance.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); instance.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
} else { } else {
instance.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT); instance.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
@ -83,6 +88,8 @@ public class AndroidLauncher extends AndroidApplication {
support = new AndroidPlatformSupport(); support = new AndroidPlatformSupport();
support.updateSystemUI();
initialize(new ShatteredPixelDungeon(support), config); initialize(new ShatteredPixelDungeon(support), config);
view = (GLSurfaceView)graphics.getView(); view = (GLSurfaceView)graphics.getView();
@ -115,4 +122,10 @@ public class AndroidLauncher extends AndroidApplication {
super.onWindowFocusChanged(hasFocus); super.onWindowFocusChanged(hasFocus);
support.updateSystemUI(); support.updateSystemUI();
} }
@Override
public void onMultiWindowModeChanged(boolean isInMultiWindowMode) {
super.onMultiWindowModeChanged(isInMultiWindowMode);
support.updateSystemUI();
}
} }

View File

@ -115,7 +115,7 @@ public class AndroidPlatformSupport extends PlatformSupport {
WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); 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()) { if (SPDSettings.fullscreen()) {
AndroidLauncher.instance.getWindow().getDecorView().setSystemUiVisibility( AndroidLauncher.instance.getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION

View File

@ -76,6 +76,14 @@ public class SPDSettings extends GameSettings {
return getBoolean(KEY_LANDSCAPE, Game.dispWidth > Game.dispHeight); 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 ){ public static void powerSaver( boolean value ){
put( KEY_POWER_SAVER, value ); put( KEY_POWER_SAVER, value );
((ShatteredPixelDungeon)ShatteredPixelDungeon.instance).updateDisplaySize(); ((ShatteredPixelDungeon)ShatteredPixelDungeon.instance).updateDisplaySize();

View File

@ -104,7 +104,6 @@ public class ShatteredPixelDungeon extends Game {
super.create(); super.create();
updateSystemUI(); updateSystemUI();
SPDSettings.landscape ( SPDSettings.landscape() );
Music.INSTANCE.enable( SPDSettings.music() ); Music.INSTANCE.enable( SPDSettings.music() );
Music.INSTANCE.volume( SPDSettings.musicVol()/10f ); Music.INSTANCE.volume( SPDSettings.musicVol()/10f );
@ -220,10 +219,4 @@ public class ShatteredPixelDungeon extends Game {
public static void updateSystemUI() { public static void updateSystemUI() {
platform.updateSystemUI(); platform.updateSystemUI();
} }
@Override
public void resume() {
super.resume();
updateSystemUI();
}
} }