mirror of
https://github.com/love2d/love-android.git
synced 2026-08-16 08:11:44 +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,20 +1,97 @@
|
||||
package org.love2d.android;
|
||||
|
||||
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.util.Log;
|
||||
import android.util.DisplayMetrics;
|
||||
|
||||
public class GameActivity extends SDLActivity {
|
||||
private static DisplayMetrics metrics = new DisplayMetrics();
|
||||
|
||||
@Override
|
||||
|
||||
private static String gamePath = "";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle 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);
|
||||
}
|
||||
|
||||
public static DisplayMetrics getMetrics() {
|
||||
|
||||
public static String getGamePath() {
|
||||
Log.d ("GameActivity", "called getGamePath(), game path = " + gamePath);
|
||||
return gamePath;
|
||||
}
|
||||
|
||||
public static DisplayMetrics getMetrics() {
|
||||
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");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user