using System;
|
using System.Collections.Generic;
|
using Shared.SimpleControl.Phone.Music;
|
|
namespace Shared.SimpleControl.Phone
|
{
|
public static class UserMiddle
|
{
|
|
public static int userMenuItemHeight {
|
get {
|
//if (Application.PixelScale > 1) {
|
// return Convert.ToInt32 (90 * Application.PixelScale + 20);
|
//} else {
|
return Convert.ToInt32 (90 * MainPage.PixelScale);
|
//}
|
}
|
}
|
|
public static FrameLayout UserPageView = new FrameLayout ();
|
|
//public static Button LinkStatusTip = new Button () {
|
// Height = Application.GetRealHeight (36),
|
// Width = Application.GetRealWidth (640),
|
// BackgroundColor = SkinStyle.Current.LinkStatusTipColor
|
//};
|
|
public static PageLayout FavoritePageView = new PageLayout () {
|
IsShowPoint = false,
|
};
|
public static FrameLayout FavoriteBodyView = new FrameLayout () {
|
Width = Application.GetRealWidth (640),
|
Height = Application.GetRealHeight (1136)
|
};
|
public static UserRoom FavoriteRoom = new UserRoom () {
|
Width = Application.GetRealWidth (640),
|
Height = Application.GetRealHeight (1136 - 90)
|
};
|
|
public static PageLayout DevicePageView = new PageLayout () {
|
IsShowPoint = false,
|
};
|
public static FrameLayout DeviceBodyView = new FrameLayout () {
|
Width = Application.GetRealWidth (640),
|
Height = Application.GetRealHeight (1136)
|
};
|
public static VerticalScrolViewLayout DeviceView = new VerticalScrolViewLayout () {
|
Y = Application.GetRealHeight (126),
|
Width = Application.GetRealWidth (640),
|
Height = Application.GetRealHeight (1136 - 126 - 90),
|
};
|
|
public static PageLayout RoomPageView = new PageLayout () {
|
IsShowPoint = false,
|
};
|
public static FrameLayout RoomBodyView = new FrameLayout () {
|
Width = Application.GetRealWidth (640),
|
Height = Application.GetRealHeight (1136)
|
};
|
|
public static PageLayout SettingPageView = new PageLayout () {
|
IsShowPoint = false,
|
};
|
public static FrameLayout SettingBodyView = new FrameLayout () {
|
BackgroundColor = SkinStyle.Current.MainColor,
|
Height = Application.GetRealHeight (1136)
|
};
|
public static VerticalScrolViewLayout SettingView = new VerticalScrolViewLayout () {
|
Y = Application.GetRealHeight (126),
|
Width = Application.GetRealWidth (640),
|
Height = Application.GetRealHeight (1136 - 126 - 90 - 90),
|
BackgroundColor = SkinStyle.Current.ViewColor,
|
ScrollEnabled = true
|
};
|
public static Button btnVersion = new Button () {
|
Y = Application.GetRealHeight (1136 - 90 - 90),
|
Width = Application.GetRealWidth (640),
|
Height = Application.GetRealHeight (90),
|
Text = Language.StringByID (R.MyInternationalizationString.Version) + " : " + MainPage.CodeIDString,
|
TextColor = SkinStyle.Current.TextColor1,
|
BackgroundColor = SkinStyle.Current.ViewColor,
|
Enable = false
|
};
|
|
public static FrameLayout UserMenuItem = new FrameLayout () {
|
Y = Application.GetRealHeight (Application.DesignHeight - 90),
|
Height = Application.GetRealHeight (95),
|
BackgroundColor = SkinStyle.Current.MainColor
|
};
|
|
public static PageLayout guidePageView = new PageLayout () {
|
IsShowPoint = false
|
};
|
|
static int curPageView = 0;
|
public static List<System.Threading.Thread> updateSensorhreadList = new List<System.Threading.Thread> ();
|
|
public static Button btnLinkStatus = new Button () {
|
Y = Application.GetRealHeight (10),
|
Width = Application.GetRealWidth (131),
|
Height = Application.GetRealHeight (80),
|
UnSelectedImagePath = MainPage.WiFiStatus,
|
};
|
|
#region ---Bottom Button----
|
public static Button btnFavorite = new Button () {
|
Width = Application.GetRealWidth (160),
|
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),
|
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),
|
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),
|
TextID = R.MyInternationalizationString.Setting,
|
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)
|
{
|
if (btnFavorite.Parent == null)
|
UserMenuItem.AddChidren (btnFavorite);
|
if (btnDevice.Parent == null)
|
UserMenuItem.AddChidren (btnDevice);
|
if (btnRoom.Parent == null)
|
UserMenuItem.AddChidren (btnRoom);
|
if (btnSetting.Parent == null)
|
UserMenuItem.AddChidren (btnSetting);
|
btnFavorite.IsSelected = false;
|
btnDevice.IsSelected = false;
|
btnRoom.IsSelected = false;
|
btnSetting.IsSelected = false;
|
btn.IsSelected = true;
|
}
|
#endregion
|
|
static void CleanPageView (FrameLayout BodyView)
|
{
|
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);
|
foreach (var thread in UserMiddle.updateSensorhreadList) {
|
thread.Abort ();
|
Console.WriteLine ("abortThread");
|
}
|
UserMiddle.updateSensorhreadList.Clear ();
|
}
|
|
public static void Init (bool isGuide = false)
|
{
|
if (MainPage.LoginUser == null)
|
MainPage.LoginUser = Newtonsoft.Json.JsonConvert.DeserializeObject<UserInfo> (System.Text.Encoding.UTF8.GetString (Shared.IO.FileUtils.ReadFile (UserInfo.GlobalRegisterFile)));
|
//判断需不需要登陆,有没有登陆,或者登陆是否过期,
|
if (MainPage.LoginUser == null || !MainPage.LoginUser.IsLogin) {
|
new AccountLogin ().Show ();
|
UserConfig.Instance.TipVersionBackup = UserConfig.Instance.VersionNumber;
|
} else {
|
if (UserConfig.Instance.GatewayList.Count == 0) {
|
UserHomePage.FrameLayoutMain.AddChidren (guidePageView);
|
var guide = new GuideAddResidence ();
|
guidePageView.AddChidren (guide);
|
guide.ShowHomeList (false);
|
guidePageView.PageIndex = 0;
|
MainPage.LoginUser.LastTime = DateTime.MinValue;
|
MainPage.LoginUser.SaveUserInfo ();
|
guidePageView.PageChange += (ddf, ffd) => {
|
if (ffd < guidePageView.ChildrenCount - 1) {
|
guidePageView.GetChildren (guidePageView.ChildrenCount - 1).RemoveFromParent ();
|
}
|
};
|
return;
|
}
|
InitHomePageView ();
|
//后台验证账号
|
System.Threading.Tasks.Task.Run (() => {
|
try {
|
var requestObj = new LoginObj () { Account = MainPage.LoginUser.AccountString, Password = MainPage.LoginUser.Password };
|
var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj);
|
var revertObj = MainPage.RequestHttps ("Login", requestJson, false, false);
|
if (revertObj != null) {
|
Application.RunOnMainThread (() => {
|
if (revertObj.StateCode == "SUCCESS") {
|
var revertData = Newtonsoft.Json.JsonConvert.DeserializeObject<UserLoginRes> (revertObj.ResponseData.ToString ());
|
MainPage.LoginUser.AllVisionRegisterDevUserNameGuid = revertData.AllVisionRegisterDevUserNameGuid;
|
MainPage.LoginUser.LastTime = DateTime.Now;
|
MainPage.LoginUser.SaveUserInfo ();
|
} else if (!string.IsNullOrEmpty (revertObj.StateCode)) {
|
MainPage.LoginUser.LastTime = DateTime.Now.AddDays (-30);
|
MainPage.LoginUser.SaveUserInfo ();
|
new AccountLogin ().Show ();
|
}
|
});
|
}
|
} catch { } finally {
|
UserConfig.Instance.SaveUserConfig ();
|
}
|
});
|
if (isGuide) {
|
ShowRoomsView ();
|
}
|
}
|
UserConfig.Instance.SaveUserConfig ();
|
btnLinkStatus.MouseUpEventHandler += (dd, ff) => {
|
EquipmentPublicClass.CheckLinkRemote (UserConfig.Instance.internetStatus);
|
};
|
}
|
|
|
/// <summary>
|
/// 加载用户界面
|
/// </summary>
|
static void InitHomePageView ()
|
{
|
//SystemRemote.LinkRemote ("", "", "",true);
|
if (null != UserPageView.Parent) {
|
if (guidePageView.Parent != null) {
|
guidePageView.RemoveFromParent ();
|
}
|
CleanPageView (FavoriteBodyView);
|
UserPageView.AddChidren (FavoritePageView);
|
FavoritePageView.AddChidren (FavoriteBodyView);
|
FavoriteBodyView.AddChidren (FavoriteRoom);
|
FavoriteRoom.InitRoomView (Room.FavoriteRoom);
|
SelectedBottomButton (btnFavorite);
|
curPageView = 0;
|
|
return;
|
}
|
#if DEBUG
|
//UserConfig.Instance.SkinCode = 1;
|
Language.CurrentLanguage = "English";
|
//var lii = new LightLogic () { Type = DeviceType.LightRGB, LoopID = 1, DeviceID = 4, SubnetID = 42, Name = "RGB" };
|
//IO.FileUtils.SaveEquipmentMessage (lii, lii.LoopID.ToString ());
|
//var lii1 = new LightSwitch () { LoopID = 1, DeviceID = 6, SubnetID = 42, Name = "继电器" };
|
//IO.FileUtils.SaveEquipmentMessage (lii1, lii1.LoopID.ToString ());
|
//var lii11 = new LightDimming () { LoopID = 1, DeviceID = 9, SubnetID = 42, Name = "调光器" };
|
//IO.FileUtils.SaveEquipmentMessage (lii11, lii11.LoopID.ToString ());
|
//var lii111 = new LightDimming () { LoopID = 11, DeviceID = 9, SubnetID = 42, Name = "调光器2" };
|
//IO.FileUtils.SaveEquipmentMessage (lii111, lii111.LoopID.ToString ());
|
|
|
//var licci11 = new CurtainModel () { LoopID = 1, DeviceID = 9, SubnetID = 42, Name = "窗帘" };
|
//IO.FileUtils.SaveEquipmentMessage (licci11, licci11.LoopID.ToString ());
|
|
//var s1 = new LightEnergySocket () { LoopID = 1, DeviceID = 1, SubnetID = 44, Name = "EnergySocket" };
|
//IO.FileUtils.SaveEquipmentMessage (s1, s1.LoopID.ToString ());
|
|
//var s2 = new LightEnergySwitch () { LoopID = 11, DeviceID = 1, SubnetID = 44, Name = "EnergySwitch" };
|
//IO.FileUtils.SaveEquipmentMessage (s2, s2.LoopID.ToString ());
|
|
InfraredMode infraredMode = new InfraredMode () { LoopID = 1, SubnetID = 100, DeviceID = 12, InfraredType = InfraredType.TV, Name = "测试电视" };
|
IO.FileUtils.SaveEquipmentMessage (infraredMode, "1");
|
ACInfrared aCInfrared = new ACInfrared () { LoopID = 1, SubnetID = 100, DeviceID = 112, Name = "测试空调" };
|
IO.FileUtils.SaveEquipmentMessage (aCInfrared, "1");
|
//var fanM = new FanModule () { Name = "Fan Module",SubnetID = 2,DeviceID = 1,LoopID = 1};
|
//IO.FileUtils.SaveEquipmentMessage (fanM);
|
//var fanLoop1 = new FanModule () { Name = "Fan 1", SubnetID = 2, DeviceID = 1, LoopID = 1 };
|
//IO.FileUtils.SaveEquipmentMessage (fanLoop1, "1");
|
//var fanLoop2 = new FanModule () { Name = "Fan 2", SubnetID = 2, DeviceID = 1, LoopID = 2 };
|
//IO.FileUtils.SaveEquipmentMessage (fanLoop2, "2");
|
LightEnergySocket sddd = new LightEnergySocket () { LoopID = 1, SubnetID = 100, DeviceID = 122, Name = "测试插座" };
|
IO.FileUtils.SaveEquipmentMessage (sddd, "1");
|
|
//var ud = new UniversalDevice () { LoopID = 1,SubnetID = 42,DeviceID = 6,ActionType = 2,Name = "Universal-1",obj1 = 1,TargetType = 0};
|
//ud.SendBytes = new List<byte> () { 1 ,0};
|
//IO.FileUtils.SaveEquipmentMessage (ud, "1");
|
//var ud2 = new UniversalDevice () { LoopID = 2, SubnetID = 42, DeviceID = 6, ActionType = 0, Name = "Universal-2", obj1 = 1,TargetType = 1};
|
//ud2.SendBytes = new List<byte> () { 2 ,0};
|
//IO.FileUtils.SaveEquipmentMessage (ud2, "2");
|
//var ud3 = new UniversalDevice () { LoopID = 3, SubnetID = 42, DeviceID = 6, ActionType = 1, Name = "Universal-3", obj1 = 1 ,TargetType = 2};
|
//ud3.SendBytes = new List<byte> () { 3 ,0};
|
//IO.FileUtils.SaveEquipmentMessage (ud3, "3");
|
#endif
|
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);
|
SelectedBottomButton (btnFavorite);
|
curPageView = 0;
|
SharedMethod.SharedMethod.CurPageLayout = FavoritePageView;
|
};
|
|
btnDevice.MouseUpEventHandler += (sender, e) => {
|
try {
|
CleanPageView (DeviceBodyView);
|
UserPageView.AddChidren (DevicePageView);
|
DevicePageView.AddChidren (DeviceBodyView);
|
DeviceBodyView.AddChidren (DeviceView);
|
SelectedBottomButton (sender as Button);
|
UserDeviceView.DeviceMode ();
|
SharedMethod.SharedMethod.CurPageLayout = DevicePageView;
|
curPageView = 1;
|
} catch { } finally {
|
}
|
};
|
btnRoom.MouseUpEventHandler += (sender, e) => {
|
CleanPageView (RoomBodyView);
|
UserPageView.AddChidren (RoomPageView);
|
RoomPageView.AddChidren (RoomBodyView);
|
UserRooms.ShowRoomList ();
|
SelectedBottomButton (btnRoom);
|
curPageView = 2;
|
SharedMethod.SharedMethod.CurPageLayout = RoomPageView;
|
};
|
|
btnSetting.MouseUpEventHandler += (sender, e) => {
|
CleanPageView (SettingBodyView);
|
UserPageView.AddChidren (SettingPageView);
|
SettingPageView.AddChidren (SettingBodyView);
|
SettingBodyView.AddChidren (SettingView);
|
SettingBodyView.AddChidren (btnVersion);
|
SelectedBottomButton (btnSetting);
|
UserSettingView.InitUserSettingView ();
|
SettingPageView.PageIndex = 0;
|
curPageView = 3;
|
SharedMethod.SharedMethod.CurPageLayout = SettingPageView;
|
};
|
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 ShowSettingView ()
|
{
|
CleanPageView (SettingBodyView);
|
UserPageView.AddChidren (SettingPageView);
|
SettingPageView.AddChidren (SettingBodyView);
|
SettingBodyView.AddChidren (SettingView);
|
SettingBodyView.AddChidren (btnVersion);
|
SelectedBottomButton (btnSetting);
|
UserSettingView.InitUserSettingView ();
|
}
|
|
public static void ShowRoomsView ()
|
{
|
CleanPageView (RoomBodyView);
|
UserPageView.AddChidren (RoomPageView);
|
RoomPageView.AddChidren (RoomBodyView);
|
//UserMiddle.RoomBodyView.RemoveAll ();
|
UserRooms.ShowRoomList ();
|
SelectedBottomButton (btnRoom);
|
curPageView = 2;
|
}
|
|
public static void ReadAllDeviceStatus ()
|
{
|
if (MainPage.LoginUser == null || !MainPage.LoginUser.IsLogin) {
|
return;
|
}
|
UserDeviceToLight.readAllStatus (true);
|
UserDeviceToSocket.readAllStatus (true);
|
UserDeviceToAC.readAllStatus (true);
|
UserDeviceToFH.readAllStatus (true);
|
}
|
}
|
}
|