forked from anassfiqhi/OpenEducationProject
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathService.uno
More file actions
137 lines (114 loc) · 4.07 KB
/
Copy pathService.uno
File metadata and controls
137 lines (114 loc) · 4.07 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
using Fuse;
using Fuse.Scripting;
using Fuse.Reactive;
using Uno.UX;
using Uno;
using Uno.Compiler.ExportTargetInterop;
using Uno.Collections;
using Uno.Threading;
[extern(Android) Require("AndroidManifest.ApplicationElement",
"<service android:name=\"com.fuse.OpenEducation.ServiceClass\" android:enabled=\"true\" android:process=\":backgProc\" />")]
[Require("AndroidManifest.Permission", "android.permission.SYSTEM_ALERT_WINDOW")]
[extern(Android) ForeignInclude(Language.Java,
"android.content.Intent",
"android.content.Context",
"android.os.Bundle",
"android.app.Activity",
"java.lang.*",
"android.widget.Toast",
//"Java.lang.*",
//"android.content.SharedPreferences",
//"android.os.Handler",
//"android.os.ResultReceiver",
"com.fuse.OpenEducation.ServiceClass")]
[UXGlobalModule]
public class Service : NativeEventEmitterModule
{
static readonly Service _instance;
public static bool Service_status;
public Service() : base(true, "Service")
{
if(_instance != null) {
return;
} else {
_instance = this;
}
Service_status = false;
Uno.UX.Resource.SetGlobalKey(_instance, "Service");
if defined(Android) {Emit("Service", false);}
AddMember(new NativeFunction("StartService", (NativeCallback)StartService));
AddMember(new NativeFunction("StopService", (NativeCallback)StopService));
AddMember(new NativeFunction("SendService_status", (NativeCallback)SendService_status));
}
object StartService(Context c, object[] args)
{
if defined(Android) StartServiceJ();
return null;
}
object StopService(Context c, object[] args)
{
if defined(Android) StopServiceJ();
return null;
}
object[] SendService_status(Fuse.Scripting.Context context, object[] args)
{
if (Service_status){
Emit("Service", true);
}
else if (!Service_status){
Emit("Service", false);
}
return null;
}
void Emit(bool args) {
Emit("Service", args);
}
[Foreign(Language.Java)]
extern(Android) void StartServiceJ()
@{
try{
if(!@{Service_status:Get()}) {
Activity a = com.fuse.Activity.getRootActivity();
a.runOnUiThread(new Runnable() {
@Override
public void run() {
com.fuse.Activity.getRootActivity().startService(new Intent(com.fuse.Activity.getRootActivity(), ServiceClass.class));
}
});
android.util.Log.d("BackgService", "UnoService started");
ServiceClass.run=true;
@{Service_status:Set(true)};
//Emit("Service", true);
@{Service:Of(_this).Emit(bool):Call(true)};
} else {
android.util.Log.d("BackgService", "UnoService already started");
}
}catch(Exception e){
e.printStackTrace();
}
@}
[Foreign(Language.Java)]
extern(Android) void StopServiceJ()
@{
try{
if(@{Service_status:Get()}) {
Activity a = com.fuse.Activity.getRootActivity();
a.runOnUiThread(new Runnable() {
@Override
public void run() {
com.fuse.Activity.getRootActivity().stopService(new Intent(com.fuse.Activity.getRootActivity(), ServiceClass.class));
}
});
android.util.Log.d("BackgService", "UnoService stopped");
ServiceClass.run=false;
@{Service_status:Set(false)};
//Emit("Service", false);
@{Service:Of(_this).Emit(bool):Call(false)};
} else {
android.util.Log.d("BackgService", "UnoService already stopped");
}
}catch(Exception e){
e.printStackTrace();
}
@}
}