Proper downloading of games and starting works when downloaded using the LÖVE app

This commit is contained in:
fysx
2014-02-20 21:27:34 +01:00
parent 4c2846f4bb
commit 5f6fa8c2b5
4 changed files with 122 additions and 95 deletions
+13 -43
View File
@@ -6,27 +6,36 @@ import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import android.app.DownloadManager;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.PowerManager;
import android.os.ResultReceiver;
import android.util.Log;
import android.util.DisplayMetrics;
import android.widget.Toast;
public class GameActivity extends SDLActivity {
private static DisplayMetrics metrics = new DisplayMetrics();
private static String gamePath = "";
// declare the dialog as a member field of your activity
private static ProgressDialog mProgressDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.d("GameActivity", "started");
Uri game = this.getIntent().getData();
if (game != null) {
if (game.getScheme().equals ("file")) {
@@ -36,7 +45,7 @@ public class GameActivity extends SDLActivity {
}
Log.d("GameActivity", "Selected the file: " + getGamePath());
}
super.onCreate(savedInstanceState);
getWindowManager().getDefaultDisplay().getMetrics(metrics);
}
@@ -72,25 +81,6 @@ public class GameActivity extends SDLActivity {
} catch (IOException e) {
Log.d ("GameActivity", "Could not open game file:" + e.getMessage());
}
} else if (sourceuri.getScheme().equals("http")) {
String url = sourceuri.getScheme() + "://" + sourceuri.getHost() + sourceuri.getPath();
Log.d("GameActivity", "url = " + url);
// instantiate it within the onCreate method
mProgressDialog = new ProgressDialog(GameActivity.this);
mProgressDialog.setMessage("Downloading Game");
mProgressDialog.setIndeterminate(true);
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
mProgressDialog.setCancelable(true);
mProgressDialog.setProgress (0);
mProgressDialog.setMax (100);
// this is how you fire the downloader
mProgressDialog.show();
Intent intent = new Intent(this, DownloadService.class);
intent.putExtra("url", url);
intent.putExtra("receiver", new DownloadReceiver(new Handler()));
startService(intent);
} else {
Log.d ("GameActivity", "Unsupported scheme: " + sourceuri.getScheme());
}
@@ -120,24 +110,4 @@ public class GameActivity extends SDLActivity {
Log.d("GameActivity", "Copied " + bytes_written + " bytes");
}
private class DownloadReceiver extends ResultReceiver{
public DownloadReceiver(Handler handler) {
super(handler);
}
@Override
protected void onReceiveResult(int resultCode, Bundle resultData) {
super.onReceiveResult(resultCode, resultData);
if (resultCode == DownloadService.UPDATE_PROGRESS) {
mProgressDialog.setIndeterminate(false);
int progress = resultData.getInt("progress");
mProgressDialog.setProgress(progress);
if (progress == 100) {
mProgressDialog.dismiss();
}
}
}
}
}