From f6e34a69f1d1e0b0b3a6252fe20acddca7fe56e5 Mon Sep 17 00:00:00 2001
From: WJC <wjc@hdlchina.com.cn>
Date: 星期二, 17 三月 2020 15:43:44 +0800
Subject: [PATCH] 2020-03-17-1
---
ZigbeeApp/Shared/Phone/Device/Light/AirSwitchControl.cs | 372 ++++++++++++++++++++++++++++++++++++++++++----------
1 files changed, 300 insertions(+), 72 deletions(-)
diff --git a/ZigbeeApp/Shared/Phone/Device/Light/AirSwitchControl.cs b/ZigbeeApp/Shared/Phone/Device/Light/AirSwitchControl.cs
index b23b5bc..7f279dc 100755
--- a/ZigbeeApp/Shared/Phone/Device/Light/AirSwitchControl.cs
+++ b/ZigbeeApp/Shared/Phone/Device/Light/AirSwitchControl.cs
@@ -2,12 +2,13 @@
using System.Collections.Generic;
using Shared.Common;
using Shared.Phone.Device.CommonForm;
+using Shared.Phone.Device.DeviceLogic;
using Shared.Phone.UserView;
using ZigBee.Device;
namespace Shared.Phone.Device.Light
{
/// <summary>
- /// 鐏厜鎺у埗鐣岄潰
+ /// 寮�鍏�
/// </summary>
public class AirSwitchControl : FrameLayout, ZigBee.Common.IStatus
{
@@ -19,7 +20,7 @@
/// <summary>
/// The action.
/// </summary>
- public Action action;
+ public Action<CommonDevice, Common.Room> action;
/// <summary>
/// The light image.
@@ -32,7 +33,7 @@
/// <summary>
/// 浼犺繃鏉ョ殑璁惧
/// </summary>
- private DeviceUI device;
+ private CommonDevice device;
/// <summary>
/// 浼犺繃鏉ョ殑鎴块棿
/// </summary>
@@ -61,7 +62,19 @@
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 鈼� 鎺ュ彛__________________________
@@ -110,20 +123,20 @@
{
var deviceUI = device;
//璁惧涓虹┖
- if (deviceUI.CommonDevice == null)
+ if (deviceUI == null)
{
return;
}
//鏄惁涓哄綋鍓嶈澶�
- if (deviceUI.CommonDevice.DeviceEpoint != common.DeviceEpoint || deviceUI.CommonDevice.DeviceAddr != common.DeviceAddr)
+ if (deviceUI.DeviceEpoint != common.DeviceEpoint || deviceUI.DeviceAddr != common.DeviceAddr)
{
return;
}
- if (deviceUI.CommonDevice.Type == DeviceType.AirSwitch)
+ if (deviceUI.Type == DeviceType.AirSwitch)
{
if (common.DeviceStatusReport.CluterID == 6)
{
- var light = deviceUI.CommonDevice as ZigBee.Device.AirSwitch;
+ var light = deviceUI as AirSwitch;
light.DeviceStatusReport = common.DeviceStatusReport;
//璁板綍銆佹洿鏂扮姸鎬�
if (light.DeviceStatusReport.AttriBute == null || light.DeviceStatusReport.AttriBute.Count == 0)
@@ -131,8 +144,22 @@
return;
}
light.OnOffStatus = light.DeviceStatusReport.AttriBute[0].AttriButeData;
- deviceIMG.IsSelected = switchBtn.IsSelected = light.OnOffStatus == 1;
- StatuBtn.Text = CommonFormResouce.GetSwitchStatu(deviceIMG.IsSelected);
+ StatuBtn.Text = Language.StringByID(R.MyInternationalizationString.Current) + " " + UserCenter.HdlDeviceOtherLogic.Current.GetDeviceStatu(device);
+
+ if (device.DfunctionType == DeviceFunctionType.A寮�鍏�)
+ {
+ SetONOFFStatu(light.OnOffStatus == 1);
+ }
+ else if (device.DfunctionType == DeviceFunctionType.A鎻掑骇)
+ {
+ deviceIMG.IsSelected = switchBtn.IsSelected = light.OnOffStatus == 1;
+ }
+ else
+ {
+ deviceIMG.IsSelected = switchBtn.IsSelected = light.OnOffStatus == 1;
+ }
+
+
light.LastDateTime = DateTime.Now;
}
}
@@ -145,7 +172,30 @@
}
else if (typeTag == "OnlineStatusChange")
{
-
+ Application.RunOnMainThread(() =>
+ {
+ try
+ {
+ var deviceUI = device;
+ //璁惧涓虹┖
+ if (deviceUI == null)
+ {
+ return;
+ }
+ //鏄惁涓哄綋鍓嶈澶�
+ if (deviceUI.DeviceEpoint != common.DeviceEpoint || deviceUI.DeviceAddr != common.DeviceAddr)
+ {
+ return;
+ }
+ deviceUI.IsOnline = common.IsOnline;
+ //OnBtn.IsSelected = OffBtn.IsSelected= deviceUI.CommonDevice.IsOnline == 1;
+ deviceUI.LastDateTime = DateTime.Now;
+ }
+ catch (Exception ex)
+ {
+ System.Console.WriteLine($"Error:{ex.Message}");
+ }
+ });
}
}
#endregion
@@ -157,9 +207,13 @@
public override void RemoveFromParent()
{
ZbGateway.StatusList.Remove(this);
- //action();
- //action = null;
+ action(device, room);
+ action = null;
RemoveUpdateControlDeviceStatuAction();
+ if (IsDrawerLockMode)
+ {
+ CommonPage.Instance.IsDrawerLockMode = false;
+ }
base.RemoveFromParent();
}
@@ -176,10 +230,10 @@
/// </summary>
/// <param name="dev">Device.</param>
/// <param name="room">Room.</param>
- public void Show(DeviceUI dev, Shared.Common.Room room)
+ public void Show(CommonDevice dev, Shared.Common.Room room)
{
device = dev;
- zbGateway = this.device.CommonDevice.Gateway;
+ zbGateway = this.device.Gateway;
this.room = room;
AddTop();
@@ -187,7 +241,7 @@
AddBodyView(device);
- var light = dev.CommonDevice as ZigBee.Device.AirSwitch;
+ var light = dev as AirSwitch;
//琛ヤ笂闈炶繙绋�
if (light.Gateway == null)
{
@@ -197,8 +251,7 @@
{
UserHomeView.ReadStatus(light, () =>
{
- light.ReadOnOffStatus();
- light.ReadAttri(Cluster_ID.Identify, AttriButeId.Switch);
+ ReadDeviceAttributeLogic.Instance.SendLightStatuComand(device);
});
}
else
@@ -206,13 +259,11 @@
//闃叉鐭椂闂村唴澶氭璇诲彇鐘舵��
if (CommonPage.ReadDeviceStatuSpan < (DateTime.Now - light.LastDateTime).TotalSeconds)
{
- light.ReadOnOffStatus();
- light.ReadAttri(Cluster_ID.Identify, AttriButeId.Switch);
+ ReadDeviceAttributeLogic.Instance.SendLightStatuComand(device);
}
}
- var de = Shared.Common.Room.LoveRoomDeviceUIFilePathList.Find((obj) => obj == device.FileName);
- if (de == null)
+ if (UserCenter.HdlRoomLogic.Current.IsCollectInRoom(device) == false)
{
collectionBtn.IsSelected = false;
}
@@ -243,16 +294,6 @@
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),
@@ -269,7 +310,7 @@
/// <summary>
/// AddBodyView
/// </summary>
- public void AddBodyView(DeviceUI device)
+ public void AddBodyView(CommonDevice device)
{
bodyFrameLayout = new FrameLayout()
{
@@ -307,9 +348,10 @@
Width = Application.GetRealWidth(500),
Height = Application.GetRealHeight(60),
Gravity = Gravity.CenterHorizontal,
- Text = device.CommonDevice.DeviceEpointName,
+ Text = Common.LocalDevice.Current.GetDeviceEpointName(device),
TextColor = ZigbeeColor.Current.GXCTextBlackColor,
- TextSize = 15
+ TextSize = 15,
+ IsBold = true
};
itemView.AddChidren(deviceNameBtn);
@@ -320,33 +362,10 @@
Height = Application.GetRealHeight(60),
Gravity = Gravity.CenterHorizontal,
TextColor = ZigbeeColor.Current.GXCTextGrayColor,
- Text = CommonFormResouce.GetSwitchStatu(device.CommonDevice.IsOnline == 1)
+ Text = Language.StringByID(R.MyInternationalizationString.Current) + " " + UserCenter.HdlDeviceOtherLogic.Current.GetDeviceStatu(device),
+ 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
{
@@ -383,9 +402,142 @@
Height = Application.GetRealHeight(50),
Text = room.Name,
TextAlignment = TextAlignment.CenterLeft,
- TextColor = ZigbeeColor.Current.GXCTextWhiteColor
+ TextColor = ZigbeeColor.Current.GXCTextWhiteColor,
+ TextSize = 12
};
itemView.AddChidren(roomName);
+
+ AddByFunctionType(itemView);
+ }
+
+ /// <summary>
+ /// AddByFunctionType
+ /// </summary>
+ private void AddByFunctionType(FrameLayout itemView)
+ {
+ if (device.DfunctionType == DeviceFunctionType.A寮�鍏�)
+ {
+ AddOnOff(itemView);
+ }
+ else if (device.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 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 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 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 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 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 as AirSwitch).OnOffStatus == 1
+ };
+ itemView.AddChidren(switchBtn);
+
+ switchBtn.MouseUpEventHandler += Switch;
+ deviceIMG.MouseUpEventHandler += Switch;
}
#endregion
@@ -396,8 +548,6 @@
/// </summary>
private void BindEvent()
{
- switchBtn.MouseUpEventHandler += Switch;
- deviceIMG.MouseUpEventHandler += Switch;
collectionBtn.MouseUpEventHandler += Collection;
}
@@ -416,17 +566,26 @@
zbGateway.ReportAction += UpdateDeviceControllStatu;
switchBtn.IsSelected = !switchBtn.IsSelected;
deviceIMG.IsSelected = !deviceIMG.IsSelected;
- StatuBtn.Text = CommonFormResouce.GetSwitchStatu(deviceIMG.IsSelected);
+ StatuBtn.Text = Language.StringByID(R.MyInternationalizationString.Current) + " ";
+ if (deviceIMG.IsSelected == true)
+ {
+ StatuBtn.Text += Language.StringByID(R.MyInternationalizationString.uOpen1);
+ }
+ else
+ {
+ StatuBtn.Text += Language.StringByID(R.MyInternationalizationString.Close);
+ }
+
if (switchBtn.IsSelected == true)
{
- (device.CommonDevice as ZigBee.Device.AirSwitch).SwitchControl(1);
+ (device as AirSwitch).SwitchControl(1);
}
else
{
- (device.CommonDevice as ZigBee.Device.AirSwitch).SwitchControl(0);
+ (device as AirSwitch).SwitchControl(0);
}
//鎺у埗寤舵椂鍥炶皟
- DeviceUI.SendCommandDelayAction(device.CommonDevice, () =>
+ UserCenter.HdlDeviceOtherLogic.Current.SendCommandDelayAction(device, () =>
{
if (Parent == null)
{
@@ -435,11 +594,80 @@
RemoveUpdateControlDeviceStatuAction();
if (sendedControlCommand == false)
{
- DeviceUI.ShowStatuTip(R.MyInternationalizationString.FAIL);
+ UserCenter.HdlDeviceOtherLogic.Current.ShowStatuTip(R.MyInternationalizationString.FAIL);
}
});
}
+ /// <summary>
+ /// ON
+ /// </summary>
+ /// <param name="sender"></param>
+ /// <param name="eventArgs"></param>
+ private void ON(object sender, MouseEventArgs eventArgs)
+ {
+ SetONOFFStatu(true);
+ (device as AirSwitch).SwitchControl(1);
+ //鎺у埗寤舵椂鍥炶皟
+ zbGateway.ReportAction += UpdateDeviceControllStatu;
+ UserCenter.HdlDeviceOtherLogic.Current.SendCommandDelayAction(device, () =>
+ {
+ if (Parent == null)
+ {
+ return;
+ }
+ RemoveUpdateControlDeviceStatuAction();
+ if (sendedControlCommand == false)
+ {
+ UserCenter.HdlDeviceOtherLogic.Current.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 as AirSwitch).SwitchControl(0);
+ //鎺у埗寤舵椂鍥炶皟
+ zbGateway.ReportAction += UpdateDeviceControllStatu;
+ UserCenter.HdlDeviceOtherLogic.Current.SendCommandDelayAction(device, () =>
+ {
+ if (Parent == null)
+ {
+ return;
+ }
+ RemoveUpdateControlDeviceStatuAction();
+ if (sendedControlCommand == false)
+ {
+ UserCenter.HdlDeviceOtherLogic.Current.ShowStatuTip(R.MyInternationalizationString.FAIL);
+ }
+ });
+ }
+
+ /// <summary>
+ /// SetONOFFStatu
+ /// </summary>
+ /// <param name="statu"></param>
+ private void SetONOFFStatu(bool statu)
+ {
+ StatuBtn.Text = Language.StringByID(R.MyInternationalizationString.Current) + " ";
+ if (statu)
+ {
+ OnBtn.IsSelected = true;
+ OffBtn.IsSelected = false;
+ StatuBtn.Text += Language.StringByID(R.MyInternationalizationString.uOpen1);
+ }
+ else
+ {
+ OnBtn.IsSelected = false;
+ OffBtn.IsSelected = true;
+ StatuBtn.Text += Language.StringByID(R.MyInternationalizationString.Close);
+ }
+ }
#endregion
@@ -456,9 +684,9 @@
UserView.HomePage.Instance.AddChidren(detailInfo);
UserView.HomePage.Instance.PageIndex += 1;
detailInfo.Show(device, room);
- detailInfo.action = () =>
+ detailInfo.EditAction += (curDev, curRoom) =>
{
- Show(device, room);
+ Show(curDev, curRoom);
};
}
@@ -475,12 +703,12 @@
//collection
if ((sender as Button).IsSelected)
{
- Shared.Common.Room.CurrentRoom.GetLoveRoom().DeleteDevice(device.FileName);
+ UserCenter.HdlRoomLogic.Current.DeleteLoveDevice(device);
(sender as Button).IsSelected = false;
}
else
{
- Shared.Common.Room.CurrentRoom.GetLoveRoom().AddDevice(device.FileName);
+ UserCenter.HdlRoomLogic.Current.AddLoveDevice(device);
(sender as Button).IsSelected = true;
}
}
@@ -505,7 +733,7 @@
return;
}
var tempDevice = (CommonDevice)objValue;
- if (tempDevice.DeviceEpoint != this.device.CommonDevice.DeviceEpoint || tempDevice.DeviceAddr != this.device.CommonDevice.DeviceAddr)
+ if (tempDevice.DeviceEpoint != this.device.DeviceEpoint || tempDevice.DeviceAddr != this.device.DeviceAddr)
{
//涓嶆槸褰撳墠璁惧鐨勬帹閫侊紝鍒欎笉澶勭悊
return;
--
Gitblit v1.8.0