wxr
2021-06-09 cb6e11c5067ecaba4d8f9907989154167c1e8943
HDL_ON/UI/UI2/FuntionControlView/Electrical/PjtPage.cs
New file
@@ -0,0 +1,674 @@
using System;
using System.Collections.Generic;
using HDL_ON.DriverLayer;
using HDL_ON.Entity;
using HDL_ON.UI.CSS;
using Shared;
namespace HDL_ON.UI
{
    /// <summary>
    /// 投影仪页面
    /// </summary>
    public class PjtPage : FrameLayout
    {
        #region 控件集合
        FrameLayout bodyView;
        /// <summary>
        /// 功能名称按钮
        /// </summary>
        Button btnFunctionName;
        /// <summary>
        /// 房间楼层信息按钮
        /// </summary>
        Button btnFromFoorAndRoom;
        /// <summary>
        /// 收藏按钮
        /// </summary>
        Button btnCollection;
        FrameLayout topMenuView;
        Button btnTopMenuUp;
        Button btnTopMenuLeft;
        Button btnTopMenuRight;
        Button btnTopMenuDown;
        Button btnOk;
        FrameLayout channleView;
        Button btnChlReduce;
        Button btnChlPlus;
        FrameLayout volView;
        Button btnVolReduce;
        Button btnVolPlus;
        Button btnBack;
        Button btnMenu;
        Button btnMore;
        Button btnPower;
        #endregion
        #region 区域变量
        //TV tvTemp = new TV();
        Function device;
        Button btnCollection_Out;
        Button btnFunctionName_Out;
        Button btnFromFloor_Out;
        /// <summary>
        /// 刷新显示信息
        /// </summary>
        Action actionRefresh;
        #endregion
        public PjtPage(Function func)
        {
            bodyView = this;
            device = func;
        }
        public void LoadPage(Button btnCollectionIcon, Button btnFunctionNameOut, Button btnFromFloorOut)
        {
            bodyView.BackgroundColor = CSS_Color.BackgroundColor;
            btnCollection_Out = btnCollectionIcon;
            btnFunctionName_Out = btnFunctionNameOut;
            btnFromFloor_Out = btnFromFloorOut;
            FrameLayout controlView = new FrameLayout()
            {
                Gravity = Gravity.CenterHorizontal,
                Y = Application.GetRealHeight(88),
                Width = Application.GetRealWidth(327),
                Height = Application.GetRealHeight(526),
                BackgroundImagePath = "Public/Fragmentbg.png",
            };
            bodyView.AddChidren(controlView);
            btnFunctionName = new Button()
            {
                X = Application.GetRealWidth(16),
                Y = Application.GetRealHeight(14),
                Width = Application.GetRealWidth(270),
                Height = Application.GetRealHeight(37),
                TextColor = CSS_Color.FirstLevelTitleColor,
                TextAlignment = TextAlignment.CenterLeft,
                TextSize = CSS_FontSize.EmphasisFontSize_FirstLevel,
                Text = device.name,
            };
            controlView.AddChidren(btnFunctionName);
            btnFromFoorAndRoom = new Button()
            {
                X = Application.GetRealWidth(16),
                Y = btnFunctionName.Bottom,
                Width = Application.GetRealWidth(270),
                Height = Application.GetRealHeight(21),
                TextColor = CSS_Color.PromptingColor1,
                TextAlignment = TextAlignment.CenterLeft,
                TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
                Text = device.GetRoomListName()
            };
            controlView.AddChidren(btnFromFoorAndRoom);
            btnCollection = new Button()
            {
                X = Application.GetRealWidth(273),
                Y = Application.GetRealHeight(14),
                Width = Application.GetMinRealAverage(40),
                Height = Application.GetMinRealAverage(40),
                SelectedImagePath = "Collection/CollectionIcon.png",
                UnSelectedImagePath = "Collection/CollectionGrayIcon.png",
                IsSelected = device.collect
            };
            controlView.AddChidren(btnCollection);
            //2020-12-16 如果是成员隐藏收藏功能
            //if (!DB_ResidenceData.Instance.CurrentRegion.isOtherShare)
            //{
            //    controlView.AddChidren(btnCollection);
            //}
            #region 轮盘控制区域
            topMenuView = new FrameLayout()
            {
                Y = Application.GetRealHeight(88),
                Gravity = Gravity.CenterHorizontal,
                Width = Application.GetRealWidth(199),
                Height = Application.GetRealWidth(199),
                BackgroundImagePath = "FunctionIcon/Electrical/TV/TVOkIcon.png",
            };
            controlView.AddChidren(topMenuView);
            btnTopMenuUp = new Button()
            {
                Gravity = Gravity.CenterHorizontal,
                Width = Application.GetRealWidth(80),
                Height = Application.GetRealWidth(50),
            };
            topMenuView.AddChidren(btnTopMenuUp);
            btnTopMenuLeft = new Button()
            {
                Gravity = Gravity.CenterVertical,
                Width = Application.GetRealWidth(50),
                Height = Application.GetRealWidth(80),
            };
            topMenuView.AddChidren(btnTopMenuLeft);
            btnTopMenuRight = new Button()
            {
                X = Application.GetRealWidth(150),
                Gravity = Gravity.CenterVertical,
                Width = Application.GetRealWidth(50),
                Height = Application.GetRealWidth(80),
            };
            topMenuView.AddChidren(btnTopMenuRight);
            btnTopMenuDown = new Button()
            {
                Y = Application.GetRealWidth(150),
                Gravity = Gravity.CenterHorizontal,
                Width = Application.GetRealWidth(80),
                Height = Application.GetRealWidth(50),
            };
            topMenuView.AddChidren(btnTopMenuDown);
            btnOk = new Button()
            {
                Gravity = Gravity.Center,
                Width = Application.GetRealWidth(100),
                Height = Application.GetRealWidth(100),
            };
            topMenuView.AddChidren(btnOk);
            #endregion
            #region 频道音量调节
            channleView = new FrameLayout()
            {
                X = Application.GetRealWidth(26),
                Y = Application.GetRealHeight(246),
                Width = Application.GetRealWidth(44),
                Height = Application.GetRealWidth(102),
                BackgroundImagePath = "FunctionIcon/Electrical/TV/MenuBgIcon.png",
            };
            controlView.AddChidren(channleView);
            btnChlPlus = new Button()
            {
                Gravity = Gravity.CenterHorizontal,
                Y = Application.GetRealHeight(10),
                Width = Application.GetRealWidth(24),
                Height = Application.GetRealWidth(24),
                UnSelectedImagePath = "FunctionIcon/Electrical/TV/PlusIcon.png"
            };
            channleView.AddChidren(btnChlPlus);
            Button btnChlText;
            btnChlText = new Button()
            {
                Gravity = Gravity.CenterVertical,
                Height = Application.GetRealWidth(23),
                TextAlignment = TextAlignment.Center,
                TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
                TextColor = CSS_Color.FirstLevelTitleColor,
                TextID = StringId.Canvas,
            };
            channleView.AddChidren(btnChlText);
            btnChlReduce = new Button()
            {
                Gravity = Gravity.CenterHorizontal,
                Y = Application.GetRealWidth(66),
                Width = Application.GetRealWidth(24),
                Height = Application.GetRealWidth(24),
                UnSelectedImagePath = "FunctionIcon/Electrical/TV/ReduceIcon.png"
            };
            channleView.AddChidren(btnChlReduce);
            volView = new FrameLayout()
            {
                X = Application.GetRealWidth(257),
                Y = Application.GetRealHeight(246),
                Width = Application.GetRealWidth(44),
                Height = Application.GetRealWidth(102),
                BackgroundImagePath = "FunctionIcon/Electrical/TV/MenuBgIcon.png",
            };
            controlView.AddChidren(volView);
            btnVolPlus = new Button()
            {
                Gravity = Gravity.CenterHorizontal,
                Y = Application.GetRealHeight(10),
                Width = Application.GetRealWidth(24),
                Height = Application.GetRealWidth(24),
                UnSelectedImagePath = "FunctionIcon/Electrical/TV/PlusIcon.png"
            };
            volView.AddChidren(btnVolPlus);
            Button btnVolText;
            btnVolText = new Button()
            {
                Gravity = Gravity.CenterVertical,
                Height = Application.GetRealWidth(23),
                TextAlignment = TextAlignment.Center,
                TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
                TextColor = CSS_Color.FirstLevelTitleColor,
                TextID = StringId.Vol,
            };
            volView.AddChidren(btnVolText);
            btnVolReduce = new Button()
            {
                Gravity = Gravity.CenterHorizontal,
                Y = Application.GetRealWidth(66),
                Width = Application.GetRealWidth(24),
                Height = Application.GetRealWidth(24),
                UnSelectedImagePath = "FunctionIcon/Electrical/TV/ReduceIcon.png"
            };
            volView.AddChidren(btnVolReduce);
            #endregion
            #region 底部控制区域
            btnBack = new Button()
            {
                X = Application.GetRealWidth(52),
                Y = Application.GetRealHeight(466),
                Width = Application.GetRealWidth(32),
                Height = Application.GetRealWidth(32),
                UnSelectedImagePath = "FunctionIcon/Electrical/TV/TVBackIcon.png",
            };
            controlView.AddChidren(btnBack);
            btnMenu = new Button()
            {
                X = Application.GetRealWidth(116),
                Y = Application.GetRealHeight(466),
                Width = Application.GetRealWidth(32),
                Height = Application.GetRealWidth(32),
                UnSelectedImagePath = "FunctionIcon/Electrical/TV/TVMenuIcon.png",
            };
            controlView.AddChidren(btnMenu);
            btnMore = new Button()
            {
                X = Application.GetRealWidth(180),
                Y = Application.GetRealHeight(466),
                Width = Application.GetRealWidth(32),
                Height = Application.GetRealWidth(32),
                UnSelectedImagePath = "FunctionIcon/AC/More.png",
            };
            controlView.AddChidren(btnMore);
            btnMore.MouseUpEventHandler = (sender, e) => {
              LoadDialog_IrMoreView();
            };
            btnPower = new Button()
            {
                X = Application.GetRealWidth(244),
                Y = Application.GetRealHeight(466),
                Width = Application.GetRealWidth(32),
                Height = Application.GetRealWidth(32),
                UnSelectedImagePath = "FunctionIcon/Electrical/TV/TVPowerIcon.png",
            };
            controlView.AddChidren(btnPower);
            #endregion
            new TopViewDiv(bodyView, Language.StringByID(StringId.PJT)).LoadTopView_FunctionTop(device, actionRefresh);
            DriverLayer.Control.Ins.SendReadCommand(device);
            LoadEventList();
        }
        /// <summary>
        /// 加载额外对红外按钮界面
        /// </summary>
        void LoadDialog_IrMoreView()
        {
            Dialog dialog = new Dialog();
            var div = new FrameLayout();
            dialog.AddChidren(div);
            div.MouseUpEventHandler = (sender, e) => {
                dialog.Close();
            };
            var bodyView = new FrameLayout()
            {
                Y = Application.GetRealHeight(427),//667
                Height = Application.GetRealHeight(240),
                BackgroundColor = CSS_Color.MainBackgroundColor,
            };
            div.AddChidren(bodyView);
            var contentView = new VerticalScrolViewLayout()
            {
                Y = Application.GetRealHeight(16),
                Gravity = Gravity.CenterHorizontal,
                Width = Application.GetRealWidth(296 + 200),
            };
            bodyView.AddChidren(contentView);
            var row = new FrameLayout()
            {
                Height = Application.GetRealHeight(60),
                Width = Application.GetRealWidth(296),
                Gravity = Gravity.CenterHorizontal,
            };
            contentView.AddChidren(row);
            int index = 0;
            List<FunctionAttributes> attrList = new List<FunctionAttributes>();
            attrList.AddRange(device.attributes);
            attrList.Add(new FunctionAttributes()
            {
                key = "+",
            });
            foreach (var attr in attrList)
            {
                if (attr.key == "up"
                    || attr.key == "down"
                    || attr.key == "right"
                    || attr.key == "left"
                    || attr.key == "zoom+"
                    || attr.key == "zoom-"
                    || attr.key == "volume+"
                    || attr.key == "volume-"
                    || attr.key == "back"
                    || attr.key == "menu"
                    || attr.key == FunctionAttributeKey.OnOff
                    )
                {
                    continue;
                }
                if (index != 0 && index % 3 == 0)
                {
                    row = new FrameLayout()
                    {
                        Height = Application.GetRealHeight(56),
                        Width = Application.GetRealWidth(296),
                        Gravity = Gravity.CenterHorizontal,
                    };
                    contentView.AddChidren(row);
                }
                if (attr.key == "+")
                {
                    var addView = new FrameLayout()
                    {
                        Gravity = Gravity.CenterVertical,
                        Width = Application.GetRealWidth(88),
                        Height = Application.GetRealHeight(40),
                        Radius = (uint)Application.GetRealHeight(18),
                        BorderColor = CSS_Color.PromptingColor1,
                        BorderWidth = (uint)Application.GetRealWidth(2),
                    };
                    if (index % 3 == 1)
                    {
                        addView.Gravity = Gravity.Center;
                    }
                    else if (index % 3 == 2)
                    {
                        addView.X = Application.GetRealWidth(208);
                    }
                    row.AddChidren(addView);
                    var btnAdd = new Button()
                    {
                        Gravity = Gravity.Center,
                        UnSelectedImagePath = "Public/PlusSignIcon.png",
                        Width = Application.GetRealWidth(32),
                        Height = Application.GetRealWidth(32),
                    };
                    addView.AddChidren(btnAdd);
                    btnAdd.MouseUpEventHandler = (sender, e) =>
                    {
                        dialog.Close();
                        Action action = () => {
                            LoadDialog_IrMoreView();
                        };
                        var addButton = new AcControlPage_AddIrButton(action);
                        MainPage.BasePageView.AddChidren(addButton);
                        addButton.Show(device);
                        MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
                    };
                }
                else
                {
                    var btn = new Button()
                    {
                        Gravity = Gravity.CenterVertical,
                        Width = Application.GetRealWidth(88),
                        Height = Application.GetRealHeight(40),
                        Radius = (uint)Application.GetRealHeight(18),
                        BorderColor = CSS_Color.PromptingColor1,
                        BorderWidth = (uint)Application.GetRealWidth(2),
                        TextAlignment = TextAlignment.Center,
                        TextSize = CSS_FontSize.TextFontSize,
                        TextColor = CSS_Color.FirstLevelTitleColor,
                        SelectedTextColor = CSS_Color.MainBackgroundColor,
                        SelectedBackgroundColor = CSS_Color.MainColor,
                    };
                    if (attr.value.Count > 0)
                    {
                        btn.Text = attr.value[0];
                    }
                    if (index % 3 == 1)
                    {
                        btn.Gravity = Gravity.Center;
                    }
                    else if (index % 3 == 2)
                    {
                        btn.X = Application.GetRealWidth(208);
                    }
                    row.AddChidren(btn);
                    btn.MouseUpEventHandler = (sender, e) =>
                    {
                        Dictionary<string, string> d = new Dictionary<string, string>();
                        d.Add(attr.key, "");
                        Control.Ins.SendWriteCommand(device, d);
                        new System.Threading.Thread(() =>
                        {
                            System.Threading.Thread.Sleep(2000);
                            Application.RunOnMainThread(() =>
                            {
                                btn.IsSelected = false;
                            });
                        })
                        { IsBackground = true }.Start();
                    };
                }
                index++;
            }
            dialog.Show();
        }
        /// <summary>
        /// 加载事件列表
        /// </summary>
        void LoadEventList()
        {
            LoadControlEvent();
            LoadCollectionEvent();
            //回退刷新信息事件
            actionRefresh = () => {
                btnFunctionName.Text = btnFunctionName_Out.Text = device.name;
                btnFromFloor_Out.Text = btnFromFoorAndRoom.Text = device.GetRoomListName();
                device.UpdataFuncitonInfo();
            };
        }
        /// <summary>
        /// 收藏功能按钮事件
        /// </summary>
        void LoadCollectionEvent()
        {
            btnCollection.MouseUpEventHandler += (sender, e) => {
                btnCollection.IsSelected = device.collect = btnCollection_Out.IsSelected = !btnCollection.IsSelected;
                device.CollectFunction();
            };
        }
        /// <summary>
        /// 加载控制事件
        /// </summary>
        void LoadControlEvent()
        {
            btnChlPlus.MouseUpEventHandler = (sender, e) =>
            {
                if (DB_ResidenceData.Instance.GatewayType == 1)
                {
                    Dictionary<string, string> d = new Dictionary<string, string>();
                    d.Add("zoom+", "");
                    Control.Ins.SendWriteCommand(device, d);
                }
            };
            btnChlReduce.MouseUpEventHandler = (sender, e) =>
            {
                if (DB_ResidenceData.Instance.GatewayType == 1)
                {
                    Dictionary<string, string> d = new Dictionary<string, string>();
                    d.Add("zoom-", "");
                    Control.Ins.SendWriteCommand(device, d);
                }
            };
            btnVolPlus.MouseUpEventHandler = (sender, e) =>
            {
                if (DB_ResidenceData.Instance.GatewayType == 1)
                {
                    Dictionary<string, string> d = new Dictionary<string, string>();
                    d.Add("volume+", "");
                    Control.Ins.SendWriteCommand(device, d);
                }
            };
            btnVolReduce.MouseUpEventHandler = (sender, e) =>
            {
                if (DB_ResidenceData.Instance.GatewayType == 1)
                {
                    Dictionary<string, string> d = new Dictionary<string, string>();
                    d.Add("volume-", "");
                    Control.Ins.SendWriteCommand(device, d);
                }
            };
            btnBack.MouseUpEventHandler = (sender, e) =>
            {
                if (DB_ResidenceData.Instance.GatewayType == 1)
                {
                    Dictionary<string, string> d = new Dictionary<string, string>();
                    d.Add("return", "");
                    Control.Ins.SendWriteCommand(device, d);
                }
            };
            btnPower.MouseUpEventHandler = (sender, e) =>
            {
                if (DB_ResidenceData.Instance.GatewayType == 1)
                {
                    Dictionary<string, string> d = new Dictionary<string, string>();
                    d.Add("on_off", "");
                    Control.Ins.SendWriteCommand(device, d);
                }
            };
            btnTopMenuUp.MouseDownEventHandler = (sender, e) => {
                topMenuView.BackgroundImagePath = "FunctionIcon/Electrical/TV/TVOkIconUp.png";
            };
            btnTopMenuDown.MouseDownEventHandler = (sender, e) => {
                topMenuView.BackgroundImagePath = "FunctionIcon/Electrical/TV/TVOkIconDown.png";
            };
            btnTopMenuLeft.MouseDownEventHandler = (sender, e) => {
                topMenuView.BackgroundImagePath = "FunctionIcon/Electrical/TV/TVOkIconLeft.png";
            };
            btnTopMenuRight.MouseDownEventHandler = (sender, e) => {
                topMenuView.BackgroundImagePath = "FunctionIcon/Electrical/TV/TVOkIconRight.png";
            };
            btnOk.MouseDownEventHandler = (sender, e) => {
                topMenuView.BackgroundImagePath = "FunctionIcon/Electrical/TV/TVOkIconOk.png";
            };
            btnMenu.MouseUpEventHandler = (sender, e) =>
            {
                topMenuView.BackgroundImagePath = "FunctionIcon/Electrical/TV/TVOkIcon.png";
                if (DB_ResidenceData.Instance.GatewayType == 1)
                {
                    Dictionary<string, string> d = new Dictionary<string, string>();
                    d.Add("menu", "");
                    Control.Ins.SendWriteCommand(device, d);
                }
            };
            btnTopMenuUp.MouseUpEventHandler = (sender, e) => {
                topMenuView.BackgroundImagePath = "FunctionIcon/Electrical/TV/TVOkIcon.png";
                if (DB_ResidenceData.Instance.GatewayType == 1)
                {
                    Dictionary<string, string> d = new Dictionary<string, string>();
                    d.Add("up", "");
                    Control.Ins.SendWriteCommand(device, d);
                }
            };
            btnTopMenuLeft.MouseUpEventHandler = (sender, e) => {
                topMenuView.BackgroundImagePath = "FunctionIcon/Electrical/TV/TVOkIcon.png";
                if (DB_ResidenceData.Instance.GatewayType == 1)
                {
                    Dictionary<string, string> d = new Dictionary<string, string>();
                    d.Add("left", "");
                    Control.Ins.SendWriteCommand(device, d);
                }
            };
            btnTopMenuRight.MouseUpEventHandler = (sender, e) => {
                topMenuView.BackgroundImagePath = "FunctionIcon/Electrical/TV/TVOkIcon.png";
                if (DB_ResidenceData.Instance.GatewayType == 1)
                {
                    Dictionary<string, string> d = new Dictionary<string, string>();
                    d.Add("right", "");
                    Control.Ins.SendWriteCommand(device, d);
                }
            };
            btnTopMenuDown.MouseUpEventHandler = (sender, e) => {
                topMenuView.BackgroundImagePath = "FunctionIcon/Electrical/TV/TVOkIcon.png";
                if (DB_ResidenceData.Instance.GatewayType == 1)
                {
                    Dictionary<string, string> d = new Dictionary<string, string>();
                    d.Add("down", "");
                    Control.Ins.SendWriteCommand(device, d);
                }
            };
            btnOk.MouseUpEventHandler = (sender, e) => {
                topMenuView.BackgroundImagePath = "FunctionIcon/Electrical/TV/TVOkIcon.png";
                if (DB_ResidenceData.Instance.GatewayType == 1)
                {
                    Dictionary<string, string> d = new Dictionary<string, string>();
                    d.Add("ok", "");
                    Control.Ins.SendWriteCommand(device, d);
                }
            };
        }
    }
}