package net.dot;
-import android.app.AlertDialog;
import android.app.Activity;
import android.os.Bundle;
+import android.os.Handler;
+import android.os.Looper;
+import android.widget.RelativeLayout;
+import android.widget.TextView;
+import android.graphics.Color;
public class MainActivity extends Activity
{
{
super.onCreate(savedInstanceState);
- AlertDialog.Builder dlgAlert = new AlertDialog.Builder(this);
- dlgAlert.setMessage("Use `adb shell am instrument -w " + getApplicationContext().getPackageName() + "net.dot.MonoRunner` to run the tests.");
- dlgAlert.create().show();
+ final String entryPointLibName = "%EntryPointLibName%";
+ final TextView textView = new TextView(this);
+ textView.setTextSize(20);
+
+ RelativeLayout rootLayout = new RelativeLayout(this);
+ RelativeLayout.LayoutParams tvLayout =
+ new RelativeLayout.LayoutParams(
+ RelativeLayout.LayoutParams.WRAP_CONTENT,
+ RelativeLayout.LayoutParams.WRAP_CONTENT);
+
+ tvLayout.addRule(RelativeLayout.CENTER_HORIZONTAL);
+ tvLayout.addRule(RelativeLayout.CENTER_VERTICAL);
+ rootLayout.addView(textView, tvLayout);
+ setContentView(rootLayout);
+
+ if (entryPointLibName == "" || entryPointLibName.startsWith("%")) {
+ textView.setText("ERROR: EntryPointLibName was not set.");
+ return;
+ } else {
+ textView.setText("Running " + entryPointLibName + "...");
+ }
+
+ final Activity ctx = this;
+ new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ int retcode = MonoRunner.initialize(entryPointLibName, ctx);
+ textView.setText("Mono Runtime returned: " + retcode);
+ }
+ }, 1000);
}
}
public class MonoRunner extends Instrumentation
{
- static MonoRunner inst;
- static String entryPointLibName = "%EntryPointLibName%";
-
static {
System.loadLibrary("monodroid");
}
+ static String entryPointLibName = "%EntryPointLibName%";
+
@Override
public void onCreate(Bundle arguments) {
if (arguments != null) {
start();
}
- @Override
- public void onStart() {
- super.onStart();
+ private static String getDocsDir(Context ctx) {
+ File docsPath = ctx.getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS);
+ if (docsPath == null) {
+ docsPath = ctx.getCacheDir();
+ }
+ return docsPath.getAbsolutePath();
+ }
- MonoRunner.inst = this;
- Context context = getContext();
+ public static int initialize(String entryPointLibName, Context context) {
String filesDir = context.getFilesDir().getAbsolutePath();
String cacheDir = context.getCacheDir().getAbsolutePath();
- File docsPath = context.getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS);
- if (docsPath == null) {
- docsPath = context.getCacheDir();
- }
- String docsDir = docsPath.getAbsolutePath();
+ String docsDir = getDocsDir(context);
// unzip libs and test files to filesDir
unzipAssets(context, filesDir, "assets.zip");
+ Log.i("DOTNET", "initRuntime, entryPointLibName=" + entryPointLibName);
+ return initRuntime(filesDir, cacheDir, docsDir, entryPointLibName);
+ }
+
+ @Override
+ public void onStart() {
+ super.onStart();
+
if (entryPointLibName == "") {
Log.e("DOTNET", "Missing entryPointLibName argument, pass '-e entryPointLibName <name.dll>' to adb to specify which program to run.");
finish(1, null);
return;
}
-
- Log.i("DOTNET", "initRuntime");
- int retcode = initRuntime(filesDir, cacheDir, docsDir, entryPointLibName);
+ int retcode = initialize(entryPointLibName, getContext());
runOnMainSync(new Runnable() {
public void run() {
Bundle result = new Bundle();
result.putInt("return-code", retcode);
// Xharness cli expects "test-results-path" with test results
- File testResults = new File(docsDir + "/testResults.xml");
+ File testResults = new File(getDocsDir(getContext()) + "/testResults.xml");
if (testResults.exists()) {
result.putString("test-results-path", testResults.getAbsolutePath());
}
-
finish(retcode, result);
}
});
}
}
- native int initRuntime(String libsDir, String cacheDir, String docsDir, String entryPointLibName);
+ static native int initRuntime(String libsDir, String cacheDir, String docsDir, String entryPointLibName);
}