wxr
2020-01-18 4cc04639fbadde3a7f3b9875353df0d90fc09043
HDL_ON/UI/UI2/1-HomePage/UI/HomePage.cs
@@ -1,16 +1,14 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using HDL_ON.Entity;
using Newtonsoft.Json.Linq;
using Shared;
namespace HDL_ON.UI
{
    public class HomePage : FrameLayout
    public partial class HomePage : FrameLayout
    {
        #region 控件列表
        FrameLayout bodyView;
        static FrameLayout bodyView;
        /// <summary>
        /// 顶部信息区域
        /// </summary>
@@ -35,6 +33,18 @@
        /// 当前pm2.5状态
        /// </summary>
        Button btnPm25Values;
        /// <summary>
        /// 灯光区域集合
        /// </summary>
        static Dictionary<string, FrameLayout> LightViews;
        /// <summary>
        /// 空调区域集合
        /// </summary>
        static Dictionary<string, FrameLayout> AcViews;
        /// <summary>
        /// 窗帘区域集合
        /// </summary>
        static Dictionary<string, FrameLayout> CurtainViews;
        #endregion
        public HomePage()
@@ -156,10 +166,15 @@
                Gravity = Gravity.CenterHorizontal,
                Width = Application.GetRealWidth(343),
                Height = Application.GetRealHeight(28),
            };
            topView.AddChidren(msgView);
            var btngb = new Button()
            {
                BackgroundColor = CSS.CSS_Color.MainColor,//0x3F4484F4,//
                Alpha = 0.4f,
            };
            topView.AddChidren(msgView);
            msgView.AddChidren(btngb);
            Button btnMsgIcon;
            btnMsgIcon = new Button()
@@ -219,7 +234,7 @@
            btnChangeFunction = new Button()
            {
                Width = Application.GetRealWidth(114),
                TextID = InternationalizationString.Functions,
                TextID = StringId.Functions,
                SelectedTextColor = CSS.CSS_Color.MainColor,
                TextColor = CSS.CSS_Color.PromptingColor1,
                //TextSize = CSS.CSS_FontSize.TextFontSize,
@@ -234,7 +249,7 @@
            {
                X = btnChangeFunction.Right,
                Gravity = Gravity.CenterVertical,
                Width = Application.GetRealWidth(2),
                Width = Application.GetRealWidth(1),
                Height = Application.GetRealHeight(14),
                BackgroundColor = CSS.CSS_Color.PromptingColor1,
            };
@@ -245,7 +260,7 @@
            {
                X = btnLine.Right,
                Width = Application.GetRealWidth(114),
                TextID = InternationalizationString.Scenes,
                TextID = StringId.Scenes,
                SelectedTextColor = CSS.CSS_Color.MainColor,
                TextColor = CSS.CSS_Color.PromptingColor1,
                TextSize = CSS.CSS_FontSize.TextFontSize,
@@ -262,14 +277,14 @@
            contextView = new VerticalScrolViewLayout()
            {
                Y = changeView.Bottom + Application.GetRealHeight(10),
                Height = Application.GetRealHeight(340 + 30), //20为超出部分
                Height = Application.GetRealHeight(310 + 30), //20为超出部分
            };
            bodyView.AddChidren(contextView);
            var lightViews = new Dictionary<string, FrameLayout>();
            var acViews = new Dictionary<string, FrameLayout>();
            var curtainViews = new Dictionary<string, FrameLayout>();
            FrameLayout rowView = new FrameLayout();
            LightViews = new Dictionary<string, FrameLayout>();
            AcViews = new Dictionary<string, FrameLayout>();
            CurtainViews = new Dictionary<string, FrameLayout>();
            var rowView = new FrameLayout();
            foreach (var function in DB_ResidenceData.residenceData.functions)
            {
@@ -281,12 +296,17 @@
                    };
                    contextView.AddChidren(rowView);
                }
                var functionView_X = Application.GetRealWidth((182 + 7) * (index % 2));
                if (index % 2 == 0)
                {
                    functionView_X += 7;
                }
                var functionView = new FrameLayout()
                {
                    X = Application.GetRealWidth((182 + 7) * (index % 2)),
                    X = functionView_X,
                    Width = Application.GetRealWidth(182),
                    Height = Application.GetRealHeight(140),
                    Tag = function.sid
                };
                rowView.AddChidren(functionView);
                var btnbg = new Button()
@@ -299,17 +319,17 @@
                {
                    case FunctionType.Light:
                        #region 灯光 Light
                        lightViews.Add(function.sid, functionView);
                        LightViews.Add(function.sid, functionView);
                        #endregion
                        break;
                    case FunctionType.Curtain:
                        #region 窗帘
                        curtainViews.Add(function.sid, functionView);
                        CurtainViews.Add(function.sid, functionView);
                        #endregion
                        break;
                    case FunctionType.AC:
                        #region 空调 AC
                        acViews.Add(function.sid, functionView);
                        AcViews.Add(function.sid, functionView);
                        #endregion
                        break;
@@ -317,11 +337,8 @@
                LoadControlView(functionView, function);
            }
            contextView.AddChidren(new Button { Height = Application.GetRealHeight(30) });
            #endregion
        }
        /// <summary>
        /// 加载控制卡片
@@ -343,9 +360,9 @@
            {
                X = Application.GetRealWidth(21),
                Y = Application.GetRealHeight(10) + btnIcon.Bottom,
                Text = function.Name,
                Text = function.name,
                IsBold = true,
                TextColor = CSS.CSS_Color.PromptingColor1,
                TextColor = CSS.CSS_Color.FirstLevelTitleColor,
                TextSize = CSS.CSS_FontSize.TextFontSize,
                Height = Application.GetRealHeight(24),
                Width = Application.GetRealWidth(140),
@@ -380,10 +397,11 @@
                Y = btnZone.Bottom,
                Height = Application.GetRealHeight(18),
                Width = Application.GetRealWidth(113),
                TextColor = CSS.CSS_Color.PromptingColor1,
                SelectedTextColor = CSS.CSS_Color.MainBackgroundColor,
                TextColor = 0x00000000,
                TextSize = CSS.CSS_FontSize.PromptFontSize_SecondaryLevel,
                TextAlignment = TextAlignment.CenterLeft,
                Tag = "state",
                Text = function.lastState
            };
            view.AddChidren(btnState);
@@ -396,7 +414,7 @@
                Width = Application.GetMinRealAverage(24),
                Height = Application.GetMinRealAverage(24),
                UnSelectedImagePath = "Collection/CollectionIcon.png",
                SelectedImagePath = "Collection/CollectionOnIcon.png",
                SelectedImagePath = "Collection/CollectionIcon.png",
            };
            view.AddChidren(btnCollection);
