using Shared.Phone.UserCenter; using System; using System.Collections.Generic; using System.Text; using ZigBee.Device; namespace Shared.Phone.MainPage.ControlForm { /// /// 主页深度卡片的底层共通 /// public class DeviceDetailCardCommonForm : EditorCommonForm { #region ■ 变量声明___________________________ /// /// 界面关闭事件 /// public Action FormCloseEvent = null; /// /// 设备对象 /// public CommonDevice device = null; /// /// 当前选择的房间对象(再次刷新界面时,这个东西有可能是null) /// public Common.Room nowSelectRoom = null; /// /// 标记它是由哪个控件调起的 /// public ViewGroup RowOrCardControl = null; /// /// 状态控件 /// private NormalViewControl btnStatu = null; /// /// 设备名称控件 /// private NormalViewControl btnDeviceName = null; /// /// 房间名称 /// private NormalViewControl btnRoomName = null; /// /// 是否获取网关反馈的结果 0:没有获取得到 1:已经获取得到 /// public int ResponeResult = 0; /// /// 当前端点的功能类型 /// private DeviceFunctionType nowDeviceFuncType = DeviceFunctionType.A未定义; /// /// 白色背景的宽度 /// private int backFrameWidth = 0; /// /// 白色背景的高度 /// private int backFrameHeight = 0; /// /// 当前的文本 /// private string CurrentText = string.Empty; #endregion #region ■ 初始化_____________________________ /// /// 画面显示(底层会固定调用此方法,借以完成画面创建) /// /// 设备对象 /// 房间 /// 白色背景的宽度(非真实值) /// 白色背景的高度(非真实值) public void ShowForm(CommonDevice i_device, Common.Room i_nowSelectRoom, int i_backWidth, int i_backHeight) { this.CurrentText = Language.StringByID(R.MyInternationalizationString.Current) + " "; this.nowSelectRoom = i_nowSelectRoom; this.backFrameWidth = i_backWidth; this.backFrameHeight = i_backHeight; //更多 var btnMore = new MostRightIconControl(69, 69); btnMore.UnSelectedImagePath = "Item/More.png"; topFrameLayout.AddChidren(btnMore); btnMore.InitControl(); btnMore.ButtonClickEvent += (sender, e) => { var detailInfo = new DeviceDetailInfoForm(); detailInfo.AddForm(device, nowSelectRoom); }; //初始化中部信息 this.InitMiddleFrame(i_device); //添加设备上报事件 this.AddDeviceReportEvent(); } /// /// 初始化中部信息 /// /// 设备对象 /// 白色背景的宽度(非真实值) /// 白色背景的高度(非真实值) private void InitMiddleFrame(CommonDevice i_device) { this.device = i_device; this.nowDeviceFuncType = device.DfunctionType; //清空bodyFrame this.ClearBodyFrame(); //白色背景控件 var frameWhiteBack = new FrameLayout(); frameWhiteBack.Y = Application.GetRealHeight(115); frameWhiteBack.Width = Application.GetRealWidth(this.backFrameWidth); frameWhiteBack.Height = Application.GetRealHeight(this.backFrameHeight); frameWhiteBack.BackgroundColor = UserCenterColor.Current.White; frameWhiteBack.Radius = (uint)Application.GetRealHeight(17); frameWhiteBack.Gravity = Gravity.CenterHorizontal; bodyFrameLayout.AddChidren(frameWhiteBack); //设备名称 this.btnDeviceName = new NormalViewControl(100, 60, true); btnDeviceName.Y = Application.GetRealHeight(46); btnDeviceName.TextSize = 15; btnDeviceName.IsBold = true; btnDeviceName.Text = HdlDeviceCommonLogic.Current.GetDeviceEpointName(i_device); btnDeviceName.Width = btnDeviceName.GetRealWidthByText(); btnDeviceName.TextAlignment = TextAlignment.Center; btnDeviceName.Gravity = Gravity.CenterHorizontal; frameWhiteBack.AddChidren(btnDeviceName); //状态 this.btnStatu = new NormalViewControl(700, 42, true); btnStatu.Y = btnDeviceName.Bottom + Application.GetRealHeight(12); btnStatu.TextSize = 10; btnStatu.TextColor = UserCenterColor.Current.TextGrayColor1; btnStatu.TextAlignment = TextAlignment.Center; btnStatu.Gravity = Gravity.CenterHorizontal; frameWhiteBack.AddChidren(btnStatu); //房间的黑色背景 var frameRoomBlack = new FrameLayout(); frameRoomBlack.Height = Application.GetRealHeight(138); frameRoomBlack.Width = frameWhiteBack.Width; frameRoomBlack.BackgroundColor = 0xff232323; frameRoomBlack.Radius= (uint)Application.GetRealHeight(17); frameRoomBlack.Gravity = Gravity.BottomCenter; frameWhiteBack.AddChidren(frameRoomBlack); //让上部变直角(因为安卓这里,单独指定左下和右下角圆角的话,圆不了) var frameTemp = new FrameLayout(); frameTemp.Height = Application.GetRealHeight(30); frameTemp.Width = frameWhiteBack.Width; frameTemp.BackgroundColor = frameRoomBlack.BackgroundColor; frameRoomBlack.AddChidren(frameTemp); //房间图标 var btnRoomIcon = new IconViewControl(81); btnRoomIcon.X = HdlControlResourse.XXLeft; btnRoomIcon.UnSelectedImagePath = "Item/Room.png"; btnRoomIcon.Gravity = Gravity.CenterVertical; frameRoomBlack.AddChidren(btnRoomIcon); //房间名称 this.btnRoomName = new NormalViewControl(600, 52, true); btnRoomName.X = btnRoomIcon.Right + Application.GetRealWidth(12); btnRoomName.TextSize = 12; btnRoomName.TextColor = UserCenterColor.Current.White; btnRoomName.Gravity = Gravity.CenterVertical; if (this.nowSelectRoom != null) { btnRoomName.Text = this.nowSelectRoom.Name; } else { //未分配 btnRoomName.TextID = R.MyInternationalizationString.uDeviceNotAssignedRoom; } frameRoomBlack.AddChidren(btnRoomName); //收藏 var btnCollect = new IconBigViewControl(69, 69); btnCollect.UnSelectedImagePath = "Item/Collection.png"; btnCollect.SelectedImagePath = "Item/CollectionSelected.png"; btnCollect.IsSelected = HdlRoomLogic.Current.IsCollectInRoom(i_device); frameWhiteBack.AddChidren(btnCollect); btnCollect.InitControl(); btnCollect.X = Application.GetRealWidth(850) - btnCollect.XOffset; btnCollect.Y = Application.GetRealHeight(35) - btnCollect.YOffset; btnCollect.ButtonClickEvent += (sender, e) => { //状态取反 btnCollect.IsSelected = !btnCollect.IsSelected; if (btnCollect.IsSelected == false) { //取消收藏 HdlRoomLogic.Current.DeleteLoveDevice(i_device); } else { //添加收藏 HdlRoomLogic.Current.AddLoveDevice(i_device); } }; //底层初始化中部控件完成之后,调用各自界面的初始化函数 this.InitMiddleFrameAfter(frameWhiteBack); } /// /// 底层初始化中部控件完成之后 /// /// 白色背景控件 public virtual void InitMiddleFrameAfter(FrameLayout frameWhiteBack) { } #endregion #region ■ 是否获取网关反馈的结果_____________ /// /// 检测是否获取网关反馈的结果,如果网关没有回复,则会弹出消息 /// /// 需要限制不能点击的控件(超时时,它会还原Select状态) /// 函数运行完成后的回调函数。参数false:没有等到网关回复 true:接收到了网关回复 public void StartCheckResponeResult(List listControl, Action lastAction = null) { this.ResponeResult = 0; //先让指定控件不能点击 foreach (var myContr in listControl) { myContr.CanClick = false; } HdlThreadLogic.Current.RunThread(() => { int waitime = 40; while (waitime > 0) { System.Threading.Thread.Sleep(100); if (this.ResponeResult == 1) { //已经获取得到数据 break; } waitime--; //2秒的时候,还是接受不到的话,强制再次刷新设备状态 if (waitime == 20) { //从新发送获取设备的状态(强制) this.device.HadReadDeviceStatu = false; if (this.RowOrCardControl != null) { this.RowOrCardControl.GetType().InvokeMember("SendStatuComand", System.Reflection.BindingFlags.InvokeMethod, null, this.RowOrCardControl, null); } } } if (waitime <= 0 && this.Parent != null) { //没有获取得到结果 HdlThreadLogic.Current.RunMain(() => { var msgContr = new ShowMsgControl(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.FAIL)); msgContr.Show(); }); } //开关按钮可以再点击 foreach (var myContr in listControl) { myContr.CanClick = true; } //函数运行完成的回调函数 lastAction?.Invoke(this.ResponeResult == 1); lastAction = null; }); } /// /// 检测网关的反馈结果(属性上报的对象:device.DeviceStatusReport) /// /// 命令区分 /// 上报数据 public virtual bool CheckResponeResultStatu(ReceiveComandDiv comandDiv, CommonDevice report) { return false; } /// /// 添加设备上报事件 /// private void AddDeviceReportEvent() { string mainKeys = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(this.device); //属性上报 HdlGatewayReceiveLogic.Current.AddAttributeEvent("DeviceDetailCardAttribute" + mainKeys, ReceiveComandDiv.A设备属性上报, (report) => { string mainKey2 = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(report); if (mainKeys != mainKey2) { //不是同一个东西 return; } //检测结果 if (this.CheckResponeResultStatu(ReceiveComandDiv.A设备属性上报, report) == true) { //结果已经接收到 this.ResponeResult = 1; } }); } #endregion #region ■ 界面重新激活事件___________________ /// /// 自身的上层界面关闭后,它自身处于最上层时,触发的事件 /// public override int FormActionAgainEvent() { //如果不是喜爱房间的话,它的房间有可能被切换了 if (this.nowSelectRoom == null || this.nowSelectRoom.IsLove == false) { this.nowSelectRoom = HdlRoomLogic.Current.GetRoomByDevice(this.device); } //如果功能类型变更了 if (this.nowDeviceFuncType != this.device.DfunctionType) { //重新刷新界面,初始化中部信息 this.InitMiddleFrame(this.device); } else { //刷新名字 this.btnDeviceName.Text = HdlDeviceCommonLogic.Current.GetDeviceEpointName(this.device); btnDeviceName.Width = btnDeviceName.GetRealWidthByText(); btnDeviceName.Gravity = Gravity.CenterHorizontal; if (this.nowSelectRoom == null) { //未分配 this.btnRoomName.TextID = R.MyInternationalizationString.uDeviceNotAssignedRoom; } else { this.btnRoomName.Text = this.nowSelectRoom.Name; } } return 1; } #endregion #region ■ 界面关闭___________________________ /// /// 界面关闭 /// public override void CloseFormBefore() { string mainKeys = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(this.device); HdlGatewayReceiveLogic.Current.RemoveEvent("DeviceDetailCardAttribute" + mainKeys); //回调函数 this.FormCloseEvent?.Invoke(this.device); this.FormCloseEvent = null; base.CloseFormBefore(); } #endregion #region ■ 一般方法___________________________ /// /// 设置状态文本(不需要指定【当前两个字】) /// /// public void SetStatuText(string text) { this.btnStatu.Text = this.CurrentText + text; } /// /// 设置PM2.5传感器状态文本(不需要指定【当前两个字】) /// /// public void SetPmTwoPointFiveStatuText(string text) { this.btnStatu.Text = text; } /// /// 重新设置设备名字控件和状态控件的Y轴 /// /// 设备名字控件的Y轴(真实值) /// 状态控件的Y轴(真实值) public void ResetDeviceNameAndStatuPoint(int i_NameY, int i_StatuY) { btnDeviceName.Y = i_NameY; btnStatu.Y = i_StatuY; } #endregion } }