using System; using System.Collections.Generic; using Shared.Common; using ZigBee.Device; using static ZigBee.Device.BindObj; namespace Shared.Phone.UserCenter.DeviceBind { public class ChooseKeyModePage : BindCommonLayout, ZigBee.Common.IStatus { /// /// 按键模式接收 /// /// Common. public void Changed(CommonDevice common) { Shared.Application.RunOnMainThread(() => { }); } /// 构造函数 /// /// public ChooseKeyModePage(ZigBee.Device.Panel key, string deviceBindType, List targetSelectList) { this.currentKey = key; this.currentModeID = key.panelMode; this.oldModeID = key.panelMode; this.curDeviceBindType = deviceBindType; this.targetList = targetSelectList; } #region ◆ 变量申明__________________________ ZigBee.Device.Panel currentKey; //显示被绑定设备或场景的view VerticalScrolViewLayout midVerticalScrolViewLayout; HorizontalScrolViewLayout btnHorizontalScrolViewLayout; /// /// 按键配置的目标列表 /// List targetList = new List(); /// /// 新的按键配置目标列表中,目标实际存在按键中,此时要删掉的数据 /// List oldTargetList = new List(); List roomList = new List(); int currentClusterID = 6; public Action> action; int currentModeID = 0; int oldModeID = 0; string curDeviceBindType = ""; #endregion public void Show() { this.TopFrameLayout(this, Language.StringByID(R.MyInternationalizationString.ChooseKeyMode)); EventHandler eHandlerBack = (sender, e) => { RemoveFromParent(); }; this.btnBack.MouseUpEventHandler += eHandlerBack; this.btnBackFrameLayout.MouseUpEventHandler += eHandlerBack; this.MidFrameLayout(this); MidFrameLayoutContent(); } async void MidFrameLayoutContent() { #region UI midVerticalScrolViewLayout = new VerticalScrolViewLayout() { }; this.midFrameLayout.AddChidren(midVerticalScrolViewLayout); var bottomFrameLayout = new FrameLayout() { Width = LayoutParams.MatchParent, Height = Application.GetRealHeight(1737 - 1472), Y = Application.GetRealHeight(1472), }; this.midFrameLayout.AddChidren(bottomFrameLayout); var btnFinifh = new Button() { Width = Application.GetRealWidth(907), Height = Application.GetRealHeight(127), Gravity = Gravity.CenterHorizontal, Radius = (uint)Application.GetRealHeight(120) / 2, TextID = R.MyInternationalizationString.Save, BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack, TextColor = Shared.Common.ZigbeeColor.Current.XMWhite, TextSize = 16, }; bottomFrameLayout.AddChidren(btnFinifh); #endregion #region 数据处理 roomList = Shared.Common.Room.Lists; Shared.Common.Room curRoom = roomList[0]; int index = 0; KeyModeList(roomList[index]); btnFinifh.MouseUpEventHandler += async (sender, e) => { oldTargetList.Clear(); bool isFinish = false; btnFinifh.Enable = false; btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMUnSelect; try { CommonPage.Loading.Start(""); //1、清空所有目标 if (currentKey.bindList != null) { var bindResult = await currentKey.ClearBindInfoAsync(); if (bindResult != null && bindResult.clearBindInfoResponseData != null) { if (bindResult.clearBindInfoResponseData.Result != 0) { Application.RunOnMainThread(() => { new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindFailed), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh); }); CommonPage.Loading.Hide(); this.RemoveFromParent(); btnFinifh.Enable = true; btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack; return; } else { currentKey.bindList.Clear(); } } else { Application.RunOnMainThread(() => { new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh); }); CommonPage.Loading.Hide(); btnFinifh.Enable = true; btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack; return; } } //2、配置模式 Panel.SetWritableValueResponAllData temp = null; switch (currentModeID) { case 100: temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.OnOff_On); break; case 101: temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.OnOff_oFF); break; case 102: temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.OnOff_OnOff); break; case 200: temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Level_Step_Up); break; case 201: temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Level_Step_Down); break; case 203: temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Level_Up); break; case 204: temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Level_Down); break; case 205: temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Level_Up_Down); break; case 300: temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Wcd_Up); break; case 301: temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Wcd_Down); break; case 302: temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Wcd_Stop); break; case 303: temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Wcd_Up_Stop); break; case 304: temp = await currentKey.ConfigureHdlKeyValueAsync(Panel.KeyMode.Wcd_Down_Stop); break; } if (temp != null && temp.setWritableValueResponData != null) { if (temp.setWritableValueResponData.Status == 0) { //3、绑定新的数据 var addBindeDev = new AddBindData(); addBindeDev.DeviceAddr = currentKey.DeviceAddr; addBindeDev.Epoint = currentKey.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); } } var dev = new AddedDeviceBindResponseAllData(); dev = await currentKey.AddDeviceBindAsync(addBindeDev); if (dev.addedDeviceBindResponseData == null) { Application.RunOnMainThread(() => { new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh); }); btnFinifh.Enable = true; btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack; } else { foreach (var ab in dev.addedDeviceBindResponseData?.BindList) { switch (ab.Result) { case 0: currentKey.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.Id == ab.BindScenesId) { targetList.RemoveAt(i); i--; } } } //isFinish = true; break; case 1: Application.RunOnMainThread(() => { new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindErrorAbsence), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh); }); break; case 2: var abr = dev.addBindResultResponseData?.Result; switch (dev.addBindResultResponseData?.Result) { case 0: currentKey.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--; } } //isFinish = true; break; case 140: Application.RunOnMainThread(() => { new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindFull), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh); }); break; default: Application.RunOnMainThread(() => { new Tip() { MaxWidth = 150, Text = ab.ESName + Language.StringByID(R.MyInternationalizationString.BindUnknownError), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh); }); break; } break; case 3: Application.RunOnMainThread(() => { new Tip() { MaxWidth = 150, Text = ab.ESName + Language.StringByID(R.MyInternationalizationString.BindErrorExisted), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh); }); break; case 4: Application.RunOnMainThread(() => { new Tip() { MaxWidth = 150, Text = ab.ESName + Language.StringByID(R.MyInternationalizationString.BindFailed), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh); }); break; default: Application.RunOnMainThread(() => { new Tip() { MaxWidth = 150, Text = ab.ESName + Language.StringByID(R.MyInternationalizationString.BindUnknownError), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh); }); break; } } } } else { Application.RunOnMainThread(() => { new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.ChangeBindMode), Direction = AMPopTipDirection.Up, CloseTime = 2 }.Show(btnFinifh); }); btnFinifh.Enable = true; btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack; return; } } else { Application.RunOnMainThread(() => { new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.Up, CloseTime = 2 }.Show(btnFinifh); }); btnFinifh.Enable = true; btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack; return; } } catch { } finally { //if (isFinish) //{ // if (action != null) // { // action(currentKey.bindList); // } // this.RemoveFromParent(); //} //else //{ // this.RemoveFromParent(); //} if (action != null) { action(currentKey.bindList); } this.RemoveFromParent(); CommonPage.Loading.Hide(); btnFinifh.Enable = true; btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack; } }; #endregion } /// /// 按键模式显示 /// /// Gateway. /// Key. void KeyModeList(Shared.Common.Room curRoom) { midVerticalScrolViewLayout.RemoveAll(); switch (curDeviceBindType) { case "AddSwitch": currentClusterID = 6; AddSwitchMode(); break; case "AddDimmer": AddDimmerMode(); currentClusterID = 8; break; case "AddCurtain": currentClusterID = 258; AddCurtainMode(); break; } } public void AddSwitchMode() { Button oldMode = null; for (int i = 0; i < 3; i++) { #region 绑定表UI显(无数据处理) var rowLayout = new FrameLayout() { Height = Application.GetRealHeight(23 + 127), BackgroundColor = Shared.Common.ZigbeeColor.Current.XMWhite, }; midVerticalScrolViewLayout.AddChidren(rowLayout); var btnModeText = new Button() { Width = Application.GetRealWidth(821), Height = Application.GetRealHeight(60), X = Application.GetRealWidth(58), Y = Application.GetRealHeight(58), TextColor = Shared.Common.ZigbeeColor.Current.TextBlack, TextAlignment = TextAlignment.CenterLeft, }; rowLayout.AddChidren(btnModeText); var btnChoose = new Button() { Width = Application.GetRealWidth(60), Height = Application.GetRealHeight(60), X = Application.GetRealWidth(861 + 81), Y = Application.GetRealHeight(35), SelectedImagePath = "DoorLock/SelectedIcon.png", Visible = false, }; rowLayout.AddChidren(btnChoose); var line2 = new Button() { Y = rowLayout.Height - 1, X = Application.GetRealWidth(58), Width = Application.GetRealWidth(965), Height = 1, BackgroundColor = Shared.Common.ZigbeeColor.Current.XMRowLine, }; rowLayout.AddChidren(line2); #endregion if (i == 0) { btnModeText.Text = Language.StringByID(R.MyInternationalizationString.OnOffOn); } if (i == 1) { btnModeText.Text = Language.StringByID(R.MyInternationalizationString.OnOffoFF); } if (i == 2) { btnModeText.Text = Language.StringByID(R.MyInternationalizationString.OnOffOnOff); line2.Visible = false; } if ((currentKey.panelMode == 100) && i == 0) { btnChoose.IsSelected = true; btnChoose.Visible = true; oldMode = btnChoose; } else if ((currentKey.panelMode == 101) && i == 1) { btnChoose.IsSelected = true; btnChoose.Visible = true; oldMode = btnChoose; } else if ((currentKey.panelMode == 102) && i == 2) { btnChoose.IsSelected = true; btnChoose.Visible = true; oldMode = btnChoose; } EventHandler hander = async (sender, e) => { if (!btnChoose.IsSelected) { if (oldMode != null) { oldMode.IsSelected = false; oldMode.Visible = false; } oldMode = btnChoose; oldMode.IsSelected = true; oldMode.Visible = true; currentKey.CurrentSwitchMode = btnModeText.Text; if (btnModeText.Text == Language.StringByID(R.MyInternationalizationString.OnOffOn)) { currentModeID = 100; currentKey.panelMode = currentModeID; } else if (btnModeText.Text == Language.StringByID(R.MyInternationalizationString.OnOffoFF)) { currentModeID = 101; currentKey.panelMode = currentModeID; } else if (btnModeText.Text == Language.StringByID(R.MyInternationalizationString.OnOffOnOff)) { currentModeID = 102; currentKey.panelMode = currentModeID; } } }; rowLayout.MouseUpEventHandler += hander; btnModeText.MouseUpEventHandler += hander; btnChoose.MouseUpEventHandler += hander; } } public void AddDimmerMode() { Button oldMode = null; for (int i = 0; i < 5; i++) { #region 绑定表UI显(无数据处理) var rowLayout = new FrameLayout() { Height = Application.GetRealHeight(23 + 127), BackgroundColor = Shared.Common.ZigbeeColor.Current.XMWhite, }; midVerticalScrolViewLayout.AddChidren(rowLayout); var btnModeText = new Button() { Width = Application.GetRealWidth(821), Height = Application.GetRealHeight(60), X = Application.GetRealWidth(58), Y = Application.GetRealHeight(58), TextColor = Shared.Common.ZigbeeColor.Current.TextBlack, TextAlignment = TextAlignment.CenterLeft, }; rowLayout.AddChidren(btnModeText); var btnChoose = new Button() { Width = Application.GetRealWidth(60), Height = Application.GetRealHeight(60), X = Application.GetRealWidth(861 + 81), Y = Application.GetRealHeight(35), SelectedImagePath = "DoorLock/SelectedIcon.png", Visible = false, }; rowLayout.AddChidren(btnChoose); var line2 = new Button() { Y = rowLayout.Height - 1, X = Application.GetRealWidth(58), Width = Application.GetRealWidth(965), Height = 1, BackgroundColor = Shared.Common.ZigbeeColor.Current.XMRowLine, }; rowLayout.AddChidren(line2); #endregion if (i == 0) { btnModeText.Text = Language.StringByID(R.MyInternationalizationString.DimmerMode1); } if (i == 1) { btnModeText.Text = Language.StringByID(R.MyInternationalizationString.DimmerMode2); } if (i == 2) { btnModeText.Text = Language.StringByID(R.MyInternationalizationString.DimmerMode3); } if (i == 3) { btnModeText.Text = Language.StringByID(R.MyInternationalizationString.DimmerMode4); } if (i == 4) { btnModeText.Text = Language.StringByID(R.MyInternationalizationString.DimmerMode5); line2.Visible = false; } if ((currentKey.panelMode == 200) && i == 0) { btnChoose.IsSelected = true; btnChoose.Visible = true; oldMode = btnChoose; } else if ((currentKey.panelMode == 201) && i == 1) { btnChoose.IsSelected = true; btnChoose.Visible = true; oldMode = btnChoose; } else if ((currentKey.panelMode == 203) && i == 2) { btnChoose.IsSelected = true; btnChoose.Visible = true; oldMode = btnChoose; } else if ((currentKey.panelMode == 204) && i == 3) { btnChoose.IsSelected = true; btnChoose.Visible = true; oldMode = btnChoose; } else if ((currentKey.panelMode == 205) && i == 4) { btnChoose.IsSelected = true; btnChoose.Visible = true; oldMode = btnChoose; } EventHandler hander = (sender, e) => { if (!btnChoose.IsSelected) { if (oldMode != null) { oldMode.IsSelected = false; oldMode.Visible = false; } oldMode = btnChoose; oldMode.IsSelected = true; oldMode.Visible = true; currentKey.CurrentSwitchMode = btnModeText.Text; if (btnModeText.Text == Language.StringByID(R.MyInternationalizationString.DimmerMode1)) { currentModeID = 200; currentKey.panelMode = currentModeID; } else if (btnModeText.Text == Language.StringByID(R.MyInternationalizationString.DimmerMode2)) { currentModeID = 201; currentKey.panelMode = currentModeID; } else if (btnModeText.Text == Language.StringByID(R.MyInternationalizationString.DimmerMode3)) { currentModeID = 203; currentKey.panelMode = currentModeID; } else if (btnModeText.Text == Language.StringByID(R.MyInternationalizationString.DimmerMode4)) { currentModeID = 204; currentKey.panelMode = currentModeID; } else if (btnModeText.Text == Language.StringByID(R.MyInternationalizationString.DimmerMode5)) { currentModeID = 205; currentKey.panelMode = currentModeID; } } }; rowLayout.MouseUpEventHandler += hander; btnModeText.MouseUpEventHandler += hander; btnChoose.MouseUpEventHandler += hander; } } public void AddCurtainMode() { Button oldMode = null; for (int i = 0; i < 5; i++) { #region 绑定表UI显(无数据处理) var rowLayout = new FrameLayout() { Height = Application.GetRealHeight(23 + 127), BackgroundColor = Shared.Common.ZigbeeColor.Current.XMWhite, }; midVerticalScrolViewLayout.AddChidren(rowLayout); var btnModeText = new Button() { Width = Application.GetRealWidth(821), Height = Application.GetRealHeight(60), X = Application.GetRealWidth(58), Y = Application.GetRealHeight(58), TextColor = Shared.Common.ZigbeeColor.Current.TextBlack, TextAlignment = TextAlignment.CenterLeft, }; rowLayout.AddChidren(btnModeText); var btnChoose = new Button() { Width = Application.GetRealWidth(60), Height = Application.GetRealHeight(60), X = Application.GetRealWidth(861 + 81), Y = Application.GetRealHeight(35), SelectedImagePath = "DoorLock/SelectedIcon.png", Visible = false, }; rowLayout.AddChidren(btnChoose); var line2 = new Button() { Y = rowLayout.Height - 1, X = Application.GetRealWidth(58), Width = Application.GetRealWidth(965), Height = 1, BackgroundColor = Shared.Common.ZigbeeColor.Current.XMRowLine, }; rowLayout.AddChidren(line2); #endregion if (i == 0) { btnModeText.Text = Language.StringByID(R.MyInternationalizationString.WcdUp); } if (i == 1) { btnModeText.Text = Language.StringByID(R.MyInternationalizationString.WcdDown); } if (i == 2) { btnModeText.Text = Language.StringByID(R.MyInternationalizationString.WcdStop); } if (i == 3) { btnModeText.Text = Language.StringByID(R.MyInternationalizationString.WcdUpStop); } if (i == 4) { btnModeText.Text = Language.StringByID(R.MyInternationalizationString.WcdDownStop); line2.Visible = false; } if ((currentKey.panelMode == 300) && i == 0) { btnChoose.IsSelected = true; btnChoose.Visible = true; oldMode = btnChoose; } else if ((currentKey.panelMode == 301) && i == 1) { btnChoose.IsSelected = true; btnChoose.Visible = true; oldMode = btnChoose; } else if ((currentKey.panelMode == 302) && i == 2) { btnChoose.IsSelected = true; btnChoose.Visible = true; oldMode = btnChoose; } else if ((currentKey.panelMode == 303) && i == 3) { btnChoose.IsSelected = true; btnChoose.Visible = true; oldMode = btnChoose; } else if ((currentKey.panelMode == 304) && i == 4) { btnChoose.IsSelected = true; btnChoose.Visible = true; oldMode = btnChoose; } EventHandler hander = (sender, e) => { if (!btnChoose.IsSelected) { if (oldMode != null) { oldMode.IsSelected = false; oldMode.Visible = false; } oldMode = btnChoose; oldMode.IsSelected = true; oldMode.Visible = true; currentKey.CurrentSwitchMode = btnModeText.Text; if (btnModeText.Text == Language.StringByID(R.MyInternationalizationString.WcdUp)) { currentModeID = 300; currentKey.panelMode = currentModeID; } else if (btnModeText.Text == Language.StringByID(R.MyInternationalizationString.WcdDown)) { currentModeID = 301; currentKey.panelMode = currentModeID; } else if (btnModeText.Text == Language.StringByID(R.MyInternationalizationString.WcdStop)) { currentModeID = 302; currentKey.panelMode = currentModeID; } else if (btnModeText.Text == Language.StringByID(R.MyInternationalizationString.WcdUpStop)) { currentModeID = 303; currentKey.panelMode = currentModeID; } else if (btnModeText.Text == Language.StringByID(R.MyInternationalizationString.WcdDownStop)) { currentModeID = 304; currentKey.panelMode = currentModeID; } } }; rowLayout.MouseUpEventHandler += hander; btnModeText.MouseUpEventHandler += hander; btnChoose.MouseUpEventHandler += hander; } } public void DeviceInfoChange(CommonDevice common, string typeTag) { } public void ChangedILogicStatus(ZigBee.Device.Logic logic) { } public void ChangedISceneStatus(Scene scene) { } } }