mirror of
https://github.com/love2d/love-android.git
synced 2026-08-19 20:20:25 +02:00
fixed #104: loading of multiple .love files
This commit is contained in:
@@ -19,6 +19,7 @@
|
|||||||
android:name="GameActivity"
|
android:name="GameActivity"
|
||||||
android:configChanges="orientation|screenSize"
|
android:configChanges="orientation|screenSize"
|
||||||
android:label="LÖVE for Android"
|
android:label="LÖVE for Android"
|
||||||
|
android:launchMode="singleTop"
|
||||||
android:screenOrientation="landscape" >
|
android:screenOrientation="landscape" >
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|||||||
@@ -75,23 +75,26 @@ const char* getSelectedGameFile()
|
|||||||
{
|
{
|
||||||
static const char *path = NULL;
|
static const char *path = NULL;
|
||||||
|
|
||||||
if (!path) {
|
if (path) {
|
||||||
JNIEnv *env = (JNIEnv*) SDL_AndroidGetJNIEnv();
|
delete path;
|
||||||
jclass activity = env->FindClass("org/love2d/android/GameActivity");
|
path = NULL;
|
||||||
|
|
||||||
jmethodID getGamePath = env->GetStaticMethodID(activity, "getGamePath", "()Ljava/lang/String;");
|
|
||||||
jstring gamePath = (jstring) env->CallStaticObjectMethod(activity, getGamePath);
|
|
||||||
const char *utf = env->GetStringUTFChars(gamePath, 0);
|
|
||||||
if (utf)
|
|
||||||
{
|
|
||||||
path = SDL_strdup(utf);
|
|
||||||
env->ReleaseStringUTFChars(gamePath, utf);
|
|
||||||
}
|
|
||||||
|
|
||||||
env->DeleteLocalRef (gamePath);
|
|
||||||
env->DeleteLocalRef (activity);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JNIEnv *env = (JNIEnv*) SDL_AndroidGetJNIEnv();
|
||||||
|
jclass activity = env->FindClass("org/love2d/android/GameActivity");
|
||||||
|
|
||||||
|
jmethodID getGamePath = env->GetStaticMethodID(activity, "getGamePath", "()Ljava/lang/String;");
|
||||||
|
jstring gamePath = (jstring) env->CallStaticObjectMethod(activity, getGamePath);
|
||||||
|
const char *utf = env->GetStringUTFChars(gamePath, 0);
|
||||||
|
if (utf)
|
||||||
|
{
|
||||||
|
path = SDL_strdup(utf);
|
||||||
|
env->ReleaseStringUTFChars(gamePath, utf);
|
||||||
|
}
|
||||||
|
|
||||||
|
env->DeleteLocalRef (gamePath);
|
||||||
|
env->DeleteLocalRef (activity);
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -99,24 +99,7 @@ public class SDLActivity extends Activity {
|
|||||||
Log.v("SDL", "onCreate():" + mSingleton);
|
Log.v("SDL", "onCreate():" + mSingleton);
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
SDLActivity.initialize();
|
startNative();
|
||||||
// So we can call stuff from static callbacks
|
|
||||||
mSingleton = this;
|
|
||||||
|
|
||||||
// Set up the surface
|
|
||||||
mSurface = new SDLSurface(getApplication());
|
|
||||||
|
|
||||||
if(Build.VERSION.SDK_INT >= 12) {
|
|
||||||
mJoystickHandler = new SDLJoystickHandler_API12();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
mJoystickHandler = new SDLJoystickHandler();
|
|
||||||
}
|
|
||||||
|
|
||||||
mLayout = new AbsoluteLayout(this);
|
|
||||||
mLayout.addView(mSurface);
|
|
||||||
|
|
||||||
setContentView(mLayout);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Events
|
// Events
|
||||||
@@ -153,28 +136,59 @@ public class SDLActivity extends Activity {
|
|||||||
SDLActivity.nativeLowMemory();
|
SDLActivity.nativeLowMemory();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Ends the native thread.
|
||||||
|
*/
|
||||||
|
public void resetNative() {
|
||||||
|
Log.v("SDL", "resetNative()");
|
||||||
|
|
||||||
|
// Send a quit message to the application
|
||||||
|
SDLActivity.mExitCalledFromJava = true;
|
||||||
|
SDLActivity.nativeQuit();
|
||||||
|
|
||||||
|
// Now wait for the SDL thread to quit
|
||||||
|
if (SDLActivity.mSDLThread != null) {
|
||||||
|
try {
|
||||||
|
SDLActivity.mSDLThread.join();
|
||||||
|
} catch(Exception e) {
|
||||||
|
Log.v("SDL", "Problem stopping thread: " + e);
|
||||||
|
}
|
||||||
|
SDLActivity.mSDLThread = null;
|
||||||
|
|
||||||
|
//Log.v("SDL", "Finished waiting for SDL thread");
|
||||||
|
}
|
||||||
|
|
||||||
|
SDLActivity.initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void startNative() {
|
||||||
|
Log.v("SDL", "startNative()");
|
||||||
|
SDLActivity.initialize();
|
||||||
|
// So we can call stuff from static callbacks
|
||||||
|
mSingleton = this;
|
||||||
|
|
||||||
|
// Set up the surface
|
||||||
|
mSurface = new SDLSurface(getApplication());
|
||||||
|
|
||||||
|
if(Build.VERSION.SDK_INT >= 12) {
|
||||||
|
mJoystickHandler = new SDLJoystickHandler_API12();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
mJoystickHandler = new SDLJoystickHandler();
|
||||||
|
}
|
||||||
|
|
||||||
|
mLayout = new AbsoluteLayout(this);
|
||||||
|
mLayout.addView(mSurface);
|
||||||
|
|
||||||
|
setContentView(mLayout);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
Log.v("SDL", "onDestroy()");
|
Log.v("SDL", "onDestroy()");
|
||||||
// Send a quit message to the application
|
|
||||||
SDLActivity.mExitCalledFromJava = true;
|
|
||||||
SDLActivity.nativeQuit();
|
|
||||||
|
|
||||||
// Now wait for the SDL thread to quit
|
resetNative();
|
||||||
if (SDLActivity.mSDLThread != null) {
|
|
||||||
try {
|
|
||||||
SDLActivity.mSDLThread.join();
|
|
||||||
} catch(Exception e) {
|
|
||||||
Log.v("SDL", "Problem stopping thread: " + e);
|
|
||||||
}
|
|
||||||
SDLActivity.mSDLThread = null;
|
|
||||||
|
|
||||||
//Log.v("SDL", "Finished waiting for SDL thread");
|
|
||||||
}
|
|
||||||
|
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
// Reset everything in case the user re opens the app
|
|
||||||
SDLActivity.initialize();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -46,9 +46,26 @@ public class GameActivity extends SDLActivity {
|
|||||||
context = this.getApplicationContext();
|
context = this.getApplicationContext();
|
||||||
vibrator = (Vibrator) this.context.getSystemService(Context.VIBRATOR_SERVICE);
|
vibrator = (Vibrator) this.context.getSystemService(Context.VIBRATOR_SERVICE);
|
||||||
|
|
||||||
Uri game = this.getIntent().getData();
|
handleIntent (this.getIntent());
|
||||||
|
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onNewIntent (Intent intent) {
|
||||||
|
Log.d("GameActivity", "onNewIntent() with " + intent);
|
||||||
|
handleIntent (intent);
|
||||||
|
resetNative();
|
||||||
|
startNative();
|
||||||
|
};
|
||||||
|
|
||||||
|
protected void handleIntent (Intent intent) {
|
||||||
|
Uri game = intent.getData();
|
||||||
if (game != null) {
|
if (game != null) {
|
||||||
if (game.getScheme().equals ("file")) {
|
if (game.getScheme().equals ("file")) {
|
||||||
|
Log.d("GameActivity", "Received intent with path: " + game.getPath());
|
||||||
|
|
||||||
// If we were given the path of a main.lua then use its
|
// If we were given the path of a main.lua then use its
|
||||||
// directory. Otherwise use full path.
|
// directory. Otherwise use full path.
|
||||||
List<String> path_segments = game.getPathSegments();
|
List<String> path_segments = game.getPathSegments();
|
||||||
@@ -60,12 +77,10 @@ public class GameActivity extends SDLActivity {
|
|||||||
} else {
|
} else {
|
||||||
copyGameToCache (game);
|
copyGameToCache (game);
|
||||||
}
|
}
|
||||||
Log.d("GameActivity", "Opening game from: " + getGamePath());
|
|
||||||
}
|
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
Log.d("GameActivity", "new gamePath: " + gamePath);
|
||||||
getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
|
|||||||
Reference in New Issue
Block a user