黄学彪
2021-03-11 7d5d552de16a149fafdc2d255ce50a86e7bef431
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
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;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        public void ShowForm()
        {
            //设置头部信息
            base.SetTitleText(Language.StringByID(StringId.AddInfraredRemoteControl));
            //这个界面的背景需要白色
            bodyFrameLayout.BackgroundColor = UI.CSS.CSS_Color.MainBackgroundColor;
 
            //初始化中部信息
            this.InitMiddleFrame();
        }
 
        /// <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);
            int yy = 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 = yy + Application.GetRealHeight(32);
            bodyFrameLayout.AddChidren(rowWifi);
            //wifi名字
            var txtWifi = rowWifi.frameTable.AddLeftInput("", 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);
            };
 
            //密码行
            var rowPsw = new RowLayoutControl();
            rowPsw.Y = rowWifi.Bottom;
            bodyFrameLayout.AddChidren(rowPsw);
            //密码
            var txtPsw = rowPsw.frameTable.AddLeftInput("551775569", 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;
            };
 
            //下一步
            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
    }
}