From 4f92fe4e4397b05bc97d17e8ad02818a689acdb8 Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期四, 10 十月 2019 13:13:33 +0800
Subject: [PATCH] 个人中心添加楼层和创建房间,实装二级验证

---
 ZigbeeApp/Shared/Phone/Device/Light/DimmableLightControl.cs |  307 ++++++++++++++++++++++++--------------------------
 1 files changed, 149 insertions(+), 158 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/Device/Light/DimmableLightControl.cs b/ZigbeeApp/Shared/Phone/Device/Light/DimmableLightControl.cs
index 06a43b9..7cdecac 100755
--- a/ZigbeeApp/Shared/Phone/Device/Light/DimmableLightControl.cs
+++ b/ZigbeeApp/Shared/Phone/Device/Light/DimmableLightControl.cs
@@ -1,5 +1,6 @@
 锘縰sing System;
 using Shared.Common;
+using Shared.Phone.Device.CommonForm;
 using ZigBee.Device;
 
 namespace Shared.Phone.Device.Light
@@ -17,10 +18,6 @@
         ///// </summary>
         private CommonForm.TopFrameLayout top;
         /// <summary>
-        /// 鏇村璁剧疆
-        /// </summary>
-        private Button moreBtn;
-        /// <summary>
         /// 浼犺繃鏉ョ殑璁惧
         /// </summary>
         private DeviceUI device;
@@ -33,25 +30,14 @@
         /// </summary>
         private Shared.Common.Room room;
         /// <summary>
-        /// The middle fl.
+        /// bodyFrameLayout
         /// </summary>
-        private FrameLayout midFL;
+        private FrameLayout bodyFrameLayout;
         /// <summary>
         /// 鏀惰棌鎸夐挳
         /// </summary>
         private Button collectionBtn;
-        /// <summary>
-        /// 璁惧鏄惁鍦ㄧ嚎鏍囪瘑--Online
-        /// </summary>
-        private readonly string DeviceStatus_Online = "Online";
-        /// <summary>
-        /// 璁惧鐘舵�佸紑鍏虫爣璇�--Switch
-        /// </summary>
-        private readonly string DeviceStatus_OnOffStatus = "Switch";
-        /// <summary>
-        /// The light image.
-        /// </summary>
-        private Button deviceIMG;
+   
         /// <summary>
         /// 寮�鍏�
         /// </summary>
@@ -59,12 +45,22 @@
         /// <summary>
         /// 婊戞潯
         /// </summary>
-        private HorizontalSeekBar levelSeekBar;
-        /// <summary>
-        /// 寤舵椂 300姣
-        /// </summary>
-        private int sleepSpan = 300;
+        private WaveSeekBar levelSeekBar;
+  
 
+        private Button StatuBtn;
+        /// <summary>
+        /// 鎴块棿
+        /// </summary>
+        private Button roomBtn;
+        /// <summary>
+        /// 鎴块棿鍚�
+        /// </summary>
+        private Button roomName;
+        /// <summary>
+        /// MaxLevel
+        /// </summary>
+        private const int MaxLevel = 254;
         #endregion
 
         #region 鈼� 鎺ュ彛__________________________
@@ -135,6 +131,18 @@
                                 }
                                 dimmableLight.OnOffStatus = dimmableLight.DeviceStatusReport.AttriBute[0].AttriButeData;
                                 switchBtn.IsSelected = dimmableLight.OnOffStatus == 1;
+                                StatuBtn.Text = CommonFormResouce.GetSwitchStatu(switchBtn.IsSelected);
+                                if (switchBtn.IsSelected == true)
+                                {
+                                    levelSeekBar.IsClickable = true;
+                                    levelSeekBar.WaveColor = ZigbeeColor.Current.GXCWaveSeekBarColor;
+                                }
+                                else
+                                {
+                                    levelSeekBar.IsClickable = false;
+                                    levelSeekBar.WaveColor = ZigbeeColor.Current.GXCWaveSeekBarUnSelectedColor;
+                                }
+                                //change color
                                 dimmableLight.LastDateTime = DateTime.Now;
                             }
                             //浜害
