using Shared.Phone.UserCenter; using System; using System.Collections.Generic; using System.Text; using System.Threading.Tasks; namespace Shared.Phone { /// /// 界面最基层的底层共通 /// public class CommonFormBase : FrameLayout { #region ■ 变量声明___________________________ /// /// 画面的ID(自动编号,唯一主键,和各页面并无任何逻辑关系,但是它的用处大着呢) /// public string FormID = string.Empty; #endregion #region ■ 初始化_____________________________ /// /// 初始化界面框架 /// public virtual void InitForm() { //将当前的画面保存到内存当中 HdlFormLogic.Current.AddActionForm(this); //Log出力 HdlLogLogic.Current.WriteLog(1, this.FormID + " 界面打开"); } /// /// 执行ShowForm()方法 /// /// 启动参数 public virtual void LoadShowFormMethod(params object[] parameter) { this.LoadFormMethodByName(this, "ShowForm", parameter); } #endregion #region ■ 添加界面___________________________ /// /// 添加画面,启动参数由指定画面的ShowForm函数所指定 /// /// 启动参数:参数由指定画面的ShowForm函数所指定 public virtual void AddForm(params object[] parameter) { //关闭输入法界面 this.CloseInputPanel(); return; } /// /// 添加指定画面,并移除当前画面,启动参数由指定画面的ShowForm函数所指定 /// /// 目标界面 /// 启动参数:参数由指定画面的ShowForm函数所指定 public void AddFormAndCloseNowForm(CommonFormBase form, params object[] parameter) { //移除当前画面 this.CloseForm(); //添加画面 form.AddForm(parameter); } #endregion #region ■ 关闭界面___________________________ /// /// 画面关闭之前(底层变更,不能重载CloseForm方法了) /// public virtual void CloseFormBefore() { //关闭输入法界面 this.CloseInputPanel(); } /// /// 画面关闭之后(新增) /// public virtual void CloseFormAfter() { } /// /// 画面关闭 /// public void CloseForm() { //Log出力 HdlLogLogic.Current.WriteLog(1, this.FormID + " 界面关闭"); try { //关闭进度条 this.CloseProgressBar(); //画面关闭之前 this.CloseFormBefore(); //调用的是Base的移除控件函数 //而不是调用this的移除控件函 base.RemoveFromParent(); //从列表中移除(防止画面二重添加) HdlFormLogic.Current.RemoveActionForm(this); //画面关闭之后 this.CloseFormAfter(); } catch (Exception ex) { //出现未知错误 this.ShowMassage(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.uUnKnownError)); //Log出力 HdlLogLogic.Current.WriteLog(ex); } } /// /// 画面关闭(在画面里面,请不要调用此方法,请使用CloseForm()方法) /// public override void RemoveFromParent() { //画面右滑时,关闭画面,调用自定义的CloseForm()方法 this.CloseForm(); } #endregion #region ■ 网关在线状态推送___________________ /// /// 网关在线状态变更推送(只有在变更的时候才会推送) /// /// 网关对象 /// 在线状态变更后的状态 /// 2020.05.25追加:此住宅是否拥有网关在线 public virtual void GatewayOnlinePush(ZigBee.Device.ZbGateway gateWay, bool online, bool hadGwOnline) { } #endregion #region ■ 圆形进度条_________________________ /// /// 进度条启动 /// /// 初始文本 public void ShowProgressBar(string text = "") { if (this.FormID != HdlFormLogic.Current.NowActionFormID) { return; } ProgressBar.Show(text); } /// /// 设置进度条的信息值(会自动计算百分比,值累加模式) /// /// 值 public void SetProgressValue(decimal value) { ProgressBar.SetValue(value); } /// /// 设置进度条的信息值 /// /// 值 public void SetProgressValue(string value) { ProgressBar.SetValue(value); } /// /// 设置进度条的信息值 /// /// 值 public void SetProgressMax(decimal value) { if (value == 0) { value = 100; } ProgressBar.SetMaxValue(value); } /// /// 关闭进度条 /// /// 是否显示重新加载的界面 public void CloseProgressBar(ShowReLoadMode mode = ShowReLoadMode.NO) { ProgressBar.Close(); if (mode == ShowReLoadMode.YES) { //显示重新加载的界面(主要是用在界面加载错误时,再次加载) this.ShowReLoadView(); } } /// /// 显示重新加载的界面(主要是用在界面加载错误时,再次加载) /// public virtual void ShowReLoadView() { } #endregion #region ■ 一般的方法_________________________ /// /// 显示信息框 /// /// 信息类型 /// 信息 /// 单击确认后执行的回调函数 /// 按钮的文本 /// 等待时间,单位为秒,设置确认按钮在多长时间后才能够点击 public void ShowMassage(ShowMsgType msgType, string msg, Action action = null, string buttonText = null, int i_waitTime = -1) { HdlMessageLogic.Current.ShowMassage(msgType, msg, action, buttonText, i_waitTime); } /// /// 判断当前正在活动的界面是否是当前这个界面 /// /// public bool NowFormIsAction() { return HdlFormLogic.Current.NowActionFormID == this.FormID; } /// /// 关闭输入法界面(未实现) /// public void CloseInputPanel() { } /// /// 计算图片的真实高宽度 /// /// /// public int GetPictrueRealSize(int i_size) { return HdlControlLogic.Current.GetPictrueRealSize(i_size); } /// /// 计算真实宽度(可能以后会变动,所以声明出来有用处) /// /// /// public int GetRealWidth(int i_size) { return HdlControlLogic.Current.GetRealWidth(i_size); } /// /// 计算真实高度度(可能以后会变动,所以声明出来有用处) /// /// /// public int GetRealHeight(int i_size) { return HdlControlLogic.Current.GetRealHeight(i_size); } /// /// 计算真实大小(这个东西有特殊用处,考虑到加长型屏幕的控件,调用此方法) /// /// /// public int GetRealSizeEx(int i_size) { return HdlControlLogic.Current.GetRealSizeEx(i_size); } #endregion #region ■ 检测错误___________________________ /// /// 检测界面的错误 /// /// public virtual bool CheckForm() { //检测控件 return this.CheckControl(this); } /// /// 检测控件 /// /// /// private bool CheckControl(View view) { //第一个进来肯定是 ViewGroup if (view is ViewGroup) { var viewGroup = (ViewGroup)view; for (int i = 0; i < viewGroup.ChildrenCount; i++) { var myView = viewGroup.GetChildren(i); if (myView is ViewGroup) { //递归检测 bool result = this.CheckControl(myView); if (result == false) { return false; } continue; } if (myView is TextInputControl) { //检测输入框的错误 var error = ((TextInputControl)myView).CheckError(); if (error != null) { this.ShowMassage(ShowMsgType.Tip, error); ((TextInputControl)myView).OnError = true; return false; } ((TextInputControl)myView).OnError = false; } } } return true; } #endregion #region ■ 反射方法___________________________ /// /// 执行指定画面的方法 /// /// 指定画面的英文名 /// 指定要加载的方法名 /// 启动参数 public object LoadFormMethodByName(string formName, string method, params object[] parameter) { var form = HdlFormLogic.Current.GetFormByName(formName); if (form == null) { return null; } return this.LoadFormMethodByName(form, method, parameter); } /// /// 执行指定画面的方法(注意:这个是专门调用异步,并且等待异步完成的高科技函数,不调用异步的情况,别使用此函数) /// /// 指定画面的英文名 /// 指定要加载的方法名 /// 启动参数 public async Task LoadFormMethodByNameAsync(string formName, string method, params object[] parameter) { var form = HdlFormLogic.Current.GetFormByName(formName); if (form == null) { return null; } var task = this.LoadFormMethodByName(form, method, parameter) as Task; await task; var result = task.GetType().GetProperty("Result").GetValue(task, null); return result; } /// /// 执行指定画面的方法 /// /// 指定画面的英文名 /// 指定要加载的方法名 /// 启动参数 public object LoadFormMethodByName(CommonFormBase form, string method, params object[] parameter) { try { if (form == null) { return null; } var myMethod = form.GetType().GetMethod(method); return myMethod.Invoke(form, parameter); } catch (Exception ex) { //出现未知错误,数据丢失 this.ShowMassage(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.uUnKnownError)); //Log出力 HdlLogLogic.Current.WriteLog(ex); return null; } } /// /// 使用反射方法,打开指定的画面(只支持继承于UserCenterCommonForm的画面) /// /// 画面的命名空间+画面的英文名 /// 启动参数 public void LoadFormByFullName(string fullName, params object[] parameter) { System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly(); var form = (CommonFormBase)assembly.CreateInstance(fullName); form.AddForm(parameter); } #endregion } }