using HDL_ON.DriverLayer; using HDL_ON.Stan; using Shared; using System; using System.Collections.Generic; using System.Text; namespace HDL_ON.UI { /// /// 添加Evoyo的Mini智能遥控器步骤3界面 /// public class AddMiniRemoteControlDirection3Page : EditorCommonForm { #region ■ 变量声明___________________________ /// /// 当前wifi的名字 /// private string NowWifiName = string.Empty; /// /// wifi的线程是否启动 /// private bool WifiThreadAction = false; /// /// wifi名(别的界面传过来的) /// private string wifiName = string.Empty; /// /// wifi密码(别的界面传过来的) /// private string wifiPassword = string.Empty; #endregion #region ■ 初始化_____________________________ /// /// 画面显示(底层会固定调用此方法,借以完成画面创建) /// /// wifi名(别的界面传过来的) /// (别的界面传过来的) 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(); }; } /// /// 初始化中部信息 /// 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; } //2021-10-26 09:32:50 增加网关进入配网模式 wxr Control.Ins.AuthGateway(); //进入下一个界面 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 ■ 一般方法___________________________ /// /// 刷新wifi名字 /// 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 } }