@@ -153,18 +161,11 @@
                                         //姝ゅ睘鎬ц〃鏄庡綋鍓嶄寒搴︾▼搴�
                                         dimmableLight.Level = attriButeList[0].AttriButeData;
                                         dimmableLight.LastDateTime = DateTime.Now;
-                                        levelSeekBar.Progress = dimmableLight.Level;
+                                        levelSeekBar.Progress = (int)(dimmableLight.Level*1.0/MaxLevel*100);
                                         break;
                                 }
                             }
-                            //***鏂版敼***璁惧鐘舵�佷笂鎶ヤ腑锛屽綋CluterID=3,璇佹槑璁惧鍦ㄧ嚎锛岀洿鎺ユ爣璁�
-                            else if ((common as DimmableLight).DeviceStatusReport.CluterID == 3)
-                            {
-                                dimmableLight = deviceUI.CommonDevice as DimmableLight;
-                                dimmableLight.IsOnline = 1;
-                                deviceIMG.IsSelected = dimmableLight.IsOnline == 1;
-                                dimmableLight.LastDateTime = DateTime.Now;
-                            }
+                            
                         }
                     }
                     catch (Exception ex)
@@ -175,34 +176,7 @@
             }
             else if (typeTag == "OnlineStatusChange")
             {
-                Application.RunOnMainThread(() =>
-                {
-                    try
-                    {
-                        var deviceUI = device;
-                        //璁惧涓虹┖
-                        if (deviceUI.CommonDevice == null)
-                        {
-                            return;
-                        }
-                        //鏄惁涓哄綋鍓嶈澶�
-                        if (deviceUI.CommonDevice.DeviceEpoint != common.DeviceEpoint || deviceUI.CommonDevice.DeviceAddr != common.DeviceAddr)
-                        {
-                            return;
-                        }
-                        if (deviceUI.CommonDevice.Type == DeviceType.DimmableLight)
-                        {
-                            dimmableLight = deviceUI.CommonDevice as DimmableLight;
-                            dimmableLight.IsOnline = (common as DimmableLight).IsOnline;
-                            deviceIMG.IsSelected = dimmableLight.IsOnline == 1;
-                            dimmableLight.LastDateTime = DateTime.Now;
-                        }
-                    }
-                    catch (Exception ex)
-                    {
-                        System.Console.WriteLine($"Error:{ex.Message}");
-                    }
-                });
+               
             }
         }
 
@@ -231,6 +205,7 @@
         public DimmableLightControl()
         {
             BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor;
+            ZbGateway.StatusList.Add(this);
         }
 
         #endregion
@@ -243,7 +218,6 @@
         /// <param name="room">Room.</param>
         public void Show(DeviceUI device, Shared.Common.Room room)
         {
-            ZbGateway.StatusList.Add(this);
             this.device = device;
             this.room = room;
             this.dimmableLight = device.CommonDevice as ZigBee.Device.DimmableLight;
@@ -251,7 +225,7 @@
             //娣诲姞topview
             AddTopView();
             //娣诲姞midview
-            AddMidview();
+            AddBodyView(this.device);
             //缁戝畾浜嬩欢
             BindEvent();
             //鏀惰棌
@@ -296,27 +270,28 @@
                 RemoveFromParent();
             };
 
