陈嘉乐
2020-07-10 48ba446936b51fffafa7c3600c0dadc6ac0e8c20
ZigbeeApp/Shared/Phone/UserCenter/Device/Bind/ChooseKeyModePage.cs
old mode 100644 new mode 100755
@@ -1,30 +1,12 @@
using System;
using System.Collections.Generic;
//using Com.Amap.Api.Location;
using Shared.Common;
using ZigBee.Device;
using static ZigBee.Device.BindObj;
namespace Shared.Phone.UserCenter.DeviceBind
{
    public class ChooseKeyModePage : BindCommonLayout, ZigBee.Common.IStatus
    public class ChooseKeyModePage : BindCommonLayout
    {
        /// <summary>
        /// 按键模式接收
        /// </summary>
        /// <param name="common">Common.</param>
        public void Changed(CommonDevice common)
        {
            //if (common.Type != ZigBee.Device.DeviceType.OnOffSwitch)
            //{
            //    return;
            //}
            Shared.Application.RunOnMainThread(() =>
            {
                //var dev = common as Panel;
            });
        }
        /// 构造函数
        /// </summary>
        /// <param name="doorLock"></param>
@@ -32,32 +14,56 @@
        {
            this.currentKey = key;
            this.currentModeID = key.panelMode;
            this.oldModeID = key.panelMode;
            this.curDeviceBindType = deviceBindType;
            this.targetList = targetSelectList;
        }
        #region ◆ 变量申明__________________________
        #region 变量申明
        /// <summary>
        /// 当前按键
        /// </summary>
        ZigBee.Device.Panel currentKey;
        //显示被绑定设备或场景的view
        /// <summary>
        /// 中部刷新列表
        /// </summary>
        VerticalScrolViewLayout midVerticalScrolViewLayout;
        /// <summary>
        /// 房间列表左右滑动布局
        /// </summary>
        HorizontalScrolViewLayout btnHorizontalScrolViewLayout;
        /// <summary>
        /// 按键配置的目标列表
        /// </summary>
        List<CommonDevice> targetList = new List<CommonDevice>();
        /// <summary>
        /// 新的按键配置目标列表中,目标实际存在按键中,此时要删掉的数据
        /// 本地旧的选中列表
        /// </summary>
        List<CommonDevice> oldTargetList = new List<CommonDevice>();
        List<Room> roomList = new List<Room>();
        /// <summary>
        /// 当前簇ID
        /// </summary>
        int currentClusterID = 6;
        /// <summary>
        /// 回调绑定目标页面刷新
        /// </summary>
        public Action<List<BindListResponseObj>> action;
        /// <summary>
        /// 当前模式ID
        /// </summary>
        int currentModeID = 0;
        int oldModeID = 0;
        /// <summary>
        /// 当前设备绑定类型
        /// </summary>
        string curDeviceBindType = "";
        /// <summary>
        /// 类型的具体模式列表
        /// </summary>
        List<int> typeDetailModeList = new List<int> { };
        #endregion
        /// <summary>
        /// 显示按键模式页
        /// </summary>
        public void Show()
        {
            this.TopFrameLayout(this, Language.StringByID(R.MyInternationalizationString.ChooseKeyMode));
@@ -73,6 +79,9 @@
            MidFrameLayoutContent();
        }
        /// <summary>
        /// 中部布局
        /// </summary>
        async void MidFrameLayoutContent()
        {
            #region UI
@@ -99,320 +108,262 @@
                BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack,
                TextColor = Shared.Common.ZigbeeColor.Current.XMWhite,
                TextSize = 16,
                IsBold = true,
            };
            bottomFrameLayout.AddChidren(btnFinifh);
            #endregion
            #region 数据处理
            roomList = Shared.Common.Room.Lists;
            Shared.Common.Room curRoom = roomList[0];
            int index = 0;
            KeyModeList(roomList[index]);
            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), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinifh);
                               });
                               return;
                           }
                       }
            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();
                       //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;
                        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;
                        }
                    }
                    //if (oldModeID != 65535 && oldModeID != currentModeID)
                    //{
                    //var bindResult = await currentKey.ClearBindInfoAsync();
                    //if (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;
                    //        return;
                    //    }
                    //    else
                    //    {
                    //        currentKey.bindList.Clear();
                    //    }
                    //}
                    //}
                    //else
                    //{
                    //    foreach (var bindedDev in currentKey.bindList)
                    //    {
                    //        for (int i = 0; i < targetList.Count; i++)
                    //        {
                    //            var de = targetList[i];
                    //            if (de.DeviceAddr == bindedDev.BindMacAddr && de.DeviceEpoint == bindedDev.BindEpoint)
                    //            {
                    //                oldTargetList.Add(de);
                    //                targetList.RemoveAt(i);
                    //                i--;
                    //            }
                    //        }
                    //    }
                    //}
                               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);
                                   }
                               }
                    //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 && temp.setWritableValueResponData.Status == 0)
                    {
                        ////删除被勾掉的数据
                        //foreach (var delDev in oldTargetList)
                        //{
                        //    var delDev1 = new BindObj.BindListResponseObj();
                        //    delDev1.BindType = 0;
                        //    delDev1.BindCluster = currentClusterID;
                        //    delDev1.BindMacAddr = delDev.DeviceAddr;
                        //    delDev1.BindEpoint = delDev.DeviceEpoint;
                        //    var result = await BindInfo.RemoveTargets(delDev1, currentKey);
                               //是亮度再次发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);
                                       }
                                   }
                               }
                        //    if (result == 0)
                        //    {
                        //        var bindSc = currentKey.bindList.Find(obj =>
                        //        (obj.BindType == 0
                        //        && obj.BindCluster == currentClusterID
                        //        && obj.BindMacAddr == delDev.DeviceAddr
                        //        && obj.BindEpoint == delDev.DeviceEpoint
                        //        ));
                        //        currentKey.bindList.Remove(bindSc);
                        //    }
                        //}
                               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;
                                       }
                        //3、绑定新的数据
                        var addBindeDev = new AddBindData();
                        addBindeDev.DeviceAddr = currentKey.DeviceAddr;
                        addBindeDev.Epoint = currentKey.DeviceEpoint;
                                       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();
                                       });
                        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 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);
                                       });
                        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.BindFailed), 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.BindFailed), 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;
                    }
                }
                catch { }
                finally
                {
                    if (isFinish)
                    {
                        if (action != null)
                        {
                            action(currentKey.bindList);
                        }
                        this.RemoveFromParent();
                    }
                    else
                    {
                        this.RemoveFromParent();
                    }
                    CommonPage.Loading.Hide();
                    btnFinifh.Enable = true;
                    btnFinifh.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack;
                }
            };
                                       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), 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), 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 
        }
