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 { /// 构造函数 /// /// public ChooseKeyModePage(ZigBee.Device.Panel key, string deviceBindType, List targetSelectList) { this.currentKey = key; this.currentModeID = key.panelMode; this.curDeviceBindType = deviceBindType; this.targetList = targetSelectList; } #region 变量申明 /// /// 当前按键 /// ZigBee.Device.Panel currentKey; /// /// 中部刷新列表 /// VerticalScrolViewLayout midVerticalScrolViewLayout; /// /// 房间列表左右滑动布局 /// HorizontalScrolViewLayout btnHorizontalScrolViewLayout; /// /// 按键配置的目标列表 /// List targetList = new List(); /// /// 本地旧的选中列表 /// List oldTargetList = new List(); /// /// 当前簇ID /// int currentClusterID = 6; /// /// 回调绑定目标页面刷新 /// public Action> action; /// /// 当前模式ID /// int currentModeID = 0; /// /// 当前设备绑定类型 /// string curDeviceBindType = ""; /// /// 类型的具体模式列表 /// List typeDetailModeList = new List { }; #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, IsBold = true, }; bottomFrameLayout.AddChidren(btnFinifh); #endregion #region 数据处理 KeyModeList(); btnFinifh.MouseUpEventHandler += (sender, e) => { oldTargetList.Clear(); btnFinifh.Enable = false; btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMUnSelect; System.Threading.Tasks.Task.Run(() => { try { Application.RunOnMainThread(() => { CommonPage.Loading.Start(""); }); //1、清空所有目标 if (currentKey.bindList != null) { var bindResult = HdlDeviceBindLogic.Current.ClearBindInfoAsync(currentKey); if (bindResult != null && bindResult.clearBindInfoResponseData != null) { if (bindResult.clearBindInfoResponseData.Result != 0) { Application.RunOnMainThread(() => { btnFinifh.Enable = true; btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack; CommonPage.Loading.Hide(); new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindFailed), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh); }); return; } else { currentKey.bindList.Clear(); } } else { Application.RunOnMainThread(() => { btnFinifh.Enable = true; btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack; CommonPage.Loading.Hide(); new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime) + "(" + "5006" + ")", Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh); }); return; } } //2、配置模式 Panel.SetWritableValueResponAllData temp = null; switch (currentModeID) { case 100: temp = HdlDeviceBindLogic.Current.ConfigureHdlKeyValueAsync(currentKey, Panel.KeyMode.OnOff_On); break; case 101: temp = HdlDeviceBindLogic.Current.ConfigureHdlKeyValueAsync(currentKey, Panel.KeyMode.OnOff_oFF); break; case 102: temp = HdlDeviceBindLogic.Current.ConfigureHdlKeyValueAsync(currentKey, Panel.KeyMode.OnOff_OnOff); break; case 200: temp = HdlDeviceBindLogic.Current.ConfigureHdlKeyValueAsync(currentKey, Panel.KeyMode.Level_Step_Up); break; case 201: temp = HdlDeviceBindLogic.Current.ConfigureHdlKeyValueAsync(currentKey, Panel.KeyMode.Level_Step_Down); break; case 203: temp = HdlDeviceBindLogic.Current.ConfigureHdlKeyValueAsync(currentKey, Panel.KeyMode.Level_Up); break; case 204: temp = HdlDeviceBindLogic.Current.ConfigureHdlKeyValueAsync(currentKey, Panel.KeyMode.Level_Down); break; case 205: temp = HdlDeviceBindLogic.Current.ConfigureHdlKeyValueAsync(currentKey, Panel.KeyMode.Level_Up_Down); break; case 300: temp = HdlDeviceBindLogic.Current.ConfigureHdlKeyValueAsync(currentKey, Panel.KeyMode.Wcd_Up); break; case 301: temp = HdlDeviceBindLogic.Current.ConfigureHdlKeyValueAsync(currentKey, Panel.KeyMode.Wcd_Down); break; case 302: temp = HdlDeviceBindLogic.Current.ConfigureHdlKeyValueAsync(currentKey, Panel.KeyMode.Wcd_Stop); break; case 303: temp = HdlDeviceBindLogic.Current.ConfigureHdlKeyValueAsync(currentKey, Panel.KeyMode.Wcd_Up_Stop); break; case 304: temp = HdlDeviceBindLogic.Current.ConfigureHdlKeyValueAsync(currentKey, 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); } } //是亮度再次发6命令 if (currentClusterID == 8) { foreach (var de in targetList) { if (de.DeviceAddr != null) { var addBindInfo = new AddBindListObj(); addBindInfo.BindType = 0; addBindInfo.BindCluster = 6; addBindInfo.BindMacAddr = de.DeviceAddr; addBindInfo.BindEpoint = de.DeviceEpoint; addBindeDev.BindList.Add(addBindInfo); } } } var dev = new AddedDeviceBindResponseAllData(); dev = HdlDeviceBindLogic.Current.AddDeviceBindAsync(addBindeDev); if (dev != null && dev.addedDeviceBindResponseData != null) { if (dev.addedDeviceBindResponseData.Result == 0) { if (currentClusterID == 8) { foreach (var de in dev.addedDeviceBindResponseData.BindList) { if (de.BindCluster == 8) { currentKey.bindList.Add(de); } } } else { currentKey.bindList = dev.addedDeviceBindResponseData.BindList; } Application.RunOnMainThread(() => { if (action != null) { action(currentKey.bindList); } targetList.Clear(); this.RemoveFromParent(); btnFinifh.Enable = true; btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack; CommonPage.Loading.Hide(); }); } else if (dev.addedDeviceBindResponseData.Result == 1) { Application.RunOnMainThread(() => { btnFinifh.Enable = true; btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack; CommonPage.Loading.Hide(); new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindFailed), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh); }); return; } else { Application.RunOnMainThread(() => { btnFinifh.Enable = true; btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack; CommonPage.Loading.Hide(); new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindUnknownError), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh); }); return; } } else { Application.RunOnMainThread(() => { btnFinifh.Enable = true; btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack; CommonPage.Loading.Hide(); new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime) + "(" + "5001" + ")", Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh); }); return; } } else { Application.RunOnMainThread(() => { btnFinifh.Enable = true; btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack; CommonPage.Loading.Hide(); new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.ChangeBindMode), Direction = AMPopTipDirection.Up, CloseTime = 2 }.Show(btnFinifh); }); return; } } else { Application.RunOnMainThread(() => { btnFinifh.Enable = true; btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack; CommonPage.Loading.Hide(); new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime) + "(" + "120_ 6533" + ")", Direction = AMPopTipDirection.Up, CloseTime = 2 }.Show(btnFinifh); }); return; } } catch { Application.RunOnMainThread(() => { btnFinifh.Enable = true; btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack; CommonPage.Loading.Hide(); }); } }); }; #endregion } /// /// 按键模式显示 /// /// Gateway. /// Key. async private void KeyModeList() { midVerticalScrolViewLayout.RemoveAll(); switch (curDeviceBindType) { case "AddSwitch": currentClusterID = 6; typeDetailModeList = await GetAddSwitchMode(); if (typeDetailModeList == null) { new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime) + "(" + "0003_switch" + ")", Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance); } else { AddSwitchMode(); } break; case "AddDimmer": currentClusterID = 8; typeDetailModeList = await GetAddDimmerMode(); if (typeDetailModeList == null) { new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime) + "(" + "0003_dimmer" + ")", Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance); } else { AddDimmerMode(); } break; case "AddCurtain": currentClusterID = 258; typeDetailModeList = await GetAddCurtainMode(); if (typeDetailModeList == null) { new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime) + "(" + "0003_curtain" + ")", Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance); } else { AddCurtainMode(); } break; } } /// /// 获取开关具体类型 /// /// System.Threading.Tasks.Task> GetAddSwitchMode() { return System.Threading.Tasks.Task.Run(async () => { //如果当前是虚拟住宅 if (Common.Config.Instance.Home.IsVirtually == true) { typeDetailModeList.Clear(); return new List() { 100, 101, 102 }; } Application.RunOnMainThread(() => { CommonPage.Loading.Start(); }); typeDetailModeList.Clear(); List result3 = new List { }; try { //获取第三级功能 if (currentKey.privateFuncThirdLevelList.Count == 0 || currentKey.privateFuncThirdLevelList.Contains(100) == false || currentKey.privateFuncThirdLevelList.Contains(101) == false || currentKey.privateFuncThirdLevelList.Contains(102) == false) { result3 = await currentKey.GetPanelDeviceFunctionLevel3(256, 100); foreach (var l3 in result3) { currentKey.privateFuncThirdLevelList.Add(l3); } } else { if (currentKey.privateFuncThirdLevelList.Contains(100) == true) { result3.Add(100); } if (currentKey.privateFuncThirdLevelList.Contains(101) == true) { result3.Add(101); } if (currentKey.privateFuncThirdLevelList.Contains(102) == true) { result3.Add(102); } } } catch (Exception ex) { var aa = ex.Message; } finally { Application.RunOnMainThread(() => { CommonPage.Loading.Hide(); }); } return result3; }); } /// /// 获取调光具体类型 /// /// System.Threading.Tasks.Task> GetAddDimmerMode() { return System.Threading.Tasks.Task.Run(async () => { //如果当前是虚拟住宅 if (Common.Config.Instance.Home.IsVirtually == true) { typeDetailModeList.Clear(); return new List() { 200, 201, 203, 204, 205 }; } Application.RunOnMainThread(() => { CommonPage.Loading.Start(); }); typeDetailModeList.Clear(); List result3 = new List { }; try { //获取第三级功能 if (currentKey.privateFuncThirdLevelList.Count == 0 || currentKey.privateFuncThirdLevelList.Contains(200) == false || currentKey.privateFuncThirdLevelList.Contains(201) == false || currentKey.privateFuncThirdLevelList.Contains(203) == false || currentKey.privateFuncThirdLevelList.Contains(204) == false || currentKey.privateFuncThirdLevelList.Contains(205) == false) { result3 = await currentKey.GetPanelDeviceFunctionLevel3(256, 200); foreach (var l3 in result3) { currentKey.privateFuncThirdLevelList.Add(l3); } } else { if (currentKey.privateFuncThirdLevelList.Contains(200) == true) { result3.Add(200); } if (currentKey.privateFuncThirdLevelList.Contains(201) == true) { result3.Add(201); } if (currentKey.privateFuncThirdLevelList.Contains(203) == true) { result3.Add(203); } if (currentKey.privateFuncThirdLevelList.Contains(204) == true) { result3.Add(204); } if (currentKey.privateFuncThirdLevelList.Contains(205) == true) { result3.Add(205); } } } catch { } finally { Application.RunOnMainThread(() => { CommonPage.Loading.Hide(); }); } return result3; }); } /// /// 获取窗帘具体类型 /// /// System.Threading.Tasks.Task> GetAddCurtainMode() { Application.RunOnMainThread(() => { CommonPage.Loading.Start(); }); return System.Threading.Tasks.Task.Run(async () => { typeDetailModeList.Clear(); //如果当前是虚拟住宅 if (Common.Config.Instance.Home.IsVirtually == true) { Application.RunOnMainThread(() => { CommonPage.Loading.Hide(); }); typeDetailModeList.Clear(); return new List() { 300, 301, 302, 303, 304 }; } List result3 = new List { }; try { //获取第三级功能 if (currentKey.privateFuncThirdLevelList.Count == 0 || currentKey.privateFuncThirdLevelList.Contains(300) == false || currentKey.privateFuncThirdLevelList.Contains(301) == false || currentKey.privateFuncThirdLevelList.Contains(302) == false || currentKey.privateFuncThirdLevelList.Contains(303) == false || currentKey.privateFuncThirdLevelList.Contains(304) == false) { result3 = await currentKey.GetPanelDeviceFunctionLevel3(256, 300); foreach (var l3 in result3) { currentKey.privateFuncThirdLevelList.Add(l3); } } else { if (currentKey.privateFuncThirdLevelList.Contains(300) == true) { result3.Add(300); } if (currentKey.privateFuncThirdLevelList.Contains(301) == true) { result3.Add(301); } if (currentKey.privateFuncThirdLevelList.Contains(302) == true) { result3.Add(302); } if (currentKey.privateFuncThirdLevelList.Contains(303) == true) { result3.Add(303); } if (currentKey.privateFuncThirdLevelList.Contains(304) == true) { result3.Add(304); } } } catch { } finally { Application.RunOnMainThread(() => { CommonPage.Loading.Hide(); }); } return result3; }); } /// /// 添加开关模式 /// async private void AddSwitchMode() { if (typeDetailModeList == null) { //再次动态获取按键支持的类 typeDetailModeList = await GetAddSwitchMode(); if (typeDetailModeList == null) { Application.RunOnMainThread(() => { new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime) + "(" + "0003_switch" + ")", Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance); }); return; } } Button oldMode = null; int i = 0; foreach (var modeSwitchValue in typeDetailModeList) { #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, TextSize = 14, }; rowLayout.AddChidren(btnModeText); var btnChoose = new Button() { Width = Application.GetMinReal(60), Height = Application.GetMinReal(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 switch (modeSwitchValue) { case 100: btnModeText.Text = Language.StringByID(R.MyInternationalizationString.OnOffOn); break; case 101: btnModeText.Text = Language.StringByID(R.MyInternationalizationString.OnOffoFF); break; case 102: btnModeText.Text = Language.StringByID(R.MyInternationalizationString.OnOffOnOff); break; } if (i == typeDetailModeList.Count - 1) { 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; } else if ((currentKey.panelMode == 65535) && i == 0) { //默认第一个 btnChoose.IsSelected = true; btnChoose.Visible = true; oldMode = btnChoose; currentModeID = 100; currentKey.panelMode = currentModeID; } 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; 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; i++; } } /// /// 添加调光模式 /// async private void AddDimmerMode() { if (typeDetailModeList == null) { //再次动态获取按键支持的类 typeDetailModeList = await GetAddDimmerMode(); if (typeDetailModeList == null) { Application.RunOnMainThread(() => { new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime) + "(" + "0003_dimmer" + ")", Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance); }); return; } } Button oldMode = null; int i = 0; List typeDetailModeListTemp = new List { }; foreach (var modeSwitchValue in typeDetailModeList) { if (modeSwitchValue == 202) { continue; } typeDetailModeListTemp.Add(modeSwitchValue); } foreach (var modeSwitchValue in typeDetailModeListTemp) { #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, TextSize = 14, }; rowLayout.AddChidren(btnModeText); var btnChoose = new Button() { Width = Application.GetMinReal(60), Height = Application.GetMinReal(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 switch (modeSwitchValue) { case 200: btnModeText.Text = Language.StringByID(R.MyInternationalizationString.DimmerMode1); break; case 201: btnModeText.Text = Language.StringByID(R.MyInternationalizationString.DimmerMode2); break; case 203: btnModeText.Text = Language.StringByID(R.MyInternationalizationString.DimmerMode3); break; case 204: btnModeText.Text = Language.StringByID(R.MyInternationalizationString.DimmerMode4); break; case 205: btnModeText.Text = Language.StringByID(R.MyInternationalizationString.DimmerMode5); break; } if (i == typeDetailModeListTemp.Count - 1) { 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; } else if ((currentKey.panelMode == 65535) && i == 0) { //默认第一个 btnChoose.IsSelected = true; btnChoose.Visible = true; oldMode = btnChoose; currentModeID = 200; currentKey.panelMode = currentModeID; } EventHandler hander = (sender, e) => { if (!btnChoose.IsSelected) { if (oldMode != null) { oldMode.IsSelected = false; oldMode.Visible = false; } oldMode = btnChoose; oldMode.IsSelected = true; oldMode.Visible = true; 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; i++; } } /// /// 添加窗帘模式 /// async private void AddCurtainMode() { if (typeDetailModeList == null) { //再次动态获取按键支持的类 typeDetailModeList = await GetAddCurtainMode(); if (typeDetailModeList == null) { Application.RunOnMainThread(() => { new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime) + "(" + "0003_curtain" + ")", Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance); }); return; } } Button oldMode = null; int i = 0; foreach (var modeSwitchValue in typeDetailModeList) { #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, TextSize = 14, }; rowLayout.AddChidren(btnModeText); var btnChoose = new Button() { Width = Application.GetMinReal(60), Height = Application.GetMinReal(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 switch (modeSwitchValue) { case 300: btnModeText.Text = Language.StringByID(R.MyInternationalizationString.WcdUp); break; case 301: btnModeText.Text = Language.StringByID(R.MyInternationalizationString.WcdDown); break; case 302: btnModeText.Text = Language.StringByID(R.MyInternationalizationString.WcdStop); break; case 303: btnModeText.Text = Language.StringByID(R.MyInternationalizationString.WcdUpStop); break; case 304: btnModeText.Text = Language.StringByID(R.MyInternationalizationString.WcdDownStop); break; } if (i == typeDetailModeList.Count - 1) { 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; } else if ((currentKey.panelMode == 65535) && i == 0) { //默认第一个 btnChoose.IsSelected = true; btnChoose.Visible = true; oldMode = btnChoose; currentModeID = 300; currentKey.panelMode = currentModeID; } EventHandler hander = (sender, e) => { if (!btnChoose.IsSelected) { if (oldMode != null) { oldMode.IsSelected = false; oldMode.Visible = false; } oldMode = btnChoose; oldMode.IsSelected = true; oldMode.Visible = true; 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; i++; } } } }