-            AddMoreview();
-        }
-
-        /// <summary>
-        /// Adds the moreview.
-        /// </summary>
-        private void AddMoreview()
-        {
-            moreBtn = new CommonForm.SelectedStatuButton()
+            var sharedBtn = new Button
             {
-                X = Application.GetRealWidth(CommonPage.AppRealWidth - 150),
-                Width = Application.GetMinReal(110),
-                Height = Application.GetMinReal(110),
+                X = Application.GetRealWidth(850),
+                Width = Application.GetMinReal(69),
+                Height = Application.GetMinReal(69),
                 Gravity = Gravity.CenterVertical,
-                UnSelectedImagePath = "Item/More.png",
-                SelectedImagePath = "Item/MoreSelected.png",
+                UnSelectedImagePath = "Item/Shared.png"
+            };
+            top.topView.AddChidren(sharedBtn);
+
+            var moreBtn = new Button
+            {
+                X = Application.GetRealWidth(953),
+                Width = Application.GetMinReal(69),
+                Height = Application.GetMinReal(69),
+                Gravity = Gravity.CenterVertical,
+                UnSelectedImagePath = "Item/More.png"
             };
             top.topView.AddChidren(moreBtn);
+
             moreBtn.MouseUpEventHandler += MoreEvent;
         }
-
         /// <summary>
         /// 鏇村璁剧疆
         /// </summary>
@@ -339,17 +314,17 @@
         #region 鈼� midview_______________________
 
         /// <summary>
-        /// Adds the midview.
+        /// AddBodyView
         /// </summary>
-        private void AddMidview()
+        public void AddBodyView(DeviceUI device)
         {
-            midFL = new FrameLayout()
+            bodyFrameLayout = new FrameLayout()
             {
-                Height = Application.GetRealHeight(CommonPage.AppRealHeight - CommonPage.Navigation_Height),
-                Y = top.Bottom,
-                BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor
+                Y = Application.GetRealHeight(184),
+                Height = Application.GetRealHeight(1737),
+                BackgroundColor = ZigbeeColor.Current.GXCGrayBackgroundColor,
             };
-            AddChidren(midFL);
+            AddChidren(bodyFrameLayout);
 
             AddItemview();
         }
@@ -367,111 +342,123 @@
                 Y = Application.GetRealHeight(115),
                 Width = Application.GetRealWidth(965),
                 Height = Application.GetRealHeight(1316),
-                Radius = CommonPage.BigFormRadius,
+                Radius = (uint)Application.GetRealHeight(CommonFormResouce.BigFormRadius),
                 Gravity = Gravity.CenterHorizontal,
-                BackgroundColor = ZigbeeColor.Current.GXCTopViewBackgroundColor
+                BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor
             };
-            midFL.AddChidren(itemView);
-            var deviceView = new FrameLayout()
-            {
-                X = 2,
-                Y = 2,
-                Width = itemView.Width - 4,
-                Height = itemView.Height - Application.GetRealHeight(138),
-                BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor,
-                Tag = device
-            };
-            itemView.AddChidren(deviceView);
+            bodyFrameLayout.AddChidren(itemView);
 
             collectionBtn = new Button()
             {
-                X = deviceView.Width - Application.GetRealWidth(130),
-                Y = Application.GetRealHeight(20),
-                Width = Application.GetMinReal(110),
-                Height = Application.GetMinReal(110),
+                X = Application.GetRealWidth(850),
+                Y = Application.GetRealHeight(46),
+                Width = Application.GetMinReal(69),
+                Height = Application.GetMinReal(69),
                 UnSelectedImagePath = "Item/Collection.png",
                 SelectedImagePath = "Item/CollectionSelected.png"
             };
-            deviceView.AddChidren(collectionBtn);
+            itemView.AddChidren(collectionBtn);
 
-            deviceIMG = new Button()
+            var deviceNameBtn = new Button()
             {
-                Y = Application.GetRealHeight(100),
-                Height = Application.GetMinRealAverage(240),
-                Width = Application.GetMinRealAverage(240),
-                Gravity = Gravity.CenterHorizontal,
-                UnSelectedImagePath = device.IconPath,
-                SelectedImagePath = device.OnlineIconPath,
-                IsSelected = dimmableLight.IsOnline == 1,
-                Tag = DeviceStatus_Online
-            };
-            deviceView.AddChidren(deviceIMG);
-
-            var lightName = new Button()
-            {
-                Y = deviceIMG.Bottom,
-                Height = Application.GetRealHeight(85),
+                Y = Application.GetRealHeight(46),
+                Width = Application.GetRealWidth(500),
+                Height = Application.GetRealHeight(60),
                 Gravity = Gravity.CenterHorizontal,
                 Text = device.CommonDevice.DeviceEpointName,
-                TextColor = ZigbeeColor.Current.GXCTextBlackColor
+                TextColor = ZigbeeColor.Current.GXCTextBlackColor,
+                TextSize = 15
             };
