using System; using System.Collections.Generic; using Shared.Common; using Shared.Phone.Device.Light; using Shared.Phone.UserCenter.Device; using ZigBee.Device; using static ZigBee.Device.BindObj; using static ZigBee.Device.Panel; namespace Shared.Phone.UserCenter.Bind { public class PanelBindPage : FrameLayout, ZigBee.Common.IStatus { /// /// 按键模式接收 /// /// Common. public void Changed(CommonDevice common) { if (common.Type != ZigBee.Device.DeviceType.OnOffSwitch) { return; } Shared.Application.RunOnMainThread(() => { var dev = common as Panel; UpdateData(btnMode, dev); }); } /// /// 加载绑定界面 /// /// Gateway. /// Key. public void Show(ZigBee.Device.ZbGateway gateway, Panel key) { curentKey = key; curGateway = gateway; InitConfigurePage(gateway, key); } #region 绑定变量 //显示被绑定设备或场景的view VerticalScrolViewLayout midVerticalScrolViewLayout; int currentClusterID = 0; int currentMode = 0; Panel curentKey; ZbGateway curGateway; /// /// 按键中被绑定的表 /// public static System.Collections.Generic.List bindList = new System.Collections.Generic.List { }; //Spinner spinnerMode;//当前模式显示控件 RowSecondRightTextView btnMode;//当前模式显示控件 FrameLayout inVerticalscrolView;//加场景或设备的view bool isBindScene = false; /// /// 获取所有房间的所有场景 /// /// All room scene UIL ist. /// /// 本地设备列表 /// public static System.Collections.Generic.List list = new System.Collections.Generic.List(); //本地场景列表 public static System.Collections.Generic.List scList = new System.Collections.Generic.List { }; //按键支持当私有模式列表 private static System.Collections.Generic.List priFunList = new System.Collections.Generic.List { }; /// /// 按键配置的目标列表 /// List targetList = new List(); #endregion /// /// 按键配置 /// /// Gateway. /// Key. async void InitConfigurePage(ZigBee.Device.ZbGateway gateway, Panel key) { bindList.Clear(); #region topFrameLayout (只有UI,无数据处理) var topFrameLayout = new FrameLayout() { Height = Application.GetRealHeight(220), BackgroundColor = Shared.Common.ZigbeeColor.Current.GXCTopViewBackgroundColor, }; this.AddChidren(topFrameLayout); var titleFrameLayout = new FrameLayout() { Y = Application.GetRealHeight(80), Height = Application.GetRealHeight(140), BackgroundColor = Shared.Common.ZigbeeColor.Current.GXCTopViewBackgroundColor, }; topFrameLayout.AddChidren(titleFrameLayout); var title = new Button() { TextAlignment = TextAlignment.Center, Text = key.DeviceInfo.DeviceName, TextColor = Shared.Common.ZigbeeColor.Current.GXCTextBlackColor, Width = Application.GetRealWidth(1080 - 500), Gravity = Gravity.CenterHorizontal, }; titleFrameLayout.AddChidren(title); var back = new Button() { X = Application.GetRealWidth(50), Height = Application.GetRealHeight(100), Width = Application.GetRealWidth(100), UnSelectedImagePath = "Item/Back.png", SelectedImagePath = "Item/BackOn.png", Gravity = Gravity.CenterVertical, }; titleFrameLayout.AddChidren(back); #endregion #region middleFrameLayout (只有UI,无数据处理) #region modeFrameLayout var midFrameLayout = new FrameLayout() { Width = LayoutParams.MatchParent, Height = Application.GetRealHeight(1920 - 220), Y = topFrameLayout.Bottom, BackgroundColor = Shared.Common.ZigbeeColor.Current.GXCBackgroundColor, }; this.AddChidren(midFrameLayout); var modeFrameLayout = new FrameLayout() { Width = LayoutParams.MatchParent, Height = Application.GetRealHeight(170), BackgroundColor = Shared.Common.ZigbeeColor.Current.GXCBackgroundColor, }; midFrameLayout.AddChidren(modeFrameLayout); var btnModeText = new Button() { X = Application.GetRealWidth(50), Width = Application.GetRealWidth(700), Height = Application.GetRealHeight(110), TextColor = ZigbeeColor.Current.GXCTextBlackColor, Text = Language.StringByID(R.MyInternationalizationString.ModeType), TextAlignment = TextAlignment.CenterLeft, TextSize = 16, Gravity = Gravity.CenterVertical, }; modeFrameLayout.AddChidren(btnModeText); btnMode = new RowSecondRightTextView(); btnMode.TextID = R.MyInternationalizationString.uNotHadSettion; btnMode.TextColor = UserCenterColor.Current.Gray; modeFrameLayout.AddChidren(btnMode); var btnRight = new RowRightIconView(); modeFrameLayout.AddChidren(btnRight); var line = new Button() { Y = modeFrameLayout.Bottom, Height = 1, BackgroundColor = ZigbeeColor.Current.GXCLineColor, }; midFrameLayout.AddChidren(line); #endregion #region addBindDevice FrameLayout (只有UI,无数据处理) var addBindDeviceFrameLayout = new FrameLayout() { Width = LayoutParams.MatchParent, Height = Application.GetRealHeight(170), Y = line.Bottom, BackgroundColor = Shared.Common.ZigbeeColor.Current.GXCBackgroundColor, }; midFrameLayout.AddChidren(addBindDeviceFrameLayout); var btnAddBindText = new Button() { X = Application.GetRealWidth(50), Width = Application.GetRealWidth(700), Height = Application.GetRealHeight(110), TextColor = ZigbeeColor.Current.GXCTextBlackColor, TextID = R.MyInternationalizationString.AddBindTargets, TextAlignment = TextAlignment.CenterLeft, TextSize = 16, Gravity = Gravity.CenterVertical }; addBindDeviceFrameLayout.AddChidren(btnAddBindText); var btnAddBind = new Button() { X = Application.CurrentWidth - Application.GetRealWidth(150), Width = Application.GetMinRealAverage(110), Height = Application.GetMinRealAverage(110), UnSelectedImagePath = "Bind/BindAdd.png", SelectedImagePath = "Bind/BindAddOn.png", Gravity = Gravity.CenterVertical }; addBindDeviceFrameLayout.AddChidren(btnAddBind); var line1 = new Button() { Y = addBindDeviceFrameLayout.Bottom, Height = 1, BackgroundColor = ZigbeeColor.Current.GXCLineColor, }; midFrameLayout.AddChidren(line1); midVerticalScrolViewLayout = new VerticalScrolViewLayout() { Y = line1.Bottom, Height = Application.GetRealHeight(1920 - 620), }; midFrameLayout.AddChidren(midVerticalScrolViewLayout); #endregion #endregion #region 处理事件 (数据处理) back.MouseUpEventHandler += (sender, e) => { list.Clear(); scList.Clear(); this.RemoveFromParent(); }; EventHandler hander = async (sender, e) => { var oldCluster = currentClusterID; if(priFunList==null) { try { CommonPage.Loading.Start(""); KeyModeList(key); } catch { } finally { CommonPage.Loading.Hide(); } } if (priFunList != null) { PickerView.Show(priFunList, ModeSelectAction); }else{ new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.NoModeSupport), Direction = AMPopTipDirection.Up, CloseTime = 2 }.Show(btnMode); } }; btnMode.MouseUpEventHandler += hander; btnRight.MouseUpEventHandler += hander; btnModeText.MouseUpEventHandler += hander; modeFrameLayout.MouseUpEventHandler += hander; btnAddBind.MouseUpEventHandler += (sender, e) => { if (currentClusterID == 0) { new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.KeyConfiguration), Direction = AMPopTipDirection.Up, CloseTime = 2 }.Show(btnAddBind); return; } bool isExistScene = false; bool isExistDevice = false; foreach (var sc in PanelBindPage.bindList) { if (sc.BindType == 2) { isExistScene = true; } else { isExistDevice = true; } } if (currentMode != 100) { var selectDeviceList = new List(); foreach (var dev in PanelBindPage.bindList) { string mainkey = Common.LocalDevice.Current.GetDeviceMainKeys(dev.BindMacAddr, dev.BindEpoint); selectDeviceList.Add(mainkey); } var listShowDevice = new List(); foreach (var device in PanelBindPage.list) { if (SupportDevice(device, currentClusterID) == false) { continue; } //如果已经被绑定过了的设备,则不在列表中进行显示 string mainkey = Common.LocalDevice.Current.GetDeviceMainKeys(device); if (selectDeviceList.Contains(mainkey) == true) { continue; } listShowDevice.Add(device); } var form = new SelectDeviceForm(); form.AddForm(form, listShowDevice, selectDeviceList, false); form.SetTitleText(Language.StringByID(R.MyInternationalizationString.AddBindTargets)); form.ActionSelectDevice += (async (devList) => { if (devList == null || devList.Count == 0) { return; } //执行目标绑定 var result = await Common.LocalDevice.Current.BindDeviceTarget(key, devList, currentClusterID); if (result != null && result.Count > 0) { bindList.Clear(); try { var getBindList = await key.GetDeviceBindAsync(); if (getBindList != null) { if (getBindList.getAllBindResponseData.BindList != null) { foreach (var b in getBindList.getAllBindResponseData.BindList) { if (b.BindCluster == currentClusterID) { bindList.Add(b); } } } } } catch { } //绑定表刷新 RefreshList(gateway, key); } }); } else { if (isExistScene) { var addBindTargetsPage = new Shared.Phone.UserCenter.Bind.AddBindTargetsPage(); Shared.Phone.UserView.HomePage.Instance.AddChidren(addBindTargetsPage); Shared.Phone.UserView.HomePage.Instance.PageIndex += 1; addBindTargetsPage.Show(key, currentClusterID, false); } else { BindInfo.AddBindTarget(key, currentClusterID, currentMode); } } }; //模式刷新 UpdateData(btnMode, key); //绑定表数据初始化(被绑定的设备列表,场景列表和设备列表) try { list.Clear(); scList.Clear(); priFunList.Clear(); foreach (var dev in Shared.Common.LocalDevice.Current.listAllDevice) { list.Add(dev); } scList = Shared.Common.Room.AllRoomSceneUIList; CommonPage.Loading.Start(""); KeyModeList(key); } catch { } finally { CommonPage.Loading.Hide(); } //绑定表刷新 RefreshList(gateway, key); #endregion } /// /// 按键绑定表显示 /// /// Gateway. /// Key. void RefreshList(ZigBee.Device.ZbGateway gateway, Panel key) { midVerticalScrolViewLayout.RemoveAll(); AddBindTargetsPage.action += (obj) => { bindList = obj; RefreshList(gateway, key); }; foreach (var bindDevice in bindList) { #region 绑定表UI显(无数据处理) var rowLayout = new RowLayout() { Height = Application.GetRealHeight(170), }; midVerticalScrolViewLayout.AddChidren(rowLayout); var devicePic = new Button() { X = Application.GetRealWidth(50), Width = Application.GetMinRealAverage(110), Height = Application.GetMinRealAverage(110), Gravity = Gravity.CenterVertical, BackgroundColor = ZigbeeColor.Current.DialogTitleColor, }; rowLayout.AddChidren(devicePic); var btnBindName = new Button() { Width = Application.GetRealWidth(500 - 120), X = devicePic.Right + Application.GetRealWidth(20), TextColor = Shared.Common.ZigbeeColor.Current.TextBlack, TextAlignment = TextAlignment.CenterLeft, }; rowLayout.AddChidren(btnBindName); var btnDel = new Button() { TextColor = Shared.Common.ZigbeeColor.Current.GXCTextWhiteColor, X = btnBindName.Right, TextID = R.MyInternationalizationString.Delete, BackgroundColor = Shared.Common.ZigbeeColor.Current.DelRowLayout, }; rowLayout.AddRightView(btnDel); #endregion #region 绑定数据处理 //被绑定设备图片 foreach (var dev in list) { if (bindDevice.BindMacAddr == dev.DeviceAddr && bindDevice.BindEpoint == dev.DeviceEpoint) { devicePic.UnSelectedImagePath = $"Device/{dev.Type.ToString()}.png"; } } //被绑定设备的场景图片 foreach (var sc in scList) //foreach (var sc in ZbGateway.AllSceneList) { if (sc.ScenesId == bindDevice.BindScenesId) { devicePic.UnSelectedImagePath = "Item/Scene.png"; } } //被绑定目标名称 if (bindDevice.ESName == "") { btnBindName.TextID = R.MyInternationalizationString.Unknown; } else { btnBindName.Text = bindDevice.ESName; } //删除事件处理 btnDel.MouseUpEventHandler += async (sender, e) => { var delDevice = new DelDeviceBindData(); delDevice.DeviceAddr = key.DeviceAddr; delDevice.Epoint = key.DeviceEpoint; if (bindDevice.BindType == 0 || bindDevice.BindType == 1) { var removeDevice = new RemoveBindListObj(); removeDevice.BindCluster = bindDevice.BindCluster; removeDevice.BindType = 0; removeDevice.BindMacAddr = bindDevice.BindMacAddr; removeDevice.BindEpoint = bindDevice.BindEpoint; delDevice.RemoveBindList.Add(removeDevice); } else if (bindDevice.BindType == 2) { var removeDevice = new RemoveBindListObj(); removeDevice.BindCluster = bindDevice.BindCluster; removeDevice.BindType = 1; removeDevice.BindScenesId = bindDevice.BindScenesId; delDevice.RemoveBindList.Add(removeDevice); } try { CommonPage.Loading.Start(""); var delResult = new DelDeviceBindResponseAllData(); delResult = await key.DelDeviceBindAsync(delDevice); if (delResult.delDeviceBindResponseData?.RemoveBindList != null) { foreach (var re in delResult.delDeviceBindResponseData.RemoveBindList) { switch (re.Result) { case 0: bindList.Remove(bindDevice); RefreshList(gateway, key); break; case 1: bindList.Clear(); try { CommonPage.Loading.Start(""); var getBindList = await key.GetDeviceBindAsync(); if (getBindList != null) { if (getBindList.getAllBindResponseData.BindList != null) { foreach (var b in getBindList.getAllBindResponseData.BindList) { if (b.BindCluster == currentClusterID) { bindList.Add(b); } } } } } catch { } finally { CommonPage.Loading.Hide(); } RefreshList(gateway, key); break; case 4: if (delResult.removeBindResultResponseData != null) { if (delResult.removeBindResultResponseData.Result == 0) { bindList.Remove(bindDevice); RefreshList(gateway, key); } else { new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.RemoveFailed), Direction = AMPopTipDirection.Up, CloseTime = 2 }.Show(btnDel); } } break; default: break; } } } } catch { } finally { CommonPage.Loading.Hide(); } }; #endregion } } /// /// 选择需要绑定的设备和场景 /// /// Gateway. /// Key. /// Action. void BindDevice(ZigBee.Device.ZbGateway gateway, Panel key) { #region 绑定的设备和场景Dialog UI var dialog = new Dialog(); var dialogBodyView = new FrameLayout() { Width = Application.GetRealWidth(753), Height = Application.GetRealHeight(946 - 50), BackgroundColor = ZigbeeColor.Current.DialogColor, Radius = 5, BorderWidth = 0, Gravity = Gravity.Center }; dialog.AddChidren(dialogBodyView); var btnTitle = new Button() { Height = Application.GetRealHeight(119), TextAlignment = TextAlignment.Center, TextID = R.MyInternationalizationString.BindDevice, BackgroundColor = ZigbeeColor.Current.DialogTitleColor, TextSize = 20, }; dialogBodyView.AddChidren(btnTitle); var BindTypeView = new FrameLayout() { Height = Application.GetRealHeight(110), BackgroundColor = ZigbeeColor.Current.DialogSubTitleColor, Y = btnTitle.Bottom, }; dialogBodyView.AddChidren(BindTypeView); var bindVerticalScrolView = new VerticalScrolViewLayout() { Height = Application.GetRealHeight(946 - 240 - 180), Width = Application.GetRealWidth(753), Y = BindTypeView.Bottom, }; dialogBodyView.AddChidren(bindVerticalScrolView); inVerticalscrolView = new FrameLayout(); bindVerticalScrolView.AddChidren(inVerticalscrolView); var btnDevice = new Button() { Width = Application.GetRealWidth(376), TextSize = 16, SelectedTextColor = Shared.Common.ZigbeeColor.Current.SelectedTextColor, TextColor = Shared.Common.ZigbeeColor.Current.TextColor, TextID = R.MyInternationalizationString.BindDevice, IsSelected = !isBindScene, }; BindTypeView.AddChidren(btnDevice); var btnScene = new Button() { Width = Application.GetRealWidth(376), X = btnDevice.Right, TextSize = 16, SelectedTextColor = Shared.Common.ZigbeeColor.Current.SelectedTextColor, TextColor = Shared.Common.ZigbeeColor.Current.TextColor, TextID = R.MyInternationalizationString.BindScene, IsSelected = isBindScene, }; BindTypeView.AddChidren(btnScene); var btnLine = new Button() { Width = 1, Height = Application.GetRealHeight(119) - 1, BackgroundColor = Shared.Common.ZigbeeColor.Current.DialogTitleLine, X = btnDevice.Right, Y = 1, }; BindTypeView.AddChidren(btnLine); var bottomView = new FrameLayout() { Y = dialogBodyView.Height - Application.GetRealHeight(119), Height = Application.GetRealHeight(119), BackgroundColor = Shared.Common.ZigbeeColor.Current.DialogTitleColor, }; dialogBodyView.AddChidren(bottomView); var btnBack = new Button() { Width = Application.GetRealWidth(119), Height = Application.GetRealHeight(119), UnSelectedImagePath = "Bind/DialogBack.png", SelectedImagePath = "Bind/DialogBackOn.png", }; bottomView.AddChidren(btnBack); btnBack.MouseUpEventHandler += (sender1, e1) => { dialog.Close(); }; var btnLineH = new Button() { Width = 1, Height = LayoutParams.MatchParent, X = btnBack.Right, BackgroundColor = Shared.Common.ZigbeeColor.Current.DialogColor, }; bottomView.AddChidren(btnLineH); var btnConfigureSave = new Button() { Width = Application.GetRealWidth(753 - 120), X = btnLineH.Right, TextID = R.MyInternationalizationString.Save, BackgroundColor = ZigbeeColor.Current.DialogTitleColor, TextAlignment = TextAlignment.Center, TextSize = 16, }; bottomView.AddChidren(btnConfigureSave); InitDeviceOrSceneView(true, key, inVerticalscrolView, (obj) => { Refresh(); }); dialog.Show(); #endregion #region 事件和数据处理 //保存处理事件(添加场景和设备) btnConfigureSave.MouseUpEventHandler += async (sender, e) => { var addBindeDev = new AddBindData(); addBindeDev.DeviceAddr = key.DeviceAddr; addBindeDev.Epoint = key.DeviceEpoint; foreach (var de in targetList) { if (de.DeviceAddr != null) { var addBindInfo = new AddBindListObj(); addBindInfo.BindType = 0; addBindInfo.BindCluster = currentClusterID; addBindInfo.BindMacAddr = de.DeviceAddr; addBindInfo.BindEpoint = de.DeviceEpoint; addBindeDev.BindList.Add(addBindInfo); } else { var addBindInfo = new AddBindListObj(); addBindInfo.BindType = 1; addBindInfo.BindCluster = currentClusterID; var sc1 = (SceneUI)de; addBindInfo.BindScenesId = sc1.ScenesId; addBindeDev.BindList.Add(addBindInfo); } } try { CommonPage.Loading.Start(""); var dev = new AddedDeviceBindResponseAllData(); dev = await key.AddDeviceBindAsync(addBindeDev); foreach (var ab in dev.addedDeviceBindResponseData?.BindList) { switch (ab.Result) { case 0: bindList.Add((BindListResponseObj)ab); for (int i = 0; i < targetList.Count; i++) { var de = targetList[i]; var sc1 = new SceneUI(); if (de.DeviceAddr == null) { sc1 = (SceneUI)de; if (sc1.ScenesId == ab.BindScenesId) { targetList.RemoveAt(i); i--; } } } RefreshList(gateway, key); break; case 1: new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindErrorAbsence), Direction = AMPopTipDirection.Up, CloseTime = 2 }.Show(btnConfigureSave); break; case 2: switch (dev.addBindResultResponseData?.Result) { case 0: bindList.Add((BindListResponseObj)ab); for (int i = 0; i < targetList.Count; i++) { var de = targetList[i]; if (de.DeviceAddr == ab.BindMacAddr && de.DeviceEpoint == ab.BindEpoint) { targetList.RemoveAt(i); i--; } } RefreshList(gateway, key); break; case 140: new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindFull), Direction = AMPopTipDirection.Up, CloseTime = 2 }.Show(btnConfigureSave); break; default: new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindFailed), Direction = AMPopTipDirection.Up, CloseTime = 2 }.Show(btnConfigureSave); break; } break; case 3: new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindErrorExisted), Direction = AMPopTipDirection.Up, CloseTime = 2 }.Show(btnConfigureSave); break; case 4: new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindFailed), Direction = AMPopTipDirection.Up, CloseTime = 2 }.Show(btnConfigureSave); break; default: break; } } } catch { } finally { CommonPage.Loading.Hide(); } }; //设备事件 btnDevice.MouseUpEventHandler += (sender, e) => { btnDevice.IsSelected = true; btnScene.IsSelected = false; isBindScene = false; InitDeviceOrSceneView(true, key, inVerticalscrolView, (obj) => { Refresh(); }); }; //场景事件 btnScene.MouseUpEventHandler += (sender, e) => { btnScene.IsSelected = true; btnDevice.IsSelected = false; isBindScene = false; InitDeviceOrSceneView(false, key, inVerticalscrolView, (obj) => { Refresh(); }); }; #endregion } /// /// 匹配当前模式的设备和场景,并选择绑定 /// /// If set to true is device. /// Hdl button. /// In verticalscrol view. /// Action. async void InitDeviceOrSceneView(bool isDevice, Panel hdlButton, FrameLayout inVerticalscrolView, Action action) { inVerticalscrolView.RemoveAll(); if (isDevice) { inVerticalscrolView.Height = Application.GetRealHeight(946 - 240); if (ZbGateway.MainGateWay == null) { return; } int btnDeviceIndex = 0; int i = 0; foreach (var device in list) { foreach (var clu in device.DeviceInfo?.InClusterList) { if (clu.InCluster == currentClusterID) { i++; var btnEquipment = new Button() { Width = (inVerticalscrolView.Width - Application.GetRealWidth(29) - Application.GetRealWidth(50)) / 2, Height = Application.GetRealHeight(90), X = Application.GetRealHeight(30), Y = Application.GetRealHeight(10), TextAlignment = TextAlignment.Center, BackgroundColor = Shared.Common.ZigbeeColor.Current.ButtonColor, SelectedBackgroundColor = Shared.Common.ZigbeeColor.Current.SelectedColor, TextColor = Shared.Common.ZigbeeColor.Current.TextColor, Text = i.ToString(), Radius = 10, }; //本地设备掉线,不显示 //if (device.DeviceInfo.IsOnline == 0) //{ // Console.WriteLine("length loss"); // continue; //} if (btnDeviceIndex < 2) { btnEquipment.X = btnDeviceIndex * (btnEquipment.Width + Application.GetRealWidth(15)) + Application.GetRealWidth(32); btnEquipment.Y = Application.GetRealHeight(10); btnDeviceIndex++; } else { btnEquipment.X = btnDeviceIndex % 2 * (btnEquipment.Width + Application.GetRealWidth(15)) + Application.GetRealWidth(31); btnEquipment.Y = (int)btnDeviceIndex / 2 * (btnEquipment.Height + Application.GetRealHeight(10)) + Application.GetRealHeight(10); btnDeviceIndex++; } if (device.DeviceInfo.DeviceName == null) { btnEquipment.Text = device.DeviceAddr + device.DeviceEpoint; } else { btnEquipment.Text = device.DeviceInfo.DeviceName; } btnEquipment.Tag = device; inVerticalscrolView.AddChidren(btnEquipment); foreach (var bindedDev in bindList) { if (device.DeviceAddr == bindedDev.BindMacAddr && device.DeviceEpoint == bindedDev.BindEpoint) { btnEquipment.IsSelected = true; btnEquipment.TextColor = ZigbeeColor.Current.SelectedTextColor; } } if (btnEquipment.IsSelected == true) { if (targetList != null) { targetList.Remove(device); } } btnEquipment.MouseUpEventHandler += (sendere, ee) => { btnEquipment.IsSelected = !btnEquipment.IsSelected; if (btnEquipment.IsSelected) { targetList.Add(device); } else { if (targetList != null) { targetList.Remove(device); } } }; } } } } else { inVerticalscrolView.Height = Application.GetRealHeight(946 - 240); int btnDeviceIndex = 0; int i = 0; foreach (var scene in scList) { i++; var btnEquipment = new Button() { Width = (inVerticalscrolView.Width - Application.GetRealWidth(29) - Application.GetRealWidth(50)) / 2, Height = Application.GetRealHeight(90), X = Application.GetRealHeight(30), Y = Application.GetRealHeight(10), TextAlignment = TextAlignment.Center, BackgroundColor = Shared.Common.ZigbeeColor.Current.ButtonColor, SelectedBackgroundColor = Shared.Common.ZigbeeColor.Current.SelectedColor, TextColor = Shared.Common.ZigbeeColor.Current.TextColor, Text = i.ToString(), Radius = 10, }; if (btnDeviceIndex < 2) { btnEquipment.X = btnDeviceIndex * (btnEquipment.Width + Application.GetRealWidth(15)) + Application.GetRealWidth(32); btnEquipment.Y = Application.GetRealHeight(10); btnDeviceIndex++; } else { btnEquipment.X = btnDeviceIndex % 2 * (btnEquipment.Width + Application.GetRealWidth(15)) + Application.GetRealWidth(31); btnEquipment.Y = (int)btnDeviceIndex / 2 * (btnEquipment.Height + Application.GetRealHeight(10)) + Application.GetRealHeight(10); btnDeviceIndex++; } if (scene.SceneName == null) { btnEquipment.Text = Language.StringByID(R.MyInternationalizationString.Unknown); } else { btnEquipment.Text = scene.SceneName; } btnEquipment.Tag = scene; inVerticalscrolView.AddChidren(btnEquipment); foreach (var bindedSc in bindList) { if (scene.ScenesId == bindedSc.BindScenesId) { btnEquipment.IsSelected = true; btnEquipment.TextColor = ZigbeeColor.Current.SelectedTextColor; } } if (btnEquipment.IsSelected == true) { if (targetList != null) { targetList.Remove(scene); } } btnEquipment.MouseUpEventHandler += (sendere, ee) => { btnEquipment.IsSelected = !btnEquipment.IsSelected; if (btnEquipment.IsSelected) { targetList.Add(scene); } else { if (targetList != null) { targetList.Remove(scene); } } }; } } } /// /// 按键绑定更新 /// /// Button mode text. /// Key. public void UpdateType(Button btnText, int curID) { switch (curID) { case 100: btnText.TextID = R.MyInternationalizationString.OnOffOn; currentClusterID = 6; currentMode = 100; break; case 101: btnText.TextID = R.MyInternationalizationString.OnOffoFF; currentClusterID = 6; currentMode = 101; break; case 102: btnText.TextID = R.MyInternationalizationString.OnOffOnOff; currentClusterID = 6; currentMode = 102; break; case 200: btnText.TextID = R.MyInternationalizationString.LevelStepUp; currentClusterID = 8; currentMode = 200; break; case 201: btnText.TextID = R.MyInternationalizationString.LevelStepDown; currentClusterID = 8; currentMode = 201; break; case 202: btnText.TextID = R.MyInternationalizationString.LevelStepUpDown; currentClusterID = 8; currentMode = 202; break; case 300: btnText.TextID = R.MyInternationalizationString.WcdUp; currentClusterID = 258; currentMode = 300; break; case 301: btnText.TextID = R.MyInternationalizationString.WcdDown; currentClusterID = 258; currentMode = 301; break; case 302: btnText.TextID = R.MyInternationalizationString.WcdStop; currentClusterID = 258; currentMode = 302; break; case 303: btnText.TextID = R.MyInternationalizationString.WcdUpStop; currentClusterID = 258; currentMode = 303; break; case 304: btnText.TextID = R.MyInternationalizationString.WcdDownStop; currentClusterID = 258; currentMode = 304; break; default: btnText.TextID = R.MyInternationalizationString.PanelCurrentMode; currentClusterID = 258; break; } } /// /// 按键绑定更新 /// /// Button mode text. /// Key. public void UpdateData(Button btnText, Panel key) { switch (key.panelMode) { case 100: btnText.TextID = R.MyInternationalizationString.OnOffOn; currentClusterID = 6; currentMode = 100; break; case 101: btnText.TextID = R.MyInternationalizationString.OnOffoFF; currentClusterID = 6; currentMode = 101; break; case 102: btnText.TextID = R.MyInternationalizationString.OnOffOnOff; currentClusterID = 6; currentMode = 102; break; case 200: btnText.TextID = R.MyInternationalizationString.LevelStepUp; currentClusterID = 8; currentMode = 200; break; case 201: btnText.TextID = R.MyInternationalizationString.LevelStepDown; currentClusterID = 8; currentMode = 201; break; case 202: btnText.TextID = R.MyInternationalizationString.LevelStepUpDown; currentClusterID = 8; currentMode = 202; break; case 300: btnText.TextID = R.MyInternationalizationString.WcdUp; currentClusterID = 258; currentMode = 300; break; case 301: btnText.TextID = R.MyInternationalizationString.WcdDown; currentClusterID = 258; currentMode = 301; break; case 302: btnText.TextID = R.MyInternationalizationString.WcdStop; currentClusterID = 258; currentMode = 302; break; case 303: btnText.TextID = R.MyInternationalizationString.WcdUpStop; currentClusterID = 258; currentMode = 303; break; case 304: btnText.TextID = R.MyInternationalizationString.WcdDownStop; currentClusterID = 258; currentMode = 304; break; default: btnText.TextID = R.MyInternationalizationString.PanelCurrentMode; currentClusterID = 258; break; } } /// /// 模式选择Action事件 /// /// private async void ModeSelectAction(string value) { var temp = new Panel.SetWritableValueResponAllData(); var oldCluster = currentClusterID; if (curentKey == null|| curGateway==null) { return; } //白天 if (value == Language.StringByID(R.MyInternationalizationString.OnOffOn)) { btnMode.TextID = R.MyInternationalizationString.OnOffOn; temp = await curentKey.ConfigureHdlKeyValueAsync(KeyMode.OnOff_On); currentClusterID = 6; currentMode = 100; } else if (value == Language.StringByID(R.MyInternationalizationString.OnOffoFF)) { btnMode.TextID = R.MyInternationalizationString.OnOffoFF; temp = await curentKey.ConfigureHdlKeyValueAsync(KeyMode.OnOff_oFF); currentClusterID = 6; currentMode = 101; } else if (value == Language.StringByID(R.MyInternationalizationString.OnOffOnOff)) { btnMode.TextID = R.MyInternationalizationString.OnOffOnOff; temp = await curentKey.ConfigureHdlKeyValueAsync(KeyMode.OnOff_OnOff ); currentClusterID = 6; currentMode = 102; } else if (value == Language.StringByID(R.MyInternationalizationString.LevelStepUp)) { btnMode.TextID = R.MyInternationalizationString.LevelStepUp; temp = await curentKey.ConfigureHdlKeyValueAsync(KeyMode.Level_Step_Up ); currentClusterID = 8; currentMode = 200; } else if (value == Language.StringByID(R.MyInternationalizationString.LevelStepDown)) { btnMode.TextID = R.MyInternationalizationString.LevelStepDown; temp = await curentKey.ConfigureHdlKeyValueAsync(KeyMode.Level_Step_Down ); currentClusterID = 8; currentMode = 201; } else if (value == Language.StringByID(R.MyInternationalizationString.LevelStepUpDown)) { btnMode.TextID = R.MyInternationalizationString.LevelStepUpDown; temp = await curentKey.ConfigureHdlKeyValueAsync(KeyMode.Level_Step_Up_Down); currentClusterID = 8; currentMode = 202; } else if (value == Language.StringByID(R.MyInternationalizationString.WcdUp)) { btnMode.TextID = R.MyInternationalizationString.WcdUp; temp = await curentKey.ConfigureHdlKeyValueAsync(KeyMode.Wcd_Up ); currentClusterID = 258; currentMode = 300; } else if (value == Language.StringByID(R.MyInternationalizationString.WcdDown)) { btnMode.TextID = R.MyInternationalizationString.WcdDown; temp = await curentKey.ConfigureHdlKeyValueAsync(KeyMode.Wcd_Down ); currentClusterID = 258; currentMode = 301; } else if (value == Language.StringByID(R.MyInternationalizationString.WcdStop)) { btnMode.TextID = R.MyInternationalizationString.WcdStop; temp = await curentKey.ConfigureHdlKeyValueAsync(KeyMode.Wcd_Stop ); currentClusterID = 258; currentMode = 302; } else if (value == Language.StringByID(R.MyInternationalizationString.WcdUpStop)) { btnMode.TextID = R.MyInternationalizationString.WcdUpStop; temp = await curentKey.ConfigureHdlKeyValueAsync(KeyMode.Wcd_Up_Stop); currentClusterID = 258; currentMode = 303; } else if (value == Language.StringByID(R.MyInternationalizationString.WcdDownStop)) { btnMode.TextID = R.MyInternationalizationString.WcdDownStop; temp = await curentKey.ConfigureHdlKeyValueAsync(KeyMode.Wcd_Down_Stop); currentClusterID = 258; currentMode = 304; } System.Threading.Thread.Sleep(1000); if (temp.setWritableValueResponData?.Status != 0) { new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.ChangeBindMode), Direction = AMPopTipDirection.Up, CloseTime = 2 }.Show(btnMode); } else { if (oldCluster != currentClusterID) { bindList.Clear(); try { CommonPage.Loading.Start(""); var getBindList = await curentKey .GetDeviceBindAsync(); if (getBindList != null) { if (getBindList.getAllBindResponseData.BindList != null) { foreach (var b in getBindList.getAllBindResponseData.BindList) { if (b.BindCluster == currentClusterID) { bindList.Add(b); } } } } } catch { } finally { CommonPage.Loading.Hide(); } RefreshList(curGateway, curentKey); } } } /// /// 按键模式列表存储 /// /// Key. private async void KeyModeList(Panel key) { try { var resultMode = await BindInfo.CheckPanelKeyFunctionLevel3(key); var tempDeata = new PanelConfigureInfoResponAllData(); foreach (var mo in resultMode) { if (mo.Value == true) { switch (mo.Key) { case "场景:触发": priFunList.Add(Language.StringByID(R.MyInternationalizationString.OnOffOn)); break; case "开关:开": priFunList.Add(Language.StringByID(R.MyInternationalizationString.OnOffOn)); break; case "开关:关": priFunList.Add(Language.StringByID(R.MyInternationalizationString.OnOffoFF)); break; case "开关:切换": priFunList.Add(Language.StringByID(R.MyInternationalizationString.OnOffOnOff)); break; case "亮度:调大": priFunList.Add(Language.StringByID(R.MyInternationalizationString.LevelStepUp)); break; case "亮度:调小": priFunList.Add(Language.StringByID(R.MyInternationalizationString.LevelStepDown)); break; case "亮度:切换": priFunList.Add(Language.StringByID(R.MyInternationalizationString.LevelStepUpDown)); break; case "窗帘:开": priFunList.Add(Language.StringByID(R.MyInternationalizationString.WcdUp)); break; case "窗帘:关": priFunList.Add(Language.StringByID(R.MyInternationalizationString.WcdDown)); break; case "窗帘:停": priFunList.Add(Language.StringByID(R.MyInternationalizationString.WcdStop)); break; case "窗帘:上升停": priFunList.Add(Language.StringByID(R.MyInternationalizationString.WcdUpStop)); break; case "窗帘:下降停": priFunList.Add(Language.StringByID(R.MyInternationalizationString.WcdDownStop)); break; default: break; } } } tempDeata = await key.ReadPanelConfigureInfoAsync(); if (tempDeata.deviceStatusReportData != null) { if (tempDeata.deviceStatusReportData.CluterID == 6) { foreach (var attr in tempDeata.deviceStatusReportData.AttriBute) { var curID = attr.AttriButeData; UpdateType(btnMode, curID); var getBindList = await key.GetDeviceBindAsync(); if (getBindList != null) { if (getBindList.getAllBindResponseData.BindList != null) { foreach (var b in getBindList.getAllBindResponseData.BindList) { if (b.BindCluster == currentClusterID) { bindList.Add(b); } } } } } } } else { new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GetDataFailed), Direction = AMPopTipDirection.Up, CloseTime = 2 }.Show(btnMode); } } catch { } } /// /// 模式选择Action事件 /// /// private async void GetCurrentMode(ZigBee.Device.ZbGateway gateway, Panel key, string value, int oldCluster) { var temp = new Panel.SetWritableValueResponAllData(); //白天 if (value == Language.StringByID(R.MyInternationalizationString.OnOffOn)) { temp = await key.ConfigureHdlKeyValueAsync(KeyMode.OnOff_On); btnMode.Text = Language.StringByID(R.MyInternationalizationString.OnOffOn); } else if (value == Language.StringByID(R.MyInternationalizationString.OnOffoFF)) { temp = await key.ConfigureHdlKeyValueAsync(KeyMode.OnOff_oFF); btnMode.Text = Language.StringByID(R.MyInternationalizationString.OnOffoFF); } else if (value == Language.StringByID(R.MyInternationalizationString.OnOffOnOff)) { temp = await key.ConfigureHdlKeyValueAsync(KeyMode.OnOff_OnOff); btnMode.Text = Language.StringByID(R.MyInternationalizationString.OnOffOnOff); } else if (value == Language.StringByID(R.MyInternationalizationString.LevelStepUp)) { temp = await key.ConfigureHdlKeyValueAsync(KeyMode.Level_Step_Up); btnMode.Text = Language.StringByID(R.MyInternationalizationString.LevelStepUp); } else if (value == Language.StringByID(R.MyInternationalizationString.LevelStepDown)) { temp = await key.ConfigureHdlKeyValueAsync(KeyMode.Level_Step_Down); btnMode.Text = Language.StringByID(R.MyInternationalizationString.LevelStepDown); } else if (value == Language.StringByID(R.MyInternationalizationString.LevelStepUpDown)) { temp = await key.ConfigureHdlKeyValueAsync(KeyMode.Level_Step_Up_Down); btnMode.Text = Language.StringByID(R.MyInternationalizationString.LevelStepUpDown); } else if (value == Language.StringByID(R.MyInternationalizationString.WcdUp)) { temp = await key.ConfigureHdlKeyValueAsync(KeyMode.Wcd_Up); btnMode.Text = Language.StringByID(R.MyInternationalizationString.WcdUp); } else if (value == Language.StringByID(R.MyInternationalizationString.WcdDown)) { temp = await key.ConfigureHdlKeyValueAsync(KeyMode.Wcd_Down); btnMode.Text = Language.StringByID(R.MyInternationalizationString.WcdDown); } else if (value == Language.StringByID(R.MyInternationalizationString.WcdStop)) { temp = await key.ConfigureHdlKeyValueAsync(KeyMode.Wcd_Stop); btnMode.Text = Language.StringByID(R.MyInternationalizationString.WcdStop); } else if (value == Language.StringByID(R.MyInternationalizationString.WcdStop)) { temp = await key.ConfigureHdlKeyValueAsync(KeyMode.Wcd_Up_Stop); btnMode.Text = Language.StringByID(R.MyInternationalizationString.WcdStop); } else if (value == Language.StringByID(R.MyInternationalizationString.WcdDownStop)) { temp = await key.ConfigureHdlKeyValueAsync(KeyMode.Wcd_Down_Stop); btnMode.Text = Language.StringByID(R.MyInternationalizationString.WcdDownStop); } System.Threading.Thread.Sleep(1000); if (temp.setWritableValueResponData?.Status != 0) { new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.ChangeBindMode), Direction = AMPopTipDirection.Up, CloseTime = 2 }.Show(btnMode); } else { if (oldCluster != currentClusterID) { bindList.Clear(); try { CommonPage.Loading.Start(""); var getBindList = await key.GetDeviceBindAsync(); if (getBindList != null) { if (getBindList.getAllBindResponseData.BindList != null) { foreach (var b in getBindList.getAllBindResponseData.BindList) { if (b.BindCluster == currentClusterID) { bindList.Add(b); } } } } } catch { } finally { CommonPage.Loading.Hide(); } RefreshList(gateway, key); } } } /// /// 能绑定到按键的设备 /// /// /// public bool SupportDevice(CommonDevice device, int currentClusterID) { foreach (var data in device.InClusterList) { //拥有on/off功能的,才支持测试 if (data.InCluster == currentClusterID) { return true; } } return false; } public void ChangedILogicStatus(Logic logic) { } public void ChangedISceneStatus(Scene scene) { } /// /// 设备状态更新接口 /// public void DeviceInfoChange(CommonDevice common, string typeTag) { } } }