using System; using System.Collections.Generic; using System.Text; namespace Shared.Phone.UserCenter { /// /// 安防管理主页的控件 /// public class SafetyMasterControl : NormalFrameLayout { #region ■ 变量声明___________________________ /// /// 在家布防 /// private GarrisonControl btnAthomeGarrison = null; /// /// 离家布防 /// private GarrisonControl btnRemovehomeGarrison = null; /// /// 撤防 /// private GarrisonControl btnReGarrisonGarrison = null; /// /// 桌布控件 /// private FrameLayout frameTable = null; #endregion #region ■ 初始化_____________________________ /// /// 初始化 /// public SafetyMasterControl() { this.Gravity = Gravity.CenterHorizontal; this.Width = Application.GetRealWidth(964); this.Height = Application.GetRealHeight(340); } /// /// 初始化控件 /// public void InitControl() { this.btnAthomeGarrison = null; this.btnReGarrisonGarrison = null; this.btnRemovehomeGarrison = null; this.frameTable = new FrameLayout(); frameTable.Height = this.Height; frameTable.Width = this.Width; frameTable.Radius = (uint)Application.GetRealHeight(58); frameTable.BackgroundColor = UserCenterColor.Current.White; this.AddChidren(frameTable); //右上圆角背景 var btnTopRight = new NormalViewControl(150, 60, true); btnTopRight.BackgroundColor = UserCenterColor.Current.White; btnTopRight.RadiusEx = 17; this.AddChidren(btnTopRight); btnTopRight.X = this.Width - btnTopRight.Width; //左下圆角背景 var btnBottomRight = new NormalViewControl(150, 60, true); btnBottomRight.BackgroundColor = UserCenterColor.Current.White; btnBottomRight.RadiusEx = 17; this.AddChidren(btnBottomRight); btnBottomRight.Y = this.Height - btnBottomRight.Height; //设置有内部防区 if (HdlSafeguardLogic.Current.IsHadInternalDefenseArea() == true) { //在家布防 btnAthomeGarrison = new GarrisonControl(); frameTable.AddChidren(btnAthomeGarrison); btnAthomeGarrison.InitControl(GarrisonMode.AtHome); btnAthomeGarrison.ButtonClickEvent += (sender, e) => { if (btnAthomeGarrison.btnIcon.IsSelected == false) { this.SetSafetyGarrisonModeInAtHome(); } }; //离家布防 btnRemovehomeGarrison = new GarrisonControl(); btnRemovehomeGarrison.X = btnAthomeGarrison.Right + Application.GetRealWidth(32); frameTable.AddChidren(btnRemovehomeGarrison); btnRemovehomeGarrison.InitControl(GarrisonMode.RemoveHome); btnRemovehomeGarrison.ButtonClickEvent += (sender, e) => { if (btnRemovehomeGarrison.btnIcon.IsSelected == false) { this.SetSafetyGarrisonModeInRemoveHome(); } }; //撤防 btnReGarrisonGarrison = new GarrisonControl(); btnReGarrisonGarrison.X = btnRemovehomeGarrison.Right + Application.GetRealWidth(32); frameTable.AddChidren(btnReGarrisonGarrison); btnReGarrisonGarrison.InitControl(GarrisonMode.RemoveGarrison); btnReGarrisonGarrison.ButtonClickEvent += (sender, e) => { this.RemoveSafetyGarrisonMode(); }; } else { //布防 btnAthomeGarrison = new GarrisonControl(); btnAthomeGarrison.X = Application.GetRealWidth(166); frameTable.AddChidren(btnAthomeGarrison); btnAthomeGarrison.InitControl(GarrisonMode.AtHome); btnAthomeGarrison.ButtonClickEvent += (sender, e) => { if (btnAthomeGarrison.btnIcon.IsSelected == false) { this.SetSafetyGarrisonModeInAtHome(); } }; //撤防 btnReGarrisonGarrison = new GarrisonControl(); btnReGarrisonGarrison.X = btnAthomeGarrison.Right + Application.GetRealWidth(32); frameTable.AddChidren(btnReGarrisonGarrison); btnReGarrisonGarrison.InitControl(GarrisonMode.RemoveGarrison); btnReGarrisonGarrison.ButtonClickEvent += (sender, e) => { this.RemoveSafetyGarrisonMode(); }; } //根据布防模式,设置图标的选择状态 this.SetIconStatuByGarrisonMode(HdlSafeguardLogic.Current.NowGarrisonMode); } #endregion #region ■ 布防撤防___________________________ /// /// 在家布防 /// private async void SetSafetyGarrisonModeInAtHome() { //打开进度条 ProgressBar.Show(string.Empty); //在家布防 GarrisonMode mode = await HdlSafeguardLogic.Current.SetSafetyGarrisonByModel(GarrisonMode.AtHome); //关闭进度条 ProgressBar.Close(); if (mode == GarrisonMode.None) { return; } Application.RunOnMainThread(() => { //根据布防模式,设置图标的选择状态 this.SetIconStatuByGarrisonMode(mode); if (mode == GarrisonMode.RemoveGarrison) { return; } //如果设置有内部防区 string msg = string.Empty; if (HdlSafeguardLogic.Current.IsHadInternalDefenseArea() == true) { //在家布防设置成功 msg = Language.StringByID(R.MyInternationalizationString.uSetAtHomeGarrisonSuccess); } else { //布防设置成功 msg = Language.StringByID(R.MyInternationalizationString.uSetGarrisonSuccess); } var control = new ShowMsgControl(ShowMsgType.Tip, msg); control.Show(); }); } /// /// 离家布防 /// private async void SetSafetyGarrisonModeInRemoveHome() { //打开进度条 ProgressBar.Show(string.Empty); //离家布防 GarrisonMode mode = await HdlSafeguardLogic.Current.SetSafetyGarrisonByModel(GarrisonMode.RemoveHome); //关闭进度条 ProgressBar.Close(); if (mode == GarrisonMode.None) { return; } Application.RunOnMainThread(() => { //根据布防模式,设置图标的选择状态 this.SetIconStatuByGarrisonMode(mode); if (mode == GarrisonMode.RemoveGarrison) { return; } //离家布防设置成功 string msg = Language.StringByID(R.MyInternationalizationString.uSetRemoveHomeGarrisonSuccess); var control = new ShowMsgControl(ShowMsgType.Tip, msg); control.Show(); }); } /// /// 撤防 /// private async void RemoveSafetyGarrisonMode() { //打开进度条 ProgressBar.Show(string.Empty); //撤防 var result = await HdlSafeguardLogic.Current.RemoveSafetyGarrison(GarrisonMode.RemoveGarrison, false); //关闭进度条 ProgressBar.Close(); if (result == -1) { return; } Application.RunOnMainThread(() => { //根据布防模式,设置图标的选择状态 this.SetIconStatuByGarrisonMode(GarrisonMode.RemoveGarrison); //离家布防设置成功 string msg = Language.StringByID(R.MyInternationalizationString.uRemoveGarrisonSuccess); var control = new ShowMsgControl(ShowMsgType.Tip, msg); control.Show(); }); } /// /// 根据布防模式,设置图标的选择状态 /// /// public void SetIconStatuByGarrisonMode(GarrisonMode mode) { //在家布防 if (mode == GarrisonMode.AtHome) { this.btnAthomeGarrison?.SetActionStatu(true); this.btnRemovehomeGarrison?.SetActionStatu(false); this.btnReGarrisonGarrison?.SetActionStatu(false); } //离家布防 else if (mode == GarrisonMode.RemoveHome) { this.btnAthomeGarrison?.SetActionStatu(false); this.btnRemovehomeGarrison?.SetActionStatu(true); this.btnReGarrisonGarrison?.SetActionStatu(false); } //撤防 else { this.btnAthomeGarrison?.SetActionStatu(false); this.btnRemovehomeGarrison?.SetActionStatu(false); this.btnReGarrisonGarrison?.SetActionStatu(true); } } #endregion #region ■ 一般方法___________________________ /// /// 设置布防按钮的可视状态 /// public void SetButtonVisible() { //设置有内部防区 if (HdlSafeguardLogic.Current.IsHadInternalDefenseArea() == true && btnRemovehomeGarrison != null) { //没必要再初始化界面 return; } Application.RunOnMainThread(() => { //清空全部控件 this.RemoveAll(); //重新初始化控件 this.InitControl(); }); } #endregion #region ■ 封装控件___________________________ /// /// 封装的布防控件 /// private class GarrisonControl : FrameLayoutStatuControl { #region ■ 变量声明___________________________ /// /// 背景控件 /// private NormalViewControl btnBack = null; /// /// 图标控件 /// public IconViewControl btnIcon = null; /// /// 文本控件 /// private NormalViewControl btnText = null; /// /// 选择状态的背景色 /// private uint selectBackColor = 0; #endregion #region ■ 初始化_____________________________ /// /// 封装的布防控件 /// public GarrisonControl() { //关闭状态显示 this.UseClickStatu = false; this.Gravity = Gravity.CenterVertical; this.Width = Application.GetRealWidth(300); this.Height = Application.GetRealHeight(216); } /// /// 初始化控件 /// /// 防区模式 public void InitControl(GarrisonMode garrison) { //移除底层事件 this.RemoveBaseClickEvent(); //背景 int backHeight = this.GetPictrueRealSize(132); btnBack = new NormalViewControl(backHeight, backHeight, false); btnBack.Gravity = Gravity.CenterHorizontal; btnBack.Radius = (uint)backHeight / 2; btnBack.BackgroundColor = UserCenterColor.Current.BodyFrameLayout; this.AddChidren(btnBack, ChidrenBindMode.BindEvent); //图标 btnIcon = new IconViewControl(81); btnIcon.Y = Application.GetRealHeight(26); btnIcon.Gravity = Gravity.CenterHorizontal; this.AddChidren(btnIcon, ChidrenBindMode.BindEvent); //文本 btnText = new NormalViewControl(this.Width, Application.GetRealHeight(58), false); btnText.TextColor = UserCenterColor.Current.TextGrayColor3; btnText.Y = Application.GetRealHeight(158); btnText.TextAlignment = TextAlignment.Center; this.AddChidren(btnText, ChidrenBindMode.NotBind); if (garrison == GarrisonMode.AtHome) { this.selectBackColor = 0xffffa200; btnIcon.UnSelectedImagePath = "Safeguard/ProtectionAtHome.png"; btnIcon.SelectedImagePath = "Safeguard/ProtectionAtHomeSelected.png"; //设置有内部防区 if (HdlSafeguardLogic.Current.IsHadInternalDefenseArea() == true) { btnText.TextID = R.MyInternationalizationString.uAtHomeGarrison; } else { btnText.TextID = R.MyInternationalizationString.uGarrison; } } else if (garrison == GarrisonMode.RemoveHome) { this.selectBackColor = 0xff35b87f; btnIcon.UnSelectedImagePath = "Safeguard/ProtectionRemoveHome.png"; btnIcon.SelectedImagePath = "Safeguard/ProtectionRemoveHomeSelected.png"; btnText.TextID = R.MyInternationalizationString.uRemoveHomeGarrison; } else if (garrison == GarrisonMode.RemoveGarrison) { this.selectBackColor = 0xff4a90e2; btnIcon.UnSelectedImagePath = "Safeguard/WithdrawGarrison.png"; btnIcon.SelectedImagePath = "Safeguard/WithdrawGarrisonSelected.png"; btnText.TextID = R.MyInternationalizationString.uWithdrawGarrison; } } #endregion #region ■ 一般方法___________________________ /// /// 设置控件的激活状态 /// /// 设置控件的激活状态 true:激活状态(选中) false:非激活状态 public void SetActionStatu(bool actionStatu) { if (actionStatu == true) { btnIcon.IsSelected = true; btnBack.BackgroundColor = selectBackColor; btnText.TextColor = selectBackColor; } else { btnIcon.IsSelected = false; btnBack.BackgroundColor = UserCenterColor.Current.BodyFrameLayout; btnText.TextColor = UserCenterColor.Current.TextGrayColor3; } } #endregion } #endregion } }