mirror of
https://github.com/love2d/love-android.git
synced 2026-08-20 20:51:22 +02:00
Merged GameLauncher and GameActivity together
The GameActivity would not run otherwise as the App started via GameActivity would call in love::android::getSelectedGameFile() the wrong activity (namely GameLauncher) that was not initialized properly. Hence it would result in a segfault.
This commit is contained in:
+1
-1
@@ -25,7 +25,7 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<activity
|
<activity
|
||||||
android:name="GameLauncher"
|
android:name="GameActivity"
|
||||||
android:configChanges="orientation|screenSize"
|
android:configChanges="orientation|screenSize"
|
||||||
android:screenOrientation="landscape" >
|
android:screenOrientation="landscape" >
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ const char* getSelectedGameFile()
|
|||||||
|
|
||||||
if (!path) {
|
if (!path) {
|
||||||
JNIEnv *env = (JNIEnv*) SDL_AndroidGetJNIEnv();
|
JNIEnv *env = (JNIEnv*) SDL_AndroidGetJNIEnv();
|
||||||
jclass activity = env->FindClass("org/love2d/android/GameLauncher");
|
jclass activity = env->FindClass("org/love2d/android/GameActivity");
|
||||||
|
|
||||||
jmethodID getGamePath = env->GetStaticMethodID(activity, "getGamePath", "()Ljava/lang/String;");
|
jmethodID getGamePath = env->GetStaticMethodID(activity, "getGamePath", "()Ljava/lang/String;");
|
||||||
jstring gamePath = (jstring) env->CallStaticObjectMethod(activity, getGamePath);
|
jstring gamePath = (jstring) env->CallStaticObjectMethod(activity, getGamePath);
|
||||||
|
|||||||
@@ -1,20 +1,97 @@
|
|||||||
package org.love2d.android;
|
package org.love2d.android;
|
||||||
|
|
||||||
import org.libsdl.app.SDLActivity;
|
import org.libsdl.app.SDLActivity;
|
||||||
|
|
||||||
|
import java.io.BufferedInputStream;
|
||||||
|
import java.io.BufferedOutputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
|
|
||||||
public class GameActivity extends SDLActivity {
|
public class GameActivity extends SDLActivity {
|
||||||
private static DisplayMetrics metrics = new DisplayMetrics();
|
private static DisplayMetrics metrics = new DisplayMetrics();
|
||||||
|
|
||||||
|
private static String gamePath = "";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
Uri game = this.getIntent().getData();
|
||||||
|
if (game != null) {
|
||||||
|
if (game.getScheme().equals ("file")) {
|
||||||
|
gamePath = game.getPath();
|
||||||
|
} else {
|
||||||
|
copyGameToCache (game);
|
||||||
|
}
|
||||||
|
Log.d("GameActivity", "Selected the file: " + getGamePath());
|
||||||
|
}
|
||||||
|
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getGamePath() {
|
||||||
|
Log.d ("GameActivity", "called getGamePath(), game path = " + gamePath);
|
||||||
|
return gamePath;
|
||||||
|
}
|
||||||
|
|
||||||
public static DisplayMetrics getMetrics() {
|
public static DisplayMetrics getMetrics() {
|
||||||
return metrics;
|
return metrics;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void copyGameToCache (Uri sourceuri)
|
||||||
|
{
|
||||||
|
String destinationFilename = this.getCacheDir().getPath()+"/downloaded.love";
|
||||||
|
gamePath = destinationFilename;
|
||||||
|
|
||||||
|
BufferedOutputStream bos = null;
|
||||||
|
try {
|
||||||
|
bos = new BufferedOutputStream(new FileOutputStream(destinationFilename, false));
|
||||||
|
} catch (IOException e) {
|
||||||
|
Log.d ("GameActivity", "Could not open destination file:" + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
int chunk_read = 0;
|
||||||
|
int bytes_written = 0;
|
||||||
|
|
||||||
|
BufferedInputStream bis = null;
|
||||||
|
if (sourceuri.getScheme().equals("content")) {
|
||||||
|
try {
|
||||||
|
bis = new BufferedInputStream(getContentResolver().openInputStream(sourceuri));
|
||||||
|
} catch (IOException e) {
|
||||||
|
Log.d ("GameActivity", "Could not open game file:" + e.getMessage());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Log.d ("GameActivity", "Unsupported scheme: " + sourceuri.getScheme());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bis != null) {
|
||||||
|
// actual copying
|
||||||
|
try {
|
||||||
|
byte[] buf = new byte[1024];
|
||||||
|
chunk_read = bis.read(buf);
|
||||||
|
do {
|
||||||
|
bos.write(buf, 0, chunk_read);
|
||||||
|
bytes_written += chunk_read;
|
||||||
|
chunk_read = bis.read(buf);
|
||||||
|
} while(chunk_read != -1);
|
||||||
|
} catch (IOException e) {
|
||||||
|
Log.d ("GameActivity", "Copying failed:" + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// close streams
|
||||||
|
try {
|
||||||
|
if (bis != null) bis.close();
|
||||||
|
if (bos != null) bos.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
Log.d ("GameActivity", "Copying failed: " + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.d("GameActivity", "Copied " + bytes_written + " bytes");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,86 +0,0 @@
|
|||||||
package org.love2d.android;
|
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
|
||||||
import java.io.BufferedOutputStream;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
public class GameLauncher extends GameActivity {
|
|
||||||
|
|
||||||
private static String gamePath;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCreate(Bundle bundle) {
|
|
||||||
Uri game = this.getIntent().getData();
|
|
||||||
if (game != null) {
|
|
||||||
if (game.getScheme().equals ("file")) {
|
|
||||||
gamePath = game.getPath();
|
|
||||||
} else {
|
|
||||||
copyGameToCache (game);
|
|
||||||
}
|
|
||||||
Log.d("GameLauncher", "Selected the file: " + getGamePath());
|
|
||||||
}
|
|
||||||
super.onCreate(bundle);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getGamePath() {
|
|
||||||
return gamePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
void copyGameToCache (Uri sourceuri)
|
|
||||||
{
|
|
||||||
String destinationFilename = this.getCacheDir().getPath()+"/downloaded.love";
|
|
||||||
gamePath = destinationFilename;
|
|
||||||
|
|
||||||
BufferedOutputStream bos = null;
|
|
||||||
try {
|
|
||||||
bos = new BufferedOutputStream(new FileOutputStream(destinationFilename, false));
|
|
||||||
} catch (IOException e) {
|
|
||||||
Log.d ("GameLauncher", "Could not open destination file:" + e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
int chunk_read = 0;
|
|
||||||
int bytes_written = 0;
|
|
||||||
|
|
||||||
BufferedInputStream bis = null;
|
|
||||||
if (sourceuri.getScheme().equals("content")) {
|
|
||||||
try {
|
|
||||||
bis = new BufferedInputStream(getContentResolver().openInputStream(sourceuri));
|
|
||||||
} catch (IOException e) {
|
|
||||||
Log.d ("GameLauncher", "Could not open game file:" + e.getMessage());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Log.d ("GameLauncher", "Unsupported scheme: " + sourceuri.getScheme());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bis != null) {
|
|
||||||
// actual copying
|
|
||||||
try {
|
|
||||||
byte[] buf = new byte[1024];
|
|
||||||
chunk_read = bis.read(buf);
|
|
||||||
do {
|
|
||||||
bos.write(buf, 0, chunk_read);
|
|
||||||
bytes_written += chunk_read;
|
|
||||||
chunk_read = bis.read(buf);
|
|
||||||
} while(chunk_read != -1);
|
|
||||||
} catch (IOException e) {
|
|
||||||
Log.d ("GameLauncher", "Copying failed:" + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// close streams
|
|
||||||
try {
|
|
||||||
if (bis != null) bis.close();
|
|
||||||
if (bos != null) bos.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
Log.d ("GameLauncher", "Copying failed: " + e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.d("GameLauncher", "Copied " + bytes_written + " bytes");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user