@@ -421,31 +372,284 @@
        /// </summary>
        /// <param name="gateway">Gateway.</param>
        /// <param name="key">Key.</param>
        void KeyModeList(Shared.Common.Room curRoom)
        async private void KeyModeList()
        {
            midVerticalScrolViewLayout.RemoveAll();
            switch (curDeviceBindType)
            {
                case "AddSwitch":
                    currentClusterID = 6;
                    AddSwitchMode();
                    typeDetailModeList = await GetAddSwitchMode();
                    if (typeDetailModeList == null)
                    {
                        new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
                    }
                    else
                    {
                        AddSwitchMode();
                    }
                    break;
                case "AddDimmer":
                    AddDimmerMode();
                    currentClusterID = 8;
                    typeDetailModeList = await GetAddDimmerMode();
                    if (typeDetailModeList == null)
                    {
                        new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
                    }
                    else
                    {
                        AddDimmerMode();
                    }
                    break;
                case "AddCurtain":
                    currentClusterID = 258;
                    AddCurtainMode();
                    typeDetailModeList = await GetAddCurtainMode();
                    if (typeDetailModeList == null)
                    {
                        new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
                    }
                    else
                    {
                        AddCurtainMode();
                    }
                    break;
            }
        }
        public void AddSwitchMode()
        /// <summary>
        /// 获取开关具体类型
        /// </summary>
        /// <returns></returns>
        System.Threading.Tasks.Task<List<int>> GetAddSwitchMode()
        {
            return System.Threading.Tasks.Task.Run(async () =>
             {
                 //如果当前是虚拟住宅
                 if (Common.Config.Instance.Home.IsVirtually == true)
                 {
                     typeDetailModeList.Clear();
                     return new List<int>() { 100, 101, 102 };
                 }
                 Application.RunOnMainThread(() =>
                 {
                     CommonPage.Loading.Start();
                 });
                 typeDetailModeList.Clear();
                 List<int> result3 = new List<int> { };
                 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;
             });
        }
        /// <summary>
        /// 获取调光具体类型
        /// </summary>
        /// <returns></returns>
        System.Threading.Tasks.Task<List<int>> GetAddDimmerMode()
        {
            return System.Threading.Tasks.Task.Run(async () =>
            {
                //如果当前是虚拟住宅
                if (Common.Config.Instance.Home.IsVirtually == true)
                {
                    typeDetailModeList.Clear();
                    return new List<int>() { 200, 201, 203, 204, 205 };
                }
                Application.RunOnMainThread(() =>
                {
                    CommonPage.Loading.Start();
                });
                typeDetailModeList.Clear();
                List<int> result3 = new List<int> { };
                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;
            });
        }
        /// <summary>
        /// 获取窗帘具体类型
        /// </summary>
        /// <returns></returns>
        System.Threading.Tasks.Task<List<int>> 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<int>() { 300, 301, 302, 303, 304 };
                }
                List<int> result3 = new List<int> { };
                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;
            });
        }
        /// <summary>
        /// 添加开关模式
        /// </summary>
        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), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
                    });
                    return;
                }
            }
            Button oldMode = null;
            for (int i = 0; i < 3; i++)
            int i = 0;
            foreach (var modeSwitchValue in typeDetailModeList)
            {
                #region 绑定表UI显(无数据处理)
                var rowLayout = new FrameLayout()
@@ -463,13 +667,14 @@
                    Y = Application.GetRealHeight(58),
                    TextColor = Shared.Common.ZigbeeColor.Current.TextBlack,
                    TextAlignment = TextAlignment.CenterLeft,
                    TextSize = 14,
                };
                rowLayout.AddChidren(btnModeText);
                var btnChoose = new Button()
                {
                    Width = Application.GetRealWidth(60),
                    Height = Application.GetRealHeight(60),
                    Width = Application.GetMinReal(60),
                    Height = Application.GetMinReal(60),
                    X = Application.GetRealWidth(861 + 81),
                    Y = Application.GetRealHeight(35),
                    SelectedImagePath = "DoorLock/SelectedIcon.png",
@@ -488,17 +693,21 @@
                rowLayout.AddChidren(line2);
                #endregion
                if (i == 0)
                switch (modeSwitchValue)
                {
                    btnModeText.Text = Language.StringByID(R.MyInternationalizationString.OnOffOn);
                    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 == 1)
                if (i == typeDetailModeList.Count - 1)
                {
                    btnModeText.Text = Language.StringByID(R.MyInternationalizationString.OnOffoFF);
                }
                if (i == 2)
                {
                    btnModeText.Text = Language.StringByID(R.MyInternationalizationString.OnOffOnOff);
                    line2.Visible = false;
                }
@@ -520,6 +729,15 @@
                    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<MouseEventArgs> hander = async (sender, e) =>
                 {
@@ -533,7 +751,6 @@
                         oldMode = btnChoose;
                         oldMode.IsSelected = true;
                         oldMode.Visible = true;
                         currentKey.CurrentSwitchMode = btnModeText.Text;
                         if (btnModeText.Text == Language.StringByID(R.MyInternationalizationString.OnOffOn))
                         {
                             currentModeID = 100;
@@ -555,13 +772,42 @@
                rowLayout.MouseUpEventHandler += hander;
                btnModeText.MouseUpEventHandler += hander;
                btnChoose.MouseUpEventHandler += hander;
                i++;
            }
        }
        public void AddDimmerMode()
        /// <summary>
        /// 添加调光模式
        /// </summary>
        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), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
                    });
                    return;
                }
            }
            Button oldMode = null;
            for (int i = 0; i < 5; i++)
            int i = 0;
            List<int> typeDetailModeListTemp = new List<int> { };
            foreach (var modeSwitchValue in typeDetailModeList)
            {
                if (modeSwitchValue == 202)
                {
                    continue;
                }
                typeDetailModeListTemp.Add(modeSwitchValue);
            }
            foreach (var modeSwitchValue in typeDetailModeListTemp)
            {
                #region 绑定表UI显(无数据处理)
                var rowLayout = new FrameLayout()
@@ -579,13 +825,14 @@
                    Y = Application.GetRealHeight(58),
                    TextColor = Shared.Common.ZigbeeColor.Current.TextBlack,
                    TextAlignment = TextAlignment.CenterLeft,
                    TextSize = 14,
                };
                rowLayout.AddChidren(btnModeText);
                var btnChoose = new Button()
                {
                    Width = Application.GetRealWidth(60),
                    Height = Application.GetRealHeight(60),
                    Width = Application.GetMinReal(60),
                    Height = Application.GetMinReal(60),
                    X = Application.GetRealWidth(861 + 81),
                    Y = Application.GetRealHeight(35),
                    SelectedImagePath = "DoorLock/SelectedIcon.png",
@@ -603,26 +850,27 @@
                };
                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 == 0)
                if (i == typeDetailModeListTemp.Count - 1)
                {
                    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;
                }
