| | |
| | | namespace Shared.Phone.Device.Light |
| | | { |
| | | /// <summary> |
| | | /// 灯光控制界面 |
| | | /// 开关 |
| | | /// </summary> |
| | | public class AirSwitchControl : FrameLayout, ZigBee.Common.IStatus |
| | | { |
| | |
| | | /// <summary> |
| | | /// The action. |
| | | /// </summary> |
| | | public Action action; |
| | | public Action<DeviceUI, Common.Room> action; |
| | | |
| | | /// <summary> |
| | | /// The light image. |
| | |
| | | private FrameLayout bodyFrameLayout; |
| | | |
| | | private Button StatuBtn; |
| | | /// <summary> |
| | | /// OnBtn |
| | | /// </summary> |
| | | private Button OnBtn; |
| | | /// <summary> |
| | | /// OffBtn |
| | | /// </summary> |
| | | private Button OffBtn; |
| | | |
| | | /// <summary> |
| | | /// IsDrawerLockMode |
| | | /// </summary> |
| | | public bool IsDrawerLockMode; |
| | | |
| | | #endregion |
| | | |
| | | #region ◆ 接口__________________________ |
| | |
| | | { |
| | | if (common.DeviceStatusReport.CluterID == 6) |
| | | { |
| | | var light = deviceUI.CommonDevice as ZigBee.Device.AirSwitch; |
| | | var light = deviceUI.CommonDevice as AirSwitch; |
| | | light.DeviceStatusReport = common.DeviceStatusReport; |
| | | //记录、更新状态 |
| | | if (light.DeviceStatusReport.AttriBute == null || light.DeviceStatusReport.AttriBute.Count == 0) |
| | |
| | | return; |
| | | } |
| | | light.OnOffStatus = light.DeviceStatusReport.AttriBute[0].AttriButeData; |
| | | deviceIMG.IsSelected = switchBtn.IsSelected = light.OnOffStatus == 1; |
| | | StatuBtn.Text = $"{Language.StringByID(R.MyInternationalizationString.Current)} {device.GetDeviceStatu()}"; |
| | | |
| | | if (device.CommonDevice.DfunctionType == DeviceFunctionType.A开关) |
| | | { |
| | | SetONOFFStatu(light.OnOffStatus == 1); |
| | | } |
| | | else if (device.CommonDevice.DfunctionType == DeviceFunctionType.A插座) |
| | | { |
| | | deviceIMG.IsSelected = switchBtn.IsSelected = light.OnOffStatus == 1; |
| | | } |
| | | else |
| | | { |
| | | deviceIMG.IsSelected = switchBtn.IsSelected = light.OnOffStatus == 1; |
| | | } |
| | | |
| | | |
| | | light.LastDateTime = DateTime.Now; |
| | | } |
| | | } |
| | |
| | | } |
| | | 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; |
| | | } |
| | | deviceUI.CommonDevice.IsOnline = common.IsOnline; |
| | | //OnBtn.IsSelected = OffBtn.IsSelected= deviceUI.CommonDevice.IsOnline == 1; |
| | | deviceUI.CommonDevice.LastDateTime = DateTime.Now; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | System.Console.WriteLine($"Error:{ex.Message}"); |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | #endregion |
| | |
| | | public override void RemoveFromParent() |
| | | { |
| | | ZbGateway.StatusList.Remove(this); |
| | | //action(); |
| | | //action = null; |
| | | action(device, room); |
| | | action = null; |
| | | RemoveUpdateControlDeviceStatuAction(); |
| | | if (IsDrawerLockMode) |
| | | { |
| | |
| | | AddBodyView(device); |
| | | |
| | | |
| | | var light = dev.CommonDevice as ZigBee.Device.AirSwitch; |
| | | var light = dev.CommonDevice as AirSwitch; |
| | | //补上非远程 |
| | | if (light.Gateway == null) |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | var de = Shared.Common.Room.LoveRoomDeviceUIFilePathList.Find((obj) => obj == device.FileName); |
| | | if (de == null) |
| | | if (Common.Room.CurrentRoom.IsCollectInRoom(device.FileName) == false) |
| | | { |
| | | collectionBtn.IsSelected = false; |
| | | } |
| | |
| | | Text = device.CommonDevice.DeviceEpointName, |
| | | TextColor = ZigbeeColor.Current.GXCTextBlackColor, |
| | | TextSize = 15, |
| | | IsBold=true |
| | | IsBold = true |
| | | }; |
| | | itemView.AddChidren(deviceNameBtn); |
| | | |
| | |
| | | TextSize = 10 |
| | | }; |
| | | 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 ZigBee.Device.AirSwitch).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 ZigBee.Device.AirSwitch).OnOffStatus == 1 |
| | | }; |
| | | itemView.AddChidren(switchBtn); |
| | | |
| | | var roomBG = new Button |
| | | { |
| | |
| | | TextSize = 12 |
| | | }; |
| | | itemView.AddChidren(roomName); |
| | | |
| | | AddByFunctionType(itemView); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// AddByFunctionType |
| | | /// </summary> |
| | | private void AddByFunctionType(FrameLayout itemView) |
| | | { |
| | | if (device.CommonDevice.DfunctionType == DeviceFunctionType.A开关) |
| | | { |
| | | AddOnOff(itemView); |
| | | } |
| | | else if (device.CommonDevice.DfunctionType == DeviceFunctionType.A插座) |
| | | { |
| | | AddPlug(itemView); |
| | | } |
| | | else |
| | | { |
| | | AddLight(itemView); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// AddOnOff |
| | | /// </summary> |
| | | private void AddOnOff(FrameLayout itemView) |
| | | { |
| | | deviceIMG = new Button() |
| | | { |
| | | Y = Application.GetRealHeight(340), |
| | | Width = Application.GetMinRealAverage(579), |
| | | Height = Application.GetMinRealAverage(579), |
| | | Gravity = Gravity.CenterHorizontal, |
| | | UnSelectedImagePath = "Light/OnOff.png", |
| | | }; |
| | | itemView.AddChidren(deviceIMG); |
| | | |
| | | OffBtn = new Button |
| | | { |
| | | X = Application.GetRealWidth(294), |
| | | Y = Application.GetRealHeight(588), |
| | | Width = Application.GetMinRealAverage(81), |
| | | Height = Application.GetMinRealAverage(81), |
| | | UnSelectedImagePath = "Light/OFF.png", |
| | | SelectedImagePath = "Light/OFFSelected.png", |
| | | IsSelected = (device.CommonDevice as AirSwitch).OnOffStatus == 0 |
| | | }; |
| | | itemView.AddChidren(OffBtn); |
| | | |
| | | OnBtn = new Button |
| | | { |
| | | X = Application.GetRealWidth(590), |
| | | Y = Application.GetRealHeight(588), |
| | | Width = Application.GetMinRealAverage(81), |
| | | Height = Application.GetMinRealAverage(81), |
| | | UnSelectedImagePath = "Light/ON.png", |
| | | SelectedImagePath = "Light/ONSelected.png", |
| | | IsSelected = (device.CommonDevice as AirSwitch).OnOffStatus == 1 |
| | | }; |
| | | itemView.AddChidren(OnBtn); |
| | | |
| | | OnBtn.MouseUpEventHandler += ON; |
| | | OffBtn.MouseUpEventHandler += OFF; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// light |
| | | /// </summary> |
| | | /// <param name="itemView"></param> |
| | | private void AddLight(FrameLayout itemView) |
| | | { |
| | | 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 AirSwitch).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 AirSwitch).OnOffStatus == 1 |
| | | }; |
| | | itemView.AddChidren(switchBtn); |
| | | |
| | | switchBtn.MouseUpEventHandler += Switch; |
| | | deviceIMG.MouseUpEventHandler += Switch; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// plug |
| | | /// </summary> |
| | | /// <param name="itemView"></param> |
| | | private void AddPlug(FrameLayout itemView) |
| | | { |
| | | deviceIMG = new Button() |
| | | { |
| | | Y = Application.GetRealHeight(344), |
| | | Width = Application.GetMinRealAverage(567), |
| | | Height = Application.GetMinRealAverage(567), |
| | | Gravity = Gravity.CenterHorizontal, |
| | | UnSelectedImagePath = "Light/Plug.png", |
| | | SelectedImagePath = "Light/PlugSelected.png", |
| | | IsSelected = (device.CommonDevice as AirSwitch).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 AirSwitch).OnOffStatus == 1 |
| | | }; |
| | | itemView.AddChidren(switchBtn); |
| | | |
| | | switchBtn.MouseUpEventHandler += Switch; |
| | | deviceIMG.MouseUpEventHandler += Switch; |
| | | } |
| | | |
| | | #endregion |
| | |
| | | /// </summary> |
| | | private void BindEvent() |
| | | { |
| | | switchBtn.MouseUpEventHandler += Switch; |
| | | deviceIMG.MouseUpEventHandler += Switch; |
| | | collectionBtn.MouseUpEventHandler += Collection; |
| | | } |
| | | |
| | |
| | | switchBtn.IsSelected = !switchBtn.IsSelected; |
| | | deviceIMG.IsSelected = !deviceIMG.IsSelected; |
| | | StatuBtn.Text = deviceIMG.IsSelected ? $"{Language.StringByID(R.MyInternationalizationString.Current)} {Language.StringByID(R.MyInternationalizationString.Open)}" : $"{Language.StringByID(R.MyInternationalizationString.Current)} {Language.StringByID(R.MyInternationalizationString.Shut)}"; |
| | | |
| | | if (switchBtn.IsSelected == true) |
| | | { |
| | | (device.CommonDevice as ZigBee.Device.AirSwitch).SwitchControl(1); |
| | | (device.CommonDevice as AirSwitch).SwitchControl(1); |
| | | } |
| | | else |
| | | { |
| | | (device.CommonDevice as ZigBee.Device.AirSwitch).SwitchControl(0); |
| | | (device.CommonDevice as AirSwitch).SwitchControl(0); |
| | | } |
| | | //控制延时回调 |
| | | DeviceUI.SendCommandDelayAction(device.CommonDevice, () => |
| | |
| | | }); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// ON |
| | | /// </summary> |
| | | /// <param name="sender"></param> |
| | | /// <param name="eventArgs"></param> |
| | | private void ON(object sender, MouseEventArgs eventArgs) |
| | | { |
| | | SetONOFFStatu(true); |
| | | (device.CommonDevice as AirSwitch).SwitchControl(1); |
| | | //控制延时回调 |
| | | zbGateway.ReportAction += UpdateDeviceControllStatu; |
| | | DeviceUI.SendCommandDelayAction(device.CommonDevice, () => |
| | | { |
| | | if (Parent == null) |
| | | { |
| | | return; |
| | | } |
| | | RemoveUpdateControlDeviceStatuAction(); |
| | | if (sendedControlCommand == false) |
| | | { |
| | | DeviceUI.ShowStatuTip(R.MyInternationalizationString.FAIL); |
| | | } |
| | | }); |
| | | } |
| | | /// <summary> |
| | | /// OFF |
| | | /// </summary> |
| | | /// <param name="sender"></param> |
| | | /// <param name="eventArgs"></param> |
| | | private void OFF(object sender, MouseEventArgs eventArgs) |
| | | { |
| | | SetONOFFStatu(false); |
| | | (device.CommonDevice as AirSwitch).SwitchControl(0); |
| | | //控制延时回调 |
| | | zbGateway.ReportAction += UpdateDeviceControllStatu; |
| | | DeviceUI.SendCommandDelayAction(device.CommonDevice, () => |
| | | { |
| | | if (Parent == null) |
| | | { |
| | | return; |
| | | } |
| | | RemoveUpdateControlDeviceStatuAction(); |
| | | if (sendedControlCommand == false) |
| | | { |
| | | DeviceUI.ShowStatuTip(R.MyInternationalizationString.FAIL); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// SetONOFFStatu |
| | | /// </summary> |
| | | /// <param name="statu"></param> |
| | | private void SetONOFFStatu(bool statu) |
| | | { |
| | | if (statu) |
| | | { |
| | | OnBtn.IsSelected = true; |
| | | OffBtn.IsSelected = false; |
| | | } |
| | | else |
| | | { |
| | | OnBtn.IsSelected = false; |
| | | OffBtn.IsSelected = true; |
| | | } |
| | | StatuBtn.Text = statu ? $"{Language.StringByID(R.MyInternationalizationString.Current)} {Language.StringByID(R.MyInternationalizationString.Open)}" : $"{Language.StringByID(R.MyInternationalizationString.Current)} {Language.StringByID(R.MyInternationalizationString.Shut)}"; |
| | | } |
| | | |
| | | |
| | | #endregion |
| | |
| | | UserView.HomePage.Instance.AddChidren(detailInfo); |
| | | UserView.HomePage.Instance.PageIndex += 1; |
| | | detailInfo.Show(device, room); |
| | | detailInfo.EditAction = (d,r) => |
| | | detailInfo.EditAction += (curDev, curRoom) => |
| | | { |
| | | Show(device, room); |
| | | Show(curDev, curRoom); |
| | | }; |
| | | } |
| | | |
| | |
| | | /// <param name="e">E.</param> |
| | | private void Collection(object sender, MouseEventArgs e) |
| | | { |
| | | //collection |
| | | if ((sender as Button).IsSelected) |
| | | { |
| | | Shared.Common.Room.CurrentRoom.GetLoveRoom().DeleteDevice(device.FileName); |