/// <summary> /// 初始化截屏服务。 /// </summary> /// <param name="data"></param> /// <param name="context"></param> /// <param name="handler"></param> public void Init(Intent data, Context context) { if (IsInit) { return; } volatileDispose = new VolatileDispose(); _intent = data; Context = context; _mediaProjectionManager = AppApplication.GetSystemService <MediaProjectionManager>(Context.MediaProjectionService); _orientationEventListener = new OrientationEvent(context, i => { try { RefreshVirtualDisplay(); } catch (Exception) { } }); if (_orientationEventListener.CanDetectOrientation()) { _orientationEventListener.Enable(); } IsInit = true; }
public void RunFile(string path) { if (string.IsNullOrWhiteSpace(path)) { return; } try { if (AppApplication.LuaThread != null) { //关闭 lua脚本运行,关闭脚本线程 AppApplication.Lua.Close(); AppApplication.LuaThread.Interrupt(); AppApplication.LuaThread = null; } //执行lua脚本 ScriptExecuteActivity.Execute(path); } catch (LuaException e) { AppApplication.OnLog("异常", e.ToString(), Color.Red); } }
/// <summary> /// 监听按键 /// </summary> /// <param name="keyCode">按键码</param> /// <param name="event">按键事件</param> public void OnKeyEvent(Keycode keyCode, KeyEvent @event) { foreach (var item in _keyMonitorEvents) { try { item.OnKeyEvent(keyCode, @event); } catch (Exception) { AppApplication.OnLog("异常", $"Error OnKeyEvent: {@event.ToString()} Listener: {item.ToString()}", Color.Red); } } }
public void execScriptFile(string file) { if (!File.Exists(file)) { AppApplication.OnLog("错误", $"脚本 {file} 不存在", Color.Red); return; } try { AppApplication.Lua.LoadFile(file); } catch (Exception e) { AppApplication.OnLog("异常", e.Message, Color.Red); } }
private static async void LoadScript(dynamic lua) { var path = "Script"; var scripts = AppUtils.GetAssets.List(path); foreach (var file in scripts) { try { var lastIndex = file.LastIndexOf('.'); if (lastIndex <= -1) { AppApplication.OnLog("异常", $"加载{file}模块失败", Color.Red); continue; } lastIndex++; var ex = file.Substring(lastIndex, file.Length - lastIndex); if (ex.ToLower() != "lua") { AppApplication.OnLog("异常", $"加载{file}模块失败", Color.Red); continue; } var f = $"{path}/{file}"; using var sr = new StreamReader(AppUtils.GetAssets.Open(f)); var str = await sr.ReadToEndAsync(); lua.LoadString(str); } catch (Exception) { AppApplication.OnLog("异常", $"加载{file}模块失败", Color.Red); } } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); var extras = IntentExtras.FromIntentAndRelease(Intent); if (extras == null) { Finish(); return; } var script = extras.Get <string>("luaScript"); if (string.IsNullOrWhiteSpace(script)) { Finish(); return; } //初始化lua全局函数 LuaGlobal.Instance.Init(); AppApplication.LuaThread = new Thread(() => { try { AppApplication.Lua?.DoFile(script); } catch (LuaException e) { AppApplication.OnLog("异常", e.Message, Color.Red); } }); AppApplication.LuaThread.Start(); }
public Sensors() { _sensorManager = AppApplication.GetSystemService <SensorManager>(Context.SensorService); }