-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainActivity.cs
61 lines (47 loc) · 1.97 KB
/
MainActivity.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using System.Threading;
using Android.App;
using Android.Content.PM;
using Android.OS;
using Android.Widget;
using PokeD.Server.Android.WrapperInstances;
namespace PokeD.Server.Android
{
[Activity(Label = "PokeD Server", MainLauncher = true, Icon = "@drawable/icon", ScreenOrientation = ScreenOrientation.SensorPortrait, LaunchMode = LaunchMode.SingleInstance)]
public class MainActivity : Activity
{
public static Action<Action> RunOnUI { get; set; }
private Thread _serverMainThread;
private Thread _serverStopThread;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
InputWrapperInstance.TextView = FindViewById<TextView>(Resource.Id.textView1);
FindViewById<Button>(Resource.Id.Button02).Click += MainActivity_02_Click;
FindViewById<Button>(Resource.Id.Button03).Click += MainActivity_03_Click;
RunOnUI += RunOnUiThread;
}
private void MainActivity_02_Click(object sender, EventArgs e)
{
if (_serverStopThread != null && _serverStopThread.IsAlive)
while (_serverStopThread.IsAlive) { Thread.SpinWait(200); }
if (_serverMainThread != null && _serverMainThread.IsAlive)
{
Program.Stop();
while (_serverMainThread.IsAlive) { Thread.SpinWait(200); }
}
_serverMainThread = new Thread(() => Program.Main());
_serverMainThread.Start();
}
private void MainActivity_03_Click(object sender, EventArgs e)
{
if (_serverMainThread != null && _serverMainThread.IsAlive)
{
_serverStopThread = new Thread(() => Program.Stop());
_serverStopThread.Start();
while (_serverMainThread.IsAlive) { Thread.SpinWait(200); }
}
}
}
}