tzy
2021-05-25 65bcedda4d8e3ff6500dbf59a4e607d96e469375
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
using HDL_ON.Stan;
using Shared;
using System;
using System.Collections.Generic;
using System.Text;
 
namespace HDL_ON.UI
{
    /// <summary>
    /// 添加Evoyo的Mini智能遥控器步骤3界面
    /// </summary>
    public class AddMiniRemoteControlDirection3Page : EditorCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 当前wifi的名字
        /// </summary>
        private string NowWifiName = string.Empty;
        /// <summary>
        /// wifi的线程是否启动
        /// </summary>
        private bool WifiThreadAction = false;
        /// <summary>
        /// wifi名(别的界面传过来的)
        /// </summary>
        private string wifiName = string.Empty;
        /// <summary>
        /// wifi密码(别的界面传过来的)
        /// </summary>
        private string wifiPassword = string.Empty;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        /// <param name="i_wifiName">wifi名(别的界面传过来的)</param>
        /// <param name="i_wifiPassword">(别的界面传过来的)</param>
        public void ShowForm(string i_wifiName, string i_wifiPassword)
        {
            this.wifiName = i_wifiName;
            this.wifiPassword = i_wifiPassword;
 
            //设置头部信息
            base.SetTitleText(Language.StringByID(StringId.AddInfraredRemoteControl));
            //这个界面的背景需要白色
            bodyFrameLayout.BackgroundColor = UI.CSS.CSS_Color.MainBackgroundColor;
 
            //初始化中部信息
            this.InitMiddleFrame();
 
            //重写底层的返回按键
            this.BackButtonClickEvent += () =>
            {
                //关掉蓝牙
                HdlBluetoothLogic.Current.Dispone();
                this.CloseForm();
            };
        }
 
        /// <summary>
        /// 初始化中部信息
        /// </summary>
        private void InitMiddleFrame()
        {
            //连接WiFi
            var btnWifi = new NormalViewControl(200, 28, true);
            btnWifi.X = HdlControlResourse.XXLeft;
            btnWifi.Y = Application.GetRealHeight(16);
            btnWifi.IsBold = true;
            btnWifi.TextColor = CSS.CSS_Color.FirstLevelTitleColor;
            btnWifi.TextSize = CSS.CSS_FontSize.EmphasisFontSize_Secondary;
            btnWifi.TextID = StringId.ConnectWiFi;
            bodyFrameLayout.AddChidren(btnWifi);
            //目前只支持2.4G WiFi网络
            //暂不支持带有中文字符的WiFi名称
            var strMsg = Language.StringByID(StringId.AddInfraredRemoteControlMsg4);
            var listContr = this.AddListMsgControls(bodyFrameLayout, strMsg, CSS.CSS_FontSize.TextFontSize, CSS.CSS_Color.TextualColor,
                Application.GetRealHeight(20), btnWifi.Bottom + Application.GetRealHeight(16), TextAlignment.CenterLeft);
 
            //wifi行
            var rowWifi = new RowLayoutControl();
            rowWifi.Y = listContr[listContr.Count - 1].Bottom + Application.GetRealHeight(32);
            bodyFrameLayout.AddChidren(rowWifi);
            //wifi名字
            var txtWifi = rowWifi.frameTable.AddLeftInput(wifiName, 200);
            txtWifi.TextColor = CSS.CSS_Color.FirstLevelTitleColor;
            //底线
            rowWifi.frameTable.AddBottomLine();
            //向右图标
            var btnRight = rowWifi.frameTable.AddMostRightEmptyIcon(24, 24);
            btnRight.UnSelectedImagePath = "Public/Right.png";
            btnRight.ButtonClickEvent += (sender, e) =>
            {
                //打开手机wifi设置界面
                HdlWifiLogic.Current.OpenAppWifiSettion();
                //刷新wifi名字
                this.RefreshWifiName(txtWifi);
            };
            if (this.wifiName != string.Empty)
            {
                //这个时候是重试模式,不允许点击
                btnRight.CanClick = false;
            }
 
            //密码行
            var rowPsw = new RowLayoutControl();
            rowPsw.Y = rowWifi.Bottom;
            bodyFrameLayout.AddChidren(rowPsw);
            //密码
            var txtPsw = rowPsw.frameTable.AddLeftInput(wifiPassword, 200);
            txtPsw.TextColor = CSS.CSS_Color.FirstLevelTitleColor;
            txtPsw.PlaceholderText = Language.StringByID(StringId.Password);
            txtPsw.SecureTextEntry = true;
            //底线
            rowPsw.frameTable.AddBottomLine();
            //眼睛图标
            var btnView = rowPsw.frameTable.AddMostRightEmptyIcon(24, 24);
            btnView.UnSelectedImagePath = "LoginIcon/HidePasswordIcon.png";
            btnView.SelectedImagePath = "LoginIcon/ShowPasswordIcon.png";
            btnView.ButtonClickEvent += (sender, e) =>
            {
                btnView.IsSelected = !btnView.IsSelected;
                txtPsw.SecureTextEntry = !btnView.IsSelected;
            };
            if (this.wifiName != string.Empty)
            {
                //这个时候是重试模式,不需要点击
                HdlThreadLogic.Current.RunThread(() =>
                {
                    System.Threading.Thread.Sleep(1000);
                    HdlThreadLogic.Current.RunMain(() =>
                    {
                        //进入下一个界面
                        this.CloseForm();
                        var form = new AddMiniRemoteControlDirection4Page();
                        form.AddForm(wifiName, wifiPassword);
                    });
                });
                return;
            }
 
            //下一步
            var btnNext = this.AddBottomClickButton(Language.StringByID(StringId.Next));
            btnNext.ButtonClickEvent += (sender, e) =>
            {
                if (txtWifi.Text.Trim() == string.Empty || txtPsw.Text.Trim() == string.Empty)
                {
                    return;
                }
 
                //进入下一个界面
                this.CloseForm();
                var form = new AddMiniRemoteControlDirection4Page();
                form.AddForm(txtWifi.Text.Trim(), txtPsw.Text);
            };
 
            HdlThreadLogic.Current.RunThread(() =>
            {
                //打开进度条,卡它一下
                this.ShowProgressBar();
                //获取当前wifi名字(里面可能会卡)
                this.NowWifiName = HdlWifiLogic.Current.SSID;
                HdlThreadLogic.Current.RunMain(() =>
                {
                    txtWifi.Text = NowWifiName;
                });
 
                this.CloseProgressBar();
            });
        }
 
        #endregion
 
        #region ■ 一般方法___________________________
 
        /// <summary>
        /// 刷新wifi名字
        /// </summary>
        private void RefreshWifiName(TextInputControl textInput)
        {
            if (this.WifiThreadAction == true) { return; }
            this.WifiThreadAction = true;
 
            HdlThreadLogic.Current.RunThread(() =>
            {
                //这个线程不会被中断
                while (this.Parent != null)
                {
                    System.Threading.Thread.Sleep(1500);
                    string wifiName = string.Empty;
                    try
                    {
                        //获取当前wifi名字(里面可能会卡)
                        wifiName = HdlWifiLogic.Current.SSID;
                    }
                    catch { continue; }
                    if (wifiName != this.NowWifiName)
                    {
                        this.NowWifiName = wifiName;
                        HdlThreadLogic.Current.RunMain(() =>
                        {
                            textInput.Text = this.NowWifiName;
                        });
                    }
                }
            });
        }
 
        #endregion
    }
}