-            deviceView.AddChidren(lightName);
+            itemView.AddChidren(deviceNameBtn);
 
-            levelSeekBar = new HorizontalSeekBar()
+            StatuBtn = new Button
             {
-                Y = lightName.Bottom + Application.GetRealHeight(150),
-                Width = Application.GetRealWidth(800),
-                Height = Application.GetRealHeight(80),
+                Y = Application.GetRealHeight(118),
+                Width = Application.GetRealWidth(600),
+                Height = Application.GetRealHeight(60),
                 Gravity = Gravity.CenterHorizontal,
-                BackgroundColor = ZigbeeColor.Current.GXCSliderUnSelectedColor,
-                ThumbColor = ZigbeeColor.Current.GXCButtonBlueColor,
-                BorderColor = ZigbeeColor.Current.GXCButtonBlueColor,
-                ProgressColor = ZigbeeColor.Current.GXCButtonBlueColor,
-                Max = 254,
-                Tag = "LevelSeekBar",
-                Progress = dimmableLight.Level,
-                SleepTime=sleepSpan,
+                TextColor = ZigbeeColor.Current.GXCTextGrayColor,
+                Text = CommonFormResouce.GetSwitchStatu(device.CommonDevice.IsOnline == 1)
             };
-            deviceView.AddChidren(levelSeekBar);
-            levelSeekBar.ProgressChanged += (send2, e2) =>
+            itemView.AddChidren(StatuBtn);
+
+            levelSeekBar = new WaveSeekBar()
             {
-                dimmableLight.SetLevel(levelSeekBar.Progress);
+                Y = Application.GetRealHeight(377),
+                Width = Application.GetRealWidth(271),
+                Height = Application.GetRealHeight(533),
+                Gravity = Gravity.CenterHorizontal,
+                WavePadding = 2,
+                MaxValue=100,
+                Progress = (int)(dimmableLight.Level*1.0/MaxLevel*100),
+                WaveColor = ZigbeeColor.Current.GXCWaveSeekBarColor
+            };
+            itemView.AddChidren(levelSeekBar);
+
+            if (dimmableLight.OnOffStatus==1)
+            {
+                levelSeekBar.IsClickable = true;
+                levelSeekBar.WaveColor = ZigbeeColor.Current.GXCWaveSeekBarColor;
+            }
+            else
+            {
+                levelSeekBar.IsClickable = false;
+                levelSeekBar.WaveColor = ZigbeeColor.Current.GXCWaveSeekBarUnSelectedColor;
+            }
+
+            levelSeekBar.OnProgressChangedEvent += (send2, e2) =>
+            {
+                dimmableLight.SetLevel((int)(levelSeekBar.Progress*MaxLevel/100.0));
             };
 
             switchBtn = new Button()
             {
-                Y = levelSeekBar.Bottom + Application.GetRealHeight(150),
+                Y = Application.GetRealHeight(1005),
+                Width = Application.GetMinRealAverage(81),
+                Height = Application.GetMinRealAverage(81),
                 Gravity = Gravity.CenterHorizontal,
-                Width = Application.GetMinRealAverage(180),
-                Height = Application.GetMinRealAverage(120),
                 UnSelectedImagePath = "Item/Switch.png",
                 SelectedImagePath = "Item/SwitchSelected.png",
-                Tag = DeviceStatus_OnOffStatus,
-                IsSelected = dimmableLight.OnOffStatus == 1
+                IsSelected = (device.CommonDevice as DimmableLight).OnOffStatus == 1
             };
-            deviceView.AddChidren(switchBtn);
+            itemView.AddChidren(switchBtn);
 
