xm
2021-11-24 1802b849f0dadc81644fb0a706d6fb45efdf2a20
HDL_ON/UI/UI2/FuntionControlView/Light/LightScene/AddLightScene.cs
@@ -1,5 +1,8 @@
using System;
using System.Collections.Generic;
using System.Threading;
using HDL_ON.DAL.Server;
using HDL_ON.DriverLayer;
using HDL_ON.Entity;
using HDL_ON.UI.CSS;
using Shared;
@@ -25,21 +28,43 @@
        /// 功能列表集合显示区域
        /// </summary>
        static VerticalScrolViewLayout functionListView;
        #endregion
        /// <summary>
        /// 完成按钮
        /// </summary>
        Button btnConfrim;
        #endregion
        /// <summary>
        /// 场景里面的功能列表
        /// </summary>
        List<Function> sceneLishtList;
        Scene lightScene;
        public AddLightScene(List<Function> functions,Scene scene)
        /// <summary>
        /// 本地的灯光列表
        /// </summary>
        List<Function> lightList;
        /// <summary>
        /// 场景对象
        /// </summary>
        Scene scene;
        /// <summary>
        /// 回调刷新
        /// </summary>
        Action<Scene> backActon;
        public AddLightScene(List<Function> functions,Scene inParscene, Action<Scene> action)
        {
            bodyView = this;
            sceneLishtList = functions;
            lightScene = scene;
            scene = inParscene;
            backActon = action;
            lightList = FunctionList.List.GetLightList();
        }
        public void LoadPage()
        {
            bodyView.BackgroundColor = CSS_Color.BackgroundColor;
            new TopViewDiv(bodyView, Language.StringByID(StringId.CombinedDimming)).LoadTopView();
            scene.name = Language.StringByID(StringId.CombinedDimming);
            /// <summary>
            /// 房间内容显示区域
@@ -78,13 +103,68 @@
            functionListView = new VerticalScrolViewLayout()
            {
                Y = Application.GetRealHeight(64 + 52),
                Height = Application.GetRealHeight(603 - 12 - 52),
                Height = Application.GetRealHeight(640 - 12 - 52 -100),
            };
            bodyView.AddChidren(functionListView);
            var lightList = FunctionList.List.GetLightList();
            foreach (var function in lightList)
            LoadLightRow(lightList);
            #region 底部view
            var bottomView = new FrameLayout()
            {
                Y = Application.GetRealHeight(591),
                Height = Application.GetRealHeight(100),
                BackgroundColor = CSS_Color.MainBackgroundColor,
                Radius = (uint)Application.GetRealWidth(12),
            };
            this.AddChidren(bottomView);
            btnConfrim = new Button()
            {
                Y = Application.GetRealHeight(12),
                Gravity = Gravity.CenterHorizontal,
                Width = Application.GetRealWidth(220),
                Height = Application.GetRealHeight(44),
                Radius = (uint)Application.GetRealHeight(22),
                TextAlignment = TextAlignment.Center,
                TextColor = CSS_Color.MainBackgroundColor,
                BackgroundColor = CSS_Color.BackgroundColor,
                TextID = StringId.Confirm,
                TextSize = CSS_FontSize.SubheadingFontSize,
                SelectedTextColor = CSS_Color.MainBackgroundColor,
                SelectedBackgroundColor = CSS_Color.MainColor,
            };
            bottomView.AddChidren(btnConfrim);
            btnConfrim.MouseUpEventHandler = (sender, e) => {
                if (btnConfrim.IsSelected)
                {
                    Action<Scene> action = (objScene) =>
                    {
                        backActon(objScene);
                        this.RemoveFromParent();
                    };
                    var lightSceneDialog = new LightSceneEditDialog(sceneLishtList, scene, action);
                    lightSceneDialog.ShowDialog();
                }
            };
            #endregion
            //加载功能筛选组件
            LoadDialog_ChangeFloor();
        }
        /// <summary>
        /// 加载功能row
        /// </summary>
        /// <param name="lightList"></param>
        void LoadLightRow(List<Function> functions)
        {
            functionListView.RemoveAll();
            foreach (var function in functions)
            {
                var functionDiv = new LightRow(function)
                {
@@ -97,42 +177,45 @@
                    BackgroundColor = CSS_Color.MainBackgroundColor,
                    Tag = function.spk + function.sid
                };
                functionDiv.LoadDiv(sceneLishtList);
                Action setAction = () =>
                {
                    if (sceneLishtList.Count > 0)
                    {
                        btnConfrim.IsSelected = true;
                    }
                    else
                    {
                        btnConfrim.IsSelected = false;
                    }
                };
                functionDiv.LoadDiv(sceneLishtList,setAction);
                functionListView.AddChidren(functionDiv);
                functionListView.AddChidren(new Button() { Height = Application.GetRealHeight(12) });
            }
        }
            #region 底部view
            var bottomView = new FrameLayout()
        /// <summary>
        /// 住宅列表点击事件
        /// </summary>
        void LoadDialog_ChangeFloor()
        {
            string nowSelectId = null;
            btnFloor.MouseUpEventHandler += (sender, e) =>
            {
                Y = Application.GetRealHeight(591),
                Height = Application.GetRealHeight(100),
                BackgroundColor = CSS_Color.MainBackgroundColor,
                Radius = (uint)Application.GetRealWidth(12),
                //显示下拉列表
                var form = new FloorRoomSelectPopupView();
                form.ShowDeviceFunctionView(btnFloor, this.lightList, (selectId, listFunc) =>
                {
                    nowSelectId = selectId;
                    //重新加载界面
                    LoadLightRow(listFunc);
                }, nowSelectId);
            };
            this.AddChidren(bottomView);
            var btnConfrim = new Button()
            {
                Y = Application.GetRealHeight(12),
                Gravity = Gravity.CenterHorizontal,
                Width = Application.GetRealWidth(220),
                Height = Application.GetRealHeight(44),
                Radius = (uint)Application.GetRealHeight(22),
                TextAlignment = TextAlignment.Center,
                TextColor = CSS_Color.MainBackgroundColor,
                BackgroundColor = CSS_Color.MainColor,
                TextID = StringId.Confirm,
            };
            bottomView.AddChidren(btnConfrim);
            btnConfrim.MouseUpEventHandler = (sender, e) => {
                var lightSceneDialog = new LightSceneEditDialog(sceneLishtList,lightScene);
                lightSceneDialog.ShowDialog();
            };
            #endregion
        }
    }
