using Shared; using System; using System.Collections.Generic; using System.Text; namespace HDL_ON.Stan { /// /// 界面相关的逻辑 /// public class HdlFormLogic { #region ■ 变量声明___________________________ /// /// 界面相关的逻辑 /// private static HdlFormLogic m_Current; /// /// 界面相关的逻辑 /// public static HdlFormLogic Current { get { if (m_Current == null) { m_Current = new HdlFormLogic(); } return m_Current; } } /// /// 当前已经打开了的画面(继承于UserCenterCommonForm才能使用)。 /// 画面打开时,会自动追击,画面关闭时,自动移除。 /// 新添加的界面会放在前面 /// private List ListActionForm = new List(); /// /// 当前正在操作的画面ID(没人会懂它为何要存在) /// public string NowActionFormID { get { return ListActionForm.Count > 0 ? ListActionForm[0].FormID : string.Empty; } } /// /// 显示监视内存的控件 /// private NormalViewControl btnMemory = null; #endregion #region ■ 添加界面相关_______________________ /// /// 检测能否添加画面 /// /// true:可以追加 false:不可追加 /// Form public bool CheckCanAddForm(CommonFormBase form) { //获取画面英文名字 string formId = GetFormID(form); //暂时这样弄看看,如果重复,则关闭掉原来的界面 var formTemp = this.GetFormByName(formId); formTemp?.CloseForm(); return true; } /// /// 把打开的画面添加到内存中 /// /// Form. public void AddActionForm(CommonFormBase form) { //获取画面英文名字 string formId = GetFormID(form); //内存添加 form.FormID = formId; this.ListActionForm.Insert(0, form); } /// /// 从列表中移除画面 /// /// 关闭的界面 public void RemoveActionForm(CommonFormBase i_closeForm) { //获取画面ID string formId = GetFormID(i_closeForm); var removeForm = this.GetFormByName(formId); if (removeForm == null) { return; } //移除画面 this.ListActionForm.Remove(removeForm); var actionForm = MainPage.BasePageView.GetChildren(MainPage.BasePageView.ChildrenCount - 1); if (actionForm == null) { return; } //关闭的界面为EditorCommonForm的时候 if ((i_closeForm is EditorCommonForm) && (actionForm is EditorCommonForm)) { //接下来激活的界面 try { var Myform = actionForm as EditorCommonForm; //触发界面再次激活的事件 Myform.FormActionAgainEvent(); } catch { } } } /// /// 获取画面ID /// /// The form name. /// Form. private string GetFormID(CommonFormBase form) { if (form.FormID != string.Empty) { return form.FormID; } //将命名空间去掉 string[] Arry = form.ToString().Split(new string[] { "." }, StringSplitOptions.RemoveEmptyEntries); string formName = Arry[Arry.Length - 1].Trim(); return formName; } #endregion #region ■ 设备状态更新推送___________________ /// /// 设备状态更新推送 /// /// 本地设备对象 /// 是否刷新主页,分类,房间等等的设备卡片的状态,默认不刷新(此变量目前是给bus接收那里使用的) public void DeviceStatuPush(Entity.Function i_LocalDevice, bool refreshCardContr = false) { HdlThreadLogic.Current.RunMain(() => { for (int i = 0; i < this.ListActionForm.Count; i++) { this.ListActionForm[i]?.DeviceStatuPush(i_LocalDevice); } if (refreshCardContr == true) { //刷新主页,分类,房间等等的设备卡片状态 this.RefreshAllDeviceCardControl(i_LocalDevice); } }, ShowErrorMode.NO); } #endregion #region ■ 手动刷新各设备卡片_________________ /// /// 手动刷新主页,分类,房间等等的设备卡片状态 /// /// 需要刷新的设备对象 public void RefreshAllDeviceCardControl(Entity.Function i_device) { //刷新主页 UI.HomePage.UpdataFunctionStates(i_device); //刷新分类 UI.ClassificationPage.UpdataInfo(i_device); //刷新房间 UI.RoomPage.UpdataStates(i_device); //刷新功能 UI.FunctionPage.UpdataStates(i_device); } #endregion #region ■ 一般方法___________________________ /// /// 关闭所有打开了的界面 /// /// 目标界面,如果指定了的话,则关闭目标界面上层的全部界面(它自身不关闭) public void CloseAllOpenForm(string tagetFrom = null) { //最后一个是装载主页的容器,所以不能删除 while (MainPage.BasePageView.ChildrenCount > 1) { var view = MainPage.BasePageView.GetChildren(MainPage.BasePageView.ChildrenCount - 1); if (view is CommonFormBase) { if (((CommonFormBase)view).FormID == tagetFrom) { //只关闭到指定目标界面 return; } ((CommonFormBase)view).CloseForm(); } else { view.RemoveFromParent(); } } } /// /// 获取当前正在激活的界面 /// /// public CommonFormBase GetNowActionForm() { return MainPage.BasePageView.GetChildren(MainPage.BasePageView.ChildrenCount - 1) as CommonFormBase; } /// /// 根据名字获取指定已经打开了的界面 /// /// /// public CommonFormBase GetFormByName(string i_formName) { for (int i = 0; i < this.ListActionForm.Count; i++) { if (this.ListActionForm[i].FormID == i_formName) { return this.ListActionForm[i]; } } return null; } /// /// 关闭指定的画面 /// /// 指定要关闭的画面英文名字 public void CloseFormByFormName(string formName) { var form = this.GetFormByName(formName); //关闭指定画面 form?.CloseForm(); } /// /// 判断指定的界面是否打开 /// /// /// public bool IsFormOpen(string formId) { var form = this.GetNowActionForm(); return form != null ? form.FormID == formId : false; } /// /// 获取全部已经打开了的界面 /// /// public List GetAllOpenForm() { var list = new List(); try { for (int i = 0; i < this.ListActionForm.Count; i++) { list.Add(this.ListActionForm[i]); } return list; } catch { return list; } } #if __Android__ /// /// 显示监听内存的界面 /// public void ShowMemoryListenView(int div) { this.btnMemory = new NormalViewControl(Application.MainPage.Width, HdlControlResourse.TopMenuFrameHeight, false); btnMemory.TextAlignment = TextAlignment.Center; btnMemory.BackgroundColor = 0xffffb9b9; btnMemory.TextSize = 10; btnMemory.IsMoreLines = true; Application.MainPage.AddChidren(btnMemory); if (div == 2) { btnMemory.Y = Application.MainPage.Height - this.btnMemory.Height; btnMemory.BringToFront(); btnMemory.Animate = Animate.DownToUp; } else { btnMemory.BringToFront(); btnMemory.Animate = Animate.UpToDown; } HdlThreadLogic.Current.RunThread(() => { int count = 0; while (this.btnMemory != null) { System.Threading.Thread.Sleep(1000); count++; if (count < 2) { continue; } count = 0; HdlThreadLogic.Current.RunMain(() => { var obj = Application.Activity.GetSystemService(Android.Content.Context.ActivityService); var activityManager = (Android.App.ActivityManager)obj; var memoryInfos = activityManager.GetProcessMemoryInfo(new int[] { Android.OS.Process.MyPid() }); if (memoryInfos.Length > 0) { string text = "PrivateDirty:" + (memoryInfos[0].TotalPrivateDirty) + "KB"; text += " Pss:" + (memoryInfos[0].TotalPss) + "KB\r\n"; text += "PrivateDirty:" + (memoryInfos[0].TotalPrivateDirty / 1024) + "MB"; text += " Pss:" + (memoryInfos[0].TotalPss / 1024) + "MB"; if (btnMemory != null) { btnMemory.Text = text; } } else { if (btnMemory != null) { btnMemory.Text = "获取内存异常"; } } obj = null; activityManager = null; memoryInfos = null; }); } }); } /// /// 关闭监听内存的界面 /// public void CloseMemoryListenView() { if (this.btnMemory != null) { this.btnMemory.RemoveFromParent(); this.btnMemory = null; } } /// /// 监测是否是在监听 /// /// public bool CheckIsListeningMemory() { return this.btnMemory != null; } #endif #endregion } }