wei
2021-06-23 d4973876384be55df64de45db8a511d1e0330872
HDL_ON/UI/UI2/FuntionControlView/Electrical/IrFanPage.cs
@@ -1,10 +1,239 @@
using System;
namespace HDL_ON.UI.UI2.FuntionControlView.Electrical
using System.Collections.Generic;
using HDL_ON.DriverLayer;
using HDL_ON.Entity;
using HDL_ON.Stan;
using HDL_ON.UI.CSS;
using Shared;
namespace HDL_ON.UI
{
    public class IrFanPage
    public class IrFanPage : DeviceFunctionCardCommonForm
    {
        public IrFanPage()
        #region ■ 变量声明___________________________
        /// <summary>
        /// 图标
        /// </summary>
        private Button btnIcon = null;
        #endregion
        #region ■ 初始化_____________________________
        /// <summary>
        /// 初始化白色区域的内容
        /// </summary>
        public override void InitFrameWhiteContent()
        {
            base.ShowColltionButton = false;
            base.SetTitleText(Language.StringByID(StringId.Electric));
            //初始化第一个索引页的内容
            this.InitFrameWhiteContent1();
            ;
        }
        /// <summary>
        /// 初始化第一个索引页的内容
        /// </summary>
        private void InitFrameWhiteContent1()
        {
            btnIcon = new Button()
            {
                Gravity = Gravity.CenterHorizontal,
                Y = Application.GetRealHeight(88),
                Width = Application.GetRealWidth(134),
                Height = Application.GetRealHeight(134),
                UnSelectedImagePath = "FunctionIcon/IrFan/FanIcon.png",
            };
            FrameWhiteCentet1.AddChidren(btnIcon);
            var patternView = new IrFanControl("FunctionIcon/IrFan/PatternIcon.png",
                                            "FunctionIcon/IrFan/PatternIconOn.png",
                                            Language.StringByID(StringId.Mode),
                                            "");
            patternView.Y = Application.GetRealHeight(263);
            patternView.X = Application.GetRealWidth(57);
            patternView.Width = Application.GetRealWidth(96);
            patternView.Height = Application.GetRealHeight(74);
            FrameWhiteCentet1.AddChidren(patternView);
            EventHandler<MouseEventArgs> mode_EventHandler = (sender, e) =>
            {
                Dictionary<string, string> d = new Dictionary<string, string>();
                d.Add("mode", "");
                Control.Ins.SendWriteCommand(device, d);
            };
            patternView.SetThouchEvent(mode_EventHandler);
            var swingView = new IrFanControl("FunctionIcon/IrFan/HeadSwingingIcon.png",
                                            "FunctionIcon/IrFan/HeadSwingingIconOn.png",
                                            Language.StringByID(StringId.HeadSwinging),
                                            "");
            swingView.Y = Application.GetRealHeight(263);
            swingView.X = Application.GetRealWidth(216);
            swingView.Width = Application.GetRealWidth(96);
            swingView.Height = Application.GetRealHeight(74);
            FrameWhiteCentet1.AddChidren(swingView);
            EventHandler<MouseEventArgs> swing_EventHandler = (sender, e) =>
            {
                Dictionary<string, string> d = new Dictionary<string, string>();
                d.Add("swing", "");
                Control.Ins.SendWriteCommand(device, d);
            };
            swingView.SetThouchEvent(swing_EventHandler);
            var timingView = new IrFanControl("FunctionIcon/IrFan/TimingIcon.png",
                                            "FunctionIcon/IrFan/TimingIconOn.png",
                                            Language.StringByID(StringId.Timing),
                                            "");
            timingView.Y = Application.GetRealHeight(366);
            timingView.X = Application.GetRealWidth(57);
            timingView.Width = Application.GetRealWidth(96);
            timingView.Height = Application.GetRealHeight(74);
            FrameWhiteCentet1.AddChidren(timingView);
            EventHandler<MouseEventArgs> timing_EventHandler = (sender, e) =>
            {
                Dictionary<string, string> d = new Dictionary<string, string>();
                d.Add("timer", "");
                Control.Ins.SendWriteCommand(device, d);
            };
            timingView.SetThouchEvent(timing_EventHandler);
            var airVolumeView = new IrFanControl("FunctionIcon/IrFan/SpeedIcon.png",
                                            "FunctionIcon/IrFan/SpeedIconOn.png",
                                            Language.StringByID(StringId.AirVolume),
                                            "");
            airVolumeView.Y = Application.GetRealHeight(263);
            airVolumeView.X = Application.GetRealWidth(216);
            airVolumeView.Width = Application.GetRealWidth(96);
            airVolumeView.Height = Application.GetRealHeight(74);
            FrameWhiteCentet1.AddChidren(airVolumeView);
            EventHandler<MouseEventArgs> speed_EventHandler = (sender, e) =>
            {
                Dictionary<string, string> d = new Dictionary<string, string>();
                d.Add("speed", "");
                Control.Ins.SendWriteCommand(device, d);
            };
            airVolumeView.SetThouchEvent(speed_EventHandler);
            Button btnPower = new Button()
            {
                Gravity = Gravity.CenterHorizontal,
                Y = Application.GetRealHeight(468),
                Width = Application.GetRealWidth(32),
                Height = Application.GetRealWidth(32),
                UnSelectedImagePath = "FunctionIcon/IrFan/PowerIcon.png",
                SelectedImagePath = "FunctionIcon/IrFan/PowerIconOn.png"
            };
            FrameWhiteCentet1.AddChidren(btnPower);
            btnPower.MouseDownEventHandler = (sender, e) =>
            {
                btnPower.IsSelected = true;
            };
            btnPower.MouseUpEventHandler = (sender, e) => {
                new System.Threading.Thread(() => {
                    Dictionary<string, string> d = new Dictionary<string, string>();
                    d.Add(FunctionAttributeKey.OnOff, "");
                    Control.Ins.SendWriteCommand(device, d);
                    System.Threading.Thread.Sleep(500);
                    Application.RunOnMainThread(() => {
                        btnPower.IsSelected = false;
                    });
                }) { IsBackground = true }.Start();
            };
        }
        #endregion
        #region ■ 设备状态反馈_______________________
        /// <summary>
        /// 设备状态反馈
        /// </summary>
        /// <param name="i_LocalDevice"></param>
        public override void DeviceStatuPush(Function i_LocalDevice)
        {
        }
        #endregion
    }
}
    public class IrFanControl : FrameLayout
    {
        private Button btnIcon;
        private Button btnTitle;
        public bool Lighting = false;
        public IrFanControl(string unSelectedIconPath, string selectedIconPath, string title, string time)
        {
            btnIcon = new Button()
            {
                Gravity = Gravity.CenterHorizontal,
                Width = Application.GetRealWidth(28),
                Height = Application.GetRealWidth(28),
                UnSelectedImagePath = unSelectedIconPath,
                SelectedImagePath = selectedIconPath,
            };
            this.AddChidren(btnIcon);
            btnTitle = new Button()
            {
                Gravity = Gravity.Center,
                Text = title,
                Height = Application.GetRealHeight(42),
                TextColor = CSS_Color.TextualColor,
                SelectedTextColor = CSS_Color.MainColor,
                TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
            };
            this.AddChidren(btnTitle);
        }
        public void SetViewStatus(bool state)
        {
            btnIcon.IsSelected = btnTitle.IsSelected = Lighting = state;
        }
        /// <summary>
        /// 设置点击事件
        /// </summary>
        public void SetThouchEvent(EventHandler<MouseEventArgs> eventHandler)
        {
            btnIcon.MouseUpEventHandler = eventHandler;
            btnTitle.MouseUpEventHandler = eventHandler;
            btnIcon.MouseDownEventHandler = (sender, e) => {
                btnIcon.IsSelected = true;
            };
            btnTitle.MouseDownEventHandler = (sender, e) => {
                btnIcon.IsSelected = true;
            };
            btnIcon.MouseUpEventHandler += (sender, e) => {
                new System.Threading.Thread(() => {
                    System.Threading.Thread.Sleep(500);
                    Application.RunOnMainThread(() =>
                    {
                        btnIcon.IsSelected = true;
                    });
                })
                { IsBackground = true }.Start();
            };
            btnTitle.MouseUpEventHandler += (sender, e) => {
                new System.Threading.Thread(() => {
                    System.Threading.Thread.Sleep(500);
                    Application.RunOnMainThread(() =>
                    {
                        btnIcon.IsSelected = true;
                    });
                })
                { IsBackground = true }.Start();
            };
        }
    }
}