-            var roomBtn = new Button()
+            var roomBG = new Button
             {
-                X = Application.GetRealWidth(50),
-                Y = Application.GetRealHeight(25) + deviceView.Bottom,
+                Y = Application.GetRealHeight(1178 - 50),
+                Height = Application.GetRealHeight(138 + 50),
+                BackgroundColor = ZigbeeColor.Current.GXCBlackBackgroundColor,
+                Radius = (uint)Application.GetRealHeight(CommonFormResouce.BigFormRadius)
+            };
+            itemView.AddChidren(roomBG);
+
+            var roomBG2 = new Button
+            {
+                Y = Application.GetRealHeight(1178 - 50),
+                Height = Application.GetRealHeight(50),
+                BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor,
+            };
+            itemView.AddChidren(roomBG2);
+
+            roomBtn = new Button()
+            {
+                X = Application.GetRealWidth(CommonFormResouce.X_Left),
+                Y = Application.GetRealHeight(1207),
                 Width = Application.GetMinReal(80),
                 Height = Application.GetMinReal(80),
-                UnSelectedImagePath = "Item/Room.png",
-                SelectedImagePath = "Item/RoomSelected.png"
+                UnSelectedImagePath = "Item/Room.png"
             };
             itemView.AddChidren(roomBtn);
 
-            var roomName = new Button()
+            roomName = new Button()
             {
-                X = roomBtn.Right + Application.GetRealWidth(20),
-                Y = roomBtn.Y,
+                X = Application.GetRealWidth(150),
+                Y = Application.GetRealHeight(1224),
                 Width = Application.GetRealWidth(400),
-                Height = Application.GetRealHeight(80),
+                Height = Application.GetRealHeight(50),
                 Text = room.Name,
                 TextAlignment = TextAlignment.CenterLeft,
-                TextColor = ZigbeeColor.Current.GXCTextBlackColor,
-                SelectedTextColor = ZigbeeColor.Current.GXCTextBlueColor
+                TextColor = ZigbeeColor.Current.GXCTextWhiteColor
             };
             itemView.AddChidren(roomName);
         }
@@ -486,7 +473,6 @@
         {
             switchBtn.MouseUpEventHandler += Switch_MouseUpEvent;
             collectionBtn.MouseUpEventHandler += Collection;
-            moreBtn.MouseUpEventHandler += MoreEvent;
         }
 
         #endregion
@@ -501,13 +487,18 @@
         private void Switch_MouseUpEvent(object sender, MouseEventArgs eventArgs)
         {
             switchBtn.IsSelected = !switchBtn.IsSelected;
+            StatuBtn.Text = CommonFormResouce.GetSwitchStatu(switchBtn.IsSelected);
             if (switchBtn.IsSelected == true)
             {
                 dimmableLight.SwitchControl(1);
+                levelSeekBar.IsClickable = true;
+                levelSeekBar.WaveColor = ZigbeeColor.Current.GXCWaveSeekBarColor;
             }
             else
             {
                 dimmableLight.SwitchControl(0);
+                levelSeekBar.IsClickable = false;
+                levelSeekBar.WaveColor = ZigbeeColor.Current.GXCWaveSeekBarUnSelectedColor;
             }
         }
 
@@ -538,15 +529,15 @@
         private void Collection(object sender, MouseEventArgs e)
         {
             //collection
-            if (collectionBtn.IsSelected)
+            if ((sender as Button).IsSelected)
             {
-                Shared.Common.Room.Lists[0].DeleteDevice(device.FileName);
-                collectionBtn.IsSelected = false;
+                Shared.Common.Room.GetLoveRoom().DeleteDevice(device.FileName);
+                (sender as Button).IsSelected = false;
             }
             else
             {
-                Shared.Common.Room.Lists[0].AddDevice(device.FileName);
-                collectionBtn.IsSelected = true;
+                Shared.Common.Room.GetLoveRoom().AddDevice(device.FileName);
+                (sender as Button).IsSelected = true;
             }
         }
 

--
Gitblit v1.8.0