From c404f2f369710fe72bbcc4cff2b7b8a2c11b5ff1 Mon Sep 17 00:00:00 2001 From: 陈嘉乐 <cjl@hdlchina.com.cn> Date: 星期二, 02 三月 2021 17:48:32 +0800 Subject: [PATCH] Merge branch 'master' into wjc --- Crabtree/SmartHome/UI/SimpleControl/Phone/Alexa/AlexaSettingScenePage.cs | 555 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 555 insertions(+), 0 deletions(-) diff --git a/Crabtree/SmartHome/UI/SimpleControl/Phone/Alexa/AlexaSettingScenePage.cs b/Crabtree/SmartHome/UI/SimpleControl/Phone/Alexa/AlexaSettingScenePage.cs new file mode 100644 index 0000000..8493a99 --- /dev/null +++ b/Crabtree/SmartHome/UI/SimpleControl/Phone/Alexa/AlexaSettingScenePage.cs @@ -0,0 +1,555 @@ +锘縰sing System; +using System.Collections.Generic; +using Shared; + +namespace Shared.SimpleControl.Phone +{ + public class AlexaSettingScenePage : Dialog + { + Room room; + //List<string> showList = new List<string> (); + VerticalScrolViewLayout deviceScrolView; + VerticalScrolViewLayout typeLayout; + string selectedDeviceType = "Scene"; + + /// <summary> + /// 璁惧銆佸満鏅垪琛� + /// </summary> + List<TargetInfo> targetInfoList = new List<TargetInfo> (); + + + + int show = 99; + FrameLayout bodyView; + public AlexaSettingScenePage (List<TargetInfo> list) + { + targetInfoList = new List<TargetInfo>(list); + + bodyView = new FrameLayout () { + BackgroundColor = SkinStyle.Current.MainColor, + }; + AddChidren (bodyView); + } + + /// <summary> + /// + /// </summary> + /// <param name="action"></param> + /// <param name="saveAction"></param> + public void ShowPage (Action<List<TargetInfo>> saveAction) + { + #region ---TopView--- + var topView = new RowLayout () { + Y = Application.GetRealHeight (36), + Height = Application.GetRealHeight (90), + Width = Application.GetRealWidth (640), + BackgroundColor = SkinStyle.Current.MainColor, + }; + bodyView.AddChidren (topView); + + var back = new Button () { + Height = Application.GetRealHeight (90), + Width = Application.GetRealWidth (85), + UnSelectedImagePath = "Item/Back.png", + SelectedImagePath = "Item/BackSelected.png", + }; + topView.AddChidren (back); + back.MouseUpEventHandler += (sender, e) => { + this.Close (); + }; + + Button NameButton = new Button () { + Width = Application.GetRealWidth (400), + Height = Application.GetMinReal (90), + TextID = R.MyInternationalizationString.Scenes, + //Text = MainPage.SoftTitle, + SelectedTextColor = SkinStyle.Current.TextColor1, + TextColor = SkinStyle.Current.TextColor1, + Gravity = Gravity.CenterHorizontal, + TextAlignment = TextAlignment.Center, + TextSize = 19, + }; + topView.AddChidren (NameButton); + + #endregion + #region type view + var chooseTypeView = new RowLayout () { + Y = topView.Bottom, + Height = Application.GetRealHeight (110), + BackgroundColor = SkinStyle.Current.ViewColor, + }; + bodyView.AddChidren (chooseTypeView); + Button btnEquipmentIcon = new Button () { + Width = Application.GetRealHeight (65), + Height = Application.GetRealHeight (65), + UnSelectedImagePath = "Scene/Scene.png", + X = Application.GetRealWidth (30), + Gravity = Gravity.CenterVertical, + }; + chooseTypeView.AddChidren (btnEquipmentIcon); + Button btnDrodIcon = new Button () { + X = Application.GetRealWidth (540), + Height = Application.GetRealHeight (46), + Width = Application.GetRealWidth (47), + UnSelectedImagePath = "Item/Down.png", + SelectedImagePath = "Item/DownSelected.png", + Gravity = Gravity.CenterVertical, + }; + chooseTypeView.AddChidren (btnDrodIcon); + Button btnEquipmentType = new Button () { + Width = Application.GetRealHeight (460), + X = btnEquipmentIcon.Right + Application.GetRealWidth (20), + TextAlignment = TextAlignment.CenterLeft, + Text = Language.StringByID (R.MyInternationalizationString.Scenes), + TextColor = SkinStyle.Current.TextColor1, + SelectedTextColor = SkinStyle.Current.DialogTextColor + }; + chooseTypeView.AddChidren (btnEquipmentType); + typeLayout = new VerticalScrolViewLayout () { + Y = chooseTypeView.Bottom, + Height = Application.GetRealHeight (0), + BackgroundColor = SkinStyle.Current.ViewColor + }; + //EventHandler<MouseEventArgs> chooseTypeMethod = (sender, e) => { + // if (show == 99) {//绗竴娆¢渶瑕佸厛鍒濆鍖栭�夋嫨璁惧绫诲瀷鐣岄潰 + // InitEquipmentTypeView (btnEquipmentType, btnEquipmentIcon, chooseTypeView); + // show = 0; + // } else if (show == 0) { + // typeLayout.Height = Application.GetRealHeight (1136 - 126 - 90); + // chooseTypeView.BackgroundColor = SkinStyle.Current.MainColor; + // show = 1; + // } else if (show == 1) { + // typeLayout.Height = 0; + // chooseTypeView.BackgroundColor = SkinStyle.Current.ViewColor; + // show = 0; + // } + //}; + //btnEquipmentType.MouseUpEventHandler += chooseTypeMethod; + //btnDrodIcon.MouseUpEventHandler += chooseTypeMethod; + //chooseTypeView.MouseUpEventHandler += chooseTypeMethod; + #endregion + + deviceScrolView = new VerticalScrolViewLayout () { + Y = chooseTypeView.Bottom, + Height = Application.GetRealHeight (1136 - 126 - 110 - 89), + BackgroundColor = SkinStyle.Current.ViewColor, + }; + bodyView.AddChidren (deviceScrolView); + + + + var btnClose = new Button () { + Height = Application.GetRealHeight (90), + Y = deviceScrolView.Bottom, + BackgroundColor = SkinStyle.Current.MainColor, + //Text = "OK", + TextID = R.MyInternationalizationString.Confrim, + TextColor = SkinStyle.Current.TextColor1, + TextAlignment = TextAlignment.Center, + TextSize = 16, + }; + bodyView.AddChidren (btnClose); + btnClose.MouseUpEventHandler += (sender, e) => { + saveAction?.Invoke (targetInfoList); ; + this.Close (); + }; + + GetSceneList (); + } + + /// <summary> + /// + /// </summary> + void GetSceneList () { + System.Threading.Tasks.Task.Run (() => { + try { + Application.RunOnMainThread (() => { + MainPage.Loading.Start (Language.StringByID (R.MyInternationalizationString.load)); + }); + + var revertObj = HttpServerRequest.Current.GetSceneList (); + + if (revertObj.Code == StateCode.SUCCESS) { + var list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<HDLLinkSceneBase>> (revertObj.Data.ToString ()); + Application.RunOnMainThread (() => { + if (list != null && list.Count > 0) { + CommonConfig.Current.SceneList = list; + } else { + CommonConfig.Current.SceneList = new List<HDLLinkSceneBase> (); + } + CommonConfig.Current.Save (); + RefreshListView (); + }); + } else { + //鎻愮ず閿欒 + IMessageCommon.Current.ShowErrorInfoAlter (revertObj.Code); + } + } catch { + + } finally { + Application.RunOnMainThread (() => { + MainPage.Loading.Hide (); + }); + } + }); + } + + /// <summary> + /// + /// </summary> + void RefreshListView () + { + deviceScrolView.RemoveAll (); + foreach (HDLLinkSceneBase sceneBase in CommonConfig.Current.SceneList) { + AddRowView (sceneBase); + } + + } + + /// <summary> + /// + /// </summary> + /// <param name="sceneBase"></param> + void AddRowView (HDLLinkSceneBase sceneBase) { + + var deviceRow = new RowLayout () { + Height = Application.GetRealHeight (120), + }; + deviceScrolView.AddChidren (deviceRow); + + var btnPoint = new Button () { + Width = Application.GetMinRealAverage (10), + Height = Application.GetMinRealAverage (10), + Radius = (uint)Application.GetMinRealAverage (5), + X = Application.GetRealWidth (50), + Gravity = Gravity.CenterVertical, + BackgroundColor = SkinStyle.Current.TextColor1, + SelectedBackgroundColor = SkinStyle.Current.SelectedColor, + }; + deviceRow.AddChidren (btnPoint); + + Button btnEquipment = new Button () { + X = btnPoint.Right + Application.GetRealWidth (30), + Width = Application.GetRealWidth (310), + TextAlignment = TextAlignment.CenterLeft, + SelectedBackgroundColor = SkinStyle.Current.SelectedColor, + SelectedTextColor = SkinStyle.Current.DialogTextColor, + TextColor = SkinStyle.Current.TextColor1, + Text = sceneBase.name, + Tag = sceneBase.userSceneId, + }; + deviceRow.AddChidren (btnEquipment); + + + var btnChoose = new Button () { + X = Application.GetRealWidth (472 + 80), + Width = Application.GetMinRealAverage (75), + Height = Application.GetMinRealAverage (72), + Gravity = Gravity.CenterVertical, + UnSelectedImagePath = "CrabtreeAdd/Choose.png", + SelectedImagePath = "CrabtreeAdd/ChooseOn.png", + + }; + + deviceRow.AddChidren (btnChoose); + + var sceneData = targetInfoList.Find ((obj) => obj.targetId == sceneBase.userSceneId); + btnChoose.IsSelected = sceneData != null; + + + btnChoose.MouseUpEventHandler += (sendere, ee) => { + btnChoose.IsSelected = !btnChoose.IsSelected; + if (btnChoose.IsSelected) { + var sceneData = targetInfoList.Find ((obj) => obj.targetId == sceneBase.userSceneId); + if (sceneData == null) { + targetInfoList.Add (new TargetInfo () { + targetId = sceneBase.userSceneId, + targetName = sceneBase.name, + isDevice = false + }); + } + + } else { + var sceneData = targetInfoList.Find ((obj) => obj.targetId == sceneBase.userSceneId); + if (sceneData != null) { + targetInfoList.Remove (sceneData); + } + } + }; + } + + ///// <summary> + ///// 鏄剧ず鍦ㄦ湰鍦版壘鍒扮殑鎵�鏈夎澶� + ///// </summary> + //void InitDeviceList () + //{ + // deviceScrolView.RemoveAll (); + // System.Threading.Tasks.Task.Run (() => { + // //鎵惧嚭闇�瑕佹樉绀虹殑璁惧 + // var filesList = IO.FileUtils.ReadFiles ().FindAll ((obj) => { + // string [] str = obj.Split ('_'); + // return obj.StartsWith ("Equipment_") && str.Length == 5; + // }); + + // var globalSceneFileList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<string>> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (Scene.GlobalSceneFilePath))); + // if (globalSceneFileList == null) { + // globalSceneFileList = new List<string> (); + // } + // List<string> RoomsSceneFileList = new List<string> (); + // foreach (var r in Room.Lists) { + // if (string.IsNullOrEmpty (r.Name)) { + // continue; + // } + // if (r != null) { + // RoomsSceneFileList.AddRange (r.SceneFilePathList); + // } + // } + // List<SceneObj> TargetList = new List<SceneObj> (); + + // //if (selectedDeviceType == "Scene") { + // // if (string.IsNullOrEmpty (room.RoomFilePath) || room.RoomFilePath == Room.FavoriteRoom) { + // // //TargetList.AddRange (globalSceneFileList); + // // //TargetList.AddRange (RoomsSceneFileList); + // // } else { + // // Application.RunOnMainThread (() => { + // // new ScenePhoneMethod ().AddOrUpdataSceneBaseMassage (room.RoomFilePath); + // // }); + // // } + // //} + + // foreach (var list in globalSceneFileList) { + // var tempScene = Scene.GetSceneByFilePath (list); + // if (tempScene != null) { + + // TargetList.Add (new SceneObj () { Name = tempScene.Name, FilePath = list }); + // } + // } + + // foreach (var list in RoomsSceneFileList) { + // var tempScene = Scene.GetSceneByFilePath (list); + // if (tempScene != null) { + // TargetList.Add (new SceneObj () { Name = tempScene.Name, FilePath = list }); + // } + // } + + + + // //for (int i = 0; i < TargetList.Count;) { + // // var taget = TargetList [i]; + // // var tacount = TargetList.FindAll ((obj) => obj == taget).Count; + // // if (tacount == 1) { + // // i++; + // // } + // // while (tacount > 1) { + // // TargetList.Remove (taget); + // // tacount--; + // // } + // //} + + + // foreach (SceneObj mSceneObj in TargetList) { + // try { + // string [] str = mSceneObj.FilePath.Split ('_'); + + // var commonBytes = IO.FileUtils.ReadFile (mSceneObj.FilePath); + // if (commonBytes.Length == 0) { + // Shared.Utlis.WriteLine ("length loss"); + // continue; + // } + // if (commonBytes.Length == 1) { + // Shared.Utlis.WriteLine ("length loss 1"); + // continue; + // } + + + // //var deviceFilePath = filePath; + + // Common commonDevice = Newtonsoft.Json.JsonConvert.DeserializeObject<Common> (System.Text.Encoding.UTF8.GetString (commonBytes)); + // if (commonDevice.Type == DeviceType.OnePortBus || commonDevice.Type == DeviceType.OnePortWirelessFR || commonDevice.Type == DeviceType.OnePortMqttFR || commonDevice.Type == DeviceType.RCU + // || commonDevice.Type == DeviceType.A31MusicModel || commonDevice.Type == DeviceType.MusicA31) { + // continue; + // } + + // Application.RunOnMainThread (() => { + // var deviceRow = new RowLayout () { + // Height = Application.GetRealHeight (120), + // }; + // deviceScrolView.AddChidren (deviceRow); + + // var btnPoint = new Button () { + // Width = Application.GetMinRealAverage (10), + // Height = Application.GetMinRealAverage (10), + // Radius = (uint)Application.GetMinRealAverage (5), + // X = Application.GetRealWidth (50), + // Gravity = Gravity.CenterVertical, + // BackgroundColor = SkinStyle.Current.TextColor1, + // SelectedBackgroundColor = SkinStyle.Current.SelectedColor, + // }; + // deviceRow.AddChidren (btnPoint); + + // Button btnEquipment = new Button () { + // X = btnPoint.Right + Application.GetRealWidth (30), + // Width = Application.GetRealWidth (310), + // TextAlignment = TextAlignment.CenterLeft, + // SelectedBackgroundColor = SkinStyle.Current.SelectedColor, + // SelectedTextColor = SkinStyle.Current.DialogTextColor, + // TextColor = SkinStyle.Current.TextColor1, + // Text = commonDevice.Name, + // Tag = mSceneObj.FilePath, + // }; + // deviceRow.AddChidren (btnEquipment); + + + // var btnChoose = new Button () { + // X = Application.GetRealWidth (472 + 80), + // Width = Application.GetRealWidth (75), + // Height = Application.GetRealHeight (72), + // Gravity = Gravity.CenterVertical, + // UnSelectedImagePath = "CrabtreeAdd/Choose.png", + // SelectedImagePath = "CrabtreeAdd/ChooseOn.png", + // IsSelected = showList.Contains (mSceneObj.Name), + // Tag = mSceneObj.FilePath + // }; + // btnChoose.AddTag ("DeviceFilePath", mSceneObj.FilePath); + // deviceRow.AddChidren (btnChoose); + + // if (showList.Contains (mSceneObj.Name)) { + // //btnChoose.Enable = false; + // roomSceneFilePathList.Add (mSceneObj.FilePath); + // } + // // + + // btnChoose.MouseUpEventHandler += (sendere, ee) => { + // btnChoose.IsSelected = !btnChoose.IsSelected; + // if (btnChoose.IsSelected) { + // if (selectedDeviceType == "Scene") { + // roomSceneFilePathList.Add (mSceneObj.FilePath); + // } + + // showList.Add (mSceneObj.Name); + // } else { + // if (selectedDeviceType == "Scene") { + // roomSceneFilePathList.Remove (mSceneObj.FilePath); + // } + + // showList.Remove (mSceneObj.Name); + // } + // }; + // }); + // } catch (Exception ex) { + // Shared.Utlis.WriteLine (ex.Message); + // } + // } + // }); + //} + + void InitEquipmentTypeView (Button btnEquipmentType, Button btnEquipmentIcon, RowLayout chooseTypeView) + { + bodyView.AddChidren (typeLayout); + + //涓嬫媺鍒楄〃鐨勬暟鎹簮锛堥�夐」涓鸿澶囩被鍨嬫湁鍏筹級 + List<string> typeTemp = new List<string>{ + Language.StringByID(R.MyInternationalizationString.Scenes), + }; + + foreach (string typeName in typeTemp) { + var dialogRow = new RowLayout () { + Height = Application.GetRealHeight (110), + }; + typeLayout.AddChidren (dialogRow); + var btnPoint = new Button () { + Width = Application.GetMinRealAverage (10), + Height = Application.GetMinRealAverage (10), + Radius = (uint)Application.GetMinRealAverage (5), + X = Application.GetRealWidth (70), + Gravity = Gravity.CenterVertical, + BackgroundColor = SkinStyle.Current.TextColor1, + SelectedBackgroundColor = SkinStyle.Current.SelectedColor, + }; + dialogRow.AddChidren (btnPoint); + + Button btnTypeName = new Button () { + Width = Application.GetRealHeight (400), + X = btnPoint.Right + Application.GetRealWidth (30), + Text = typeName, + TextAlignment = TextAlignment.CenterLeft, + TextColor = SkinStyle.Current.TextColor1 + }; + dialogRow.AddChidren (btnTypeName); + EventHandler<MouseEventArgs> typeEvent = (sender1, e1) => { + typeLayout.Height = 0; + btnEquipmentType.Text = typeName; + //if (typeName == Language.StringByID (R.MyInternationalizationString.Lights)) { + // btnEquipmentIcon.UnSelectedImagePath = "Item/Light.png"; + // selectedDeviceType = "Light"; + //} else if (typeName == Language.StringByID (R.MyInternationalizationString.Curtains)) { + // btnEquipmentIcon.UnSelectedImagePath = "Curtain/Curtain.png"; + // selectedDeviceType = "Curtain"; + //} else if (typeName == Language.StringByID (R.MyInternationalizationString.AC)) { + // btnEquipmentIcon.UnSelectedImagePath = "AC/AC.png"; + // selectedDeviceType = "AC"; + //} else if (typeName == Language.StringByID (R.MyInternationalizationString.FoolHeat)) { + // btnEquipmentIcon.UnSelectedImagePath = "Item/FloorHeating.png"; + // selectedDeviceType = "FoolHeat"; + //} else if (typeName == Language.StringByID (R.MyInternationalizationString.DryContactPanel)) { + // btnEquipmentIcon.UnSelectedImagePath = "Item/DryContact.png"; + // selectedDeviceType = "DryContact"; + //} else if (typeName == Language.StringByID (R.MyInternationalizationString.MusicModel)) { + // btnEquipmentIcon.UnSelectedImagePath = "Item/Music.png"; + // selectedDeviceType = "Music"; + //} else if (typeName == Language.StringByID (R.MyInternationalizationString.InfraredMode)) { + // btnEquipmentIcon.UnSelectedImagePath = "Item/InfraredTV.png"; + // selectedDeviceType = "InfraredMode"; + //} else if (typeName == Language.StringByID (R.MyInternationalizationString.TV)) { + // btnEquipmentIcon.UnSelectedImagePath = "Item/InfraredTV.png"; + // selectedDeviceType = "InfraredMode"; + //} else if (typeName == Language.StringByID (R.MyInternationalizationString.ElectricalControl)) { + // btnEquipmentIcon.UnSelectedImagePath = "Light/Socket.png"; + // selectedDeviceType = "EC";//鐢靛櫒鎺у埗 + //} else if (typeName == Language.StringByID (R.MyInternationalizationString.Fan)) { + // btnEquipmentIcon.UnSelectedImagePath = "Fan/Fan.png"; + // selectedDeviceType = "Fan"; + // //} else if (typeName == Language.StringByID (R.MyInternationalizationString.LogicModule)) { + // // btnEquipmentIcon.UnSelectedImagePath = "Item/PointBig.png"; + // // selectedDeviceType = "LogicModule"; + //} else + if (typeName == Language.StringByID (R.MyInternationalizationString.Scenes)) { + btnEquipmentIcon.UnSelectedImagePath = "Scene/Scene.png"; + selectedDeviceType = "Scene"; + } + //else if (typeName == Language.StringByID (R.MyInternationalizationString.UniversalDevice)) { + // btnEquipmentIcon.UnSelectedImagePath = "UniversalDevice/UniversalDevice.png"; + // selectedDeviceType = "UniversalDevice"; + //} else if (typeName == Language.StringByID (R.MyInternationalizationString.Sensor)) { + // btnEquipmentIcon.UnSelectedImagePath = "UniversalDevice/UniversalDevice.png"; + // selectedDeviceType = "Sensor"; + //} else if (typeName == Language.StringByID (R.MyInternationalizationString.FreshAir)) { + // btnEquipmentIcon.UnSelectedImagePath = "FreshAir/FreshAir.png"; + // selectedDeviceType = "FreshAir"; + //} + else { + btnEquipmentIcon.UnSelectedImagePath = "Item/LogicModule.png"; + selectedDeviceType = "All"; + } + chooseTypeView.BackgroundColor = SkinStyle.Current.ViewColor; + GetSceneList (); + }; + dialogRow.MouseUpEventHandler += typeEvent; + btnTypeName.MouseUpEventHandler += typeEvent; + } + } + } + + + public class SceneObj + { + /// <summary> + /// 璺緞 + /// </summary> + public string FilePath; + /// <summary> + /// 鍦烘櫙Name + /// </summary> + public string Name; + } +} -- Gitblit v1.8.0