@@ -405,13 +423,12 @@
            {
                X = Application.GetRealWidth(122),
                Y = Application.GetRealHeight(92),
                Width = Application.GetRealWidth(48),
                Height = Application.GetRealHeight(36),
                Width = Application.GetMinRealAverage(48),
                Height = Application.GetMinRealAverage(36),
                UnSelectedImagePath = "Collection/Switch.png",
                SelectedImagePath = "Collection/SwitchOn.png",
            };
            view.AddChidren(btnSwitch);
            switch (function.funcType)
            {
@@ -421,15 +438,25 @@
                    btnIcon.SelectedImagePath = "Public/FunctionIcon/LightOnIcon.png";
                    btnSwitch.MouseUpEventHandler += (sender, e) => {
                        var jsonString = new JObject { { "Namespace", "HDL" }, { "Command", "write" }, { "Type", "device" } };
                        var data = new JObject { { "Switch", 1 }, { "Dimmer", 100 }, { "sid", "0001002019101209000025670400010001" } };
                        jsonString.Add("objects", data);
                        Control.Send(jsonString, function, 3);
                        var curState = !btnSwitch.IsSelected;
                        for (int i = 0; i < view.ChildrenCount; i++)
                        {
                            if (view.GetChildren(i).GetType() == typeof(Button))
                            {
                                var btn = view.GetChildren(i) as Button;
                                btn.IsSelected = curState;
                            }
                        }
                        new System.Threading.Thread(() =>
                        {
                            var light = function as Light;
                            light.state = btnSwitch.IsSelected ? 1 : 0;
                            Control.Send("write", function, 3);
                        })
                        { IsBackground = true }.Start();
                    };
                    #endregion
                    break;
                case FunctionType.Curtain:
                    #region 窗帘
                    btnIcon.UnSelectedImagePath = "Public/FunctionIcon/CurtainIcon.png";
@@ -451,6 +478,5 @@
            }
        }
    }
}