v0.7.4b: restructured initialization logic into new android module

A lot of cleanup is needed for this, but everything works
This commit is contained in:
Evan Debenham
2019-08-01 15:35:27 -04:00
parent 11efd1d0c3
commit 3e815a3165
202 changed files with 483 additions and 313 deletions

View File

@@ -21,30 +21,24 @@
package com.watabou.noosa;
import android.content.pm.PackageManager.NameNotFoundException;
import android.opengl.GLSurfaceView;
import android.os.Build;
import android.os.Bundle;
import android.os.SystemClock;
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
import com.watabou.glscripts.Script;
import com.watabou.gltextures.TextureCache;
import com.watabou.glwrap.Blending;
import com.watabou.glwrap.Vertexbuffer;
import com.watabou.input.InputHandler;
import com.watabou.input.KeyEvent;
import com.watabou.noosa.audio.Music;
import com.watabou.utils.PlatformSupport;
import com.watabou.utils.SystemTime;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
public class Game extends AndroidApplication implements ApplicationListener {
public class Game implements ApplicationListener {
public static Game instance;
@@ -85,62 +79,27 @@ public class Game extends AndroidApplication implements ApplicationListener {
protected GLSurfaceView view;
//protected SurfaceHolder holder;
protected InputHandler inputHandler;
protected static InputHandler inputHandler;
public Game( Class<? extends Scene> c ) {
super();
protected static PlatformSupport platform;
public Game(Class<? extends Scene> c, PlatformSupport platform) {
sceneClass = c;
}
@Override
protected void onCreate( Bundle savedInstanceState ) {
super.onCreate( savedInstanceState );
instance = this;
//FIXME this should be moved into a separate class, once we start to move to multiplatform
try {
version = getPackageManager().getPackageInfo( getPackageName(), 0 ).versionName;
} catch (NameNotFoundException e) {
version = "???";
}
try {
versionCode = getPackageManager().getPackageInfo( getPackageName(), 0 ).versionCode;
} catch (NameNotFoundException e) {
versionCode = 0;
}
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
config.depth = 0;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
//use rgb888 on more modern devices for better visuals
config.r = config.g = config.b = 8;
} else {
//and rgb565 (default) on older ones for better performance
}
config.useCompass = false;
config.useAccelerometer = false;
//TODO consider the following additional options, might be better than setting manually
//config.hideStatusBar
//config.useImmersiveMode
initialize(this, config);
this.platform = platform;
}
/*@Override
protected void onCreate( Bundle savedInstanceState ) {
super.onCreate( savedInstanceState );
//FIXME shouldn't have a reference to the view here, remove things which access this
view = (GLSurfaceView)graphics.getView();
inputHandler = new InputHandler();
Gdx.input.setInputProcessor(inputHandler);
Gdx.input.setCatchKey(KeyEvent.BACK, true);
Gdx.input.setCatchKey(KeyEvent.MENU, true);
//FIXME this doesn't seem to work quite right. That might not be due to LibGDX though.
Music.setMuteListener();
//so first call to onstart/onresume calls correct logic.
paused = true;
}
//paused = true;
}*/
private boolean paused;
@@ -156,6 +115,11 @@ public class Game extends AndroidApplication implements ApplicationListener {
Blending.useDefault();
inputHandler = new InputHandler();
Gdx.input.setInputProcessor(inputHandler);
Gdx.input.setCatchKey(KeyEvent.BACK, true);
Gdx.input.setCatchKey(KeyEvent.MENU, true);
//refreshes texture and vertex data stored on the gpu
TextureCache.reload();
RenderedText.reloadCache();
@@ -219,6 +183,10 @@ public class Game extends AndroidApplication implements ApplicationListener {
//Sample.INSTANCE.resume();
}
public void finish(){
Gdx.app.exit();
}
@Override
public void dispose() {
destroyGame();
@@ -325,4 +293,5 @@ public class Game extends AndroidApplication implements ApplicationListener {
void beforeCreate();
void afterCreate();
}
}

View File

@@ -73,7 +73,7 @@ public class Scene extends Group {
}
protected void onBackPressed() {
Gdx.app.exit();
Game.instance.finish();
}
protected void onMenuPressed() {

View File

@@ -21,13 +21,7 @@
package com.watabou.noosa.audio;
import android.app.Activity;
import android.os.Build;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import com.badlogic.gdx.Gdx;
import com.watabou.noosa.Game;
public enum Music {
@@ -114,29 +108,4 @@ public enum Music {
return enabled;
}
//FIXME android-specific code, that is also broken by being part of this class.
public static void setMuteListener(){
//versions lower than this require READ_PHONE_STATE permission
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
TelephonyManager mgr =
(TelephonyManager) Game.instance.getSystemService(Activity.TELEPHONY_SERVICE);
mgr.listen(new PhoneStateListener(){
@Override
public void onCallStateChanged(int state, String incomingNumber)
{
if( state == TelephonyManager.CALL_STATE_RINGING ) {
INSTANCE.pause();
} else if( state == TelephonyManager.CALL_STATE_IDLE ) {
if (!Game.instance.isPaused()) {
INSTANCE.resume();
}
}
super.onCallStateChanged(state, incomingNumber);
}
}, PhoneStateListener.LISTEN_CALL_STATE);
}
}
}

View File

@@ -24,6 +24,7 @@ package com.watabou.utils;
import com.badlogic.gdx.Gdx;
import com.watabou.BuildConfig;
//TODO migrate to platformSupport class
public class DeviceCompat {
public static boolean supportsFullScreen(){

View File

@@ -0,0 +1,30 @@
/*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.watabou.utils;
public abstract class PlatformSupport {
public abstract void updateDisplaySize();
public abstract void updateSystemUI();
}