From 380faca85d155cc5519ffff2bac2b5c7270bcbcb Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Thu, 13 Aug 2020 17:09:13 -0400 Subject: [PATCH] v0.8.2a: removed some redundant work in onCreate --- .../android/AndroidGame.java | 61 +++++++++++-------- .../shatteredpixeldungeon/SPDAction.java | 4 ++ 2 files changed, 38 insertions(+), 27 deletions(-) diff --git a/android/src/main/java/com/shatteredpixel/shatteredpixeldungeon/android/AndroidGame.java b/android/src/main/java/com/shatteredpixel/shatteredpixeldungeon/android/AndroidGame.java index d711ff6d3..543ec0da7 100644 --- a/android/src/main/java/com/shatteredpixel/shatteredpixeldungeon/android/AndroidGame.java +++ b/android/src/main/java/com/shatteredpixel/shatteredpixeldungeon/android/AndroidGame.java @@ -49,38 +49,45 @@ public class AndroidGame extends AndroidApplication { @Override protected void onCreate (Bundle savedInstanceState) { super.onCreate(savedInstanceState); - - instance = this; - - try { - Game.version = getPackageManager().getPackageInfo( getPackageName(), 0 ).versionName; - } catch (PackageManager.NameNotFoundException e) { - Game.version = "???"; - } - try { - Game.versionCode = getPackageManager().getPackageInfo( getPackageName(), 0 ).versionCode; - } catch (PackageManager.NameNotFoundException e) { - Game.versionCode = 0; - } - if (UpdateImpl.supportsUpdates()){ - Updates.service = UpdateImpl.getUpdateService(); - } - if (NewsImpl.supportsNews()){ - News.service = NewsImpl.getNewsService(); - } + //there are some things we only need to set up on first launch + if (instance == null) { - FileUtils.setDefaultFileProperties( Files.FileType.Local, "" ); - - // grab preferences directly using our instance first - // so that we don't need to rely on Gdx.app, which isn't initialized yet. - // Note that we use a different prefs name on android for legacy purposes, - // this is the default prefs filename given to an android app (.xml is automatically added to it) - SPDSettings.set(instance.getPreferences("ShatteredPixelDungeon")); + instance = this; + + try { + Game.version = getPackageManager().getPackageInfo(getPackageName(), 0).versionName; + } catch (PackageManager.NameNotFoundException e) { + Game.version = "???"; + } + try { + Game.versionCode = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode; + } catch (PackageManager.NameNotFoundException e) { + Game.versionCode = 0; + } + + if (UpdateImpl.supportsUpdates()) { + Updates.service = UpdateImpl.getUpdateService(); + } + if (NewsImpl.supportsNews()) { + News.service = NewsImpl.getNewsService(); + } + + FileUtils.setDefaultFileProperties(Files.FileType.Local, ""); + + // grab preferences directly using our instance first + // so that we don't need to rely on Gdx.app, which isn't initialized yet. + // Note that we use a different prefs name on android for legacy purposes, + // this is the default prefs filename given to an android app (.xml is automatically added to it) + SPDSettings.set(instance.getPreferences("ShatteredPixelDungeon")); + + } else { + instance = this; + } //set desired orientation (if it exists) before initializing the app. if (SPDSettings.landscape() != null) { - AndroidGame.instance.setRequestedOrientation( SPDSettings.landscape() ? + instance.setRequestedOrientation( SPDSettings.landscape() ? ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE : ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT ); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/SPDAction.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/SPDAction.java index f418834cc..d075ea5d0 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/SPDAction.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/SPDAction.java @@ -131,6 +131,10 @@ public class SPDAction extends GameAction { public static void loadBindings(){ + if (!KeyBindings.getAllBindings().isEmpty()){ + return; + } + try { Bundle b = FileUtils.bundleFromFile(BINDINGS_FILE);