using System; using System.Collections.Generic; using Shared.Common; using ZigBee.Device; using Shared.Phone.Device.AC; namespace Shared.Phone.UserView { /// /// User page. /// public class UserPage : FrameLayout,ZigBee.Common.IStatus { #region ◆ 变量_______________________ /// /// The user menu page. /// static UserPage userMenuPage; /// /// 底部单独菜单的宽度-360 /// private static readonly int tabBarEnum_Width = CommonPage.AppRealWidth / 3; /// /// 底部按钮图片的高度 /// private static readonly int tabBarEnumIMG_Height = 98; /// /// 底部按钮图片的宽度 /// private static readonly int tabBarEnumIMG_Width = 138; /// /// 底部按钮图片的Y值 /// private static readonly int tabBarEnumIMG_Y = 3; /// /// 底部按钮文字的高度 /// private static readonly int tabBarEnumName_Height = 40; /// /// 底部按钮文字的Y值 /// private static readonly int tabBarEnumName_Y = 104; #endregion #region ◆ 接口____________________________ /// /// 该接口将弃用 !!!!!! /// 改用DeviceInfoChange() /// /// The changed. /// Common. public void Changed(CommonDevice common) { } /// /// 设备状态更新接口 /// type:如果为 DeviceInComingRespon:设备新上报 /// type:如果为 IASInfoReport:RemoveDeviceRespon /// type:如果为 DeviceStatusReport:设备上报 /// type:如果为 IASInfoReport:IAS安防信息上报 /// type:如果为 OnlineStatusChange: 设备在线状态更新 /// /// Common. /// Type tag. public void DeviceInfoChange(CommonDevice common, string typeTag) { var myDevice = LocalDevice.Current.GetDevice(common.DeviceAddr, common.DeviceEpoint); if (myDevice == null) { return; } //设备上报状态中 当CluterID=3,就证明该设备在线,直接标记 if (typeTag == "DeviceStatusReport") { try { switch (myDevice.Type) { case DeviceType.OnOffOutput: //开关功能 if (common.DeviceStatusReport.CluterID == 6) { var onOffOutputLight = (ToggleLight)myDevice; onOffOutputLight.DeviceStatusReport = common.DeviceStatusReport; //记录、更新状态 if (onOffOutputLight.DeviceStatusReport.AttriBute == null || onOffOutputLight.DeviceStatusReport.AttriBute.Count == 0) { return; } onOffOutputLight.OnOffStatus = onOffOutputLight.DeviceStatusReport.AttriBute[0].AttriButeData; onOffOutputLight.LastDateTime = DateTime.Now; } //当CluterID=3,就证明该设备在线,直接标记 if (common.DeviceStatusReport.CluterID == 3) { myDevice.IsOnline = 1; myDevice.LastDateTime = DateTime.Now; } break; case DeviceType.AirSwitch: //开关功能 if (common.DeviceStatusReport.CluterID == 6) { var airSwitch = (AirSwitch)myDevice; airSwitch.DeviceStatusReport = common.DeviceStatusReport; if (airSwitch.DeviceStatusReport.AttriBute == null || airSwitch.DeviceStatusReport.AttriBute.Count == 0) { return; } airSwitch.OnOffStatus = airSwitch.DeviceStatusReport.AttriBute[0].AttriButeData; airSwitch.LastDateTime = DateTime.Now; } //当CluterID=3,就证明该设备在线,直接标记 if (common.DeviceStatusReport.CluterID == 3) { myDevice.IsOnline = 1; myDevice.LastDateTime = DateTime.Now; } break; case DeviceType.WindowCoveringDevice: if (common.DeviceStatusReport.CluterID == 258) { var rollershade = (Rollershade)myDevice; rollershade.DeviceStatusReport = common.DeviceStatusReport; var attriButeList = rollershade.DeviceStatusReport.AttriBute; if (attriButeList == null || attriButeList.Count == 0) { return; } switch (attriButeList[0].AttributeId) { case 0: rollershade.WcdType = attriButeList[0].AttriButeData; rollershade.LastDateTime = DateTime.Now; break; } } if (common.DeviceStatusReport.CluterID == 3) { myDevice.IsOnline = 1; myDevice.LastDateTime = DateTime.Now; } break; case DeviceType.Thermostat: //AC功能 if (common.DeviceStatusReport.CluterID == 513) { var ac = (AC)myDevice; ac.DeviceStatusReport = common.DeviceStatusReport; var attriButeList = ac.DeviceStatusReport.AttriBute; if (attriButeList == null || attriButeList.Count == 0) { return; } //此属性表明室内当前的温度 * 100,实际温度为“LocalTemperature / 100”,单位:℃ var curTemp = (attriButeList[0].AttriButeData / 100 < ACControlBase.Temperature_High || attriButeList[0].AttriButeData / 100 > ACControlBase.Temperature_Low) ? attriButeList[0].AttriButeData / 100 : ACControlBase.Temperature_Default; switch (attriButeList[0].AttributeId) { case 0: ac.currentLocalTemperature = curTemp; ac.LastDateTime = DateTime.Now; break; case 17: ac.currentCoolingSetpoint = curTemp; ac.LastDateTime = DateTime.Now; break; case 18: ac.currentHeatingSetpoint = curTemp; ac.LastDateTime = DateTime.Now; break; case 4096: ac.currentAutoSetpoint = curTemp; ac.LastDateTime = DateTime.Now; break; case 28: ac.currentSystemMode = attriButeList[0].AttriButeData; ac.LastDateTime = DateTime.Now; break; } } if (common.DeviceStatusReport.CluterID == 514) { var ac = (AC)myDevice; var attriButeList = common.DeviceStatusReport.AttriBute; if (attriButeList == null || attriButeList.Count == 0) { return; } ac.DeviceStatusReport = common.DeviceStatusReport; switch (attriButeList[0].AttributeId) { case 0: ac.currentFanMode = attriButeList[0].AttriButeData; ac.LastDateTime = DateTime.Now; break; case 4096: ac.currentFanSwingMode = attriButeList[0].AttriButeData; ac.LastDateTime = DateTime.Now; break; } } //当CluterID=3,就证明该设备在线,直接标记 if (common.DeviceStatusReport.CluterID == 3) { myDevice.IsOnline = 1; myDevice.LastDateTime = DateTime.Now; } break; case DeviceType.DimmableLight: //调光灯功能 //开关功能 if (common.DeviceStatusReport.CluterID == 6) { var dimmableLight = (DimmableLight)myDevice; dimmableLight.DeviceStatusReport = common.DeviceStatusReport; //记录、更新状态 if (dimmableLight.DeviceStatusReport.AttriBute == null || dimmableLight.DeviceStatusReport.AttriBute.Count == 0) { return; } dimmableLight.OnOffStatus = dimmableLight.DeviceStatusReport.AttriBute[0].AttriButeData; dimmableLight.LastDateTime = DateTime.Now; } //亮度 if (common.DeviceStatusReport.CluterID == 8) { var dimmableLight = (DimmableLight)myDevice; dimmableLight.DeviceStatusReport = common.DeviceStatusReport; var attriButeList = dimmableLight.DeviceStatusReport.AttriBute; if (attriButeList == null || attriButeList.Count == 0) { return; } switch (attriButeList[0].AttributeId) { case 0: dimmableLight.Level = attriButeList[0].AttriButeData; dimmableLight.LastDateTime = DateTime.Now; break; } } //当CluterID=3,就证明该设备在线,直接标记 if (common.DeviceStatusReport.CluterID == 3) { myDevice.IsOnline = 1; myDevice.LastDateTime = DateTime.Now; } break; } } catch (Exception ex) { System.Console.WriteLine($"Error:{ex.Message}"); } } //设备在线状态上报 else if (typeTag == "OnlineStatusChange") { myDevice.IsOnline = common.IsOnline; //记录回复时间 myDevice.LastDateTime = DateTime.Now; } } /// /// Changeds the IL ogic status. /// /// Logic. public void ChangedILogicStatus(ZigBee.Device.Logic logic) { //throw new NotImplementedException(); } /// /// Changeds the IS cene status. /// /// Scene. public void ChangedISceneStatus(Scene scene) { //throw new NotImplementedException(); } #endregion /// /// 用户界面 /// /// The instance. public static UserPage Instance { get { if (userMenuPage == null) { userMenuPage = new UserPage { }; } return userMenuPage; } } /// /// Initializes a new instance of the class. /// public UserPage() { BackgroundColor = Shared.Common.ZigbeeColor.Current.MainColor; ZbGateway.StatusList.Add(this); } /// /// 用户主体界面(中间部分) /// public FrameLayout BodyView = new FrameLayout { Height = Application.GetRealHeight(CommonPage.AppRealHeight - CommonPage.TabbarHeight), BackgroundColor = Shared.Common.ZigbeeColor.Current.MainColor, }; /// /// 用户菜单界面(底部部分) /// public FrameLayout BottomMenuView = new FrameLayout { Y = Application.GetRealHeight(CommonPage.AppRealHeight - CommonPage.TabbarHeight), Height = Application.GetRealHeight(CommonPage.TabbarHeight), BackgroundColor = Shared.Common.ZigbeeColor.Current.GXCBottomColor, }; #region 分割线 private Button bottomLine = new Button { Height = 1, BackgroundColor = ZigbeeColor.Current.GXCBottomLineColor }; #endregion #region 底部-主页按钮 /// /// 底部-主页按钮 /// public FrameLayout homePageFL = new FrameLayout { Width = Application.GetRealWidth(tabBarEnum_Width), Height = Application.GetRealHeight(CommonPage.TabbarHeight), }; /// /// The home page image. /// public Button homePageIMG = new Button { Y = Application.GetRealHeight(tabBarEnumIMG_Y), Height = Application.GetMinRealAverage(tabBarEnumIMG_Height), Width = Application.GetMinRealAverage(tabBarEnumIMG_Width), UnSelectedImagePath = "Navigation/Home.png", SelectedImagePath = "Navigation/HomeSelected.png", IsSelected = true, Gravity = Gravity.CenterHorizontal }; /// /// The name of the home page. /// public Button homePageName = new Button { Y = Application.GetRealHeight(tabBarEnumName_Y), Height = Application.GetRealHeight(tabBarEnumName_Height), TextID = R.MyInternationalizationString.HomePage, TextColor = Shared.Common.ZigbeeColor.Current.GXCTextBottomUnSelectedColor, SelectedTextColor = Shared.Common.ZigbeeColor.Current.GXCTextBlackColor2, IsSelected = true, Gravity = Gravity.CenterHorizontal, TextSize = 10 }; #endregion #region 分类-底部按钮 /// /// 分类-底部按钮 /// public FrameLayout categoryFL = new FrameLayout { X=Application.GetRealWidth(tabBarEnum_Width), Width = Application.GetRealWidth(tabBarEnum_Width), Height = Application.GetRealHeight(CommonPage.TabbarHeight) }; /// /// The category image. /// public Button categoryIMG = new Button { Y = Application.GetRealHeight(tabBarEnumIMG_Y), Height = Application.GetMinRealAverage(tabBarEnumIMG_Height), Width = Application.GetMinRealAverage(tabBarEnumIMG_Width), UnSelectedImagePath = "Navigation/Category.png", SelectedImagePath = "Navigation/CategorySelected.png", Gravity = Gravity.CenterHorizontal }; /// /// The name of the category. /// public Button categoryName = new Button { Y = Application.GetRealHeight(tabBarEnumName_Y), Height = Application.GetRealHeight(tabBarEnumName_Height), TextID = R.MyInternationalizationString.Category, TextColor = Shared.Common.ZigbeeColor.Current.GXCTextBottomUnSelectedColor, SelectedTextColor = Shared.Common.ZigbeeColor.Current.GXCTextBlackColor2, IsSelected = false, Gravity = Gravity.CenterHorizontal, TextSize=10 }; #endregion #region 个人中心-底部按钮 /// /// 个人中心-底部按钮 /// public FrameLayout settingFL = new FrameLayout { X = Application.GetRealWidth(tabBarEnum_Width*2), Width = Application.GetRealWidth(tabBarEnum_Width), Height = Application.GetRealHeight(CommonPage.TabbarHeight) }; /// /// The setting image. /// public Button settingIMG = new Button { Y = Application.GetRealHeight(tabBarEnumIMG_Y), Height = Application.GetMinRealAverage(tabBarEnumIMG_Height), Width = Application.GetMinRealAverage(tabBarEnumIMG_Width), UnSelectedImagePath = "Navigation/Setting.png", SelectedImagePath = "Navigation/SettingSelected.png", Gravity = Gravity.CenterHorizontal }; /// /// 个人中心 /// public Button settingName = new Button { Y = Application.GetRealHeight(tabBarEnumName_Y), Height = Application.GetRealHeight(tabBarEnumName_Height), TextID = R.MyInternationalizationString.Me, TextColor = Shared.Common.ZigbeeColor.Current.GXCTextBottomUnSelectedColor, SelectedTextColor = Shared.Common.ZigbeeColor.Current.GXCTextBlackColor2, IsSelected = false, Gravity = Gravity.CenterHorizontal, TextSize = 10 }; #endregion EventHandler BottomEventHandler = (sender, e) => { Instance.homePageName.IsSelected = false; Instance.homePageIMG.IsSelected = false; Instance.categoryName.IsSelected = false; Instance.categoryIMG.IsSelected = false; Instance.settingName.IsSelected = false; Instance.settingIMG.IsSelected = false; Instance.BodyView.RemoveAll(); if (sender == Instance.homePageIMG || sender == Instance.homePageName) { //主页 Instance.homePageName.IsSelected = true; Instance.homePageIMG.IsSelected = true; var home = new UserHomeView { }; Instance.BodyView.AddChidren(home); home.Show(); } else if (sender == Instance.categoryIMG || sender==Instance.categoryName) { //分类 Instance.categoryName.IsSelected = true; Instance.categoryIMG.IsSelected = true; var category = new Phone.Device.Category.Category { }; Instance.BodyView.AddChidren(category); category.Show(); } else if (sender == Instance.settingIMG || sender==Instance.settingName) { //个人中心 Instance.settingName.IsSelected = true; Instance.settingIMG.IsSelected = true; var form = new UserCenter.UserMain.UserMainForm(); Instance.BodyView.AddChidren(form); form.ShowForm(); } }; /// /// Fresh this instance. /// public void Fresh() { BottomEventHandler(Instance.homePageIMG, null); } /// /// Inits the page. /// public void InitPage() { if (0 < ChildrenCount) { return; } AddChidren(BodyView); AddChidren(BottomMenuView); BottomMenuView.AddChidren(Instance.bottomLine); Instance.homePageFL.AddChidren(Instance.homePageIMG); Instance.homePageFL.AddChidren(Instance.homePageName); BottomMenuView.AddChidren(Instance.homePageFL); Instance.categoryFL.AddChidren(Instance.categoryIMG); Instance.categoryFL.AddChidren(Instance.categoryName); BottomMenuView.AddChidren(Instance.categoryFL); Instance.settingFL.AddChidren(Instance.settingIMG); Instance.settingFL.AddChidren(Instance.settingName); BottomMenuView.AddChidren(Instance.settingFL); homePageIMG.MouseUpEventHandler += BottomEventHandler; homePageName.MouseUpEventHandler += BottomEventHandler; categoryIMG.MouseUpEventHandler += BottomEventHandler; categoryName.MouseUpEventHandler += BottomEventHandler; settingIMG.MouseUpEventHandler += BottomEventHandler; settingName.MouseUpEventHandler += BottomEventHandler; } } }