黄学彪
2019-09-30 404cdc88627f942df7944af04ee05b9d527752d6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
using System;
using System.Collections.Generic;
using System.Text;
using ZigBee.Device;
 
namespace Shared.Phone.UserCenter.DevicePirSensor
{
    /// <summary>
    /// PIR传感器光感调节界面★
    /// </summary>
    public class PirSensorLightPerceptionRegulationForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 传感器设备
        /// </summary>
        private IASZone deviceIASZone = null;
        /// <summary>
        /// 滑动的进度条
        /// </summary>
        private HorizontalSeekBar SeekBar = null;
        /// <summary>
        /// 灯光的配置
        /// </summary>
        private IASZone.ConfigureParamates Lightconfigure = null;
        /// <summary>
        /// 当前选择的光感等级
        /// </summary>
        private int selectLightLevel = -1;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        /// <param name="i_iasZone">传感器设备</param>
        /// <param name="i_Lightconfigure">灯光的配置</param>
        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();
            //};
        }
 
        /// <summary>
        /// 初始化中部信息
        /// </summary>
        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 ■ 设置光感等级_______________________
 
        /// <summary>
        /// 初始化光感等级的滑动进度条
        /// </summary>
        /// <param name="space">左右间距大小</param>
        /// <param name="TextYY">文本的Y轴</param>
        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();
        }
 
        /// <summary>
        /// 初始化滑动进度条
        /// </summary>
        /// <param name="level">光感等级总刻度</param>
        /// <param name="space">左右间距大小</param>
        /// <param name="TextYY">文本的Y轴</param>
        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 ■ 保存配置___________________________
 
        /// <summary>
        /// 保存传感器的灯光的配置信息
        /// </summary>
        /// <returns></returns>
        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 ■ 界面关闭___________________________
 
        /// <summary>
        /// 界面关闭
        /// </summary>
        public override void CloseForm()
        {
            UserView.HomePage.Instance.ScrollEnabled = true;
 
            base.CloseForm();
        }
 
        #endregion
    }
}