mirror of
https://github.com/love2d/love-android.git
synced 2026-08-16 08:11:44 +02:00
Proper downloading of games and starting works when downloaded using the LÖVE app
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user