New file |
| | |
| | | using System; |
| | | using HDL_ON.UI.CSS; |
| | | using Shared; |
| | | using HDL_ON.Entity; |
| | | using System.Collections.Generic; |
| | | using System.Threading; |
| | | using HDL_ON.DAL.Server; |
| | | |
| | | namespace HDL_ON.UI |
| | | { |
| | | public partial class SceneAddPage : FrameLayout |
| | | { |
| | | FrameLayout bodyView; |
| | | /// <summary> |
| | | /// 场景背景显示区域 |
| | | /// </summary> |
| | | ImageView addSceneImageView; |
| | | /// <summary> |
| | | /// 场景功能列表显示区域 |
| | | /// </summary> |
| | | VerticalScrolViewLayout functionListView; |
| | | /// <summary> |
| | | /// 场景名称row |
| | | /// </summary> |
| | | FrameLayout sceneNameView; |
| | | |
| | | /// <summary> |
| | | /// 场景名称显示文本 |
| | | /// </summary> |
| | | Button btnSceneName; |
| | | /// <summary> |
| | | /// 场景名称修改图标 |
| | | /// </summary> |
| | | Button btnEditSceneNameIcon; |
| | | |
| | | /// <summary> |
| | | /// 所属区域row |
| | | /// </summary> |
| | | FrameLayout belongToZoneRow; |
| | | Button btnBelongToZoneRight; |
| | | Button btnZoneName; |
| | | |
| | | Button btnAddFunctionTitle; |
| | | /// <summary> |
| | | /// 底部完成按钮 |
| | | /// </summary> |
| | | Button btnComplete; |
| | | |
| | | |
| | | #region 图标选择部分图标 |
| | | /// <summary> |
| | | /// 背景图选项区域 |
| | | /// </summary> |
| | | FrameLayout pictureOptionView; |
| | | /// <summary> |
| | | /// 背景图选项选择区域 |
| | | /// </summary> |
| | | VerticalScrolViewLayout optionView; |
| | | /// <summary> |
| | | /// 默认图库按钮 |
| | | /// </summary> |
| | | Button btnDefaultGallery; |
| | | /// <summary> |
| | | /// 拍照按钮 |
| | | /// </summary> |
| | | Button btnTakePicture; |
| | | /// <summary> |
| | | /// 相册按钮 |
| | | /// </summary> |
| | | Button btnAlbum; |
| | | /// <summary> |
| | | /// 取消按钮 |
| | | /// </summary> |
| | | Button btnCancel; |
| | | #endregion |
| | | |
| | | Scene scene; |
| | | |
| | | /// <summary> |
| | | /// 更新功能row |
| | | /// </summary> |
| | | Action refreshFunctionRowAction; |
| | | /// <summary> |
| | | /// 回掉更新 |
| | | /// </summary> |
| | | Action backAction; |
| | | public SceneAddPage(Scene s, Action act) |
| | | { |
| | | bodyView = this; |
| | | scene = s; |
| | | backAction = act; |
| | | |
| | | refreshFunctionRowAction = () => { |
| | | LoadFunctionRow(functionListView); |
| | | }; |
| | | } |
| | | |
| | | public void LoadPage() |
| | | { |
| | | new TopViewDiv(bodyView, Language.StringByID(StringId.NewScene)).LoadTopView(); |
| | | |
| | | bodyView.BackgroundColor = CSS_Color.MainBackgroundColor; |
| | | |
| | | var contentView = new VerticalScrolViewLayout() |
| | | { |
| | | Y = Application.GetRealHeight(64), |
| | | Height = Application.GetRealHeight(603 - 50), |
| | | }; |
| | | bodyView.AddChidren(contentView); |
| | | contentView.AddChidren(new Button() { Height = Application.GetRealWidth(12) }); |
| | | |
| | | var sceneBgView = new FrameLayout() |
| | | { |
| | | Gravity = Gravity.CenterHorizontal, |
| | | Width = Application.GetRealWidth(252), |
| | | Height = Application.GetRealWidth(188 + 24), |
| | | Radius = (uint)Application.GetRealWidth(12), |
| | | BackgroundColor = CSS_Color.MainBackgroundColor, |
| | | }; |
| | | contentView.AddChidren(sceneBgView); |
| | | |
| | | addSceneImageView = new ImageView() |
| | | { |
| | | Gravity = Gravity.CenterHorizontal, |
| | | Height = Application.GetRealWidth(184), |
| | | Radius = (uint)Application.GetRealWidth(12), |
| | | //ImagePath = scene.ImagePath |
| | | }; |
| | | sceneBgView.AddChidren(addSceneImageView); |
| | | |
| | | //2020-12-03 修改图片加载方法 |
| | | ImageUtlis.Current.LoadLocalOrNetworkImages(scene.ImagePath, addSceneImageView); |
| | | |
| | | #region 场景名称row |
| | | sceneNameView = new FrameLayout() |
| | | { |
| | | Height = Application.GetRealWidth(50), |
| | | }; |
| | | contentView.AddChidren(sceneNameView); |
| | | |
| | | Button btnSceneTitle = new Button() |
| | | { |
| | | X = Application.GetRealWidth(16), |
| | | Width = Application.GetRealWidth(90), |
| | | TextAlignment = TextAlignment.CenterLeft, |
| | | TextColor = CSS_Color.FirstLevelTitleColor, |
| | | TextSize = CSS_FontSize.TextFontSize, |
| | | TextID = StringId.SceneName, |
| | | }; |
| | | sceneNameView.AddChidren(btnSceneTitle); |
| | | |
| | | btnEditSceneNameIcon = new Button() |
| | | { |
| | | X = Application.GetRealWidth(333), |
| | | Gravity = Gravity.CenterVertical, |
| | | Width = Application.GetMinRealAverage(28), |
| | | Height = Application.GetMinRealAverage(28), |
| | | UnSelectedImagePath = "Public/EditIcon.png", |
| | | }; |
| | | sceneNameView.AddChidren(btnEditSceneNameIcon); |
| | | |
| | | btnSceneName = new Button() |
| | | { |
| | | X = Application.GetRealWidth(100), |
| | | Width = Application.GetRealWidth(230), |
| | | TextAlignment = TextAlignment.CenterRight, |
| | | TextColor = CSS_Color.PromptingColor1, |
| | | TextSize = CSS_FontSize.TextFontSize, |
| | | Text = scene.name |
| | | }; |
| | | sceneNameView.AddChidren(btnSceneName); |
| | | |
| | | Button btnSceneNameLine = new Button() |
| | | { |
| | | Y = Application.GetRealWidth(49), |
| | | Gravity = Gravity.CenterHorizontal, |
| | | Height = Application.GetRealHeight(1), |
| | | Width = Application.GetRealWidth(343), |
| | | BackgroundColor = CSS_Color.DividingLineColor, |
| | | }; |
| | | sceneNameView.AddChidren(btnSceneNameLine); |
| | | #endregion |
| | | |
| | | #region 所属区域row |
| | | belongToZoneRow = new FrameLayout() |
| | | { |
| | | Y = sceneNameView.Bottom, |
| | | Height = Application.GetRealWidth(50), |
| | | }; |
| | | contentView.AddChidren(belongToZoneRow); |
| | | |
| | | Button btnBelongToTitle = new Button() |
| | | { |
| | | X = Application.GetRealWidth(16), |
| | | Width = Application.GetRealWidth(90), |
| | | TextAlignment = TextAlignment.CenterLeft, |
| | | TextColor = CSS_Color.FirstLevelTitleColor, |
| | | TextSize = CSS_FontSize.TextFontSize, |
| | | TextID = StringId.BelongToZone, |
| | | }; |
| | | belongToZoneRow.AddChidren(btnBelongToTitle); |
| | | |
| | | btnBelongToZoneRight = new Button() |
| | | { |
| | | X = Application.GetRealWidth(339), |
| | | Gravity = Gravity.CenterVertical, |
| | | Width = Application.GetMinRealAverage(16), |
| | | Height = Application.GetMinRealAverage(16), |
| | | UnSelectedImagePath = "Public/Right.png", |
| | | }; |
| | | belongToZoneRow.AddChidren(btnBelongToZoneRight); |
| | | |
| | | btnZoneName = new Button() |
| | | { |
| | | X = Application.GetRealWidth(100), |
| | | Width = Application.GetRealWidth(230), |
| | | TextAlignment = TextAlignment.CenterRight, |
| | | TextColor = CSS_Color.PromptingColor1, |
| | | TextSize = CSS_FontSize.TextFontSize, |
| | | Text = scene.GetRoomListName() == "" ? Language.StringByID(StringId.WholeHouseScene) : scene.GetRoomListName() |
| | | }; |
| | | belongToZoneRow.AddChidren(btnZoneName); |
| | | |
| | | contentView.AddChidren(new Button() |
| | | { |
| | | Y = belongToZoneRow.Bottom, |
| | | Height = Application.GetRealHeight(8), |
| | | BackgroundColor = CSS_Color.DividingLineColor, |
| | | }); |
| | | #endregion |
| | | |
| | | #region 场景延时row |
| | | if (DB_ResidenceData.Instance.GatewayType == 1) |
| | | { |
| | | FrameLayout sceneDelayRow = new FrameLayout() |
| | | { |
| | | Y = sceneNameView.Bottom, |
| | | Height = Application.GetRealWidth(50), |
| | | }; |
| | | contentView.AddChidren(sceneDelayRow); |
| | | |
| | | Button btnSceneDelayRight = new Button() |
| | | { |
| | | X = Application.GetRealWidth(339), |
| | | Gravity = Gravity.CenterVertical, |
| | | Width = Application.GetMinRealAverage(16), |
| | | Height = Application.GetMinRealAverage(16), |
| | | UnSelectedImagePath = "Public/Right.png", |
| | | }; |
| | | sceneDelayRow.AddChidren(btnSceneDelayRight); |
| | | |
| | | var btnSceneDelayInfo = new Button() |
| | | { |
| | | Width = Application.GetRealWidth(327), |
| | | TextAlignment = TextAlignment.CenterRight, |
| | | TextColor = CSS_Color.PromptingColor1, |
| | | TextSize = CSS_FontSize.PromptFontSize_FirstLevel, |
| | | Text = scene.delayText |
| | | }; |
| | | sceneDelayRow.AddChidren(btnSceneDelayInfo); |
| | | |
| | | Button btnSceneDelayTitle = new Button() |
| | | { |
| | | X = Application.GetRealWidth(16), |
| | | //Width = Application.GetRealWidth(90), |
| | | TextAlignment = TextAlignment.CenterLeft, |
| | | TextColor = CSS_Color.FirstLevelTitleColor, |
| | | TextSize = CSS_FontSize.TextFontSize, |
| | | TextID = StringId.SceneDelay, |
| | | }; |
| | | sceneDelayRow.AddChidren(btnSceneDelayTitle); |
| | | |
| | | |
| | | btnSceneDelayTitle.MouseUpEventHandler = (sender, e) => |
| | | { |
| | | new PublicAssmebly().SetSceneDelayDialog(scene, btnSceneDelayInfo); |
| | | }; |
| | | |
| | | contentView.AddChidren(new Button() |
| | | { |
| | | Y = sceneDelayRow.Bottom, |
| | | Height = Application.GetRealHeight(8), |
| | | BackgroundColor = CSS_Color.DividingLineColor, |
| | | }); |
| | | } |
| | | #endregion |
| | | |
| | | #region 添加功能row |
| | | FrameLayout addFunctionRow = new FrameLayout() |
| | | { |
| | | Height = Application.GetRealWidth(44), |
| | | }; |
| | | contentView.AddChidren(addFunctionRow); |
| | | |
| | | Button btnAddIcon = new Button() |
| | | { |
| | | X = Application.GetRealWidth(333), |
| | | Gravity = Gravity.CenterVertical, |
| | | Width = Application.GetMinRealAverage(28), |
| | | Height = Application.GetMinRealAverage(28), |
| | | UnSelectedImagePath = "Public/AddIcon.png", |
| | | }; |
| | | addFunctionRow.AddChidren(btnAddIcon); |
| | | |
| | | btnAddFunctionTitle = new Button() |
| | | { |
| | | X = Application.GetRealWidth(16), |
| | | TextAlignment = TextAlignment.CenterLeft, |
| | | TextColor = CSS_Color.MainColor, |
| | | TextSize = CSS_FontSize.SubheadingFontSize, |
| | | TextID = StringId.AddFunction, |
| | | IsBold = true, |
| | | }; |
| | | addFunctionRow.AddChidren(btnAddFunctionTitle); |
| | | |
| | | functionListView = new VerticalScrolViewLayout() |
| | | { |
| | | Height = 0, |
| | | }; |
| | | contentView.AddChidren(functionListView); |
| | | |
| | | LoadFunctionRow(functionListView); |
| | | |
| | | Button btnLine1 = new Button() |
| | | { |
| | | //Y = sceneDelayRow.Bottom, |
| | | Height = Application.GetRealHeight(8), |
| | | BackgroundColor = CSS_Color.DividingLineColor, |
| | | }; |
| | | contentView.AddChidren(btnLine1); |
| | | |
| | | Button btnLine2 = new Button() |
| | | { |
| | | //Y = sceneDelayRow.Bottom, |
| | | Height = Application.GetRealHeight(228), |
| | | BackgroundColor = CSS_Color.DividingLineColor, |
| | | }; |
| | | contentView.AddChidren(btnLine2); |
| | | #endregion |
| | | |
| | | Button btnBottomLine = new Button() |
| | | { |
| | | Y = Application.GetRealHeight(667 - 50) - 1, |
| | | Height = 1, |
| | | BackgroundColor = CSS_Color.DividingLineColor, |
| | | }; |
| | | bodyView.AddChidren(btnBottomLine); |
| | | |
| | | btnComplete = new Button() |
| | | { |
| | | Y = Application.GetRealHeight(667 - 50), |
| | | Height = Application.GetRealHeight(50), |
| | | TextAlignment = TextAlignment.Center, |
| | | TextColor = CSS_Color.MainColor, |
| | | TextSize = CSS_FontSize.SubheadingFontSize, |
| | | TextID = StringId.Complete, |
| | | BackgroundColor = CSS_Color.MainBackgroundColor, |
| | | //IsBold = true |
| | | }; |
| | | bodyView.AddChidren(btnComplete); |
| | | |
| | | LoadEventList(); |
| | | } |
| | | /// <summary> |
| | | /// 加载功能列表 |
| | | /// </summary> |
| | | void LoadFunctionRow(VerticalScrolViewLayout functionListView) |
| | | { |
| | | functionListView.RemoveAll(); |
| | | functionListView.Height = Application.GetRealWidth(65 * scene.functions.Count); |
| | | foreach (var scenefunction in scene.functions) |
| | | { |
| | | var row = new RowLayout() |
| | | { |
| | | Height = Application.GetRealWidth(65), |
| | | BackgroundColor = CSS_Color.MainBackgroundColor, |
| | | LineColor = 0x00000000 |
| | | }; |
| | | functionListView.AddChidren(row); |
| | | |
| | | row.AddChidren(new Button() |
| | | { |
| | | Gravity = Gravity.CenterHorizontal, |
| | | Width = Application.GetRealWidth(343), |
| | | Height = Application.GetRealWidth(1), |
| | | BackgroundColor = CSS_Color.DividingLineColor, |
| | | }); |
| | | Button btnRight = new Button() |
| | | { |
| | | X = Application.GetRealWidth(339), |
| | | Gravity = Gravity.CenterVertical, |
| | | Width = Application.GetMinRealAverage(16), |
| | | Height = Application.GetMinRealAverage(16), |
| | | UnSelectedImagePath = "Public/Right.png", |
| | | }; |
| | | row.AddChidren(btnRight); |
| | | |
| | | var btnFunctionInfo = new Button() |
| | | { |
| | | Width = Application.GetRealWidth(327), |
| | | Height = Application.GetRealWidth(32), |
| | | TextAlignment = TextAlignment.BottomRight, |
| | | TextColor = CSS_Color.FirstLevelTitleColor, |
| | | TextSize = CSS_FontSize.PromptFontSize_FirstLevel, |
| | | Text = GetFunctionScnenInfo(scenefunction), |
| | | }; |
| | | row.AddChidren(btnFunctionInfo); |
| | | |
| | | var btnFunctionDelayInfo = new Button() |
| | | { |
| | | Width = Application.GetRealWidth(327), |
| | | Y = Application.GetRealWidth(35), |
| | | Height = Application.GetRealWidth(32), |
| | | TextAlignment = TextAlignment.TopRight, |
| | | TextColor = CSS_Color.PromptingColor1, |
| | | TextSize = CSS_FontSize.PromptFontSize_FirstLevel, |
| | | }; |
| | | row.AddChidren(btnFunctionDelayInfo); |
| | | |
| | | if (Convert.ToInt32(scenefunction.delay) > 0) |
| | | { |
| | | btnFunctionDelayInfo.Text = Language.StringByID(StringId.Delay) + " " + scenefunction.localFunction.delayText; |
| | | } |
| | | else |
| | | { |
| | | btnFunctionDelayInfo.Text = Language.StringByID(StringId.NoDelay); |
| | | } |
| | | |
| | | var btnFunctionName = new Button() |
| | | { |
| | | X = Application.GetRealWidth(16), |
| | | Height = Application.GetRealWidth(44), |
| | | TextAlignment = TextAlignment.CenterLeft, |
| | | TextColor = CSS_Color.FirstLevelTitleColor, |
| | | TextSize = CSS_FontSize.TextFontSize, |
| | | Text = scenefunction.localFunction.name, |
| | | }; |
| | | row.AddChidren(btnFunctionName); |
| | | |
| | | var btnFunctionFloorAndRoom = new Button() |
| | | { |
| | | X = Application.GetRealWidth(16), |
| | | Y = Application.GetRealWidth(24), |
| | | Height = Application.GetRealWidth(41), |
| | | TextAlignment = TextAlignment.CenterLeft, |
| | | TextColor = CSS_Color.PromptingColor1, |
| | | TextSize = CSS_FontSize.TextFontSize, |
| | | Text = scenefunction.localFunction.GetRoomListName(), |
| | | }; |
| | | row.AddChidren(btnFunctionFloorAndRoom); |
| | | |
| | | btnFunctionName.MouseUpEventHandler = (sender, e) => |
| | | { |
| | | var ssf = new SceneFunctionInfoEditPage(scene, scenefunction, refreshFunctionRowAction); |
| | | MainPage.BasePageView.AddChidren(ssf); |
| | | ssf.LoadPage(); |
| | | MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1; |
| | | }; |
| | | btnFunctionFloorAndRoom.MouseUpEventHandler = (sender, e) => |
| | | { |
| | | var ssf = new SceneFunctionInfoEditPage(scene, scenefunction, refreshFunctionRowAction); |
| | | MainPage.BasePageView.AddChidren(ssf); |
| | | ssf.LoadPage(); |
| | | MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1; |
| | | }; |
| | | |
| | | Button btnDelSceneFunction = new Button() |
| | | { |
| | | BackgroundColor = CSS_Color.WarningColor, |
| | | TextColor = CSS_Color.MainBackgroundColor, |
| | | TextID = StringId.Del, |
| | | }; |
| | | row.AddRightView(btnDelSceneFunction); |
| | | btnDelSceneFunction.MouseUpEventHandler = (sender, e) => { |
| | | scene.functions.Remove(scenefunction); |
| | | scene.SaveSceneData(true); |
| | | row.RemoveFromParent(); |
| | | functionListView.Height = Application.GetRealWidth(65 * scene.functions.Count); |
| | | }; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 解析场景功能数据 |
| | | /// </summary> |
| | | /// <param name="sceneFunction"></param> |
| | | string GetFunctionScnenInfo(SceneFunction sceneFunction) |
| | | { |
| | | var sceneFunctionInfo = ""; |
| | | foreach (var sfs in sceneFunction.status) |
| | | { |
| | | if (sfs.key == FunctionAttributeKey.OnOff) |
| | | { |
| | | if (sfs.value == "off") |
| | | return Language.StringByID(StringId.Close); |
| | | } |
| | | } |
| | | |
| | | if (sceneFunction.status.Count == 0) |
| | | { |
| | | return sceneFunctionInfo += Language.StringByID(StringId.Open); |
| | | } |
| | | |
| | | var modeState = sceneFunction.status.Find((obj) => obj.key == FunctionAttributeKey.Mode); |
| | | var tempState = sceneFunction.status.Find((obj) => obj.key == FunctionAttributeKey.SetTemp); |
| | | var fanState = sceneFunction.status.Find((obj) => obj.key == FunctionAttributeKey.FanSpeed); |
| | | if (modeState != null) |
| | | { |
| | | sceneFunctionInfo += FunctionList.List.GetValueText(modeState.key, modeState.value); |
| | | } |
| | | if (tempState != null) |
| | | { |
| | | sceneFunctionInfo += FunctionList.List.GetValueText(tempState.key, tempState.value); |
| | | sceneFunctionInfo += FunctionList.List.GetUintString(tempState.key); |
| | | } |
| | | if (fanState != null) |
| | | { |
| | | sceneFunctionInfo += FunctionList.List.GetValueText(fanState.key, fanState.value); |
| | | } |
| | | var briState = sceneFunction.status.Find((obj) => obj.key == FunctionAttributeKey.Brightness); |
| | | if (briState != null) |
| | | { |
| | | sceneFunctionInfo += Language.StringByID(StringId.Open) + " " + sceneFunction.localFunction.attributes.Find((obj) => obj.key == "brightness").curValue.ToString() + "%"; |
| | | } |
| | | else |
| | | { |
| | | sceneFunctionInfo += Language.StringByID(StringId.Open); |
| | | } |
| | | var perState = sceneFunction.status.Find((obj) => obj.key == FunctionAttributeKey.Percent); |
| | | if (perState != null) |
| | | { |
| | | sceneFunctionInfo += Language.StringByID(StringId.Open) + " " + sceneFunction.localFunction.attributes.Find((obj) => obj.key == "brightness").curValue.ToString() + "%"; |
| | | } |
| | | else |
| | | { |
| | | sceneFunctionInfo += Language.StringByID(StringId.Open); |
| | | } |
| | | |
| | | //FunctionAttributes perTrait; |
| | | |
| | | //switch (sceneFunction.localFunction.functionType) |
| | | //{ |
| | | //case FunctionType.AC: |
| | | //var acMode = sceneFunction.status.Find((obj) => obj.key == FunctionAttributeKey.Mode); |
| | | //var acTemp = sceneFunction.status.Find((obj) => obj.key == FunctionAttributeKey.SetTemp); |
| | | //var acFan = sceneFunction.status.Find((obj) => obj.key == FunctionAttributeKey.FanSpeed); |
| | | //if (acMode != null) |
| | | //{ |
| | | // sceneFunctionInfo += FunctionList.List.GetValueText(acMode.key, acMode.value); |
| | | //} |
| | | //if (acTemp != null) |
| | | //{ |
| | | // sceneFunctionInfo += FunctionList.List.GetValueText(acTemp.key, acTemp.value); |
| | | // sceneFunctionInfo += FunctionList.List.GetUintString(acTemp.key); |
| | | //} |
| | | //if (acFan!=null) |
| | | //{ |
| | | // sceneFunctionInfo += FunctionList.List.GetValueText(acFan.key, acFan.value); |
| | | //} |
| | | // break; |
| | | //case FunctionType.FloorHeating: |
| | | //sceneFunctionInfo += sceneFunction.localFunction.attributes.Find((obj) => obj.key == "mode").GetCurValueText(); |
| | | //sceneFunctionInfo += " " + sceneFunction.localFunction.attributes.Find((obj) => obj.key == "set_temp").curValue.ToString() + |
| | | // sceneFunction.localFunction.attributes.Find((obj) => obj.key == "set_temp").uintString; |
| | | //break; |
| | | //case FunctionType.Dimmer: |
| | | //perTrait = sceneFunction.localFunction.attributes.Find((obj) => obj.key == "brightness"); |
| | | //if (perTrait != null) |
| | | //{ |
| | | // sceneFunctionInfo += Language.StringByID(StringId.Open) + " " + sceneFunction.localFunction.attributes.Find((obj) => obj.key == "brightness").curValue.ToString() + "%"; |
| | | //} |
| | | //else |
| | | //{ |
| | | // sceneFunctionInfo += Language.StringByID(StringId.Open); |
| | | //} |
| | | //break; |
| | | //case FunctionType.Relay: |
| | | // sceneFunctionInfo += Language.StringByID(StringId.Open); |
| | | // break; |
| | | //case FunctionType.RGB: |
| | | // perTrait = sceneFunction.localFunction.attributes.Find((obj) => obj.key == "percent"); |
| | | // if (perTrait != null) |
| | | // { |
| | | // sceneFunctionInfo += Language.StringByID(StringId.Open) + " " + sceneFunction.localFunction.attributes.Find((obj) => obj.key == "brightness").curValue.ToString() + "%"; |
| | | // } |
| | | // else |
| | | // { |
| | | // sceneFunctionInfo += Language.StringByID(StringId.Open); |
| | | // } |
| | | // break; |
| | | //case FunctionType.Curtain: |
| | | // sceneFunctionInfo += Language.StringByID(StringId.Open); |
| | | // break; |
| | | //case FunctionType.MotorCurtain: |
| | | // perTrait = sceneFunction.localFunction.attributes.Find((obj) => obj.key == "percent"); |
| | | // if (perTrait != null) |
| | | // { |
| | | // sceneFunctionInfo += Language.StringByID(StringId.Open) + " " + sceneFunction.localFunction.attributes.Find((obj) => obj.key == "percent").curValue.ToString() + "%"; |
| | | // } |
| | | // else |
| | | // { |
| | | // sceneFunctionInfo += Language.StringByID(StringId.Open); |
| | | // } |
| | | // break; |
| | | //} |
| | | return sceneFunctionInfo; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 加载图标选择选项 |
| | | /// </summary> |
| | | void LoadPictureOptionView() |
| | | { |
| | | var pView = new FrameLayout() |
| | | { |
| | | BackgroundColor = CSS_Color.DialogTransparentColor1, |
| | | }; |
| | | bodyView.AddChidren(pView); |
| | | |
| | | pictureOptionView = new FrameLayout() |
| | | { |
| | | Y = Application.GetRealHeight(445), |
| | | Height = Application.GetRealHeight(250), |
| | | AnimateSpeed = 0.3f, |
| | | Animate = Animate.DownToUp, |
| | | }; |
| | | pView.AddChidren(pictureOptionView); |
| | | |
| | | optionView = new VerticalScrolViewLayout() |
| | | { |
| | | Gravity = Gravity.CenterHorizontal, |
| | | Width = Application.GetRealWidth(343), |
| | | Height = Application.GetRealHeight(150), |
| | | BackgroundColor = CSS_Color.MainBackgroundColor, |
| | | Radius = (uint)Application.GetRealWidth(12), |
| | | }; |
| | | pictureOptionView.AddChidren(optionView); |
| | | |
| | | btnDefaultGallery = new Button() |
| | | { |
| | | Height = Application.GetRealHeight(50), |
| | | TextAlignment = TextAlignment.Center, |
| | | TextColor = CSS_Color.TextualColor, |
| | | SelectedTextColor = CSS_Color.MainColor, |
| | | TextSize = CSS_FontSize.SubheadingFontSize, |
| | | TextID = StringId.DefaultGallery, |
| | | }; |
| | | optionView.AddChidren(btnDefaultGallery); |
| | | |
| | | optionView.AddChidren(new Button() { Height = Application.GetRealHeight(1), Width = Application.GetRealWidth(343), BackgroundColor = CSS_Color.DividingLineColor }); |
| | | |
| | | btnTakePicture = new Button() |
| | | { |
| | | Height = Application.GetRealHeight(50), |
| | | TextAlignment = TextAlignment.Center, |
| | | TextColor = CSS_Color.TextualColor, |
| | | SelectedTextColor = CSS_Color.MainColor, |
| | | TextSize = CSS_FontSize.SubheadingFontSize, |
| | | TextID = StringId.TakePicture, |
| | | }; |
| | | optionView.AddChidren(btnTakePicture); |
| | | |
| | | optionView.AddChidren(new Button() { Height = Application.GetRealHeight(1), Width = Application.GetRealWidth(343), BackgroundColor = CSS_Color.DividingLineColor }); |
| | | |
| | | btnAlbum = new Button() |
| | | { |
| | | Height = Application.GetRealHeight(50), |
| | | TextAlignment = TextAlignment.Center, |
| | | TextColor = CSS_Color.TextualColor, |
| | | SelectedTextColor = CSS_Color.MainColor, |
| | | TextSize = CSS_FontSize.SubheadingFontSize, |
| | | TextID = StringId.Album, |
| | | }; |
| | | optionView.AddChidren(btnAlbum); |
| | | |
| | | optionView.AddChidren(new Button() { Height = Application.GetRealHeight(1), Width = Application.GetRealWidth(343), BackgroundColor = CSS_Color.DividingLineColor }); |
| | | |
| | | btnCancel = new Button() |
| | | { |
| | | Gravity = Gravity.CenterHorizontal, |
| | | Y = Application.GetRealHeight(8) + optionView.Bottom, |
| | | Width = Application.GetRealWidth(343), |
| | | Height = Application.GetRealHeight(50), |
| | | BackgroundColor = CSS_Color.MainBackgroundColor, |
| | | Radius = (uint)Application.GetRealWidth(12), |
| | | TextID = StringId.Cancel, |
| | | TextColor = CSS_Color.WarningColor, |
| | | TextSize = CSS_FontSize.SubheadingFontSize, |
| | | }; |
| | | pictureOptionView.AddChidren(btnCancel); |
| | | |
| | | |
| | | LoadEvent_PictureOptionViewEventList(pView); |
| | | } |
| | | |
| | | |
| | | } |
| | | //-------------------------------------- |
| | | public partial class SceneAddPage |
| | | { |
| | | void LoadEventList() |
| | | { |
| | | LoadEvent_ChangeSceneImage(); |
| | | LoadEvent_ChangeSceneZone(); |
| | | LoadEvent_ChangeFunctionList(); |
| | | LoadEvent_CompleteEvent(); |
| | | LoadEvent_EditRoomName(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 修改场景所属区域 |
| | | /// </summary> |
| | | void LoadEvent_ChangeSceneZone() |
| | | { |
| | | EventHandler<MouseEventArgs> eventHandler = (sender, e) => |
| | | { |
| | | Action backAction = () => { |
| | | btnZoneName.Text = scene.GetRoomListName(); |
| | | }; |
| | | var ssl = new SetSceneLocationPage(scene, backAction); |
| | | MainPage.BasePageView.AddChidren(ssl); |
| | | ssl.LoadPage(); |
| | | MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1; |
| | | }; |
| | | btnZoneName.MouseUpEventHandler = eventHandler; |
| | | belongToZoneRow.MouseUpEventHandler = eventHandler; |
| | | btnBelongToZoneRight.MouseUpEventHandler = eventHandler; |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 修改场景的功能列表 |
| | | /// </summary> |
| | | void LoadEvent_ChangeFunctionList() |
| | | { |
| | | btnAddFunctionTitle.MouseUpEventHandler = (sender, e) => { |
| | | var sefp = new SceneFunctionListEditPage(scene, refreshFunctionRowAction); |
| | | MainPage.BasePageView.AddChidren(sefp); |
| | | sefp.LoadPage(); |
| | | MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1; |
| | | }; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 修改场景背景事件 |
| | | /// </summary> |
| | | void LoadEvent_ChangeSceneImage() |
| | | { |
| | | addSceneImageView.MouseUpEventHandler = (sender, e) => { |
| | | LoadPictureOptionView(); |
| | | }; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 加载背景图选择区域事件列表 |
| | | /// </summary> |
| | | void LoadEvent_PictureOptionViewEventList(FrameLayout pView) |
| | | { |
| | | pictureOptionView.MouseUpEventHandler = (sender, e) => |
| | | { |
| | | pictureOptionView.Parent.RemoveFromParent(); |
| | | }; |
| | | pView.MouseUpEventHandler = (sender, e) => |
| | | { |
| | | pictureOptionView.Parent.RemoveFromParent(); |
| | | }; |
| | | |
| | | btnCancel.MouseUpEventHandler = (sender, e) => |
| | | { |
| | | pictureOptionView.Parent.RemoveFromParent(); |
| | | }; |
| | | btnTakePicture.MouseDownEventHandler = (sender, e) => { |
| | | btnTakePicture.IsSelected = true; |
| | | }; |
| | | btnTakePicture.MouseUpEventHandler = (sender, e) => |
| | | { |
| | | btnTakePicture.IsSelected = false; |
| | | |
| | | //var pid = Guid.NewGuid(); |
| | | //CropImage.TakePicture((imagePath) => |
| | | //{ |
| | | // if (imagePath != null) |
| | | // { |
| | | // addSceneImageView.ImagePath = imagePath.ToString(); |
| | | // scene.ImagePath = addSceneImageView.ImagePath; |
| | | // MainPage.Log("SelectPicture 裁剪图片返回路径: " + imagePath); |
| | | // } |
| | | //}, pid.ToString(), 4, 3); |
| | | |
| | | |
| | | var imageName = Guid.NewGuid().ToString(); |
| | | //var imageName = scene.sid; |
| | | CropImage.TakePicture((imagePath) => |
| | | { |
| | | CropImageCallBack(imagePath); |
| | | |
| | | }, imageName, 4, 3); |
| | | |
| | | //if (pageTitleId == StringId.EditScene) |
| | | //{ |
| | | // scene.SaveFunctionData(); |
| | | //} |
| | | pictureOptionView.Parent.RemoveFromParent(); |
| | | }; |
| | | btnAlbum.MouseDownEventHandler = (sender, e) => { |
| | | btnAlbum.IsSelected = true; |
| | | }; |
| | | |
| | | btnAlbum.MouseUpEventHandler = (sender, e) => |
| | | { |
| | | btnAlbum.IsSelected = false; |
| | | //var pid = Guid.NewGuid(); |
| | | //CropImage.SelectPicture((imagePath) => |
| | | //{ |
| | | // if (imagePath != null) |
| | | // { |
| | | // addSceneImageView.ImagePath = imagePath.ToString(); |
| | | // scene.ImagePath = addSceneImageView.ImagePath; |
| | | // MainPage.Log("SelectPicture 裁剪图片返回路径: " + imagePath); |
| | | // } |
| | | //}, pid.ToString(), 4, 3); |
| | | |
| | | //从相册选择图片裁剪 |
| | | var imageName = Guid.NewGuid().ToString(); |
| | | //var imageName = scene.sid; |
| | | CropImage.SelectPicture((imagePath) => |
| | | { |
| | | CropImageCallBack(imagePath); |
| | | }, imageName, 4, 3); |
| | | |
| | | |
| | | //if (pageTitleId == StringId.EditScene) |
| | | //{ |
| | | // scene.SaveFunctionData(); |
| | | //} |
| | | pictureOptionView.Parent.RemoveFromParent(); |
| | | }; |
| | | |
| | | btnDefaultGallery.MouseUpEventHandler = (sender, e) => { |
| | | pictureOptionView.Parent.RemoveFromParent(); |
| | | Action<string> action = (obj) => { |
| | | scene.ImagePath = obj; |
| | | addSceneImageView.ImagePath = scene.ImagePath; |
| | | }; |
| | | |
| | | var galleryPage = new GalleryPage(scene.ImagePath, action); |
| | | MainPage.BasePageView.AddChidren(galleryPage); |
| | | galleryPage.LoadPage(true); |
| | | MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1; |
| | | }; |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 裁剪完照片回调,统一处理 |
| | | /// </summary> |
| | | /// <param name="imagePath">裁剪后的真实路径</param> |
| | | /// <param name="imageName">自定义的图片名称</param> |
| | | void CropImageCallBack(string selectImagePath) |
| | | { |
| | | if (string.IsNullOrEmpty(selectImagePath) == true) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | //上传成功到回调 |
| | | Action<string> uploadSuccessAction = (imageUrl) => |
| | | { |
| | | //2020-12-03 需要讲最新的图片路径同步到云端 |
| | | scene.ImagePath = imageUrl; |
| | | }; |
| | | //上传图片到云端 |
| | | UploadImage(selectImagePath, addSceneImageView, scene, uploadSuccessAction); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 完成按钮点击事件 |
| | | /// </summary> |
| | | void LoadEvent_CompleteEvent() |
| | | { |
| | | btnComplete.MouseUpEventHandler += (sender, e) => |
| | | { |
| | | if (string.IsNullOrEmpty(scene.name)) |
| | | { |
| | | new Tip() |
| | | { |
| | | CloseTime = 1, |
| | | Text = Language.StringByID(StringId.SceneNameCannotBeEmpty), |
| | | Direction = AMPopTipDirection.None, |
| | | }.Show(bodyView); |
| | | return; |
| | | } |
| | | foreach (var tempRoom in FunctionList.List.scenes) |
| | | { |
| | | if (scene.name == tempRoom.name) |
| | | { |
| | | new PublicAssmebly().TipMsg(StringId.Tip, StringId.SceneNameAlreadyExists); |
| | | return; |
| | | } |
| | | } |
| | | var result = scene.AddScene(); |
| | | if (result == StateCode.SUCCESS) |
| | | { |
| | | FunctionList.List.scenes.Add(scene); |
| | | backAction(); |
| | | this.RemoveFromParent(); |
| | | } |
| | | else |
| | | { |
| | | IMessageCommon.Current.ShowErrorInfoAlter(result); |
| | | } |
| | | }; |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 加载修改场景名称窗口事件 |
| | | /// </summary> |
| | | void LoadEvent_EditRoomName() |
| | | { |
| | | Action<string> callBack = (str) => |
| | | { |
| | | //名称不能为空 |
| | | if (string.IsNullOrEmpty(str)) |
| | | { |
| | | new Tip() |
| | | { |
| | | CloseTime = 1, |
| | | Text = Language.StringByID(StringId.SceneNameCannotBeEmpty), |
| | | Direction = AMPopTipDirection.None, |
| | | }.Show(bodyView); |
| | | return; |
| | | } |
| | | btnSceneName.Text = str; |
| | | scene.name = str; |
| | | }; |
| | | EventHandler<MouseEventArgs> eventHandler = (sender, e) => |
| | | { |
| | | List<string> sceneNameList = new List<string>(); |
| | | foreach (var tempScene in FunctionList.List.scenes) |
| | | { |
| | | sceneNameList.Add(tempScene.name); |
| | | } |
| | | new PublicAssmebly().LoadDialog_EditParater(StringId.SceneName, scene.name, callBack, StringId.SceneNameCannotBeEmpty, StringId.SceneNameAlreadyExists, sceneNameList); |
| | | }; |
| | | sceneNameView.MouseUpEventHandler = eventHandler; |
| | | btnSceneName.MouseUpEventHandler = eventHandler; |
| | | btnEditSceneNameIcon.MouseUpEventHandler = eventHandler; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 上传图片方法 |
| | | /// </summary> |
| | | /// <param name="selectImagePath">裁剪后的图片路径</param> |
| | | /// <param name="imageView"></param> |
| | | /// <param name="uploadSuccessAction"></param> |
| | | void UploadImage(string selectImagePath, ImageView imageView, Scene mScene, Action<string> uploadSuccessAction) |
| | | { |
| | | try |
| | | { |
| | | //MainPage.Log("SelectPicture 裁剪图片返回路径: " + selectImagePath); |
| | | //1.读取裁剪后的图片,然后删除 |
| | | var imageBytes = Shared.IO.FileUtils.ReadFile(selectImagePath); |
| | | System.IO.File.Delete(selectImagePath); |
| | | |
| | | var waitPage = new Loading(); |
| | | bodyView.AddChidren(waitPage); |
| | | waitPage.Start(Language.StringByID(StringId.PleaseWait)); |
| | | //开始上传 |
| | | new Thread(() => |
| | | { |
| | | try |
| | | { |
| | | var newImageName = mScene.name.Trim() + ".png"; |
| | | var uploadImageObj = new UploadImageObj() |
| | | { |
| | | prefix = "Scene" + Utlis.GetTimestamp(), |
| | | fileName = newImageName, |
| | | uid = mScene.sid, |
| | | content = imageBytes, |
| | | }; |
| | | |
| | | var imageUrl = ImageUtlis.Current.UploadImage(uploadImageObj); |
| | | if (!string.IsNullOrEmpty(imageUrl) && imageUrl.Contains(newImageName)) |
| | | { |
| | | //上传成功 |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | //Utlis.WriteLine("上传成功:" + imageUrl); |
| | | //1.2如果是自定义图片删除之前的 |
| | | if (!string.IsNullOrEmpty(imageView.ImagePath) && !imageView.ImagePath.Contains("Classification/Room/Roombg")) |
| | | { |
| | | //Utlis.WriteLine("删除: " + imageView.ImagePath); |
| | | System.IO.File.Delete(imageView.ImagePath); |
| | | } |
| | | //重命名保存 |
| | | ImageUtlis.Current.WriteFileByBytes(imageUrl, imageBytes); |
| | | imageView.ImagePath = null; |
| | | imageView.ImageBytes = imageBytes; |
| | | //上传成功 |
| | | Utlis.ShowTip(Language.StringByID(StringId.UploadSuccessfully)); |
| | | uploadSuccessAction?.Invoke(imageUrl); |
| | | }); |
| | | } |
| | | else |
| | | { |
| | | //上传失败 |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | //上传失败 |
| | | Utlis.ShowTip(Language.StringByID(StringId.UploadFailed)); |
| | | }); |
| | | } |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | } |
| | | finally |
| | | { |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | if (waitPage != null) |
| | | { |
| | | waitPage.RemoveFromParent(); |
| | | waitPage = null; |
| | | } |
| | | }); |
| | | } |
| | | }) |
| | | { IsBackground = true }.Start(); |
| | | } |
| | | catch { } |
| | | } |
| | | } |
| | | } |