@@ -174,7 +257,7 @@
        /// <summary>
        /// 加载控制卡片区域
        /// </summary>
        public void LoadDiv(List<Function> functions)
        public void LoadDiv(List<Function> functions,Action action)
        {
            btnIcon = new Button()
            {
@@ -242,6 +325,11 @@
                        functions.Remove(removeTemp);
                    }
                }
                ///刷新界面
                if (functions.Count == 0 || functions.Count == 1)
                {
                    action();
                }
            };
        }
@@ -254,19 +342,33 @@
    /// </summary>
    public class LightSceneEditDialog :Dialog
    {
        /// <summary>
        /// 传入的灯光列表
        /// 加入场景控制功能列表
        /// </summary>
        List<Function> lights;
        /// <summary>
        /// 临时灯光对象
        /// 处理灯光方法
        /// </summary>
        Light tempLight = new Light();
        //发送数据收集
        Dictionary<string, string> commandDic = new Dictionary<string, string>();
        Scene editScene;
        public LightSceneEditDialog(List<Function> functions,Scene scene)
        Scene scene;
        Action<Scene> backAction;
        public LightSceneEditDialog(List<Function> functions,Scene inParScene,Action<Scene> action)
        {
            lights = functions;
            editScene = scene;
            scene = inParScene;
            backAction = action;
        }
        public void ShowDialog()
        {
            commandDic.Add(FunctionAttributeKey.OnOff, "off");
            var hadDimming = lights.Find((obj) => obj.spk == SPK.LightDimming) != null;
            var hadCCT = lights.Find((obj) => obj.spk == SPK.LightCCT) != null;
            var hadRGB = lights.Find((obj) => obj.spk == SPK.LightRGB) != null;
@@ -285,7 +387,6 @@
            bodyView.AddChidren(contentView);
            #region 标题区
            bool inEdit = false;//是否在编辑标题
            var titleView = new FrameLayout()
            {
                Width = Application.GetRealWidth(343),
@@ -321,48 +422,74 @@
                X = Application.GetRealWidth(12) + btnTitle.Right,
                Gravity = Gravity.CenterVertical,
                UnSelectedImagePath = "Public/Edit.png",
                SelectedImagePath = "Public/HookIcon.png"
                //SelectedImagePath = "Public/HookIcon.png"
            };
            titleView.AddChidren(btnEditIcon);
            EventHandler<MouseEventArgs> dd = (sender, e) =>
            {
                inEdit = !inEdit;
                btnEditIcon.IsSelected = inEdit;
                if (inEdit)
                Action<string> callBack = (str) =>
                {
                    btnTitle.Width = btnTitle.GetTextWidth();
                }
                else
                {
                    if (btnTitle.GetTextWidth() > Application.GetRealWidth(197))//247
                    //名称不能为空
                    if (string.IsNullOrEmpty(str))
                    {
                        new Tip()
                        {
                            CloseTime = 1,
                            Text = Language.StringByID(StringId.NameCannotBeEmpty),
                            Direction = AMPopTipDirection.None,
                        }.Show(bodyView);
                        return;
                    }
                    btnTitle.Text = str;
                    scene.name = str;
                    if (btnTitle.GetTextWidth() > Application.GetRealWidth(197))//247
                        {
                        btnTitle.Width = Application.GetRealWidth(197);
                    }
                    else
                    {
                        btnTitle.Width = btnTitle.GetTextWidth();
                    }
                    editScene.name = btnTitle.Text.Trim();
                };
            EventHandler<MouseEventArgs> eventHandler = (sender, e) =>
            {
                List<string> sceneNameList = new List<string>();
                foreach (var tempScene in FunctionList.List.scenes)
                {
                    sceneNameList.Add(tempScene.name);
                }
                new PublicAssmebly().LoadDialog_EditParater(StringId.SceneName, scene.name, callBack, StringId.SceneNameCannotBeEmpty, StringId.SceneNameAlreadyExists, sceneNameList);
            };
            btnTitle.MouseUpEventHandler = dd;
            btnEditIcon.MouseUpEventHandler = dd;
            btnTitle.MouseUpEventHandler = eventHandler;
            btnEditIcon.MouseUpEventHandler = eventHandler;
            titleView.AddChidren(new Button() { Height = 1, BackgroundColor = CSS_Color.DividingLineColor, Y = Application.GetRealHeight(51) });
            #endregion
            var dimmingLight = editScene.functions.Find((obj) => obj.localFunction.spk == SPK.LightDimming);
            var cctLight = editScene.functions.Find((obj) => obj.localFunction.spk == SPK.LightCCT);
            var rgbLight = editScene.functions.Find((obj) => obj.localFunction.spk == SPK.LightRGB);
            //var dimmingLight = lights.Find((obj) => obj.spk == SPK.LightDimming);
            //var cctLight = lights.Find((obj) => obj.spk == SPK.LightCCT);
            //var rgbLight = lights.Find((obj) => obj.spk == SPK.LightRGB);
            var dimmingLight = scene.functions.Find((obj) => obj.localFunction.spk == SPK.LightDimming);
            var cctLight = scene.functions.Find((obj) => obj.localFunction.spk == SPK.LightCCT);
            var rgbLight = scene.functions.Find((obj) => obj.localFunction.spk == SPK.LightRGB);
            var brightnessValue = 0;
            var cctValue = 27;
            if(rgbLight!= null)
            {
                int.TryParse(rgbLight.status.Find((obj) => obj.key == FunctionAttributeKey.Brightness).value, out brightnessValue);
            }
            if (cctLight != null)
            {
                int.TryParse(cctLight.status.Find((obj) => obj.key == FunctionAttributeKey.Brightness).value, out brightnessValue);
                int.TryParse(cctLight.status.Find((obj) => obj.key == FunctionAttributeKey.CCT).value, out cctValue);
            }
            if(dimmingLight!=null)
            {
                int.TryParse(cctLight.status.Find((obj) => obj.key == FunctionAttributeKey.CCT).value, out cctValue);
            }
@@ -372,83 +499,113 @@
            {
                Y = Application.GetRealHeight(52),
                Width = Application.GetRealWidth(343),
                ScrollEnabled = false,
            };
            //属性设置区域高度
            int attrViewHight = Application.GetRealHeight(27 + 22);
            attrView.AddChidren(new Button() { Height = Application.GetRealHeight(27) });
            int attrViewHight = Application.GetRealHeight(18 + 22);
            if (hadDimming)
            //只有继电器
            if (!hadDimming && !hadCCT && !hadRGB)
            {
                attrViewHight += Application.GetRealHeight(54 + 11);
                var dimmingView = new FrameLayout();
                attrView.AddChidren(dimmingView);
                attrViewHight += Application.GetRealHeight(50);
                attrView.Height = attrViewHight;
                contentView.AddChidren(attrView);
                attrView.AddChidren(new Button() { Height = Application.GetRealHeight(18) });
                #region 亮度调节
                var btnBrightnessText = new Button()
                var view = new FrameLayout()
                {
                    X = Application.GetRealWidth(35),
                    Y = Application.GetRealHeight(1),
                    Width = Application.GetRealWidth(224),
                    Height = Application.GetRealHeight(21),
                    TextAlignment = TextAlignment.CenterLeft,
                    TextColor = CSS_Color.FirstLevelTitleColor,
                    TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
                    TextID = StringId.Brightness,
                    BackgroundColor = 0xFFFF0000
                    Width = Application.GetRealWidth(343),
                    Height = Application.GetRealHeight(50),
                };
                dimmingView.AddChidren(btnBrightnessText);
                attrView.AddChidren(view);
                var btnMinValuesText = new Button()
                var btnClose = new Button()
                {
                    X = Application.GetRealWidth(35),
                    Y = btnBrightnessText.Bottom,
                    Width = Application.GetRealWidth(30),
                    Height = Application.GetRealHeight(21),
                    Text = "0%",
                    TextAlignment = TextAlignment.CenterLeft,
                    TextColor = CSS_Color.PromptingColor1,
                    TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
                    X = Application.GetRealWidth(50),
                    Gravity = Gravity.CenterVertical,
                    Width = Application.GetRealWidth(98),
                    Height = Application.GetRealHeight(40),
                    TextColor = CSS_Color.TextualColor,
                    SelectedBackgroundColor = CSS_Color.MainColor,
                    SelectedTextColor = CSS_Color.MainBackgroundColor,
                    BackgroundColor = CSS_Color.DividingLineColor,
                    TextID = StringId.OFF,
                    TextSize = CSS_FontSize.TextFontSize,
                    Radius = (uint)Application.GetRealWidth(5),
                    IsSelected = true,
                    //BorderWidth = 1,
                    //BorderColor = 0x00000000
                };
                dimmingView.AddChidren(btnMinValuesText);
                view.AddChidren(btnClose);
                var dimmerBar = new DiyImageSeekBar()
                var btnOpen = new Button()
                {
                    X = Application.GetRealWidth(35 + 22),
                    Y = Application.GetRealHeight(11),
                    Width = Application.GetRealWidth(210),
                    Height = Application.GetRealHeight(54),
                    SeekBarViewHeight = Application.GetRealHeight(8),
                    ThumbImagePath = "Public/ThumbImage.png",
                    ThumbImageHeight = Application.GetRealHeight(54),
                    ProgressTextColor = CSS_Color.FirstLevelTitleColor,
                    ProgressTextSize = CSS_FontSize.PromptFontSize_FirstLevel,
                    ProgressBarColor = CSS_Color.AuxiliaryColor1,
                    MaxValue = 100,
                    Progress = brightnessValue,
                    SeekBarPadding = Application.GetRealWidth(20),
                    X = Application.GetRealWidth(100 + 98),
                    Gravity = Gravity.CenterVertical,
                    Width = Application.GetRealWidth(98),
                    Height = Application.GetRealHeight(40),
                    TextColor = CSS_Color.TextualColor,
                    SelectedBackgroundColor = CSS_Color.MainColor,
                    SelectedTextColor = CSS_Color.MainBackgroundColor,
                    BackgroundColor = CSS_Color.DividingLineColor,
                    TextID = StringId.On,
                    TextSize = CSS_FontSize.TextFontSize,
                    Radius = (uint)Application.GetRealWidth(5),
                };
                //dimmingView.AddChidren(dimmerBar);
                view.AddChidren(btnOpen);
                var btnMaxValuesText = new Button()
                btnClose.MouseUpEventHandler = (sender, e) =>
                {
                    X = dimmerBar.Right,
                    Y = btnBrightnessText.Bottom,
                    Width = Application.GetRealWidth(45),
                    Height = Application.GetRealHeight(21),
                    Text = "100%",
                    TextAlignment = TextAlignment.CenterLeft,
                    TextColor = CSS_Color.PromptingColor1,
                    TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
                    btnClose.IsSelected = true;
                    btnOpen.IsSelected = false;
                    commandDic[FunctionAttributeKey.OnOff] = "off";
                };
                dimmingView.AddChidren(btnMaxValuesText);
                #endregion
                btnOpen.MouseUpEventHandler = (sender, e) =>
                {
                    btnClose.IsSelected = false;
                    btnOpen.IsSelected = true;
                    commandDic[FunctionAttributeKey.OnOff] = "on";
                };
            }
            attrView.Height = attrViewHight;
            contentView.AddChidren(attrView);
            else
            {
                if(hadRGB)
                {
                    attrViewHight += Application.GetRealHeight(248);
                    hadDimming = true;
                }
                if (hadCCT)
                {
                    attrViewHight += Application.GetRealHeight(54 + 11);
                    hadDimming = true;
                }
                if (hadDimming)
                {
                    attrViewHight += Application.GetRealHeight(54 + 11);
                }
                attrView.Height = attrViewHight;
                contentView.AddChidren(attrView);
                attrView.AddChidren(new Button() { Height = Application.GetRealHeight(18) });
                if (hadDimming)
                {
                    LoadDimmingAttrView(attrView);
                }
                if (hadCCT)
                {
                    LoadCctAttrView(attrView);
                }
                if(hadRGB)
                {
                    LoadRgbAttrView(attrView);
                }
            }
            contentView.Height = Application.GetRealHeight(52 + 44) + attrViewHight;
            contentView.Gravity = Gravity.Center;
@@ -459,9 +616,10 @@
            var bottomView = new FrameLayout()
            {
                Y = Application.GetRealHeight(52) + attrViewHight,
                Height = Application.GetRealHeight(44),
                Height = Application.GetRealHeight(46),
            };
            contentView.AddChidren(bottomView);
            bottomView.AddChidren(new Button() { Height = 1, BackgroundColor = CSS_Color.DividingLineColor });
            var btnSave = new Button()
            {
@@ -489,212 +647,476 @@
            //例:右下圆角 大小为50
            int mRectCornerID = HDLUtils.RectCornerBottomRight;
            btnComplete.SetCornerWithSameRadius((uint)Application.GetMinRealAverage(12), mRectCornerID);
            bottomView.AddChidren(new Button() { Height = 1, BackgroundColor = CSS_Color.DividingLineColor });
            btnComplete.SetCornerWithSameRadius((uint)Application.GetRealWidth(14), mRectCornerID);
            btnSave.MouseUpEventHandler = (sender, e) => {
                this.Close();
            };
            btnComplete.MouseUpEventHandler = (sender, e) => {
                this.Close();
                var waitPage = new Loading();
                MainPage.BaseView.AddChidren(waitPage);
                waitPage.Start(Language.StringByID(StringId.PleaseWait));
                new Thread(() =>
                {
                    try
                    {
                        foreach (var light in lights)
                        {
                            Dictionary<string, string> sendDate = new Dictionary<string, string>();
                            //赋值场景功能数据
                            foreach (var attr in light.GetAttributes())
                            {
                                if (commandDic.ContainsKey(attr))
                                {
                                    try
                                    {
                                        sendDate.Add(attr, commandDic[attr]);
                                    }
                                    catch { }
                                }
                            }
                                Control.Ins.SendWriteCommand(light, sendDate);
                            Thread.Sleep(50);
                        }
                    }
                    catch
                    { }
                    finally
                    {
                        Application.RunOnMainThread(() =>
                        {
                            waitPage.Hide();
                            if (waitPage != null)
                            {
                                backAction(null);
                                waitPage.RemoveFromParent();
                            }
                        });
                    }
                })
                { IsBackground = true }.Start();
            };
            btnSave.MouseUpEventHandler += (sender, e) =>
            {
                if (string.IsNullOrEmpty(scene.name))
                {
                    new Tip()
                    {
                        CloseTime = 1,
                        Text = Language.StringByID(StringId.SceneNameCannotBeEmpty),
                        Direction = AMPopTipDirection.None,
                    }.Show(bodyView);
                    return;
                }
                foreach (var tempRoom in FunctionList.List.scenes)
                {
                    if (scene.name == tempRoom.name)
                    {
                        new PublicAssmebly().TipMsg(StringId.Tip, StringId.SceneNameAlreadyExists);
                        return;
                    }
                }
                var waitPage = new Loading();
                MainPage.BaseView.AddChidren(waitPage);
                waitPage.Start(Language.StringByID(StringId.PleaseWait));
                new Thread(() =>
                {
                    try
                    {
                        var serverScene = new Scene();
                        for (int i = 0; i < lights.Count; i++)
                        {
                            var light = lights[i];
                            //赋值场景功能数据
                            foreach (var attr in light.GetAttributes())
                            {
                                if (commandDic.ContainsKey(attr))
                                {
                                    try
                                    {
                                        light.SetAttrState(attr, commandDic[attr]);
                                    }
                                    catch { }
                                }
                            }
                            //转换场景的功能对象
                            var sceneFunction = light.ConvertSceneFunction();
                            //查询有没有存在
                            var temp = scene.functions.Find((obj) => obj.sid == sceneFunction.sid);
                            //赋值
                            if (temp != null)
                            {
                                temp = sceneFunction;
                            }
                            else
                            {
                                scene.functions.Add(sceneFunction);
                            }
                        }
                        var result = FunctionList.List.AddScene(scene, out serverScene);
                        Application.RunOnMainThread(() =>
                        {
                            if (result == StateCode.SUCCESS)
                            {
                                scene = serverScene;
                                FunctionList.List.scenes.Add(scene);
                                backAction(scene);
                                this.Close();
                            }
                            else
                            {
                                IMessageCommon.Current.ShowErrorInfoAlter(result);
                            }
                        });
                    }
                    catch { }
                    finally
                    {
                        Application.RunOnMainThread(() => {
                            waitPage.Hide();
                            waitPage.RemoveFromParent();
                        });
                    }
                })
                { IsBackground = true, Priority = ThreadPriority.AboveNormal }.Start();
            };
            #endregion
            this.Show();
            return;
            //只有调光器
            if (!hadDimming&&!hadCCT&&!hadRGB)
            {
                contentView.Height = Application.GetRealHeight(520);
                contentView.Width = Application.GetRealWidth(343);
                contentView.Gravity = Gravity.Center;
                contentView.Radius = (uint)Application.GetRealWidth(12);
                contentView.AddChidren(titleView);
            }
            else if (hadCCT && hadRGB)//
            {
                contentView.Height = Application.GetRealHeight(520);
                contentView.Width = Application.GetRealWidth(343);
                contentView.Gravity = Gravity.Center;
                contentView.Radius = (uint)Application.GetRealWidth(12);
                contentView.AddChidren(titleView);
                #region 亮度调节
                var btnBrightnessText = new Button()
                {
                    X = Application.GetRealWidth(35),
                    Y = Application.GetRealHeight(82),
                    Width = Application.GetRealWidth(224),
                    Height = Application.GetRealHeight(21),
                    TextAlignment = TextAlignment.CenterLeft,
                    TextColor = CSS_Color.FirstLevelTitleColor,
                    TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
                    TextID = StringId.Brightness,
                };
                contentView.AddChidren(btnBrightnessText);
                var btnMinValuesText = new Button()
                {
                    X = Application.GetRealWidth(35),
                    Y = btnBrightnessText.Bottom,
                    Width = Application.GetRealWidth(30),
                    Height = Application.GetRealHeight(21),
                    Text = "0%",
                    TextAlignment = TextAlignment.CenterLeft,
                    TextColor = CSS_Color.PromptingColor1,
                    TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
                };
                contentView.AddChidren(btnMinValuesText);
                var dimmerBar = new DiyImageSeekBar()
                {
                    X = Application.GetRealWidth(35 + 22),
                    Y = Application.GetRealHeight(312),
                    Width = Application.GetRealWidth(210),
                    Height = Application.GetRealHeight(54),
                    SeekBarViewHeight = Application.GetRealHeight(8),
                    ThumbImagePath = "Public/ThumbImage.png",
                    ThumbImageHeight = Application.GetRealHeight(54),
                    ProgressTextColor = CSS_Color.FirstLevelTitleColor,
                    ProgressTextSize = CSS_FontSize.PromptFontSize_FirstLevel,
                    ProgressBarColor = CSS_Color.AuxiliaryColor1 ,
                    MaxValue = 100,
                    Progress = brightnessValue,
                    SeekBarPadding = Application.GetRealWidth(20),
                };
                contentView.AddChidren(dimmerBar);
                var btnMaxValuesText = new Button()
                {
                    X = dimmerBar.Right,
                    Y = btnBrightnessText.Bottom,
                    Width = Application.GetRealWidth(45),
                    Height = Application.GetRealHeight(21),
                    Text = "100%",
                    TextAlignment = TextAlignment.CenterLeft,
                    TextColor = CSS_Color.PromptingColor1,
                    TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
                };
                contentView.AddChidren(btnMaxValuesText);
                #endregion
                #region 色温
                //色温
                var btnTempClolor = new Button();
                btnTempClolor.X = Application.GetRealWidth(35);
                btnTempClolor.Y = Application.GetRealHeight(159);
                btnTempClolor.Width = Application.GetRealWidth(224);
                btnTempClolor.Height = Application.GetRealHeight(21);
                btnTempClolor.TextAlignment = TextAlignment.CenterLeft;
                btnTempClolor.TextColor = CSS_Color.FirstLevelTitleColor;
                btnTempClolor.TextSize = CSS_FontSize.PromptFontSize_FirstLevel;
                btnTempClolor.TextID = StringId.ColorTemperature;
                contentView.AddChidren(btnTempClolor);
                //2700K
                var btnTempClolorMin = new Button();
                btnTempClolorMin.Y = btnTempClolor.Bottom + Application.GetRealHeight(9);
                btnTempClolorMin.Width = Application.GetRealWidth(54);
                btnTempClolorMin.Height = Application.GetRealHeight(21);
                btnTempClolorMin.Text = "2700K";
                btnTempClolorMin.TextAlignment = TextAlignment.CenterRight;
                btnTempClolorMin.TextColor = CSS_Color.PromptingColor1;
                btnTempClolorMin.TextSize = CSS_FontSize.PromptFontSize_FirstLevel;
                contentView.AddChidren(btnTempClolorMin);
                //滑动条的背景图片
                var btnColorTemplatrueBack = new Button();
                //需要减掉滑动条的左右间距
                btnColorTemplatrueBack.Width = Application.GetRealWidth(210 - 20 * 2);
                btnColorTemplatrueBack.Height = Application.GetRealHeight(8);
                btnColorTemplatrueBack.Gravity = Gravity.CenterHorizontal;
                btnColorTemplatrueBack.UnSelectedImagePath = "FunctionIcon/Light/ColorTemperatureBar.png";
                contentView.AddChidren(btnColorTemplatrueBack);
                //滑动条控件
                var barColorTemplatrue = new CCTSeekBarControl();
                barColorTemplatrue.X = btnTempClolorMin.Right;
                barColorTemplatrue.Y = Application.GetRealHeight(340);
                barColorTemplatrue.MinValue = 27;
                barColorTemplatrue.MaxValue = 65;
                barColorTemplatrue.ProgressBarColor = 0x00000000;//全部透明
                barColorTemplatrue.ProgressBarUnEnableColor = 0x00000000;
                barColorTemplatrue.SeekBarBackgroundColor = 0x00000000;
                contentView.AddChidren(barColorTemplatrue);
                barColorTemplatrue.Y = btnTempClolorMin.Y - (barColorTemplatrue.Height - btnTempClolorMin.Height) / 2;
                //显示上方的Txt
                barColorTemplatrue.ShowCustomTextView(Application.GetRealWidth(50), CSS_FontSize.PromptFontSize_FirstLevel, CSS_Color.FirstLevelTitleColor);
                var cct = 27;
                int.TryParse(cctLight.status.Find((obj)=>obj.key == FunctionAttributeKey.CCT).value, out cct);
                barColorTemplatrue.Progress = cct;
                //设置初始值
                barColorTemplatrue.SetCustomText(barColorTemplatrue.Progress * 100 + "K");
                //变更背景图的Y轴坐标
                btnColorTemplatrueBack.Y = barColorTemplatrue.Y + (barColorTemplatrue.Height - btnColorTemplatrueBack.Height) / 2;
                //6500K
                var btnTempClolorMax = new Button();
                btnTempClolorMax.Y = btnTempClolorMin.Y;
                btnTempClolorMax.X = barColorTemplatrue.Right;
                btnTempClolorMax.Width = Application.GetRealWidth(54);
                btnTempClolorMax.Height = Application.GetRealHeight(21);
                btnTempClolorMax.Text = "6500K";
                btnTempClolorMax.TextAlignment = TextAlignment.CenterLeft;
                btnTempClolorMax.TextColor = CSS_Color.PromptingColor1;
                btnTempClolorMax.TextSize = CSS_FontSize.PromptFontSize_FirstLevel;
                contentView.AddChidren(btnTempClolorMax);
                #endregion
                #region RGB
                var btnCurColor = new Button()
                {
                    X = Application.GetRealWidth(24),
                    Y = Application.GetRealHeight(241),
                    Width = Application.GetMinRealAverage(24),
                    Height = Application.GetMinRealAverage(24),
                    Radius = (uint)Application.GetMinRealAverage(8),
                    BorderColor = CSS_Color.PromptingColor2,
                    BorderWidth = 1,
                    BackgroundColor = (uint)(0xFF000000 + new Light().GetRGBcolor(new Function(),rgbLight.status.Find((obj) => obj.key == FunctionAttributeKey.RGB).value))
                };
                contentView.AddChidren(btnCurColor);
                //色盘的桌布控件(限制那个白色滑动球使用)
                var framePickerBack = new FrameLayout();
                framePickerBack.Gravity = Gravity.CenterHorizontal;
                framePickerBack.Y = Application.GetRealHeight(249);
                framePickerBack.Width = Application.GetMinRealAverage(198);
                framePickerBack.Height = Application.GetMinRealAverage(198);
                contentView.AddChidren(framePickerBack);
                var colorPicker = new ColorPicker()
                {
                    ColorImagePath = "FunctionIcon/Light/ColorWheel.png",
                };
                framePickerBack.AddChidren(colorPicker);
                #endregion
            }
            else if (hadDimming && !hadCCT && !hadRGB)
            {
                contentView.Height = Application.GetRealHeight(211);
                contentView.Width = Application.GetRealWidth(343);
                contentView.Gravity = Gravity.Center;
                contentView.Radius = (uint)Application.GetRealWidth(12);
                contentView.AddChidren(titleView);
            }
        }
        /// <summary>
        /// 加载调光属性设置控件
        /// </summary>
        /// <param name="attrView"></param>
        void LoadDimmingAttrView(VerticalScrolViewLayout attrView)
        {
            commandDic.TryAdd(FunctionAttributeKey.Percent, "0");
            var dimmingView = new FrameLayout()
            {
                Height = Application.GetRealHeight(54 + 11)
            };
            attrView.AddChidren(dimmingView);
            #region 亮度调节
            var btnBrightnessText = new Button()
            {
                X = Application.GetRealWidth(35),
                Y = Application.GetRealHeight(1),
                Width = Application.GetRealWidth(224),
                Height = Application.GetRealHeight(25),
                TextAlignment = TextAlignment.CenterLeft,
                TextColor = CSS_Color.FirstLevelTitleColor,
                TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
                TextID = StringId.Brightness,
            };
            btnBrightnessText.Text = Language.StringByID(StringId.Brightness) + " " + commandDic[FunctionAttributeKey.Percent] + "%";
            dimmingView.AddChidren(btnBrightnessText);
            var btnMinValuesText = new Button()
            {
                X = Application.GetRealWidth(35),
                Y = btnBrightnessText.Bottom,
                Width = Application.GetRealWidth(40),
                Height = Application.GetRealHeight(21),
                Text = "0%",
                TextAlignment = TextAlignment.CenterLeft,
                TextColor = CSS_Color.PromptingColor1,
                TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
            };
            dimmingView.AddChidren(btnMinValuesText);
            var dimmerBar = new DiyImageSeekBar()
            {
                X = Application.GetRealWidth(45 + 10),
                Y = Application.GetRealHeight(11),
                Width = Application.GetRealWidth(220),
                Height = Application.GetRealHeight(54),
                SeekBarViewHeight = Application.GetRealHeight(8),
                ThumbImagePath = "Public/ThumbImage.png",
                ThumbImageHeight = Application.GetRealHeight(54),
                ProgressTextColor = CSS_Color.FirstLevelTitleColor,
                ProgressTextSize = CSS_FontSize.PromptFontSize_FirstLevel,
                ProgressBarColor = CSS_Color.AuxiliaryColor1,
                MaxValue = 100,
                Progress = Convert.ToInt32(commandDic[FunctionAttributeKey.Percent]),
                SeekBarPadding = Application.GetRealWidth(20),
                IsProgressTextShow = false,
                ProgressChangeDelayTime = 0,
            };
            dimmingView.AddChidren(dimmerBar);
            dimmerBar.OnProgressChangedEvent = (sender, e) => {
                btnBrightnessText.Text = Language.StringByID(StringId.Brightness) + " " + e + "%";
            };
            dimmerBar.OnStopTrackingTouchEvent = (sender, e) => {
                commandDic[FunctionAttributeKey.Percent] = dimmerBar.Progress.ToString();
                btnBrightnessText.Text = Language.StringByID(StringId.Brightness) + " " + e + "%";
            };
            var btnMaxValuesText = new Button()
            {
                X = dimmerBar.Right,
                Y = btnBrightnessText.Bottom,
                Width = Application.GetRealWidth(55),
                Height = Application.GetRealHeight(21),
                Text = "100%",
                TextAlignment = TextAlignment.CenterLeft,
                TextColor = CSS_Color.PromptingColor1,
                TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
            };
            dimmingView.AddChidren(btnMaxValuesText);
            #endregion
        }
        /// <summary>
        /// 加载cct属性设置控件
        /// </summary>
        /// <param name="attrView"></param>
        void LoadCctAttrView(VerticalScrolViewLayout attrView)
        {
            #region 色温
            var cctView = new FrameLayout()
            {
                Height = Application.GetRealHeight(54 + 11)
            };
            attrView.AddChidren(cctView);
            //色温
            var btnTempClolor = new Button();
            btnTempClolor.X = Application.GetRealWidth(35);
            btnTempClolor.Y = Application.GetRealHeight(1);
            btnTempClolor.Width = Application.GetRealWidth(224);
            btnTempClolor.Height = Application.GetRealHeight(21);
            btnTempClolor.TextAlignment = TextAlignment.CenterLeft;
            btnTempClolor.TextColor = CSS_Color.FirstLevelTitleColor;
            btnTempClolor.TextSize = CSS_FontSize.PromptFontSize_FirstLevel;
            btnTempClolor.TextID = StringId.ColorTemperature;
            cctView.AddChidren(btnTempClolor);
            //2700K
            var btnTempClolorMin = new Button()
            {
                X = Application.GetRealWidth(35),
                Y = btnTempClolor.Bottom,
                Width = Application.GetRealWidth(40),
                Height = Application.GetRealHeight(21),
            };
            btnTempClolorMin.Width = Application.GetRealWidth(54);
            btnTempClolorMin.Height = Application.GetRealHeight(21);
            btnTempClolorMin.Text = "2700K";
            btnTempClolorMin.TextAlignment = TextAlignment.CenterLeft;
            btnTempClolorMin.TextColor = CSS_Color.PromptingColor1;
            btnTempClolorMin.TextSize = CSS_FontSize.PromptFontSize_FirstLevel;
            cctView.AddChidren(btnTempClolorMin);
            //滑动条的背景图片
            var btnColorTemplatrueBack = new Button()
            {
                X = Application.GetRealWidth(55 + 22 + 15),
                Y = Application.GetRealHeight(11),
                Width = Application.GetRealWidth(180),
                Height = Application.GetRealHeight(54),
            };
            btnColorTemplatrueBack.UnSelectedImagePath = "FunctionIcon/Light/ColorTemperatureBar.png";
            btnColorTemplatrueBack.Height = Application.GetRealHeight(8);
            btnColorTemplatrueBack.Gravity = Gravity.CenterHorizontal;
            cctView.AddChidren(btnColorTemplatrueBack);
            //滑动条控件
            var barColorTemplatrue = new CCTSeekBarControl()
            {
                X = Application.GetRealWidth(55 + 22),
                Y = Application.GetRealHeight(11),
                Width = Application.GetRealWidth(220),
                Height = Application.GetRealHeight(54),
            };
            barColorTemplatrue.MinValue = 27;
            barColorTemplatrue.MaxValue = 65;
            barColorTemplatrue.ProgressBarColor = 0x00000000;//全部透明
            barColorTemplatrue.ProgressBarUnEnableColor = 0x00000000;
            barColorTemplatrue.SeekBarBackgroundColor = 0x00000000;
            cctView.AddChidren(barColorTemplatrue);
            barColorTemplatrue.Y = btnTempClolorMin.Y - (barColorTemplatrue.Height - btnTempClolorMin.Height) / 2;
            var cct = 27;
            //int.TryParse(cctLight.status.Find((obj) => obj.key == FunctionAttributeKey.CCT).value, out cct);
            barColorTemplatrue.Progress = cct;
            //设置初始值
            btnTempClolor.Text = Language.StringByID(StringId.ColorTemperature) + " " + (barColorTemplatrue.Progress * 100 + "K");
            barColorTemplatrue.OnProgressChangedEvent = (sender, e) =>
            {
                btnTempClolor.Text = Language.StringByID(StringId.ColorTemperature) + " " + (barColorTemplatrue.Progress * 100 + "K");
            };
            barColorTemplatrue.OnStopTrackingTouchEvent = (sender, e) =>
            {
                commandDic[FunctionAttributeKey.CCT] = (barColorTemplatrue.Progress*100).ToString();
            };
            //变更背景图的Y轴坐标
            btnColorTemplatrueBack.Y = barColorTemplatrue.Y + (barColorTemplatrue.Height - btnColorTemplatrueBack.Height) / 2;
            //6500K
            var btnTempClolorMax = new Button();
            btnTempClolorMax.Y = btnTempClolorMin.Y;
            btnTempClolorMax.X = barColorTemplatrue.Right - Application.GetRealWidth(30);
            btnTempClolorMax.Width = Application.GetRealWidth(54);
            btnTempClolorMax.Height = Application.GetRealHeight(21);
            btnTempClolorMax.Text = "6500K";
            btnTempClolorMax.TextAlignment = TextAlignment.CenterRight;
            btnTempClolorMax.TextColor = CSS_Color.PromptingColor1;
            btnTempClolorMax.TextSize = CSS_FontSize.PromptFontSize_FirstLevel;
            cctView.AddChidren(btnTempClolorMax);
            #endregion
        }
        /// <summary>
        /// 加载rgb属性设置控件
        /// </summary>
        /// <param name="attrView"></param>
        void LoadRgbAttrView(VerticalScrolViewLayout attrView)
        {
            #region RGB
            commandDic.TryAdd(FunctionAttributeKey.RGB, "255,255,255");
            var rgbView = new FrameLayout()
            {
                Height = Application.GetRealHeight(248)
            };
            attrView.AddChidren(rgbView);
            var btnCurColor = new Button()
            {
                X = Application.GetRealWidth(24),
                Y = Application.GetRealHeight(10),
                Width = Application.GetMinRealAverage(24),
                Height = Application.GetMinRealAverage(24),
                Radius = (uint)Application.GetMinRealAverage(8),
                BorderColor = CSS_Color.PromptingColor2,
                BorderWidth = 1,
                BackgroundColor = (uint)(0xFF000000 + tempLight.GetRGBcolor(commandDic[FunctionAttributeKey.RGB]))
            };
            rgbView.AddChidren(btnCurColor);
            //色盘的桌布控件(限制那个白色滑动球使用)
            var framePickerBack = new FrameLayout();
            framePickerBack.Gravity = Gravity.CenterHorizontal;
            framePickerBack.Y = Application.GetRealHeight(20);
            framePickerBack.Width = Application.GetMinRealAverage(198);
            framePickerBack.Height = Application.GetMinRealAverage(198);
            rgbView.AddChidren(framePickerBack);
            var colorPicker = new ColorPicker()
            {
                ColorImagePath = "FunctionIcon/Light/ColorWheel.png",
            };
            framePickerBack.AddChidren(colorPicker);
            //白点控件
            var btnWhiteRound = new Button();
            btnWhiteRound.Width = Application.GetRealWidth(24);
            btnWhiteRound.Height = Application.GetRealWidth(24);
            btnWhiteRound.UnSelectedImagePath = "FunctionIcon/Light/ColorWheelTip.png";
            btnWhiteRound.Visible = false;
            framePickerBack.AddChidren(btnWhiteRound);
            //当前点击的【点】是否正确
            bool pointIsRight = false;
            //圆的半径(考虑边界,需要设置它的半径比较小一点)
            int circleR = colorPicker.Width / 2 - Application.GetRealWidth(12);
            colorPicker.ColorChaged += (sender2, e2) => {
                string rgbString = (e2[0] + "," + e2[1] + "," + e2[2]).ToString();
                commandDic[FunctionAttributeKey.RGB] = rgbString;
                btnCurColor.BackgroundColor = (uint)(0xFF000000 + tempLight.GetRGBcolor(rgbString));
            };
            colorPicker.MouseDownEventHandler += (sender, e) =>
            {
                pointIsRight = this.CheckPoint(circleR, colorPicker.Width / 2, colorPicker.Height / 2, (int)e.X, (int)e.Y);
                if (pointIsRight == false)
                {
                    //点的区域不是圆盘内
                    return;
                }
                //显示白点
                btnWhiteRound.X = (int)e.X - btnWhiteRound.Width / 2;
                btnWhiteRound.Y = (int)e.Y - btnWhiteRound.Height / 2;
                if (btnWhiteRound.Visible == false)
                {
                    btnWhiteRound.Visible = true;
                }
            };
            colorPicker.MouseMoveEventHandler += (sender, e) =>
            {
                //当鼠标点下事件处理
                colorPicker.MouseDownEventHandler(sender, e);
            };
            #endregion
        }
        /// <summary>
        /// 检测点击点
        /// </summary>
        /// <param name="circleR">圆的半径</param>
        /// <param name="circleX">圆心X轴</param>
        /// <param name="circleY">圆心Y轴</param>
        /// <param name="pointX">点击点的X轴</param>
        /// <param name="pointY">点击点的Y轴</param>
        /// <returns></returns>
        private bool CheckPoint(int circleR, int circleX, int circleY, int pointX, int pointY)
        {
            int dwidth = circleX - pointX;
            if (dwidth < 0) { dwidth *= -1; }
            int dHeight = circleY - pointY;
            if (dHeight < 0) { dHeight *= -1; }
            //根据三角函数,求三角形的斜边长
            int dlength = dwidth * dwidth + dHeight * dHeight;
            //半径长度(不开方,所以是按平方算)
            circleR *= circleR;
            if (dlength < circleR)
            {
                //如果组成的三角形并没有长过半径,则代表还在圆内(不允许点边界)
                return true;
            }
            return false;
        }
    }
}