using System; using HDL_ON.Entity; using HDL_ON.UI.CSS; using Shared; using System.Collections.Generic; namespace HDL_ON.UI { public class SceneFunctionInfoEditPage : FrameLayout { FrameLayout bodyView; VerticalScrolViewLayout contentView; Scene scene; Action refreshAction; Function function; public SceneFunctionInfoEditPage(Scene s,Function fc,Action action) { bodyView = this; scene = s; function = fc; refreshAction = action; } public void LoadPage() { bodyView.BackgroundColor = CSS_Color.BackgroundColor; new TopViewDiv(bodyView, function.name).LoadTopView(); contentView = new VerticalScrolViewLayout() { Y = Application.GetRealHeight(64), Height = Application.GetRealHeight(520), ScrollEnabled = false, }; bodyView.AddChidren(contentView); //加载开关Row LoadFunctionRow(function.trait_on_off); switch (function.functionType) { case FunctionType.AC: LoadFunctionRow(function.function.Find((obj) => obj.name == "temperature")); LoadFunctionRow(function.function.Find((obj) => obj.name == "mode")); LoadFunctionRow(function.function.Find((obj) => obj.name == "fan")); break; case FunctionType.FloorHeating: LoadFunctionRow(function.function.Find((obj) => obj.name == "temperature")); LoadFunctionRow(function.function.Find((obj) => obj.name == "mode")); break; case FunctionType.Curtain: //无操作 break; case FunctionType.MotorCurtain: case FunctionType.RollingShutter: LoadFunctionRow(function.function.Find((obj) => obj.name == "percent")); break; case FunctionType.Relay: //无操作 break; case FunctionType.Dimmer: case FunctionType.RGB: LoadFunctionRow(function.function.Find((obj) => obj.name == "brightness")); break; } //加载延时Row LoadDelayRow(); var bottomView = new FrameLayout() { Y = Application.GetRealHeight(591), Height = Application.GetRealHeight(106), BackgroundColor = CSS_Color.MainBackgroundColor, Radius = (uint)Application.GetRealWidth(16), }; bodyView.AddChidren(bottomView); var btnConfrim = new Button() { Gravity = Gravity.CenterHorizontal, Y = Application.GetRealHeight(12), Width = Application.GetRealWidth(220), Height = Application.GetRealWidth(44), TextAlignment = TextAlignment.Center, TextColor = CSS_Color.MainBackgroundColor, BackgroundColor = CSS_Color.MainColor, TextSize = CSS_FontSize.SubheadingFontSize, IsBold = true, Radius = (uint) Application.GetRealWidth(22), TextID = StringId.Complete }; bottomView.AddChidren(btnConfrim); btnConfrim.MouseUpEventHandler = (sender, e) => { var temp = scene.sceneFunctionList.Find((obj) => obj.sid == function.sid); if (temp!=null) { temp = function; } else { scene.sceneFunctionList.Add(function); } refreshAction(); this.RemoveFromParent(); }; } /// /// 加载功能Row /// void LoadFunctionRow(Trait trait) { if (trait == null) return; #region Row code var row = new FrameLayout() { Height = Application.GetRealHeight(50), BackgroundColor = CSS_Color.MainBackgroundColor, }; contentView.AddChidren(row); if (trait.name != "on_off") { row.AddChidren(new Button() { X = Application.GetRealWidth(16), Height = Application.GetRealHeight(1), Width = Application.GetRealWidth(343), BackgroundColor = CSS_Color.DividingLineColor }); } Button btnBrightnessRight = new Button() { X = Application.GetRealWidth(339), Gravity = Gravity.CenterVertical, Width = Application.GetMinRealAverage(16), Height = Application.GetMinRealAverage(16), UnSelectedImagePath = "Public/Right.png", }; row.AddChidren(btnBrightnessRight); var btnFunctionText = new Button() { Width = Application.GetRealWidth(330), TextAlignment = TextAlignment.CenterRight, TextColor = CSS_Color.PromptingColor1, TextSize = CSS_FontSize.PromptFontSize_FirstLevel, Text = trait.GetCurValueText() + trait.uintString }; row.AddChidren(btnFunctionText); var btnFunctionName = new Button() { X = Application.GetRealWidth(16), TextAlignment = TextAlignment.CenterLeft, TextColor = CSS_Color.FirstLevelTitleColor, TextSize = CSS_FontSize.SubheadingFontSize, Text = trait.name_text }; row.AddChidren(btnFunctionName); btnFunctionName.MouseUpEventHandler = (sender, e) => { switch (trait.name) { case "on_off": LoadEditDialog_OnOff(trait, btnFunctionText); break; case "brightness": LoadEditDialog_Percent(trait, btnFunctionText); break; //case "color": // break; case "mode": LoadEditDialog_FunctionPar(trait, btnFunctionText); break; case "fan": LoadEditDialog_FunctionPar(trait, btnFunctionText); break; case "temperature": LoadEditDialog_Temp(trait, btnFunctionText); break; case "delay": break; case "cct": break; //case "fade_time": case "percent": LoadEditDialog_Percent(trait, btnFunctionText); break; //case "lock": //case "ico": //case "swing": //case "set_ point": //case "pm25": //case "volume": //case "vol_step": //case "source": //case "treble": //case "bass": //case "playlist": //case "song_name": //case "current_status": //case "enable": //case "lux": //case "adjust_value": //case "range": //case "humidity": //case "type": //case "state": //case "sensitivity": //case "pm25value": } //LoadEditDialog_Temp(trait, btnFunctionText); }; #endregion } #region 加载功能场景数据调节界面 /// /// 加载延时Row /// void LoadDelayRow() { #region 延时row FrameLayout delayRow = new FrameLayout() { Height = Application.GetRealWidth(50), BackgroundColor = CSS_Color.MainBackgroundColor }; contentView.AddChidren(delayRow); delayRow.AddChidren(new Button() { X = Application.GetRealWidth(16), Height = Application.GetRealHeight(1), Width = Application.GetRealWidth(343), BackgroundColor = CSS_Color.DividingLineColor }); Button btnDelayRight = new Button() { X = Application.GetRealWidth(339), Gravity = Gravity.CenterVertical, Width = Application.GetMinRealAverage(16), Height = Application.GetMinRealAverage(16), UnSelectedImagePath = "Public/Right.png", }; delayRow.AddChidren(btnDelayRight); var btnDelayInfo = new Button() { Width = Application.GetRealWidth(327), TextAlignment = TextAlignment.CenterRight, TextColor = CSS_Color.PromptingColor1, TextSize = CSS_FontSize.PromptFontSize_FirstLevel, Text = scene.delayText }; delayRow.AddChidren(btnDelayInfo); Button btnSceneDelayTitle = new Button() { X = Application.GetRealWidth(16), TextAlignment = TextAlignment.CenterLeft, TextColor = CSS_Color.FirstLevelTitleColor, TextSize = CSS_FontSize.SubheadingFontSize, TextID = StringId.Delay, }; delayRow.AddChidren(btnSceneDelayTitle); btnSceneDelayTitle.MouseUpEventHandler = (sender, e) => { new PublicAssmebly().SetSceneDelayDialog(function, btnDelayInfo); }; #endregion } #endregion #region 属性选择弹窗 /// /// 加载开关选择弹窗 /// /// /// void LoadEditDialog_OnOff(Trait trait, Button btn) { Dialog dialog = new Dialog(); var pView = new FrameLayout() { BackgroundColor = CSS_Color.DialogTransparentColor1, }; dialog.AddChidren(pView); var optionBaseView = new FrameLayout() { Y = Application.GetRealHeight(500), Height = Application.GetRealHeight(160), AnimateSpeed = 0.3f, Animate = Animate.DownToUp, }; pView.AddChidren(optionBaseView); var optionView = new VerticalScrolViewLayout() { Gravity = Gravity.CenterHorizontal, Width = Application.GetRealWidth(343), Height = Application.GetRealHeight(100), BackgroundColor = CSS_Color.MainBackgroundColor, Radius = (uint)Application.GetRealWidth(12), ScrollEnabled = false, }; optionBaseView.AddChidren(optionView); var btnOn = new Button() { Height = Application.GetRealHeight(50), TextAlignment = TextAlignment.Center, TextColor = CSS_Color.TextualColor, SelectedTextColor = CSS_Color.MainColor, TextSize = CSS_FontSize.SubheadingFontSize, TextID = StringId.On, IsSelected = function.trait_on_off.value.ToString() == "on" }; optionView.AddChidren(btnOn); optionView.AddChidren(new Button() { Height = Application.GetRealHeight(1), BackgroundColor = CSS_Color.DividingLineColor }); var btnOff = new Button() { Height = Application.GetRealHeight(50), TextAlignment = TextAlignment.Center, TextColor = CSS_Color.TextualColor, SelectedTextColor = CSS_Color.MainColor, TextSize = CSS_FontSize.SubheadingFontSize, TextID = StringId.OFF, IsSelected = function.trait_on_off.value.ToString() == "off" }; optionView.AddChidren(btnOff); var 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, }; optionBaseView.AddChidren(btnCancel); dialog.Show(); pView.MouseUpEventHandler = (sender, e) => { dialog.Close(); }; btnCancel.MouseUpEventHandler = (sender, e) => { dialog.Close(); }; btnOn.MouseUpEventHandler = (sender, e) => { dialog.Close(); trait.value = "on"; btn.Text = trait.GetCurValueText() + trait.uintString; }; btnOff.MouseUpEventHandler = (sender,e) =>{ dialog.Close(); trait.value = "off"; btn.Text= trait.GetCurValueText() + trait.uintString; }; } /// /// 加载温度选择弹窗 /// /// /// void LoadEditDialog_Temp(Trait trait, Button btn) { List pickerItems = new List(); if(trait == null) { return; } Dialog dialog = new Dialog(); var pView = new FrameLayout() { BackgroundColor = CSS_Color.DialogTransparentColor1, }; dialog.AddChidren(pView); var optionBaseView = new FrameLayout() { Y = Application.GetRealHeight(456-60), Gravity = Gravity.CenterHorizontal, Width = Application.GetRealWidth(343), Height = Application.GetRealHeight(260), AnimateSpeed = 0.3f, Animate = Animate.DownToUp, BackgroundColor = CSS_Color.MainBackgroundColor, Radius = (uint)Application.GetRealWidth(12), }; pView.AddChidren(optionBaseView); var topView = new FrameLayout() { Gravity = Gravity.CenterHorizontal, Width = Application.GetRealWidth(343), Height = Application.GetRealHeight(40), BackgroundColor = CSS_Color.MainBackgroundColor, Radius = (uint)Application.GetRealWidth(12), }; optionBaseView.AddChidren(topView); topView.AddChidren(new Button() {Y = Application.GetRealHeight(39), Height = Application.GetRealHeight(1), BackgroundColor = CSS_Color.DividingLineColor }); var btnCancel = new Button() { X = Application.GetRealWidth(21), Width = Application.GetRealWidth(100), TextAlignment = TextAlignment.CenterLeft, TextColor = CSS_Color.PromptingColor1, TextSize = CSS_FontSize.TextFontSize, TextID = StringId.Cancel, }; topView.AddChidren(btnCancel); var btnConfrim = new Button() { Width = Application.GetRealWidth(320), TextAlignment = TextAlignment.CenterRight, TextColor = CSS_Color.MainColor, TextSize = CSS_FontSize.TextFontSize, TextID = StringId.Confirm, }; topView.AddChidren(btnConfrim); UIPickerView uIPickerView = new UIPickerView() { Y = Application.GetRealHeight(40), Height = Application.GetRealHeight(210), Radius = (uint)Application.GetRealWidth(12), }; if(trait!=null) { if (trait.data_type == "float") { for (double i = trait.min; i <= trait.max; i += 0.5) { pickerItems.Add(i.ToString() + trait.uintString); } } else { for (int i = trait.min; i <= trait.max; i += 1) { pickerItems.Add(i.ToString() + trait.uintString); } } }else { for (int i = 16; i <= 32; i += 1) { pickerItems.Add(i.ToString() + trait.uintString); } } uIPickerView.setNPicker(pickerItems, null, null); optionBaseView.AddChidren(uIPickerView); uIPickerView.setCurrentItems(pickerItems.IndexOf(trait.value.ToString()), 4, 5); string selectItem = trait.value.ToString() + trait.uintString; dialog.Show(); pView.MouseUpEventHandler = (sender, e) => { dialog.Close(); }; btnCancel.MouseUpEventHandler = (sender, e) => { dialog.Close(); }; uIPickerView.OnSelectChangeEvent = (int1, int2, int3) => { selectItem = pickerItems[int1]; }; btnConfrim.MouseUpEventHandler = (sender, e) => { dialog.Close(); btn.Text = selectItem; }; } /// /// 加载亮度选择弹窗 /// /// /// void LoadEditDialog_Percent(Trait trait, Button btn) { if (trait == null) { return; } Dialog dialog = new Dialog(); var pView = new FrameLayout() { BackgroundColor = CSS_Color.DialogTransparentColor1, }; dialog.AddChidren(pView); var optionBaseView = new FrameLayout() { Y = Application.GetRealHeight(467), Gravity = Gravity.CenterHorizontal, Width = Application.GetRealWidth(343), Height = Application.GetRealHeight(180), AnimateSpeed = 0.3f, Animate = Animate.DownToUp, BackgroundColor = CSS_Color.MainBackgroundColor, Radius = (uint)Application.GetRealWidth(12), }; pView.AddChidren(optionBaseView); var topView = new FrameLayout() { Gravity = Gravity.CenterHorizontal, Width = Application.GetRealWidth(343), Height = Application.GetRealHeight(40), BackgroundColor = CSS_Color.MainBackgroundColor, Radius = (uint)Application.GetRealWidth(12), }; optionBaseView.AddChidren(topView); topView.AddChidren(new Button() { Y = Application.GetRealHeight(39), Height = Application.GetRealHeight(1), BackgroundColor = CSS_Color.DividingLineColor }); var btnTitle = new Button() { Gravity = Gravity.CenterHorizontal, TextAlignment = TextAlignment.Center, Width = Application.GetRealWidth(100), Text = trait.name_text, IsBold = true, TextColor = CSS_Color.FirstLevelTitleColor, TextSize = CSS_FontSize.SubheadingFontSize, }; topView.AddChidren(btnTitle); var btnCancel = new Button() { X = Application.GetRealWidth(21), Width = Application.GetRealWidth(100), TextAlignment = TextAlignment.CenterLeft, TextColor = CSS_Color.PromptingColor1, TextSize = CSS_FontSize.TextFontSize, TextID = StringId.Cancel, }; topView.AddChidren(btnCancel); var btnConfrim = new Button() { Width = Application.GetRealWidth(320), TextAlignment = TextAlignment.CenterRight, TextColor = CSS_Color.MainColor, TextSize = CSS_FontSize.TextFontSize, TextID = StringId.Confirm, }; topView.AddChidren(btnConfrim); Button btnMinusSignIcon = new Button() { X = Application.GetRealWidth(26), Y = Application.GetRealHeight(118), Width = Application.GetMinRealAverage(24), Height = Application.GetMinRealAverage(24), UnSelectedImagePath = "Public/MinusSignIcon.png", }; optionBaseView.AddChidren(btnMinusSignIcon); DiyImageSeekBar controlBar = new DiyImageSeekBar() { X = btnMinusSignIcon.Right + Application.GetRealWidth(12), Y = Application.GetRealHeight(100),//414,设计数据 Width = Application.GetRealWidth(220), Height = Application.GetRealHeight(54), SeekBarViewHeight = Application.GetRealHeight(8), ThumbImagePath = "Public/ThumbImage.png", ThumbImageHeight = Application.GetRealHeight(54), ProgressBarColor = CSS_Color.MainColor, ProgressTextColor = CSS_Color.FirstLevelTitleColor, ProgressTextSize = CSS_FontSize.PromptFontSize_FirstLevel, MaxValue = 100, Progress = trait.value.ToString().Replace("{}", "") == "" ? 0 : Convert.ToInt32( trait.value), SeekBarPadding = Application.GetRealWidth(20), }; optionBaseView.AddChidren(controlBar); Button btnPlusSgnIcon = new Button() { X = controlBar.Right + Application.GetRealWidth(12), Y = Application.GetRealHeight(118), Width = Application.GetMinRealAverage(24), Height = Application.GetMinRealAverage(24), UnSelectedImagePath = "Public/PlusSignIcon.png", }; optionBaseView.AddChidren(btnPlusSgnIcon); btnMinusSignIcon.MouseUpEventHandler = (sender, e) => { controlBar.Progress--; }; btnPlusSgnIcon.MouseUpEventHandler = (sender, e) => { controlBar.Progress++; }; dialog.Show(); pView.MouseUpEventHandler = (sender, e) => { dialog.Close(); }; btnCancel.MouseUpEventHandler = (sender, e) => { dialog.Close(); }; btnConfrim.MouseUpEventHandler = (sender, e) => { dialog.Close(); trait.value = controlBar.Progress; btn.Text = trait.value + trait.uintString; }; } /// /// 加载功能属性数据选择弹窗 /// void LoadEditDialog_FunctionPar(Trait trait, Button btn) { Button lastButton = new Button(); var lastData = ""; var lastText = ""; Dialog dialog = new Dialog(); var pView = new FrameLayout() { BackgroundColor = CSS_Color.DialogTransparentColor1, }; dialog.AddChidren(pView); var optionBaseView = new FrameLayout() { Y = Application.GetRealHeight(579 - 50 * trait.value_key.Count), Gravity = Gravity.CenterHorizontal, Width = Application.GetRealWidth(343), Height = Application.GetRealHeight(50 * trait.value_key.Count + 50), AnimateSpeed = 0.3f, Animate = Animate.DownToUp, BackgroundColor = CSS_Color.MainBackgroundColor, Radius = (uint)Application.GetRealWidth(12), }; pView.AddChidren(optionBaseView); var topView = new FrameLayout() { Gravity = Gravity.CenterHorizontal, Width = Application.GetRealWidth(343), Height = Application.GetRealHeight(50), BackgroundColor = CSS_Color.MainBackgroundColor, Radius = (uint)Application.GetRealWidth(12), }; optionBaseView.AddChidren(topView); var btnTitle = new Button() { Gravity = Gravity.CenterHorizontal, TextAlignment = TextAlignment.Center, Width = Application.GetRealWidth(100), Text = trait.name_text, IsBold = true, TextColor = CSS_Color.FirstLevelTitleColor, TextSize = CSS_FontSize.SubheadingFontSize, }; topView.AddChidren(btnTitle); var btnCancel = new Button() { X = Application.GetRealWidth(21), Width = Application.GetRealWidth(100), TextAlignment = TextAlignment.CenterLeft, TextColor = CSS_Color.PromptingColor1, TextSize = CSS_FontSize.TextFontSize, TextID = StringId.Cancel, }; topView.AddChidren(btnCancel); var btnConfrim = new Button() { Width = Application.GetRealWidth(320), TextAlignment = TextAlignment.CenterRight, TextColor = CSS_Color.MainColor, TextSize = CSS_FontSize.TextFontSize, TextID = StringId.Complete, }; topView.AddChidren(btnConfrim); int hei = 1; foreach (var m in trait.value_key) { var row = new FrameLayout() { Y = Application.GetRealHeight(50 * hei), Height = Application.GetRealHeight(50), }; optionBaseView.AddChidren(row); if (trait.value_key.Count > hei) { optionBaseView.AddChidren(new Button() { Gravity = Gravity.CenterHorizontal, Y = row.Bottom, Width = Application.GetRealWidth(343), BackgroundColor = CSS_Color.DividingLineColor, Height = 1, }); } hei++; var btnChoose = new Button() { X = Application.GetRealWidth(303), Gravity = Gravity.CenterVertical, Width = Application.GetMinRealAverage(28), Height = Application.GetMinRealAverage(28), UnSelectedImagePath = "Public/ChooseIcon.png", SelectedImagePath = "Public/ChooseOnIcon.png", }; row.AddChidren(btnChoose); if (trait.value.ToString() == m) { lastButton = btnChoose; btnChoose.IsSelected = true; } var btnPropertyTitle = new Button() { X = Application.GetRealWidth(16), TextAlignment = TextAlignment.CenterLeft, TextColor = CSS_Color.FirstLevelTitleColor, TextSize = CSS_FontSize.TextFontSize, Tag = m, Text = trait.GetValueText(m) }; row.AddChidren(btnPropertyTitle); btnPropertyTitle.MouseUpEventHandler = (sender, e) => { btnChoose.IsSelected = true; if (lastButton != null) { lastButton.IsSelected = false; } lastButton = btnChoose; lastData = btnPropertyTitle.Tag.ToString(); lastText = btnPropertyTitle.Text; }; } dialog.Show(); pView.MouseUpEventHandler = (sender, e) => { dialog.Close(); }; btnCancel.MouseUpEventHandler = (sender, e) => { dialog.Close(); }; btnConfrim.MouseUpEventHandler = (sender, e) => { dialog.Close(); trait.value = lastData; btn.Text = lastText; }; } #endregion } }