@@ -656,6 +904,15 @@
                    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<MouseEventArgs> hander = (sender, e) =>
                {
@@ -669,7 +926,6 @@
                        oldMode = btnChoose;
                        oldMode.IsSelected = true;
                        oldMode.Visible = true;
                        currentKey.CurrentSwitchMode = btnModeText.Text;
                        if (btnModeText.Text == Language.StringByID(R.MyInternationalizationString.DimmerMode1))
                        {
                            currentModeID = 200;
@@ -700,14 +956,31 @@
                rowLayout.MouseUpEventHandler += hander;
                btnModeText.MouseUpEventHandler += hander;
                btnChoose.MouseUpEventHandler += hander;
                i++;
            }
        }
        public void AddCurtainMode()
        /// <summary>
        /// 添加窗帘模式
        /// </summary>
        async private void AddCurtainMode()
        {
            if (typeDetailModeList == null)
            {
                //再次动态获取按键支持的类
                typeDetailModeList = await GetAddSwitchMode();
                if (typeDetailModeList == null)
                {
                    Application.RunOnMainThread(() =>
                    {
                        new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
                    });
                    return;
                }
            }
            Button oldMode = null;
            for (int i = 0; i < 5; i++)
            int i = 0;
            foreach (var modeSwitchValue in typeDetailModeList)
            {
                #region 绑定表UI显(无数据处理)
                var rowLayout = new FrameLayout()
@@ -725,13 +998,14 @@
                    Y = Application.GetRealHeight(58),
                    TextColor = Shared.Common.ZigbeeColor.Current.TextBlack,
                    TextAlignment = TextAlignment.CenterLeft,
                    TextSize = 14,
                };
                rowLayout.AddChidren(btnModeText);
                var btnChoose = new Button()
                {
                    Width = Application.GetRealWidth(60),
                    Height = Application.GetRealHeight(60),
                    Width = Application.GetMinReal(60),
                    Height = Application.GetMinReal(60),
                    X = Application.GetRealWidth(861 + 81),
                    Y = Application.GetRealHeight(35),
                    SelectedImagePath = "DoorLock/SelectedIcon.png",
@@ -749,26 +1023,27 @@
                };
                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 == 0)
                if (i == typeDetailModeList.Count - 1)
                {
                    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;
                }
@@ -802,6 +1077,15 @@
                    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<MouseEventArgs> hander = (sender, e) =>
                {
@@ -815,7 +1099,6 @@
                        oldMode = btnChoose;
                        oldMode.IsSelected = true;
                        oldMode.Visible = true;
                        currentKey.CurrentSwitchMode = btnModeText.Text;
                        if (btnModeText.Text == Language.StringByID(R.MyInternationalizationString.WcdUp))
                        {
                            currentModeID = 300;
@@ -846,19 +1129,8 @@
                rowLayout.MouseUpEventHandler += hander;
                btnModeText.MouseUpEventHandler += hander;
                btnChoose.MouseUpEventHandler += hander;
                i++;
            }
        }
        public void DeviceInfoChange(CommonDevice common, string typeTag)
        {
        }
        public void ChangedILogicStatus(ZigBee.Device.Logic logic)
        {
        }
        public void ChangedISceneStatus(Scene scene)
        {
        }
    }
}