2015-11-06 13:22:16 +00:00
|
|
|
package com.virtualapplications.play;
|
|
|
|
|
2021-08-10 17:32:20 -04:00
|
|
|
import android.app.AlertDialog;
|
|
|
|
import android.app.ProgressDialog;
|
2015-11-06 13:22:16 +00:00
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
2021-08-10 17:32:20 -04:00
|
|
|
import android.os.AsyncTask;
|
2015-11-06 13:22:16 +00:00
|
|
|
|
2015-11-22 19:00:17 -05:00
|
|
|
public class VirtualMachineManager
|
|
|
|
{
|
2023-10-10 11:59:59 -04:00
|
|
|
public interface OnGameLaunchCompleteListener
|
|
|
|
{
|
|
|
|
void onComplete();
|
|
|
|
}
|
|
|
|
|
2021-08-10 17:32:20 -04:00
|
|
|
private static final class GameLauncher extends AsyncTask<Void, Void, Void>
|
2015-11-22 19:00:17 -05:00
|
|
|
{
|
2021-08-10 17:32:20 -04:00
|
|
|
private ProgressDialog progDialog;
|
|
|
|
final Context _ctx;
|
|
|
|
final String _bootablePath;
|
2023-10-10 11:59:59 -04:00
|
|
|
final OnGameLaunchCompleteListener _completeListener;
|
2021-08-10 17:32:20 -04:00
|
|
|
Exception _exception;
|
|
|
|
|
2023-10-10 11:59:59 -04:00
|
|
|
public GameLauncher(Context ctx, String bootablePath, OnGameLaunchCompleteListener completeListener)
|
2021-08-10 17:32:20 -04:00
|
|
|
{
|
|
|
|
_ctx = ctx;
|
2023-10-10 11:59:59 -04:00
|
|
|
_bootablePath = bootablePath;
|
|
|
|
_completeListener = completeListener;
|
2021-08-10 17:32:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
protected void onPreExecute()
|
|
|
|
{
|
|
|
|
progDialog = ProgressDialog.show(_ctx,
|
|
|
|
_ctx.getString(R.string.launch_game),
|
|
|
|
_ctx.getString(R.string.launch_game_msg), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Void... params)
|
2015-11-22 19:00:17 -05:00
|
|
|
{
|
2021-08-10 17:32:20 -04:00
|
|
|
try
|
|
|
|
{
|
|
|
|
if(BootablesInterop.IsBootableExecutablePath(_bootablePath))
|
|
|
|
{
|
|
|
|
NativeInterop.loadElf(_bootablePath);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NativeInterop.bootDiskImage(_bootablePath);
|
|
|
|
}
|
|
|
|
Intent intent = new Intent(_ctx, EmulatorActivity.class);
|
|
|
|
_ctx.startActivity(intent);
|
|
|
|
}
|
|
|
|
catch(Exception e)
|
|
|
|
{
|
|
|
|
_exception = e;
|
|
|
|
}
|
|
|
|
return null;
|
2015-11-22 19:00:17 -05:00
|
|
|
}
|
2021-08-10 17:32:20 -04:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPostExecute(Void result)
|
|
|
|
{
|
|
|
|
if(progDialog != null && progDialog.isShowing())
|
|
|
|
{
|
2021-10-01 09:07:45 -04:00
|
|
|
try
|
|
|
|
{
|
|
|
|
progDialog.dismiss();
|
|
|
|
}
|
|
|
|
catch(final Exception e)
|
|
|
|
{
|
|
|
|
//We don't really care if we get an exception while dismissing
|
|
|
|
}
|
2021-08-10 17:32:20 -04:00
|
|
|
}
|
|
|
|
if(_exception != null)
|
|
|
|
{
|
|
|
|
displaySimpleMessage("Error", _exception.getMessage());
|
|
|
|
}
|
2023-10-10 11:59:59 -04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if(_completeListener != null)
|
|
|
|
{
|
|
|
|
_completeListener.onComplete();
|
|
|
|
}
|
|
|
|
}
|
2021-08-10 17:32:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
private void displaySimpleMessage(String title, String message)
|
2015-11-22 19:00:17 -05:00
|
|
|
{
|
2021-08-10 17:32:20 -04:00
|
|
|
new AlertDialog.Builder(_ctx)
|
|
|
|
.setTitle(title)
|
|
|
|
.setMessage(message)
|
|
|
|
.setPositiveButton(android.R.string.ok, null)
|
2023-10-10 11:59:59 -04:00
|
|
|
.setOnDismissListener(dialogInterface -> {
|
|
|
|
if(_completeListener != null)
|
|
|
|
{
|
|
|
|
_completeListener.onComplete();
|
|
|
|
}
|
|
|
|
})
|
2021-08-10 17:32:20 -04:00
|
|
|
.create()
|
|
|
|
.show();
|
2015-11-22 19:00:17 -05:00
|
|
|
}
|
2021-08-10 17:32:20 -04:00
|
|
|
}
|
|
|
|
|
2023-10-10 11:59:59 -04:00
|
|
|
public static void launchGame(Context ctx, String bootablePath, OnGameLaunchCompleteListener completeListener)
|
2021-08-10 17:32:20 -04:00
|
|
|
{
|
2023-10-10 11:59:59 -04:00
|
|
|
GameLauncher launcher = new GameLauncher(ctx, bootablePath, completeListener);
|
2021-08-10 17:32:20 -04:00
|
|
|
launcher.execute();
|
2015-11-22 19:00:17 -05:00
|
|
|
}
|
|
|
|
}
|