using System; using System.Collections.Generic; using Shared.SimpleControl.Phone.Music; namespace Shared.SimpleControl.Phone { public static class UserMiddle { public static int userMenuItemHeight { get { return Convert.ToInt32 (90 * MainPage.PixelScale); } } public static FrameLayout UserPageView = new FrameLayout (); public static Button LinkStatusTip = new Button () { Height = Application.GetRealHeight (Convert.ToInt32 (36 * MainPage.PixelScale)), BackgroundColor = SkinStyle.Current.LinkStatusTipColor }; public static PageLayout FavoritePageView = new PageLayout () { IsShowPoint = false, }; public static FrameLayout FavoriteBodyView = new FrameLayout (); public static UserRoom FavoriteRoom = new UserRoom () { //BackgroundColor = 0xFF0000ff, Height = Application.GetRealHeight (Application.DesignHeight - userMenuItemHeight) }; public static PageLayout DevicePageView = new PageLayout () { IsShowPoint = false, }; public static FrameLayout DeviceBodyView = new FrameLayout () { Height = Application.GetRealHeight (Application.DesignHeight) }; public static VerticalScrolViewLayout DeviceView = new VerticalScrolViewLayout () { Y = Application.GetRealHeight (126), Height = Application.GetRealHeight (Application.DesignHeight - 126 - userMenuItemHeight), }; public static PageLayout RoomPageView = new PageLayout () { IsShowPoint = false, }; public static FrameLayout RoomBodyView = new FrameLayout () { Width = Application.GetRealWidth (640), Height = Application.GetRealHeight (Application.DesignHeight) }; public static PageLayout SettingPageView = new PageLayout () { BackgroundColor = 0xFF121212, IsShowPoint = false, }; public static FrameLayout SettingBodyView = new FrameLayout () { BackgroundColor = 0xFF121212, Height = Application.GetRealHeight (Application.DesignHeight) }; public static VerticalScrolViewLayout SettingView = new VerticalScrolViewLayout () { Height = Application.GetRealHeight (Application.DesignHeight - userMenuItemHeight), BackgroundColor = 0xFF121212, ScrollEnabled = false }; public static FrameLayout UserMenuItem = new FrameLayout () { Y = Application.GetRealHeight (Application.DesignHeight - userMenuItemHeight), Height = Application.GetRealHeight (userMenuItemHeight+5), BackgroundColor = SkinStyle.Current.MainColor }; static int curPageView = 0; #region ---Bottom Button---- public static Button btnFavorite = new Button () { Width = Application.GetRealWidth (160), Height = MainPage.GetDesignHeight (90), TextID = R.MyInternationalizationString.Favorite, TextColor = SkinStyle.Current.TextColor1, SelectedTextColor = SkinStyle.Current.SelectedColor, BackgroundColor = SkinStyle.Current.MainColor, SelectedBackgroundColor = SkinStyle.Current.UserMenuItemButton, UnSelectedImagePath = "Navigation/MenuFavorite.png", SelectedImagePath = "Navigation/MenuFavoriteOn.png", TextSize = 10, Padding = new Padding (Application.GetRealHeight (50), 0, 0, 0), IsSelected = true }; public static Button btnDevice = new Button () { X = Application.GetRealWidth (160), Width = Application.GetRealWidth (160), Height = MainPage.GetDesignHeight (90), TextID = R.MyInternationalizationString.Category, SelectedTextColor = SkinStyle.Current.SelectedColor, TextColor = SkinStyle.Current.TextColor1, BackgroundColor = SkinStyle.Current.MainColor, SelectedBackgroundColor = SkinStyle.Current.UserMenuItemButton, UnSelectedImagePath = "Navigation/MenuCategory.png", SelectedImagePath = "Navigation/MenuCategoryOn.png", TextSize = 10, Padding = new Padding (Application.GetRealHeight (50), 0, 0, 0), }; public static Button btnRoom = new Button () { X = Application.GetRealWidth (160 * 2), Width = Application.GetRealWidth (160), Height = MainPage.GetDesignHeight (90), TextID = R.MyInternationalizationString.Rooms, SelectedTextColor = SkinStyle.Current.SelectedColor, TextColor = SkinStyle.Current.TextColor1, BackgroundColor = SkinStyle.Current.MainColor, SelectedBackgroundColor = SkinStyle.Current.UserMenuItemButton, UnSelectedImagePath = "Navigation/MenuRoom.png", SelectedImagePath = "Navigation/MenuRoomOn.png", TextSize = 10, Padding = new Padding (Application.GetRealHeight (50), 0, 0, 0), }; public static Button btnSetting = new Button () { X = Application.GetRealWidth (160 * 3), Width = Application.GetRealWidth (160), Height = MainPage.GetDesignHeight (90), Text = "Download", SelectedTextColor = SkinStyle.Current.SelectedColor, TextColor = SkinStyle.Current.TextColor1, BackgroundColor = SkinStyle.Current.MainColor, SelectedBackgroundColor = SkinStyle.Current.UserMenuItemButton, UnSelectedImagePath = "Navigation/MenuSettings.png", SelectedImagePath = "Navigation/MenuSettingsOn.png", TextSize = 10, Padding = new Padding (Application.GetRealHeight (50), 0, 0, 0), }; public static void SelectedBottomButton (Button btn) { btnFavorite.IsSelected = false; btnDevice.IsSelected = false; btnRoom.IsSelected = false; btnSetting.IsSelected = false; btn.IsSelected = true; } #endregion static void CleanPageView (FrameLayout BodyView) { UserMenuItem.RemoveAll (); FavoriteRoom.RemoveAll (); FavoriteBodyView.RemoveAll (); FavoritePageView.RemoveAll (); DeviceView.RemoveAll (); DeviceBodyView.RemoveAll (); DevicePageView.RemoveAll (); RoomBodyView.RemoveAll (); RoomPageView.RemoveAll (); SettingView.RemoveAll (); SettingBodyView.RemoveAll (); SettingPageView.RemoveAll (); UserPageView.RemoveAll (); BodyView.AddChidren (UserMenuItem); UserMenuItem.AddChidren (btnFavorite); UserMenuItem.AddChidren (btnDevice); UserMenuItem.AddChidren (btnRoom); UserMenuItem.AddChidren (btnSetting); } public static void Init () { if (MainPage.LoginUser == null) MainPage.LoginUser = Newtonsoft.Json.JsonConvert.DeserializeObject (System.Text.Encoding.UTF8.GetString (Shared.IO.FileUtils.ReadFile (UserInfo.GlobalRegisterFile))); //判断需不需要登录,有没有登录,或者登录是否过期, if (MainPage.LoginUser == null ) { var ssd = new AccountLogin (); ssd.Show (); ssd.LoginViewShow (); } else { InitHomePageView (); } } /// /// 加载用户界面 /// public static void InitHomePageView () { //var s1 = new LightSwitch () { SubnetID = 42, DeviceID = 6, LoopID = 1, Name = "Dimming 1"}; //IO.FileUtils.SaveEquipmentMessage (s1, "1"); #if DEBUG //var tv = new InfraredMode () { SubnetID = 42, DeviceID = 1, LoopID = 1, InfraredType = InfraredType.TV, Name = "TV" }; //IO.FileUtils.SaveEquipmentMessage (tv, "1"); //var tv1 = new InfraredMode () { SubnetID = 42, DeviceID = 1, LoopID = 11, InfraredType = InfraredType.STB, Name = "stb" }; //IO.FileUtils.SaveEquipmentMessage (tv1, "11"); //var ac = new ACInfrared () { SubnetID = 42, DeviceID = 1, LoopID = 111, Name = "ac" }; //IO.FileUtils.SaveEquipmentMessage (ac, "111"); //var mLightDoorLock = new LightDoorLock () { SubnetID = 42, DeviceID = 7, LoopID = 1, Name = "Door Lock", ReadStatusSubnetID = 42, ReadStatusDeviceID = 5, ReadStatusLoopID = 3 }; //IO.FileUtils.SaveEquipmentMessage (mLightDoorLock, "1"); //var mCurtainModel = new CurtainModel () { SubnetID = 111, DeviceID = 8, LoopID = 1, Name = "Curtain" }; //IO.FileUtils.SaveEquipmentMessage (mCurtainModel, "1"); //var s2 = new LightMixDimming () { SubnetID = 42, DeviceID = 2, LoopID = 2, Name = "Dimming 2", CurrentBrightness = 100 }; //IO.FileUtils.SaveEquipmentMessage (s1, "2"); //var s3 = new LightMixDimming () { SubnetID = 42, DeviceID = 2, LoopID = 3, Name = "Dimming 3", CurrentBrightness = 0 }; //IO.FileUtils.SaveEquipmentMessage (s1, "3"); //var s4 = new LightMixDimming () { SubnetID = 42, DeviceID = 2, LoopID = 4, Name = "Dimming 4", CurrentBrightness = 88 }; //IO.FileUtils.SaveEquipmentMessage (s1, "4"); //var lii = new LightLogic () { Type = DeviceType.LightRGB, LoopID = 1, DeviceID = 4, SubnetID = 42, Name = "RGB" }; //IO.FileUtils.SaveEquipmentMessage (lii, lii.LoopID.ToString ()); //var daliLoop = new LightDALI { // Type = DeviceType.LightDALI, LoopID = 1, CoolTones_High = 100, CoolTones_Low = 100, CoolTones_High_Modular = 100, CoolTones_Low_Modular = 100, // WarmTones_High = 10, WarmTones_Low = 10, WarmTones_Low_Modular = 10, WarmTones_High_Modular = 10, CurrentBrightness = 0, CurTones_High = 20, CurTones_Low = 20, SubnetID = 42, DeviceID = 222 //}; //IO.FileUtils.SaveEquipmentMessage (daliLoop, daliLoop.LoopID.ToString ()); //var tt = new CurtainTrietex () { LoopID = 1, DeviceID = 1, SubnetID = 42, Name = "开合帘" }; //IO.FileUtils.SaveEquipmentMessage (tt, "1"); //var fa = new FreshAir () { LoopID = 1, DeviceID = 112, SubnetID = 42, Name = "Fresh Air" }; //IO.FileUtils.SaveEquipmentMessage (fa, fa.LoopID.ToString ()); //var se = new SensorPM25 () { LoopID = 1, DeviceID = 1, SubnetID = 11, Name = "PM2.5", CurrentPM25 = 22 }; //IO.FileUtils.SaveEquipmentMessage (se, "1"); //var se1 = new SensorCO2 () { LoopID = 1, DeviceID = 2, SubnetID = 11, Name = "CO2", CurrentCO2 = 338 }; //IO.FileUtils.SaveEquipmentMessage (se1, "2"); //var se2 = new SensorTVOC () { LoopID = 1, DeviceID = 3, SubnetID = 11, Name = "TVOC", CurrentTVOC = 197 }; //IO.FileUtils.SaveEquipmentMessage (se2, "3"); //var se3 = new SensorTemperature () { LoopID = 1, DeviceID = 4, SubnetID = 11, Name = "Temp.", CurrentTemperature = 19 }; //IO.FileUtils.SaveEquipmentMessage (se3, "4"); //var se4 = new SensorHumidity () { LoopID = 1, DeviceID = 5, SubnetID = 11, Name = "Humidity", CurrentHumidity = 43 }; //IO.FileUtils.SaveEquipmentMessage (se4, "5"); //var infraredMode1 = new ACInfrared () { LoopID = 1, SubnetID = 42, DeviceID = 12, Name = "AC",SetTemperature = 26,IndoorTemperature =28 }; //IO.FileUtils.SaveEquipmentMessage (infraredMode1, "1"); //var udo = new UniversalDevice () { LoopID = 1, SubnetID = 1, DeviceID = 6, ActionType = 2, Name = "Universal-1", obj1 = 1, TargetType = 0 }; //udo.SendBytes = new List () { 1, 0 }; //IO.FileUtils.SaveEquipmentMessage (udo, "1"); //var ud12 = new UniversalDevice () { LoopID = 2, SubnetID = 1, DeviceID = 6, ActionType = 0, Name = "Universal-2", obj1 = 1, TargetType = 1 }; //ud12.SendBytes = new List () { 2, 0 }; //IO.FileUtils.SaveEquipmentMessage (ud12, "2"); //var ud13 = new UniversalDevice () { ON_Text = "DAKAI", OFF_Text = "GUAN", LoopID = 3, SubnetID = 1, DeviceID = 6, ActionType = 1, Name = "Universal-3", obj1 = 1, TargetType = 2 }; //ud13.SendBytes = new List () { 3, 0 }; //IO.FileUtils.SaveEquipmentMessage (ud13, "3"); //var ud8 = new UniversalDevice () { LoopID = 1, SubnetID = 42, DeviceID = 90, ActionType = 2, Name = "Universal-1", obj1 = 1, TargetType = 0, UniversalType = 0xE01C }; //ud8.SendBytes = new List () { 1, 100 }; //IO.FileUtils.SaveEquipmentMessage (ud8, "1"); //var ud82 = new UniversalDevice () { LoopID = 1, SubnetID = 42, DeviceID = 90, ActionType = 2, Name = "Universal-2", obj1 = 1, TargetType = 0, UniversalType = 0xE01C }; //ud82.SendBytes = new List () { 2, 100 }; //IO.FileUtils.SaveEquipmentMessage (ud82, "2"); //var ud83 = new UniversalDevice () { ON_Text = "DAKAI", OFF_Text = "GUAN", LoopID = 3, SubnetID = 2, DeviceID = 6, ActionType = 1, Name = "Universal-3", obj1 = 1, TargetType = 2 }; //ud83.SendBytes = new List () { 3, 0 }; //IO.FileUtils.SaveEquipmentMessage (ud83, "3"); //SecurityModul sm0 = new SecurityModul () { Name = "SecurityModul-1", SubnetID = 42, DeviceID = 11, LoopID = 1, obj1 = 1 }; //SecurityModul sm1 = new SecurityModul () { Name = "SecurityArea-1", SubnetID = 42, DeviceID = 11, LoopID = 1, obj1 = 1, AreaNumber = 1 }; //SecurityModul sm2 = new SecurityModul () { Name = "SecurityArea-2", SubnetID = 42, DeviceID = 11, LoopID = 2, obj1 = 1, AreaNumber = 2 }; //SecurityModul sm3 = new SecurityModul () { Name = "SecurityArea-3", SubnetID = 42, DeviceID = 11, LoopID = 3, obj1 = 1, AreaNumber = 3 }; //SecurityModul sm4 = new SecurityModul () { Name = "SecurityArea-4", SubnetID = 42, DeviceID = 11, LoopID = 4, obj1 = 1, AreaNumber = 4 }; //SecurityModul sm5 = new SecurityModul () { Name = "SecurityArea-5", SubnetID = 42, DeviceID = 11, LoopID = 5, obj1 = 1, AreaNumber = 5 }; //SecurityModul sm6 = new SecurityModul () { Name = "SecurityArea-6", SubnetID = 42, DeviceID = 11, LoopID = 6, obj1 = 1, AreaNumber = 6 }; //ScurityDryContact sdc = new ScurityDryContact () { Name = "window", SubnetID = 42, DeviceID = 10, LoopID = 1, obj1 = 1, AreaNumber = 1 }; //ScurityDryContact sdc2 = new ScurityDryContact () { Name = "door", SubnetID = 42, DeviceID = 10, LoopID = 2, obj1 = 1, SensorType = 1, AreaNumber = 1 }; //ScurityDryContact sdc3 = new ScurityDryContact () { Name = "door2", SubnetID = 42, DeviceID = 10, LoopID = 3, obj1 = 1, SensorType = 1, AreaNumber = 1 }; //sm1.SensorList.Add (sdc); //sm1.SensorList.Add (sdc2); //sm2.SensorList.Add (sdc3); //IO.FileUtils.SaveEquipmentMessage (sm1, "1"); //IO.FileUtils.SaveEquipmentMessage (sm2, "2"); //IO.FileUtils.SaveEquipmentMessage (sm3, "3"); //IO.FileUtils.SaveEquipmentMessage (sm4, "4"); //IO.FileUtils.SaveEquipmentMessage (sm5, "5"); //IO.FileUtils.SaveEquipmentMessage (sm6, "6"); #endif if (null != UserPageView.Parent) { CleanPageView (FavoriteBodyView); UserPageView.AddChidren (FavoritePageView); FavoritePageView.AddChidren (FavoriteBodyView); FavoriteBodyView.AddChidren (FavoriteRoom); FavoriteRoom.InitRoomView (Room.FavoriteRoom); SelectedBottomButton (btnFavorite); curPageView = 0; btnFavorite.TextID = R.MyInternationalizationString.Favorite; btnDevice.TextID = R.MyInternationalizationString.Category; btnRoom.TextID = R.MyInternationalizationString.Rooms; btnSetting.TextID = R.MyInternationalizationString.Setting; FavoritePageView.PageIndex = 0; return; } UserHomePage.FrameLayoutMain.AddChidren (UserPageView); UserHomePage.FrameLayoutMain.AddChidren (LinkStatusTip); UserPageView.AddChidren (FavoritePageView); FavoritePageView.AddChidren (FavoriteBodyView); FavoriteBodyView.AddChidren (UserMenuItem); FavoriteBodyView.AddChidren (FavoriteRoom); FavoriteRoom.InitRoomView (Room.FavoriteRoom); #region 底部导航栏 UserMenuItem.AddChidren (btnFavorite); UserMenuItem.AddChidren (btnDevice); UserMenuItem.AddChidren (btnRoom); UserMenuItem.AddChidren (btnSetting); SelectedBottomButton (btnFavorite); btnFavorite.MouseUpEventHandler += (sender, e) => { CleanPageView (FavoriteBodyView); UserPageView.AddChidren (FavoritePageView); FavoritePageView.AddChidren (FavoriteBodyView); FavoriteBodyView.AddChidren (FavoriteRoom); FavoriteRoom.InitRoomView (Room.FavoriteRoom); curPageView = 0; SharedMethod.SharedMethod.CurPageLayout = FavoritePageView; SelectedBottomButton (btnFavorite); LinkStatusTip.BackgroundColor = SkinStyle.Current.LinkStatusTipColor; }; btnDevice.MouseUpEventHandler += (sender, e) => { try { CleanPageView (DeviceBodyView); UserPageView.AddChidren (DevicePageView); DevicePageView.AddChidren (DeviceBodyView); DeviceBodyView.AddChidren (DeviceView); UserDeviceView.DeviceMode (); curPageView = 1; SharedMethod.SharedMethod.CurPageLayout = DevicePageView; DevicePageView.PageIndex = 0; SelectedBottomButton (btnDevice); LinkStatusTip.BackgroundColor = SkinStyle.Current.LinkStatusTipColor; } catch (Exception ex) { Console.WriteLine (ex.Message); } finally { } }; btnRoom.MouseUpEventHandler += (sender, e) => { CleanPageView (RoomBodyView); UserPageView.AddChidren (RoomPageView); RoomPageView.AddChidren (RoomBodyView); UserRooms.ShowRoomList (); curPageView = 2; SharedMethod.SharedMethod.CurPageLayout = RoomPageView; RoomPageView.PageIndex = 0; SelectedBottomButton (btnRoom); LinkStatusTip.BackgroundColor = SkinStyle.Current.LinkStatusTipColor; }; btnSetting.MouseUpEventHandler += (sender, e) => { CleanPageView (SettingBodyView); UserPageView.AddChidren (SettingPageView); SettingPageView.AddChidren (SettingBodyView); SettingBodyView.AddChidren (SettingView); //UserSettingView.InitUserSettingView (); var loginView = new LoginView (); SettingView.AddChidren (loginView); loginView.LoginViewShow (); curPageView = 3; SharedMethod.SharedMethod.CurPageLayout = SettingPageView; SettingPageView.PageIndex = 0; SelectedBottomButton (btnSetting); LinkStatusTip.BackgroundColor = 0xFF121212; }; FavoritePageView.PageChange += (sender, e) => { if (e < FavoritePageView.ChildrenCount - 1) { FavoritePageView.GetChildren (FavoritePageView.ChildrenCount - 1).RemoveFromParent (); } }; SettingPageView.PageChange += (sender, e) => { if (e < SettingPageView.ChildrenCount - 1) { SettingPageView.GetChildren (SettingPageView.ChildrenCount - 1).RemoveFromParent (); } }; RoomPageView.PageChange += (sender, e) => { if (e < RoomPageView.ChildrenCount - 1) { RoomPageView.GetChildren (RoomPageView.ChildrenCount - 1).RemoveFromParent (); } }; DevicePageView.PageChange += (sender, e) => { while (e < DevicePageView.ChildrenCount - 1) { DevicePageView.GetChildren (DevicePageView.ChildrenCount - 1).RemoveFromParent (); } if (e == 0) { DevicePageView.ScrollEnabled = true; } }; #endregion } public static void ShowRoomsView () { CleanPageView (RoomBodyView); UserPageView.AddChidren (RoomPageView); RoomPageView.AddChidren (RoomBodyView); //UserMiddle.RoomBodyView.RemoveAll (); UserRooms.ShowRoomList (); curPageView = 2; SelectedBottomButton (btnRoom); } public static void ReadAllDeviceStatus () { if (MainPage.LoginUser == null || !MainPage.LoginUser.IsLogin) { return; } UserDeviceToCurtains.readAllStatus (true); UserDeviceToLight.readAllStatus (true); UserDeviceToSocket.readAllStatus (true); UserDeviceToAC.readAllStatus (true); UserDeviceToFH.readAllStatus (true); UserFresAirList.readAllStatus (true); } } }