using System; using System.Collections.Generic; using HDL_ON.Common; using HDL_ON.DAL.Server; using HDL_ON.Entity; using HDL_ON.UI.CSS; using Shared; namespace HDL_ON.UI.UI2.FuntionControlView.VideoDoorLock { public class VideoDoorlockAudioSetupPage : FrameLayout { FrameLayout bodyView; Function device; /// /// 门铃系统音量 /// int doorlockSystemSound = 0; /// /// 门铃音量 /// int doorbelVol = 0; public VideoDoorlockAudioSetupPage(Function function) { device = function; bodyView = this; } public void LoadPage() { new TopViewDiv(bodyView, Language.StringByID(StringId.AudioSetup)).LoadTopView(); bodyView.BackgroundColor = CSS_Color.BackgroundColor; #region 门锁系统音量 var doorlockSystemVolumeView = new FrameLayout() { Y = Application.GetRealHeight(64), Height = Application.GetRealHeight(50), BackgroundColor = CSS.CSS_Color.MainBackgroundColor, }; bodyView.AddChidren(doorlockSystemVolumeView); var btnDoorlockSystemVolumeRight = new Button() { X = Application.GetRealWidth(339), Gravity = Gravity.CenterVertical, Width = Application.GetMinRealAverage(16), Height = Application.GetMinRealAverage(16), UnSelectedImagePath = "Public/Right.png", }; doorlockSystemVolumeView.AddChidren(btnDoorlockSystemVolumeRight); var btnDoorlockSystemVolumeStateText = new Button() { X = Application.GetRealWidth(100), Width = Application.GetRealWidth(223), TextAlignment = TextAlignment.CenterRight, TextSize = CSS_FontSize.TextFontSize, TextColor = CSS_Color.PromptingColor1, }; doorlockSystemVolumeView.AddChidren(btnDoorlockSystemVolumeStateText); var btnDoorlockSystemVolumeText = new Button() { X = Application.GetRealWidth(16), TextSize = CSS_FontSize.SubheadingFontSize, TextColor = CSS_Color.FirstLevelTitleColor, TextAlignment = TextAlignment.CenterLeft, TextID = StringId.DoorlockSystemVolume, }; doorlockSystemVolumeView.AddChidren(btnDoorlockSystemVolumeText); btnDoorlockSystemVolumeText.MouseUpEventHandler = (sender, e) => { LoadEditDialog(StringId.DoorlockSystemVolume, 3-doorlockSystemSound, btnDoorlockSystemVolumeStateText); }; #endregion #region 门铃音量 var viewDoorbellVolume = new FrameLayout() { Y = doorlockSystemVolumeView.Bottom, Height = Application.GetRealHeight(50), BackgroundColor = CSS.CSS_Color.MainBackgroundColor, }; bodyView.AddChidren(viewDoorbellVolume); viewDoorbellVolume.AddChidren(new Button { Height = 1, BackgroundColor = CSS_Color.DividingLineColor, }); var btnDoorbellVolumeRight = new Button() { X = Application.GetRealWidth(339), Gravity = Gravity.CenterVertical, Width = Application.GetMinRealAverage(16), Height = Application.GetMinRealAverage(16), UnSelectedImagePath = "Public/Right.png", }; viewDoorbellVolume.AddChidren(btnDoorbellVolumeRight); var btnDoorbellVolumeStateText = new Button() { X = Application.GetRealWidth(100), Width = Application.GetRealWidth(223), TextAlignment = TextAlignment.CenterRight, TextSize = CSS_FontSize.TextFontSize, TextColor = CSS_Color.PromptingColor1, }; viewDoorbellVolume.AddChidren(btnDoorbellVolumeStateText); var btnDoorbellVolumeText = new Button() { X = Application.GetRealWidth(16), TextSize = CSS_FontSize.SubheadingFontSize, TextColor = CSS_Color.FirstLevelTitleColor, TextAlignment = TextAlignment.CenterLeft, TextID = StringId.DoorbellVolume, }; viewDoorbellVolume.AddChidren(btnDoorbellVolumeText); btnDoorbellVolumeText.MouseUpEventHandler = (sender, e) => { LoadEditDialog(StringId.DoorbellVolume, doorbelVol, btnDoorbellVolumeStateText); }; #endregion var waitPage = new Loading(); bodyView.AddChidren(waitPage); waitPage.Start(""); new System.Threading.Thread(() => { try { var pack = ApiUtlis.Ins.HttpRequest.GetDoorLockSystemSound(device.deviceId); if (pack != null && pack.Code == StateCode.SUCCESS) { Application.RunOnMainThread(() => { //更新界面 var doorLockSystemSound = Newtonsoft.Json.JsonConvert.DeserializeObject(pack.Data.ToString()); if(doorLockSystemSound != null) { switch (doorLockSystemSound.sound) { case 0: doorlockSystemSound = 0; btnDoorlockSystemVolumeStateText.TextID = StringId.Mute; break; case 1: doorlockSystemSound = 1; btnDoorlockSystemVolumeStateText.TextID = StringId.Low; break; case 2: doorlockSystemSound = 2; btnDoorlockSystemVolumeStateText.TextID = StringId.Moderate; break; case 3: doorlockSystemSound = 3; btnDoorlockSystemVolumeStateText.TextID = StringId.High; break; } } }); } else { //失败提示 Application.RunOnMainThread(() => { if (!string.IsNullOrEmpty(pack.message)) { var tip = new Tip() { MaxWidth = Application.GetRealWidth(300), Text = $"{pack.message}({pack.Code})", CloseTime = 3, Direction = AMPopTipDirection.None }; tip.Show(MainPage.BaseView); } }); } pack = ApiUtlis.Ins.HttpRequest.GetDoorBellTone(device.deviceId); if (pack != null && pack.Code == StateCode.SUCCESS) { Application.RunOnMainThread(() => { //更新界面 var doorbellTone = Newtonsoft.Json.JsonConvert.DeserializeObject(pack.Data.ToString()); if (doorbellTone != null) { if (doorbellTone.volume == 0) { doorbelVol = 3; btnDoorbellVolumeStateText.TextID = StringId.Mute; } else if (doorbellTone.volume > 0 && doorbellTone.volume < 35) { doorbelVol = 2; btnDoorbellVolumeStateText.TextID = StringId.Low; } else if (doorbellTone.volume > 35 && doorbellTone.volume < 70) { doorbelVol = 1; btnDoorbellVolumeStateText.TextID = StringId.Moderate; } else if (doorbellTone.volume > 70) { doorbelVol = 0; btnDoorbellVolumeStateText.TextID = StringId.High; } } }); } else { //失败提示 Application.RunOnMainThread(() => { if (!string.IsNullOrEmpty(pack.message)) { var tip = new Tip() { MaxWidth = Application.GetRealWidth(300), Text = $"{pack.message}({pack.Code})", CloseTime = 3, Direction = AMPopTipDirection.None }; tip.Show(MainPage.BaseView); } }); } } catch (Exception ex) { MainPage.Log($"UnlockSettingPage error : {ex.Message}"); } finally { Application.RunOnMainThread(() => { waitPage.Hide(); }); } }) { IsBackground = true }.Start(); } /// /// 加载功能属性数据选择弹窗 /// void LoadEditDialog(int titleId, int index, 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 * 4), Gravity = Gravity.CenterHorizontal, Width = Application.GetRealWidth(343), Height = Application.GetRealHeight(50 * 4 + 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), TextID = titleId, 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() { X = Application.GetRealWidth(200), Width = Application.GetRealWidth(120), TextAlignment = TextAlignment.CenterRight, TextColor = CSS_Color.MainColor, TextSize = CSS_FontSize.TextFontSize, TextID = StringId.Complete, }; topView.AddChidren(btnConfrim); int hei = 1; var statusList = new List { Language.StringByID(StringId.High), Language.StringByID(StringId.Moderate), Language.StringByID(StringId.Low), Language.StringByID(StringId.Mute), }; foreach (var m in statusList) { var row = new FrameLayout() { Y = Application.GetRealHeight(50 * hei), Height = Application.GetRealHeight(50), }; optionBaseView.AddChidren(row); if (statusList.Count > hei) { optionBaseView.AddChidren(new Button() { Gravity = Gravity.CenterHorizontal, Y = row.Bottom, Width = Application.GetRealWidth(343), BackgroundColor = CSS_Color.DividingLineColor, Height = 1, }); } 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 (index == hei - 1) { 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 = hei-1, Text = 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; }; hei++; } dialog.Show(); pView.MouseUpEventHandler = (sender, e) => { dialog.Close(); }; btnCancel.MouseUpEventHandler = (sender, e) => { dialog.Close(); }; btnConfrim.MouseUpEventHandler = (sender, e) => { dialog.Close(); if(titleId == StringId.DoorlockSystemVolume) { var waitPage = new Loading(); bodyView.AddChidren(waitPage); waitPage.Start(""); new System.Threading.Thread(() => { try { int sound = 0; /// 0-静音 1-低音 2-中音 3-高音 4-自动 switch (lastData) { case "0": sound = 3; break; case "1": sound = 2; break; case "2": sound = 1; break; case "3": sound = 0; break; } var pack = ApiUtlis.Ins.HttpRequest.SetDoorLockSystemSound(device.deviceId,sound); if (pack != null && pack.Code == StateCode.SUCCESS) { Application.RunOnMainThread(() => { //更新界面 switch (sound) { case 0: btn.TextID = StringId.Mute; break; case 1: btn.TextID = StringId.Low; break; case 2: btn.TextID = StringId.Moderate; break; case 3: btn.TextID = StringId.High; break; } }); } else { //失败提示 Application.RunOnMainThread(() => { if (!string.IsNullOrEmpty(pack.message)) { var tip = new Tip() { MaxWidth = Application.GetRealWidth(300), Text = $"{pack.message}({pack.Code})", CloseTime = 3, Direction = AMPopTipDirection.None }; tip.Show(MainPage.BaseView); } }); } } catch (Exception ex) { MainPage.Log($"{this.GetType()} error 4: {ex.Message}"); } finally { Application.RunOnMainThread(() => { waitPage.Hide(); }); } }) { IsBackground = true }.Start(); } else { var waitPage = new Loading(); bodyView.AddChidren(waitPage); waitPage.Start(""); new System.Threading.Thread(() => { try { int Vol = 0; switch (lastData) { case "0": Vol = 100; break; case "1": Vol = 70; break; case "2": Vol = 30; break; case "3": Vol = 0; break; } var pack = ApiUtlis.Ins.HttpRequest.SetDoorBellTone(device.deviceId,Vol); if (pack != null && pack.Code == StateCode.SUCCESS) { Application.RunOnMainThread(() => { //更新界面 switch (lastData) { case "0": btn.TextID = StringId.High; break; case "1": btn.TextID = StringId.Moderate; break; case "2": btn.TextID = StringId.Low; break; case "3": btn.TextID = StringId.Mute; break; } }); } else { //失败提示 Application.RunOnMainThread(() => { if (!string.IsNullOrEmpty(pack.message)) { var tip = new Tip() { MaxWidth = Application.GetRealWidth(300), Text = $"{pack.message}({pack.Code})", CloseTime = 3, Direction = AMPopTipDirection.None }; tip.Show(MainPage.BaseView); } }); } } catch (Exception ex) { MainPage.Log($"{this.GetType()} error 5 : {ex.Message}"); } finally { Application.RunOnMainThread(() => { waitPage.Hide(); }); } }) { IsBackground = true }.Start(); } }; } } /// /// 门锁系统声音 /// public class DoorLockSystemSound { /// /// 声音 /// 0-静音 1-低音 2-中音 3-高音 4-自动 /// public int sound = 0; } /// /// 门铃提示音量 /// public class DoorBellTone { /// /// 音量 范围0-100 /// public int volume = 0; } }