using HDL_ON.Stan; using Shared; using System; using System.Collections.Generic; using System.Text; namespace HDL_ON.UI { /// /// 添加Evoyo的Mini智能遥控器步骤2界面 /// public class AddMiniRemoteControlDirection2Page : EditorCommonForm { #region ■ 变量声明___________________________ #endregion #region ■ 初始化_____________________________ /// /// 画面显示(底层会固定调用此方法,借以完成画面创建) /// public void ShowForm() { //设置头部信息 base.SetTitleText(Language.StringByID(StringId.AddInfraredRemoteControl)); //这个界面的背景需要白色 bodyFrameLayout.BackgroundColor = UI.CSS.CSS_Color.MainBackgroundColor; //初始化中部信息 this.InitMiddleFrame(); } /// /// 初始化中部信息 /// private void InitMiddleFrame() { //清空body this.ClearBodyFrame(); //进度条 var btnProgress = new ProgressRowBar(180, 6); btnProgress.Y = Application.GetRealHeight(218); btnProgress.Gravity = Gravity.CenterHorizontal; bodyFrameLayout.AddChidren(btnProgress); btnProgress.StartMode1(true); //设备搜索中... var btnSearch = new NormalViewControl(bodyFrameLayout.Width, Application.GetRealHeight(20), false); btnSearch.Y = btnProgress.Bottom + Application.GetRealHeight(40); btnSearch.TextColor = CSS.CSS_Color.FirstLevelTitleColor; btnSearch.TextID = StringId.SearchingDevice; btnSearch.TextAlignment = TextAlignment.Center; bodyFrameLayout.AddChidren(btnSearch); //请确保您的蓝牙已开启并处于可以被搜索状态 var strMsg = Language.StringByID(StringId.AddInfraredRemoteControlMsg2); this.AddListMsgControls(bodyFrameLayout, strMsg, CSS.CSS_FontSize.TextFontSize, CSS.CSS_Color.FirstLevelTitleColor, Application.GetRealHeight(20), btnSearch.Bottom + Application.GetRealHeight(4)); //搜索时间(秒) int searchTime = 5; #if __IOS__ #endif #if __Android__ //安卓搜索蓝牙(特效问题,加1秒) this.StartSearchBluetoothOnAndriod(searchTime + 1); #endif HdlThreadLogic.Current.RunThread(() => { //进度条特效 for (int i = 0; i <= searchTime; i++) { HdlThreadLogic.Current.RunMain(() => { btnProgress.SetValue(i + 1, searchTime); }); System.Threading.Thread.Sleep(1000); } }); } #endregion #region ■ 安卓搜索蓝牙_______________________ #if __Android__ /// /// 安卓搜索蓝牙 /// /// 搜索时间(秒) private void StartSearchBluetoothOnAndriod(int i_searchTime) { //开始搜索蓝牙 HdlAndroidBluetoothLogic.Current.ScanBluetooth(i_searchTime, (listBluetooth) => { var listDevice = new List(); foreach (var device in listBluetooth) { //只有这个标识,才是红外宝 if (device.Name.StartsWith("MIR01R-LK.10") == true) { //是指定的红外宝设备 listDevice.Add(device); } } if (listDevice.Count == 0) { //摧毁蓝牙缓存 HdlAndroidBluetoothLogic.Current.Dispone(); //显示失败界面 HdlThreadLogic.Current.RunMain(() => { this.ShowFailView(); }); } else if (listDevice.Count == 1) { //如果只检测到一个,则直接连接 HdlAndroidBluetoothLogic.Current.ContectBluetooth(listDevice[0], (result) => { if (result == true) { //连接成功,则跳转到下一个界面 HdlThreadLogic.Current.RunMain(() => { this.CloseForm(); var form = new AddMiniRemoteControlDirection3Page(); form.AddForm(); }); } }); } else { var listName = new List(); foreach (var device in listDevice) { listName.Add(device.Name); } //显示选择蓝牙列表的界面(当匹配到多个蓝牙的时候使用) this.ShowBluetoothListView(listName, (index) => { //如果只检测到一个,则直接连接 HdlAndroidBluetoothLogic.Current.ContectBluetooth(listDevice[index], (result) => { if (result == true) { //连接成功,则跳转到下一个界面 HdlThreadLogic.Current.RunMain(() => { this.CloseForm(); var form = new AddMiniRemoteControlDirection3Page(); form.AddForm(); }); } }); }); } }); } #endif #endregion #region ■ 显示选择蓝牙列表的界面_____________ /// /// 显示选择蓝牙列表的界面(当匹配到多个蓝牙的时候使用) /// /// 蓝牙名字列表 /// 选择事件(考虑到Ios和安卓,所以这样定参数) private void ShowBluetoothListView(List listName, Action selectEvent) { HdlThreadLogic.Current.RunMain(() => { var contr = new BottomItemSelectControl(listName.Count, Language.StringByID(StringId.ChooseInfraredRemoteControl), false); //初始化 contr.AddRowMenu(listName, new List()); contr.FinishOnlyEvent += (div, value) => { if (div == 0) { //如果点击了取消,则关闭这个界面,不管了 this.CloseForm(); } else { //调用回调函数 selectEvent?.Invoke(value); } }; }); } #endregion #region ■ 显示失败界面_______________________ /// /// 显示失败界面 /// private void ShowFailView() { //清空body this.ClearBodyFrame(); //图片 var btnPic = new PicViewControl(180, 180); btnPic.Y = Application.GetRealHeight(48); btnPic.Gravity = Gravity.CenterHorizontal; btnPic.UnSelectedImagePath = "Public/TipIcon_Failed.png"; bodyFrameLayout.AddChidren(btnPic); //没有发现红外遥控器 var btnMsgNot = new NormalViewControl(bodyFrameLayout.Width, Application.GetRealHeight(22), false); btnMsgNot.Y = btnPic.Bottom + Application.GetRealHeight(16); btnMsgNot.TextAlignment = TextAlignment.Center; btnMsgNot.TextColor = CSS.CSS_Color.AuxiliaryColor2; btnMsgNot.TextSize = CSS.CSS_FontSize.SubheadingFontSize; btnMsgNot.TextID = StringId.NoInfraredRemoteControlFound; bodyFrameLayout.AddChidren(btnMsgNot); //1、请检查设备是否正常通电 //2、请检查蓝牙功能是否正常开启 //3、请检查指示灯是否蓝色快闪状态 var strMsg = Language.StringByID(StringId.AddInfraredRemoteControlMsg3); this.AddListMsgControls(bodyFrameLayout, strMsg, CSS.CSS_FontSize.TextFontSize, CSS.CSS_Color.TextualColor, Application.GetRealHeight(20), btnMsgNot.Bottom + Application.GetRealHeight(8), TextAlignment.Center, true); //重新搜索 var btnReSearch = this.AddBottomClickButton(Language.StringByID(StringId.ReSearch)); btnReSearch.ButtonClickEvent += (sender, e) => { //初始化中部信息 this.InitMiddleFrame(); }; } #endregion } }