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:
@@ -1,2 +0,0 @@
|
||||
#LibGDX native dependancies
|
||||
libgdx.so
|
||||
@@ -1,3 +1,4 @@
|
||||
//FIXME currently an android library while small amounts of android-specific code remain
|
||||
apply plugin: 'com.android.library'
|
||||
|
||||
android {
|
||||
@@ -6,13 +7,6 @@ android {
|
||||
defaultConfig {
|
||||
//noinspection MinSdkTooLow
|
||||
minSdkVersion appAndroidMinSDK
|
||||
|
||||
consumerProguardFiles 'proguard-rules.pro'
|
||||
}
|
||||
sourceSets {
|
||||
main {
|
||||
jniLibs.srcDirs = ['libs']
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,39 +15,7 @@ configurations { natives }
|
||||
dependencies {
|
||||
//TODO migrate this to implementation from api
|
||||
//in order to do this I have to remove 100% of libGDX API access from core
|
||||
api "com.badlogicgames.gdx:gdx:$gdxVersion"
|
||||
api "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
|
||||
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
|
||||
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
|
||||
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
|
||||
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-arm64-v8a"
|
||||
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86_64"
|
||||
implementation "com.badlogicgames.gdx:gdx-controllers:$gdxVersion"
|
||||
implementation "com.badlogicgames.gdx:gdx-controllers-android:$gdxVersion"
|
||||
}
|
||||
|
||||
// called every time gradle gets executed, takes the native dependencies of
|
||||
// the natives configuration, and extracts them to the proper libs/ folders
|
||||
// so they get packed with the APK.
|
||||
task copyAndroidNatives() {
|
||||
file("libs/armeabi/").mkdirs()
|
||||
file("libs/armeabi-v7a/").mkdirs()
|
||||
file("libs/arm64-v8a/").mkdirs()
|
||||
file("libs/x86_64/").mkdirs()
|
||||
file("libs/x86/").mkdirs()
|
||||
|
||||
configurations.natives.files.each { jar ->
|
||||
def outputDir = null
|
||||
if(jar.name.endsWith("natives-arm64-v8a.jar")) outputDir = file("libs/arm64-v8a")
|
||||
if(jar.name.endsWith("natives-armeabi-v7a.jar")) outputDir = file("libs/armeabi-v7a")
|
||||
if(jar.name.endsWith("natives-armeabi.jar")) outputDir = file("libs/armeabi")
|
||||
if(jar.name.endsWith("natives-x86_64.jar")) outputDir = file("libs/x86_64")
|
||||
if(jar.name.endsWith("natives-x86.jar")) outputDir = file("libs/x86")
|
||||
if(outputDir != null) {
|
||||
copy {
|
||||
from zipTree(jar)
|
||||
into outputDir
|
||||
include "*.so"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Vendored
-19
@@ -1,19 +0,0 @@
|
||||
-dontwarn android.support.**
|
||||
-dontwarn com.badlogic.gdx.backends.android.AndroidFragmentApplication
|
||||
-dontwarn com.badlogic.gdx.utils.GdxBuild
|
||||
-dontwarn com.badlogic.gdx.physics.box2d.utils.Box2DBuild
|
||||
-dontwarn com.badlogic.gdx.jnigen.BuildTarget*
|
||||
|
||||
-keepclassmembers class com.badlogic.gdx.backends.android.AndroidInput* {
|
||||
<init>(com.badlogic.gdx.Application, android.content.Context, java.lang.Object, com.badlogic.gdx.backends.android.AndroidApplicationConfiguration);
|
||||
}
|
||||
|
||||
-keepclassmembers class com.badlogic.gdx.physics.box2d.World {
|
||||
boolean contactFilter(long, long);
|
||||
void beginContact(long);
|
||||
void endContact(long);
|
||||
void preSolve(long, long);
|
||||
void postSolve(long, long);
|
||||
boolean reportFixture(long);
|
||||
float reportRayFixture(long, float, float, float, float, float);
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ public class Scene extends Group {
|
||||
}
|
||||
|
||||
protected void onBackPressed() {
|
||||
Gdx.app.exit();
|
||||
Game.instance.finish();
|
||||
}
|
||||
|
||||
protected void onMenuPressed() {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(){
|
||||
|
||||
@@ -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();
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user