using System; using System.Collections.Generic; using System.Text; using ZigBee.Device; namespace Shared.Phone.UserCenter.DevicePirSensor { /// /// PIR传感器光感调节界面★ /// public class PirSensorLightPerceptionRegulationForm : EditorCommonForm { #region ■ 变量声明___________________________ /// /// 传感器设备 /// private IASZone deviceIASZone = null; /// /// 滑动的进度条 /// private HorizontalSeekBar SeekBar = null; /// /// 灯光的配置 /// private IASZone.ConfigureParamates Lightconfigure = null; /// /// 当前选择的光感等级 /// private int selectLightLevel = -1; #endregion #region ■ 初始化_____________________________ /// /// 画面显示(底层会固定调用此方法,借以完成画面创建) /// /// 传感器设备 /// 灯光的配置 public void ShowForm(IASZone i_iasZone, IASZone.ConfigureParamates i_Lightconfigure) { UserView.HomePage.Instance.ScrollEnabled = false; deviceIASZone = i_iasZone; Lightconfigure = i_Lightconfigure; //设置头部信息 base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uLightPerceptionRegulation)); //初始化中部信息 this.InitMiddleFrame(); //完成 //var btnfinish = new TopLayoutFinshView(); //topFrameLayout.AddChidren(btnfinish); //btnfinish.MouseUpEventHandler += (sender, e) => //{ // if (this.selectLightLevel == -1) // { // //什么都没有选择过 // this.CloseForm(); // return; // } // //保存传感器的灯光的配置信息 // this.SaveLightSettionData(); //}; } /// /// 初始化中部信息 /// private void InitMiddleFrame() { //清空bodyFrame this.ClearBodyFrame(); //左右间距 int space = Application.GetRealWidth(60); int YY = Application.GetRealHeight(220); //全天 var btnFullDay = new NormalViewControl(200, true); btnFullDay.X = space; btnFullDay.Y = YY; btnFullDay.TextID = R.MyInternationalizationString.uFullDay; btnFullDay.TextAlignment = TextAlignment.CenterLeft; bodyFrameLayout.AddChidren(btnFullDay); //中等 var btnMiddle = new NormalViewControl(200, true); btnMiddle.Gravity = Gravity.CenterHorizontal; btnMiddle.Y = YY; btnMiddle.TextID = R.MyInternationalizationString.uMedium; btnMiddle.TextAlignment = TextAlignment.Center; bodyFrameLayout.AddChidren(btnMiddle); //较暗 var btnMoreDark = new NormalViewControl(200, true); btnMoreDark.Y = YY; btnMoreDark.TextID = R.MyInternationalizationString.uMoreDark; btnMoreDark.TextAlignment = TextAlignment.CenterRight; bodyFrameLayout.AddChidren(btnMoreDark); btnMoreDark.X = bodyFrameLayout.Width - space - btnMoreDark.Width; //刻度图片 var btnScale = new PicViewControl(919, 97); btnScale.Y = btnMoreDark.Bottom + Application.GetRealHeight(20); btnScale.Gravity = Gravity.CenterHorizontal; btnScale.UnSelectedImagePath = "Item/PirSensorLightScale.png"; bodyFrameLayout.AddChidren(btnScale); //初始化光感等级的滑动进度条 this.InitLightLevelControl(space, YY); } #endregion #region ■ 设置光感等级_______________________ /// /// 初始化光感等级的滑动进度条 /// /// 左右间距大小 /// 文本的Y轴 private async void InitLightLevelControl(int space, int TextYY) { //打开进度条 this.ShowProgressBar(); //获取PIR传感器的【光感等级总刻度】 var level = await HdlPirSensorLogic.Current.GetPirLightAbilitySize(this.deviceIASZone); if (level == -1) { //关闭进度条 this.CloseProgressBar(ShowReLoadMode.YES); return; } Application.RunOnMainThread(() => { if (this.Parent != null) { //初始化滑动进度条 this.InitSeekBarControl(level, space, TextYY); } }); //关闭进度条 this.CloseProgressBar(); } /// /// 初始化滑动进度条 /// /// 光感等级总刻度 /// 左右间距大小 /// 文本的Y轴 private void InitSeekBarControl(int level, int space, int TextYY) { //这个是刻度移动一次的范围 int avgWidth = (Application.CurrentWidth - space * 2) / level; //刻度按钮 var btnScale = new IconViewControl(55); btnScale.X = space + avgWidth * (level - Lightconfigure.levelSize) + Application.GetRealWidth(10); btnScale.Y = Application.GetRealHeight(220) + TextYY; btnScale.UnSelectedImagePath = "Item/PirSensorLightScaleButton.png"; bodyFrameLayout.AddChidren(btnScale); //这东西有误差 btnScale.X += Application.GetRealWidth(4) * (level - Lightconfigure.levelSize); //光感等级总刻度 int lightLevelCount = level; //进度条 SeekBar = new HorizontalSeekBar(); SeekBar.X = space; SeekBar.Y = Application.GetRealHeight(200) + TextYY; SeekBar.Width = bodyFrameLayout.Width - space * 2; SeekBar.Height = Application.GetRealHeight(110); SeekBar.Max = level - 1; SeekBar.Gravity = Gravity.CenterHorizontal; SeekBar.BackgroundColor = UserCenterColor.Current.Transparent; SeekBar.BorderColor = UserCenterColor.Current.Transparent; SeekBar.ThumbColor = UserCenterColor.Current.Transparent; SeekBar.ProgressColor = UserCenterColor.Current.Transparent; bodyFrameLayout.AddChidren(SeekBar); SeekBar.Progress = level - Lightconfigure.levelSize; SeekBar.ProgressChanged += (sender, value) => { //因为它的等级刻度从左往右是从大到小的 this.selectLightLevel = lightLevelCount - value; //图标移动 btnScale.X = space + avgWidth * value + Application.GetRealWidth(10); //这东西有误差 btnScale.X += Application.GetRealWidth(4) * value; }; } #endregion #region ■ 保存配置___________________________ /// /// 保存传感器的灯光的配置信息 /// /// private async void SaveLightSettionData() { //开启进度条 this.ShowProgressBar(); //先记录缓存 int levelSize = this.Lightconfigure.levelSize; //设置新值 this.Lightconfigure.levelSize = this.selectLightLevel; var result = await HdlPirSensorLogic.Current.SetPirSensorLightSettion(this.deviceIASZone, this.Lightconfigure); //关闭进度条 this.CloseProgressBar(); if (result == true) { Application.RunOnMainThread(() => { this.CloseForm(); }); } else { //还原缓存 this.Lightconfigure.levelSize = levelSize; } } #endregion #region ■ 界面关闭___________________________ /// /// 界面关闭 /// public override void CloseForm() { UserView.HomePage.Instance.ScrollEnabled = true; base.CloseForm(); } #endregion } }