| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using Shared.Common; |
| | | using Shared.Phone.Device.CommonForm; |
| | | using Shared.Phone.UserView; |
| | | using ZigBee.Device; |
| | | namespace Shared.Phone.Device.Light |
| | |
| | | { |
| | | #region ◆ 变量__________________________ |
| | | /// <summary> |
| | | /// 设备是否在线标识--Online |
| | | /// </summary> |
| | | private readonly string DeviceStatus_Online = "Online"; |
| | | /// <summary> |
| | | /// 设备状态开关标识--Switch |
| | | /// </summary> |
| | | private readonly string DeviceStatus_OnOffStatus = "Switch"; |
| | | /// <summary> |
| | | /// 开关 |
| | | /// </summary> |
| | | private Button switchBtn; |
| | |
| | | /// The action. |
| | | /// </summary> |
| | | public Action action; |
| | | /// <summary> |
| | | /// The light view. |
| | | /// </summary> |
| | | private FrameLayout deviceView; |
| | | |
| | | /// <summary> |
| | | /// The light image. |
| | | /// </summary> |
| | |
| | | /// 传过来的房间 |
| | | /// </summary> |
| | | private Shared.Common.Room room; |
| | | /// <summary> |
| | | /// 更多设置 |
| | | /// </summary> |
| | | private Button moreBtn; |
| | | |
| | | /// <summary> |
| | | /// 房间 |
| | | /// </summary> |
| | |
| | | /// 是否发送控制命令成功了 |
| | | /// </summary> |
| | | private bool sendedControlCommand = false; |
| | | |
| | | /// <summary> |
| | | /// bodyFrameLayout |
| | | /// </summary> |
| | | private FrameLayout bodyFrameLayout; |
| | | |
| | | private Button StatuBtn; |
| | | |
| | | #endregion |
| | | |
| | |
| | | { |
| | | try |
| | | { |
| | | var deviceUI = deviceView.Tag as DeviceUI; |
| | | var deviceUI = device; |
| | | //设备为空 |
| | | if (deviceUI.CommonDevice == null) |
| | | { |
| | |
| | | var light = deviceUI.CommonDevice as ToggleLight; |
| | | light.DeviceStatusReport = (common as ToggleLight).DeviceStatusReport; |
| | | //记录、更新状态 |
| | | if(light.DeviceStatusReport.AttriBute==null || light.DeviceStatusReport.AttriBute.Count==0) |
| | | if (light.DeviceStatusReport.AttriBute == null || light.DeviceStatusReport.AttriBute.Count == 0) |
| | | { |
| | | return; |
| | | } |
| | | light.OnOffStatus = light.DeviceStatusReport.AttriBute[0].AttriButeData; |
| | | switchBtn.IsSelected = light.OnOffStatus == 1; |
| | | light.LastDateTime = DateTime.Now; |
| | | } |
| | | //***新改***设备状态上报中,当CluterID=3,证明设备在线,直接标记 |
| | | else if ((common as ToggleLight).DeviceStatusReport.CluterID == 3) |
| | | { |
| | | var light = deviceUI.CommonDevice as ToggleLight; |
| | | light.IsOnline = 1; |
| | | deviceIMG.IsSelected = light.IsOnline == 1; |
| | | deviceIMG.IsSelected = switchBtn.IsSelected = light.OnOffStatus == 1; |
| | | StatuBtn.Text = CommonFormResouce.GetSwitchStatu(deviceIMG.IsSelected); |
| | | light.LastDateTime = DateTime.Now; |
| | | } |
| | | } |
| | |
| | | } |
| | | else if (typeTag == "OnlineStatusChange") |
| | | { |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | try |
| | | { |
| | | var deviceUI = deviceView.Tag as DeviceUI; |
| | | //设备为空 |
| | | if (deviceUI.CommonDevice == null) |
| | | { |
| | | return; |
| | | } |
| | | //是否为当前设备 |
| | | if (deviceUI.CommonDevice.DeviceEpoint != common.DeviceEpoint || deviceUI.CommonDevice.DeviceAddr != common.DeviceAddr) |
| | | { |
| | | return; |
| | | } |
| | | if (deviceUI.CommonDevice.Type == DeviceType.OnOffOutput) |
| | | { |
| | | var light = deviceUI.CommonDevice as ToggleLight; |
| | | light.IsOnline = (common as ToggleLight).IsOnline; |
| | | deviceIMG.IsSelected = light.IsOnline == 1; |
| | | light.LastDateTime = DateTime.Now; |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | System.Console.WriteLine($"Error:{ex.Message}"); |
| | | } |
| | | }); |
| | | |
| | | } |
| | | } |
| | | #endregion |
| | | |
| | | #region ◆ 初始化________________________ |
| | | #region ◆ 初始化_____________________ |
| | | /// <summary> |
| | | /// 重写移除方法 |
| | | /// </summary> |
| | | public override void RemoveFromParent() |
| | | { |
| | | ZbGateway.StatusList.Remove(this); |
| | | action(); |
| | | action = null; |
| | | RemoveUpdateControlDeviceStatuAction(); |
| | | base.RemoveFromParent(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 构造方法 |
| | | /// </summary> |
| | | public LightControl() |
| | | { |
| | | BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor; |
| | | ZbGateway.StatusList.Add(this); |
| | | } |
| | | /// <summary> |
| | | /// 显示界面 |
| | | /// </summary> |
| | | /// <param name="device">Device.</param> |
| | | /// <param name="dev">Device.</param> |
| | | /// <param name="room">Room.</param> |
| | | public void Show(DeviceUI device,Shared.Common.Room room) |
| | | public void Show(DeviceUI dev,Shared.Common.Room room) |
| | | { |
| | | #region topview |
| | | |
| | | var topBGView = new FrameLayout()
{
Height = Application.GetRealHeight(CommonPage.Navigation_Height),
BackgroundColor = ZigbeeColor.Current.GXCTopViewBackgroundColor
};
AddChidren(topBGView);
var topView = new FrameLayout()
{
Y = Application.GetRealHeight(CommonPage.NavigationTitle_Y),
Height = Application.GetRealHeight(CommonPage.Navigation_Height - CommonPage.NavigationTitle_Y),
BackgroundColor = ZigbeeColor.Current.GXCTopViewBackgroundColor,
};
AddChidren(topView); |
| | | |
| | | moreBtn = new Device.CommonForm.SelectedStatuButton() |
| | | { |
| | | X=Application.GetRealWidth(CommonPage.AppRealWidth-150), |
| | | Width=Application.GetMinReal(110), |
| | | Height=Application.GetMinReal(110), |
| | | Gravity=Gravity.CenterVertical, |
| | | UnSelectedImagePath = "Item/More.png", |
| | | SelectedImagePath = "Item/MoreSelected.png", |
| | | }; |
| | | topView.AddChidren(moreBtn); |
| | | |
| | | var back = new Device.CommonForm.BackButton() { };
topView.AddChidren(back); |
| | | back.MouseUpEventHandler += (sender, e) => |
| | | { |
| | | this.RemoveFromParent(); |
| | | }; |
| | | |
| | | if (device == null || device.CommonDevice == null || room == null) |
| | | { |
| | | return; |
| | | } |
| | | this.device = device; |
| | | this.zbGateway = this.device.CommonDevice.Gateway; |
| | | device = dev; |
| | | zbGateway = this.device.CommonDevice.Gateway; |
| | | this.room = room; |
| | | var light = device.CommonDevice as ToggleLight; |
| | | |
| | | AddTop(); |
| | | |
| | | AddBodyView(device); |
| | | |
| | | |
| | | var light = dev.CommonDevice as ToggleLight; |
| | | //补上非远程 |
| | | if (light.Gateway == null) |
| | | { |
| | |
| | | light.ReadAttri(Cluster_ID.Identify, AttriButeId.Switch); |
| | | } |
| | | } |
| | | #endregion |
| | | |
| | | #region midFL |
| | | var midFL = new FrameLayout() |
| | | { |
| | | Height = Application.GetRealHeight(CommonPage.AppRealHeight - CommonPage.Navigation_Height), |
| | | Y = topView.Bottom, |
| | | BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor, |
| | | }; |
| | | this.AddChidren(midFL); |
| | | |
| | | var itemView = new FrameLayout() |
| | | { |
| | | X = Application.GetRealWidth(50), |
| | | Y = Application.GetRealHeight(50), |
| | | Width = Application.GetRealWidth(CommonPage.AppRealWidth - 100), |
| | | Height = Application.GetRealHeight(850), |
| | | Radius = CommonPage.BigFormRadius, |
| | | Gravity = Gravity.CenterHorizontal, |
| | | BackgroundColor = ZigbeeColor.Current.GXCTopViewBackgroundColor |
| | | }; |
| | | midFL.AddChidren(itemView); |
| | | deviceView = new FrameLayout() |
| | | { |
| | | X = 2, |
| | | Y = 2, |
| | | Width = itemView.Width - 4, |
| | | Height = itemView.Height - Application.GetRealHeight(130), |
| | | BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor, |
| | | Tag = device |
| | | }; |
| | | itemView.AddChidren(deviceView); |
| | | |
| | | collectionBtn = new Button() |
| | | { |
| | | X = deviceView.Width - Application.GetRealWidth(130), |
| | | Y = Application.GetRealHeight(20), |
| | | Width = Application.GetMinReal(110), |
| | | Height = Application.GetMinReal(110), |
| | | UnSelectedImagePath = "Item/Collection.png", |
| | | SelectedImagePath = "Item/CollectionSelected.png" |
| | | }; |
| | | deviceView.AddChidren(collectionBtn); |
| | | |
| | | deviceIMG = new Button() |
| | | { |
| | | Y = Application.GetRealHeight(100), |
| | | Height = Application.GetMinRealAverage(240), |
| | | Width = Application.GetMinRealAverage(240), |
| | | Gravity = Gravity.CenterHorizontal, |
| | | UnSelectedImagePath = device.IconPath, |
| | | SelectedImagePath = device.OnlineIconPath, |
| | | IsSelected = light.IsOnline == 1, |
| | | Tag = DeviceStatus_Online |
| | | }; |
| | | deviceView.AddChidren(deviceIMG); |
| | | |
| | | var lightName = new Button() |
| | | { |
| | | Y = deviceIMG.Bottom, |
| | | Height = Application.GetRealHeight(85), |
| | | Gravity = Gravity.CenterHorizontal, |
| | | Text = device.CommonDevice.DeviceEpointName, |
| | | TextColor = ZigbeeColor.Current.GXCTextBlackColor |
| | | }; |
| | | deviceView.AddChidren(lightName); |
| | | |
| | | switchBtn = new Button() |
| | | { |
| | | Y = lightName.Bottom + Application.GetRealHeight(70), |
| | | Gravity = Gravity.CenterHorizontal, |
| | | Width = Application.GetMinRealAverage(180), |
| | | Height = Application.GetMinRealAverage(120), |
| | | UnSelectedImagePath = "Item/Switch.png", |
| | | SelectedImagePath = "Item/SwitchSelected.png", |
| | | Tag = DeviceStatus_OnOffStatus, |
| | | IsSelected = light.OnOffStatus == 1 |
| | | }; |
| | | deviceView.AddChidren(switchBtn); |
| | | |
| | | roomBtn = new Button() |
| | | { |
| | | X = Application.GetRealWidth(50), |
| | | Y = Application.GetRealHeight(25) + deviceView.Bottom, |
| | | Width = Application.GetMinReal(80), |
| | | Height = Application.GetMinReal(80), |
| | | UnSelectedImagePath = "Item/Room.png", |
| | | SelectedImagePath = "Item/RoomSelected.png" |
| | | }; |
| | | itemView.AddChidren(roomBtn); |
| | | |
| | | roomName = new Button() |
| | | { |
| | | X = roomBtn.Right + Application.GetRealWidth(20), |
| | | Y = roomBtn.Y, |
| | | Width = Application.GetRealWidth(400), |
| | | Height = Application.GetRealHeight(80), |
| | | Text = room.Name, |
| | | TextAlignment = TextAlignment.CenterLeft, |
| | | TextColor = ZigbeeColor.Current.GXCTextBlackColor, |
| | | SelectedTextColor = ZigbeeColor.Current.GXCTextBlueColor |
| | | }; |
| | | itemView.AddChidren(roomName); |
| | | |
| | | //var moreBtn = new Button() |
| | | //{ |
| | | // X = itemView.Width - Application.GetRealWidth(130), |
| | | // Y = roomBtn.Y, |
| | | // Width = Application.GetMinReal(80), |
| | | // Height = Application.GetMinReal(80), |
| | | // UnSelectedImagePath = "Item/More.png", |
| | | // SelectedImagePath = "Item/MoreSelected.png", |
| | | //}; |
| | | //itemView.AddChidren(moreBtn); |
| | | var dev = Shared.Common.Room.LoveRoomDeviceUIFilePathList.Find((obj) => obj == device.FileName); |
| | | if (dev == null) |
| | | var de = Shared.Common.Room.LoveRoomDeviceUIFilePathList.Find((obj) => obj == device.FileName); |
| | | if (de == null) |
| | | { |
| | | collectionBtn.IsSelected = false; |
| | | } |
| | |
| | | { |
| | | collectionBtn.IsSelected = true; |
| | | } |
| | | this.BindEvent(); |
| | | #endregion |
| | | |
| | | |
| | | BindEvent(); |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 重写移除方法 |
| | | /// </summary> |
| | | public override void RemoveFromParent() |
| | | { |
| | | ZbGateway.StatusList.Remove(this); |
| | | action(); |
| | | action = null; |
| | | RemoveUpdateControlDeviceStatuAction(); |
| | | base.RemoveFromParent(); |
| | | } |
| | | #endregion |
| | | |
| | | #region ◆ Add______________________________ |
| | | |
| | | /// <summary> |
| | | /// 构造方法 |
| | | /// AddTop |
| | | /// </summary> |
| | | public LightControl() |
| | | public void AddTop() |
| | | { |
| | | BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor; |
| | | ZbGateway.StatusList.Add(this); |
| | | var top = new TopFrameLayout(); |
| | | AddChidren(top); |
| | | top.InitTopview(); |
| | | top.backButton.MouseUpEventHandler += (sender, e) => |
| | | { |
| | | RemoveFromParent(); |
| | | }; |
| | | |
| | | var sharedBtn = new Button |
| | | { |
| | | X = Application.GetRealWidth(850), |
| | | Width = Application.GetMinReal(69), |
| | | Height = Application.GetMinReal(69), |
| | | Gravity = Gravity.CenterVertical, |
| | | 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 += More; |
| | | |
| | | } |
| | | /// <summary> |
| | | /// AddBodyView |
| | | /// </summary> |
| | | public void AddBodyView(DeviceUI device) |
| | | { |
| | | bodyFrameLayout = new FrameLayout() |
| | | { |
| | | Y = Application.GetRealHeight(184), |
| | | Height = Application.GetRealHeight(1737), |
| | | BackgroundColor = ZigbeeColor.Current.GXCGrayBackgroundColor, |
| | | }; |
| | | AddChidren(bodyFrameLayout); |
| | | |
| | | var itemView = new FrameLayout() |
| | | { |
| | | Y = Application.GetRealHeight(115), |
| | | Width = Application.GetRealWidth(965), |
| | | Height = Application.GetRealHeight(1316), |
| | | Radius =(uint)Application.GetRealHeight(CommonFormResouce.BigFormRadius), |
| | | Gravity = Gravity.CenterHorizontal, |
| | | BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor |
| | | }; |
| | | bodyFrameLayout.AddChidren(itemView); |
| | | |
| | | collectionBtn = new Button() |
| | | { |
| | | X = Application.GetRealWidth(850), |
| | | Y = Application.GetRealHeight(46), |
| | | Width = Application.GetMinReal(69), |
| | | Height = Application.GetMinReal(69), |
| | | UnSelectedImagePath = "Item/Collection.png", |
| | | SelectedImagePath = "Item/CollectionSelected.png" |
| | | }; |
| | | itemView.AddChidren(collectionBtn); |
| | | |
| | | var deviceNameBtn = new Button() |
| | | { |
| | | Y = Application.GetRealHeight(46), |
| | | Width=Application.GetRealWidth(500), |
| | | Height = Application.GetRealHeight(60), |
| | | Gravity = Gravity.CenterHorizontal, |
| | | Text = device.CommonDevice.DeviceEpointName, |
| | | TextColor = ZigbeeColor.Current.GXCTextBlackColor, |
| | | TextSize=15 |
| | | }; |
| | | itemView.AddChidren(deviceNameBtn); |
| | | |
| | | StatuBtn = new Button |
| | | { |
| | | Y = Application.GetRealHeight(118), |
| | | Width = Application.GetRealWidth(600), |
| | | Height = Application.GetRealHeight(60), |
| | | Gravity = Gravity.CenterHorizontal, |
| | | TextColor = ZigbeeColor.Current.GXCTextGrayColor, |
| | | Text=CommonFormResouce.GetSwitchStatu(device.CommonDevice.IsOnline==1) |
| | | }; |
| | | itemView.AddChidren(StatuBtn); |
| | | |
| | | deviceIMG = new Button() |
| | | { |
| | | Y = Application.GetRealHeight(389), |
| | | Width = Application.GetMinRealAverage(377), |
| | | Height = Application.GetMinRealAverage(435), |
| | | Gravity = Gravity.CenterHorizontal, |
| | | UnSelectedImagePath = "Light/DeskLamp.png", |
| | | SelectedImagePath = "Light/DeskLampSelected.png", |
| | | IsSelected = (device.CommonDevice as ToggleLight).OnOffStatus == 1 |
| | | }; |
| | | itemView.AddChidren(deviceIMG); |
| | | |
| | | switchBtn = new Button() |
| | | { |
| | | Y = Application.GetRealHeight(996), |
| | | Width = Application.GetMinRealAverage(81), |
| | | Height = Application.GetMinRealAverage(81), |
| | | Gravity = Gravity.CenterHorizontal, |
| | | UnSelectedImagePath = "Item/Switch.png", |
| | | SelectedImagePath = "Item/SwitchSelected.png", |
| | | IsSelected = (device.CommonDevice as ToggleLight).OnOffStatus == 1 |
| | | }; |
| | | itemView.AddChidren(switchBtn); |
| | | |
| | | var roomBG = new Button |
| | | { |
| | | 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" |
| | | }; |
| | | itemView.AddChidren(roomBtn); |
| | | |
| | | roomName = new Button() |
| | | { |
| | | X = Application.GetRealWidth(150), |
| | | Y = Application.GetRealHeight(1224), |
| | | Width = Application.GetRealWidth(400), |
| | | Height = Application.GetRealHeight(50), |
| | | Text = room.Name, |
| | | TextAlignment = TextAlignment.CenterLeft, |
| | | TextColor = ZigbeeColor.Current.GXCTextWhiteColor |
| | | }; |
| | | itemView.AddChidren(roomName); |
| | | } |
| | | |
| | | #endregion |
| | |
| | | private void BindEvent() |
| | | { |
| | | switchBtn.MouseUpEventHandler += Switch; |
| | | deviceIMG.MouseUpEventHandler += Switch; |
| | | collectionBtn.MouseUpEventHandler += Collection; |
| | | moreBtn.MouseUpEventHandler += More; |
| | | roomBtn.MouseUpEventHandler += BackToRoomHandler; |
| | | roomName.MouseUpEventHandler += BackToRoomHandler; |
| | | } |
| | | |
| | | #endregion |
| | |
| | | sendedControlCommand = false; |
| | | zbGateway.ReportAction += UpdateDeviceControllStatu; |
| | | switchBtn.IsSelected = !switchBtn.IsSelected; |
| | | deviceIMG.IsSelected = !deviceIMG.IsSelected; |
| | | StatuBtn.Text = CommonFormResouce.GetSwitchStatu(deviceIMG.IsSelected); |
| | | if (switchBtn.IsSelected == true) |
| | | { |
| | | (device.CommonDevice as ToggleLight).SwitchControl(1); |
| | |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | |
| | | #endregion |
| | | |
| | |
| | | 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; |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ◆ 回到主页________________________ |
| | | /// <summary> |
| | | /// 回到主页 |
| | | /// </summary> |
| | | /// <param name="sender">Sender.</param> |
| | | /// <param name="mouseEventArgs">The ${ParameterType} instance containing the event data.</param> |
| | | private void BackToRoomHandler(object sender, MouseEventArgs mouseEventArgs ) |
| | | { |
| | | //backToRoom |
| | | |
| | | } |
| | | |
| | | #endregion |