using System; using System.Collections.Generic; using System.Text; namespace Shared.Phone.UserCenter.DevicePirSensor { /// /// PIR传感器的触发目标选择界面 /// public class PirSensorTargetSelectForm : EditorCommonForm { #region ■ 变量声明___________________________ /// /// 结束选择的事件(设备主键) /// public Action> FinishSelectEvent = null; /// /// 当前选择的楼层ID /// private string nowSelectFloorId = string.Empty; /// /// 桌布控件 /// private FrameLayout frameTable = null; /// /// 房间对象 /// private Dictionary> dicRoom = new Dictionary>(); /// /// 已经存在的绑定设备 /// private List listEsixtDevice = new List(); #endregion #region ■ 初始化_____________________________ /// /// 画面显示(底层会固定调用此方法,借以完成画面创建) /// /// 存在的设备 public void ShowForm(List i_listEsixtDevice) { this.listEsixtDevice.AddRange(i_listEsixtDevice); //设置头部信息 base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uTriggerTarget)); //初始化右上角的控件 this.InitTopRightMenuControl(); //初始化中部信息 this.InitMiddleFrame(); } /// /// 初始化中部信息 /// private void InitMiddleFrame() { //清空bodyFrame this.ClearBodyFrame(); //房间的容器控件 var frameBack = new FrameLayout(); frameBack.Height = Application.GetRealHeight(204); bodyFrameLayout.AddChidren(frameBack); var scrolContr = new HorizontalScrolViewLayout(); scrolContr.Gravity = Gravity.CenterVertical; scrolContr.Height = frameBack.Height; frameBack.AddChidren(scrolContr); //桌布控件 this.frameTable = new FrameLayout(); frameTable.Y = frameBack.Bottom; frameTable.Height = bodyFrameLayout.Height - frameBack.Height; bodyFrameLayout.AddChidren(frameTable); HdlThreadLogic.Current.RunMainInThread(() => { if (dicRoom.ContainsKey(nowSelectFloorId) == true && dicRoom[nowSelectFloorId].Count > 0) { //初始化房间控件 this.InitRoomControl(scrolContr, dicRoom[nowSelectFloorId]); //确定按钮 var btnOk = new BottomClickButton(); btnOk.TextID = R.MyInternationalizationString.uConfirm1; bodyFrameLayout.AddChidren(btnOk); btnOk.ButtonClickEvent += (sender, e) => { //调用回调函数 this.FinishSelectEvent?.Invoke(listEsixtDevice); //界面关闭 this.CloseForm(); }; } else { //没有可以添加的目标 var btnPic = new PicViewControl(683, 392); btnPic.UnSelectedImagePath = "Item/NoFunction.png"; btnPic.Y = (int)(bodyFrameLayout.Height * 0.382) - Application.GetRealHeight(392 / 2); btnPic.Gravity = Gravity.CenterHorizontal; bodyFrameLayout.AddChidren(btnPic); var btnView = new NormalViewControl(bodyFrameLayout.Width, Application.GetRealHeight(50), false); btnView.Y = btnPic.Bottom + Application.GetRealHeight(32); btnView.TextID = R.MyInternationalizationString.uNotHadAddTarget; btnView.TextAlignment = TextAlignment.Center; btnView.TextSize = 12; btnView.TextColor = UserCenterColor.Current.TextGrayColor1; bodyFrameLayout.AddChidren(btnView); return; } }); } #endregion #region ■ 初始化右上角的控件_________________ /// /// 初始化右上角的控件 /// private void InitTopRightMenuControl() { //房间分组 foreach (var room in Common.Room.Lists) { //检测该房间能否显示 if (this.CheckCanShowRow(room) == false) { continue; } if (dicRoom.ContainsKey(room.FloorId) == false) { dicRoom[room.FloorId] = new List(); } dicRoom[room.FloorId].Add(room); } if (dicRoom.Count == 0) { //默认一个空的东西 dicRoom[string.Empty] = new List(); } //获取楼层 var dicFloor = Common.Room.CurrentRoom.GetFloorSortList(); if (dicFloor.Count == 0) { return; } var btnIconContr = new MostRightIconControl(69, 69); btnIconContr.UnSelectedImagePath = "Item/Drop_Down.png"; topFrameLayout.AddChidren(btnIconContr); btnIconContr.InitControl(); var btnFloor = new NormalViewControl(300, 69, true); btnFloor.Gravity = Gravity.CenterVertical; btnFloor.X = btnIconContr.X + btnIconContr.btnIcon.X - Application.GetRealWidth(300); btnFloor.TextAlignment = TextAlignment.CenterRight; topFrameLayout.AddChidren(btnFloor); foreach (var floorId in dicFloor.Keys) { //第一个楼层 this.nowSelectFloorId = floorId; btnFloor.Text = dicFloor[floorId]; break; } btnIconContr.ButtonClickEvent += (sender, e) => { //楼层菜单 var contr = new TopRightMenuControl(dicFloor.Count, 449, Language.StringByID(R.MyInternationalizationString.SelectFloor)); foreach (var floorId in dicFloor.Keys) { contr.AddRowMenu(dicFloor[floorId], "Floor/Floor.png", "Floor/FloorSelected.png", () => { //记录起选择的ID this.nowSelectFloorId = floorId; btnFloor.Text = dicFloor[this.nowSelectFloorId]; //初始化中部信息 this.InitMiddleFrame(); }); } }; } #endregion #region ■ 初始化房间控件_____________________ /// /// 初始化房间控件 /// /// 容器 /// 房间列表 private void InitRoomControl(HorizontalScrolViewLayout scrolContr, List listRoom) { string oldRoomId = listRoom[0].Id; FrameLayoutControl oldFrameBack = null; NormalViewControl oldBtnText = null; //弄个空的进去占位置 var frameTemp = new FrameLayout(); frameTemp.Height = scrolContr.Height; frameTemp.Width = ControlCommonResourse.XXLeft / 2; scrolContr.AddChidren(frameTemp); for (int i = 0; i < listRoom.Count; i++) { var room = listRoom[i]; //带图片的 var frameBack = new FrameLayoutControl(); frameBack.UseClickStatu = false; frameBack.Gravity = Gravity.Center; frameBack.Height = Application.GetRealHeight(159); frameBack.Width = Application.GetRealWidth(255); if (i == 0) { frameBack.BackgroundImagePath = "Item/RoomIconBackgroundSelected.png"; oldFrameBack = frameBack; } else { frameBack.BackgroundImagePath = "Item/RoomIconBackground.png"; } scrolContr.AddChidren(frameBack); //文字 var btnText = new NormalViewControl(frameBack.Width - (int)(frameBack.Height * 0.47), frameBack.Height, false); btnText.Gravity = Gravity.CenterHorizontal; btnText.Text = room.Name; btnText.TextSize = 12; btnText.TextAlignment = TextAlignment.Center; if (i == 0) { btnText.TextColor = UserCenterColor.Current.White; oldBtnText = btnText; } else { btnText.TextColor = UserCenterColor.Current.TextGrayColor1; } frameBack.AddChidren(btnText, ChidrenBindMode.BindEventOnly); frameBack.ButtonClickEvent += (sender, e) => { if (oldRoomId == room.Id) { //同一个东西 return; } oldRoomId = room.Id; //状态变更 frameBack.BackgroundImagePath = "Item/RoomIconBackgroundSelected.png"; btnText.TextColor = UserCenterColor.Current.White; oldFrameBack.BackgroundImagePath = "Item/RoomIconBackground.png"; oldBtnText.TextColor = UserCenterColor.Current.TextGrayColor1; oldFrameBack = frameBack; oldBtnText = btnText; //初始化设备行 this.InitDeviceControl(room); }; } //初始化设备行 this.InitDeviceControl(listRoom[0]); } #endregion #region ■ 初始化设备控件_____________________ /// /// 初始化设备控件 /// /// private void InitDeviceControl(Common.Room room) { //先清空 this.frameTable.RemoveAll(); var frameBack = new FrameLayout(); frameBack.Height = Application.GetRealHeight(11); frameBack.BackgroundColor = UserCenterColor.Current.White; frameTable.AddChidren(frameBack); var listView = new VerticalListControl(12); listView.Y = frameBack.Bottom; listView.Height = frameTable.Height - frameBack.Height; listView.BackgroundColor = UserCenterColor.Current.White; frameTable.AddChidren(listView); var listDevice = new List(); foreach (var deviceUi in room.DeviceUIList) { var device = deviceUi.CommonDevice; //检测设备 if (this.CheckCanShowDevice(device) == true) { listDevice.Add(device); } } for (int i = 0; i < listDevice.Count; i++) { var device = listDevice[i]; string mainKey = Common.LocalDevice.Current.GetDeviceMainKeys(device); var rowDevice = new FrameRowControl(listView.rowSpace / 2); listView.AddChidren(rowDevice); //图标 var btnIcon = rowDevice.AddLeftIcon(81); Common.LocalDevice.Current.SetDeviceIconToControl(btnIcon, device); //设备名称 var btnName = rowDevice.AddLeftCaption(Common.LocalDevice.Current.GetDeviceEpointName(device), 600); btnName.TextSize = 15; //选择 var btnSelect = rowDevice.AddMostRightEmptyIcon(58, 58); if (listEsixtDevice.Contains(mainKey) == false) { btnSelect.Visible = false; } btnSelect.UnSelectedImagePath = "Item/ItemSelected.png"; if (i != listDevice.Count - 1) { //底线 rowDevice.AddBottomLine(); } rowDevice.ButtonClickEvent += (sender, e) => { btnSelect.Visible = !btnSelect.Visible; if (btnSelect.Visible == true) { listEsixtDevice.Add(mainKey); } else { listEsixtDevice.Remove(mainKey); } }; } listDevice = null; //调整控件真实高度 listView.AdjustRealHeight(Application.GetRealHeight(23)); //借用这个东西进行检测 var btnTemp = new BottomClickButton(); //如果真实高度已经超过了确定按键 if (listView.Bottom + frameTable.Y > btnTemp.Yaxis) { listView.Height = frameTable.Height - frameBack.Height; var frameTemp = new FrameLayout(); frameTemp.Height = bodyFrameLayout.Height - btnTemp.Yaxis; listView.AddChidren(frameTemp); } } #endregion #region ■ 一般方法___________________________ /// /// 检测该房间能否显示 /// /// /// private bool CheckCanShowRow(Common.Room room) { if (room.DeviceUIList.Count == 0) { return false; } if (room.IsLove == true) { return false; } foreach (var deviceUi in room.DeviceUIList) { //检测该设备能否显示 if (this.CheckCanShowDevice(deviceUi.CommonDevice) == false) { continue; } //存在设备的话,此房间可以显示 return true; } return false; } /// /// 检测该设备能否显示 /// /// /// private bool CheckCanShowDevice(ZigBee.Device.CommonDevice device) { if (device == null) { return false; } //如果是传感器,或者是没有开关簇的话(这里判断的是输入簇) if ((device.Type == ZigBee.Device.DeviceType.IASZone) || Common.LocalDevice.Current.InDeviceIsCanOnOff(device) == false) { return false; } return true; } #endregion #region ■ 界面关闭___________________________ /// /// 界面关闭 /// public override void CloseForm() { this.FinishSelectEvent = null; base.CloseForm(); } #endregion } }